diff options
Diffstat (limited to 'plugins/openid/lib/Auth/Yadis')
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/HTTPFetcher.php | 31 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/Manager.php | 61 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/ParanoidHTTPFetcher.php | 16 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/ParseHTML.php | 15 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/PlainHTTPFetcher.php | 8 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/XML.php | 33 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/XRDS.php | 35 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/XRI.php | 5 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/XRIRes.php | 4 | ||||
-rw-r--r-- | plugins/openid/lib/Auth/Yadis/Yadis.php | 41 |
10 files changed, 192 insertions, 57 deletions
diff --git a/plugins/openid/lib/Auth/Yadis/HTTPFetcher.php b/plugins/openid/lib/Auth/Yadis/HTTPFetcher.php index 76bc3239..a6e6814e 100644 --- a/plugins/openid/lib/Auth/Yadis/HTTPFetcher.php +++ b/plugins/openid/lib/Auth/Yadis/HTTPFetcher.php @@ -19,10 +19,16 @@ require_once "Auth/OpenID.php"; define('Auth_OpenID_FETCHER_MAX_RESPONSE_KB', 1024); -define('Auth_OpenID_USER_AGENT', +define('Auth_OpenID_USER_AGENT', 'php-openid/'.Auth_OpenID_VERSION.' (php/'.phpversion().')'); class Auth_Yadis_HTTPResponse { + + public $final_url = ''; + public $status = ''; + public $body = ''; + public $headers = array(); + function __construct($final_url = null, $status = null, $headers = null, $body = null) { @@ -43,13 +49,14 @@ class Auth_Yadis_HTTPResponse { */ class Auth_Yadis_HTTPFetcher { - var $timeout = 20; // timeout in seconds. + public $timeout = 20; // timeout in seconds. /** * Return whether a URL can be fetched. Returns false if the URL * scheme is not allowed or is not supported by this fetcher * implementation; returns true otherwise. * + * @param string $url * @return bool */ function canFetchURL($url) @@ -74,6 +81,9 @@ class Auth_Yadis_HTTPFetcher { * conform to your local policy. * * By default, will attempt to fetch any http or https URL. + * + * @param string $url + * @return bool */ function allowedURL($url) { @@ -90,12 +100,15 @@ class Auth_Yadis_HTTPFetcher { function supportsSSL() { trigger_error("not implemented", E_USER_ERROR); + return false; } /** * Is this an https URL? * * @access private + * @param string $url + * @return bool */ function isHTTPS($url) { @@ -106,6 +119,8 @@ class Auth_Yadis_HTTPFetcher { * Is this an http or https URL? * * @access private + * @param string $url + * @return bool */ function URLHasAllowedScheme($url) { @@ -114,6 +129,9 @@ class Auth_Yadis_HTTPFetcher { /** * @access private + * @param array $headers + * @param string $url + * @return null|string */ function _findRedirect($headers, $url) { @@ -159,16 +177,13 @@ class Auth_Yadis_HTTPFetcher { * returns the server's response. * * @param string $url The URL to be fetched. - * @param array $extra_headers An array of header strings - * (e.g. "Accept: text/html"). - * @return mixed $result An array of ($code, $url, $headers, - * $body) if the URL could be fetched; null if the URL does not - * pass the URLHasAllowedScheme check or if the server's response - * is malformed. + * @param array $headers + * @return Auth_Yadis_HTTPResponse|null */ function get($url, $headers = null) { trigger_error("not implemented", E_USER_ERROR); + return null; } } diff --git a/plugins/openid/lib/Auth/Yadis/Manager.php b/plugins/openid/lib/Auth/Yadis/Manager.php index 8c8c3e5a..8aae2da4 100644 --- a/plugins/openid/lib/Auth/Yadis/Manager.php +++ b/plugins/openid/lib/Auth/Yadis/Manager.php @@ -32,7 +32,7 @@ class Auth_Yadis_PHPSession { * @param string $name The name of the key to retrieve. * @param string $default The optional value to return if the key * is not found in the session. - * @return string $result The key's value in the session or + * @return mixed $result The key's value in the session or * $default if it isn't found. */ function get($name, $default=null) @@ -73,17 +73,21 @@ class Auth_Yadis_PHPSession { * * @package OpenID */ -class Auth_Yadis_SessionLoader { +abstract class Auth_Yadis_SessionLoader { /** * Override this. * * @access private + * @param array $data + * @return bool */ function check($data) { return true; } + public abstract function requiredKeys(); + /** * Given a session data value (an array), this creates an object * (returned by $this->newObject()) whose attributes and values @@ -93,6 +97,8 @@ class Auth_Yadis_SessionLoader { * evaluates to false. * * @access private + * @param array $data + * @return null */ function fromSession($data) { @@ -132,6 +138,8 @@ class Auth_Yadis_SessionLoader { * the original data array before calling $this->newObject($data). * * @access private + * @param array $data + * @return array */ function prepareForLoad($data) { @@ -145,6 +153,8 @@ class Auth_Yadis_SessionLoader { * the object's attributes. * * @access private + * @param array $data + * @return null */ function newObject($data) { @@ -158,6 +168,8 @@ class Auth_Yadis_SessionLoader { * from $obj. * * @access private + * @param object $obj + * @return array */ function toSession($obj) { @@ -181,6 +193,8 @@ class Auth_Yadis_SessionLoader { * Override this. * * @access private + * @param object $obj + * @return array */ function prepareForSave($obj) { @@ -275,10 +289,29 @@ class Auth_Yadis_ManagerLoader extends Auth_Yadis_SessionLoader { */ class Auth_Yadis_Manager { + /** @var string */ + public $starting_url; + + /** @var string */ + public $yadis_url; + + /** @var array */ + public $services; + + /** @var string */ + public $session_key; + + /** @var Auth_OpenID_ServiceEndpoint */ + public $_current; + /** * Intialize a new yadis service manager. * * @access private + * @param string $starting_url + * @param string $yadis_url + * @param array $services + * @param string $session_key */ function __construct($starting_url, $yadis_url, $services, $session_key) @@ -340,6 +373,8 @@ class Auth_Yadis_Manager { /** * @access private + * @param string $url + * @return bool */ function forURL($url) { @@ -371,12 +406,12 @@ class Auth_Yadis_Discovery { /** * @access private */ - var $DEFAULT_SUFFIX = 'auth'; + public $DEFAULT_SUFFIX = 'auth'; /** * @access private */ - var $PREFIX = '_yadis_services_'; + public $PREFIX = '_yadis_services_'; /** * Initialize a discovery object. @@ -404,6 +439,10 @@ class Auth_Yadis_Discovery { /** * Return the next authentication service for the pair of * user_input and session. This function handles fallback. + * + * @param callback $discover_cb + * @param object $fetcher + * @return null|Auth_OpenID_ServiceEndpoint */ function getNextService($discover_cb, $fetcher) { @@ -437,8 +476,9 @@ class Auth_Yadis_Discovery { * most-recently-attempted service from the manager, if one * exists. * - * @param $force True if the manager should be deleted regardless + * @param bool $force True if the manager should be deleted regardless * of whether it's a manager for $this->url. + * @return null|Auth_OpenID_ServiceEndpoint */ function cleanup($force=false) { @@ -465,8 +505,9 @@ class Auth_Yadis_Discovery { /** * @access private * - * @param $force True if the manager should be returned regardless + * @param bool $force True if the manager should be returned regardless * of whether it's a manager for $this->url. + * @return null|Auth_Yadis_Manager */ function getManager($force=false) { @@ -474,6 +515,7 @@ class Auth_Yadis_Discovery { // suffix from the session. $manager_str = $this->session->get($this->getSessionKey()); + /** @var Auth_Yadis_Manager $manager */ $manager = null; if ($manager_str !== null) { @@ -484,10 +526,14 @@ class Auth_Yadis_Discovery { if ($manager && ($manager->forURL($this->url) || $force)) { return $manager; } + return null; } /** * @access private + * @param array $services + * @param null|string $yadis_url + * @return Auth_Yadis_Manager|null */ function createManager($services, $yadis_url = null) { @@ -504,12 +550,13 @@ class Auth_Yadis_Discovery { serialize($loader->toSession($manager))); return $manager; } + return null; } /** * @access private * - * @param $force True if the manager should be deleted regardless + * @param bool $force True if the manager should be deleted regardless * of whether it's a manager for $this->url. */ function destroyManager($force=false) diff --git a/plugins/openid/lib/Auth/Yadis/ParanoidHTTPFetcher.php b/plugins/openid/lib/Auth/Yadis/ParanoidHTTPFetcher.php index d15969be..29acf3b1 100644 --- a/plugins/openid/lib/Auth/Yadis/ParanoidHTTPFetcher.php +++ b/plugins/openid/lib/Auth/Yadis/ParanoidHTTPFetcher.php @@ -27,6 +27,10 @@ require_once "Auth/OpenID.php"; * @package OpenID */ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { + + private $headers = array(); + private $data = ''; + function __construct() { $this->reset(); @@ -40,6 +44,9 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { /** * @access private + * @param string $ch + * @param string $header + * @return int */ function _writeHeader($ch, $header) { @@ -49,6 +56,9 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { /** * @access private + * @param string $ch + * @param string $data + * @return int */ function _writeData($ch, $data) { @@ -75,6 +85,11 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { } } + /** + * @param string $url + * @param array|null $extra_headers + * @return Auth_Yadis_HTTPResponse|null + */ function get($url, $extra_headers = null) { if (!$this->canFetchURL($url)) { @@ -153,6 +168,7 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { if (defined('Auth_OpenID_HTTP_PROXY')) { curl_setopt($c, CURLOPT_PROXY, Auth_OpenID_HTTP_PROXY); } + curl_exec($c); $code = curl_getinfo($c, CURLINFO_HTTP_CODE); diff --git a/plugins/openid/lib/Auth/Yadis/ParseHTML.php b/plugins/openid/lib/Auth/Yadis/ParseHTML.php index e0e9043c..8b8b33f2 100644 --- a/plugins/openid/lib/Auth/Yadis/ParseHTML.php +++ b/plugins/openid/lib/Auth/Yadis/ParseHTML.php @@ -25,23 +25,22 @@ class Auth_Yadis_ParseHTML { /** * @access private */ - var $_re_flags = "si"; + public $_re_flags = "si"; /** * @access private */ - var $_removed_re = - "<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>"; + public $_removed_re = '<!--.*?-->|<!\[CDATA\[.*?\]\]>|<script\b(?!:)[^>]*>.*?<\/script>'; /** * @access private */ - var $_tag_expr = "<%s%s(?:\s.*?)?%s>"; + public $_tag_expr = '<%s%s(?:\s.*?)?%s>'; /** * @access private */ - var $_attr_find = '\b([-\w]+)=(".*?"|\'.*?\'|.+?)[\/\s>]'; + public $_attr_find = '\b([-\w]+)=(".*?"|\'.*?\'|.+?)[\/\s>]'; function __construct() { @@ -78,7 +77,7 @@ class Auth_Yadis_ParseHTML { { $matches = array(); $double = '/^"(.*)"$/'; - $single = "/^\'(.*)\'$/"; + $single = "/^'(.*)'$/"; if (preg_match($double, $str, $matches)) { return $matches[1]; @@ -90,7 +89,7 @@ class Auth_Yadis_ParseHTML { } /** - * Create a regular expression that will match an opening + * Create a regular expression that will match an opening * or closing tag from a set of names. * * @access private @@ -181,7 +180,7 @@ class Auth_Yadis_ParseHTML { $link_data = array(); $link_matches = array(); - + if (!preg_match_all($this->tagPattern('meta', false, 'maybe'), $html_string, $link_matches)) { return array(); diff --git a/plugins/openid/lib/Auth/Yadis/PlainHTTPFetcher.php b/plugins/openid/lib/Auth/Yadis/PlainHTTPFetcher.php index 26890539..7a1bbba9 100644 --- a/plugins/openid/lib/Auth/Yadis/PlainHTTPFetcher.php +++ b/plugins/openid/lib/Auth/Yadis/PlainHTTPFetcher.php @@ -34,6 +34,11 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { return function_exists('openssl_open'); } + /** + * @param string $url + * @param array|null $extra_headers + * @return Auth_Yadis_HTTPResponse|null|bool + */ function get($url, $extra_headers = null) { if (!$this->canFetchURL($url)) { @@ -44,6 +49,9 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { $stop = time() + $this->timeout; $off = $this->timeout; + $headers = array(); + $code = ''; + $body = ''; while ($redir && ($off > 0)) { diff --git a/plugins/openid/lib/Auth/Yadis/XML.php b/plugins/openid/lib/Auth/Yadis/XML.php index c96b2a90..3039d54e 100644 --- a/plugins/openid/lib/Auth/Yadis/XML.php +++ b/plugins/openid/lib/Auth/Yadis/XML.php @@ -61,6 +61,7 @@ class Auth_Yadis_XMLParser { function registerNamespace($prefix, $uri) { // Not implemented. + return false; } /** @@ -76,6 +77,7 @@ class Auth_Yadis_XMLParser { function setXML($xml_string) { // Not implemented. + return false; } /** @@ -94,6 +96,7 @@ class Auth_Yadis_XMLParser { function &evalXPath($xpath, $node = null) { // Not implemented. + return array(); } /** @@ -107,6 +110,7 @@ class Auth_Yadis_XMLParser { function content($node) { // Not implemented. + return ''; } /** @@ -115,12 +119,13 @@ class Auth_Yadis_XMLParser { * @param mixed $node A node object from a previous call to * $this->evalXPath(). * - * @return array $attrs An array mapping attribute names to + * @return array An array mapping attribute names to * values. */ function attributes($node) { // Not implemented. + return array(); } } @@ -217,13 +222,16 @@ class Auth_Yadis_domxml extends Auth_Yadis_XMLParser { * @package OpenID */ class Auth_Yadis_dom extends Auth_Yadis_XMLParser { - function __construct() - { - $this->xml = null; - $this->doc = null; - $this->xpath = null; - $this->errors = array(); - } + + /** @var string */ + protected $xml = ''; + + protected $doc = null; + + /** @var DOMXPath */ + protected $xpath = null; + + protected $errors = array(); function setXML($xml_string) { @@ -294,11 +302,17 @@ class Auth_Yadis_dom extends Auth_Yadis_XMLParser { if ($node) { return $node->textContent; } + return ''; } + /** + * @param DOMNode $node + * @return array + */ function attributes($node) { if ($node) { + /** @var DOMNamedNodeMap $arr */ $arr = $node->attributes; $result = array(); @@ -311,6 +325,7 @@ class Auth_Yadis_dom extends Auth_Yadis_XMLParser { return $result; } + return array(); } } @@ -343,6 +358,8 @@ function Auth_Yadis_getSupportedExtensions() * the availability of PHP extensions for XML parsing. If * Auth_Yadis_setDefaultParser has been called, the parser used in * that call will be returned instead. + * + * @return Auth_Yadis_XMLParser|bool */ function Auth_Yadis_getXMLParser() { diff --git a/plugins/openid/lib/Auth/Yadis/XRDS.php b/plugins/openid/lib/Auth/Yadis/XRDS.php index 4f1ede07..81e0c91b 100644 --- a/plugins/openid/lib/Auth/Yadis/XRDS.php +++ b/plugins/openid/lib/Auth/Yadis/XRDS.php @@ -54,6 +54,8 @@ function Auth_Yadis_getNSMap() /** * @access private + * @param array $arr + * @return array */ function Auth_Yadis_array_scramble($arr) { @@ -82,14 +84,10 @@ function Auth_Yadis_array_scramble($arr) */ class Auth_Yadis_Service { - /** - * Creates an empty service object. - */ - function __construct() - { - $this->element = null; - $this->parser = null; - } + public $element = null; + + /** @var Auth_Yadis_XMLParser */ + public $parser = null; /** * Return the URIs in the "Type" elements, if any, of this Service @@ -213,7 +211,7 @@ class Auth_Yadis_Service { */ function Auth_Yadis_getXRDExpiration($xrd_element, $default=null) { - $expires_element = $xrd_element->$parser->evalXPath('/xrd:Expires'); + $expires_element = $xrd_element->parser->evalXPath('/xrd:Expires'); if ($expires_element === null) { return $default; } else { @@ -251,9 +249,22 @@ function Auth_Yadis_getXRDExpiration($xrd_element, $default=null) */ class Auth_Yadis_XRDS { + /** @var Auth_Yadis_XMLParser */ + public $parser; + + public $xrdNode; + + public $allXrdNodes; + + /** @var Auth_Yadis_Service[][] */ + public $serviceList; + /** * Instantiate a Auth_Yadis_XRDS object. Requires an XPath * instance which has been used to parse a valid XRDS document. + * + * @param Auth_Yadis_XMLParser $xmlParser + * @param array $xrdNodes */ function __construct($xmlParser, $xrdNodes) { @@ -270,6 +281,7 @@ class Auth_Yadis_XRDS { * XRDS XML is valid. * * @param string $xml_string An XRDS XML string. + * @param array|null $extra_ns_map * @return mixed $xrds An instance of Auth_Yadis_XRDS or null, * depending on the validity of $xml_string */ @@ -321,12 +333,13 @@ class Auth_Yadis_XRDS { return $_null; } - $xrds = new Auth_Yadis_XRDS($parser, $xrd_nodes); - return $xrds; + return new Auth_Yadis_XRDS($parser, $xrd_nodes); } /** * @access private + * @param int $priority + * @param string $service */ function _addService($priority, $service) { diff --git a/plugins/openid/lib/Auth/Yadis/XRI.php b/plugins/openid/lib/Auth/Yadis/XRI.php index 0143a692..50c291f9 100644 --- a/plugins/openid/lib/Auth/Yadis/XRI.php +++ b/plugins/openid/lib/Auth/Yadis/XRI.php @@ -184,6 +184,11 @@ function Auth_Yadis_XRI($xri) return $xri; } +/** + * @param string $iname + * @param Auth_Yadis_XRDS $xrds + * @return bool|string + */ function Auth_Yadis_getCanonicalID($iname, $xrds) { // Returns false or a canonical ID value. diff --git a/plugins/openid/lib/Auth/Yadis/XRIRes.php b/plugins/openid/lib/Auth/Yadis/XRIRes.php index b484beec..cdf7ef58 100644 --- a/plugins/openid/lib/Auth/Yadis/XRIRes.php +++ b/plugins/openid/lib/Auth/Yadis/XRIRes.php @@ -8,6 +8,10 @@ require_once 'Auth/Yadis/XRDS.php'; require_once 'Auth/Yadis/XRI.php'; class Auth_Yadis_ProxyResolver { + + /** @var Auth_Yadis_HTTPFetcher */ + protected $fetcher; + function __construct($fetcher, $proxy_url = null) { $this->fetcher = $fetcher; diff --git a/plugins/openid/lib/Auth/Yadis/Yadis.php b/plugins/openid/lib/Auth/Yadis/Yadis.php index 5be56da1..70dc944d 100644 --- a/plugins/openid/lib/Auth/Yadis/Yadis.php +++ b/plugins/openid/lib/Auth/Yadis/Yadis.php @@ -48,25 +48,28 @@ define('Auth_Yadis_HEADER_NAME', 'X-XRDS-Location'); class Auth_Yadis_DiscoveryResult { // The URI that was passed to the fetcher - var $request_uri = null; + public $request_uri = null; // The result of following redirects from the request_uri - var $normalized_uri = null; + public $normalized_uri = null; // The URI from which the response text was returned (set to // None if there was no XRDS document found) - var $xrds_uri = null; + public $xrds_uri = null; - var $xrds = null; + /** + * @var Auth_Yadis_XRDS + */ + public $xrds = null; // The content-type returned with the response_text - var $content_type = null; + public $content_type = null; // The document returned from the xrds_uri - var $response_text = null; + public $response_text = null; // Did the discovery fail miserably? - var $failed = false; + public $failed = false; function __construct($request_uri) { @@ -123,7 +126,11 @@ class Auth_Yadis_DiscoveryResult { * * input_url: The URL on which to perform the Yadis protocol * - * @return: The normalized identity URL and an iterable of endpoint + * @param string $input_url + * @param $xrds_parse_func + * @param null $discover_func + * @param null $fetcher + * @return string The normalized identity URL and an iterable of endpoint * objects generated by the filter function. * * xrds_parse_func: a callback which will take (uri, xrds_text) and @@ -137,7 +144,7 @@ function Auth_Yadis_getServiceEndpoints($input_url, $xrds_parse_func, $discover_func=null, $fetcher=null) { if ($discover_func === null) { - $discover_function = array('Auth_Yadis_Yadis', 'discover'); + $discover_func = array('Auth_Yadis_Yadis', 'discover'); } $yadis_result = call_user_func_array($discover_func, @@ -249,6 +256,9 @@ class Auth_Yadis_Yadis { * * If Auth_Yadis_CURL_OVERRIDE is defined, this method will always * return a {@link Auth_Yadis_PlainHTTPFetcher}. + * + * @param int $timeout + * @return Auth_Yadis_ParanoidHTTPFetcher|Auth_Yadis_PlainHTTPFetcher */ static function getHTTPFetcher($timeout = 20) { @@ -268,6 +278,9 @@ class Auth_Yadis_Yadis { /** * @access private + * @param array $header_list + * @param array $names + * @return string */ static function _getHeader($header_list, $names) { @@ -284,6 +297,8 @@ class Auth_Yadis_Yadis { /** * @access private + * @param string $content_type_header + * @return string */ static function _getContentType($content_type_header) { @@ -291,6 +306,7 @@ class Auth_Yadis_Yadis { $parts = explode(";", $content_type_header); return strtolower($parts[0]); } + return ''; } /** @@ -300,16 +316,12 @@ class Auth_Yadis_Yadis { * * @param string $uri The URI on which to perform Yadis discovery. * - * @param array $http_response An array reference where the HTTP - * response object will be stored (see {@link - * Auth_Yadis_HTTPResponse}. - * * @param Auth_Yadis_HTTPFetcher $fetcher An instance of a * Auth_Yadis_HTTPFetcher subclass. * * @param array $extra_ns_map An array which maps namespace names * to namespace URIs to be used when parsing the Yadis XRDS - * document. + * document. UNUSED. * * @param integer $timeout An optional fetcher timeout, in seconds. * @@ -322,7 +334,6 @@ class Auth_Yadis_Yadis { { $result = new Auth_Yadis_DiscoveryResult($uri); - $request_uri = $uri; $headers = array("Accept: " . Auth_Yadis_CONTENT_TYPE . ', text/html; q=0.3, application/xhtml+xml; q=0.5'); |