Changes in trunk/wp-includes/class-IXR.php [14677:16809]
- File:
-
- 1 edited
-
trunk/wp-includes/class-IXR.php (modified) (51 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-IXR.php
r14677 r16809 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 $final = false; 220 do { 221 if (strlen($this->message) <= $chunk_size) { 222 $final = true; 223 } 224 $part = substr($this->message, 0, $chunk_size); 225 $this->message = substr($this->message, $chunk_size); 226 if (!xml_parse($this->_parser, $part, $final)) { 227 return false; 228 } 229 if ($final) { 230 break; 231 } 232 } while (true); 233 xml_parser_free($this->_parser); 234 186 235 // Grab the error messages, if any 187 236 if ($this->messageType == 'fault') { 188 237 $this->faultCode = $this->params[0]['faultCode']; 189 238 $this->faultString = $this->params[0]['faultString']; 190 }239 } 191 240 return true; 192 241 } 193 function tag_open($parser, $tag, $attr) { 242 243 function tag_open($parser, $tag, $attr) 244 { 194 245 $this->_currentTagContents = ''; 195 246 $this->currentTag = $tag; … … 200 251 $this->messageType = $tag; 201 252 break; 202 /* Deal with stacks of arrays and structs */253 /* Deal with stacks of arrays and structs */ 203 254 case 'data': // data is to all intents and puposes more interesting than array 204 255 $this->_arraystructstypes[] = 'array'; … … 211 262 } 212 263 } 213 function cdata($parser, $cdata) { 264 265 function cdata($parser, $cdata) 266 { 214 267 $this->_currentTagContents .= $cdata; 215 268 } 216 function tag_close($parser, $tag) { 269 270 function tag_close($parser, $tag) 271 { 217 272 $valueFlag = false; 218 273 switch($tag) { 219 274 case 'int': 220 275 case 'i4': 221 $value = (int) trim($this->_currentTagContents);276 $value = (int)trim($this->_currentTagContents); 222 277 $valueFlag = true; 223 278 break; 224 279 case 'double': 225 $value = (double) trim($this->_currentTagContents);280 $value = (double)trim($this->_currentTagContents); 226 281 $valueFlag = true; 227 282 break; 228 283 case 'string': 229 $value = $this->_currentTagContents;284 $value = (string)trim($this->_currentTagContents); 230 285 $valueFlag = true; 231 286 break; 232 287 case 'dateTime.iso8601': 233 288 $value = new IXR_Date(trim($this->_currentTagContents)); 234 // $value = $iso->getTimestamp();235 289 $valueFlag = true; 236 290 break; … … 243 297 break; 244 298 case 'boolean': 245 $value = (boolean) trim($this->_currentTagContents);299 $value = (boolean)trim($this->_currentTagContents); 246 300 $valueFlag = true; 247 301 break; 248 302 case 'base64': 249 $value = base64_decode( trim( $this->_currentTagContents ));303 $value = base64_decode($this->_currentTagContents); 250 304 $valueFlag = true; 251 305 break; 252 /* Deal with stacks of arrays and structs */306 /* Deal with stacks of arrays and structs */ 253 307 case 'data': 254 308 case 'struct': … … 267 321 break; 268 322 } 323 269 324 if ($valueFlag) { 270 325 if (count($this->_arraystructs) > 0) { … … 292 347 * @since 1.5 293 348 */ 294 class IXR_Server { 349 class IXR_Server 350 { 295 351 var $data; 296 352 var $callbacks = array(); 297 353 var $message; 298 354 var $capabilities; 299 function IXR_Server($callbacks = false, $data = false) { 355 356 function IXR_Server($callbacks = false, $data = false, $wait = false) 357 { 300 358 $this->setCapabilities(); 301 359 if ($callbacks) { … … 303 361 } 304 362 $this->setCallbacks(); 305 $this->serve($data); 306 } 307 function serve($data = false) { 363 if (!$wait) { 364 $this->serve($data); 365 } 366 } 367 368 function serve($data = false) 369 { 308 370 if (!$data) { 371 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { 372 header('Content-Type: text/plain'); // merged from WP #9093 373 die('XML-RPC server accepts POST requests only.'); 374 } 375 309 376 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; 377 if (empty($HTTP_RAW_POST_DATA)) { 378 // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 379 $data = file_get_contents('php://input'); 380 } else { 381 $data =& $HTTP_RAW_POST_DATA; 382 } 315 383 } 316 384 $this->message = new IXR_Message($data); … … 322 390 } 323 391 $result = $this->call($this->message->methodName, $this->message->params); 392 324 393 // Is the result an error? 325 394 if (is_a($result, 'IXR_Error')) { 326 395 $this->error($result); 327 396 } 397 328 398 // Encode the result 329 399 $r = new IXR_Value($result); 330 400 $resultxml = $r->getXml(); 401 331 402 // Create the XML 332 403 $xml = <<<EOD … … 335 406 <param> 336 407 <value> 337 $resultxml408 $resultxml 338 409 </value> 339 410 </param> … … 342 413 343 414 EOD; 344 // Send it 345 $this->output($xml); 346 } 347 function call($methodname, $args) { 415 // Send it 416 $this->output($xml); 417 } 418 419 function call($methodname, $args) 420 { 348 421 if (!$this->hasMethod($methodname)) { 349 return new IXR_Error(-32601, 'server error. requested method '. 350 $methodname.' does not exist.'); 422 return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); 351 423 } 352 424 $method = $this->callbacks[$methodname]; 425 353 426 // Perform the callback and send the response 354 427 if (count($args) == 1) { … … 356 429 $args = $args[0]; 357 430 } 431 358 432 // Are we dealing with a function or a method? 359 if ( is_string( $method ) && substr($method, 0, 5) == 'this:') {433 if (is_string($method) && substr($method, 0, 5) == 'this:') { 360 434 // It's a class method - check it exists 361 435 $method = substr($method, 5); 362 436 if (!method_exists($this, $method)) { 363 return new IXR_Error(-32601, 'server error. requested class method "'. 364 $method.'" does not exist.');365 } 366 // Call the method437 return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); 438 } 439 440 //Call the method 367 441 $result = $this->$method($args); 368 442 } else { 369 443 // It's a function - does it exist? 370 444 if (is_array($method)) { 371 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 if (!is_callable(array($method[0], $method[1]))) { 446 return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); 374 447 } 375 448 } else if (!function_exists($method)) { 376 return new IXR_Error(-32601, 'server error. requested function "'. 377 $method.'" does not exist.');378 } 449 return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); 450 } 451 379 452 // Call the function 380 453 $result = call_user_func($method, $args); … … 383 456 } 384 457 385 function error($error, $message = false) { 458 function error($error, $message = false) 459 { 386 460 // Accepts either an error object or an error code and message 387 461 if ($message && !is_object($error)) { … … 390 464 $this->output($error->getXml()); 391 465 } 392 function output($xml) { 466 467 function output($xml) 468 { 393 469 $xml = '<?xml version="1.0"?>'."\n".$xml; 394 470 $length = strlen($xml); … … 400 476 exit; 401 477 } 402 function hasMethod($method) { 478 479 function hasMethod($method) 480 { 403 481 return in_array($method, array_keys($this->callbacks)); 404 482 } 405 function setCapabilities() { 483 484 function setCapabilities() 485 { 406 486 // Initialises capabilities array 407 487 $this->capabilities = array( … … 409 489 'specUrl' => 'http://www.xmlrpc.com/spec', 410 490 'specVersion' => 1 411 ),491 ), 412 492 'faults_interop' => array( 413 493 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', 414 494 'specVersion' => 20010516 415 ),495 ), 416 496 'system.multicall' => array( 417 497 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', 418 498 'specVersion' => 1 419 ),499 ), 420 500 ); 421 501 } 422 function getCapabilities($args) { 502 503 function getCapabilities($args) 504 { 423 505 return $this->capabilities; 424 506 } 425 function setCallbacks() { 507 508 function setCallbacks() 509 { 426 510 $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; 427 511 $this->callbacks['system.listMethods'] = 'this:listMethods'; 428 512 $this->callbacks['system.multicall'] = 'this:multiCall'; 429 513 } 430 function listMethods($args) { 514 515 function listMethods($args) 516 { 431 517 // Returns a list of methods - uses array_reverse to ensure user defined 432 518 // methods are listed before server defined methods 433 519 return array_reverse(array_keys($this->callbacks)); 434 520 } 435 function multiCall($methodcalls) { 521 522 function multiCall($methodcalls) 523 { 436 524 // See http://www.xmlrpc.com/discuss/msgReader$1208 437 525 $return = array(); … … 463 551 * @since 1.5 464 552 */ 465 class IXR_Request { 553 class IXR_Request 554 { 466 555 var $method; 467 556 var $args; 468 557 var $xml; 469 function IXR_Request($method, $args) { 558 559 function IXR_Request($method, $args) 560 { 470 561 $this->method = $method; 471 562 $this->args = $args; … … 485 576 $this->xml .= '</params></methodCall>'; 486 577 } 487 function getLength() { 578 579 function getLength() 580 { 488 581 return strlen($this->xml); 489 582 } 490 function getXml() { 583 584 function getXml() 585 { 491 586 return $this->xml; 492 587 } … … 498 593 * @package IXR 499 594 * @since 1.5 595 * 500 596 */ 501 class IXR_Client { 597 class IXR_Client 598 { 502 599 var $server; 503 600 var $port; 504 601 var $path; 505 602 var $useragent; 506 var $headers;507 603 var $response; 508 604 var $message = false; 509 605 var $debug = false; 510 606 var $timeout; 607 var $headers = array(); 608 511 609 // Storage place for an error message 512 610 var $error = false; 513 function IXR_Client($server, $path = false, $port = 80, $timeout = false) { 611 612 function IXR_Client($server, $path = false, $port = 80, $timeout = 15) 613 { 514 614 if (!$path) { 515 615 // Assume we have been given a URL instead … … 518 618 $this->port = isset($bits['port']) ? $bits['port'] : 80; 519 619 $this->path = isset($bits['path']) ? $bits['path'] : '/'; 620 520 621 // Make absolutely sure we have a path 521 622 if (!$this->path) { … … 530 631 $this->timeout = $timeout; 531 632 } 532 function query() { 633 634 function query() 635 { 533 636 $args = func_get_args(); 534 637 $method = array_shift($args); … … 539 642 $request = "POST {$this->path} HTTP/1.0$r"; 540 643 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; 644 // Merged from WP #8145 - allow custom headers 645 $this->headers['Host'] = $this->server; 646 $this->headers['Content-Type'] = 'text/xml'; 647 $this->headers['User-Agent'] = $this->useragent; 648 $this->headers['Content-Length']= $length; 649 650 foreach( $this->headers as $header => $value ) { 651 $request .= "{$header}: {$value}{$r}"; 652 } 653 $request .= $r; 550 654 551 655 $request .= $xml; 656 552 657 // Now send the request 553 658 if ($this->debug) { 554 659 echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; 555 660 } 661 556 662 if ($this->timeout) { 557 663 $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); … … 560 666 } 561 667 if (!$fp) { 562 $this->error = new IXR_Error(-32300, "transport error - could not open socket: $errno $errstr");668 $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); 563 669 return false; 564 670 } 565 671 fputs($fp, $request); 566 672 $contents = ''; 567 $debug _contents = '';673 $debugContents = ''; 568 674 $gotFirstLine = false; 569 675 $gettingHeaders = true; … … 573 679 // Check line for '200' 574 680 if (strstr($line, '200') === false) { 575 $this->error = new IXR_Error(-3230 1, 'transport error - HTTP status code was not 200');681 $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); 576 682 return false; 577 683 } … … 582 688 } 583 689 if (!$gettingHeaders) { 584 // WP#12559 remove trim so as to not strip newlines from received response.690 // merged from WP #12559 - remove trim 585 691 $contents .= $line; 586 692 } 587 693 if ($this->debug) { 588 $debug_contents .= $line;694 $debugContents .= $line; 589 695 } 590 696 } 591 697 if ($this->debug) { 592 echo '<pre class="ixr_response">'.htmlspecialchars($debug_contents)."\n</pre>\n\n"; 593 } 698 echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; 699 } 700 594 701 // Now parse what we've got back 595 702 $this->message = new IXR_Message($contents); … … 599 706 return false; 600 707 } 708 601 709 // Is the message a fault? 602 710 if ($this->message->messageType == 'fault') { … … 604 712 return false; 605 713 } 714 606 715 // Message must be OK 607 716 return true; 608 717 } 609 function getResponse() { 718 719 function getResponse() 720 { 610 721 // methodResponses can only have one param - return that 611 722 return $this->message->params[0]; 612 723 } 613 function isError() { 724 725 function isError() 726 { 614 727 return (is_object($this->error)); 615 728 } 616 function getErrorCode() { 729 730 function getErrorCode() 731 { 617 732 return $this->error->code; 618 733 } 619 function getErrorMessage() { 734 735 function getErrorMessage() 736 { 620 737 return $this->error->message; 621 738 } 622 739 } 740 623 741 624 742 /** … … 628 746 * @since 1.5 629 747 */ 630 class IXR_Error { 748 class IXR_Error 749 { 631 750 var $code; 632 751 var $message; 633 function IXR_Error($code, $message) { 752 753 function IXR_Error($code, $message) 754 { 634 755 $this->code = $code; 635 // WP adds htmlspecialchars(). See #5666636 756 $this->message = htmlspecialchars($message); 637 757 } 638 function getXml() { 758 759 function getXml() 760 { 639 761 $xml = <<<EOD 640 762 <methodResponse> … … 674 796 var $second; 675 797 var $timezone; 676 function IXR_Date($time) { 798 799 function IXR_Date($time) 800 { 677 801 // $time can be a PHP timestamp or an ISO one 678 802 if (is_numeric($time)) { … … 682 806 } 683 807 } 684 function parseTimestamp($timestamp) { 808 809 function parseTimestamp($timestamp) 810 { 685 811 $this->year = date('Y', $timestamp); 686 812 $this->month = date('m', $timestamp); … … 689 815 $this->minute = date('i', $timestamp); 690 816 $this->second = date('s', $timestamp); 691 // WP adds timezone. See #2036692 817 $this->timezone = ''; 693 818 } 694 function parseIso($iso) { 819 820 function parseIso($iso) 821 { 695 822 $this->year = substr($iso, 0, 4); 696 823 $this->month = substr($iso, 4, 2); … … 699 826 $this->minute = substr($iso, 12, 2); 700 827 $this->second = substr($iso, 15, 2); 701 // WP adds timezone. See #2036702 828 $this->timezone = substr($iso, 17); 703 829 } 704 function getIso() { 705 // WP adds timezone. See #2036 830 831 function getIso() 832 { 706 833 return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; 707 834 } 708 function getXml() { 835 836 function getXml() 837 { 709 838 return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; 710 839 } 711 function getTimestamp() { 840 841 function getTimestamp() 842 { 712 843 return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); 713 844 } … … 720 851 * @since 1.5 721 852 */ 722 class IXR_Base64 { 853 class IXR_Base64 854 { 723 855 var $data; 724 function IXR_Base64($data) { 856 857 function IXR_Base64($data) 858 { 725 859 $this->data = $data; 726 860 } 727 function getXml() { 861 862 function getXml() 863 { 728 864 return '<base64>'.base64_encode($this->data).'</base64>'; 729 865 } … … 736 872 * @since 1.5 737 873 */ 738 class IXR_IntrospectionServer extends IXR_Server { 874 class IXR_IntrospectionServer extends IXR_Server 875 { 739 876 var $signatures; 740 877 var $help; 741 function IXR_IntrospectionServer() { 878 879 function IXR_IntrospectionServer() 880 { 742 881 $this->setCallbacks(); 743 882 $this->setCapabilities(); … … 771 910 ); 772 911 } 773 function addCallback($method, $callback, $args, $help) { 912 913 function addCallback($method, $callback, $args, $help) 914 { 774 915 $this->callbacks[$method] = $callback; 775 916 $this->signatures[$method] = $args; 776 917 $this->help[$method] = $help; 777 918 } 778 function call($methodname, $args) { 919 920 function call($methodname, $args) 921 { 779 922 // Make sure it's in an array 780 923 if ($args && !is_array($args)) { 781 924 $args = array($args); 782 925 } 926 783 927 // Over-rides default call method, adds signature check 784 928 if (!$this->hasMethod($methodname)) { … … 788 932 $signature = $this->signatures[$methodname]; 789 933 $returnType = array_shift($signature); 934 790 935 // Check the number of arguments 791 936 if (count($args) != count($signature)) { 792 937 return new IXR_Error(-32602, 'server error. wrong number of method parameters'); 793 938 } 939 794 940 // Check the argument types 795 941 $ok = true; … … 836 982 return parent::call($methodname, $argsbackup); 837 983 } 838 function methodSignature($method) { 984 985 function methodSignature($method) 986 { 839 987 if (!$this->hasMethod($method)) { 840 988 return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.'); … … 874 1022 return $return; 875 1023 } 876 function methodHelp($method) { 1024 1025 function methodHelp($method) 1026 { 877 1027 return $this->help[$method]; 878 1028 } … … 885 1035 * @since 1.5 886 1036 */ 887 class IXR_ClientMulticall extends IXR_Client { 1037 class IXR_ClientMulticall extends IXR_Client 1038 { 888 1039 var $calls = array(); 889 function IXR_ClientMulticall($server, $path = false, $port = 80) { 1040 1041 function IXR_ClientMulticall($server, $path = false, $port = 80) 1042 { 890 1043 parent::IXR_Client($server, $path, $port); 891 1044 $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; 892 1045 } 893 function addCall() { 1046 1047 function addCall() 1048 { 894 1049 $args = func_get_args(); 895 1050 $methodName = array_shift($args); … … 900 1055 $this->calls[] = $struct; 901 1056 } 902 function query() { 1057 1058 function query() 1059 { 903 1060 // Prepare multicall, then call the parent::query() method 904 1061 return parent::query('system.multicall', $this->calls);
Note: See TracChangeset
for help on using the changeset viewer.