b2evolution PHP Cross Reference Blogging Systems

Source: /inc/_ext/phpsvnclient/http.php - 1759 lines - 63590 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*
   4   * http.php
   5   *
   6   * @(#) $Header: /home/mlemos/cvsroot/http/http.php,v 1.76 2008/03/18 07:59:05 mlemos Exp $
   7   *
   8   */
   9  
  10  if( ! defined( 'EVO_MAIN_INIT' ) ) die( 'Please, do not access this page directly.' );
  11  
  12  class http_class {
  13  
  14      var $host_name = "";
  15      var $host_port = 0;
  16      var $proxy_host_name = "";
  17      var $proxy_host_port = 80;
  18      var $socks_host_name = '';
  19      var $socks_host_port = 1080;
  20      var $socks_version = '5';
  21      var $protocol = "http";
  22      var $request_method = "GET";
  23      var $user_agent = 'httpclient (http://www.phpclasses.org/httpclient $Revision: 1.76 $)';
  24      var $authentication_mechanism = "";
  25      var $user;
  26      var $password;
  27      var $realm;
  28      var $workstation;
  29      var $proxy_authentication_mechanism = "";
  30      var $proxy_user;
  31      var $proxy_password;
  32      var $proxy_realm;
  33      var $proxy_workstation;
  34      var $request_uri = "";
  35      var $request = "";
  36      var $request_headers = array();
  37      var $request_user;
  38      var $request_password;
  39      var $request_realm;
  40      var $request_workstation;
  41      var $proxy_request_user;
  42      var $proxy_request_password;
  43      var $proxy_request_realm;
  44      var $proxy_request_workstation;
  45      var $request_body = "";
  46      var $request_arguments = array();
  47      var $protocol_version = "1.1";
  48      var $timeout = 0;
  49      var $data_timeout = 0;
  50      var $debug = 0;
  51      var $debug_response_body = 1;
  52      var $html_debug = 0;
  53      var $support_cookies = 1;
  54      var $cookies = array();
  55      var $error = "";
  56      var $exclude_address = "";
  57      var $follow_redirect = 0;
  58      var $redirection_limit = 5;
  59      var $response_status = "";
  60      var $response_message = "";
  61      var $file_buffer_length = 8000;
  62      var $force_multipart_form_post = 0;
  63      var $prefer_curl = 0;
  64  
  65      /* private variables - DO NOT ACCESS */
  66      var $state = "Disconnected";
  67      var $use_curl = 0;
  68      var $connection = 0;
  69      var $content_length = 0;
  70      var $response = "";
  71      var $read_response = 0;
  72      var $read_length = 0;
  73      var $request_host = "";
  74      var $next_token = "";
  75      var $redirection_level = 0;
  76      var $chunked = 0;
  77      var $remaining_chunk = 0;
  78      var $last_chunk_read = 0;
  79      var $months = array(
  80      "Jan" => "01",
  81      "Feb" => "02",
  82      "Mar" => "03",
  83      "Apr" => "04",
  84      "May" => "05",
  85      "Jun" => "06",
  86      "Jul" => "07",
  87      "Aug" => "08",
  88      "Sep" => "09",
  89      "Oct" => "10",
  90      "Nov" => "11",
  91      "Dec" => "12");
  92      var $session = '';
  93      var $connection_close = 0;
  94  
  95      /* Private methods - DO NOT CALL */
  96  
  97      Function Tokenize($string, $separator="") {
  98      if (!strcmp($separator, "")) {
  99          $separator = $string;
 100          $string = $this->next_token;
 101      }
 102      for ($character = 0; $character < strlen($separator); $character++) {
 103          if (GetType($position = strpos($string, $separator[$character])) == "integer")
 104          $found = (IsSet($found) ? min($found, $position) : $position);
 105      }
 106      if (IsSet($found)) {
 107          $this->next_token = substr($string, $found + 1);
 108          return(substr($string, 0, $found));
 109      } else {
 110          $this->next_token = "";
 111          return($string);
 112      }
 113      }
 114  
 115      Function CookieEncode($value, $name) {
 116      return($name ? str_replace("=", "%25", $value) : str_replace(";", "%3B", $value));
 117      }
 118  
 119      Function SetError($error) {
 120      return($this->error = $error);
 121      }
 122  
 123      Function SetPHPError($error, &$php_error_message) {
 124      if (IsSet($php_error_message)
 125          && strlen($php_error_message))
 126          $error.=": " . $php_error_message;
 127      return($this->SetError($error));
 128      }
 129  
 130      Function SetDataAccessError($error, $check_connection=0) {
 131      $this->error = $error;
 132      if (!$this->use_curl
 133          && function_exists("socket_get_status")) {
 134          $status = socket_get_status($this->connection);
 135          if ($status["timed_out"])
 136          $this->error.=": data access time out";
 137          elseif ($status["eof"]) {
 138          if ($check_connection)
 139              $this->error = "";
 140          else
 141              $this->error.=": the server disconnected";
 142          }
 143      }
 144      }
 145  
 146      Function OutputDebug($message) {
 147      $message.="\n";
 148      if ($this->html_debug)
 149          $message = str_replace("\n", "<br />\n", HtmlEntities($message));
 150      echo $message;
 151      evo_flush();
 152      }
 153  
 154      Function GetLine() {
 155      for ($line = "";;) {
 156          if ($this->use_curl) {
 157          $eol = strpos($this->response, "\n", $this->read_response);
 158          $data = ($eol ? substr($this->response, $this->read_response, $eol + 1 - $this->read_response) : "");
 159          $this->read_response+=strlen($data);
 160          } else {
 161          if (feof($this->connection)) {
 162              $this->SetDataAccessError("reached the end of data while reading from the HTTP server connection");
 163              return(0);
 164          }
 165          $data = fgets($this->connection, 100);
 166          }
 167          if (GetType($data) != "string"
 168              || strlen($data) == 0) {
 169          $this->SetDataAccessError("it was not possible to read line from the HTTP server");
 170          return(0);
 171          }
 172          $line.=$data;
 173          $length = strlen($line);
 174          if ($length
 175              && !strcmp(substr($line, $length - 1, 1), "\n")) {
 176          $length-= ( ($length >= 2 && !strcmp(substr($line, $length - 2, 1), "\r")) ? 2 : 1);
 177          $line = substr($line, 0, $length);
 178          if ($this->debug)
 179              $this->OutputDebug("S $line");
 180          return($line);
 181          }
 182      }
 183      }
 184  
 185      Function PutLine($line) {
 186      if ($this->debug)
 187          $this->OutputDebug("C $line");
 188      if (!fputs($this->connection, $line . "\r\n")) {
 189          $this->SetDataAccessError("it was not possible to send a line to the HTTP server");
 190          return(0);
 191      }
 192      return(1);
 193      }
 194  
 195      Function PutData($data) {
 196      if (strlen($data)) {
 197          if ($this->debug)
 198          $this->OutputDebug('C ' . $data);
 199          if (!fputs($this->connection, $data)) {
 200          $this->SetDataAccessError("it was not possible to send data to the HTTP server");
 201          return(0);
 202          }
 203      }
 204      return(1);
 205      }
 206  
 207      Function FlushData() {
 208      if (!fflush($this->connection)) {
 209          $this->SetDataAccessError("it was not possible to send data to the HTTP server");
 210          return(0);
 211      }
 212      return(1);
 213      }
 214  
 215      Function ReadChunkSize() {
 216      if ($this->remaining_chunk == 0) {
 217          $debug = $this->debug;
 218          if (!$this->debug_response_body)
 219          $this->debug = 0;
 220          $line = $this->GetLine();
 221          $this->debug = $debug;
 222          if (GetType($line) != "string")
 223          return($this->SetError("4 could not read chunk start: " . $this->error));
 224          $this->remaining_chunk = hexdec($line);
 225      }
 226      return("");
 227      }
 228  
 229      Function ReadBytes($length) {
 230      if ($this->use_curl) {
 231          $bytes = substr($this->response, $this->read_response, min($length, strlen($this->response) - $this->read_response));
 232          $this->read_response+=strlen($bytes);
 233          if ($this->debug
 234              && $this->debug_response_body
 235              && strlen($bytes))
 236          $this->OutputDebug("S " . $bytes);
 237      }
 238      else {
 239          if ($this->chunked) {
 240          for ($bytes = "", $remaining = $length; $remaining;) {
 241              if (strlen($this->ReadChunkSize()))
 242              return("");
 243              if ($this->remaining_chunk == 0) {
 244              $this->last_chunk_read = 1;
 245              break;
 246              }
 247              $ask = min($this->remaining_chunk, $remaining);
 248              $chunk = @fread($this->connection, $ask);
 249              $read = strlen($chunk);
 250              if ($read == 0) {
 251              $this->SetDataAccessError("it was not possible to read data chunk from the HTTP server");
 252              return("");
 253              }
 254              if ($this->debug
 255                  && $this->debug_response_body)
 256              $this->OutputDebug("S " . $chunk);
 257              $bytes.=$chunk;
 258              $this->remaining_chunk-=$read;
 259              $remaining-=$read;
 260              if ($this->remaining_chunk == 0) {
 261              if (feof($this->connection))
 262                  return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server"));
 263              $data = @fread($this->connection, 2);
 264              if (strcmp($data, "\r\n")) {
 265                  $this->SetDataAccessError("it was not possible to read end of data chunk from the HTTP server");
 266                  return("");
 267              }
 268              }
 269          }
 270          } else {
 271          $bytes = @fread($this->connection, $length);
 272          if (strlen($bytes)) {
 273              if ($this->debug
 274                  && $this->debug_response_body)
 275              $this->OutputDebug("S " . $bytes);
 276          }
 277          else
 278              $this->SetDataAccessError("it was not possible to read data from the HTTP server", $this->connection_close);
 279          }
 280      }
 281      return($bytes);
 282      }
 283  
 284      Function EndOfInput() {
 285      if ($this->use_curl)
 286          return($this->read_response >= strlen($this->response));
 287      if ($this->chunked)
 288          return($this->last_chunk_read);
 289      return(feof($this->connection));
 290      }
 291  
 292      Function Resolve($domain, &$ip, $server_type) {
 293      if (preg_match("/^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" .
 294              "(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$/", $domain))
 295          $ip = $domain;
 296      else {
 297          if ($this->debug)
 298          $this->OutputDebug('Resolving ' . $server_type . ' server domain "' . $domain . '"...');
 299          if (!strcmp($ip = @gethostbyname($domain), $domain))
 300          $ip = "";
 301      }
 302      if (strlen($ip) == 0
 303          || (strlen($this->exclude_address)
 304          && !strcmp(@gethostbyname($this->exclude_address), $ip)))
 305          return($this->SetError("could not resolve the host domain \"" . $domain . "\""));
 306      return('');
 307      }
 308  
 309      Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP') {
 310      $domain = $host_name;
 311      $port = $host_port;
 312      if (strlen($error = $this->Resolve($domain, $ip, $server_type)))
 313          return($error);
 314      if (strlen($this->socks_host_name)) {
 315          switch ($this->socks_version) {
 316          case '4':
 317              $version = 4;
 318              break;
 319          case '5':
 320              $version = 5;
 321              break;
 322          default:
 323              return('it was not specified a supported SOCKS protocol version');
 324              break;
 325          }
 326          $host_ip = $ip;
 327          $port = $this->socks_host_port;
 328          $host_server_type = $server_type;
 329          $server_type = 'SOCKS';
 330          if (strlen($error = $this->Resolve($this->socks_host_name, $ip, $server_type)))
 331          return($error);
 332      }
 333      if ($this->debug)
 334          $this->OutputDebug('Connecting to ' . $server_type . ' server IP ' . $ip . ' port ' . $port . '...');
 335      if ($ssl)
 336          $ip = "ssl://" . $ip;
 337      if (($this->connection = ($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno))) == 0) {
 338          switch ($errno) {
 339          case -3:
 340              return($this->SetError("-3 socket could not be created"));
 341          case -4:
 342              return($this->SetError("-4 dns lookup on hostname \"" . $host_name . "\" failed"));
 343          case -5:
 344              return($this->SetError("-5 connection refused or timed out"));
 345          case -6:
 346              return($this->SetError("-6 fdopen() call failed"));
 347          case -7:
 348              return($this->SetError("-7 setvbuf() call failed"));
 349          default:
 350              return($this->SetPHPError($errno . " could not connect to the host \"" . $host_name . "\"", $php_errormsg));
 351          }
 352      } else {
 353          if ($this->data_timeout
 354              && function_exists("socket_set_timeout"))
 355          socket_set_timeout($this->connection, $this->data_timeout, 0);
 356          if (strlen($this->socks_host_name)) {
 357          if ($this->debug)
 358              $this->OutputDebug('Connected to the SOCKS server ' . $this->socks_host_name);
 359          $send_error = 'it was not possible to send data to the SOCKS server';
 360          $receive_error = 'it was not possible to receive data from the SOCKS server';
 361          switch ($version) {
 362              case 4:
 363              $command = 1;
 364              if (!fputs($this->connection, chr($version) . chr($command) . pack('nN', $host_port, ip2long($host_ip)) . $this->user . Chr(0)))
 365                  $error = $this->SetDataAccessError($send_error);
 366              else {
 367                  $response = fgets($this->connection, 9);
 368                  if (strlen($response) != 8)
 369                  $error = $this->SetDataAccessError($receive_error);
 370                  else {
 371                  $socks_errors = array(
 372                      "\x5a" => '',
 373                      "\x5b" => 'request rejected',
 374                      "\x5c" => 'request failed because client is not running identd (or not reachable from the server)',
 375                      "\x5d" => 'request failed because client\'s identd could not confirm the user ID string in the request',
 376                  );
 377                  $error_code = $response[1];
 378                  $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
 379                  if (strlen($error))
 380                      $error = 'SOCKS error: ' . $error;
 381                  }
 382              }
 383              break;
 384              case 5:
 385              if ($this->debug)
 386                  $this->OutputDebug('Negotiating the authentication method ...');
 387              $methods = 1;
 388              $method = 0;
 389              if (!fputs($this->connection, chr($version) . chr($methods) . chr($method)))
 390                  $error = $this->SetDataAccessError($send_error);
 391              else {
 392                  $response = fgets($this->connection, 3);
 393                  if (strlen($response) != 2)
 394                  $error = $this->SetDataAccessError($receive_error);
 395                  elseif (Ord($response[1]) != $method)
 396                  $error = 'the SOCKS server requires an authentication method that is not yet supported';
 397                  else {
 398                  if ($this->debug)
 399                      $this->OutputDebug('Connecting to ' . $host_server_type . ' server IP ' . $host_ip . ' port ' . $host_port . '...');
 400                  $command = 1;
 401                  $address_type = 1;
 402                  if (!fputs($this->connection, chr($version) . chr($command) . "\x00" . chr($address_type) . pack('Nn', ip2long($host_ip), $host_port)))
 403                      $error = $this->SetDataAccessError($send_error);
 404                  else {
 405                      $response = fgets($this->connection, 11);
 406                      if (strlen($response) != 10)
 407                      $error = $this->SetDataAccessError($receive_error);
 408                      else {
 409                      $socks_errors = array(
 410                          "\x00" => '',
 411                          "\x01" => 'general SOCKS server failure',
 412                          "\x02" => 'connection not allowed by ruleset',
 413                          "\x03" => 'Network unreachable',
 414                          "\x04" => 'Host unreachable',
 415                          "\x05" => 'Connection refused',
 416                          "\x06" => 'TTL expired',
 417                          "\x07" => 'Command not supported',
 418                          "\x08" => 'Address type not supported'
 419                      );
 420                      $error_code = $response[1];
 421                      $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
 422                      if (strlen($error))
 423                          $error = 'SOCKS error: ' . $error;
 424                      }
 425                  }
 426                  }
 427              }
 428              break;
 429              default:
 430              $error = 'support for SOCKS protocol version ' . $this->socks_version . ' is not yet implemented';
 431              break;
 432          }
 433          if (strlen($error)) {
 434              fclose($this->connection);
 435              return($error);
 436          }
 437          }
 438          if ($this->debug)
 439          $this->OutputDebug("Connected to $host_name");
 440          if (strlen($this->proxy_host_name)
 441              && !strcmp(strtolower($this->protocol), 'https')) {
 442          if (function_exists('stream_socket_enable_crypto')
 443              && in_array('ssl', stream_get_transports()))
 444              $this->state = "ConnectedToProxy";
 445          else {
 446              $this->OutputDebug("It is not possible to start SSL after connecting to the proxy server. If the proxy refuses to forward the SSL request, you may need to upgrade to PHP 5.1 or later with OpenSSL support enabled.");
 447              $this->state = "Connected";
 448          }
 449          }
 450          else
 451          $this->state = "Connected";
 452          return("");
 453      }
 454      }
 455  
 456      Function Disconnect() {
 457      if ($this->debug)
 458          $this->OutputDebug("Disconnected from " . $this->host_name);
 459      if ($this->use_curl) {
 460          curl_close($this->connection);
 461          $this->response = "";
 462      }
 463      else
 464          fclose($this->connection);
 465      $this->state = "Disconnected";
 466      return("");
 467      }
 468  
 469      /* Public methods */
 470  
 471      Function GetRequestArguments($url, &$arguments) {
 472      if (strlen($this->error))
 473          return($this->error);
 474      $arguments = array();
 475      $parameters = @parse_url($url);
 476  
 477      if (!$parameters)
 478          return($this->SetError("it was not specified a valid URL"));
 479      if (!IsSet($parameters["scheme"]))
 480          return($this->SetError("it was not specified the protocol type argument"));
 481      switch (strtolower($parameters["scheme"])) {
 482          case "http":
 483          case "https":
 484          $arguments["Protocol"] = $parameters["scheme"];
 485          break;
 486          default:
 487          return($parameters["scheme"] . " connection scheme is not yet supported");
 488      }
 489      if (!IsSet($parameters["host"]))
 490          return($this->SetError("it was not specified the connection host argument"));
 491      $arguments["HostName"] = $parameters["host"];
 492      $arguments["Headers"] = array("Host" => $parameters["host"] . (IsSet($parameters["port"]) ? ":" . $parameters["port"] : ""));
 493      if (IsSet($parameters["user"])) {
 494          $arguments["AuthUser"] = UrlDecode($parameters["user"]);
 495          if (!IsSet($parameters["pass"]))
 496          $arguments["AuthPassword"] = "";
 497      }
 498      if (IsSet($parameters["pass"])) {
 499          if (!IsSet($parameters["user"]))
 500          $arguments["AuthUser"] = "";
 501          $arguments["AuthPassword"] = UrlDecode($parameters["pass"]);
 502      }
 503      if (IsSet($parameters["port"])) {
 504          if (strcmp($parameters["port"], strval(intval($parameters["port"]))))
 505          return($this->SetError("it was not specified a valid connection host argument"));
 506          $arguments["HostPort"] = intval($parameters["port"]);
 507      }
 508      else
 509          $arguments["HostPort"] = 0;
 510      $arguments["RequestURI"] = (IsSet($parameters["path"]) ? $parameters["path"] : "/") . (IsSet($parameters["query"]) ? "?" . $parameters["query"] : "");
 511      if (strlen($this->user_agent))
 512          $arguments["Headers"]["User-Agent"] = $this->user_agent;
 513      return("");
 514      }
 515  
 516      Function Open($arguments) {
 517      if (strlen($this->error))
 518          return($this->error);
 519      if ($this->state != "Disconnected")
 520          return("1 already connected");
 521      if (IsSet($arguments["HostName"]))
 522          $this->host_name = $arguments["HostName"];
 523      if (IsSet($arguments["HostPort"]))
 524          $this->host_port = $arguments["HostPort"];
 525      if (IsSet($arguments["ProxyHostName"]))
 526          $this->proxy_host_name = $arguments["ProxyHostName"];
 527      if (IsSet($arguments["ProxyHostPort"]))
 528          $this->proxy_host_port = $arguments["ProxyHostPort"];
 529      if (IsSet($arguments["SOCKSHostName"]))
 530          $this->socks_host_name = $arguments["SOCKSHostName"];
 531      if (IsSet($arguments["SOCKSHostPort"]))
 532          $this->socks_host_port = $arguments["SOCKSHostPort"];
 533      if (IsSet($arguments["SOCKSVersion"]))
 534          $this->socks_version = $arguments["SOCKSVersion"];
 535      if (IsSet($arguments["Protocol"]))
 536          $this->protocol = $arguments["Protocol"];
 537      switch (strtolower($this->protocol)) {
 538          case "http":
 539          $default_port = 80;
 540          break;
 541          case "https":
 542          $default_port = 443;
 543          break;
 544          default:
 545          return($this->SetError("2 it was not specified a valid connection protocol"));
 546      }
 547      if (strlen($this->proxy_host_name) == 0) {
 548          if (strlen($this->host_name) == 0)
 549          return($this->SetError("2 it was not specified a valid hostname"));
 550          $host_name = $this->host_name;
 551          $host_port = ($this->host_port ? $this->host_port : $default_port);
 552          $server_type = 'HTTP';
 553      }
 554      else {
 555          $host_name = $this->proxy_host_name;
 556          $host_port = $this->proxy_host_port;
 557          $server_type = 'HTTP proxy';
 558      }
 559      $ssl = (strtolower($this->protocol) == "https" && strlen($this->proxy_host_name) == 0);
 560      if ($ssl
 561          && strlen($this->socks_host_name))
 562          return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported'));
 563      $this->use_curl = ($ssl && $this->prefer_curl && function_exists("curl_init"));
 564      if ($this->debug)
 565          $this->OutputDebug("Connecting to " . $this->host_name);
 566      if ($this->use_curl) {
 567          $error = (($this->connection = curl_init($this->protocol . "://" . $this->host_name . ($host_port == $default_port ? "" : ":" . strval($host_port)) . "/")) ? "" : "Could not initialize a CURL session");
 568          if (strlen($error) == 0) {
 569          if (IsSet($arguments["SSLCertificateFile"]))
 570              curl_setopt($this->connection, CURLOPT_SSLCERT, $arguments["SSLCertificateFile"]);
 571          if (IsSet($arguments["SSLCertificatePassword"]))
 572              curl_setopt($this->connection, CURLOPT_SSLCERTPASSWD, $arguments["SSLCertificatePassword"]);
 573          if (IsSet($arguments["SSLKeyFile"]))
 574              curl_setopt($this->connection, CURLOPT_SSLKEY, $arguments["SSLKeyFile"]);
 575          if (IsSet($arguments["SSLKeyPassword"]))
 576              curl_setopt($this->connection, CURLOPT_SSLKEYPASSWD, $arguments["SSLKeyPassword"]);
 577          }
 578          $this->state = "Connected";
 579      }
 580      else {
 581          $error = "";
 582          if (strlen($this->proxy_host_name)
 583              && (IsSet($arguments["SSLCertificateFile"])
 584              || IsSet($arguments["SSLCertificateFile"])))
 585          $error = "establishing SSL connections using certificates or private keys via non-SSL proxies is not supported";
 586          else {
 587          if ($ssl) {
 588              if (IsSet($arguments["SSLCertificateFile"]))
 589              $error = "establishing SSL connections using certificates is only supported when the cURL extension is enabled";
 590              elseif (IsSet($arguments["SSLKeyFile"]))
 591              $error = "establishing SSL connections using a private key is only supported when the cURL extension is enabled";
 592              else {
 593              $version = explode(".", function_exists("phpversion") ? phpversion() : "3.0.7");
 594              $php_version = intval($version[0]) * 1000000 + intval($version[1]) * 1000 + intval($version[2]);
 595              if ($php_version < 4003000)
 596                  $error = "establishing SSL connections requires at least PHP version 4.3.0 or having the cURL extension enabled";
 597              elseif (!function_exists("extension_loaded")
 598                  || !extension_loaded("openssl"))
 599                  $error = "establishing SSL connections requires the OpenSSL extension enabled";
 600              }
 601          }
 602          if (strlen($error) == 0)
 603              $error = $this->Connect($host_name, $host_port, $ssl, $server_type);
 604          }
 605      }
 606      if (strlen($error))
 607          return($this->SetError($error));
 608      $this->session = md5(uniqid(""));
 609      return("");
 610      }
 611  
 612      Function Close() {
 613      if ($this->state == "Disconnected")
 614          return("1 already disconnected");
 615      $error = $this->Disconnect();
 616      if (strlen($error) == 0)
 617          $this->state = "Disconnected";
 618      return($error);
 619      }
 620  
 621      Function PickCookies(&$cookies, $secure) {
 622      if (IsSet($this->cookies[$secure])) {
 623          $now = gmdate("Y-m-d H-i-s");
 624          for ($domain = 0, Reset($this->cookies[$secure]); $domain < count($this->cookies[$secure]); Next($this->cookies[$secure]), $domain++) {
 625          $domain_pattern = Key($this->cookies[$secure]);
 626          $match = strlen($this->request_host) - strlen($domain_pattern);
 627          if ($match >= 0
 628              && !strcmp($domain_pattern, substr($this->request_host, $match))
 629              && ($match == 0
 630              || $domain_pattern[0] == "."
 631              || $this->request_host[$match - 1] == ".")) {
 632              for (Reset($this->cookies[$secure][$domain_pattern]), $path_part = 0; $path_part < count($this->cookies[$secure][$domain_pattern]); Next($this->cookies[$secure][$domain_pattern]), $path_part++) {
 633              $path = Key($this->cookies[$secure][$domain_pattern]);
 634              if (strlen($this->request_uri) >= strlen($path)
 635                  && substr($this->request_uri, 0, strlen($path)) == $path) {
 636                  for (Reset($this->cookies[$secure][$domain_pattern][$path]), $cookie = 0; $cookie < count($this->cookies[$secure][$domain_pattern][$path]); Next($this->cookies[$secure][$domain_pattern][$path]), $cookie++) {
 637                  $cookie_name = Key($this->cookies[$secure][$domain_pattern][$path]);
 638                  $expires = $this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
 639                  if ($expires == ""
 640                      || strcmp($now, $expires) < 0)
 641                      $cookies[$cookie_name] = $this->cookies[$secure][$domain_pattern][$path][$cookie_name];
 642                  }
 643              }
 644              }
 645          }
 646          }
 647      }
 648      }
 649  
 650      Function GetFileDefinition($file, &$definition) {
 651      $name = "";
 652      if (IsSet($file["FileName"]))
 653          $name = basename($file["FileName"]);
 654      if (IsSet($file["Name"]))
 655          $name = $file["Name"];
 656      if (strlen($name) == 0)
 657          return("it was not specified the file part name");
 658      if (IsSet($file["Content-Type"])) {
 659          $content_type = $file["Content-Type"];
 660          $type = $this->Tokenize(strtolower($content_type), "/");
 661          $sub_type = $this->Tokenize("");
 662          switch ($type) {
 663          case "text":
 664          case "image":
 665          case "audio":
 666          case "video":
 667          case "application":
 668          case "message":
 669              break;
 670          case "automatic":
 671              switch ($sub_type) {
 672              case "name":
 673                  switch (GetType($dot = strrpos($name, ".")) == "integer" ? strtolower(substr($name, $dot)) : "") {
 674                  case ".xls":
 675                      $content_type = "application/excel";
 676                      break;
 677                  case ".hqx":
 678                      $content_type = "application/macbinhex40";
 679                      break;
 680                  case ".doc":
 681                  case ".dot":
 682                  case ".wrd":
 683                      $content_type = "application/msword";
 684                      break;
 685                  case ".pdf":
 686                      $content_type = "application/pdf";
 687                      break;
 688                  case ".pgp":
 689                      $content_type = "application/pgp";
 690                      break;
 691                  case ".ps":
 692                  case ".eps":
 693                  case ".ai":
 694                      $content_type = "application/postscript";
 695                      break;
 696                  case ".ppt":
 697                      $content_type = "application/powerpoint";
 698                      break;
 699                  case ".rtf":
 700                      $content_type = "application/rtf";
 701                      break;
 702                  case ".tgz":
 703                  case ".gtar":
 704                      $content_type = "application/x-gtar";
 705                      break;
 706                  case ".gz":
 707                      $content_type = "application/x-gzip";
 708                      break;
 709                  case ".php":
 710                  case ".php3":
 711                      $content_type = "application/x-httpd-php";
 712                      break;
 713                  case ".js":
 714                      $content_type = "application/x-javascript";
 715                      break;
 716                  case ".ppd":
 717                  case ".psd":
 718                      $content_type = "application/x-photoshop";
 719                      break;
 720                  case ".swf":
 721                  case ".swc":
 722                  case ".rf":
 723                      $content_type = "application/x-shockwave-flash";
 724                      break;
 725                  case ".tar":
 726                      $content_type = "application/x-tar";
 727                      break;
 728                  case ".zip":
 729                      $content_type = "application/zip";
 730                      break;
 731                  case ".mid":
 732                  case ".midi":
 733                  case ".kar":
 734                      $content_type = "audio/midi";
 735                      break;
 736                  case ".mp2":
 737                  case ".mp3":
 738                  case ".mpga":
 739                      $content_type = "audio/mpeg";
 740                      break;
 741                  case ".ra":
 742                      $content_type = "audio/x-realaudio";
 743                      break;
 744                  case ".wav":
 745                      $content_type = "audio/wav";
 746                      break;
 747                  case ".bmp":
 748                      $content_type = "image/bitmap";
 749                      break;
 750                  case ".gif":
 751                      $content_type = "image/gif";
 752                      break;
 753                  case ".iff":
 754                      $content_type = "image/iff";
 755                      break;
 756                  case ".jb2":
 757                      $content_type = "image/jb2";
 758                      break;
 759                  case ".jpg":
 760                  case ".jpe":
 761                  case ".jpeg":
 762                      $content_type = "image/jpeg";
 763                      break;
 764                  case ".jpx":
 765                      $content_type = "image/jpx";
 766                      break;
 767                  case ".png":
 768                      $content_type = "image/png";
 769                      break;
 770                  case ".tif":
 771                  case ".tiff":
 772                      $content_type = "image/tiff";
 773                      break;
 774                  case ".wbmp":
 775                      $content_type = "image/vnd.wap.wbmp";
 776                      break;
 777                  case ".xbm":
 778                      $content_type = "image/xbm";
 779                      break;
 780                  case ".css":
 781                      $content_type = "text/css";
 782                      break;
 783                  case ".txt":
 784                      $content_type = "text/plain";
 785                      break;
 786                  case ".htm":
 787                  case ".html":
 788                      $content_type = "text/html";
 789                      break;
 790                  case ".xml":
 791                      $content_type = "text/xml";
 792                      break;
 793                  case ".mpg":
 794                  case ".mpe":
 795                  case ".mpeg":
 796                      $content_type = "video/mpeg";
 797                      break;
 798                  case ".qt":
 799                  case ".mov":
 800                      $content_type = "video/quicktime";
 801                      break;
 802                  case ".avi":
 803                      $content_type = "video/x-ms-video";
 804                      break;
 805                  case ".eml":
 806                      $content_type = "message/rfc822";
 807                      break;
 808                  default:
 809                      $content_type = "application/octet-stream";
 810                      break;
 811                  }
 812                  break;
 813              default:
 814                  return($content_type . " is not a supported automatic content type detection method");
 815              }
 816              break;
 817          default:
 818              return($content_type . " is not a supported file content type");
 819          }
 820      }
 821      else
 822          $content_type="application/octet-stream";
 823      $definition = array(
 824          "Content-Type" => $content_type,
 825          "NAME" => $name
 826      );
 827      if (IsSet($file["FileName"])) {
 828          if (GetType($length = @filesize($file["FileName"])) != "integer") {
 829          $error = "it was not possible to determine the length of the file " . $file["FileName"];
 830          if (IsSet($php_errormsg)
 831              && strlen($php_errormsg))
 832              $error.=": " . $php_errormsg;
 833          if (!file_exists($file["FileName"]))
 834              $error = "it was not possible to access the file " . $file["FileName"];
 835          return($error);
 836          }
 837          $definition["FILENAME"] = $file["FileName"];
 838          $definition["Content-Length"] = $length;
 839      }
 840      elseif (IsSet($file["Data"]))
 841          $definition["Content-Length"] = strlen($definition["DATA"] = $file["Data"]);
 842      else
 843          return("it was not specified a valid file name");
 844      return("");
 845      }
 846  
 847      Function ConnectFromProxy($arguments, &$headers) {
 848      if (!$this->PutLine('CONNECT ' . $this->host_name . ':' . ($this->host_port ? $this->host_port : 443) . ' HTTP/1.0')
 849          || (strlen($this->user_agent)
 850          && !$this->PutLine('User-Agent: ' . $this->user_agent))
 851          || (IsSet($arguments['Headers']['Proxy-Authorization'])
 852          && !$this->PutLine('Proxy-Authorization: ' . $arguments['Headers']['Proxy-Authorization']))
 853          || !$this->PutLine('')) {
 854          $this->Disconnect();
 855          return($this->error);
 856      }
 857      $this->state = "ConnectSent";
 858      if (strlen($error = $this->ReadReplyHeadersResponse($headers)))
 859          return($error);
 860      $proxy_authorization = "";
 861      while (!strcmp($this->response_status, "100")) {
 862          $this->state = "ConnectSent";
 863          if (strlen($error = $this->ReadReplyHeadersResponse($headers)))
 864          return($error);
 865      }
 866      switch ($this->response_status) {
 867          case "200":
 868          if (!@stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT)) {
 869              $this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg);
 870              $this->Disconnect();
 871              return($this->error);
 872          }
 873          $this->state = "Connected";
 874          break;
 875          case "407":
 876          if (strlen($error = $this->Authenticate($headers, -1, $proxy_authorization, $this->proxy_request_user, $this->proxy_request_password, $this->proxy_request_realm, $this->proxy_request_workstation)))
 877              return($error);
 878          break;
 879          default:
 880          return($this->SetError("unable to send request via proxy"));
 881      }
 882      return("");
 883      }
 884  
 885      Function SendRequest($arguments) {
 886      if (strlen($this->error))
 887          return($this->error);
 888      if (IsSet($arguments["ProxyUser"]))
 889          $this->proxy_request_user = $arguments["ProxyUser"];
 890      elseif (IsSet($this->proxy_user))
 891          $this->proxy_request_user = $this->proxy_user;
 892      if (IsSet($arguments["ProxyPassword"]))
 893          $this->proxy_request_password = $arguments["ProxyPassword"];
 894      elseif (IsSet($this->proxy_password))
 895          $this->proxy_request_password = $this->proxy_password;
 896      if (IsSet($arguments["ProxyRealm"]))
 897          $this->proxy_request_realm = $arguments["ProxyRealm"];
 898      elseif (IsSet($this->proxy_realm))
 899          $this->proxy_request_realm = $this->proxy_realm;
 900      if (IsSet($arguments["ProxyWorkstation"]))
 901          $this->proxy_request_workstation = $arguments["ProxyWorkstation"];
 902      elseif (IsSet($this->proxy_workstation))
 903          $this->proxy_request_workstation = $this->proxy_workstation;
 904      switch ($this->state) {
 905          case "Disconnected":
 906          return($this->SetError("1 connection was not yet established"));
 907          case "Connected":
 908          $connect = 0;
 909          break;
 910          case "ConnectedToProxy":
 911          if (strlen($error = $this->ConnectFromProxy($arguments, $headers)))
 912              return($error);
 913          $connect = 1;
 914          break;
 915          default:
 916          return($this->SetError("2 can not send request in the current connection state"));
 917      }
 918      if (IsSet($arguments["RequestMethod"]))
 919          $this->request_method = $arguments["RequestMethod"];
 920      if (IsSet($arguments["User-Agent"]))
 921          $this->user_agent = $arguments["User-Agent"];
 922      if (!IsSet($arguments["Headers"]["User-Agent"])
 923          && strlen($this->user_agent))
 924          $arguments["Headers"]["User-Agent"] = $this->user_agent;
 925      if (strlen($this->request_method) == 0)
 926          return($this->SetError("3 it was not specified a valid request method"));
 927      if (IsSet($arguments["RequestURI"]))
 928          $this->request_uri = $arguments["RequestURI"];
 929      if (strlen($this->request_uri) == 0
 930          || substr($this->request_uri, 0, 1) != "/")
 931          return($this->SetError("4 it was not specified a valid request URI"));
 932      $this->request_arguments = $arguments;
 933      $this->request_headers = (IsSet($arguments["Headers"]) ? $arguments["Headers"] : array());
 934      $body_length = 0;
 935      $this->request_body = "";
 936      $get_body = 1;
 937      if ($this->request_method == "POST"
 938          || $this->request_method == "PUT") {
 939          if (IsSet($arguments['StreamRequest'])) {
 940          $get_body = 0;
 941          $this->request_headers["Transfer-Encoding"] = "chunked";
 942          } elseif (IsSet($arguments["PostFiles"])
 943              || ($this->force_multipart_form_post
 944              && IsSet($arguments["PostValues"]))) {
 945          $boundary = "--" . md5(uniqid(time()));
 946          $this->request_headers["Content-Type"] = "multipart/form-data; boundary=" . $boundary . (IsSet($arguments["CharSet"]) ? "; charset=" . $arguments["CharSet"] : "");
 947          $post_parts = array();
 948          if (IsSet($arguments["PostValues"])) {
 949              $values = $arguments["PostValues"];
 950              if (GetType($values) != "array")
 951              return($this->SetError("5 it was not specified a valid POST method values array"));
 952              for (Reset($values), $value = 0; $value < count($values); Next($values), $value++) {
 953              $input = Key($values);
 954              $headers = "--" . $boundary . "\r\nContent-Disposition: form-data; name=\"" . $input . "\"\r\n\r\n";
 955              $data = $values[$input];
 956              $post_parts[] = array("HEADERS" => $headers, "DATA" => $data);
 957              $body_length+=strlen($headers) + strlen($data) + strlen("\r\n");
 958              }
 959          }
 960          $body_length+=strlen("--" . $boundary . "--\r\n");
 961          $files = (IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());
 962          Reset($files);
 963          $end = (GetType($input = Key($files)) != "string");
 964          for (; !$end;) {
 965              if (strlen($error = $this->GetFileDefinition($files[$input], $definition)))
 966              return("3 " . $error);
 967              $headers = "--" . $boundary . "\r\nContent-Disposition: form-data; name=\"" . $input . "\"; filename=\"" . $definition["NAME"] . "\"\r\nContent-Type: " . $definition["Content-Type"] . "\r\n\r\n";
 968              $part = count($post_parts);
 969              $post_parts[$part] = array("HEADERS" => $headers);
 970              if (IsSet($definition["FILENAME"])) {
 971              $post_parts[$part]["FILENAME"] = $definition["FILENAME"];
 972              $data = "";
 973              }
 974              else
 975              $data=$definition["DATA"];
 976              $post_parts[$part]["DATA"] = $data;
 977              $body_length+=strlen($headers) + $definition["Content-Length"] + strlen("\r\n");
 978              Next($files);
 979              $end = (GetType($input = Key($files)) != "string");
 980          }
 981          $get_body = 0;
 982          }
 983          elseif (IsSet($arguments["PostValues"])) {
 984          $values = $arguments["PostValues"];
 985          if (GetType($values) != "array")
 986              return($this->SetError("5 it was not specified a valid POST method values array"));
 987          for (Reset($values), $value = 0; $value < count($values); Next($values), $value++) {
 988              $k = Key($values);
 989              if (GetType($values[$k]) == "array") {
 990              for ($v = 0; $v < count($values[$k]); $v++) {
 991                  if ($value + $v > 0)
 992                  $this->request_body.="&";
 993                  $this->request_body.=UrlEncode($k) . "=" . UrlEncode($values[$k][$v]);
 994              }
 995              }
 996              else {
 997              if ($value > 0)
 998                  $this->request_body.="&";
 999              $this->request_body.=UrlEncode($k) . "=" . UrlEncode($values[$k]);
1000              }
1001          }
1002          $this->request_headers["Content-Type"] = "application/x-www-form-urlencoded" . (IsSet($arguments["CharSet"]) ? "; charset=" . $arguments["CharSet"] : "");
1003          $get_body = 0;
1004          }
1005      }
1006      if ($get_body
1007          && (IsSet($arguments["Body"])
1008          || IsSet($arguments["BodyStream"]))) {
1009          if (IsSet($arguments["Body"]))
1010          $this->request_body = $arguments["Body"];
1011          else {
1012          $stream = $arguments["BodyStream"];
1013          $this->request_body = "";
1014          for ($part = 0; $part < count($stream); $part++) {
1015              if (IsSet($stream[$part]["Data"]))
1016              $this->request_body.=$stream[$part]["Data"];
1017              elseif (IsSet($stream[$part]["File"])) {
1018              if (!($file = @fopen($stream[$part]["File"], "rb")))
1019                  return($this->SetPHPError("could not open upload file " . $stream[$part]["File"], $php_errormsg));
1020              while (!feof($file)) {
1021                  if (GetType($block = @fread($file, $this->file_buffer_length)) != "string") {
1022                  $error = $this->SetPHPError("could not read body stream file " . $stream[$part]["File"], $php_errormsg);
1023                  fclose($file);
1024                  return($error);
1025                  }
1026                  $this->request_body.=$block;
1027              }
1028              fclose($file);
1029              }
1030              else
1031              return("5 it was not specified a valid file or data body stream element at position " . $part);
1032          }
1033          }
1034          if (!IsSet($this->request_headers["Content-Type"]))
1035          $this->request_headers["Content-Type"] = "application/octet-stream" . (IsSet($arguments["CharSet"]) ? "; charset=" . $arguments["CharSet"] : "");
1036      }
1037      if (IsSet($arguments["AuthUser"]))
1038          $this->request_user = $arguments["AuthUser"];
1039      elseif (IsSet($this->user))
1040          $this->request_user = $this->user;
1041      if (IsSet($arguments["AuthPassword"]))
1042          $this->request_password = $arguments["AuthPassword"];
1043      elseif (IsSet($this->password))
1044          $this->request_password = $this->password;
1045      if (IsSet($arguments["AuthRealm"]))
1046          $this->request_realm = $arguments["AuthRealm"];
1047      elseif (IsSet($this->realm))
1048          $this->request_realm = $this->realm;
1049      if (IsSet($arguments["AuthWorkstation"]))
1050          $this->request_workstation = $arguments["AuthWorkstation"];
1051      elseif (IsSet($this->workstation))
1052          $this->request_workstation = $this->workstation;
1053      if (strlen($this->proxy_host_name) == 0
1054          || $connect)
1055          $request_uri = $this->request_uri;
1056      else {
1057          switch (strtolower($this->protocol)) {
1058          case "http":
1059              $default_port = 80;
1060              break;
1061          case "https":
1062              $default_port = 443;
1063              break;
1064          }
1065          $request_uri = strtolower($this->protocol) . "://" . $this->host_name . (($this->host_port == 0 || $this->host_port == $default_port) ? "" : ":" . $this->host_port) . $this->request_uri;
1066      }
1067      if ($this->use_curl) {
1068          $version = (GetType($v = curl_version()) == "array" ? (IsSet($v["version"]) ? $v["version"] : "0.0.0") : (ereg("^libcurl/([0-9]+\\.[0-9]+\\.[0-9]+)", $v, $m) ? $m[1] : "0.0.0"));
1069          $curl_version = 100000 * intval($this->Tokenize($version, ".")) + 1000 * intval($this->Tokenize(".")) + intval($this->Tokenize(""));
1070          $protocol_version = ($curl_version < 713002 ? "1.0" : $this->protocol_version);
1071      }
1072      else
1073          $protocol_version=$this->protocol_version;
1074      $this->request = $this->request_method . " " . $request_uri . " HTTP/" . $protocol_version;
1075      if ($body_length
1076          || ($body_length = strlen($this->request_body)))
1077          $this->request_headers["Content-Length"] = $body_length;
1078      for ($headers = array(), $host_set = 0, Reset($this->request_headers), $header = 0; $header < count($this->request_headers); Next($this->request_headers), $header++) {
1079          $header_name = Key($this->request_headers);
1080          $header_value = $this->request_headers[$header_name];
1081          if (GetType($header_value) == "array") {
1082          for (Reset($header_value), $value = 0; $value < count($header_value); Next($header_value), $value++)
1083              $headers[] = $header_name . ": " . $header_value[Key($header_value)];
1084          }
1085          else
1086          $headers[] = $header_name . ": " . $header_value;
1087          if (strtolower(Key($this->request_headers)) == "host") {
1088          $this->request_host = strtolower($header_value);
1089          $host_set = 1;
1090          }
1091      }
1092      if (!$host_set) {
1093          $headers[] = "Host: " . $this->host_name;
1094          $this->request_host = strtolower($this->host_name);
1095      }
1096      if (count($this->cookies)) {
1097          $cookies = array();
1098          $this->PickCookies($cookies, 0);
1099          if (strtolower($this->protocol) == "https")
1100          $this->PickCookies($cookies, 1);
1101          if (count($cookies)) {
1102          $h = count($headers);
1103          $headers[$h] = "Cookie:";
1104          for (Reset($cookies), $cookie = 0; $cookie < count($cookies); Next($cookies), $cookie++) {
1105              $cookie_name = Key($cookies);
1106              $headers[$h].=" " . $cookie_name . "=" . $cookies[$cookie_name]["value"] . ";";
1107          }
1108          }
1109      }
1110      $next_state = "RequestSent";
1111      if ($this->use_curl) {
1112          if (IsSet($arguments['StreamRequest']))
1113          return($this->SetError("Streaming request data is not supported when using Curl"));
1114          if ($body_length
1115              && strlen($this->request_body) == 0) {
1116          for ($request_body = "", $success = 1, $part = 0; $part < count($post_parts); $part++) {
1117              $request_body.=$post_parts[$part]["HEADERS"] . $post_parts[$part]["DATA"];
1118              if (IsSet($post_parts[$part]["FILENAME"])) {
1119              if (!($file = @fopen($post_parts[$part]["FILENAME"], "rb"))) {
1120                  $this->SetPHPError("could not open upload file " . $post_parts[$part]["FILENAME"], $php_errormsg);
1121                  $success = 0;
1122                  break;
1123              }
1124              while (!feof($file)) {
1125                  if (GetType($block = @fread($file, $this->file_buffer_length)) != "string") {
1126                  $this->SetPHPError("could not read upload file", $php_errormsg);
1127                  $success = 0;
1128                  break;
1129                  }
1130                  $request_body.=$block;
1131              }
1132              fclose($file);
1133              if (!$success)
1134                  break;
1135              }
1136              $request_body.="\r\n";
1137          }
1138          $request_body.="--" . $boundary . "--\r\n";
1139          }
1140          else
1141          $request_body=$this->request_body;
1142          curl_setopt($this->connection, CURLOPT_HEADER, 1);
1143          curl_setopt($this->connection, CURLOPT_RETURNTRANSFER, 1);
1144          if ($this->timeout)
1145          curl_setopt($this->connection, CURLOPT_TIMEOUT, $this->timeout);
1146          curl_setopt($this->connection, CURLOPT_SSL_VERIFYPEER, 0);
1147          curl_setopt($this->connection, CURLOPT_SSL_VERIFYHOST, 0);
1148          $request = $this->request . "\r\n" . implode("\r\n", $headers) . "\r\n\r\n" . $request_body;
1149          curl_setopt($this->connection, CURLOPT_CUSTOMREQUEST, $request);
1150          if ($this->debug)
1151          $this->OutputDebug("C " . $request);
1152          if (!($success = (strlen($this->response = curl_exec($this->connection)) != 0))) {
1153          $error = curl_error($this->connection);
1154          $this->SetError("Could not execute the request" . (strlen($error) ? ": " . $error : ""));
1155          }
1156      } else {
1157          if (($success = $this->PutLine($this->request))) {
1158          for ($header = 0; $header < count($headers); $header++) {
1159              if (!$success = $this->PutLine($headers[$header]))
1160              break;
1161          }
1162          if ($success
1163              && ($success = $this->PutLine(""))) {
1164              if (IsSet($arguments['StreamRequest']))
1165              $next_state = "SendingRequestBody";
1166              elseif ($body_length) {
1167              if (strlen($this->request_body))
1168                  $success = $this->PutData($this->request_body);
1169              else {
1170                  for ($part = 0; $part < count($post_parts); $part++) {
1171                  if (!($success = $this->PutData($post_parts[$part]["HEADERS"]))
1172                      || !($success = $this->PutData($post_parts[$part]["DATA"])))
1173                      break;
1174                  if (IsSet($post_parts[$part]["FILENAME"])) {
1175                      if (!($file = @fopen($post_parts[$part]["FILENAME"], "rb"))) {
1176                      $this->SetPHPError("could not open upload file " . $post_parts[$part]["FILENAME"], $php_errormsg);
1177                      $success = 0;
1178                      break;
1179                      }
1180                      while (!feof($file)) {
1181                      if (GetType($block = @fread($file, $this->file_buffer_length)) != "string") {
1182                          $this->SetPHPError("could not read upload file", $php_errormsg);
1183                          $success = 0;
1184                          break;
1185                      }
1186                      if (!($success = $this->PutData($block)))
1187                          break;
1188                      }
1189                      fclose($file);
1190                      if (!$success)
1191                      break;
1192                  }
1193                  if (!($success = $this->PutLine("")))
1194                      break;
1195                  }
1196                  if ($success)
1197                  $success = $this->PutLine("--" . $boundary . "--");
1198              }
1199              if ($success)
1200                  $sucess = $this->FlushData();
1201              }
1202          }
1203          }
1204      }
1205      if (!$success)
1206          return($this->SetError("5 could not send the HTTP request: " . $this->error));
1207      $this->state = $next_state;
1208      return("");
1209      }
1210  
1211      Function SetCookie($name, $value, $expires="", $path="/", $domain="", $secure=0, $verbatim=0) {
1212      if (strlen($this->error))
1213          return($this->error);
1214      if (strlen($name) == 0)
1215          return($this->SetError("it was not specified a valid cookie name"));
1216      if (strlen($path) == 0
1217          || strcmp($path[0], "/"))
1218          return($this->SetError($path . " is not a valid path for setting cookie " . $name));
1219      if ($domain == ""
1220          || !strpos($domain, ".", $domain[0] == "." ? 1 : 0))
1221          return($this->SetError($domain . " is not a valid domain for setting cookie " . $name));
1222      $domain = strtolower($domain);
1223      if (!strcmp($domain[0], "."))
1224          $domain = substr($domain, 1);
1225      if (!$verbatim) {
1226          $name = $this->CookieEncode($name, 1);
1227          $value = $this->CookieEncode($value, 0);
1228      }
1229      $secure = intval($secure);
1230      $this->cookies[$secure][$domain][$path][$name] = array(
1231          "name" => $name,
1232          "value" => $value,
1233          "domain" => $domain,
1234          "path" => $path,
1235          "expires" => $expires,
1236          "secure" => $secure
1237      );
1238      return("");
1239      }
1240  
1241      Function SendRequestBody($data, $end_of_data) {
1242      if (strlen($this->error))
1243          return($this->error);
1244      switch ($this->state) {
1245          case "Disconnected":
1246          return($this->SetError("1 connection was not yet established"));
1247          case "Connected":
1248          case "ConnectedToProxy":
1249          return($this->SetError("2 request was not sent"));
1250          case "SendingRequestBody":
1251          break;
1252          case "RequestSent":
1253          return($this->SetError("3 request body was already sent"));
1254          default:
1255          return($this->SetError("4 can not send the request body in the current connection state"));
1256      }
1257      $length = strlen($data);
1258      if ($length) {
1259          $size = dechex($length) . "\r\n";
1260          if (!$this->PutData($size)
1261              || !$this->PutData($data))
1262          return($this->error);
1263      }
1264      if ($end_of_data) {
1265          $size = "0\r\n";
1266          if (!$this->PutData($size))
1267          return($this->error);
1268          $this->state = "RequestSent";
1269      }
1270      return("");
1271      }
1272  
1273      Function ReadReplyHeadersResponse(&$headers) {
1274      $headers = array();
1275      if (strlen($this->error))
1276          return($this->error);
1277      switch ($this->state) {
1278          case "Disconnected":
1279          return($this->SetError("1 connection was not yet established"));
1280          case "Connected":
1281          return($this->SetError("2 request was not sent"));
1282          case "ConnectedToProxy":
1283          return($this->SetError("2 connection from the remote server from the proxy was not yet established"));
1284          case "SendingRequestBody":
1285          return($this->SetError("4 request body data was not completely sent"));
1286          case "ConnectSent":
1287          $connect = 1;
1288          break;
1289          case "RequestSent":
1290          $connect = 0;
1291          break;
1292          default:
1293          return($this->SetError("3 can not get request headers in the current connection state"));
1294      }
1295      $this->content_length = $this->read_length = $this->read_response = $this->remaining_chunk = 0;
1296      $this->content_length_set = $this->chunked = $this->last_chunk_read = $chunked = 0;
1297      $this->connection_close = 0;
1298      for ($this->response_status = "";;) {
1299          $line = $this->GetLine();
1300          if (GetType($line) != "string")
1301          return($this->SetError("4 could not read request reply: " . $this->error));
1302          if (strlen($this->response_status) == 0) {
1303          if (!preg_match('%^http/[0-9]+\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)$%i', $line, $matches))
1304              return($this->SetError("3 it was received an unexpected HTTP response status"));
1305          $this->response_status = $matches[1];
1306          $this->response_message = $matches[2];
1307          }
1308          if ($line == "") {
1309          if (strlen($this->response_status) == 0)
1310              return($this->SetError("3 it was not received HTTP response status"));
1311          $this->state = ($connect ? "GotConnectHeaders" : "GotReplyHeaders");
1312          break;
1313          }
1314          $header_name = strtolower($this->Tokenize($line, ":"));
1315          $header_value = Trim(Chop($this->Tokenize("\r\n")));
1316          if (IsSet($headers[$header_name])) {
1317          if (GetType($headers[$header_name]) == "string")
1318              $headers[$header_name] = array($headers[$header_name]);
1319          $headers[$header_name][] = $header_value;
1320          }
1321          else
1322          $headers[$header_name] = $header_value;
1323          if (!$connect) {
1324          switch ($header_name) {
1325              case "content-length":
1326              $this->content_length = intval($headers[$header_name]);
1327              $this->content_length_set = 1;
1328              break;
1329              case "transfer-encoding":
1330              $encoding = $this->Tokenize($header_value, "; \t");
1331              if (!$this->use_curl
1332                  && !strcmp($encoding, "chunked"))
1333                  $chunked = 1;
1334              break;
1335              case "set-cookie":
1336              if ($this->support_cookies) {
1337                  if (GetType($headers[$header_name]) == "array")
1338                  $cookie_headers = $headers[$header_name];
1339                  else
1340                  $cookie_headers=array($headers[$header_name]);
1341                  for ($cookie = 0; $cookie < count($cookie_headers); $cookie++) {
1342                  $cookie_name = trim($this->Tokenize($cookie_headers[$cookie], "="));
1343                  $cookie_value = $this->Tokenize(";");
1344                  $domain = $this->request_host;
1345                  $path = "/";
1346                  $expires = "";
1347                  $secure = 0;
1348                  while (($name = trim(UrlDecode($this->Tokenize("=")))) != "") {
1349                      $value = UrlDecode($this->Tokenize(";"));
1350                      switch ($name) {
1351                      case "domain":
1352                          $domain = $value;
1353                          break;
1354                      case "path":
1355                          $path = $value;
1356                          break;
1357                      case "expires":
1358                          if (ereg("^((Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday|Sun|Sunday), )?([0-9]{2})\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-([0-9]{2,4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}) GMT\$", $value, $matches)) {
1359                          $year = intval($matches[5]);
1360                          if ($year < 1900)
1361                              $year+= ( $year < 70 ? 2000 : 1900);
1362                          $expires = "$year-" . $this->months[$matches[4]] . "-" . $matches[3] . " " . $matches[6] . ":" . $matches[7] . ":" . $matches[8];
1363                          }
1364                          break;
1365                      case "secure":
1366                          $secure = 1;
1367                          break;
1368                      }
1369                  }
1370                  if (strlen($this->SetCookie($cookie_name, $cookie_value, $expires, $path, $domain, $secure, 1)))
1371                      $this->error = "";
1372                  }
1373              }
1374              break;
1375              case "connection":
1376              $this->connection_close = !strcmp(strtolower($header_value), "close");
1377              break;
1378          }
1379          }
1380      }
1381      $this->chunked = $chunked;
1382      if ($this->content_length_set)
1383          $this->connection_close = 0;
1384      return("");
1385      }
1386  
1387      Function Redirect(&$headers) {
1388      if ($this->follow_redirect) {
1389          if (!IsSet($headers["location"])
1390              || (GetType($headers["location"]) != "array"
1391              && strlen($location = $headers["location"]) == 0)
1392              || (GetType($headers["location"]) == "array"
1393              && strlen($location = $headers["location"][0]) == 0))
1394          return($this->SetError("3 it was received a redirect without location URL"));
1395          if (strcmp($location[0], "/")) {
1396          $location_arguments = parse_url($location);
1397          if (!IsSet($location_arguments["scheme"]))
1398              $location = ((GetType($end = strrpos($this->request_uri, "/")) == "integer" && $end > 1) ? substr($this->request_uri, 0, $end) : "") . "/" . $location;
1399          }
1400          if (!strcmp($location[0], "/"))
1401          $location = $this->protocol . "://" . $this->host_name . ($this->host_port ? ":" . $this->host_port : "") . $location;
1402          $error = $this->GetRequestArguments($location, $arguments);
1403          if (strlen($error))
1404          return($this->SetError("could not process redirect url: " . $error));
1405          $arguments["RequestMethod"] = "GET";
1406          if (strlen($error = $this->Close()) == 0
1407              && strlen($error = $this->Open($arguments)) == 0
1408              && strlen($error = $this->SendRequest($arguments)) == 0) {
1409          $this->redirection_level++;
1410          if ($this->redirection_level > $this->redirection_limit)
1411              $error = "it was exceeded the limit of request redirections";
1412          else
1413              $error=$this->ReadReplyHeaders($headers);
1414          $this->redirection_level--;
1415          }
1416          if (strlen($error))
1417          return($this->SetError($error));
1418      }
1419      return("");
1420      }
1421  
1422      Function Authenticate(&$headers, $proxy, &$proxy_authorization, &$user, &$password, &$realm, &$workstation) {
1423      if ($proxy) {
1424          $authenticate_header = "proxy-authenticate";
1425          $authorization_header = "Proxy-Authorization";
1426          $authenticate_status = "407";
1427          $authentication_mechanism = $this->proxy_authentication_mechanism;
1428      } else {
1429          $authenticate_header = "www-authenticate";
1430          $authorization_header = "Authorization";
1431          $authenticate_status = "401";
1432          $authentication_mechanism = $this->authentication_mechanism;
1433      }
1434      if (IsSet($headers[$authenticate_header])) {
1435          if (function_exists("class_exists")
1436              && !class_exists("sasl_client_class"))
1437          return($this->SetError("the SASL client class needs to be loaded to be able to authenticate" . ($proxy ? " with the proxy server" : "") . " and access this site"));
1438          if (GetType($headers[$authenticate_header]) == "array")
1439          $authenticate = $headers[$authenticate_header];
1440          else
1441          $authenticate=array($headers[$authenticate_header]);
1442          for ($response = "", $mechanisms = array(), $m = 0; $m < count($authenticate); $m++) {
1443          $mechanism = $this->Tokenize($authenticate[$m], " ");
1444          $response = $this->Tokenize("");
1445          if (strlen($authentication_mechanism)) {
1446              if (!strcmp($authentication_mechanism, $mechanism)) {
1447              $mechanisms[] = $mechanism;
1448              break;
1449              }
1450          }
1451          else
1452              $mechanisms[] = $mechanism;
1453          }
1454          $sasl = new sasl_client_class;
1455          if (IsSet($user))
1456          $sasl->SetCredential("user", $user);
1457          if (IsSet($password))
1458          $sasl->SetCredential("password", $password);
1459          if (IsSet($realm))
1460          $sasl->SetCredential("realm", $realm);
1461          if (IsSet($workstation))
1462          $sasl->SetCredential("workstation", $workstation);
1463          $sasl->SetCredential("uri", $this->request_uri);
1464          $sasl->SetCredential("method", $this->request_method);
1465          $sasl->SetCredential("session", $this->session);
1466          do {
1467          $status = $sasl->Start($mechanisms, $message, $interactions);
1468          } while ($status == SASL_INTERACT);
1469          switch ($status) {
1470          case SASL_CONTINUE:
1471              break;
1472          case SASL_NOMECH:
1473              return($this->SetError(($proxy ? "proxy " : "") . "authentication error: " . (strlen($authentication_mechanism) ? "authentication mechanism " . $authentication_mechanism . " may not be used: " : "") . $sasl->error));
1474          default:
1475              return($this->SetError("Could not start the SASL " . ($proxy ? "proxy " : "") . "authentication client: " . $sasl->error));
1476          }
1477          if ($proxy >= 0) {
1478          for (;;) {
1479              if (strlen($error = $this->ReadReplyBody($body, $this->file_buffer_length)))
1480              return($error);
1481              if (strlen($body) == 0)
1482              break;
1483          }
1484          }
1485          $authorization_value = $sasl->mechanism . (IsSet($message) ? " " . ($sasl->encode_response ? base64_encode($message) : $message) : "");
1486          $request_arguments = $this->request_arguments;
1487          $arguments = $request_arguments;
1488          $arguments["Headers"][$authorization_header] = $authorization_value;
1489          if (!$proxy
1490              && strlen($proxy_authorization))
1491          $arguments["Headers"]["Proxy-Authorization"] = $proxy_authorization;
1492          if (strlen($error = $this->Close())
1493              || strlen($error = $this->Open($arguments)))
1494          return($this->SetError($error));
1495          $authenticated = 0;
1496          if (IsSet($message)) {
1497          if ($proxy < 0) {
1498              if (strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1499              return($this->SetError($error));
1500          }
1501          else {
1502              if (strlen($error = $this->SendRequest($arguments))
1503                  || strlen($error = $this->ReadReplyHeadersResponse($headers)))
1504              return($this->SetError($error));
1505          }
1506          if (!IsSet($headers[$authenticate_header]))
1507              $authenticate = array();
1508          elseif (GetType($headers[$authenticate_header]) == "array")
1509              $authenticate = $headers[$authenticate_header];
1510          else
1511              $authenticate=array($headers[$authenticate_header]);
1512          for ($mechanism = 0; $mechanism < count($authenticate); $mechanism++) {
1513              if (!strcmp($this->Tokenize($authenticate[$mechanism], " "), $sasl->mechanism)) {
1514              $response = $this->Tokenize("");
1515              break;
1516              }
1517          }
1518          switch ($this->response_status) {
1519              case $authenticate_status:
1520              break;
1521              case "301":
1522              case "302":
1523              case "303":
1524              case "307":
1525              if ($proxy >= 0)
1526                  return($this->Redirect($headers));
1527              default:
1528              if (intval($this->response_status / 100) == 2) {
1529                  if ($proxy)
1530                  $proxy_authorization = $authorization_value;
1531                  $authenticated = 1;
1532                  break;
1533              }
1534              if ($proxy
1535                  && !strcmp($this->response_status, "401")) {
1536                  $proxy_authorization = $authorization_value;
1537                  $authenticated = 1;
1538                  break;
1539              }
1540              return($this->SetError(($proxy ? "proxy " : "") . "authentication error: " . $this->response_status . " " . $this->response_message));
1541          }
1542          }
1543          for (; !$authenticated;) {
1544          do {
1545              $status = $sasl->Step($response, $message, $interactions);
1546          } while ($status == SASL_INTERACT);
1547          switch ($status) {
1548              case SASL_CONTINUE:
1549              $authorization_value = $sasl->mechanism . (IsSet($message) ? " " . ($sasl->encode_response ? base64_encode($message) : $message) : "");
1550              $arguments = $request_arguments;
1551              $arguments["Headers"][$authorization_header] = $authorization_value;
1552              if (!$proxy
1553                  && strlen($proxy_authorization))
1554                  $arguments["Headers"]["Proxy-Authorization"] = $proxy_authorization;
1555              if ($proxy < 0) {
1556                  if (strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1557                  return($this->SetError($error));
1558              }
1559              else {
1560                  if (strlen($error = $this->SendRequest($arguments))
1561                      || strlen($error = $this->ReadReplyHeadersResponse($headers)))
1562                  return($this->SetError($error));
1563              }
1564              switch ($this->response_status) {
1565                  case $authenticate_status:
1566                  if (GetType($headers[$authenticate_header]) == "array")
1567                      $authenticate = $headers[$authenticate_header];
1568                  else
1569                      $authenticate=array($headers[$authenticate_header]);
1570                  for ($response = "", $mechanism = 0; $mechanism < count($authenticate); $mechanism++) {
1571                      if (!strcmp($this->Tokenize($authenticate[$mechanism], " "), $sasl->mechanism)) {
1572                      $response = $this->Tokenize("");
1573                      break;
1574                      }
1575                  }
1576                  if ($proxy >= 0) {
1577                      for (;;) {
1578                      if (strlen($error = $this->ReadReplyBody($body, $this->file_buffer_length)))
1579                          return($error);
1580                      if (strlen($body) == 0)
1581                          break;
1582                      }
1583                  }
1584                  $this->state = "Connected";
1585                  break;
1586                  case "301":
1587                  case "302":
1588                  case "303":
1589                  case "307":
1590                  if ($proxy >= 0)
1591                      return($this->Redirect($headers));
1592                  default:
1593                  if (intval($this->response_status / 100) == 2) {
1594                      if ($proxy)
1595                      $proxy_authorization = $authorization_value;
1596                      $authenticated = 1;
1597                      break;
1598                  }
1599                  if ($proxy
1600                      && !strcmp($this->response_status, "401")) {
1601                      $proxy_authorization = $authorization_value;
1602                      $authenticated = 1;
1603                      break;
1604                  }
1605                  return($this->SetError(($proxy ? "proxy " : "") . "authentication error: " . $this->response_status . " " . $this->response_message));
1606              }
1607              break;
1608              default:
1609              return($this->SetError("Could not process the SASL " . ($proxy ? "proxy " : "") . "authentication step: " . $sasl->error));
1610          }
1611          }
1612      }
1613      return("");
1614      }
1615  
1616      Function ReadReplyHeaders(&$headers) {
1617      if (strlen($error = $this->ReadReplyHeadersResponse($headers)))
1618          return($error);
1619      $proxy_authorization = "";
1620      while (!strcmp($this->response_status, "100")) {
1621          $this->state = "RequestSent";
1622          if (strlen($error = $this->ReadReplyHeadersResponse($headers)))
1623          return($error);
1624      }
1625      switch ($this->response_status) {
1626          case "301":
1627          case "302":
1628          case "303":
1629          case "307":
1630          if (strlen($error = $this->Redirect($headers)))
1631              return($error);
1632          break;
1633          case "407":
1634          if (strlen($error = $this->Authenticate($headers, 1, $proxy_authorization, $this->proxy_request_user, $this->proxy_request_password, $this->proxy_request_realm, $this->proxy_request_workstation)))
1635              return($error);
1636          if (strcmp($this->response_status, "401"))
1637              return("");
1638          case "401":
1639          return($this->Authenticate($headers, 0, $proxy_authorization, $this->request_user, $this->request_password, $this->request_realm, $this->request_workstation));
1640      }
1641      return("");
1642      }
1643  
1644      Function ReadReplyBody(&$body, $length) {
1645      $body = "";
1646      if (strlen($this->error))
1647          return($this->error);
1648      switch ($this->state) {
1649          case "Disconnected":
1650          return($this->SetError("1 connection was not yet established"));
1651          case "Connected":
1652          case "ConnectedToProxy":
1653          return($this->SetError("2 request was not sent"));
1654          case "RequestSent":
1655          if (($error = $this->ReadReplyHeaders($headers)) != "")
1656              return($error);
1657          break;
1658          case "GotReplyHeaders":
1659          break;
1660          default:
1661          return($this->SetError("3 can not get request headers in the current connection state"));
1662      }
1663      if ($this->content_length_set)
1664          $length = min($this->content_length - $this->read_length, $length);
1665      if ($length > 0
1666          && !$this->EndOfInput()
1667          && ($body = $this->ReadBytes($length)) == "") {
1668          if (strlen($this->error))
1669          return($this->SetError("4 could not get the request reply body: " . $this->error));
1670      }
1671      $this->read_length+=strlen($body);
1672      return("");
1673      }
1674  
1675      Function SaveCookies(&$cookies, $domain='', $secure_only=0, $persistent_only=0) {
1676      $now = gmdate("Y-m-d H-i-s");
1677      $cookies = array();
1678      for ($secure_cookies = 0, Reset($this->cookies); $secure_cookies < count($this->cookies); Next($this->cookies), $secure_cookies++) {
1679          $secure = Key($this->cookies);
1680          if (!$secure_only
1681              || $secure) {
1682          for ($cookie_domain = 0, Reset($this->cookies[$secure]); $cookie_domain < count($this->cookies[$secure]); Next($this->cookies[$secure]), $cookie_domain++) {
1683              $domain_pattern = Key($this->cookies[$secure]);
1684              $match = strlen($domain) - strlen($domain_pattern);
1685              if (strlen($domain) == 0
1686                  || ($match >= 0
1687                  && !strcmp($domain_pattern, substr($domain, $match))
1688                  && ($match == 0
1689                  || $domain_pattern[0] == "."
1690                  || $domain[$match - 1] == "."))) {
1691              for (Reset($this->cookies[$secure][$domain_pattern]), $path_part = 0; $path_part < count($this->cookies[$secure][$domain_pattern]); Next($this->cookies[$secure][$domain_pattern]), $path_part++) {
1692                  $path = Key($this->cookies[$secure][$domain_pattern]);
1693                  for (Reset($this->cookies[$secure][$domain_pattern][$path]), $cookie = 0; $cookie < count($this->cookies[$secure][$domain_pattern][$path]); Next($this->cookies[$secure][$domain_pattern][$path]), $cookie++) {
1694                  $cookie_name = Key($this->cookies[$secure][$domain_pattern][$path]);
1695                  $expires = $this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
1696                  if ((!$persistent_only
1697                      && strlen($expires) == 0)
1698                      || (strlen($expires)
1699                      && strcmp($now, $expires) < 0))
1700                      $cookies[$secure][$domain_pattern][$path][$cookie_name] = $this->cookies[$secure][$domain_pattern][$path][$cookie_name];
1701                  }
1702              }
1703              }
1704          }
1705          }
1706      }
1707      }
1708  
1709      Function SavePersistentCookies(&$cookies, $domain='', $secure_only=0) {
1710      $this->SaveCookies($cookies, $domain, $secure_only, 1);
1711      }
1712  
1713      Function GetPersistentCookies(&$cookies, $domain='', $secure_only=0) {
1714      $this->SavePersistentCookies($cookies, $domain, $secure_only);
1715      }
1716  
1717      Function RestoreCookies($cookies, $clear=1) {
1718      $new_cookies = ($clear ? array() : $this->cookies);
1719      for ($secure_cookies = 0, Reset($cookies); $secure_cookies < count($cookies); Next($cookies), $secure_cookies++) {
1720          $secure = Key($cookies);
1721          if (GetType($secure) != "integer")
1722          return($this->SetError("invalid cookie secure value type (" . serialize($secure) . ")"));
1723          for ($cookie_domain = 0, Reset($cookies[$secure]); $cookie_domain < count($cookies[$secure]); Next($cookies[$secure]), $cookie_domain++) {
1724          $domain_pattern = Key($cookies[$secure]);
1725          if (GetType($domain_pattern) != "string")
1726              return($this->SetError("invalid cookie domain value type (" . serialize($domain_pattern) . ")"));
1727          for (Reset($cookies[$secure][$domain_pattern]), $path_part = 0; $path_part < count($cookies[$secure][$domain_pattern]); Next($cookies[$secure][$domain_pattern]), $path_part++) {
1728              $path = Key($cookies[$secure][$domain_pattern]);
1729              if (GetType($path) != "string"
1730                  || strcmp(substr($path, 0, 1), "/"))
1731              return($this->SetError("invalid cookie path value type (" . serialize($path) . ")"));
1732              for (Reset($cookies[$secure][$domain_pattern][$path]), $cookie = 0; $cookie < count($cookies[$secure][$domain_pattern][$path]); Next($cookies[$secure][$domain_pattern][$path]), $cookie++) {
1733              $cookie_name = Key($cookies[$secure][$domain_pattern][$path]);
1734              $expires = $cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
1735              $value = $cookies[$secure][$domain_pattern][$path][$cookie_name]["value"];
1736              if (GetType($expires) != "string"
1737                  || (strlen($expires)
1738                  && !ereg("^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$", $expires)))
1739                  return($this->SetError("invalid cookie expiry value type (" . serialize($expires) . ")"));
1740              $new_cookies[$secure][$domain_pattern][$path][$cookie_name] = array(
1741                  "name" => $cookie_name,
1742                  "value" => $value,
1743                  "domain" => $domain_pattern,
1744                  "path" => $path,
1745                  "expires" => $expires,
1746                  "secure" => $secure
1747              );
1748              }
1749          }
1750          }
1751      }
1752      $this->cookies = $new_cookies;
1753      return("");
1754      }
1755  
1756  }
1757  
1758  ;
1759  ?>

title

Description

title

Description

title

Description

title

title

Body