Changeset 15612 for trunk/wp-includes/class-IXR.php
- Timestamp:
- 09/13/2010 04:36:08 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-IXR.php
r14677 r15612 1 1 <?php 2 2 /** 3 * IXR - The Inutio XML-RPC Library 3 * IXR - The Incutio XML-RPC Library 4 * 5 * Copyright (c) 2010, Incutio Ltd. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * - Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * - Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * - Neither the name of Incutio Ltd. nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 21 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 28 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 30 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 4 31 * 5 32 * @package IXR 6 33 * @since 1.5 7 34 * 8 * @copyright Incutio Ltd 2002-2005 9 * @version 1.7 (beta) 23rd May 2005 10 * @author Simon Willison 11 * @link http://scripts.incutio.com/xmlrpc/ Site 12 * @link http://scripts.incutio.com/xmlrpc/manual.php Manual 13 * @license BSD License http://www.opensource.org/licenses/bsd-license.php 35 * @copyright Incutio Ltd 2010 (http://www.incutio.com) 36 * @version 1.7.4 7th September 2010 37 * @author Simon Willison 38 * @link http://scripts.incutio.com/xmlrpc/ Site/manual 39 * @license http://www.opensource.org/licenses/bsd-license.php BSD 14 40 */ 15 41 … … 24 50 var $type; 25 51 26 function IXR_Value ($data, $type = false) { 52 function IXR_Value($data, $type = false) 53 { 27 54 $this->data = $data; 28 55 if (!$type) { … … 31 58 $this->type = $type; 32 59 if ($type == 'struct') { 33 / * Turn all the values in the array in to new IXR_Value objects */60 // Turn all the values in the array in to new IXR_Value objects 34 61 foreach ($this->data as $key => $value) { 35 62 $this->data[$key] = new IXR_Value($value); … … 43 70 } 44 71 45 function calculateType() { 72 function calculateType() 73 { 46 74 if ($this->data === true || $this->data === false) { 47 75 return 'boolean'; … … 53 81 return 'double'; 54 82 } 83 55 84 // Deal with IXR object types base64 and date 56 85 if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { … … 60 89 return 'base64'; 61 90 } 91 62 92 // If it is a normal PHP object convert it in to a struct 63 93 if (is_object($this->data)) { 64 65 94 $this->data = get_object_vars($this->data); 66 95 return 'struct'; … … 69 98 return 'string'; 70 99 } 71 /* We have an array - is it an array or a struct ? */ 100 101 // We have an array - is it an array or a struct? 72 102 if ($this->isStruct($this->data)) { 73 103 return 'struct'; … … 77 107 } 78 108 79 function getXml() { 80 /* Return XML for this value */ 109 function getXml() 110 { 111 // Return XML for this value 81 112 switch ($this->type) { 82 113 case 'boolean': … … 118 149 } 119 150 120 function isStruct($array) { 121 /* Nasty function to check if an array is a struct or not */ 151 /** 152 * Checks whether or not the supplied array is a struct or not 153 * 154 * @param unknown_type $array 155 * @return boolean 156 */ 157 function isStruct($array) 158 { 122 159 $expected = 0; 123 160 foreach ($array as $key => $value) { … … 132 169 133 170 /** 134 * IXR_M essage171 * IXR_MESSAGE 135 172 * 136 173 * @package IXR 137 174 * @since 1.5 175 * 138 176 */ 139 class IXR_Message { 177 class IXR_Message 178 { 140 179 var $message; 141 180 var $messageType; // methodCall / methodResponse / fault … … 144 183 var $methodName; 145 184 var $params; 185 146 186 // Current variable stacks 147 187 var $_arraystructs = array(); // The stack used to keep track of the current array/struct … … 154 194 // The XML parser 155 195 var $_parser; 156 function IXR_Message (&$message) { 157 $this->message = &$message; 158 } 159 function parse() { 160 // first remove the XML declaration 161 // this method avoids the RAM usage of preg_replace on very large messages 162 $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr( $this->message, 0, 100 ), 1 ); 163 $this->message = substr_replace($this->message, $header, 0, 100); 196 197 function IXR_Message($message) 198 { 199 $this->message =& $message; 200 } 201 202 function parse() 203 { 204 // first remove the XML declaration 205 // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages 206 $header = preg_replace( '/<\?xml.*?\?'.'>/', '', substr($this->message, 0, 100), 1); 207 $this->message = substr_replace($this->message, $header, 0, 100); 164 208 if (trim($this->message) == '') { 165 209 return false; 166 210 } 167 211 $this->_parser = xml_parser_create(); 168 212 // Set XML parser to take the case of tags in to account … … 171 215 xml_set_object($this->_parser, $this); 172 216 xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); 173 xml_set_character_data_handler($this->_parser, 'cdata'); 174 $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages 175 do { 176 if ( strlen($this->message) <= $chunk_size ) 177 $final=true; 178 $part = substr( $this->message, 0, $chunk_size ); 179 $this->message = substr( $this->message, $chunk_size ); 180 if ( !xml_parse( $this->_parser, $part, $final ) ) 181 return false; 182 if ( $final ) 183 break; 184 } while ( true ); 185 xml_parser_free($this->_parser); 217 xml_set_character_data_handler($this->_parser, 'cdata'); 218 $chunk_size = 262144; // 256Kb, parse in chunks to avoid the RAM usage on very large messages 219 do { 220 if (strlen($this->message) <= $chunk_size) { 221 $final = true; 222 } 223 $part = substr($this->message, 0, $chunk_size); 224 $this->message = substr($this->message, $chunk_size); 225 if (!xml_parse($this->_parser, $part, $final)) { 226 return false; 227 } 228 if ($final) { 229 break; 230 } 231 } while (true); 232 xml_parser_free($this->_parser); 233 186 234 // Grab the error messages, if any 187 235 if ($this->messageType == 'fault') { 188 236 $this->faultCode = $this->params[0]['faultCode']; 189 237 $this->faultString = $this->params[0]['faultString']; 190 238 } 191 239 return true; 192 240 } 193 function tag_open($parser, $tag, $attr) { 241 242 function tag_open($parser, $tag, $attr) 243 { 194 244 $this->_currentTagContents = ''; 195 245 $this->currentTag = $tag; … … 200 250 $this->messageType = $tag; 201 251 break; 202 /* Deal with stacks of arrays and structs */252 /* Deal with stacks of arrays and structs */ 203 253 case 'data': // data is to all intents and puposes more interesting than array 204 254 $this->_arraystructstypes[] = 'array'; … … 211 261 } 212 262 } 213 function cdata($parser, $cdata) { 263 264 function cdata($parser, $cdata) 265 { 214 266 $this->_currentTagContents .= $cdata; 215 267 } 216 function tag_close($parser, $tag) { 268 269 function tag_close($parser, $tag) 270 { 217 271 $valueFlag = false; 218 272 switch($tag) { 219 273 case 'int': 220 274 case 'i4': 221 $value = (int) 275 $value = (int)trim($this->_currentTagContents); 222 276 $valueFlag = true; 223 277 break; 224 278 case 'double': 225 $value = (double) 279 $value = (double)trim($this->_currentTagContents); 226 280 $valueFlag = true; 227 281 break; 228 282 case 'string': 229 $value = $this->_currentTagContents;283 $value = (string)trim($this->_currentTagContents); 230 284 $valueFlag = true; 231 285 break; 232 286 case 'dateTime.iso8601': 233 287 $value = new IXR_Date(trim($this->_currentTagContents)); 234 // $value = $iso->getTimestamp();235 288 $valueFlag = true; 236 289 break; … … 243 296 break; 244 297 case 'boolean': 245 $value = (boolean) 298 $value = (boolean)trim($this->_currentTagContents); 246 299 $valueFlag = true; 247 300 break; 248 301 case 'base64': 249 $value = base64_decode( trim( $this->_currentTagContents ));302 $value = base64_decode($this->_currentTagContents); 250 303 $valueFlag = true; 251 304 break; 252 /* Deal with stacks of arrays and structs */305 /* Deal with stacks of arrays and structs */ 253 306 case 'data': 254 307 case 'struct': … … 267 320 break; 268 321 } 322 269 323 if ($valueFlag) { 270 324 if (count($this->_arraystructs) > 0) { … … 292 346 * @since 1.5 293 347 */ 294 class IXR_Server { 348 class IXR_Server 349 { 295 350 var $data; 296 351 var $callbacks = array(); 297 352 var $message; 298 353 var $capabilities; 299 function IXR_Server($callbacks = false, $data = false) { 354 355 function IXR_Server($callbacks = false, $data = false, $wait = false) 356 { 300 357 $this->setCapabilities(); 301 358 if ($callbacks) { … … 303 360 } 304 361 $this->setCallbacks(); 305 $this->serve($data); 306 } 307 function serve($data = false) { 362 if (!$wait) { 363 $this->serve($data); 364 } 365 } 366 367 function serve($data = false) 368 { 308 369 if (!$data) { 370 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { 371 header('Content-Type: text/plain'); // merged from WP #9093 372 die('XML-RPC server accepts POST requests only.'); 373 } 374 309 375 global $HTTP_RAW_POST_DATA; 310 if (!$HTTP_RAW_POST_DATA) { 311 header( 'Content-Type: text/plain' ); 312 die('XML-RPC server accepts POST requests only.'); 313 } 314 $data = &$HTTP_RAW_POST_DATA; 376 if (empty($HTTP_RAW_POST_DATA)) { 377 // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 378 $data = file_get_contents('php://input'); 379 } else { 380 $data =& $HTTP_RAW_POST_DATA; 381 } 315 382 } 316 383 $this->message = new IXR_Message($data); … … 322 389 } 323 390 $result = $this->call($this->message->methodName, $this->message->params); 391 324 392 // Is the result an error? 325 393 if (is_a($result, 'IXR_Error')) { 326 394 $this->error($result); 327 395 } 396 328 397 // Encode the result 329 398 $r = new IXR_Value($result); 330 399 $resultxml = $r->getXml(); 400 331 401 // Create the XML 332 402 $xml = <<<EOD … … 335 405 <param> 336 406 <value> 337 407 $resultxml 338 408 </value> 339 409 </param> … … 342 412 343 413 EOD; 344 // Send it 345 $this->output($xml); 346 } 347 function call($methodname, $args) { 414 // Send it 415 $this->output($xml); 416 } 417 418 function call($methodname, $args) 419 { 348 420 if (!$this->hasMethod($methodname)) { 349 return new IXR_Error(-32601, 'server error. requested method '. 350 $methodname.' does not exist.'); 421 return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); 351 422 } 352 423 $method = $this->callbacks[$methodname]; 424 353 425 // Perform the callback and send the response 354 426 if (count($args) == 1) { … … 356 428 $args = $args[0]; 357 429 } 430 358 431 // Are we dealing with a function or a method? 359 if ( is_string( $method ) && substr($method, 0, 5) == 'this:') {432 if (is_string($method) && substr($method, 0, 5) == 'this:') { 360 433 // It's a class method - check it exists 361 434 $method = substr($method, 5); 362 435 if (!method_exists($this, $method)) { 363 return new IXR_Error(-32601, 'server error. requested class method "'. 364 $method.'" does not exist.');365 } 366 // 436 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); 437 } 438 439 //Call the method 367 440 $result = $this->$method($args); 368 441 } else { … … 370 443 if (is_array($method)) { 371 444 if (!method_exists($method[0], $method[1])) { 372 return new IXR_Error(-32601, 'server error. requested object method "'. 373 $method[1].'" does not exist.'); 445 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); 374 446 } 375 447 } else if (!function_exists($method)) { 376 return new IXR_Error(-32601, 'server error. requested function "'. 377 $method.'" does not exist.');378 } 448 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); 449 } 450 379 451 // Call the function 380 452 $result = call_user_func($method, $args); … … 383 455 } 384 456 385 function error($error, $message = false) { 457 function error($error, $message = false) 458 { 386 459 // Accepts either an error object or an error code and message 387 460 if ($message && !is_object($error)) { … … 390 463 $this->output($error->getXml()); 391 464 } 392 function output($xml) { 465 466 function output($xml) 467 { 393 468 $xml = '<?xml version="1.0"?>'."\n".$xml; 394 469 $length = strlen($xml); … … 400 475 exit; 401 476 } 402 function hasMethod($method) { 477 478 function hasMethod($method) 479 { 403 480 return in_array($method, array_keys($this->callbacks)); 404 481 } 405 function setCapabilities() { 482 483 function setCapabilities() 484 { 406 485 // Initialises capabilities array 407 486 $this->capabilities = array( … … 409 488 'specUrl' => 'http://www.xmlrpc.com/spec', 410 489 'specVersion' => 1 411 490 ), 412 491 'faults_interop' => array( 413 492 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 414 493 'specVersion' => 20010516 415 494 ), 416 495 'system.multicall' => array( 417 496 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', 418 497 'specVersion' => 1 419 498 ), 420 499 ); 421 500 } 422 function getCapabilities($args) { 501 502 function getCapabilities($args) 503 { 423 504 return $this->capabilities; 424 505 } 425 function setCallbacks() { 506 507 function setCallbacks() 508 { 426 509 $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; 427 510 $this->callbacks['system.listMethods'] = 'this:listMethods'; 428 511 $this->callbacks['system.multicall'] = 'this:multiCall'; 429 512 } 430 function listMethods($args) { 513 514 function listMethods($args) 515 { 431 516 // Returns a list of methods - uses array_reverse to ensure user defined 432 517 // methods are listed before server defined methods 433 518 return array_reverse(array_keys($this->callbacks)); 434 519 } 435 function multiCall($methodcalls) { 520 521 function multiCall($methodcalls) 522 { 436 523 // See http://www.xmlrpc.com/discuss/msgReader$1208 437 524 $return = array(); … … 463 550 * @since 1.5 464 551 */ 465 class IXR_Request { 552 class IXR_Request 553 { 466 554 var $method; 467 555 var $args; 468 556 var $xml; 469 function IXR_Request($method, $args) { 557 558 function IXR_Request($method, $args) 559 { 470 560 $this->method = $method; 471 561 $this->args = $args; … … 485 575 $this->xml .= '</params></methodCall>'; 486 576 } 487 function getLength() { 577 578 function getLength() 579 { 488 580 return strlen($this->xml); 489 581 } 490 function getXml() { 582 583 function getXml() 584 { 491 585 return $this->xml; 492 586 } … … 498 592 * @package IXR 499 593 * @since 1.5 594 * 500 595 */ 501 class IXR_Client { 596 class IXR_Client 597 { 502 598 var $server; 503 599 var $port; 504 600 var $path; 505 601 var $useragent; 506 var $headers;507 602 var $response; 508 603 var $message = false; 509 604 var $debug = false; 510 605 var $timeout; 606 511 607 // Storage place for an error message 512 608 var $error = false; 513 function IXR_Client($server, $path = false, $port = 80, $timeout = false) { 609 610 function IXR_Client($server, $path = false, $port = 80, $timeout = 15) 611 { 514 612 if (!$path) { 515 613 // Assume we have been given a URL instead … … 518 616 $this->port = isset($bits['port']) ? $bits['port'] : 80; 519 617 $this->path = isset($bits['path']) ? $bits['path'] : '/'; 618 520 619 // Make absolutely sure we have a path 521 620 if (!$this->path) { … … 530 629 $this->timeout = $timeout; 531 630 } 532 function query() { 631 632 function query() 633 { 533 634 $args = func_get_args(); 534 635 $method = array_shift($args); … … 539 640 $request = "POST {$this->path} HTTP/1.0$r"; 540 641 541 $this->headers['Host'] = $this->server; 542 $this->headers['Content-Type'] = 'text/xml'; 543 $this->headers['User-Agent'] = $this->useragent; 544 $this->headers['Content-Length']= $length; 545 546 foreach( $this->headers as $header => $value ) { 547 $request .= "{$header}: {$value}{$r}"; 548 } 549 $request .= $r; 642 // Merged from WP #8145 - allow custom headers 643 $this->headers['Host'] = $this->server; 644 $this->headers['Content-Type'] = 'text/xml'; 645 $this->headers['User-Agent'] = $this->useragent; 646 $this->headers['Content-Length']= $length; 647 648 foreach( $this->headers as $header => $value ) { 649 $request .= "{$header}: {$value}{$r}"; 650 } 651 $request .= $r; 550 652 551 653 $request .= $xml; 654 552 655 // Now send the request 553 656 if ($this->debug) { 554 657 echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; 555 658 } 659 556 660 if ($this->timeout) { 557 661 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); … … 560 664 } 561 665 if (!$fp) { 562 $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");666 $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); 563 667 return false; 564 668 } 565 669 fputs($fp, $request); 566 670 $contents = ''; 567 $debug _contents = '';671 $debugContents = ''; 568 672 $gotFirstLine = false; 569 673 $gettingHeaders = true; … … 573 677 // Check line for '200' 574 678 if (strstr($line, '200') === false) { 575 $this->error = new IXR_Error(-3230 1, 'transport error - HTTP status code was not 200');679 $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); 576 680 return false; 577 681 } … … 582 686 } 583 687 if (!$gettingHeaders) { 584 // WP#12559 remove trim so as to not strip newlines from received response.688 // merged from WP #12559 - remove trim 585 689 $contents .= $line; 586 690 } 587 691 if ($this->debug) { 588 $debug_contents .= $line;692 $debugContents .= $line; 589 693 } 590 694 } 591 695 if ($this->debug) { 592 echo '<pre class="ixr_response">'.htmlspecialchars($debug_contents)."\n</pre>\n\n"; 593 } 696 echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; 697 } 698 594 699 // Now parse what we've got back 595 700 $this->message = new IXR_Message($contents); … … 599 704 return false; 600 705 } 706 601 707 // Is the message a fault? 602 708 if ($this->message->messageType == 'fault') { … … 604 710 return false; 605 711 } 712 606 713 // Message must be OK 607 714 return true; 608 715 } 609 function getResponse() { 716 717 function getResponse() 718 { 610 719 // methodResponses can only have one param - return that 611 720 return $this->message->params[0]; 612 721 } 613 function isError() { 722 723 function isError() 724 { 614 725 return (is_object($this->error)); 615 726 } 616 function getErrorCode() { 727 728 function getErrorCode() 729 { 617 730 return $this->error->code; 618 731 } 619 function getErrorMessage() { 732 733 function getErrorMessage() 734 { 620 735 return $this->error->message; 621 736 } 622 737 } 738 623 739 624 740 /** … … 628 744 * @since 1.5 629 745 */ 630 class IXR_Error { 746 class IXR_Error 747 { 631 748 var $code; 632 749 var $message; 633 function IXR_Error($code, $message) { 750 751 function IXR_Error($code, $message) 752 { 634 753 $this->code = $code; 635 // WP adds htmlspecialchars(). See #5666636 754 $this->message = htmlspecialchars($message); 637 755 } 638 function getXml() { 756 757 function getXml() 758 { 639 759 $xml = <<<EOD 640 760 <methodResponse> … … 674 794 var $second; 675 795 var $timezone; 676 function IXR_Date($time) { 796 797 function IXR_Date($time) 798 { 677 799 // $time can be a PHP timestamp or an ISO one 678 800 if (is_numeric($time)) { … … 682 804 } 683 805 } 684 function parseTimestamp($timestamp) { 806 807 function parseTimestamp($timestamp) 808 { 685 809 $this->year = date('Y', $timestamp); 686 810 $this->month = date('m', $timestamp); … … 689 813 $this->minute = date('i', $timestamp); 690 814 $this->second = date('s', $timestamp); 691 // WP adds timezone. See #2036692 815 $this->timezone = ''; 693 816 } 694 function parseIso($iso) { 817 818 function parseIso($iso) 819 { 695 820 $this->year = substr($iso, 0, 4); 696 821 $this->month = substr($iso, 4, 2); … … 699 824 $this->minute = substr($iso, 12, 2); 700 825 $this->second = substr($iso, 15, 2); 701 // WP adds timezone. See #2036702 826 $this->timezone = substr($iso, 17); 703 827 } 704 function getIso() { 705 // WP adds timezone. See #2036 828 829 function getIso() 830 { 706 831 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; 707 832 } 708 function getXml() { 833 834 function getXml() 835 { 709 836 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; 710 837 } 711 function getTimestamp() { 838 839 function getTimestamp() 840 { 712 841 return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); 713 842 } … … 720 849 * @since 1.5 721 850 */ 722 class IXR_Base64 { 851 class IXR_Base64 852 { 723 853 var $data; 724 function IXR_Base64($data) { 854 855 function IXR_Base64($data) 856 { 725 857 $this->data = $data; 726 858 } 727 function getXml() { 859 860 function getXml() 861 { 728 862 return '<base64>'.base64_encode($this->data).'</base64>'; 729 863 } … … 736 870 * @since 1.5 737 871 */ 738 class IXR_IntrospectionServer extends IXR_Server { 872 class IXR_IntrospectionServer extends IXR_Server 873 { 739 874 var $signatures; 740 875 var $help; 741 function IXR_IntrospectionServer() { 876 877 function IXR_IntrospectionServer() 878 { 742 879 $this->setCallbacks(); 743 880 $this->setCapabilities(); … … 771 908 ); 772 909 } 773 function addCallback($method, $callback, $args, $help) { 910 911 function addCallback($method, $callback, $args, $help) 912 { 774 913 $this->callbacks[$method] = $callback; 775 914 $this->signatures[$method] = $args; 776 915 $this->help[$method] = $help; 777 916 } 778 function call($methodname, $args) { 917 918 function call($methodname, $args) 919 { 779 920 // Make sure it's in an array 780 921 if ($args && !is_array($args)) { 781 922 $args = array($args); 782 923 } 924 783 925 // Over-rides default call method, adds signature check 784 926 if (!$this->hasMethod($methodname)) { … … 788 930 $signature = $this->signatures[$methodname]; 789 931 $returnType = array_shift($signature); 932 790 933 // Check the number of arguments 791 934 if (count($args) != count($signature)) { 792 935 return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 793 936 } 937 794 938 // Check the argument types 795 939 $ok = true; … … 836 980 return parent::call($methodname, $argsbackup); 837 981 } 838 function methodSignature($method) { 982 983 function methodSignature($method) 984 { 839 985 if (!$this->hasMethod($method)) { 840 986 return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); … … 874 1020 return $return; 875 1021 } 876 function methodHelp($method) { 1022 1023 function methodHelp($method) 1024 { 877 1025 return $this->help[$method]; 878 1026 } … … 885 1033 * @since 1.5 886 1034 */ 887 class IXR_ClientMulticall extends IXR_Client { 1035 class IXR_ClientMulticall extends IXR_Client 1036 { 888 1037 var $calls = array(); 889 function IXR_ClientMulticall($server, $path = false, $port = 80) { 1038 1039 function IXR_ClientMulticall($server, $path = false, $port = 80) 1040 { 890 1041 parent::IXR_Client($server, $path, $port); 891 1042 $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; 892 1043 } 893 function addCall() { 1044 1045 function addCall() 1046 { 894 1047 $args = func_get_args(); 895 1048 $methodName = array_shift($args); … … 900 1053 $this->calls[] = $struct; 901 1054 } 902 function query() { 1055 1056 function query() 1057 { 903 1058 // Prepare multicall, then call the parent::query() method 904 1059 return parent::query('system.multicall', $this->calls);
Note: See TracChangeset
for help on using the changeset viewer.