Add analytics
[bus.git] / busui / owa / includes / httpclient-2009-09-02 / http.php
blob:a/busui/owa/includes/httpclient-2009-09-02/http.php -> blob:b/busui/owa/includes/httpclient-2009-09-02/http.php
--- a/busui/owa/includes/httpclient-2009-09-02/http.php
+++ b/busui/owa/includes/httpclient-2009-09-02/http.php
@@ -1,1 +1,1982 @@
-
+<?php
+/*
+ * http.php
+ *
+ * @(#) $Header: /home/mlemos/cvsroot/http/http.php,v 1.79 2009/09/03 00:09:37 mlemos Exp $
+ *
+ */
+
+class http_class
+{
+	var $host_name="";
+	var $host_port=0;
+	var $proxy_host_name="";
+	var $proxy_host_port=80;
+	var $socks_host_name = '';
+	var $socks_host_port = 1080;
+	var $socks_version = '5';
+
+	var $protocol="http";
+	var $request_method="GET";
+	var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.79 $)';
+	var $authentication_mechanism="";
+	var $user;
+	var $password;
+	var $realm;
+	var $workstation;
+	var $proxy_authentication_mechanism="";
+	var $proxy_user;
+	var $proxy_password;
+	var $proxy_realm;
+	var $proxy_workstation;
+	var $request_uri="";
+	var $request="";
+	var $request_headers=array();
+	var $request_user;
+	var $request_password;
+	var $request_realm;
+	var $request_workstation;
+	var $proxy_request_user;
+	var $proxy_request_password;
+	var $proxy_request_realm;
+	var $proxy_request_workstation;
+	var $request_body="";
+	var $request_arguments=array();
+	var $protocol_version="1.1";
+	var $timeout=0;
+	var $data_timeout=0;
+	var $debug=0;
+	var $debug_response_body=1;
+	var $html_debug=0;
+	var $support_cookies=1;
+	var $cookies=array();
+	var $error="";
+	var $exclude_address="";
+	var $follow_redirect=0;
+	var $redirection_limit=5;
+	var $response_status="";
+	var $response_message="";
+	var $file_buffer_length=8000;
+	var $force_multipart_form_post=0;
+	var $prefer_curl = 0;
+
+	/* private variables - DO NOT ACCESS */
+
+	var $state="Disconnected";
+	var $use_curl=0;
+	var $connection=0;
+	var $content_length=0;
+	var $response="";
+	var $read_response=0;
+	var $read_length=0;
+	var $request_host="";
+	var $next_token="";
+	var $redirection_level=0;
+	var $chunked=0;
+	var $remaining_chunk=0;
+	var $last_chunk_read=0;
+	var $months=array(
+		"Jan"=>"01",
+		"Feb"=>"02",
+		"Mar"=>"03",
+		"Apr"=>"04",
+		"May"=>"05",
+		"Jun"=>"06",
+		"Jul"=>"07",
+		"Aug"=>"08",
+		"Sep"=>"09",
+		"Oct"=>"10",
+		"Nov"=>"11",
+		"Dec"=>"12");
+	var $session='';
+	var $connection_close=0;
+
+	/* Private methods - DO NOT CALL */
+
+	Function Tokenize($string,$separator="")
+	{
+		if(!strcmp($separator,""))
+		{
+			$separator=$string;
+			$string=$this->next_token;
+		}
+		for($character=0;$character<strlen($separator);$character++)
+		{
+			if(GetType($position=strpos($string,$separator[$character]))=="integer")
+				$found=(IsSet($found) ? min($found,$position) : $position);
+		}
+		if(IsSet($found))
+		{
+			$this->next_token=substr($string,$found+1);
+			return(substr($string,0,$found));
+		}
+		else
+		{
+			$this->next_token="";
+			return($string);
+		}
+	}
+
+	Function CookieEncode($value, $name)
+	{
+		return($name ? str_replace("=", "%25", $value) : str_replace(";", "%3B", $value));
+	}
+
+	Function SetError($error)
+	{
+		return($this->error=$error);
+	}
+
+	Function SetPHPError($error, &$php_error_message)
+	{
+		if(IsSet($php_error_message)
+		&& strlen($php_error_message))
+			$error.=": ".$php_error_message;
+		return($this->SetError($error));
+	}
+
+	Function SetDataAccessError($error,$check_connection=0)
+	{
+		$this->error=$error;
+		if(!$this->use_curl
+		&& function_exists("socket_get_status"))
+		{
+			$status=socket_get_status($this->connection);
+			if($status["timed_out"])
+				$this->error.=": data access time out";
+			elseif($status["eof"])
+			{
+				if($check_connection)
+					$this->error="";
+				else
+					$this->error.=": the server disconnected";
+			}
+		}
+	}
+
+	Function OutputDebug($message)
+	{
+		$message.="\n";
+		if($this->html_debug)
+			$message=str_replace("\n","<br />\n",HtmlEntities($message));
+		echo $message;
+		flush();
+	}
+
+	Function GetLine()
+	{
+		for($line="";;)
+		{
+			if($this->use_curl)
+			{
+				$eol=strpos($this->response,"\n",$this->read_response);
+				$data=($eol ? substr($this->response,$this->read_response,$eol+1-$this->read_response) : "");
+				$this->read_response+=strlen($data);
+			}
+			else
+			{
+				if(feof($this->connection))
+				{
+					$this->SetDataAccessError("reached the end of data while reading from the HTTP server connection");
+					return(0);
+				}
+				$data=fgets($this->connection,100);
+			}
+			if(GetType($data)!="string"
+			|| strlen($data)==0)
+			{
+				$this->SetDataAccessError("it was not possible to read line from the HTTP server");
+				return(0);
+			}
+			$line.=$data;
+			$length=strlen($line);
+			if($length
+			&& !strcmp(substr($line,$length-1,1),"\n"))
+			{
+				$length-=(($length>=2 && !strcmp(substr($line,$length-2,1),"\r")) ? 2 : 1);
+				$line=substr($line,0,$length);
+				if($this->debug)
+					$this->OutputDebug("S $line");
+				return($line);
+			}
+		}
+	}
+
+	Function PutLine($line)
+	{
+		if($this->debug)
+			$this->OutputDebug("C $line");
+		if(!fputs($this->connection,$line."\r\n"))
+		{
+			$this->SetDataAccessError("it was not possible to send a line to the HTTP server");
+			return(0);
+		}
+		return(1);
+	}
+
+	Function PutData($data)
+	{
+		if(strlen($data))
+		{
+			if($this->debug)
+				$this->OutputDebug('C '.$data);
+			if(!fputs($this->connection,$data))
+			{
+				$this->SetDataAccessError("it was not possible to send data to the HTTP server");
+				return(0);
+			}
+		}
+		return(1);
+	}
+
+	Function FlushData()
+	{
+		if(!fflush($this->connection))
+		{
+			$this->SetDataAccessError("it was not possible to send data to the HTTP server");
+			return(0);
+		}
+		return(1);
+	}
+
+	Function ReadChunkSize()
+	{
+		if($this->remaining_chunk==0)
+		{
+			$debug=$this->debug;
+			if(!$this->debug_response_body)
+				$this->debug=0;
+			$line=$this->GetLine();
+			$this->debug=$debug;
+			if(GetType($line)!="string")
+				return($this->SetError("4 could not read chunk start: ".$this->error));
+			$this->remaining_chunk=hexdec($line);
+		}
+		return("");
+	}
+
+	Function ReadBytes($length)
+	{
+		if($this->use_curl)
+		{
+			$bytes=substr($this->response,$this->read_response,min($length,strlen($this->response)-$this->read_response));
+			$this->read_response+=strlen($bytes);
+			if($this->debug
+			&& $this->debug_response_body
+			&& strlen($bytes))
+				$this->OutputDebug("S ".$bytes);
+		}
+		else
+		{
+			if($this->chunked)
+			{
+				for($bytes="",$remaining=$length;$remaining;)
+				{
+					if(strlen($this->ReadChunkSize()))
+						return("");
+					if($this->remaining_chunk==0)
+					{
+						$this->last_chunk_read=1;
+						break;
+					}
+					$ask=min($this->remaining_chunk,$remaining);
+					$chunk=@fread($this->connection,$ask);
+					$read=strlen($chunk);
+					if($read==0)
+					{
+						$this->SetDataAccessError("it was not possible to read data chunk from the HTTP server");
+						return("");
+					}
+					if($this->debug
+					&& $this->debug_response_body)
+						$this->OutputDebug("S ".$chunk);
+					$bytes.=$chunk;
+					$this->remaining_chunk-=$read;
+					$remaining-=$read;
+					if($this->remaining_chunk==0)
+					{
+						if(feof($this->connection))
+							return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server"));
+						$data=@fread($this->connection,2);
+						if(strcmp($data,"\r\n"))
+						{
+							$this->SetDataAccessError("it was not possible to read end of data chunk from the HTTP server");
+							return("");
+						}
+					}
+				}
+			}
+			else
+			{
+				$bytes=@fread($this->connection,$length);
+				if(strlen($bytes))
+				{
+					if($this->debug
+					&& $this->debug_response_body)
+						$this->OutputDebug("S ".$bytes);
+				}
+				else
+					$this->SetDataAccessError("it was not possible to read data from the HTTP server", $this->connection_close);
+			}
+		}
+		return($bytes);
+	}
+
+	Function EndOfInput()
+	{
+		if($this->use_curl)
+			return($this->read_response>=strlen($this->response));
+		if($this->chunked)
+			return($this->last_chunk_read);
+		return(feof($this->connection));
+	}
+
+	Function Resolve($domain, &$ip, $server_type)
+	{
+		if(preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/',$domain))
+			$ip=$domain;
+		else
+		{
+			if($this->debug)
+				$this->OutputDebug('Resolving '.$server_type.' server domain "'.$domain.'"...');
+			if(!strcmp($ip=@gethostbyname($domain),$domain))
+				$ip="";
+		}
+		if(strlen($ip)==0
+		|| (strlen($this->exclude_address)
+		&& !strcmp(@gethostbyname($this->exclude_address),$ip)))
+			return($this->SetError("could not resolve the host domain \"".$domain."\""));
+		return('');
+	}
+
+	Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP')
+	{
+		$domain=$host_name;
+		$port = $host_port;
+		if(strlen($error = $this->Resolve($domain, $ip, $server_type)))
+			return($error);
+		if(strlen($this->socks_host_name))
+		{
+			switch($this->socks_version)
+			{
+				case '4':
+					$version = 4;
+					break;
+				case '5':
+					$version = 5;
+					break;
+				default:
+					return('it was not specified a supported SOCKS protocol version');
+					break;
+			}
+			$host_ip = $ip;
+			$port = $this->socks_host_port;
+			$host_server_type = $server_type;
+			$server_type = 'SOCKS';
+			if(strlen($error = $this->Resolve($this->socks_host_name, $ip, $server_type)))
+				return($error);
+		}
+		if($this->debug)
+			$this->OutputDebug('Connecting to '.$server_type.' server IP '.$ip.' port '.$port.'...');
+		if($ssl)
+			$ip="ssl://".$ip;
+		if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
+		{
+			switch($errno)
+			{
+				case -3:
+					return($this->SetError("-3 socket could not be created"));
+				case -4:
+					return($this->SetError("-4 dns lookup on hostname \"".$host_name."\" failed"));
+				case -5:
+					return($this->SetError("-5 connection refused or timed out"));
+				case -6:
+					return($this->SetError("-6 fdopen() call failed"));
+				case -7:
+					return($this->SetError("-7 setvbuf() call failed"));
+				default:
+					return($this->SetPHPError($errno." could not connect to the host \"".$host_name."\"",$php_errormsg));
+			}
+		}
+		else
+		{
+			if($this->data_timeout
+			&& function_exists("socket_set_timeout"))
+				socket_set_timeout($this->connection,$this->data_timeout,0);
+			if(strlen($this->socks_host_name))
+			{
+				if($this->debug)
+					$this->OutputDebug('Connected to the SOCKS server '.$this->socks_host_name);
+				$send_error = 'it was not possible to send data to the SOCKS server';
+				$receive_error = 'it was not possible to receive data from the SOCKS server';
+				switch($version)
+				{
+					case 4:
+						$command = 1;
+						if(!fputs($this->connection, chr($version).chr($command).pack('nN', $host_port, ip2long($host_ip)).$this->user.Chr(0)))
+							$error = $this->SetDataAccessError($send_error);
+						else
+						{
+							$response = fgets($this->connection, 9);
+							if(strlen($response) != 8)
+								$error = $this->SetDataAccessError($receive_error);
+							else
+							{
+								$socks_errors = array(
+									"\x5a"=>'',
+									"\x5b"=>'request rejected',
+									"\x5c"=>'request failed because client is not running identd (or not reachable from the server)',
+									"\x5d"=>'request failed because client\'s identd could not confirm the user ID string in the request',
+								);
+								$error_code = $response[1];
+								$error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
+								if(strlen($error))
+									$error = 'SOCKS error: '.$error;
+							}
+						}
+						break;
+					case 5:
+						if($this->debug)
+							$this->OutputDebug('Negotiating the authentication method ...');
+						$methods = 1;
+						$method = 0;
+						if(!fputs($this->connection, chr($version).chr($methods).chr($method)))
+							$error = $this->SetDataAccessError($send_error);
+						else
+						{
+							$response = fgets($this->connection, 3);
+							if(strlen($response) != 2)
+								$error = $this->SetDataAccessError($receive_error);
+							elseif(Ord($response[1]) != $method)
+								$error = 'the SOCKS server requires an authentication method that is not yet supported';
+							else
+							{
+								if($this->debug)
+									$this->OutputDebug('Connecting to '.$host_server_type.' server IP '.$host_ip.' port '.$host_port.'...');
+								$command = 1;
+								$address_type = 1;
+								if(!fputs($this->connection, chr($version).chr($command)."\x00".chr($address_type).pack('Nn', ip2long($host_ip), $host_port)))
+									$error = $this->SetDataAccessError($send_error);
+								else
+								{
+									$response = fgets($this->connection, 11);
+									if(strlen($response) != 10)
+										$error = $this->SetDataAccessError($receive_error);
+									else
+									{
+										$socks_errors = array(
+											"\x00"=>'',
+											"\x01"=>'general SOCKS server failure',
+											"\x02"=>'connection not allowed by ruleset',
+											"\x03"=>'Network unreachable',
+											"\x04"=>'Host unreachable',
+											"\x05"=>'Connection refused',
+											"\x06"=>'TTL expired',
+											"\x07"=>'Command not supported',
+											"\x08"=>'Address type not supported'
+										);
+										$error_code = $response[1];
+										$error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
+										if(strlen($error))
+											$error = 'SOCKS error: '.$error;
+									}
+								}
+							}
+						}
+						break;
+					default:
+						$error = 'support for SOCKS protocol version '.$this->socks_version.' is not yet implemented';
+						break;
+				}
+				if(strlen($error))
+				{
+					fclose($this->connection);
+					return($error);
+				}
+			}
+			if($this->debug)
+				$this->OutputDebug("Connected to $host_name");
+			if(strlen($this->proxy_host_name)
+			&& !strcmp(strtolower($this->protocol), 'https'))
+			{
+				if(function_exists('stream_socket_enable_crypto')
+				&& in_array('ssl', stream_get_transports()))
+					$this->state = "ConnectedToProxy";
+				else
+				{
+					$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.");
+					$this->state="Connected";
+				}
+			}
+			else
+				$this->state="Connected";
+			return("");
+		}
+	}
+
+	Function Disconnect()
+	{
+		if($this->debug)
+			$this->OutputDebug("Disconnected from ".$this->host_name);
+		if($this->use_curl)
+		{
+			curl_close($this->connection);
+			$this->response="";
+		}
+		else
+			fclose($this->connection);
+		$this->state="Disconnected";
+		return("");
+	}
+
+	/* Public methods */
+
+	Function GetRequestArguments($url, &$arguments)
+	{
+		$this->error = '';
+		$arguments=array();
+		$url = str_replace(' ', '%20', $url);
+		$parameters=@parse_url($url);
+		if(!$parameters)
+			return($this->SetError("it was not specified a valid URL"));
+		if(!IsSet($parameters["scheme"]))
+			return($this->SetError("it was not specified the protocol type argument"));
+		switch(strtolower($parameters["scheme"]))
+		{
+			case "http":
+			case "https":
+				$arguments["Protocol"]=$parameters["scheme"];
+				break;
+			default:
+				return($parameters["scheme"]." connection scheme is not yet supported");
+		}
+		if(!IsSet($parameters["host"]))
+			return($this->SetError("it was not specified the connection host argument"));
+		$arguments["HostName"]=$parameters["host"];
+		$arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : ""));
+		if(IsSet($parameters["user"]))
+		{
+			$arguments["AuthUser"]=UrlDecode($parameters["user"]);
+			if(!IsSet($parameters["pass"]))
+				$arguments["AuthPassword"]="";
+		}
+		if(IsSet($parameters["pass"]))
+		{
+			if(!IsSet($parameters["user"]))
+				$arguments["AuthUser"]="";
+			$arguments["AuthPassword"]=UrlDecode($parameters["pass"]);
+		}
+		if(IsSet($parameters["port"]))
+		{
+			if(strcmp($parameters["port"],strval(intval($parameters["port"]))))
+				return($this->SetError("it was not specified a valid connection host argument"));
+			$arguments["HostPort"]=intval($parameters["port"]);
+		}
+		else
+			$arguments["HostPort"]=0;
+		$arguments["RequestURI"]=(IsSet($parameters["path"]) ? $parameters["path"] : "/").(IsSet($parameters["query"]) ? "?".$parameters["query"] : "");
+		if(strlen($this->user_agent))
+			$arguments["Headers"]["User-Agent"]=$this->user_agent;
+		return("");
+	}
+
+	Function Open($arguments)
+	{
+		if(strlen($this->error))
+			return($this->error);
+		if($this->state!="Disconnected")
+			return("1 already connected");
+		if(IsSet($arguments["HostName"]))
+			$this->host_name=$arguments["HostName"];
+		if(IsSet($arguments["HostPort"]))
+			$this->host_port=$arguments["HostPort"];
+		if(IsSet($arguments["ProxyHostName"]))
+			$this->proxy_host_name=$arguments["ProxyHostName"];
+		if(IsSet($arguments["ProxyHostPort"]))
+			$this->proxy_host_port=$arguments["ProxyHostPort"];
+		if(IsSet($arguments["SOCKSHostName"]))
+			$this->socks_host_name=$arguments["SOCKSHostName"];
+		if(IsSet($arguments["SOCKSHostPort"]))
+			$this->socks_host_port=$arguments["SOCKSHostPort"];
+		if(IsSet($arguments["SOCKSVersion"]))
+			$this->socks_version=$arguments["SOCKSVersion"];
+		if(IsSet($arguments["Protocol"]))
+			$this->protocol=$arguments["Protocol"];
+		switch(strtolower($this->protocol))
+		{
+			case "http":
+				$default_port=80;
+				break;
+			case "https":
+				$default_port=443;
+				break;
+			default:
+				return($this->SetError("2 it was not specified a valid connection protocol"));
+		}
+		if(strlen($this->proxy_host_name)==0)
+		{
+			if(strlen($this->host_name)==0)
+				return($this->SetError("2 it was not specified a valid hostname"));
+			$host_name=$this->host_name;
+			$host_port=($this->host_port ? $this->host_port : $default_port);
+			$server_type = 'HTTP';
+		}
+		else
+		{
+			$host_name=$this->proxy_host_name;
+			$host_port=$this->proxy_host_port;
+			$server_type = 'HTTP proxy';
+		}
+		$ssl=(strtolower($this->protocol)=="https" && strlen($this->proxy_host_name)==0);
+		if($ssl
+		&& strlen($this->socks_host_name))
+			return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported'));
+		$this->use_curl=($ssl && $this->prefer_curl && function_exists("curl_init"));
+		if($this->debug)
+			$this->OutputDebug("Connecting to ".$this->host_name);
+		if($this->use_curl)
+		{
+			$error=(($this->connection=curl_init($this->protocol."://".$this->host_name.($host_port==$default_port ? "" : ":".strval($host_port))."/")) ? "" : "Could not initialize a CURL session");
+			if(strlen($error)==0)
+			{
+				if(IsSet($arguments["SSLCertificateFile"]))
+					curl_setopt($this->connection,CURLOPT_SSLCERT,$arguments["SSLCertificateFile"]);
+				if(IsSet($arguments["SSLCertificatePassword"]))
+					curl_setopt($this->connection,CURLOPT_SSLCERTPASSWD,$arguments["SSLCertificatePassword"]);
+				if(IsSet($arguments["SSLKeyFile"]))
+					curl_setopt($this->connection,CURLOPT_SSLKEY,$arguments["SSLKeyFile"]);
+				if(IsSet($arguments["SSLKeyPassword"]))
+					curl_setopt($this->connection,CURLOPT_SSLKEYPASSWD,$arguments["SSLKeyPassword"]);
+			}
+			$this->state="Connected";
+		}
+		else
+		{
+			$error="";
+			if(strlen($this->proxy_host_name)
+			&& (IsSet($arguments["SSLCertificateFile"])
+			|| IsSet($arguments["SSLCertificateFile"])))
+				$error="establishing SSL connections using certificates or private keys via non-SSL proxies is not supported";
+			else
+			{
+				if($ssl)
+				{
+					if(IsSet($arguments["SSLCertificateFile"]))
+						$error="establishing SSL connections using certificates is only supported when the cURL extension is enabled";
+					elseif(IsSet($arguments["SSLKeyFile"]))
+						$error="establishing SSL connections using a private key is only supported when the cURL extension is enabled";
+					else
+					{
+						$version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
+						$php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
+						if($php_version<4003000)
+							$error="establishing SSL connections requires at least PHP version 4.3.0 or having the cURL extension enabled";
+						elseif(!function_exists("extension_loaded")
+						|| !extension_loaded("openssl"))
+							$error="establishing SSL connections requires the OpenSSL extension enabled";
+					}
+				}
+				if(strlen($error)==0)
+					$error=$this->Connect($host_name, $host_port, $ssl, $server_type);
+			}
+		}
+		if(strlen($error))
+			return($this->SetError($error));
+		$this->session=md5(uniqid(""));
+		return("");
+	}
+
+	Function Close()
+	{
+		if($this->state=="Disconnected")
+			return("1 already disconnected");
+		$error=$this->Disconnect();
+		if(strlen($error)==0)
+			$this->state="Disconnected";
+		return($error);
+	}
+
+	Function PickCookies(&$cookies,$secure)
+	{
+		if(IsSet($this->cookies[$secure]))
+		{
+			$now=gmdate("Y-m-d H-i-s");
+			for($domain=0,Reset($this->cookies[$secure]);$domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$domain++)
+			{
+				$domain_pattern=Key($this->cookies[$secure]);
+				$match=strlen($this->request_host)-strlen($domain_pattern);
+				if($match>=0
+				&& !strcmp($domain_pattern,substr($this->request_host,$match))
+				&& ($match==0
+				|| $domain_pattern[0]=="."
+				|| $this->request_host[$match-1]=="."))
+				{
+					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++)
+					{
+						$path=Key($this->cookies[$secure][$domain_pattern]);
+						if(strlen($this->request_uri)>=strlen($path)
+						&& substr($this->request_uri,0,strlen($path))==$path)
+						{
+							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++)
+							{
+								$cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]);
+								$expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
+								if($expires==""
+								|| strcmp($now,$expires)<0)
+									$cookies[$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name];
+							}
+						}
+					}
+				}
+			}
+		}
+	}
+
+	Function GetFileDefinition($file, &$definition)
+	{
+		$name="";
+		if(IsSet($file["FileName"]))
+			$name=basename($file["FileName"]);
+		if(IsSet($file["Name"]))
+			$name=$file["Name"];
+		if(strlen($name)==0)
+			return("it was not specified the file part name");
+		if(IsSet($file["Content-Type"]))
+		{
+			$content_type=$file["Content-Type"];
+			$type=$this->Tokenize(strtolower($content_type),"/");
+			$sub_type=$this->Tokenize("");
+			switch($type)
+			{
+				case "text":
+				case "image":
+				case "audio":
+				case "video":
+				case "application":
+				case "message":
+					break;
+				case "automatic":
+					switch($sub_type)
+					{
+						case "name":
+							switch(GetType($dot=strrpos($name,"."))=="integer" ? strtolower(substr($name,$dot)) : "")
+							{
+								case ".xls":
+									$content_type="application/excel";
+									break;
+								case ".hqx":
+									$content_type="application/macbinhex40";
+									break;
+								case ".doc":
+								case ".dot":
+								case ".wrd":
+									$content_type="application/msword";
+									break;
+								case ".pdf":
+									$content_type="application/pdf";
+									break;
+								case ".pgp":
+									$content_type="application/pgp";
+									break;
+								case ".ps":
+								case ".eps":
+								case ".ai":
+									$content_type="application/postscript";
+									break;
+								case ".ppt":
+									$content_type="application/powerpoint";
+									break;
+								case ".rtf":
+									$content_type="application/rtf";
+									break;
+								case ".tgz":
+								case ".gtar":
+									$content_type="application/x-gtar";
+									break;
+								case ".gz":
+									$content_type="application/x-gzip";
+									break;
+								case ".php":
+								case ".php3":
+									$content_type="application/x-httpd-php";
+									break;
+								case ".js":
+									$content_type="application/x-javascript";
+									break;
+								case ".ppd":
+								case ".psd":
+									$content_type="application/x-photoshop";
+									break;
+								case ".swf":
+								case ".swc":
+								case ".rf":
+									$content_type="application/x-shockwave-flash";
+									break;
+								case ".tar":
+									$content_type="application/x-tar";
+									break;
+								case ".zip":
+									$content_type="application/zip";
+									break;
+								case ".mid":
+								case ".midi":
+								case ".kar":
+									$content_type="audio/midi";
+									break;
+								case ".mp2":
+								case ".mp3":
+								case ".mpga":
+									$content_type="audio/mpeg";
+									break;
+								case ".ra":
+									$content_type="audio/x-realaudio";
+									break;
+								case ".wav":
+									$content_type="audio/wav";
+									break;
+								case ".bmp":
+									$content_type="image/bitmap";
+									break;
+								case ".gif":
+									$content_type="image/gif";
+									break;
+								case ".iff":
+									$content_type="image/iff";
+									break;
+								case ".jb2":
+									$content_type="image/jb2";
+									break;
+								case ".jpg":
+								case ".jpe":
+								case ".jpeg":
+									$content_type="image/jpeg";
+									break;
+								case ".jpx":
+									$content_type="image/jpx";
+									break;
+								case ".png":
+									$content_type="image/png";
+									break;
+								case ".tif":
+								case ".tiff":
+									$content_type="image/tiff";
+									break;
+								case ".wbmp":
+									$content_type="image/vnd.wap.wbmp";
+									break;
+								case ".xbm":
+									$content_type="image/xbm";
+									break;
+								case ".css":
+									$content_type="text/css";
+									break;
+								case ".txt":
+									$content_type="text/plain";
+									break;
+								case ".htm":
+								case ".html":
+									$content_type="text/html";
+									break;
+								case ".xml":
+									$content_type="text/xml";
+									break;
+								case ".mpg":
+