ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Auth_Yadis_ParanoidHTTPFetcher Class Reference
+ Inheritance diagram for Auth_Yadis_ParanoidHTTPFetcher:
+ Collaboration diagram for Auth_Yadis_ParanoidHTTPFetcher:

Public Member Functions

 Auth_Yadis_ParanoidHTTPFetcher ()
 
 reset ()
 
 _writeHeader ($ch, $header)
 @access private More...
 
 _writeData ($ch, $data)
 @access private More...
 
 supportsSSL ()
 Does this fetcher support SSL URLs? More...
 
 get ($url, $extra_headers=null)
 Fetches the specified URL using optional extra headers and returns the server's response. More...
 
 post ($url, $body, $extra_headers=null)
 
- Public Member Functions inherited from Auth_Yadis_HTTPFetcher
 canFetchURL ($url)
 Return whether a URL can be fetched. More...
 
 allowedURL ($url)
 Return whether a URL should be allowed. More...
 
 supportsSSL ()
 Does this fetcher implementation (and runtime) support fetching HTTPS URLs? May inspect the runtime environment. More...
 
 isHTTPS ($url)
 Is this an https URL? More...
 
 URLHasAllowedScheme ($url)
 Is this an http or https URL? More...
 
 _findRedirect ($headers, $url)
 @access private More...
 
 get ($url, $headers=null)
 Fetches the specified URL using optional extra headers and returns the server's response. More...
 

Additional Inherited Members

- Data Fields inherited from Auth_Yadis_HTTPFetcher
 $timeout = 20
 

Detailed Description

Definition at line 29 of file ParanoidHTTPFetcher.php.

Member Function Documentation

◆ _writeData()

Auth_Yadis_ParanoidHTTPFetcher::_writeData (   $ch,
  $data 
)

@access private

Definition at line 53 of file ParanoidHTTPFetcher.php.

54 {
55 if (strlen($this->data) > 1024*Auth_OpenID_FETCHER_MAX_RESPONSE_KB) {
56 return 0;
57 } else {
58 $this->data .= $data;
59 return strlen($data);
60 }
61 }
const Auth_OpenID_FETCHER_MAX_RESPONSE_KB
Require logging functionality.
Definition: HTTPFetcher.php:21
$data

References $data, and Auth_OpenID_FETCHER_MAX_RESPONSE_KB.

◆ _writeHeader()

Auth_Yadis_ParanoidHTTPFetcher::_writeHeader (   $ch,
  $header 
)

@access private

Definition at line 44 of file ParanoidHTTPFetcher.php.

45 {
46 array_push($this->headers, rtrim($header));
47 return strlen($header);
48 }
$header

References $header.

◆ Auth_Yadis_ParanoidHTTPFetcher()

Auth_Yadis_ParanoidHTTPFetcher::Auth_Yadis_ParanoidHTTPFetcher ( )

Definition at line 30 of file ParanoidHTTPFetcher.php.

31 {
32 $this->reset();
33 }

References reset().

+ Here is the call graph for this function:

◆ get()

Auth_Yadis_ParanoidHTTPFetcher::get (   $url,
  $headers = null 
)

Fetches the specified URL using optional extra headers and returns the server's response.

Parameters
string$urlThe URL to be fetched.
array$extra_headersAn array of header strings (e.g. "Accept: text/html").
Returns
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.

Reimplemented from Auth_Yadis_HTTPFetcher.

Definition at line 78 of file ParanoidHTTPFetcher.php.

79 {
80 if (!$this->canFetchURL($url)) {
81 return null;
82 }
83
84 $stop = time() + $this->timeout;
85 $off = $this->timeout;
86
87 $redir = true;
88
89 while ($redir && ($off > 0)) {
90 $this->reset();
91
92 $c = curl_init();
93
94 if ($c === false) {
96 "curl_init returned false; could not " .
97 "initialize for URL '%s'", $url);
98 return null;
99 }
100
101 if (defined('CURLOPT_NOSIGNAL')) {
102 curl_setopt($c, CURLOPT_NOSIGNAL, true);
103 }
104
105 if (!$this->allowedURL($url)) {
106 Auth_OpenID::log("Fetching URL not allowed: %s",
107 $url);
108 return null;
109 }
110
111 curl_setopt($c, CURLOPT_WRITEFUNCTION,
112 array($this, "_writeData"));
113 curl_setopt($c, CURLOPT_HEADERFUNCTION,
114 array($this, "_writeHeader"));
115
116 if ($extra_headers) {
117 curl_setopt($c, CURLOPT_HTTPHEADER, $extra_headers);
118 }
119
120 $cv = curl_version();
121 if(is_array($cv)) {
122 $curl_user_agent = 'curl/'.$cv['version'];
123 } else {
124 $curl_user_agent = $cv;
125 }
126 curl_setopt($c, CURLOPT_USERAGENT,
127 Auth_OpenID_USER_AGENT.' '.$curl_user_agent);
128 curl_setopt($c, CURLOPT_TIMEOUT, $off);
129 curl_setopt($c, CURLOPT_URL, $url);
130
131 if (defined('Auth_OpenID_VERIFY_HOST')) {
132 curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
133 curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
134 }
135 curl_exec($c);
136
137 $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
138 $body = $this->data;
139 $headers = $this->headers;
140
141 if (!$code) {
142 Auth_OpenID::log("Got no response code when fetching %s", $url);
143 Auth_OpenID::log("CURL error (%s): %s",
144 curl_errno($c), curl_error($c));
145 return null;
146 }
147
148 if (in_array($code, array(301, 302, 303, 307))) {
149 $url = $this->_findRedirect($headers, $url);
150 $redir = true;
151 } else {
152 $redir = false;
153 curl_close($c);
154
155 if (defined('Auth_OpenID_VERIFY_HOST') &&
156 $this->isHTTPS($url)) {
157 Auth_OpenID::log('OpenID: Verified SSL host %s using '.
158 'curl/get', $url);
159 }
160 $new_headers = array();
161
162 foreach ($headers as $header) {
163 if (strpos($header, ': ')) {
164 list($name, $value) = explode(': ', $header, 2);
165 $new_headers[$name] = $value;
166 }
167 }
168
170 "Successfully fetched '%s': GET response code %s",
171 $url, $code);
172
174 $new_headers, $body);
175 }
176
177 $off = $stop - time();
178 }
179
180 return null;
181 }
const Auth_OpenID_USER_AGENT
Definition: HTTPFetcher.php:22
static log($format_string)
Wrap PHP's standard error_log functionality.
Definition: OpenID.php:525
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
_findRedirect($headers, $url)
@access private
$code
Definition: example_050.php:99
$url
Definition: shib_logout.php:72

