diff options
author | tailor <cygnus@janrain.com> | 2008-05-21 00:32:13 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2008-05-21 00:32:13 +0000 |
commit | bad45cb45aea88552dc61bbfca03b946b173bf76 (patch) | |
tree | e3ff84bf5a3db0449ea779ae37f7279f20912ef2 /Auth | |
parent | 1b5a2a7cf7fb6c01b503d49a17eda69d4293ddde (diff) | |
download | php-openid-bad45cb45aea88552dc61bbfca03b946b173bf76.zip php-openid-bad45cb45aea88552dc61bbfca03b946b173bf76.tar.gz php-openid-bad45cb45aea88552dc61bbfca03b946b173bf76.tar.bz2 |
[project @ Collapse allowedURL and isHTTPS checks into HTTPFetcher.canFetchURL]
Diffstat (limited to 'Auth')
-rw-r--r-- | Auth/Yadis/HTTPFetcher.php | 29 | ||||
-rw-r--r-- | Auth/Yadis/ParanoidHTTPFetcher.php | 16 | ||||
-rw-r--r-- | Auth/Yadis/PlainHTTPFetcher.php | 12 |
3 files changed, 34 insertions, 23 deletions
diff --git a/Auth/Yadis/HTTPFetcher.php b/Auth/Yadis/HTTPFetcher.php index 97617bf..6c2d6fa 100644 --- a/Auth/Yadis/HTTPFetcher.php +++ b/Auth/Yadis/HTTPFetcher.php @@ -13,6 +13,11 @@ * @license http://www.gnu.org/copyleft/lesser.html LGPL */ +/** + * Require logging functionality + */ +require_once "Auth/OpenID.php"; + class Auth_Yadis_HTTPResponse { function Auth_Yadis_HTTPResponse($final_url = null, $status = null, $headers = null, $body = null) @@ -37,6 +42,30 @@ class Auth_Yadis_HTTPFetcher { var $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. + * + * @return bool + */ + function canFetchURL($url) + { + if ($this->isHTTPS($url) && !$this->supportsSSL()) { + Auth_OpenID::log("HTTPS URL unsupported fetching %s", + $url); + return false; + } + + if (!$this->allowedURL($url)) { + Auth_OpenID::log("URL fetching not allowed for '%s'", + $url); + return false; + } + + return true; + } + + /** * Return whether a URL should be allowed. Override this method to * conform to your local policy. * diff --git a/Auth/Yadis/ParanoidHTTPFetcher.php b/Auth/Yadis/ParanoidHTTPFetcher.php index d34dc1c..e10f8c1 100644 --- a/Auth/Yadis/ParanoidHTTPFetcher.php +++ b/Auth/Yadis/ParanoidHTTPFetcher.php @@ -73,9 +73,7 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { function get($url, $extra_headers = null) { - if ($this->isHTTPS($url) && !$this->supportsSSL()) { - Auth_OpenID::log("HTTPS URL unsupported fetching %s", - $url); + if (!$this->canFetchURL($url)) { return null; } @@ -167,19 +165,11 @@ class Auth_Yadis_ParanoidHTTPFetcher extends Auth_Yadis_HTTPFetcher { function post($url, $body, $extra_headers = null) { - $this->reset(); - - if ($this->isHTTPS($url) && !$this->supportsSSL()) { - Auth_OpenID::log("HTTPS URL unsupported fetching %s", - $url); + if (!$this->canFetchURL($url)) { return null; } - if (!$this->allowedURL($url)) { - Auth_OpenID::log("Fetching URL not allowed: %s", - $url); - return null; - } + $this->reset(); $c = curl_init(); diff --git a/Auth/Yadis/PlainHTTPFetcher.php b/Auth/Yadis/PlainHTTPFetcher.php index d3b0d03..a89ebec 100644 --- a/Auth/Yadis/PlainHTTPFetcher.php +++ b/Auth/Yadis/PlainHTTPFetcher.php @@ -36,11 +36,7 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { function get($url, $extra_headers = null) { - if ($this->isHTTPS($url) && !$this->supportsSSL()) { - return null; - } - - if (!$this->allowedURL($url)) { + if (!$this->canFetchURL($url)) { return null; } @@ -147,11 +143,7 @@ class Auth_Yadis_PlainHTTPFetcher extends Auth_Yadis_HTTPFetcher { function post($url, $body, $extra_headers = null) { - if ($this->isHTTPS($url) && !$this->supportsSSL()) { - return null; - } - - if (!$this->allowedURL($url)) { + if (!$this->canFetchURL($url)) { return null; } |