summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2008-11-19 20:57:23 -0500
committerStarla Insigna <hatkirby@fourisland.com>2008-11-19 20:57:23 -0500
commit6a66b6b2fea3fa24862586e27e9b03a2f92196a5 (patch)
treeb84819db2837748574dcac4705beb4bd50fb52f9
parent51337807124d7f57d6cff6656d41b5fd57010c6b (diff)
downloadfourisland-6a66b6b2fea3fa24862586e27e9b03a2f92196a5.tar.gz
fourisland-6a66b6b2fea3fa24862586e27e9b03a2f92196a5.tar.bz2
fourisland-6a66b6b2fea3fa24862586e27e9b03a2f92196a5.zip
Removed includes/phpsvnclient.php
phpsvnclient.php was previously used to interface the Four Island Subversion Repositories so changesets could be seen via the RSS feed, but not only
not many people want this in their RSS feed, and the people that did could get a seperate feed, but Four Island no longer uses Subversion, instead it
uses the better, distributive Mercurial.
-rwxr-xr-xincludes/definitions.php52
-rwxr-xr-xincludes/http.php1982
-rwxr-xr-xincludes/phpsvnclient.php420
-rwxr-xr-xincludes/xml_parser.php427
-rwxr-xr-xpages/projects.php94
-rwxr-xr-xrss.php54
6 files changed, 0 insertions, 3029 deletions
diff --git a/includes/definitions.php b/includes/definitions.php deleted file mode 100755 index 581eb85..0000000 --- a/includes/definitions.php +++ /dev/null
@@ -1,52 +0,0 @@
1<?php
2/*
3***************************************************************************
4* Copyright (C) 2007-2008 by Sixdegrees *
5* cesar@sixdegrees.com.br *
6* "Working with freedom" *
7* http://www.sixdegrees.com.br *
8* *
9* Permission is hereby granted, free of charge, to any person obtaining *
10* a copy of this software and associated documentation files (the *
11* "Software"), to deal in the Software without restriction, including *
12* without limitation the rights to use, copy, modify, merge, publish, *
13* distribute, sublicense, and/or sell copies of the Software, and to *
14* permit persons to whom the Software is furnished to do so, subject to *
15* the following conditions: *
16* *
17* The above copyright notice and this permission notice shall be *
18* included in all copies or substantial portions of the Software. *
19* *
20* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
21* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
22* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
23* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
24* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26* OTHER DEALINGS IN THE SOFTWARE. *
27***************************************************************************
28*/
29define("PHPSVN_NORMAL_REQUEST",'<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop>
30<getlastmodified xmlns="DAV:"/><version-controlled-configuration xmlns="DAV:"/><resourcetype xmlns="DAV:"/><baseline-relative-path xmlns="http://subversion.tigris.org/xmlns/dav/"/><repository-uuid xmlns="http://subversion.tigris.org/xmlns/dav/"/></prop></propfind>');
31define("PHPSVN_VERSION_REQUEST",'<?xml version="1.0" encoding="utf-8"?><propfind xmlns="DAV:"><prop><checked-in xmlns="DAV:"/></prop></propfind>');
32define("PHPSVN_LOGS_REQUEST",'<?xml version="1.0" encoding="utf-8"?> <S:log-report xmlns:S="svn:"> <S:start-revision>%d</S:start-revision><S:end-revision>%d</S:end-revision><S:path></S:path></S:log-report>');
33
34define("SVN_LAST_MODIFIED","lp1:getlastmodified");
35define("SVN_URL","D:href");
36define("SVN_RELATIVE_URL","lp3:baseline-relative-path");
37define("SVN_FILE_ID","lp3:repository-uuid");
38define("SVN_STATUS","D:status");
39define("SVN_IN_FILE","D:propstat");
40define("SVN_FILE","D:response");
41
42define("SVN_LOGS_BEGINGS","S:log-item");
43define("SVN_LOGS_VERSION","D:version-name");
44define("SVN_LOGS_AUTHOR","D:creator-displayname");
45define("SVN_LOGS_DATE","S:date");
46define("SVN_LOGS_COMMENT","D:comment");
47
48define("NOT_FOUND", 2);
49define("AUTH_REQUIRED", 3);
50define("UNKNOWN_ERROR",4);
51define("NO_ERROR",1)
52?>
diff --git a/includes/http.php b/includes/http.php deleted file mode 100755 index d0e55d7..0000000 --- a/includes/http.php +++ /dev/null
@@ -1,1982 +0,0 @@
1<?php
2/*
3 * http.php
4 *
5 * @(#) $Header: /home/mlemos/cvsroot/http/http.php,v 1.76 2008/03/18 07:59:05 mlemos Exp $
6 *
7 */
8
9class http_class
10{
11 var $host_name="";
12 var $host_port=0;
13 var $proxy_host_name="";
14 var $proxy_host_port=80;
15 var $socks_host_name = '';
16 var $socks_host_port = 1080;
17 var $socks_version = '5';
18
19 var $protocol="http";
20 var $request_method="GET";
21 var $user_agent='httpclient (http://www.phpclasses.org/httpclient $Revision: 1.76 $)';
22 var $authentication_mechanism="";
23 var $user;
24 var $password;
25 var $realm;
26 var $workstation;
27 var $proxy_authentication_mechanism="";
28 var $proxy_user;
29 var $proxy_password;
30 var $proxy_realm;
31 var $proxy_workstation;
32 var $request_uri="";
33 var $request="";
34 var $request_headers=array();
35 var $request_user;
36 var $request_password;
37 var $request_realm;
38 var $request_workstation;
39 var $proxy_request_user;
40 var $proxy_request_password;
41 var $proxy_request_realm;
42 var $proxy_request_workstation;
43 var $request_body="";
44 var $request_arguments=array();
45 var $protocol_version="1.1";
46 var $timeout=0;
47 var $data_timeout=0;
48 var $debug=0;
49 var $debug_response_body=1;
50 var $html_debug=0;
51 var $support_cookies=1;
52 var $cookies=array();
53 var $error="";
54 var $exclude_address="";
55 var $follow_redirect=0;
56 var $redirection_limit=5;
57 var $response_status="";
58 var $response_message="";
59 var $file_buffer_length=8000;
60 var $force_multipart_form_post=0;
61 var $prefer_curl = 0;
62
63 /* private variables - DO NOT ACCESS */
64
65 var $state="Disconnected";
66 var $use_curl=0;
67 var $connection=0;
68 var $content_length=0;
69 var $response="";
70 var $read_response=0;
71 var $read_length=0;
72 var $request_host="";
73 var $next_token="";
74 var $redirection_level=0;
75 var $chunked=0;
76 var $remaining_chunk=0;
77 var $last_chunk_read=0;
78 var $months=array(
79 "Jan"=>"01",
80 "Feb"=>"02",
81 "Mar"=>"03",
82 "Apr"=>"04",
83 "May"=>"05",
84 "Jun"=>"06",
85 "Jul"=>"07",
86 "Aug"=>"08",
87 "Sep"=>"09",
88 "Oct"=>"10",
89 "Nov"=>"11",
90 "Dec"=>"12");
91 var $session='';
92 var $connection_close=0;
93
94 /* Private methods - DO NOT CALL */
95
96 Function Tokenize($string,$separator="")
97 {
98 if(!strcmp($separator,""))
99 {
100 $separator=$string;
101 $string=$this->next_token;
102 }
103 for($character=0;$character<strlen($separator);$character++)
104 {
105 if(GetType($position=strpos($string,$separator[$character]))=="integer")
106 $found=(IsSet($found) ? min($found,$position) : $position);
107 }
108 if(IsSet($found))
109 {
110 $this->next_token=substr($string,$found+1);
111 return(substr($string,0,$found));
112 }
113 else
114 {
115 $this->next_token="";
116 return($string);
117 }
118 }
119
120 Function CookieEncode($value, $name)
121 {
122 return($name ? str_replace("=", "%25", $value) : str_replace(";", "%3B", $value));
123 }
124
125 Function SetError($error)
126 {
127 return($this->error=$error);
128 }
129
130 Function SetPHPError($error, &$php_error_message)
131 {
132 if(IsSet($php_error_message)
133 && strlen($php_error_message))
134 $error.=": ".$php_error_message;
135 return($this->SetError($error));
136 }
137
138 Function SetDataAccessError($error,$check_connection=0)
139 {
140 $this->error=$error;
141 if(!$this->use_curl
142 && function_exists("socket_get_status"))
143 {
144 $status=socket_get_status($this->connection);
145 if($status["timed_out"])
146 $this->error.=": data access time out";
147 elseif($status["eof"])
148 {
149 if($check_connection)
150 $this->error="";
151 else
152 $this->error.=": the server disconnected";
153 }
154 }
155 }
156
157 Function OutputDebug($message)
158 {
159 $message.="\n";
160 if($this->html_debug)
161 $message=str_replace("\n","<br />\n",HtmlEntities($message));
162 echo $message;
163 flush();
164 }
165
166 Function GetLine()
167 {
168 for($line="";;)
169 {
170 if($this->use_curl)
171 {
172 $eol=strpos($this->response,"\n",$this->read_response);
173 $data=($eol ? substr($this->response,$this->read_response,$eol+1-$this->read_response) : "");
174 $this->read_response+=strlen($data);
175 }
176 else
177 {
178 if(feof($this->connection))
179 {
180 $this->SetDataAccessError("reached the end of data while reading from the HTTP server connection");
181 return(0);
182 }
183 $data=fgets($this->connection,100);
184 }
185 if(GetType($data)!="string"
186 || strlen($data)==0)
187 {
188 $this->SetDataAccessError("it was not possible to read line from the HTTP server");
189 return(0);
190 }
191 $line.=$data;
192 $length=strlen($line);
193 if($length
194 && !strcmp(substr($line,$length-1,1),"\n"))
195 {
196 $length-=(($length>=2 && !strcmp(substr($line,$length-2,1),"\r")) ? 2 : 1);
197 $line=substr($line,0,$length);
198 if($this->debug)
199 $this->OutputDebug("S $line");
200 return($line);
201 }
202 }
203 }
204
205 Function PutLine($line)
206 {
207 if($this->debug)
208 $this->OutputDebug("C $line");
209 if(!fputs($this->connection,$line."\r\n"))
210 {
211 $this->SetDataAccessError("it was not possible to send a line to the HTTP server");
212 return(0);
213 }
214 return(1);
215 }
216
217 Function PutData($data)
218 {
219 if(strlen($data))
220 {
221 if($this->debug)
222 $this->OutputDebug('C '.$data);
223 if(!fputs($this->connection,$data))
224 {
225 $this->SetDataAccessError("it was not possible to send data to the HTTP server");
226 return(0);
227 }
228 }
229 return(1);
230 }
231
232 Function FlushData()
233 {
234 if(!fflush($this->connection))
235 {
236 $this->SetDataAccessError("it was not possible to send data to the HTTP server");
237 return(0);
238 }
239 return(1);
240 }
241
242 Function ReadChunkSize()
243 {
244 if($this->remaining_chunk==0)
245 {
246 $debug=$this->debug;
247 if(!$this->debug_response_body)
248 $this->debug=0;
249 $line=$this->GetLine();
250 $this->debug=$debug;
251 if(GetType($line)!="string")
252 return($this->SetError("4 could not read chunk start: ".$this->error));
253 $this->remaining_chunk=hexdec($line);
254 }
255 return("");
256 }
257
258 Function ReadBytes($length)
259 {
260 if($this->use_curl)
261 {
262 $bytes=substr($this->response,$this->read_response,min($length,strlen($this->response)-$this->read_response));
263 $this->read_response+=strlen($bytes);
264 if($this->debug
265 && $this->debug_response_body
266 && strlen($bytes))
267 $this->OutputDebug("S ".$bytes);
268 }
269 else
270 {
271 if($this->chunked)
272 {
273 for($bytes="",$remaining=$length;$remaining;)
274 {
275 if(strlen($this->ReadChunkSize()))
276 return("");
277 if($this->remaining_chunk==0)
278 {
279 $this->last_chunk_read=1;
280 break;
281 }
282 $ask=min($this->remaining_chunk,$remaining);
283 $chunk=@fread($this->connection,$ask);
284 $read=strlen($chunk);
285 if($read==0)
286 {
287 $this->SetDataAccessError("it was not possible to read data chunk from the HTTP server");
288 return("");
289 }
290 if($this->debug
291 && $this->debug_response_body)
292 $this->OutputDebug("S ".$chunk);
293 $bytes.=$chunk;
294 $this->remaining_chunk-=$read;
295 $remaining-=$read;
296 if($this->remaining_chunk==0)
297 {
298 if(feof($this->connection))
299 return($this->SetError("reached the end of data while reading the end of data chunk mark from the HTTP server"));
300 $data=@fread($this->connection,2);
301 if(strcmp($data,"\r\n"))
302 {
303 $this->SetDataAccessError("it was not possible to read end of data chunk from the HTTP server");
304 return("");
305 }
306 }
307 }
308 }
309 else
310 {
311 $bytes=@fread($this->connection,$length);
312 if(strlen($bytes))
313 {
314 if($this->debug
315 && $this->debug_response_body)
316 $this->OutputDebug("S ".$bytes);
317 }
318 else
319 $this->SetDataAccessError("it was not possible to read data from the HTTP server", $this->connection_close);
320 }
321 }
322 return($bytes);
323 }
324
325 Function EndOfInput()
326 {
327 if($this->use_curl)
328 return($this->read_response>=strlen($this->response));
329 if($this->chunked)
330 return($this->last_chunk_read);
331 return(feof($this->connection));
332 }
333
334 Function Resolve($domain, &$ip, $server_type)
335 {
336 if(ereg('^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$',$domain))
337 $ip=$domain;
338 else
339 {
340 if($this->debug)
341 $this->OutputDebug('Resolving '.$server_type.' server domain "'.$domain.'"...');
342 if(!strcmp($ip=@gethostbyname($domain),$domain))
343 $ip="";
344 }
345 if(strlen($ip)==0
346 || (strlen($this->exclude_address)
347 && !strcmp(@gethostbyname($this->exclude_address),$ip)))
348 return($this->SetError("could not resolve the host domain \"".$domain."\""));
349 return('');
350 }
351
352 Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP')
353 {
354 $domain=$host_name;
355 $port = $host_port;
356 if(strlen($error = $this->Resolve($domain, $ip, $server_type)))
357 return($error);
358 if(strlen($this->socks_host_name))
359 {
360 switch($this->socks_version)
361 {
362 case '4':
363 $version = 4;
364 break;
365 case '5':
366 $version = 5;
367 break;
368 default:
369 return('it was not specified a supported SOCKS protocol version');
370 break;
371 }
372 $host_ip = $ip;
373 $port = $this->socks_host_port;
374 $host_server_type = $server_type;
375 $server_type = 'SOCKS';
376 if(strlen($error = $this->Resolve($this->socks_host_name, $ip, $server_type)))
377 return($error);
378 }
379 if($this->debug)
380 $this->OutputDebug('Connecting to '.$server_type.' server IP '.$ip.' port '.$port.'...');
381 if($ssl)
382 $ip="ssl://".$ip;
383 if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
384 {
385 switch($errno)
386 {
387 case -3:
388 return($this->SetError("-3 socket could not be created"));
389 case -4:
390 return($this->SetError("-4 dns lookup on hostname \"".$host_name."\" failed"));
391 case -5:
392 return($this->SetError("-5 connection refused or timed out"));
393 case -6:
394 return($this->SetError("-6 fdopen() call failed"));
395 case -7:
396 return($this->SetError("-7 setvbuf() call failed"));
397 default:
398 return($this->SetPHPError($errno." could not connect to the host \"".$host_name."\"",$php_errormsg));
399 }
400 }
401 else
402 {
403 if($this->data_timeout
404 && function_exists("socket_set_timeout"))
405 socket_set_timeout($this->connection,$this->data_timeout,0);
406 if(strlen($this->socks_host_name))
407 {
408 if($this->debug)
409 $this->OutputDebug('Connected to the SOCKS server '.$this->socks_host_name);
410 $send_error = 'it was not possible to send data to the SOCKS server';
411 $receive_error = 'it was not possible to receive data from the SOCKS server';
412 switch($version)
413 {
414 case 4:
415 $command = 1;
416 if(!fputs($this->connection, chr($version).chr($command).pack('nN', $host_port, ip2long($host_ip)).$this->user.Chr(0)))
417 $error = $this->SetDataAccessError($send_error);
418 else
419 {
420 $response = fgets($this->connection, 9);
421 if(strlen($response) != 8)
422 $error = $this->SetDataAccessError($receive_error);
423 else
424 {
425 $socks_errors = array(
426 "\x5a"=>'',
427 "\x5b"=>'request rejected',
428 "\x5c"=>'request failed because client is not running identd (or not reachable from the server)',
429 "\x5d"=>'request failed because client\'s identd could not confirm the user ID string in the request',
430 );
431 $error_code = $response[1];
432 $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
433 if(strlen($error))
434 $error = 'SOCKS error: '.$error;
435 }
436 }
437 break;
438 case 5:
439 if($this->debug)
440 $this->OutputDebug('Negotiating the authentication method ...');
441 $methods = 1;
442 $method = 0;
443 if(!fputs($this->connection, chr($version).chr($methods).chr($method)))
444 $error = $this->SetDataAccessError($send_error);
445 else
446 {
447 $response = fgets($this->connection, 3);
448 if(strlen($response) != 2)
449 $error = $this->SetDataAccessError($receive_error);
450 elseif(Ord($response[1]) != $method)
451 $error = 'the SOCKS server requires an authentication method that is not yet supported';
452 else
453 {
454 if($this->debug)
455 $this->OutputDebug('Connecting to '.$host_server_type.' server IP '.$host_ip.' port '.$host_port.'...');
456 $command = 1;
457 $address_type = 1;
458 if(!fputs($this->connection, chr($version).chr($command)."\x00".chr($address_type).pack('Nn', ip2long($host_ip), $host_port)))
459 $error = $this->SetDataAccessError($send_error);
460 else
461 {
462 $response = fgets($this->connection, 11);
463 if(strlen($response) != 10)
464 $error = $this->SetDataAccessError($receive_error);
465 else
466 {
467 $socks_errors = array(
468 "\x00"=>'',
469 "\x01"=>'general SOCKS server failure',
470 "\x02"=>'connection not allowed by ruleset',
471 "\x03"=>'Network unreachable',
472 "\x04"=>'Host unreachable',
473 "\x05"=>'Connection refused',
474 "\x06"=>'TTL expired',
475 "\x07"=>'Command not supported',
476 "\x08"=>'Address type not supported'
477 );
478 $error_code = $response[1];
479 $error = (IsSet($socks_errors[$error_code]) ? $socks_errors[$error_code] : 'unknown');
480 if(strlen($error))
481 $error = 'SOCKS error: '.$error;
482 }
483 }
484 }
485 }
486 break;
487 default:
488 $error = 'support for SOCKS protocol version '.$this->socks_version.' is not yet implemented';
489 break;
490 }
491 if(strlen($error))
492 {
493 fclose($this->connection);
494 return($error);
495 }
496 }
497 if($this->debug)
498 $this->OutputDebug("Connected to $host_name");
499 if(strlen($this->proxy_host_name)
500 && !strcmp(strtolower($this->protocol), 'https'))
501 {
502 if(function_exists('stream_socket_enable_crypto')
503 && in_array('ssl', stream_get_transports()))
504 $this->state = "ConnectedToProxy";
505 else
506 {
507 $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.");
508 $this->state="Connected";
509 }
510 }
511 else
512 $this->state="Connected";
513 return("");
514 }
515 }
516
517 Function Disconnect()
518 {
519 if($this->debug)
520 $this->OutputDebug("Disconnected from ".$this->host_name);
521 if($this->use_curl)
522 {
523 curl_close($this->connection);
524 $this->response="";
525 }
526 else
527 fclose($this->connection);
528 $this->state="Disconnected";
529 return("");
530 }
531
532 /* Public methods */
533
534 Function GetRequestArguments($url, &$arguments)
535 {
536 if(strlen($this->error))
537 return($this->error);
538 $arguments=array();
539 $parameters=@parse_url($url);
540 if(!$parameters)
541 return($this->SetError("it was not specified a valid URL"));
542 if(!IsSet($parameters["scheme"]))
543 return($this->SetError("it was not specified the protocol type argument"));
544 switch(strtolower($parameters["scheme"]))
545 {
546 case "http":
547 case "https":
548 $arguments["Protocol"]=$parameters["scheme"];
549 break;
550 default:
551 return($parameters["scheme"]." connection scheme is not yet supported");
552 }
553 if(!IsSet($parameters["host"]))
554 return($this->SetError("it was not specified the connection host argument"));
555 $arguments["HostName"]=$parameters["host"];
556 $arguments["Headers"]=array("Host"=>$parameters["host"].(IsSet($parameters["port"]) ? ":".$parameters["port"] : ""));
557 if(IsSet($parameters["user"]))
558 {
559 $arguments["AuthUser"]=UrlDecode($parameters["user"]);
560 if(!IsSet($parameters["pass"]))
561 $arguments["AuthPassword"]="";
562 }
563 if(IsSet($parameters["pass"]))
564 {
565 if(!IsSet($parameters["user"]))
566 $arguments["AuthUser"]="";
567 $arguments["AuthPassword"]=UrlDecode($parameters["pass"]);
568 }
569 if(IsSet($parameters["port"]))
570 {
571 if(strcmp($parameters["port"],strval(intval($parameters["port"]))))
572 return($this->SetError("it was not specified a valid connection host argument"));
573 $arguments["HostPort"]=intval($parameters["port"]);
574 }
575 else
576 $arguments["HostPort"]=0;
577 $arguments["RequestURI"]=(IsSet($parameters["path"]) ? $parameters["path"] : "/").(IsSet($parameters["query"]) ? "?".$parameters["query"] : "");
578 if(strlen($this->user_agent))
579 $arguments["Headers"]["User-Agent"]=$this->user_agent;
580 return("");
581 }
582
583 Function Open($arguments)
584 {
585 if(strlen($this->error))
586 return($this->error);
587 if($this->state!="Disconnected")
588 return("1 already connected");
589 if(IsSet($arguments["HostName"]))
590 $this->host_name=$arguments["HostName"];
591 if(IsSet($arguments["HostPort"]))
592 $this->host_port=$arguments["HostPort"];
593 if(IsSet($arguments["ProxyHostName"]))
594 $this->proxy_host_name=$arguments["ProxyHostName"];
595 if(IsSet($arguments["ProxyHostPort"]))
596 $this->proxy_host_port=$arguments["ProxyHostPort"];
597 if(IsSet($arguments["SOCKSHostName"]))
598 $this->socks_host_name=$arguments["SOCKSHostName"];
599 if(IsSet($arguments["SOCKSHostPort"]))
600 $this->socks_host_port=$arguments["SOCKSHostPort"];
601 if(IsSet($arguments["SOCKSVersion"]))
602 $this->socks_version=$arguments["SOCKSVersion"];
603 if(IsSet($arguments["Protocol"]))
604 $this->protocol=$arguments["Protocol"];
605 switch(strtolower($this->protocol))
606 {
607 case "http":
608 $default_port=80;
609 break;
610 case "https":
611 $default_port=443;
612 break;
613 default:
614 return($this->SetError("2 it was not specified a valid connection protocol"));
615 }
616 if(strlen($this->proxy_host_name)==0)
617 {
618 if(strlen($this->host_name)==0)
619 return($this->SetError("2 it was not specified a valid hostname"));
620 $host_name=$this->host_name;
621 $host_port=($this->host_port ? $this->host_port : $default_port);
622 $server_type = 'HTTP';
623 }
624 else
625 {
626 $host_name=$this->proxy_host_name;
627 $host_port=$this->proxy_host_port;
628 $server_type = 'HTTP proxy';
629 }
630 $ssl=(strtolower($this->protocol)=="https" && strlen($this->proxy_host_name)==0);
631 if($ssl
632 && strlen($this->socks_host_name))
633 return($this->SetError('establishing SSL connections via a SOCKS server is not yet supported'));
634 $this->use_curl=($ssl && $this->prefer_curl && function_exists("curl_init"));
635 if($this->debug)
636 $this->OutputDebug("Connecting to ".$this->host_name);
637 if($this->use_curl)
638 {
639 $error=(($this->connection=curl_init($this->protocol."://".$this->host_name.($host_port==$default_port ? "" : ":".strval($host_port))."/")) ? "" : "Could not initialize a CURL session");
640 if(strlen($error)==0)
641 {
642 if(IsSet($arguments["SSLCertificateFile"]))
643 curl_setopt($this->connection,CURLOPT_SSLCERT,$arguments["SSLCertificateFile"]);
644 if(IsSet($arguments["SSLCertificatePassword"]))
645 curl_setopt($this->connection,CURLOPT_SSLCERTPASSWD,$arguments["SSLCertificatePassword"]);
646 if(IsSet($arguments["SSLKeyFile"]))
647 curl_setopt($this->connection,CURLOPT_SSLKEY,$arguments["SSLKeyFile"]);
648 if(IsSet($arguments["SSLKeyPassword"]))
649 curl_setopt($this->connection,CURLOPT_SSLKEYPASSWD,$arguments["SSLKeyPassword"]);
650 }
651 $this->state="Connected";
652 }
653 else
654 {
655 $error="";
656 if(strlen($this->proxy_host_name)
657 && (IsSet($arguments["SSLCertificateFile"])
658 || IsSet($arguments["SSLCertificateFile"])))
659 $error="establishing SSL connections using certificates or private keys via non-SSL proxies is not supported";
660 else
661 {
662 if($ssl)
663 {
664 if(IsSet($arguments["SSLCertificateFile"]))
665 $error="establishing SSL connections using certificates is only supported when the cURL extension is enabled";
666 elseif(IsSet($arguments["SSLKeyFile"]))
667 $error="establishing SSL connections using a private key is only supported when the cURL extension is enabled";
668 else
669 {
670 $version=explode(".",function_exists("phpversion") ? phpversion() : "3.0.7");
671 $php_version=intval($version[0])*1000000+intval($version[1])*1000+intval($version[2]);
672 if($php_version<4003000)
673 $error="establishing SSL connections requires at least PHP version 4.3.0 or having the cURL extension enabled";
674 elseif(!function_exists("extension_loaded")
675 || !extension_loaded("openssl"))
676 $error="establishing SSL connections requires the OpenSSL extension enabled";
677 }
678 }
679 if(strlen($error)==0)
680 $error=$this->Connect($host_name, $host_port, $ssl, $server_type);
681 }
682 }
683 if(strlen($error))
684 return($this->SetError($error));
685 $this->session=md5(uniqid(""));
686 return("");
687 }
688
689 Function Close()
690 {
691 if($this->state=="Disconnected")
692 return("1 already disconnected");
693 $error=$this->Disconnect();
694 if(strlen($error)==0)
695 $this->state="Disconnected";
696 return($error);
697 }
698
699 Function PickCookies(&$cookies,$secure)
700 {
701 if(IsSet($this->cookies[$secure]))
702 {
703 $now=gmdate("Y-m-d H-i-s");
704 for($domain=0,Reset($this->cookies[$secure]);$domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$domain++)
705 {
706 $domain_pattern=Key($this->cookies[$secure]);
707 $match=strlen($this->request_host)-strlen($domain_pattern);
708 if($match>=0
709 && !strcmp($domain_pattern,substr($this->request_host,$match))
710 && ($match==0
711 || $domain_pattern[0]=="."
712 || $this->request_host[$match-1]=="."))
713 {
714 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++)
715 {
716 $path=Key($this->cookies[$secure][$domain_pattern]);
717 if(strlen($this->request_uri)>=strlen($path)
718 && substr($this->request_uri,0,strlen($path))==$path)
719 {
720 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++)
721 {
722 $cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]);
723 $expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
724 if($expires==""
725 || strcmp($now,$expires)<0)
726 $cookies[$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name];
727 }
728 }
729 }
730 }
731 }
732 }
733 }
734
735 Function GetFileDefinition($file, &$definition)
736 {
737 $name="";
738 if(IsSet($file["FileName"]))
739 $name=basename($file["FileName"]);
740 if(IsSet($file["Name"]))
741 $name=$file["Name"];
742 if(strlen($name)==0)
743 return("it was not specified the file part name");
744 if(IsSet($file["Content-Type"]))
745 {
746 $content_type=$file["Content-Type"];
747 $type=$this->Tokenize(strtolower($content_type),"/");
748 $sub_type=$this->Tokenize("");
749 switch($type)
750 {
751 case "text":
752 case "image":
753 case "audio":
754 case "video":
755 case "application":
756 case "message":
757 break;
758 case "automatic":
759 switch($sub_type)
760 {
761 case "name":
762 switch(GetType($dot=strrpos($name,"."))=="integer" ? strtolower(substr($name,$dot)) : "")
763 {
764 case ".xls":
765 $content_type="application/excel";
766 break;
767 case ".hqx":
768 $content_type="application/macbinhex40";
769 break;
770 case ".doc":
771 case ".dot":
772 case ".wrd":
773 $content_type="application/msword";
774 break;
775 case ".pdf":
776 $content_type="application/pdf";
777 break;
778 case ".pgp":
779 $content_type="application/pgp";
780 break;
781 case ".ps":
782 case ".eps":
783 case ".ai":
784 $content_type="application/postscript";
785 break;
786 case ".ppt":
787 $content_type="application/powerpoint";
788 break;
789 case ".rtf":
790 $content_type="application/rtf";
791 break;
792 case ".tgz":
793 case ".gtar":
794 $content_type="application/x-gtar";
795 break;
796 case ".gz":
797 $content_type="application/x-gzip";
798 break;
799 case ".php":
800 case ".php3":
801 $content_type="application/x-httpd-php";
802 break;
803 case ".js":
804 $content_type="application/x-javascript";
805 break;
806 case ".ppd":
807 case ".psd":
808 $content_type="application/x-photoshop";
809 break;
810 case ".swf":
811 case ".swc":
812 case ".rf":
813 $content_type="application/x-shockwave-flash";
814 break;
815 case ".tar":
816 $content_type="application/x-tar";
817 break;
818 case ".zip":
819 $content_type="application/zip";
820 break;
821 case ".mid":
822 case ".midi":
823 case ".kar":
824 $content_type="audio/midi";
825 break;
826 case ".mp2":
827 case ".mp3":
828 case ".mpga":
829 $content_type="audio/mpeg";
830 break;
831 case ".ra":
832 $content_type="audio/x-realaudio";
833 break;
834 case ".wav":
835 $content_type="audio/wav";
836 break;
837 case ".bmp":
838 $content_type="image/bitmap";
839 break;
840 case ".gif":
841 $content_type="image/gif";
842 break;
843 case ".iff":
844 $content_type="image/iff";
845 break;
846 case ".jb2":
847 $content_type="image/jb2";
848 break;
849 case ".jpg":
850 case ".jpe":
851 case ".jpeg":
852 $content_type="image/jpeg";
853 break;
854 case ".jpx":
855 $content_type="image/jpx";
856 break;
857 case ".png":
858 $content_type="image/png";
859 break;
860 case ".tif":
861 case ".tiff":
862 $content_type="image/tiff";
863 break;
864 case ".wbmp":
865 $content_type="image/vnd.wap.wbmp";
866 break;
867 case ".xbm":
868 $content_type="image/xbm";
869 break;
870 case ".css":
871 $content_type="text/css";
872 break;
873 case ".txt":
874 $content_type="text/plain";
875 break;
876 case ".htm":
877 case ".html":
878 $content_type="text/html";
879 break;
880 case ".xml":
881 $content_type="text/xml";
882 break;
883 case ".mpg":
884 case ".mpe":
885 case ".mpeg":
886 $content_type="video/mpeg";
887 break;
888 case ".qt":
889 case ".mov":
890 $content_type="video/quicktime";
891 break;
892 case ".avi":
893 $content_type="video/x-ms-video";
894 break;
895 case ".eml":
896 $content_type="message/rfc822";
897 break;
898 default:
899 $content_type="application/octet-stream";
900 break;
901 }
902 break;
903 default:
904 return($content_type." is not a supported automatic content type detection method");
905 }
906 break;
907 default:
908 return($content_type." is not a supported file content type");
909 }
910 }
911 else
912 $content_type="application/octet-stream";
913 $definition=array(
914 "Content-Type"=>$content_type,
915 "NAME"=>$name
916 );
917 if(IsSet($file["FileName"]))
918 {
919 if(GetType($length=@filesize($file["FileName"]))!="integer")
920 {
921 $error="it was not possible to determine the length of the file ".$file["FileName"];
922 if(IsSet($php_errormsg)
923 && strlen($php_errormsg))
924 $error.=": ".$php_errormsg;
925 if(!file_exists($file["FileName"]))
926 $error="it was not possible to access the file ".$file["FileName"];
927 return($error);
928 }
929 $definition["FILENAME"]=$file["FileName"];
930 $definition["Content-Length"]=$length;
931 }
932 elseif(IsSet($file["Data"]))
933 $definition["Content-Length"]=strlen($definition["DATA"]=$file["Data"]);
934 else
935 return("it was not specified a valid file name");
936 return("");
937 }
938
939 Function ConnectFromProxy($arguments, &$headers)
940 {
941 if(!$this->PutLine('CONNECT '.$this->host_name.':'.($this->host_port ? $this->host_port : 443).' HTTP/1.0')
942 || (strlen($this->user_agent)
943 && !$this->PutLine('User-Agent: '.$this->user_agent))
944 || (IsSet($arguments['Headers']['Proxy-Authorization'])
945 && !$this->PutLine('Proxy-Authorization: '.$arguments['Headers']['Proxy-Authorization']))
946 || !$this->PutLine(''))
947 {
948 $this->Disconnect();
949 return($this->error);
950 }
951 $this->state = "ConnectSent";
952 if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
953 return($error);
954 $proxy_authorization="";
955 while(!strcmp($this->response_status, "100"))
956 {
957 $this->state="ConnectSent";
958 if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
959 return($error);
960 }
961 switch($this->response_status)
962 {
963 case "200":
964 if(!@stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
965 {
966 $this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg);
967 $this->Disconnect();
968 return($this->error);
969 }
970 $this->state = "Connected";
971 break;
972 case "407":
973 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)))
974 return($error);
975 break;
976 default:
977 return($this->SetError("unable to send request via proxy"));
978 }
979 return("");
980 }
981
982 Function SendRequest($arguments)
983 {
984 if(strlen($this->error))
985 return($this->error);
986 if(IsSet($arguments["ProxyUser"]))
987 $this->proxy_request_user=$arguments["ProxyUser"];
988 elseif(IsSet($this->proxy_user))
989 $this->proxy_request_user=$this->proxy_user;
990 if(IsSet($arguments["ProxyPassword"]))
991 $this->proxy_request_password=$arguments["ProxyPassword"];
992 elseif(IsSet($this->proxy_password))
993 $this->proxy_request_password=$this->proxy_password;
994 if(IsSet($arguments["ProxyRealm"]))
995 $this->proxy_request_realm=$arguments["ProxyRealm"];
996 elseif(IsSet($this->proxy_realm))
997 $this->proxy_request_realm=$this->proxy_realm;
998 if(IsSet($arguments["ProxyWorkstation"]))
999 $this->proxy_request_workstation=$arguments["ProxyWorkstation"];
1000 elseif(IsSet($this->proxy_workstation))
1001 $this->proxy_request_workstation=$this->proxy_workstation;
1002 switch($this->state)
1003 {
1004 case "Disconnected":
1005 return($this->SetError("1 connection was not yet established"));
1006 case "Connected":
1007 $connect = 0;
1008 break;
1009 case "ConnectedToProxy":
1010 if(strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1011 return($error);
1012 $connect = 1;
1013 break;
1014 default:
1015 return($this->SetError("2 can not send request in the current connection state"));
1016 }
1017 if(IsSet($arguments["RequestMethod"]))
1018 $this->request_method=$arguments["RequestMethod"];
1019 if(IsSet($arguments["User-Agent"]))
1020 $this->user_agent=$arguments["User-Agent"];
1021 if(!IsSet($arguments["Headers"]["User-Agent"])
1022 && strlen($this->user_agent))
1023 $arguments["Headers"]["User-Agent"]=$this->user_agent;
1024 if(strlen($this->request_method)==0)
1025 return($this->SetError("3 it was not specified a valid request method"));
1026 if(IsSet($arguments["RequestURI"]))
1027 $this->request_uri=$arguments["RequestURI"];
1028 if(strlen($this->request_uri)==0
1029 || substr($this->request_uri,0,1)!="/")
1030 return($this->SetError("4 it was not specified a valid request URI"));
1031 $this->request_arguments=$arguments;
1032 $this->request_headers=(IsSet($arguments["Headers"]) ? $arguments["Headers"] : array());
1033 $body_length=0;
1034 $this->request_body="";
1035 $get_body=1;
1036 if($this->request_method=="POST"
1037 || $this->request_method=="PUT")
1038 {
1039 if(IsSet($arguments['StreamRequest']))
1040 {
1041 $get_body = 0;
1042 $this->request_headers["Transfer-Encoding"]="chunked";
1043 }
1044 elseif(IsSet($arguments["PostFiles"])
1045 || ($this->force_multipart_form_post
1046 && IsSet($arguments["PostValues"])))
1047 {
1048 $boundary="--".md5(uniqid(time()));
1049 $this->request_headers["Content-Type"]="multipart/form-data; boundary=".$boundary.(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1050 $post_parts=array();
1051 if(IsSet($arguments["PostValues"]))
1052 {
1053 $values=$arguments["PostValues"];
1054 if(GetType($values)!="array")
1055 return($this->SetError("5 it was not specified a valid POST method values array"));
1056 for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
1057 {
1058 $input=Key($values);
1059 $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"\r\n\r\n";
1060 $data=$values[$input];
1061 $post_parts[]=array("HEADERS"=>$headers,"DATA"=>$data);
1062 $body_length+=strlen($headers)+strlen($data)+strlen("\r\n");
1063 }
1064 }
1065 $body_length+=strlen("--".$boundary."--\r\n");
1066 $files=(IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());
1067 Reset($files);
1068 $end=(GetType($input=Key($files))!="string");
1069 for(;!$end;)
1070 {
1071 if(strlen($error=$this->GetFileDefinition($files[$input],$definition)))
1072 return("3 ".$error);
1073 $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"; filename=\"".$definition["NAME"]."\"\r\nContent-Type: ".$definition["Content-Type"]."\r\n\r\n";
1074 $part=count($post_parts);
1075 $post_parts[$part]=array("HEADERS"=>$headers);
1076 if(IsSet($definition["FILENAME"]))
1077 {
1078 $post_parts[$part]["FILENAME"]=$definition["FILENAME"];
1079 $data="";
1080 }
1081 else
1082 $data=$definition["DATA"];
1083 $post_parts[$part]["DATA"]=$data;
1084 $body_length+=strlen($headers)+$definition["Content-Length"]+strlen("\r\n");
1085 Next($files);
1086 $end=(GetType($input=Key($files))!="string");
1087 }
1088 $get_body=0;
1089 }
1090 elseif(IsSet($arguments["PostValues"]))
1091 {
1092 $values=$arguments["PostValues"];
1093 if(GetType($values)!="array")
1094 return($this->SetError("5 it was not specified a valid POST method values array"));
1095 for(Reset($values),$value=0;$value<count($values);Next($values),$value++)
1096 {
1097 $k=Key($values);
1098 if(GetType($values[$k])=="array")
1099 {
1100 for($v = 0; $v < count($values[$k]); $v++)
1101 {
1102 if($value+$v>0)
1103 $this->request_body.="&";
1104 $this->request_body.=UrlEncode($k)."=".UrlEncode($values[$k][$v]);
1105 }
1106 }
1107 else
1108 {
1109 if($value>0)
1110 $this->request_body.="&";
1111 $this->request_body.=UrlEncode($k)."=".UrlEncode($values[$k]);
1112 }
1113 }
1114 $this->request_headers["Content-Type"]="application/x-www-form-urlencoded".(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1115 $get_body=0;
1116 }
1117 }
1118 if($get_body
1119 && (IsSet($arguments["Body"])
1120 || IsSet($arguments["BodyStream"])))
1121 {
1122 if(IsSet($arguments["Body"]))
1123 $this->request_body=$arguments["Body"];
1124 else
1125 {
1126 $stream=$arguments["BodyStream"];
1127 $this->request_body="";
1128 for($part=0; $part<count($stream); $part++)
1129 {
1130 if(IsSet($stream[$part]["Data"]))
1131 $this->request_body.=$stream[$part]["Data"];
1132 elseif(IsSet($stream[$part]["File"]))
1133 {
1134 if(!($file=@fopen($stream[$part]["File"],"rb")))
1135 return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg));
1136 while(!feof($file))
1137 {
1138 if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1139 {
1140 $error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg);
1141 fclose($file);
1142 return($error);
1143 }
1144 $this->request_body.=$block;
1145 }
1146 fclose($file);
1147 }
1148 else
1149 return("5 it was not specified a valid file or data body stream element at position ".$part);
1150 }
1151 }
1152 if(!IsSet($this->request_headers["Content-Type"]))
1153 $this->request_headers["Content-Type"]="application/octet-stream".(IsSet($arguments["CharSet"]) ? "; charset=".$arguments["CharSet"] : "");
1154 }
1155 if(IsSet($arguments["AuthUser"]))
1156 $this->request_user=$arguments["AuthUser"];
1157 elseif(IsSet($this->user))
1158 $this->request_user=$this->user;
1159 if(IsSet($arguments["AuthPassword"]))
1160 $this->request_password=$arguments["AuthPassword"];
1161 elseif(IsSet($this->password))
1162 $this->request_password=$this->password;
1163 if(IsSet($arguments["AuthRealm"]))
1164 $this->request_realm=$arguments["AuthRealm"];
1165 elseif(IsSet($this->realm))
1166 $this->request_realm=$this->realm;
1167 if(IsSet($arguments["AuthWorkstation"]))
1168 $this->request_workstation=$arguments["AuthWorkstation"];
1169 elseif(IsSet($this->workstation))
1170 $this->request_workstation=$this->workstation;
1171 if(strlen($this->proxy_host_name)==0
1172 || $connect)
1173 $request_uri=$this->request_uri;
1174 else
1175 {
1176 switch(strtolower($this->protocol))
1177 {
1178 case "http":
1179 $default_port=80;
1180 break;
1181 case "https":
1182 $default_port=443;
1183 break;
1184 }
1185 $request_uri=strtolower($this->protocol)."://".$this->host_name.(($this->host_port==0 || $this->host_port==$default_port) ? "" : ":".$this->host_port).$this->request_uri;
1186 }
1187 if($this->use_curl)
1188 {
1189 $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"));
1190 $curl_version=100000*intval($this->Tokenize($version,"."))+1000*intval($this->Tokenize("."))+intval($this->Tokenize(""));
1191 $protocol_version=($curl_version<713002 ? "1.0" : $this->protocol_version);
1192 }
1193 else
1194 $protocol_version=$this->protocol_version;
1195 $this->request=$this->request_method." ".$request_uri." HTTP/".$protocol_version;
1196 if($body_length
1197 || ($body_length=strlen($this->request_body)))
1198 $this->request_headers["Content-Length"]=$body_length;
1199 for($headers=array(),$host_set=0,Reset($this->request_headers),$header=0;$header<count($this->request_headers);Next($this->request_headers),$header++)
1200 {
1201 $header_name=Key($this->request_headers);
1202 $header_value=$this->request_headers[$header_name];
1203 if(GetType($header_value)=="array")
1204 {
1205 for(Reset($header_value),$value=0;$value<count($header_value);Next($header_value),$value++)
1206 $headers[]=$header_name.": ".$header_value[Key($header_value)];
1207 }
1208 else
1209 $headers[]=$header_name.": ".$header_value;
1210 if(strtolower(Key($this->request_headers))=="host")
1211 {
1212 $this->request_host=strtolower($header_value);
1213 $host_set=1;
1214 }
1215 }
1216 if(!$host_set)
1217 {
1218 $headers[]="Host: ".$this->host_name;
1219 $this->request_host=strtolower($this->host_name);
1220 }
1221 if(count($this->cookies))
1222 {
1223 $cookies=array();
1224 $this->PickCookies($cookies,0);
1225 if(strtolower($this->protocol)=="https")
1226 $this->PickCookies($cookies,1);
1227 if(count($cookies))
1228 {
1229 $h=count($headers);
1230 $headers[$h]="Cookie:";
1231 for(Reset($cookies),$cookie=0;$cookie<count($cookies);Next($cookies),$cookie++)
1232 {
1233 $cookie_name=Key($cookies);
1234 $headers[$h].=" ".$cookie_name."=".$cookies[$cookie_name]["value"].";";
1235 }
1236 }
1237 }
1238 $next_state = "RequestSent";
1239 if($this->use_curl)
1240 {
1241 if(IsSet($arguments['StreamRequest']))
1242 return($this->SetError("Streaming request data is not supported when using Curl"));
1243 if($body_length
1244 && strlen($this->request_body)==0)
1245 {
1246 for($request_body="",$success=1,$part=0;$part<count($post_parts);$part++)
1247 {
1248 $request_body.=$post_parts[$part]["HEADERS"].$post_parts[$part]["DATA"];
1249 if(IsSet($post_parts[$part]["FILENAME"]))
1250 {
1251 if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
1252 {
1253 $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg);
1254 $success=0;
1255 break;
1256 }
1257 while(!feof($file))
1258 {
1259 if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1260 {
1261 $this->SetPHPError("could not read upload file", $php_errormsg);
1262 $success=0;
1263 break;
1264 }
1265 $request_body.=$block;
1266 }
1267 fclose($file);
1268 if(!$success)
1269 break;
1270 }
1271 $request_body.="\r\n";
1272 }
1273 $request_body.="--".$boundary."--\r\n";
1274 }
1275 else
1276 $request_body=$this->request_body;
1277 curl_setopt($this->connection,CURLOPT_HEADER,1);
1278 curl_setopt($this->connection,CURLOPT_RETURNTRANSFER,1);
1279 if($this->timeout)
1280 curl_setopt($this->connection,CURLOPT_TIMEOUT,$this->timeout);
1281 curl_setopt($this->connection,CURLOPT_SSL_VERIFYPEER,0);
1282 curl_setopt($this->connection,CURLOPT_SSL_VERIFYHOST,0);
1283 $request=$this->request."\r\n".implode("\r\n",$headers)."\r\n\r\n".$request_body;
1284 curl_setopt($this->connection,CURLOPT_CUSTOMREQUEST,$request);
1285 if($this->debug)
1286 $this->OutputDebug("C ".$request);
1287 if(!($success=(strlen($this->response=curl_exec($this->connection))!=0)))
1288 {
1289 $error=curl_error($this->connection);
1290 $this->SetError("Could not execute the request".(strlen($error) ? ": ".$error : ""));
1291 }
1292 }
1293 else
1294 {
1295 if(($success=$this->PutLine($this->request)))
1296 {
1297 for($header=0;$header<count($headers);$header++)
1298 {
1299 if(!$success=$this->PutLine($headers[$header]))
1300 break;
1301 }
1302 if($success
1303 && ($success=$this->PutLine("")))
1304 {
1305 if(IsSet($arguments['StreamRequest']))
1306 $next_state = "SendingRequestBody";
1307 elseif($body_length)
1308 {
1309 if(strlen($this->request_body))
1310 $success=$this->PutData($this->request_body);
1311 else
1312 {
1313 for($part=0;$part<count($post_parts);$part++)
1314 {
1315 if(!($success=$this->PutData($post_parts[$part]["HEADERS"]))
1316 || !($success=$this->PutData($post_parts[$part]["DATA"])))
1317 break;
1318 if(IsSet($post_parts[$part]["FILENAME"]))
1319 {
1320 if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
1321 {
1322 $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg);
1323 $success=0;
1324 break;
1325 }
1326 while(!feof($file))
1327 {
1328 if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1329 {
1330 $this->SetPHPError("could not read upload file", $php_errormsg);
1331 $success=0;
1332 break;
1333 }
1334 if(!($success=$this->PutData($block)))
1335 break;
1336 }
1337 fclose($file);
1338 if(!$success)
1339 break;
1340 }
1341 if(!($success=$this->PutLine("")))
1342 break;
1343 }
1344 if($success)
1345 $success=$this->PutLine("--".$boundary."--");
1346 }
1347 if($success)
1348 $sucess=$this->FlushData();
1349 }
1350 }
1351 }
1352 }
1353 if(!$success)
1354 return($this->SetError("5 could not send the HTTP request: ".$this->error));
1355 $this->state=$next_state;
1356 return("");
1357 }
1358
1359 Function SetCookie($name, $value, $expires="" , $path="/" , $domain="" , $secure=0, $verbatim=0)
1360 {
1361 if(strlen($this->error))
1362 return($this->error);
1363 if(strlen($name)==0)
1364 return($this->SetError("it was not specified a valid cookie name"));
1365 if(strlen($path)==0
1366 || strcmp($path[0],"/"))
1367 return($this->SetError($path." is not a valid path for setting cookie ".$name));
1368 if($domain==""
1369 || !strpos($domain,".",$domain[0]=="." ? 1 : 0))
1370 return($this->SetError($domain." is not a valid domain for setting cookie ".$name));
1371 $domain=strtolower($domain);
1372 if(!strcmp($domain[0],"."))
1373 $domain=substr($domain,1);
1374 if(!$verbatim)
1375 {
1376 $name=$this->CookieEncode($name,1);
1377 $value=$this->CookieEncode($value,0);
1378 }
1379 $secure=intval($secure);
1380 $this->cookies[$secure][$domain][$path][$name]=array(
1381 "name"=>$name,
1382 "value"=>$value,
1383 "domain"=>$domain,
1384 "path"=>$path,
1385 "expires"=>$expires,
1386 "secure"=>$secure
1387 );
1388 return("");
1389 }
1390
1391 Function SendRequestBody($data, $end_of_data)
1392 {
1393 if(strlen($this->error))
1394 return($this->error);
1395 switch($this->state)
1396 {
1397 case "Disconnected":
1398 return($this->SetError("1 connection was not yet established"));
1399 case "Connected":
1400 case "ConnectedToProxy":
1401 return($this->SetError("2 request was not sent"));
1402 case "SendingRequestBody":
1403 break;
1404 case "RequestSent":
1405 return($this->SetError("3 request body was already sent"));
1406 default:
1407 return($this->SetError("4 can not send the request body in the current connection state"));
1408 }
1409 $length = strlen($data);
1410 if($length)
1411 {
1412 $size = dechex($length)."\r\n";
1413 if(!$this->PutData($size)
1414 || !$this->PutData($data))
1415 return($this->error);
1416 }
1417 if($end_of_data)
1418 {
1419 $size = "0\r\n";
1420 if(!$this->PutData($size))
1421 return($this->error);
1422 $this->state = "RequestSent";
1423 }
1424 return("");
1425 }
1426
1427 Function ReadReplyHeadersResponse(&$headers)
1428 {
1429 $headers=array();
1430 if(strlen($this->error))
1431 return($this->error);
1432 switch($this->state)
1433 {
1434 case "Disconnected":
1435 return($this->SetError("1 connection was not yet established"));
1436 case "Connected":
1437 return($this->SetError("2 request was not sent"));
1438 case "ConnectedToProxy":
1439 return($this->SetError("2 connection from the remote server from the proxy was not yet established"));
1440 case "SendingRequestBody":
1441 return($this->SetError("4 request body data was not completely sent"));
1442 case "ConnectSent":
1443 $connect = 1;
1444 break;
1445 case "RequestSent":
1446 $connect = 0;
1447 break;
1448 default:
1449 return($this->SetError("3 can not get request headers in the current connection state"));
1450 }
1451 $this->content_length=$this->read_length=$this->read_response=$this->remaining_chunk=0;
1452 $this->content_length_set=$this->chunked=$this->last_chunk_read=$chunked=0;
1453 $this->connection_close=0;
1454 for($this->response_status="";;)
1455 {
1456 $line=$this->GetLine();
1457 if(GetType($line)!="string")
1458 return($this->SetError("4 could not read request reply: ".$this->error));
1459 if(strlen($this->response_status)==0)
1460 {
1461 if(!eregi($match="^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$",$line,$matches))
1462 return($this->SetError("3 it was received an unexpected HTTP response status"));
1463 $this->response_status=$matches[1];
1464 $this->response_message=$matches[2];
1465 }
1466 if($line=="")
1467 {
1468 if(strlen($this->response_status)==0)
1469 return($this->SetError("3 it was not received HTTP response status"));
1470 $this->state=($connect ? "GotConnectHeaders" : "GotReplyHeaders");
1471 break;
1472 }
1473 $header_name=strtolower($this->Tokenize($line,":"));
1474 $header_value=Trim(Chop($this->Tokenize("\r\n")));
1475 if(IsSet($headers[$header_name]))
1476 {
1477 if(GetType($headers[$header_name])=="string")
1478 $headers[$header_name]=array($headers[$header_name]);
1479 $headers[$header_name][]=$header_value;
1480 }
1481 else
1482 $headers[$header_name]=$header_value;
1483 if(!$connect)
1484 {
1485 switch($header_name)
1486 {
1487 case "content-length":
1488 $this->content_length=intval($headers[$header_name]);
1489 $this->content_length_set=1;
1490 break;
1491 case "transfer-encoding":
1492 $encoding=$this->Tokenize($header_value,"; \t");
1493 if(!$this->use_curl
1494 && !strcmp($encoding,"chunked"))
1495 $chunked=1;
1496 break;
1497 case "set-cookie":
1498 if($this->support_cookies)
1499 {
1500 if(GetType($headers[$header_name])=="array")
1501 $cookie_headers=$headers[$header_name];
1502 else
1503 $cookie_headers=array($headers[$header_name]);
1504 for($cookie=0;$cookie<count($cookie_headers);$cookie++)
1505 {
1506 $cookie_name=trim($this->Tokenize($cookie_headers[$cookie],"="));
1507 $cookie_value=$this->Tokenize(";");
1508 $domain=$this->request_host;
1509 $path="/";
1510 $expires="";
1511 $secure=0;
1512 while(($name=trim(UrlDecode($this->Tokenize("="))))!="")
1513 {
1514 $value=UrlDecode($this->Tokenize(";"));
1515 switch($name)
1516 {
1517 case "domain":
1518 $domain=$value;
1519 break;
1520 case "path":
1521 $path=$value;
1522 break;
1523 case "expires":
1524 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))
1525 {
1526 $year=intval($matches[5]);
1527 if($year<1900)
1528 $year+=($year<70 ? 2000 : 1900);
1529 $expires="$year-".$this->months[$matches[4]]."-".$matches[3]." ".$matches[6].":".$matches[7].":".$matches[8];
1530 }
1531 break;
1532 case "secure":
1533 $secure=1;
1534 break;
1535 }
1536 }
1537 if(strlen($this->SetCookie($cookie_name, $cookie_value, $expires, $path , $domain, $secure, 1)))
1538 $this->error="";
1539 }
1540 }
1541 break;
1542 case "connection":
1543 $this->connection_close=!strcmp(strtolower($header_value),"close");
1544 break;
1545 }
1546 }
1547 }
1548 $this->chunked=$chunked;
1549 if($this->content_length_set)
1550 $this->connection_close=0;
1551 return("");
1552 }
1553
1554 Function Redirect(&$headers)
1555 {
1556 if($this->follow_redirect)
1557 {
1558 if(!IsSet($headers["location"])
1559 || (GetType($headers["location"])!="array"
1560 && strlen($location=$headers["location"])==0)
1561 || (GetType($headers["location"])=="array"
1562 && strlen($location=$headers["location"][0])==0))
1563 return($this->SetError("3 it was received a redirect without location URL"));
1564 if(strcmp($location[0],"/"))
1565 {
1566 $location_arguments=parse_url($location);
1567 if(!IsSet($location_arguments["scheme"]))
1568 $location=((GetType($end=strrpos($this->request_uri,"/"))=="integer" && $end>1) ? substr($this->request_uri,0,$end) : "")."/".$location;
1569 }
1570 if(!strcmp($location[0],"/"))
1571 $location=$this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location;
1572 $error=$this->GetRequestArguments($location,$arguments);
1573 if(strlen($error))
1574 return($this->SetError("could not process redirect url: ".$error));
1575 $arguments["RequestMethod"]="GET";
1576 if(strlen($error=$this->Close())==0
1577 && strlen($error=$this->Open($arguments))==0
1578 && strlen($error=$this->SendRequest($arguments))==0)
1579 {
1580 $this->redirection_level++;
1581 if($this->redirection_level>$this->redirection_limit)
1582 $error="it was exceeded the limit of request redirections";
1583 else
1584 $error=$this->ReadReplyHeaders($headers);
1585 $this->redirection_level--;
1586 }
1587 if(strlen($error))
1588 return($this->SetError($error));
1589 }
1590 return("");
1591 }
1592
1593 Function Authenticate(&$headers, $proxy, &$proxy_authorization, &$user, &$password, &$realm, &$workstation)
1594 {
1595 if($proxy)
1596 {
1597 $authenticate_header="proxy-authenticate";
1598 $authorization_header="Proxy-Authorization";
1599 $authenticate_status="407";
1600 $authentication_mechanism=$this->proxy_authentication_mechanism;
1601 }
1602 else
1603 {
1604 $authenticate_header="www-authenticate";
1605 $authorization_header="Authorization";
1606 $authenticate_status="401";
1607 $authentication_mechanism=$this->authentication_mechanism;
1608 }
1609 if(IsSet($headers[$authenticate_header]))
1610 {
1611 if(function_exists("class_exists")
1612 && !class_exists("sasl_client_class"))
1613 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"));
1614 if(GetType($headers[$authenticate_header])=="array")
1615 $authenticate=$headers[$authenticate_header];
1616 else
1617 $authenticate=array($headers[$authenticate_header]);
1618 for($response="", $mechanisms=array(),$m=0;$m<count($authenticate);$m++)
1619 {
1620 $mechanism=$this->Tokenize($authenticate[$m]," ");
1621 $response=$this->Tokenize("");
1622 if(strlen($authentication_mechanism))
1623 {
1624 if(!strcmp($authentication_mechanism,$mechanism))
1625 {
1626 $mechanisms[]=$mechanism;
1627 break;
1628 }
1629 }
1630 else
1631 $mechanisms[]=$mechanism;
1632 }
1633 $sasl=new sasl_client_class;
1634 if(IsSet($user))
1635 $sasl->SetCredential("user",$user);
1636 if(IsSet($password))
1637 $sasl->SetCredential("password",$password);
1638 if(IsSet($realm))
1639 $sasl->SetCredential("realm",$realm);
1640 if(IsSet($workstation))
1641 $sasl->SetCredential("workstation",$workstation);
1642 $sasl->SetCredential("uri",$this->request_uri);
1643 $sasl->SetCredential("method",$this->request_method);
1644 $sasl->SetCredential("session",$this->session);
1645 do
1646 {
1647 $status=$sasl->Start($mechanisms,$message,$interactions);
1648 }
1649 while($status==SASL_INTERACT);
1650 switch($status)
1651 {
1652 case SASL_CONTINUE:
1653 break;
1654 case SASL_NOMECH:
1655 return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".(strlen($authentication_mechanism) ? "authentication mechanism ".$authentication_mechanism." may not be used: " : "").$sasl->error));
1656 default:
1657 return($this->SetError("Could not start the SASL ".($proxy ? "proxy " : "")."authentication client: ".$sasl->error));
1658 }
1659 if($proxy >= 0)
1660 {
1661 for(;;)
1662 {
1663 if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
1664 return($error);
1665 if(strlen($body)==0)
1666 break;
1667 }
1668 }
1669 $authorization_value=$sasl->mechanism.(IsSet($message) ? " ".($sasl->encode_response ? base64_encode($message) : $message) : "");
1670 $request_arguments=$this->request_arguments;
1671 $arguments=$request_arguments;
1672 $arguments["Headers"][$authorization_header]=$authorization_value;
1673 if(!$proxy
1674 && strlen($proxy_authorization))
1675 $arguments["Headers"]["Proxy-Authorization"]=$proxy_authorization;
1676 if(strlen($error=$this->Close())
1677 || strlen($error=$this->Open($arguments)))
1678 return($this->SetError($error));
1679 $authenticated=0;
1680 if(IsSet($message))
1681 {
1682 if($proxy < 0)
1683 {
1684 if(strlen($error=$this->ConnectFromProxy($arguments, $headers)))
1685 return($this->SetError($error));
1686 }
1687 else
1688 {
1689 if(strlen($error=$this->SendRequest($arguments))
1690 || strlen($error=$this->ReadReplyHeadersResponse($headers)))
1691 return($this->SetError($error));
1692 }
1693 if(!IsSet($headers[$authenticate_header]))
1694 $authenticate=array();
1695 elseif(GetType($headers[$authenticate_header])=="array")
1696 $authenticate=$headers[$authenticate_header];
1697 else
1698 $authenticate=array($headers[$authenticate_header]);
1699 for($mechanism=0;$mechanism<count($authenticate);$mechanism++)
1700 {
1701 if(!strcmp($this->Tokenize($authenticate[$mechanism]," "),$sasl->mechanism))
1702 {
1703 $response=$this->Tokenize("");
1704 break;
1705 }
1706 }
1707 switch($this->response_status)
1708 {
1709 case $authenticate_status:
1710 break;
1711 case "301":
1712 case "302":
1713 case "303":
1714 case "307":
1715 if($proxy >= 0)
1716 return($this->Redirect($headers));
1717 default:
1718 if(intval($this->response_status/100)==2)
1719 {
1720 if($proxy)
1721 $proxy_authorization=$authorization_value;
1722 $authenticated=1;
1723 break;
1724 }
1725 if($proxy
1726 && !strcmp($this->response_status,"401"))
1727 {
1728 $proxy_authorization=$authorization_value;
1729 $authenticated=1;
1730 break;
1731 }
1732 return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message));
1733 }
1734 }
1735 for(;!$authenticated;)
1736 {
1737 do
1738 {
1739 $status=$sasl->Step($response,$message,$interactions);
1740 }
1741 while($status==SASL_INTERACT);
1742 switch($status)
1743 {
1744 case SASL_CONTINUE:
1745 $authorization_value=$sasl->mechanism.(IsSet($message) ? " ".($sasl->encode_response ? base64_encode($message) : $message) : "");
1746 $arguments=$request_arguments;
1747 $arguments["Headers"][$authorization_header]=$authorization_value;
1748 if(!$proxy
1749 && strlen($proxy_authorization))
1750 $arguments["Headers"]["Proxy-Authorization"]=$proxy_authorization;
1751 if($proxy < 0)
1752 {
1753 if(strlen($error=$this->ConnectFromProxy($arguments, $headers)))
1754 return($this->SetError($error));
1755 }
1756 else
1757 {
1758 if(strlen($error=$this->SendRequest($arguments))
1759 || strlen($error=$this->ReadReplyHeadersResponse($headers)))
1760 return($this->SetError($error));
1761 }
1762 switch($this->response_status)
1763 {
1764 case $authenticate_status:
1765 if(GetType($headers[$authenticate_header])=="array")
1766 $authenticate=$headers[$authenticate_header];
1767 else
1768 $authenticate=array($headers[$authenticate_header]);
1769 for($response="",$mechanism=0;$mechanism<count($authenticate);$mechanism++)
1770 {
1771 if(!strcmp($this->Tokenize($authenticate[$mechanism]," "),$sasl->mechanism))
1772 {
1773 $response=$this->Tokenize("");
1774 break;
1775 }
1776 }
1777 if($proxy >= 0)
1778 {
1779 for(;;)
1780 {
1781 if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
1782 return($error);
1783 if(strlen($body)==0)
1784 break;
1785 }
1786 }
1787 $this->state="Connected";
1788 break;
1789 case "301":
1790 case "302":
1791 case "303":
1792 case "307":
1793 if($proxy >= 0)
1794 return($this->Redirect($headers));
1795 default:
1796 if(intval($this->response_status/100)==2)
1797 {
1798 if($proxy)
1799 $proxy_authorization=$authorization_value;
1800 $authenticated=1;
1801 break;
1802 }
1803 if($proxy
1804 && !strcmp($this->response_status,"401"))
1805 {
1806 $proxy_authorization=$authorization_value;
1807 $authenticated=1;
1808 break;
1809 }
1810 return($this->SetError(($proxy ? "proxy " : "")."authentication error: ".$this->response_status." ".$this->response_message));
1811 }
1812 break;
1813 default:
1814 return($this->SetError("Could not process the SASL ".($proxy ? "proxy " : "")."authentication step: ".$sasl->error));
1815 }
1816 }
1817 }
1818 return("");
1819 }
1820
1821 Function ReadReplyHeaders(&$headers)
1822 {
1823 if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1824 return($error);
1825 $proxy_authorization="";
1826 while(!strcmp($this->response_status, "100"))
1827 {
1828 $this->state="RequestSent";
1829 if(strlen($error=$this->ReadReplyHeadersResponse($headers)))
1830 return($error);
1831 }
1832 switch($this->response_status)
1833 {
1834 case "301":
1835 case "302":
1836 case "303":
1837 case "307":
1838 if(strlen($error=$this->Redirect($headers)))
1839 return($error);
1840 break;
1841 case "407":
1842 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)))
1843 return($error);
1844 if(strcmp($this->response_status,"401"))
1845 return("");
1846 case "401":
1847 return($this->Authenticate($headers, 0, $proxy_authorization, $this->request_user, $this->request_password, $this->request_realm, $this->request_workstation));
1848 }
1849 return("");
1850 }
1851
1852 Function ReadReplyBody(&$body,$length)
1853 {
1854 $body="";
1855 if(strlen($this->error))
1856 return($this->error);
1857 switch($this->state)
1858 {
1859 case "Disconnected":
1860 return($this->SetError("1 connection was not yet established"));
1861 case "Connected":
1862 case "ConnectedToProxy":
1863 return($this->SetError("2 request was not sent"));
1864 case "RequestSent":
1865 if(($error=$this->ReadReplyHeaders($headers))!="")
1866 return($error);
1867 break;
1868 case "GotReplyHeaders":
1869 break;
1870 default:
1871 return($this->SetError("3 can not get request headers in the current connection state"));
1872 }
1873 if($this->content_length_set)
1874 $length=min($this->content_length-$this->read_length,$length);
1875 if($length>0
1876 && !$this->EndOfInput()
1877 && ($body=$this->ReadBytes($length))=="")
1878 {
1879 if(strlen($this->error))
1880 return($this->SetError("4 could not get the request reply body: ".$this->error));
1881 }
1882 $this->read_length+=strlen($body);
1883 return("");
1884 }
1885
1886 Function SaveCookies(&$cookies, $domain='', $secure_only=0, $persistent_only=0)
1887 {
1888 $now=gmdate("Y-m-d H-i-s");
1889 $cookies=array();
1890 for($secure_cookies=0,Reset($this->cookies);$secure_cookies<count($this->cookies);Next($this->cookies),$secure_cookies++)
1891 {
1892 $secure=Key($this->cookies);
1893 if(!$secure_only
1894 || $secure)
1895 {
1896 for($cookie_domain=0,Reset($this->cookies[$secure]);$cookie_domain<count($this->cookies[$secure]);Next($this->cookies[$secure]),$cookie_domain++)
1897 {
1898 $domain_pattern=Key($this->cookies[$secure]);
1899 $match=strlen($domain)-strlen($domain_pattern);
1900 if(strlen($domain)==0
1901 || ($match>=0
1902 && !strcmp($domain_pattern,substr($domain,$match))
1903 && ($match==0
1904 || $domain_pattern[0]=="."
1905 || $domain[$match-1]==".")))
1906 {
1907 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++)
1908 {
1909 $path=Key($this->cookies[$secure][$domain_pattern]);
1910 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++)
1911 {
1912 $cookie_name=Key($this->cookies[$secure][$domain_pattern][$path]);
1913 $expires=$this->cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
1914 if((!$persistent_only
1915 && strlen($expires)==0)
1916 || (strlen($expires)
1917 && strcmp($now,$expires)<0))
1918 $cookies[$secure][$domain_pattern][$path][$cookie_name]=$this->cookies[$secure][$domain_pattern][$path][$cookie_name];
1919 }
1920 }
1921 }
1922 }
1923 }
1924 }
1925 }
1926
1927 Function SavePersistentCookies(&$cookies, $domain='', $secure_only=0)
1928 {
1929 $this->SaveCookies($cookies, $domain, $secure_only, 1);
1930 }
1931
1932 Function GetPersistentCookies(&$cookies, $domain='', $secure_only=0)
1933 {
1934 $this->SavePersistentCookies($cookies, $domain, $secure_only);
1935 }
1936
1937 Function RestoreCookies($cookies, $clear=1)
1938 {
1939 $new_cookies=($clear ? array() : $this->cookies);
1940 for($secure_cookies=0, Reset($cookies); $secure_cookies<count($cookies); Next($cookies), $secure_cookies++)
1941 {
1942 $secure=Key($cookies);
1943 if(GetType($secure)!="integer")
1944 return($this->SetError("invalid cookie secure value type (".serialize($secure).")"));
1945 for($cookie_domain=0,Reset($cookies[$secure]);$cookie_domain<count($cookies[$secure]);Next($cookies[$secure]),$cookie_domain++)
1946 {
1947 $domain_pattern=Key($cookies[$secure]);
1948 if(GetType($domain_pattern)!="string")
1949 return($this->SetError("invalid cookie domain value type (".serialize($domain_pattern).")"));
1950 for(Reset($cookies[$secure][$domain_pattern]),$path_part=0;$path_part<count($cookies[$secure][$domain_pattern]);Next($cookies[$secure][$domain_pattern]),$path_part++)
1951 {
1952 $path=Key($cookies[$secure][$domain_pattern]);
1953 if(GetType($path)!="string"
1954 || strcmp(substr($path, 0, 1), "/"))
1955 return($this->SetError("invalid cookie path value type (".serialize($path).")"));
1956 for(Reset($cookies[$secure][$domain_pattern][$path]),$cookie=0;$cookie<count($cookies[$secure][$domain_pattern][$path]);Next($cookies[$secure][$domain_pattern][$path]),$cookie++)
1957 {
1958 $cookie_name=Key($cookies[$secure][$domain_pattern][$path]);
1959 $expires=$cookies[$secure][$domain_pattern][$path][$cookie_name]["expires"];
1960 $value=$cookies[$secure][$domain_pattern][$path][$cookie_name]["value"];
1961 if(GetType($expires)!="string"
1962 || (strlen($expires)
1963 && !ereg("^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}\$", $expires)))
1964 return($this->SetError("invalid cookie expiry value type (".serialize($expires).")"));
1965 $new_cookies[$secure][$domain_pattern][$path][$cookie_name]=array(
1966 "name"=>$cookie_name,
1967 "value"=>$value,
1968 "domain"=>$domain_pattern,
1969 "path"=>$path,
1970 "expires"=>$expires,
1971 "secure"=>$secure
1972 );
1973 }
1974 }
1975 }
1976 }
1977 $this->cookies=$new_cookies;
1978 return("");
1979 }
1980};
1981
1982?> \ No newline at end of file
diff --git a/includes/phpsvnclient.php b/includes/phpsvnclient.php deleted file mode 100755 index 811c86d..0000000 --- a/includes/phpsvnclient.php +++ /dev/null
@@ -1,420 +0,0 @@
1<?php
2/*
3***************************************************************************
4* Copyright (C) 2007-2008 by Sixdegrees *
5* cesar@sixdegrees.com.br *
6* "Working with freedom" *
7* http://www.sixdegrees.com.br *
8* *
9* Permission is hereby granted, free of charge, to any person obtaining *
10* a copy of this software and associated documentation files (the *
11* "Software"), to deal in the Software without restriction, including *
12* without limitation the rights to use, copy, modify, merge, publish, *
13* distribute, sublicense, and/or sell copies of the Software, and to *
14* permit persons to whom the Software is furnished to do so, subject to *
15* the following conditions: *
16* *
17* The above copyright notice and this permission notice shall be *
18* included in all copies or substantial portions of the Software. *
19* *
20* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
21* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
22* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
23* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR *
24* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26* OTHER DEALINGS IN THE SOFTWARE. *
27***************************************************************************
28*/
29define("PHPSVN_DIR",dirname(__FILE__) );
30
31require(PHPSVN_DIR."/http.php");
32require(PHPSVN_DIR."/xml_parser.php");
33require(PHPSVN_DIR."/definitions.php");
34
35
36/**
37 * PHP SVN CLIENT
38 *
39 * This class is a SVN client. It can perform read operations
40 * to a SVN server (over Web-DAV).
41 * It can get directory files, file contents, logs. All the operaration
42 * could be done for a specific version or for the last version.
43 *
44 * @author Cesar D. Rodas <cesar@sixdegrees.com.br>
45 * @license BSD License
46 */
47class phpSVNclient
48{
49 /**
50 * SVN Repository URL
51 *
52 * @var string
53 * @access private
54 */
55 var $_url;
56 /**
57 * Cache, for don't request the same thing in a
58 * short period of time.
59 *
60 * @var string
61 * @access private
62 */
63 var $_cache;
64 /**
65 * HTTP Client object
66 *
67 * @var object
68 * @access private
69 */
70 var $_http;
71 /**
72 * Respository Version.
73 *
74 * @access private
75 * @var interger
76 */
77 var $_repVersion;
78 /**
79 * Password
80 *
81 * @access private
82 * @var string
83 */
84 var $pass;
85 /**
86 * Password
87 *
88 * @access private
89 * @var string
90 */
91 var $user;
92 /**
93 * Last error number
94 *
95 * Possible values are NOT_ERROR, NOT_FOUND, AUTH_REQUIRED, UNKOWN_ERROR
96 *
97 * @access public
98 * @var integer
99 */
100 var $errNro;
101
102 function phpSVNclient()
103 {
104 $http = & $this->_http;
105 $http = new http_class;
106 $http->user_agent = "phpSVNclient (http://cesars.users.phpclasses.org/svnclient)";
107 }
108
109 /**
110 * Set URL
111 *
112 * Set the project repository URL.
113 *
114 * @param string $url URL of the project.
115 * @access public
116 */
117 function setRespository($url)
118 {
119 $this->_url = $url;
120 }
121
122 /**
123 * Add Authentication settings
124 *
125 * @param string $user Username
126 * @param string $pass Password
127 */
128 function setAuth($user,$pass) {
129 $this->user = $user;
130 $this->pass = $pass;
131 }
132
133 /**
134 * Get Files
135 *
136 * This method returns all the files in $folder
137 * in the version $version of the repository.
138 *
139 * @param string $folder Folder to get files
140 * @param integer $version Repository version, -1 means actual
141 * @return array List of files.
142 */
143 function getDirectoryFiles($folder='/',$version=-1) {
144 $actVersion = $this->getVersion();
145 if ( $version == -1 || $version > $actVersion) {
146 $version = $actVersion;
147 }
148 $url = $this->cleanURL($this->_url."/!svn/bc/".$version."/".$folder."/");
149 $this->initQuery($args,"PROPFIND",$url);
150 $args['Body'] = PHPSVN_NORMAL_REQUEST;
151 $args['Headers']['Content-Length'] = strlen(PHPSVN_NORMAL_REQUEST);
152
153 if ( ! $this->Request($args, $headers, $body) ) {
154 return false;
155 }
156 $parser=new xml_parser_class;
157 $parser->Parse( $body,true);
158
159
160 $fileinfo = array(
161
162 SVN_LAST_MODIFIED => "last-mod",
163 SVN_RELATIVE_URL => "path",
164 SVN_STATUS => "status"
165 );
166
167 $start = false;
168 $last = "";
169 $tmp = array();
170 $files = array();
171 $tmp1 = 0;
172
173
174 foreach($parser->structure as $key=>$value) {
175 if ( is_array($value) and $value["Tag"] == SVN_FILE) {
176 if ( count($tmp) > 0 && $tmp1++ > 0) {
177 $files[] = $tmp;
178 }
179 $start=true;
180 $last = "";
181 $tmp = array();
182 continue;
183 }
184 if (!$start) continue;
185 if ( $last != "") {
186 $tmp[ $fileinfo[$last] ] = $value;
187 $last = "";
188 continue;
189 }
190 if ( is_array($value) && isset($value["Tag"]) && isset( $fileinfo[$value["Tag"]] ) ) {
191 $last = $value["Tag"];
192 }
193 }
194
195 return $files;
196 }
197
198 /**
199 * Returns file contents
200 *
201 * @param string $file File pathname
202 * @param integer $version File Version
203 * @return Array File content and information
204 */
205 function getFile($file,$version=-1) {
206 $actVersion = $this->getVersion();
207 if ( $version == -1 || $version > $actVersion) {
208 $version = $actVersion;
209 }
210 $url = $this->cleanURL($this->_url."/!svn/bc/".$version."/".$file."/");
211 $this->initQuery($args,"GET",$url);
212 if ( ! $this->Request($args, $headers, $body) )
213 return false;
214 return $body;
215 }
216
217 /**
218 * Get changes logs of a file.
219 *
220 * Get repository change logs between version
221 * $vini and $vend.
222 *
223 * @param integer $vini Initial Version
224 * @param integer $vend End Version
225 * @return Array Respository Logs
226 */
227 function getRepositoryLogs($vini=0,$vend=-1) {
228 return $this->getFileLogs("/",$vini,$vend);
229 }
230
231 /**
232 * Get changes logs of a file.
233 *
234 * Get repository change of a file between version
235 * $vini and $vend.
236 *
237 * @param
238 * @param integer $vini Initial Version
239 * @param integer $vend End Version
240 * @return Array Respository Logs
241 */
242 function getFileLogs($file, $vini=0,$vend=-1) {
243 $actVersion = $this->getVersion();
244 if ( $vend == -1 || $vend > $actVersion)
245 $vend = $actVersion;
246 else
247 $vend++;
248
249 if ( $vini < 0) $vini=0;
250 if ( $vini > $vend) $vini = $vend;
251
252 $url = $this->cleanURL($this->_url."/!svn/bc/".$actVersion."/".$file."/");
253 $this->initQuery($args,"REPORT",$url);
254 $args['Body'] = sprintf(PHPSVN_LOGS_REQUEST,$vini,$vend);
255 $args['Headers']['Content-Length'] = strlen($args['Body']);
256 $args['Headers']['Depth']=1;
257
258 if ( ! $this->Request($args, $headers, $body) )
259 return false;
260
261
262 $parser=new xml_parser_class;
263 $parser->Parse( $body,true);
264
265
266 $fileinfo = array(
267 SVN_LOGS_VERSION=>"version",
268 SVN_LOGS_AUTHOR => "author",
269 SVN_LOGS_DATE => "date",
270 SVN_LOGS_COMMENT => "comment"
271
272 );
273
274 $start = false;
275 $last = "";
276 $tmp = array();
277 $files = array();
278 $tmp1 = 0;
279
280
281 foreach($parser->structure as $key=>$value) {
282 if ( is_array($value) and $value["Tag"] == SVN_LOGS_BEGINGS) {
283 if ( count($tmp) > 0 && $tmp1++ > 0) {
284 $logs[] = $tmp;
285 }
286 $start=true;
287 $last = "";
288 $tmp = array();
289 continue;
290 }
291 if (!$start) continue;
292 if ( $last != "") {
293 $tmp[ $fileinfo[$last] ] = $value;
294 $last = "";
295 continue;
296 }
297 if ( is_array($value) && isset($value["Tag"]) && isset( $fileinfo[$value["Tag"]] ) ) {
298 $last = $value["Tag"];
299 }
300 }
301
302 return $logs;
303 }
304
305 /**
306 * Get the repository version
307 *
308 * @return integer Repository version
309 * @access public
310 */
311 function getVersion() {
312 if ( $this->_repVersion < 0) return $this->_repVersion;
313
314 $this->_repVersion = -1;
315
316 $this->initQuery($args,"PROPFIND",$this->cleanURL($this->_url."/!svn/vcc/default") );
317 $args['Body'] = PHPSVN_VERSION_REQUEST;
318 $args['Headers']['Content-Length'] = strlen(PHPSVN_NORMAL_REQUEST);
319 $args['Headers']['Depth']=0;
320
321 if ( !$this->Request($args, $tmp, $body) ) {
322 return $this->_repVersion;
323 }
324
325 $parser=new xml_parser_class;
326 $parser->Parse( $body,true);
327 $enable=false;
328 foreach($parser->structure as $value) {
329 if ( $enable ) {
330 $t = explode("/",$value);
331 if ( is_numeric($t[ count($t) -1 ]) ) {
332 $this->_repVersion = $t[ count($t) -1 ];
333 break;
334 }
335 }
336 if ( is_array($value) && $value['Tag'] == 'D:href') $enable = true;
337 }
338
339 return $this->_repVersion;
340 }
341
342 /**
343 * Prepare HTTP CLIENT object
344 *
345 * @param array &$arguments Byreferences variable.
346 * @param string $method Method for the request (GET,POST,PROPFIND, REPORT,ETC).
347 * @param string $url URL for the action.
348 * @access private
349 */
350 function initQuery(&$arguments,$method, $url) {
351 $http = & $this->_http;
352 $http->GetRequestArguments($url,$arguments);
353 if ( isset($this->user) && isset($this->pass)) {
354 $arguments["Headers"]["Authorization"] = " Basic ".base64_encode($this->user.":".$this->pass);
355 }
356 $arguments["RequestMethod"]=$method;
357 $arguments["Headers"]["Content-Type"] = "text/xml";
358 $arguments["Headers"]["Depth"] = 1;
359 }
360
361 /**
362 * Open a connection, send request, read header
363 * and body.
364 *
365 * @param Array $args Connetion's argument
366 * @param Array &$headers Array with the header response.
367 * @param string &$body Body response.
368 * @return boolean True is query success
369 * @access private
370 */
371 function Request($args, &$headers, &$body) {
372 $http = & $this->_http;
373 $http->Open($args);
374 $http->SendRequest($args);
375 $http->ReadReplyHeaders($headers);
376 if ($http->response_status[0] != 2) {
377 switch( $http->response_status ) {
378 case 404:
379 $this->errNro=NOT_FOUND;
380 break;
381 case 401:
382 $this->errNro=AUTH_REQUIRED;
383 break;
384 default:
385 $this->errNro=UNKNOWN_ERROR;
386
387 }
388 $http->close();
389 return false;
390 }
391 $this->errNro = NO_ERROR;
392 $body='';
393 $tbody='';
394 for(;;)
395 {
396 $error=$http->ReadReplyBody($tbody,1000);
397 if($error!="" || strlen($tbody)==0) break;
398 $body.=($tbody);
399 }
400 $http->close();
401 return true;
402 }
403
404 /**
405 * Clean URL
406 *
407 * Delete "//" on URL requests.
408 *
409 * @param string $url URL
410 * @return string New cleaned URL.
411 * @access private
412 */
413 function cleanURL($url) {
414 $t = parse_url($url);
415 if ( isset($t['path']) )
416 $t['path'] = str_replace("//","/",$t['path']);
417 return $t['scheme']."://".$t['host'].(isset($t['path']) ? $t['path'] : "/");
418 }
419}
420?>
diff --git a/includes/xml_parser.php b/includes/xml_parser.php deleted file mode 100755 index 15e02e0..0000000 --- a/includes/xml_parser.php +++ /dev/null
@@ -1,427 +0,0 @@
1<?php
2/*
3 * xml_parser.php
4 *
5 * @(#) $Header: /home/mlemos/cvsroot/xmlparser/xml_parser.php,v 1.19 2006/11/22 01:25:05 mlemos Exp $
6 *
7 */
8
9/*
10 * Parser error numbers:
11 *
12 * 1 - Could not create the XML parser
13 * 2 - Could not parse data
14 * 3 - Could not read from input stream
15 *
16 */
17
18$xml_parser_handlers=array();
19
20Function xml_parser_start_element_handler($parser,$name,$attrs)
21{
22 global $xml_parser_handlers;
23
24 if(!strcmp($xml_parser_handlers[$parser]->error,""))
25 $xml_parser_handlers[$parser]->StartElement($xml_parser_handlers[$parser],$name,$attrs);
26}
27
28Function xml_parser_end_element_handler($parser,$name)
29{
30 global $xml_parser_handlers;
31
32 if(!strcmp($xml_parser_handlers[$parser]->error,""))
33 $xml_parser_handlers[$parser]->EndElement($xml_parser_handlers[$parser],$name);
34}
35
36Function xml_parser_character_data_handler($parser,$data)
37{
38 global $xml_parser_handlers;
39
40 if(!strcmp($xml_parser_handlers[$parser]->error,""))
41 $xml_parser_handlers[$parser]->CharacterData($xml_parser_handlers[$parser],$data);
42}
43
44class xml_parser_handler_class
45{
46 var $xml_parser;
47 var $error_number=0;
48 var $error="";
49 var $error_code=0;
50 var $error_line,$error_column,$error_byte_index;
51 var $structure=array();
52 var $positions=array();
53 var $path="";
54 var $store_positions=0;
55 var $simplified_xml=0;
56 var $fail_on_non_simplified_xml=0;
57
58 Function SetError(&$object,$error_number,$error)
59 {
60 $object->error_number=$error_number;
61 $object->error=$error;
62 $object->error_line=xml_get_current_line_number($object->xml_parser);
63 $object->error_column=xml_get_current_column_number($object->xml_parser);
64 $object->error_byte_index=xml_get_current_byte_index($object->xml_parser);
65 }
66
67 Function SetElementData(&$object,$path,&$data)
68 {
69 $object->structure[$path]=$data;
70 if($object->store_positions)
71 {
72 $object->positions[$path]=array(
73 "Line"=>xml_get_current_line_number($object->xml_parser),
74 "Column"=>xml_get_current_column_number($object->xml_parser),
75 "Byte"=>xml_get_current_byte_index($object->xml_parser)
76 );
77 }
78 }
79
80 Function StartElement(&$object,$name,&$attrs)
81 {
82 if(strcmp($this->path,""))
83 {
84 $element=$object->structure[$this->path]["Elements"];
85 $object->structure[$this->path]["Elements"]++;
86 $this->path.=",$element";
87 }
88 else
89 {
90 $element=0;
91 $this->path="0";
92 }
93 $data=array(
94 "Tag"=>$name,
95 "Elements"=>0
96 );
97 if($object->simplified_xml)
98 {
99 if($object->fail_on_non_simplified_xml
100 && count($attrs)>0)
101 {
102 $this->SetError($object,2,"Simplified XML can not have attributes in tags");
103 return;
104 }
105 }
106 else
107 $data["Attributes"]=$attrs;
108 $this->SetElementData($object,$this->path,$data);
109 }
110
111 Function EndElement(&$object,$name)
112 {
113 $this->path=(($position=strrpos($this->path,",")) ? substr($this->path,0,$position) : "");
114 }
115
116 Function CharacterData(&$object,$data)
117 {
118 $element=$object->structure[$this->path]["Elements"];
119 $previous=$this->path.",".strval($element-1);
120 if($element>0
121 && GetType($object->structure[$previous])=="string")
122 $object->structure[$previous].=$data;
123 else
124 {
125 $this->SetElementData($object,$this->path.",$element",$data);
126 $object->structure[$this->path]["Elements"]++;
127 }
128 }
129};
130
131class xml_parser_class
132{
133 var $xml_parser=0;
134 var $parser_handler;
135 var $error="";
136 var $error_number=0;
137 var $error_line=0;
138 var $error_column=0;
139 var $error_byte_index=0;
140 var $error_code=0;
141 var $stream_buffer_size=4096;
142 var $structure=array();
143 var $positions=array();
144 var $store_positions=0;
145 var $case_folding=0;
146 var $target_encoding="ISO-8859-1";
147 var $simplified_xml=0;
148 var $fail_on_non_simplified_xml=0;
149
150 Function xml_parser_start_element_handler($parser,$name,$attrs)
151 {
152 if(!strcmp($this->error,""))
153 $this->parser_handler->StartElement($this,$name,$attrs);
154 }
155
156 Function xml_parser_end_element_handler($parser,$name)
157 {
158 if(!strcmp($this->error,""))
159 $this->parser_handler->EndElement($this,$name);
160 }
161
162 Function xml_parser_character_data_handler($parser,$data)
163 {
164 if(!strcmp($this->error,""))
165 $this->parser_handler->CharacterData($this,$data);
166 }
167
168 Function SetErrorPosition($error_number,$error,$line,$column,$byte_index)
169 {
170 $this->error_number=$error_number;
171 $this->error=$error;
172 $this->error_line=$line;
173 $this->error_column=$column;
174 $this->error_byte_index=$byte_index;
175 }
176
177 Function SetError($error_number,$error)
178 {
179 $this->error_number=$error_number;
180 $this->error=$error;
181 if($this->xml_parser)
182 {
183 $line=xml_get_current_line_number($this->xml_parser);
184 $column=xml_get_current_column_number($this->xml_parser);
185 $byte_index=xml_get_current_byte_index($this->xml_parser);
186 }
187 else
188 {
189 $line=$column=1;
190 $byte_index=0;
191 }
192 $this->SetErrorPosition($error_number,$error,$line,$column,$byte_index);
193 }
194
195 Function Parse($data,$end_of_data)
196 {
197 global $xml_parser_handlers;
198
199 if(strcmp($this->error,""))
200 return($this->error);
201 if(!$this->xml_parser)
202 {
203 if(!function_exists("xml_parser_create"))
204 {
205 $this->SetError(1,"XML support is not available in this PHP configuration");
206 return($this->error);
207 }
208 if(!($this->xml_parser=xml_parser_create()))
209 {
210 $this->SetError(1,"Could not create the XML parser");
211 return($this->error);
212 }
213 xml_parser_set_option($this->xml_parser,XML_OPTION_CASE_FOLDING,$this->case_folding);
214 xml_parser_set_option($this->xml_parser,XML_OPTION_TARGET_ENCODING,$this->target_encoding);
215 if(function_exists("xml_set_object"))
216 {
217 xml_set_object($this->xml_parser,$this);
218 $this->parser_handler=new xml_parser_handler_class;
219 $this->structure=array();
220 $this->positions=array();
221 }
222 else
223 {
224 $xml_parser_handlers[$this->xml_parser]=new xml_parser_handler_class;
225 $xml_parser_handlers[$this->xml_parser]->xml_parser=$this->xml_parser;
226 $xml_parser_handlers[$this->xml_parser]->store_positions=$this->store_positions;
227 $xml_parser_handlers[$this->xml_parser]->simplified_xml=$this->simplified_xml;
228 $xml_parser_handlers[$this->xml_parser]->fail_on_non_simplified_xml=$this->fail_on_non_simplified_xml;
229 }
230 xml_set_element_handler($this->xml_parser,"xml_parser_start_element_handler","xml_parser_end_element_handler");
231 xml_set_character_data_handler($this->xml_parser,"xml_parser_character_data_handler");
232 }
233 $parser_ok=xml_parse($this->xml_parser,$data,$end_of_data);
234 if(!function_exists("xml_set_object"))
235 $this->error=$xml_parser_handlers[$this->xml_parser]->error;
236 if(!strcmp($this->error,""))
237 {
238 if($parser_ok)
239 {
240 if($end_of_data)
241 {
242 if(function_exists("xml_set_object"))
243 Unset($this->parser_handler);
244 else
245 {
246 $this->structure=$xml_parser_handlers[$this->xml_parser]->structure;
247 $this->positions=$xml_parser_handlers[$this->xml_parser]->positions;
248 Unset($xml_parser_handlers[$this->xml_parser]);
249 }
250 xml_parser_free($this->xml_parser);
251 $this->xml_parser=0;
252 }
253 }
254 else
255 $this->SetError(2,"Could not parse data: ".xml_error_string($this->error_code=xml_get_error_code($this->xml_parser)));
256 }
257 else
258 {
259 if(!function_exists("xml_set_object"))
260 {
261 $this->error_number=$xml_parser_handlers[$this->xml_parser]->error_number;
262 $this->error_code=$xml_parser_handlers[$this->xml_parser]->error_code;
263 $this->error_line=$xml_parser_handlers[$this->xml_parser]->error_line;
264 $this->error_column=$xml_parser_handlers[$this->xml_parser]->error_column;
265 $this->error_byte_index=$xml_parser_handlers[$this->xml_parser]->error_byte_index;
266 }
267 }
268 return($this->error);
269 }
270
271 Function VerifyWhiteSpace($path)
272 {
273 if($this->store_positions)
274 {
275 $line=$parser->positions[$path]["Line"];
276 $column=$parser->positions[$path]["Column"];
277 $byte_index=$parser->positions[$path]["Byte"];
278 }
279 else
280 {
281 $line=$column=1;
282 $byte_index=0;
283 }
284 if(!IsSet($this->structure[$path]))
285 {
286 $this->SetErrorPosition(2,"element path does not exist",$line,$column,$byte_index);
287 return($this->error);
288 }
289 if(GetType($this->structure[$path])!="string")
290 {
291 $this->SetErrorPosition(2,"element is not data",$line,$column,$byte_index);
292 return($this->error);
293 }
294 $data=$this->structure[$path];
295 for($previous_return=0,$position=0;$position<strlen($data);$position++)
296 {
297 switch($data[$position])
298 {
299 case " ":
300 case "\t":
301 $column++;
302 $byte_index++;
303 $previous_return=0;
304 break;
305 case "\n":
306 if(!$previous_return)
307 $line++;
308 $column=1;
309 $byte_index++;
310 $previous_return=0;
311 break;
312 case "\r":
313 $line++;
314 $column=1;
315 $byte_index++;
316 $previous_return=1;
317 break;
318 default:
319 $this->SetErrorPosition(2,"data is not white space",$line,$column,$byte_index);
320 return($this->error);
321 }
322 }
323 return("");
324 }
325
326 Function ParseStream($stream)
327 {
328 if(strcmp($this->error,""))
329 return($this->error);
330 do
331 {
332 if(!($data=@fread($stream,$this->stream_buffer_size)))
333 {
334 if(!feof($stream))
335 {
336 $this->SetError(3,"Could not read from input stream".(IsSet($php_errormsg) ? ': '.$php_errormsg : ''));
337 break;
338 }
339 }
340 if(strcmp($error=$this->Parse($data,feof($stream)),""))
341 break;
342 }
343 while(!feof($stream));
344 return($this->error);
345 }
346
347 Function ParseFile($file)
348 {
349 if(!file_exists($file))
350 return("the XML file to parse ($file) does not exist");
351 if(!($definition=@fopen($file,"r")))
352 return("could not open the XML file ($file)".(IsSet($php_errormsg) ? ': '.$php_errormsg : ''));
353 $error=$this->ParseStream($definition);
354 fclose($definition);
355 return($error);
356 }
357};
358
359Function XMLParseFile(&$parser,$file,$store_positions,$cache="",$case_folding=0,$target_encoding="ISO-8859-1",$simplified_xml=0,$fail_on_non_simplified_xml=0)
360{
361 if(!file_exists($file))
362 return("the XML file to parse ($file) does not exist");
363 if(strcmp($cache,""))
364 {
365 if(file_exists($cache)
366 && filemtime($file)<=filemtime($cache))
367 {
368 if(($cache_file=@fopen($cache,"r")))
369 {
370 if(function_exists("set_file_buffer"))
371 set_file_buffer($cache_file,0);
372 if(!($cache_contents=@fread($cache_file,filesize($cache))))
373 $error="could not read from the XML cache file $cache".(IsSet($php_errormsg) ? ': '.$php_errormsg : '');
374 else
375 $error="";
376 fclose($cache_file);
377 if(!strcmp($error,""))
378 {
379 if(GetType($parser=unserialize($cache_contents))=="object"
380 && IsSet($parser->structure))
381 {
382 if(!IsSet($parser->simplified_xml))
383 $parser->simplified_xml=0;
384 if(($simplified_xml
385 || !$parser->simplified_xml)
386 && (!$store_positions
387 || $parser->store_positions))
388 {
389 return("");
390 }
391 }
392 else
393 $error="it was not specified a valid cache object in XML file ($cache)";
394 }
395 }
396 else
397 $error="could not open cache XML file ($cache)".(IsSet($php_errormsg) ? ': '.$php_errormsg : '');
398 if(strcmp($error,""))
399 return($error);
400 }
401 }
402 $parser=new xml_parser_class;
403 $parser->store_positions=$store_positions;
404 $parser->case_folding=$case_folding;
405 $parser->target_encoding=$target_encoding;
406 $parser->simplified_xml=$simplified_xml;
407 $parser->fail_on_non_simplified_xml=$fail_on_non_simplified_xml;
408 if(!strcmp($error=$parser->ParseFile($file),"")
409 && strcmp($cache,""))
410 {
411 if(($cache_file=@fopen($cache,"w")))
412 {
413 if(function_exists("set_file_buffer"))
414 set_file_buffer($cache_file,0);
415 if(!@fwrite($cache_file,serialize($parser))
416 || !@fclose($cache_file))
417 $error="could to write to the XML cache file ($cache)".(IsSet($php_errormsg) ? ': '.$php_errormsg : '');
418 if(strcmp($error,""))
419 unlink($cache);
420 }
421 else
422 $error="could not open for writing to the cache file ($cache)".(IsSet($php_errormsg) ? ': '.$php_errormsg : '');
423 }
424 return($error);
425}
426
427?> \ No newline at end of file
diff --git a/pages/projects.php b/pages/projects.php deleted file mode 100755 index 4129cdf..0000000 --- a/pages/projects.php +++ /dev/null
@@ -1,94 +0,0 @@
1<?php
2/*
3 444444444
4 4::::::::4
5 4:::::::::4
6 4::::44::::4
7 4::::4 4::::4 Four Island
8 4::::4 4::::4
9 4::::4 4::::4 Written and maintained by Starla Insigna
104::::444444::::444
114::::::::::::::::4 pages/projects.php
124444444444:::::444
13 4::::4 Please do not use, reproduce or steal the
14 4::::4 contents of this file without explicit
15 4::::4 permission from Hatkirby.
16 44::::::44
17 4::::::::4
18 4444444444
19*/
20
21if (!defined('S_INCLUDE_FILE')) {define('S_INCLUDE_FILE',1);}
22
23require('headerproc.php');
24
25include('includes/phpsvnclient.php');
26
27if (!isset($_GET['project']))
28{
29
30} else {
31 if (!isset($_GET['folder']) && !isset($_GET['file']))
32 {
33 } else if (isset($_GET['folder']))
34 {
35 if ($_GET['folder'] == 'browse')
36 {
37 $template = new FITemplate('projects/browse');
38
39 if (!isset($_GET['id']))
40 {
41 $path = '/';
42 } else {
43 $path = '/' . $_GET['id'];
44 }
45 if (!isset($_GET['rev']))
46 {
47 $rev = -1;
48 } else {
49 $rev = $_GET['rev'];
50 }
51
52 $svn = new phpSVNclient();
53 $svn->setRespository('http://svn.fourisland.com/' . $_GET['project']);
54 $svn->setAuth('hatkirby','popstartwo506');
55 $data = $svn->getFile($path,$rev);
56
57 if (substr($path,strlen($path)-1,1) != '/')
58 {
59 $template->add('DATA', str_replace(' ','&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',str_replace(' ','&nbsp;&nbsp;',nl2br(htmlentities($data)))));
60 $template->adds_block('FILE', array('NAME' => $path));
61 } else {
62 $template->add('DATA', $data);
63 }
64
65 $logs = $svn->getFileLogs($path);
66 $template->add('LOGDATA', str_replace("\n\n",'<P>',htmlentities($logs[count($logs)-1]['comment'])));
67 $template->add('AUTHOR', $logs[count($logs)-1]['author']);
68 $template->add('DATE', date('F dS Y \a\\t g:i:s a',strtotime($logs[count($logs)-1]['date'])));
69
70 if ($rev != -1)
71 {
72 $template->adds_block('FORWARD', array( 'URL' => ('/projects/' . $_GET['project'] . '/browse' . $path . '?rev=' . ($rev+1)),
73 'NUM' => ($rev+1)));
74 }
75
76 if ($rev == -1)
77 {
78 $rev = $svn->getVersion();
79 }
80
81 if ($rev != 1)
82 {
83 $template->adds_block('BACK', array( 'URL' => ('/projects/' . $_GET['project'] . '/browse' . $path . '?rev=' . ($rev-1)),
84 'NUM' => ($rev-1)));
85 }
86 }
87 } else if (isset($_GET['file']))
88 {
89 }
90}
91
92$template->display();
93
94?>
diff --git a/rss.php b/rss.php index c9e866f..b13aef2 100755 --- a/rss.php +++ b/rss.php
@@ -23,7 +23,6 @@ require('headerproc.php');
23include('../security/config.php'); 23include('../security/config.php');
24include('includes/db.php'); 24include('includes/db.php');
25include('includes/bbcode.php'); 25include('includes/bbcode.php');
26include('includes/phpsvnclient.php');
27 26
28header('Content-type: application/rss+xml'); 27header('Content-type: application/rss+xml');
29 28
@@ -61,9 +60,6 @@ if (isset($_GET['mode']))
61 case 'poll': 60 case 'poll':
62?> Polls<?php 61?> Polls<?php
63 break; 62 break;
64 case 'projects':
65?> Projects<?php
66 break;
67 case 'comments': 63 case 'comments':
68?> Comments<?php 64?> Comments<?php
69 break; 65 break;
@@ -100,9 +96,6 @@ if (isset($_GET['mode']))
100 case 'poll': 96 case 'poll':
101?>An archive of all of the Four Island POTWs<?php 97?>An archive of all of the Four Island POTWs<?php
102 break; 98 break;
103 case 'projects':
104?>An archive of all of the Four Island Project checkins<?php
105 break;
106 case 'comments': 99 case 'comments':
107?>An archive of all of the comments people have left on Four Island<?php 100?>An archive of all of the comments people have left on Four Island<?php
108 break; 101 break;
@@ -168,33 +161,6 @@ if ($_GET['mode'] == 'poll')
168 } 161 }
169} 162}
170 163
171if (!isset($_GET['mode']) || ($_GET['mode'] == 'projects'))
172{
173 $svn = new phpSVNclient();
174 ob_start();
175 $projs = explode(" ",system('dir /var/svn'));
176 ob_end_clean();
177
178// $si = $i;
179
180 foreach ($projs as $name)
181 {
182 $svn->setRespository('http://svn.fourisland.com/' . $name);
183// $svn->setAuth('hatkirby','popstartwo506');
184 $logs = $svn->getFileLogs('');
185
186 $k=0;
187 while (($items[$i] = $logs[$k]))
188 {
189 $items[$i]['sortDate'] = strtotime($items[$i]['date']);
190 $items[$i]['itemType'] = 'project';
191 $items[$i]['project'] = $name;
192 $i++;
193 $k++;
194 }
195 }
196}
197
198if (!isset($_GET['mode']) || ($_GET['mode'] == 'comments')) 164if (!isset($_GET['mode']) || ($_GET['mode'] == 'comments'))
199{ 165{
200 $getcomments = "SELECT * FROM comments ORDER BY id DESC LIMIT 0,10"; 166 $getcomments = "SELECT * FROM comments ORDER BY id DESC LIMIT 0,10";
@@ -288,26 +254,6 @@ foreach ($items as $key => $value)
288 break; 254 break;
289 case 'poll': 255 case 'poll':
290 break; 256 break;
291 case 'project':
292 $value['comment'] = str_replace('[','',str_replace(']','',$value['comment']));
293 if (strpos($value['comment'],"\n") !== FALSE)
294 {
295 $title = htmlentities(substr($value['comment'],0,strpos($value['comment'],"\n")));
296 } else {
297 $title = htmlentities($value['comment']);
298 }
299?>
300 <item>
301 <title><?php echo($value['project']); ?> r<?php echo($value['version']); ?> - <?php echo($title); ?></title>
302
303 <link>http://www.fourisland.com/projects/<?php echo($value['project']); ?>/changeset/<?php echo(urlencode($value['version'])); ?></link>
304
305 <description><?php echo(htmlentities(nl2br($value['comment']))); ?></description>
306
307 <pubDate><?php echo(date('D, d M Y H:i:s O',$value['sortDate'])); ?></pubDate>
308 </item>
309<?php
310 break;
311 case 'comment': 257 case 'comment':
312?> 258?>
313 <item> 259 <item>