|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /** 00004 * This module contains the HTTP fetcher interface 00005 * 00006 * PHP versions 4 and 5 00007 * 00008 * LICENSE: See the COPYING file included in this distribution. 00009 * 00010 * @package OpenID 00011 * @author JanRain, Inc. <openid@janrain.com> 00012 * @copyright 2005-2008 Janrain, Inc. 00013 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 00014 */ 00015 00016 /** 00017 * Require logging functionality 00018 */ 00019 require_once "Auth/OpenID.php"; 00020 00021 define('Auth_OpenID_FETCHER_MAX_RESPONSE_KB', 1024); 00022 define('Auth_OpenID_USER_AGENT', 00023 'php-openid/'.Auth_OpenID_VERSION.' (php/'.phpversion().')'); 00024 00025 class Auth_Yadis_HTTPResponse { 00026 function Auth_Yadis_HTTPResponse($final_url = null, $status = null, 00027 $headers = null, $body = null) 00028 { 00029 $this->final_url = $final_url; 00030 $this->status = $status; 00031 $this->headers = $headers; 00032 $this->body = $body; 00033 } 00034 } 00035 00036 /** 00037 * This class is the interface for HTTP fetchers the Yadis library 00038 * uses. This interface is only important if you need to write a new 00039 * fetcher for some reason. 00040 * 00041 * @access private 00042 * @package OpenID 00043 */ 00044 class Auth_Yadis_HTTPFetcher { 00045 00046 var $timeout = 20; // timeout in seconds. 00047 00048 /** 00049 * Return whether a URL can be fetched. Returns false if the URL 00050 * scheme is not allowed or is not supported by this fetcher 00051 * implementation; returns true otherwise. 00052 * 00053 * @return bool 00054 */ 00055 function canFetchURL($url) 00056 { 00057 if ($this->isHTTPS($url) && !$this->supportsSSL()) { 00058 Auth_OpenID::log("HTTPS URL unsupported fetching %s", 00059 $url); 00060 return false; 00061 } 00062 00063 if (!$this->allowedURL($url)) { 00064 Auth_OpenID::log("URL fetching not allowed for '%s'", 00065 $url); 00066 return false; 00067 } 00068 00069 return true; 00070 } 00071 00072 /** 00073 * Return whether a URL should be allowed. Override this method to 00074 * conform to your local policy. 00075 * 00076 * By default, will attempt to fetch any http or https URL. 00077 */ 00078 function allowedURL($url) 00079 { 00080 return $this->URLHasAllowedScheme($url); 00081 } 00082 00083 /** 00084 * Does this fetcher implementation (and runtime) support fetching 00085 * HTTPS URLs? May inspect the runtime environment. 00086 * 00087 * @return bool $support True if this fetcher supports HTTPS 00088 * fetching; false if not. 00089 */ 00090 function supportsSSL() 00091 { 00092 trigger_error("not implemented", E_USER_ERROR); 00093 } 00094 00095 /** 00096 * Is this an https URL? 00097 * 00098 * @access private 00099 */ 00100 function isHTTPS($url) 00101 { 00102 return (bool)preg_match('/^https:\/\//i', $url); 00103 } 00104 00105 /** 00106 * Is this an http or https URL? 00107 * 00108 * @access private 00109 */ 00110 function URLHasAllowedScheme($url) 00111 { 00112 return (bool)preg_match('/^https?:\/\//i', $url); 00113 } 00114 00115 /** 00116 * @access private 00117 */ 00118 function _findRedirect($headers) 00119 { 00120 foreach ($headers as $line) { 00121 if (strpos(strtolower($line), "location: ") === 0) { 00122 $parts = explode(" ", $line, 2); 00123 return $parts[1]; 00124 } 00125 } 00126 return null; 00127 } 00128 00129 /** 00130 * Fetches the specified URL using optional extra headers and 00131 * returns the server's response. 00132 * 00133 * @param string $url The URL to be fetched. 00134 * @param array $extra_headers An array of header strings 00135 * (e.g. "Accept: text/html"). 00136 * @return mixed $result An array of ($code, $url, $headers, 00137 * $body) if the URL could be fetched; null if the URL does not 00138 * pass the URLHasAllowedScheme check or if the server's response 00139 * is malformed. 00140 */ 00141 function get($url, $headers) 00142 { 00143 trigger_error("not implemented", E_USER_ERROR); 00144 } 00145 } 00146 00147 ?>
1.8.0