ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
HTTPFetcher.php
Go to the documentation of this file.
1<?php
2
19require_once "Auth/OpenID.php";
20
21define('Auth_OpenID_FETCHER_MAX_RESPONSE_KB', 1024);
22define('Auth_OpenID_USER_AGENT',
23 'php-openid/'.Auth_OpenID_VERSION.' (php/'.phpversion().')');
26 function Auth_Yadis_HTTPResponse($final_url = null, $status = null,
27 $headers = null, $body = null)
28 {
29 $this->final_url = $final_url;
30 $this->status = $status;
31 $this->headers = $headers;
32 $this->body = $body;
33 }
34}
35
46 var $timeout = 20; // timeout in seconds.
47
55 function canFetchURL($url)
56 {
57 if ($this->isHTTPS($url) && !$this->supportsSSL()) {
58 Auth_OpenID::log("HTTPS URL unsupported fetching %s",
59 $url);
60 return false;
61 }
62
63 if (!$this->allowedURL($url)) {
64 Auth_OpenID::log("URL fetching not allowed for '%s'",
65 $url);
66 return false;
67 }
68
69 return true;
70 }
71
78 function allowedURL($url)
79 {
80 return $this->URLHasAllowedScheme($url);
81 }
82
90 function supportsSSL()
91 {
92 trigger_error("not implemented", E_USER_ERROR);
93 }
94
100 function isHTTPS($url)
101 {
102 return (bool)preg_match('/^https:\/\//i', $url);
103 }
104
110 function URLHasAllowedScheme($url)
111 {
112 return (bool)preg_match('/^https?:\/\//i', $url);
113 }
114
118 function _findRedirect($headers, $url)
119 {
120 foreach ($headers as $line) {
121 if (strpos(strtolower($line), "location: ") === 0) {
122 $parts = explode(" ", $line, 2);
123 $loc = $parts[1];
124 $ppos = strpos($loc, "://");
125 if ($ppos === false || $ppos > strpos($loc, "/")) {
126 /* no host; add it */
127 $hpos = strpos($url, "://");
128 $prt = substr($url, 0, $hpos+3);
129 $url = substr($url, $hpos+3);
130 if (substr($loc, 0, 1) == "/") {
131 /* absolute path */
132 $fspos = strpos($url, "/");
133 if ($fspos) $loc = $prt.substr($url, 0, $fspos).$loc;
134 else $loc = $prt.$url.$loc;
135 } else {
136 /* relative path */
137 $pp = $prt;
138 while (1) {
139 $xpos = strpos($url, "/");
140 if ($xpos === false) break;
141 $apos = strpos($url, "?");
142 if ($apos !== false && $apos < $xpos) break;
143 $apos = strpos($url, "&");
144 if ($apos !== false && $apos < $xpos) break;
145 $pp .= substr($url, 0, $xpos+1);
146 $url = substr($url, $xpos+1);
147 }
148 $loc = $pp.$loc;
149 }
150 }
151 return $loc;
152 }
153 }
154 return null;
155 }
156
169 function get($url, $headers = null)
170 {
171 trigger_error("not implemented", E_USER_ERROR);
172 }
173}
174
const Auth_OpenID_VERSION
The library version string.
Definition: OpenID.php:23
static log($format_string)
Wrap PHP's standard error_log functionality.
Definition: OpenID.php:525
supportsSSL()
Does this fetcher implementation (and runtime) support fetching HTTPS URLs? May inspect the runtime e...
Definition: HTTPFetcher.php:89
allowedURL($url)
Return whether a URL should be allowed.
Definition: HTTPFetcher.php:77
isHTTPS($url)
Is this an https URL?
Definition: HTTPFetcher.php:99
canFetchURL($url)
Return whether a URL can be fetched.
Definition: HTTPFetcher.php:54
URLHasAllowedScheme($url)
Is this an http or https URL?
_findRedirect($headers, $url)
@access private
Auth_Yadis_HTTPResponse($final_url=null, $status=null, $headers=null, $body=null)
Definition: HTTPFetcher.php:25
$url
Definition: shib_logout.php:72