References $code, $data, $header, Auth_Yadis_HTTPFetcher\$timeout, $url, Auth_Yadis_HTTPFetcher\_findRedirect(), Auth_Yadis_HTTPFetcher\allowedURL(), Auth_OpenID_USER_AGENT, Auth_Yadis_HTTPFetcher\canFetchURL(), Auth_Yadis_HTTPFetcher\isHTTPS(), Auth_OpenID\log(), and reset().

+ Here is the call graph for this function:

◆ post()

Auth_Yadis_ParanoidHTTPFetcher::post (   $url,
  $body,
  $extra_headers = null 
)

Definition at line 183 of file ParanoidHTTPFetcher.php.

184 {
185 if (!$this->canFetchURL($url)) {
186 return null;
187 }
188
189 $this->reset();
190
191 $c = curl_init();
192
193 if (defined('CURLOPT_NOSIGNAL')) {
194 curl_setopt($c, CURLOPT_NOSIGNAL, true);
195 }
196
197 curl_setopt($c, CURLOPT_POST, true);
198 curl_setopt($c, CURLOPT_POSTFIELDS, $body);
199 curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
200 curl_setopt($c, CURLOPT_URL, $url);
201 curl_setopt($c, CURLOPT_WRITEFUNCTION,
202 array($this, "_writeData"));
203
204 if (defined('Auth_OpenID_VERIFY_HOST')) {
205 curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
206 curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
207 }
208
209 curl_exec($c);
210
211 $code = curl_getinfo($c, CURLINFO_HTTP_CODE);
212
213 if (!$code) {
214 Auth_OpenID::log("Got no response code when fetching %s", $url);
215 Auth_OpenID::log("CURL error (%s): %s",
216 curl_errno($c), curl_error($c));
217 return null;
218 }
219
220 if (defined('Auth_OpenID_VERIFY_HOST') && $this->isHTTPS($url)) {
221 Auth_OpenID::log('OpenID: Verified SSL host %s using '.
222 'curl/post', $url);
223 }
224 $body = $this->data;
225
226 curl_close($c);
227
228 $new_headers = $extra_headers;
229
230 foreach ($this->headers as $header) {
231 if (strpos($header, ': ')) {
232 list($name, $value) = explode(': ', $header, 2);
233 $new_headers[$name] = $value;
234 }
235
236 }
237
238 Auth_OpenID::log("Successfully fetched '%s': POST response code %s",
239 $url, $code);
240
242 $new_headers, $body);
243 }

References $code, $data, $header, $url, Auth_Yadis_HTTPFetcher\canFetchURL(), Auth_Yadis_HTTPFetcher\isHTTPS(), Auth_OpenID\log(), and reset().

+ Here is the call graph for this function:

◆ reset()

Auth_Yadis_ParanoidHTTPFetcher::reset ( )

Definition at line 35 of file ParanoidHTTPFetcher.php.

36 {
37 $this->headers = array();
38 $this->data = "";
39 }

Referenced by Auth_Yadis_ParanoidHTTPFetcher(), get(), and post().

+ Here is the caller graph for this function:

◆ supportsSSL()

Auth_Yadis_ParanoidHTTPFetcher::supportsSSL ( )

Does this fetcher support SSL URLs?

Reimplemented from Auth_Yadis_HTTPFetcher.

Definition at line 66 of file ParanoidHTTPFetcher.php.

67 {
68 $v = curl_version();
69 if(is_array($v)) {
70 return in_array('https', $v['protocols']);
71 } elseif (is_string($v)) {
72 return preg_match('/OpenSSL/i', $v);
73 } else {
74 return 0;
75 }
76 }

The documentation for this class was generated from the following file: