This commit is contained in:
Laurent Destailleur 2021-11-01 03:18:12 +01:00
parent 6acc8a6582
commit 2f7e246ab3

View File

@ -66,58 +66,55 @@
************************/ ************************/
class httpException extends Exception class httpException extends Exception
{ {
protected $errno; protected $errno;
public function __construct ($msg, $errno = null) public function __construct($msg, $errno = null)
{ {
parent::__construct ($msg); parent::__construct($msg);
$this->errno = $errno; $this->errno = $errno;
} }
public function getErrorFormatted () public function getErrorFormatted()
{ {
return sprintf ("[http_class]: %s -- "._(" file %s, line %s"), return sprintf("[http_class]: %s -- "._(" file %s, line %s"),
$this->getMessage (), $this->getFile (), $this->getLine ()); $this->getMessage(), $this->getFile(), $this->getLine());
} }
public function getErrno () public function getErrno()
{ {
return $this->errno; return $this->errno;
} }
} }
function error2string($value) function error2string($value)
{ {
$level_names = array( $level_names = array(
E_ERROR => 'E_ERROR', E_ERROR => 'E_ERROR',
E_WARNING => 'E_WARNING', E_WARNING => 'E_WARNING',
E_PARSE => 'E_PARSE', E_PARSE => 'E_PARSE',
E_NOTICE => 'E_NOTICE', E_NOTICE => 'E_NOTICE',
E_CORE_ERROR => 'E_CORE_ERROR', E_CORE_ERROR => 'E_CORE_ERROR',
E_CORE_WARNING => 'E_CORE_WARNING', E_CORE_WARNING => 'E_CORE_WARNING',
E_COMPILE_ERROR => 'E_COMPILE_ERROR', E_COMPILE_ERROR => 'E_COMPILE_ERROR',
E_COMPILE_WARNING => 'E_COMPILE_WARNING', E_COMPILE_WARNING => 'E_COMPILE_WARNING',
E_USER_ERROR => 'E_USER_ERROR', E_USER_ERROR => 'E_USER_ERROR',
E_USER_WARNING => 'E_USER_WARNING', E_USER_WARNING => 'E_USER_WARNING',
E_USER_NOTICE => 'E_USER_NOTICE' E_USER_NOTICE => 'E_USER_NOTICE'
); );
if(defined('E_STRICT')) { if (defined('E_STRICT')) {
$level_names[E_STRICT]='E_STRICT'; $level_names[E_STRICT]='E_STRICT';
} }
$levels=array(); $levels=array();
if(($value&E_ALL)==E_ALL) if (($value&E_ALL)==E_ALL) {
{ $levels[]='E_ALL';
$levels[]='E_ALL'; $value&=~E_ALL;
$value&=~E_ALL; }
} foreach ($level_names as $level=>$name) {
foreach($level_names as $level=>$name) if (($value&$level)==$level) {
{ $levels[]=$name;
if(($value&$level)==$level) }
{ }
$levels[]=$name; return implode(' | ', $levels);
}
}
return implode(' | ',$levels);
} }
/*********************** /***********************
@ -127,486 +124,427 @@ function error2string($value)
************************/ ************************/
class http_class class http_class
{ {
// variables declaration // variables declaration
public $debug; public $debug;
public $html_debug; public $html_debug;
public $timeout = 30; // time waiting for connection, seconds public $timeout = 30; // time waiting for connection, seconds
public $data_timeout = 30; // time waiting for data, milliseconds public $data_timeout = 30; // time waiting for data, milliseconds
public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond public $data_chunk_timeout = 1; // time waiting between data chunks, millisecond
public $force_multipart_form_post; public $force_multipart_form_post;
public $username; public $username;
public $password; public $password;
public $request_headers = array (); public $request_headers = array ();
public $request_body = "Not a useful information"; public $request_body = "Not a useful information";
public $status; public $status;
public $window_size = 1024; // chunk size of data public $window_size = 1024; // chunk size of data
public $with_exceptions = 0; // compatibility mode for old scripts public $with_exceptions = 0; // compatibility mode for old scripts
public $port; public $port;
public $host; public $host;
private $default_port = 631; private $default_port = 631;
private $headers; private $headers;
private $reply_headers = array (); private $reply_headers = array ();
private $reply_body = array (); private $reply_body = array ();
private $connection; private $connection;
private $arguments; private $arguments;
private $bodystream = array (); private $bodystream = array ();
private $last_limit; private $last_limit;
private $connected; private $connected;
private $nc = 1; private $nc = 1;
private $user_agent = "PRINTIPP/0.81+CVS"; private $user_agent = "PRINTIPP/0.81+CVS";
private $readed_bytes = 0; private $readed_bytes = 0;
public function __construct () public function __construct()
{ {
true; true;
} }
/********************* /*********************
* *
* Public functions * Public functions
* *
**********************/ **********************/
public function GetRequestArguments ($url, &$arguments) public function GetRequestArguments($url, &$arguments)
{ {
$this->arguments = array (); $this->arguments = array ();
$this->arguments["URL"] = $arguments["URL"] = $url; $this->arguments["URL"] = $arguments["URL"] = $url;
$this->arguments["RequestMethod"] = $arguments["RequestMethod"] = "POST"; $this->arguments["RequestMethod"] = $arguments["RequestMethod"] = "POST";
$this->headers["Content-Length"] = 0; $this->headers["Content-Length"] = 0;
$this->headers["Content-Type"] = "application/octet-stream"; $this->headers["Content-Type"] = "application/octet-stream";
$this->headers["Host"] = $this->host; $this->headers["Host"] = $this->host;
$this->headers["User-Agent"] = $this->user_agent; $this->headers["User-Agent"] = $this->user_agent;
//$this->headers["Expect"] = "100-continue"; //$this->headers["Expect"] = "100-continue";
} }
public function Open ($arguments) public function Open($arguments)
{ {
$this->connected = false; $this->connected = false;
$url = $arguments["URL"]; $url = $arguments["URL"];
$port = $this->default_port; $port = $this->default_port;
#$url = split (':', $url, 2); // $url = split (':', $url, 2);
$url = preg_split ('#:#', $url, 2); $url = preg_split('#:#', $url, 2);
$transport_type = $url[0]; $transport_type = $url[0];
$unix = false; $unix = false;
switch ($transport_type) switch ($transport_type) {
{ case 'http':
case 'http': $transport_type = 'tcp://';
$transport_type = 'tcp://'; break;
break;
case 'https': case 'https':
$transport_type = 'tls://'; $transport_type = 'tls://';
break; break;
case 'unix': case 'unix':
$transport_type = 'unix://'; $transport_type = 'unix://';
$port = 0; $port = 0;
$unix = true; $unix = true;
break; break;
default: default:
$transport_type = 'tcp://'; $transport_type = 'tcp://';
break; break;
} }
$url = $url[1]; $url = $url[1];
if (!$unix) if (!$unix) {
{ // $url = split ("/", preg_replace ("#^/{1,}#", '', $url), 2);
#$url = split ("/", preg_replace ("#^/{1,}#", '', $url), 2); $url = preg_split("#/#", preg_replace("#^/{1,}#", '', $url), 2);
$url = preg_split ("#/#", preg_replace ("#^/{1,}#", '', $url), 2); $url = $url[0];
$url = $url[0]; $port = $this->port;
$port = $this->port; $error = sprintf(_("Cannot resolve url: %s"), $url);
$error = sprintf (_("Cannot resolve url: %s"), $url); $ip = gethostbyname($url);
$ip = gethostbyname ($url); $ip = @gethostbyaddr($ip);
$ip = @gethostbyaddr ($ip); if (!$ip) {
if (!$ip) return $this->_HttpError($error, E_USER_WARNING);
{ }
return $this->_HttpError ($error, E_USER_WARNING); if (strstr($url, ":")) { // we got an ipv6 address
} if (!strstr($url, "[")) { // it is not escaped
if (strstr ($url, ":")) // we got an ipv6 address $url = sprintf("[%s]", $url);
{ }
if (!strstr ($url, "[")) // it is not escaped }
{ }
$url = sprintf ("[%s]", $url); $this->connection = @fsockopen($transport_type.$url, $port, $errno, $errstr, $this->timeout);
} $error =
} sprintf(_('Unable to connect to "%s%s port %s": %s'), $transport_type,
} $url, $port, $errstr);
$this->connection = @fsockopen ($transport_type.$url, $port, $errno, $errstr, $this->timeout); if (!$this->connection) {
$error = return $this->_HttpError($error, E_USER_WARNING);
sprintf (_('Unable to connect to "%s%s port %s": %s'), $transport_type, }
$url, $port, $errstr); $this->connected = true;
if (!$this->connection) return array (true, "success");
{ }
return $this->_HttpError ($error, E_USER_WARNING);
}
$this->connected = true;
return array (true, "success");
}
public function SendRequest ($arguments) public function SendRequest($arguments)
{ {
$error = $error =
sprintf (_('Streaming request failed to %s'), $arguments['RequestURI']); sprintf(_('Streaming request failed to %s'), $arguments['RequestURI']);
$result = self::_StreamRequest ($arguments); $result = self::_StreamRequest($arguments);
if (!$result[0]) if (!$result[0]) {
{ return $this->_HttpError($error." ".$result[1], E_USER_WARNING);
return $this->_HttpError ($error." ".$result[1], E_USER_WARNING); }
} self::_ReadReply();
self::_ReadReply (); if (!preg_match('#http/1.1 401 unauthorized#', $this->status)) {
if (!preg_match ('#http/1.1 401 unauthorized#', $this->status)) return array (true, "success");
{ }
return array (true, "success"); $headers = array_keys($this->reply_headers);
} $error = _("need authentication but no mechanism provided");
$headers = array_keys ($this->reply_headers); if (!in_array("www-authenticate", $headers)) {
$error = _("need authentication but no mechanism provided"); return $this->_HttpError($error, E_USER_WARNING);
if (!in_array ("www-authenticate", $headers)) }
{ // $authtype = split (' ', $this->reply_headers["www-authenticate"]);
return $this->_HttpError ($error, E_USER_WARNING); $authtype = preg_split('# #', $this->reply_headers["www-authenticate"]);
} $authtype = strtolower($authtype[0]);
#$authtype = split (' ', $this->reply_headers["www-authenticate"]); switch ($authtype) {
$authtype = preg_split ('# #', $this->reply_headers["www-authenticate"]); case 'basic':
$authtype = strtolower ($authtype[0]); $pass = base64_encode($this->user.":".$this->password);
switch ($authtype) $arguments["Headers"]["Authorization"] = "Basic ".$pass;
{ break;
case 'basic':
$pass = base64_encode ($this->user.":".$this->password);
$arguments["Headers"]["Authorization"] = "Basic ".$pass;
break;
case 'digest': case 'digest':
$arguments["Headers"]["Authorization"] = self::_BuildDigest (); $arguments["Headers"]["Authorization"] = self::_BuildDigest();
break; break;
default: default:
$error = $error =
sprintf (_("need '%s' authentication mechanism, but have not"), sprintf(_("need '%s' authentication mechanism, but have not"),
$authtype[0]); $authtype[0]);
return $this->_HttpError ($error, E_USER_WARNING); return $this->_HttpError($error, E_USER_WARNING);
break; break;
} }
self::Close (); self::Close();
self::Open ($arguments); self::Open($arguments);
$error = sprintf(_('Streaming request failed to %s after a try to authenticate'), $arguments['RequestURI']); $error = sprintf(_('Streaming request failed to %s after a try to authenticate'), $arguments['RequestURI']);
$result = self::_StreamRequest ($arguments); $result = self::_StreamRequest($arguments);
if (!$result[0]) if (!$result[0]) {
{ return $this->_HttpError($error.": ".$result[1], E_USER_WARNING);
return $this->_HttpError ($error.": ".$result[1], E_USER_WARNING); }
} self::_ReadReply();
self::_ReadReply (); return array (true, "success");
return array (true, "success"); }
}
public function ReadReplyHeaders (&$headers) public function ReadReplyHeaders(&$headers)
{ {
$headers = $this->reply_headers; $headers = $this->reply_headers;
} }
public function ReadReplyBody (&$body, $chunk_size) public function ReadReplyBody(&$body, $chunk_size)
{ {
$body = substr ($this->reply_body, $this->last_limit, $chunk_size); $body = substr($this->reply_body, $this->last_limit, $chunk_size);
$this->last_limit += $chunk_size; $this->last_limit += $chunk_size;
} }
public function Close () public function Close()
{ {
if (!$this->connected) if (!$this->connected) {
{ return;
return; }
} fclose($this->connection);
fclose ($this->connection); }
}
/********************* /*********************
* *
* Private functions * Private functions
* *
*********************/ *********************/
private function _HttpError ($msg, $level, $errno = null) private function _HttpError($msg, $level, $errno = null)
{ {
$trace = ''; $trace = '';
$backtrace = debug_backtrace(); $backtrace = debug_backtrace();
foreach ($backtrace as $trace) foreach ($backtrace as $trace) {
{ $trace .= sprintf("in [file: '%s'][function: '%s'][line: %s];\n", $trace['file'], $trace['function'], $trace['line']);
$trace .= sprintf ("in [file: '%s'][function: '%s'][line: %s];\n", $trace['file'], $trace['function'],$trace['line']); }
} $msg = sprintf( '%s\n%s: [errno: %s]: %s',
$msg = sprintf ( '%s\n%s: [errno: %s]: %s', $trace, error2string($level), $errno, $msg);
$trace, error2string ($level), $errno, $msg); if ($this->with_exceptions) {
if ($this->with_exceptions) throw new httpException($msg, $errno);
{ } else {
throw new httpException ($msg, $errno); trigger_error($msg, $level);
} return array (false, $msg);
else }
{ }
trigger_error ($msg, $level);
return array (false, $msg);
}
}
private function _streamString ($string) private function _streamString($string)
{ {
$success = fwrite ($this->connection, $string); $success = fwrite($this->connection, $string);
if (!$success) if (!$success) {
{ return false;
return false; }
} return true;
return true; }
}
private function _StreamRequest ($arguments) private function _StreamRequest($arguments)
{ {
$this->status = false; $this->status = false;
$this->reply_headers = array (); $this->reply_headers = array ();
$this->reply_body = ""; $this->reply_body = "";
if (!$this->connected) if (!$this->connected) {
{ return $this->_HttpError(_("not connected"), E_USER_WARNING);
return $this->_HttpError (_("not connected"), E_USER_WARNING); }
} $this->arguments = $arguments;
$this->arguments = $arguments; $content_length = 0;
$content_length = 0; foreach ($this->arguments["BodyStream"] as $argument) {
foreach ($this->arguments["BodyStream"] as $argument) // list ($type, $value) = each ($argument);
{ $type = key($argument);
list ($type, $value) = each ($argument); $value = current($argument);
reset ($argument); reset($argument);
if ($type == "Data") if ($type == "Data") {
{ $length = strlen($value);
$length = strlen ($value); } elseif ($type == "File") {
} if (is_readable($value)) {
elseif ($type == "File") $length = filesize($value);
{ } else {
if (is_readable ($value)) $length = 0;
{ return $this->_HttpError(sprintf(_("%s: file is not readable"), $value), E_USER_WARNING);
$length = filesize ($value); }
} } else {
else $length = 0;
{ return $this->_HttpError(sprintf(_("%s: not a valid argument for content"), $type), E_USER_WARNING);
$length = 0; }
return $this->_HttpError (sprintf (_("%s: file is not readable"), $value), E_USER_WARNING); $content_length += $length;
} }
} $this->request_body = sprintf(_("%s Bytes"), $content_length);
else $this->headers["Content-Length"] = $content_length;
{ $this->arguments["Headers"] = array_merge($this->headers, $this->arguments["Headers"]);
$length = 0; if ($this->arguments["RequestMethod"] != "POST") {
return $this->_HttpError (sprintf(_("%s: not a valid argument for content"), $type), E_USER_WARNING); return $this->_HttpError(sprintf(_("%s: method not implemented"), $arguments["RequestMethod"]), E_USER_WARNING);
} }
$content_length += $length; $string = sprintf("POST %s HTTP/1.1\r\n", $this->arguments["RequestURI"]);
} $this->request_headers[$string] = '';
$this->request_body = sprintf (_("%s Bytes"), $content_length); if (!$this->_streamString($string)) {
$this->headers["Content-Length"] = $content_length; return $this->_HttpError(_("Error while puts POST operation"), E_USER_WARNING);
$this->arguments["Headers"] = array_merge ($this->headers, $this->arguments["Headers"]); }
if ($this->arguments["RequestMethod"] != "POST") foreach ($this->arguments["Headers"] as $header => $value) {
{ $string = sprintf("%s: %s\r\n", $header, $value);
return $this->_HttpError (sprintf(_("%s: method not implemented"), $arguments["RequestMethod"]), E_USER_WARNING); $this->request_headers[$header] = $value;
} if (!$this->_streamString($string)) {
$string = sprintf ("POST %s HTTP/1.1\r\n", $this->arguments["RequestURI"]); return $this->_HttpError(_("Error while puts HTTP headers"), E_USER_WARNING);
$this->request_headers[$string] = ''; }
if (!$this->_streamString ($string)) }
{ $string = "\r\n";
return $this->_HttpError (_("Error while puts POST operation"), E_USER_WARNING); if (!$this->_streamString($string)) {
} return $this->_HttpError(_("Error while ends HTTP headers"), E_USER_WARNING);
foreach ($this->arguments["Headers"] as $header => $value) }
{ foreach ($this->arguments["BodyStream"] as $argument) {
$string = sprintf ("%s: %s\r\n", $header, $value); // list ($type, $value) = each ($argument);
$this->request_headers[$header] = $value; $type = key($argument);
if (!$this->_streamString ($string)) $value = current($argument);
{ reset($argument);
return $this->_HttpError (_("Error while puts HTTP headers"), E_USER_WARNING); if ($type == "Data") {
} $streamed_length = 0;
} while ($streamed_length < strlen($value)) {
$string = "\r\n"; $string = substr($value, $streamed_length, $this->window_size);
if (!$this->_streamString ($string)) if (!$this->_streamString($string)) {
{ return $this->_HttpError(_("error while sending body data"), E_USER_WARNING);
return $this->_HttpError (_("Error while ends HTTP headers"), E_USER_WARNING); }
} $streamed_length += $this->window_size;
foreach ($this->arguments["BodyStream"] as $argument) }
{ } elseif ($type == "File") {
list ($type, $value) = each ($argument); if (is_readable($value)) {
reset ($argument); $file = fopen($value, 'rb');
if ($type == "Data") while (!feof($file)) {
{ if (gettype($block = @fread($file, $this->window_size)) != "string") {
$streamed_length = 0; return $this->_HttpError(_("cannot read file to upload"), E_USER_WARNING);
while ($streamed_length < strlen ($value)) }
{ if (!$this->_streamString($block)) {
$string = substr ($value, $streamed_length, $this->window_size); return $this->_HttpError(_("error while sending body data"), E_USER_WARNING);
if (!$this->_streamString ($string)) }
{ }
return $this->_HttpError (_("error while sending body data"), E_USER_WARNING); }
} }
$streamed_length += $this->window_size; }
} return array (true, "success");
} }
elseif ($type == "File")
{
if (is_readable ($value))
{
$file = fopen ($value, 'rb');
while (!feof ($file))
{
if (gettype ($block = @fread ($file, $this->window_size)) != "string")
{
return $this->_HttpError (_("cannot read file to upload"), E_USER_WARNING);
}
if (!$this->_streamString ($block))
{
return $this->_HttpError (_("error while sending body data"), E_USER_WARNING);
}
}
}
}
}
return array (true, "success");
}
private function _ReadReply () private function _ReadReply()
{ {
if (!$this->connected) if (!$this->connected) {
{ return array (false, _("not connected"));
return array (false, _("not connected")); }
} $this->reply_headers = array ();
$this->reply_headers = array (); $this->reply_body = "";
$this->reply_body = ""; $headers = array ();
$headers = array (); $body = "";
$body = ""; while (!feof($this->connection)) {
while (!feof ($this->connection)) $line = fgets($this->connection, 1024);
{ if (strlen(trim($line)) == 0) {
$line = fgets ($this->connection, 1024); break;
if (strlen (trim($line)) == 0) } // \r\n => end of headers
{ if (preg_match('#^[[:space:]]#', $line)) {
break; $headers[-1] .= sprintf(' %s', trim($line));
} // \r\n => end of headers continue;
if (preg_match ('#^[[:space:]]#', $line)) }
{ $headers[] = trim($line);
$headers[-1] .= sprintf(' %s', trim ($line)); }
continue; $this->status = isset($headers[0]) ? strtolower($headers[0]) : false;
} foreach ($headers as $header) {
$headers[] = trim ($line); $header = preg_split("#: #", $header);
} $header[0] = strtolower($header[0]);
$this->status = isset ($headers[0]) ? strtolower ($headers[0]) : false; if ($header[0] !== "www-authenticate") {
foreach ($headers as $header) $header[1] = isset($header[1]) ? strtolower($header[1]) : "";
{ }
$header = preg_split ("#: #", $header); if (!isset($this->reply_headers[$header[0]])) {
$header[0] = strtolower ($header[0]); $this->reply_headers[$header[0]] = $header[1];
if ($header[0] !== "www-authenticate") }
{ }
$header[1] = isset ($header[1]) ? strtolower ($header[1]) : ""; self::_ReadStream();
} return true;
if (!isset ($this->reply_headers[$header[0]])) }
{
$this->reply_headers[$header[0]] = $header[1];
}
}
self::_ReadStream ();
return true;
}
private function _ReadStream () private function _ReadStream()
{ {
if (! array_key_exists ("content-length", $this->reply_headers)) if (! array_key_exists("content-length", $this->reply_headers)) {
{ stream_set_blocking($this->connection, 0);
stream_set_blocking($this->connection, 0); $this->reply_body = stream_get_contents($this->connection);
$this->reply_body = stream_get_contents($this->connection); return true;
return true; }
} stream_set_blocking($this->connection, 1);
stream_set_blocking($this->connection, 1); $content_length = $this->reply_headers["content-length"];
$content_length = $this->reply_headers["content-length"]; $this->reply_body = stream_get_contents($this->connection, $content_length);
$this->reply_body = stream_get_contents($this->connection,$content_length); return true;
return true; }
}
private function _BuildDigest () private function _BuildDigest()
{ {
$auth = $this->reply_headers["www-authenticate"]; $auth = $this->reply_headers["www-authenticate"];
#list ($head, $auth) = split (" ", $auth, 2); // list ($head, $auth) = split (" ", $auth, 2);
list ($head, $auth) = preg_split ("# #", $auth, 2); list ($head, $auth) = preg_split("# #", $auth, 2);
#$auth = split (", ", $auth); // $auth = split (", ", $auth);
$auth = preg_split ("#, #", $auth); $auth = preg_split("#, #", $auth);
foreach ($auth as $sheme) foreach ($auth as $sheme) {
{ // list ($sheme, $value) = split ('=', $sheme);
#list ($sheme, $value) = split ('=', $sheme); list ($sheme, $value) = preg_split('#=#', $sheme);
list ($sheme, $value) = preg_split ('#=#', $sheme); $fields[$sheme] = trim(trim($value), '"');
$fields[$sheme] = trim (trim ($value), '"'); }
} $nc = sprintf('%x', $this->nc);
$nc = sprintf ('%x', $this->nc); $prepend = "";
$prepend = ""; while ((strlen($nc) + strlen($prepend)) < 8)
while ((strlen ($nc) + strlen ($prepend)) < 8) $prependi .= "0";
$prependi .= "0"; $nc = $prepend.$nc;
$nc = $prepend.$nc; $cnonce = "printipp";
$cnonce = "printipp"; $username = $this->user;
$username = $this->user; $password = $this->password;
$password = $this->password; $A1 = $username.":".$fields["realm"].":".$password;
$A1 = $username.":".$fields["realm"].":".$password; if (array_key_exists("algorithm", $fields)) {
if (array_key_exists ("algorithm", $fields)) $algorithm = strtolower($fields["algorithm"]);
{ switch ($algorithm) {
$algorithm = strtolower ($fields["algorithm"]); case "md5":
switch ($algorithm) break;
{
case "md5":
break;
case "md5-sess": case "md5-sess":
$A1 = $A1 =
$username.":".$fields["realm"].":".$password.":". $username.":".$fields["realm"].":".$password.":".
$fields['nonce'].":".$cnonce; $fields['nonce'].":".$cnonce;
break; break;
default: default:
return $this->_HttpError( return $this->_HttpError(
sprintf (_("digest Authorization: algorithm '%s' not implemented"), sprintf(_("digest Authorization: algorithm '%s' not implemented"),
$algorithm), $algorithm),
E_USER_WARNING); E_USER_WARNING);
return false; return false;
break; break;
} }
} }
$A2 = "POST:".$this->arguments["RequestURI"]; $A2 = "POST:".$this->arguments["RequestURI"];
if (array_key_exists ("qop", $fields)) if (array_key_exists("qop", $fields)) {
{ $qop = strtolower($fields["qop"]);
$qop = strtolower ($fields["qop"]); // $qop = split (" ", $qop);
#$qop = split (" ", $qop); $qop = preg_split("# #", $qop);
$qop = preg_split ("# #", $qop); if (in_array("auth", $qop)) {
if (in_array ("auth", $qop)) $qop = "auth";
{ } else {
$qop = "auth"; self::_HttpError(
} sprintf(_("digest Authorization: algorithm '%s' not implemented"),
else $qop),
{ E_USER_WARNING);
self::_HttpError( return false;
sprintf (_("digest Authorization: algorithm '%s' not implemented"), }
$qop), }
E_USER_WARNING); $response = md5(md5($A1).":".$fields["nonce"].":".md5($A2));
return false; if (isset($qop) && ($qop == "auth")) {
} $response =
} md5(md5($A1).":".$fields["nonce"].":".$nc.":".$cnonce.":".$qop.
$response = md5 (md5 ($A1).":".$fields["nonce"].":".md5 ($A2)); ":".$A2);
if (isset ($qop) && ($qop == "auth")) }
{ $auth_scheme =
$response = sprintf('Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s"',
md5 (md5 ($A1).":".$fields["nonce"].":".$nc.":".$cnonce.":".$qop. $username, $fields["realm"], $fields['nonce'],
":".$A2); $this->arguments["RequestURI"], $response);
} if (isset($algorithm)) {
$auth_scheme = $auth_scheme .= sprintf(', algorithm="%s"', $algorithm);
sprintf }
('Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s"', if (isset($qop)) {
$username, $fields["realm"], $fields['nonce'], $auth_scheme .= sprintf(', cnonce="%s"', $cnonce);
$this->arguments["RequestURI"], $response); }
if (isset ($algorithm)) if (array_key_exists("opaque", $fields)) {
{ $auth_scheme .= sprintf(', opaque="%s"', $fields['opaque']);
$auth_scheme .= sprintf (', algorithm="%s"', $algorithm); }
} if (isset($qop)) {
if (isset ($qop)) $auth_scheme .= sprintf(', qop="%s"', $qop);
{ }
$auth_scheme .= sprintf (', cnonce="%s"', $cnonce); $auth_scheme .= sprintf(', nc=%s', $nc);
} $this->nc++;
if (array_key_exists ("opaque", $fields)) return $auth_scheme;
{ }
$auth_scheme .= sprintf (', opaque="%s"', $fields['opaque']);
}
if (isset ($qop))
{
$auth_scheme .= sprintf (', qop="%s"', $qop);
}
$auth_scheme .= sprintf (', nc=%s', $nc);
$this->nc++;
return $auth_scheme;
}
} }