Ticket #1400: class-IXR.php.diff
| File class-IXR.php.diff, 10.4 KB (added by ringmaster, 8 years ago) |
|---|
-
class-IXR.php
1 1 <?php 2 2 3 3 /* 4 IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002 5 Version 1.62WP - Simon Willison, 11th July 2003 (htmlentities -> htmlspecialchars) 6 ^^^^^^ (We've made some changes) 4 IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002-2005 5 Version 1.7 (beta) - Simon Willison, 23rd May 2005 7 6 Site: http://scripts.incutio.com/xmlrpc/ 8 7 Manual: http://scripts.incutio.com/xmlrpc/manual.php 9 Made available under the BSD License: http://www.opensource.org/licenses/bsd-license.php 8 Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php 9 10 Changed in 1.7: 11 * Fixed bug where whitespace between elements accumulated in _currentTagContents 12 * Fixed bug in IXR_Date where Unix timestamps were parsed incorrectly 13 * Fixed bug with request longer than 4096 bytes (thanks Ryuji Tamagawa) 14 * Struct keys now have XML entities escaped (thanks Andrew Collington) 15 Merged changes from WordPress (thanks, guys): 16 * Trim before base64_decode: http://trac.wordpress.org/ticket/654 17 * Added optional timeout parameter to IXR_Client: http://trac.wordpress.org/changeset/1673 18 * Added support for class object callbacks: http://trac.wordpress.org/ticket/708 19 (thanks Owen Winkler) 20 21 Previous version was 1.61, released 11th July 2003 22 10 23 */ 11 24 12 25 … … 90 103 case 'struct': 91 104 $return = '<struct>'."\n"; 92 105 foreach ($this->data as $name => $value) { 106 $name = htmlspecialchars($name); 93 107 $return .= " <member><name>$name</name><value>"; 94 108 $return .= $value->getXml()."</value></member>\n"; 95 109 } … … 165 179 return true; 166 180 } 167 181 function tag_open($parser, $tag, $attr) { 182 $this->_currentTagContents = ''; 168 183 $this->currentTag = $tag; 169 184 switch($tag) { 170 185 case 'methodCall': … … 192 207 case 'int': 193 208 case 'i4': 194 209 $value = (int)trim($this->_currentTagContents); 195 $this->_currentTagContents = '';196 210 $valueFlag = true; 197 211 break; 198 212 case 'double': 199 213 $value = (double)trim($this->_currentTagContents); 200 $this->_currentTagContents = '';201 214 $valueFlag = true; 202 215 break; 203 216 case 'string': 204 $value = (string)trim($this->_currentTagContents); 205 $this->_currentTagContents = ''; 217 $value = $this->_currentTagContents; 206 218 $valueFlag = true; 207 219 break; 208 220 case 'dateTime.iso8601': 209 221 $value = new IXR_Date(trim($this->_currentTagContents)); 210 222 // $value = $iso->getTimestamp(); 211 $this->_currentTagContents = '';212 223 $valueFlag = true; 213 224 break; 214 225 case 'value': 215 226 // "If no type is indicated, the type is string." 216 227 if (trim($this->_currentTagContents) != '') { 217 228 $value = (string)$this->_currentTagContents; 218 $this->_currentTagContents = '';219 229 $valueFlag = true; 220 230 } 221 231 break; 222 232 case 'boolean': 223 233 $value = (boolean)trim($this->_currentTagContents); 224 $this->_currentTagContents = '';225 234 $valueFlag = true; 226 235 break; 227 236 case 'base64': 228 $value = base64_decode( trim($this->_currentTagContents) ); 229 $this->_currentTagContents = ''; 237 $value = base64_decode(trim($this->_currentTagContents)); 230 238 $valueFlag = true; 231 239 break; 232 240 /* Deal with stacks of arrays and structs */ … … 241 249 break; 242 250 case 'name': 243 251 $this->_currentStructName[] = trim($this->_currentTagContents); 244 $this->_currentTagContents = '';245 252 break; 246 253 case 'methodName': 247 254 $this->methodName = trim($this->_currentTagContents); 248 $this->_currentTagContents = '';249 255 break; 250 256 } 251 257 if ($valueFlag) { 252 /*253 if (!is_array($value) && !is_object($value)) {254 $value = trim($value);255 }256 */257 258 if (count($this->_arraystructs) > 0) { 258 259 // Add value to struct or array 259 260 if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { … … 268 269 $this->params[] = $value; 269 270 } 270 271 } 272 $this->_currentTagContents = ''; 271 273 } 272 274 } 273 275 … … 326 328 } 327 329 function call($methodname, $args) { 328 330 if (!$this->hasMethod($methodname)) { 329 return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); 331 return new IXR_Error(-32601, 'server error. requested method '. 332 $methodname.' does not exist.'); 330 333 } 331 334 $method = $this->callbacks[$methodname]; 332 335 // Perform the callback and send the response … … 339 342 // It's a class method - check it exists 340 343 $method = substr($method, 5); 341 344 if (!method_exists($this, $method)) { 342 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); 345 return new IXR_Error(-32601, 'server error. requested class method "'. 346 $method.'" does not exist.'); 343 347 } 344 348 // Call the method 345 349 $result = $this->$method($args); 346 350 } else { 347 351 // It's a function - does it exist? 348 352 if (is_array($method)) { 349 if (!method_exists($method[0], $method[1])) { 350 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); 351 } 353 if (!method_exists($method[0], $method[1])) { 354 return new IXR_Error(-32601, 'server error. requested object method "'. 355 $method[1].'" does not exist.'); 356 } 352 357 } else if (!function_exists($method)) { 353 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); 358 return new IXR_Error(-32601, 'server error. requested function "'. 359 $method.'" does not exist.'); 354 360 } 355 361 // Call the function 356 362 $result = call_user_func($method, $args); … … 469 475 var $path; 470 476 var $useragent; 471 477 var $response; 472 var $timeout;473 var $vendor = '';474 478 var $message = false; 475 479 var $debug = false; 480 var $timeout; 476 481 // Storage place for an error message 477 482 var $error = false; 478 function IXR_Client($server, $path = false, $port = 80, $timeout = 30, $vendor = '') {483 function IXR_Client($server, $path = false, $port = 80, $timeout = false) { 479 484 if (!$path) { 480 485 // Assume we have been given a URL instead 481 486 $bits = parse_url($server); … … 490 495 $this->server = $server; 491 496 $this->path = $path; 492 497 $this->port = $port; 493 $this->timeout = $timeout;494 498 } 495 499 $this->useragent = 'The Incutio XML-RPC PHP Library'; 500 $this->timeout = $timeout; 496 501 } 497 502 function query() { 498 503 $args = func_get_args(); … … 511 516 if ($this->debug) { 512 517 echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n"; 513 518 } 514 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); 519 if ($this->timeout) { 520 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); 521 } else { 522 $fp = @fsockopen($this->server, $this->port, $errno, $errstr); 523 } 515 524 if (!$fp) { 516 $this->error = new IXR_Error(-32300, 'transport error - could not open socket');525 $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr"); 517 526 return false; 518 527 } 519 528 fputs($fp, $request); … … 534 543 $gettingHeaders = false; 535 544 } 536 545 if (!$gettingHeaders) { 537 $contents .= trim($line) ."\n";546 $contents .= trim($line); 538 547 } 539 548 } 540 549 if ($this->debug) { … … 610 619 var $hour; 611 620 var $minute; 612 621 var $second; 613 var $timezone;614 622 function IXR_Date($time) { 615 623 // $time can be a PHP timestamp or an ISO one 616 624 if (is_numeric($time)) { … … 621 629 } 622 630 function parseTimestamp($timestamp) { 623 631 $this->year = date('Y', $timestamp); 624 $this->month = date(' Y', $timestamp);625 $this->day = date(' Y', $timestamp);632 $this->month = date('m', $timestamp); 633 $this->day = date('d', $timestamp); 626 634 $this->hour = date('H', $timestamp); 627 635 $this->minute = date('i', $timestamp); 628 636 $this->second = date('s', $timestamp); 629 637 } 630 638 function parseIso($iso) { 631 639 $this->year = substr($iso, 0, 4); 632 $this->month = substr($iso, 4, 2); 640 $this->month = substr($iso, 4, 2); 633 641 $this->day = substr($iso, 6, 2); 634 642 $this->hour = substr($iso, 9, 2); 635 643 $this->minute = substr($iso, 12, 2); 636 644 $this->second = substr($iso, 15, 2); 637 $this->timezone = substr($iso, 17);638 645 } 639 646 function getIso() { 640 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second .$this->timezone;647 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second; 641 648 } 642 649 function getXml() { 643 650 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; … … 713 720 $returnType = array_shift($signature); 714 721 // Check the number of arguments 715 722 if (count($args) != count($signature)) { 716 // print 'Num of args: '.count($args).' Num in signature: '.count($signature);717 723 return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 718 724 } 719 725 // Check the argument types … … 825 831 } 826 832 } 827 833 828 ?> 829 No newline at end of file 834 ?><?php 835 836 ?>
