ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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)
 private
 _writeData ($ch, $data)
 private
 supportsSSL ()
 Does this fetcher support SSL URLs?
 get ($url, $extra_headers=null)
 Fetches the specified URL using optional extra headers and returns the server's response.
 post ($url, $body, $extra_headers=null)
- Public Member Functions inherited from Auth_Yadis_HTTPFetcher
 canFetchURL ($url)
 Return whether a URL can be fetched.
 allowedURL ($url)
 Return whether a URL should be allowed.
 isHTTPS ($url)
 Is this an https URL?
 URLHasAllowedScheme ($url)
 Is this an http or https URL?
 _findRedirect ($headers, $url)
 private

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

Auth_Yadis_ParanoidHTTPFetcher::_writeData (   $ch,
  $data 
)

private

Definition at line 53 of file ParanoidHTTPFetcher.php.

References $data, and Auth_OpenID_FETCHER_MAX_RESPONSE_KB.

{
if (strlen($this->data) > 1024*Auth_OpenID_FETCHER_MAX_RESPONSE_KB) {
return 0;
} else {
$this->data .= $data;
return strlen($data);
}
}
Auth_Yadis_ParanoidHTTPFetcher::_writeHeader (   $ch,
  $header 
)

private

Definition at line 44 of file ParanoidHTTPFetcher.php.

{
array_push($this->headers, rtrim($header));
return strlen($header);
}
Auth_Yadis_ParanoidHTTPFetcher::Auth_Yadis_ParanoidHTTPFetcher ( )

Definition at line 30 of file ParanoidHTTPFetcher.php.

References reset().

{
$this->reset();
}

+ Here is the call graph for this function:

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.

References $data, $name, Auth_Yadis_HTTPFetcher\$timeout, 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().

{
if (!$this->canFetchURL($url)) {
return null;
}
$stop = time() + $this->timeout;
$redir = true;
while ($redir && ($off > 0)) {
$this->reset();
$c = curl_init();
if ($c === false) {
"curl_init returned false; could not " .
"initialize for URL '%s'", $url);
return null;
}
if (defined('CURLOPT_NOSIGNAL')) {
curl_setopt($c, CURLOPT_NOSIGNAL, true);
}
if (!$this->allowedURL($url)) {
Auth_OpenID::log("Fetching URL not allowed: %s",
$url);
return null;
}
curl_setopt($c, CURLOPT_WRITEFUNCTION,
array($this, "_writeData"));
curl_setopt($c, CURLOPT_HEADERFUNCTION,
array($this, "_writeHeader"));
if ($extra_headers) {
curl_setopt($c, CURLOPT_HTTPHEADER, $extra_headers);
}
$cv = curl_version();
if(is_array($cv)) {
$curl_user_agent = 'curl/'.$cv['version'];
} else {
$curl_user_agent = $cv;
}
curl_setopt($c, CURLOPT_USERAGENT,
Auth_OpenID_USER_AGENT.' '.$curl_user_agent);
curl_setopt($c, CURLOPT_TIMEOUT, $off);
curl_setopt($c, CURLOPT_URL, $url);
if (defined('Auth_OpenID_VERIFY_HOST')) {
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
}
curl_exec($c);
$code = curl_getinfo($c, CURLINFO_HTTP_CODE);
$body = $this->data;
$headers = $this->headers;
if (!$code) {
Auth_OpenID::log("Got no response code when fetching %s", $url);
Auth_OpenID::log("CURL error (%s): %s",
curl_errno($c), curl_error($c));
return null;
}
if (in_array($code, array(301, 302, 303, 307))) {
$url = $this->_findRedirect($headers, $url);
$redir = true;
} else {
$redir = false;
curl_close($c);
if (defined('Auth_OpenID_VERIFY_HOST') &&
$this->isHTTPS($url)) {
Auth_OpenID::log('OpenID: Verified SSL host %s using '.
'curl/get', $url);
}
$new_headers = array();
foreach ($headers as $header) {
if (strpos($header, ': ')) {
list($name, $value) = explode(': ', $header, 2);
$new_headers[$name] = $value;
}
}
"Successfully fetched '%s': GET response code %s",
$url, $code);
return new Auth_Yadis_HTTPResponse($url, $code,
$new_headers, $body);
}
$off = $stop - time();
}
return null;
}

+ Here is the call graph for this function:

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

Definition at line 183 of file ParanoidHTTPFetcher.php.

References $data, $name, Auth_Yadis_HTTPFetcher\canFetchURL(), Auth_Yadis_HTTPFetcher\isHTTPS(), Auth_OpenID\log(), and reset().

{
if (!$this->canFetchURL($url)) {
return null;
}
$this->reset();
$c = curl_init();
if (defined('CURLOPT_NOSIGNAL')) {
curl_setopt($c, CURLOPT_NOSIGNAL, true);
}
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $body);
curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($c, CURLOPT_URL, $url);
curl_setopt($c, CURLOPT_WRITEFUNCTION,
array($this, "_writeData"));
if (defined('Auth_OpenID_VERIFY_HOST')) {
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);
}
curl_exec($c);
$code = curl_getinfo($c, CURLINFO_HTTP_CODE);
if (!$code) {
Auth_OpenID::log("Got no response code when fetching %s", $url);
Auth_OpenID::log("CURL error (%s): %s",
curl_errno($c), curl_error($c));
return null;
}
if (defined('Auth_OpenID_VERIFY_HOST') && $this->isHTTPS($url)) {
Auth_OpenID::log('OpenID: Verified SSL host %s using '.
'curl/post', $url);
}
$body = $this->data;
curl_close($c);
$new_headers = $extra_headers;
foreach ($this->headers as $header) {
if (strpos($header, ': ')) {
list($name, $value) = explode(': ', $header, 2);
$new_headers[$name] = $value;
}
}
Auth_OpenID::log("Successfully fetched '%s': POST response code %s",
$url, $code);
return new Auth_Yadis_HTTPResponse($url, $code,
$new_headers, $body);
}

+ Here is the call graph for this function:

Auth_Yadis_ParanoidHTTPFetcher::reset ( )

Definition at line 35 of file ParanoidHTTPFetcher.php.

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

{
$this->headers = array();
$this->data = "";
}

+ Here is the caller graph for this function:

Auth_Yadis_ParanoidHTTPFetcher::supportsSSL ( )

Does this fetcher support SSL URLs?

Reimplemented from Auth_Yadis_HTTPFetcher.

Definition at line 66 of file ParanoidHTTPFetcher.php.

{
$v = curl_version();
if(is_array($v)) {
return in_array('https', $v['protocols']);
} elseif (is_string($v)) {
return preg_match('/OpenSSL/i', $v);
} else {
return 0;
}
}

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