[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/net/xmlrpc/ -> IXR_Library.lib.php (source)

   1  <?php
   2  
   3  /* 
   4     IXR - The Inutio XML-RPC Library - (c) Incutio Ltd 2002
   5     Version 1.61 - Simon Willison, 11th July 2003 (htmlentities -> htmlspecialchars)
   6     Site:   http://scripts.incutio.com/xmlrpc/
   7     Manual: http://scripts.incutio.com/xmlrpc/manual.php
   8     Made available under the Artistic License: http://www.opensource.org/licenses/artistic-license.php
   9  */
  10  
  11  
  12  class IXR_Value {
  13      var $data;
  14      var $type;
  15      function IXR_Value ($data, $type = false) {
  16          $this->data = $data;
  17          if (!$type) {
  18              $type = $this->calculateType();
  19          }
  20          $this->type = $type;
  21          if ($type == 'struct') {
  22              /* Turn all the values in the array in to new IXR_Value objects */
  23              foreach ($this->data as $key => $value) {
  24                  $this->data[$key] = new IXR_Value($value);
  25              }
  26          }
  27          if ($type == 'array') {
  28              for ($i = 0, $j = count($this->data); $i < $j; $i++) {
  29                  $this->data[$i] = new IXR_Value($this->data[$i]);
  30              }
  31          }
  32      }
  33      function calculateType() {
  34          if ($this->data === true || $this->data === false) {
  35              return 'boolean';
  36          }
  37          if (is_integer($this->data)) {
  38              return 'int';
  39          }
  40          if (is_double($this->data)) {
  41              return 'double';
  42          }
  43          // Deal with IXR object types base64 and date
  44          if (is_object($this->data) && is_a($this->data, 'IXR_Date')) {
  45              return 'date';
  46          }
  47          if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) {
  48              return 'base64';
  49          }
  50          // If it is a normal PHP object convert it in to a struct
  51          if (is_object($this->data)) {
  52              
  53              $this->data = get_object_vars($this->data);
  54              return 'struct';
  55          }
  56          if (!is_array($this->data)) {
  57              return 'string';
  58          }
  59          /* We have an array - is it an array or a struct ? */
  60          if ($this->isStruct($this->data)) {
  61              return 'struct';
  62          } else {
  63              return 'array';
  64          }
  65      }
  66      function getXml() {
  67          /* Return XML for this value */
  68          switch ($this->type) {
  69              case 'boolean':
  70                  return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>';
  71                  break;
  72              case 'int':
  73                  return '<int>'.$this->data.'</int>';
  74                  break;
  75              case 'double':
  76                  return '<double>'.$this->data.'</double>';
  77                  break;
  78              case 'string':
  79                  return '<string>'.htmlspecialchars($this->data).'</string>';
  80                  break;
  81              case 'array':
  82                  $return = '<array><data>'."\n";
  83                  foreach ($this->data as $item) {
  84                      $return .= '  <value>'.$item->getXml()."</value>\n";
  85                  }
  86                  $return .= '</data></array>';
  87                  return $return;
  88                  break;
  89              case 'struct':
  90                  $return = '<struct>'."\n";
  91                  foreach ($this->data as $name => $value) {
  92                      $return .= "  <member><name>".htmlspecialchars($name)."</name><value>";
  93                      $return .= $value->getXml()."</value></member>\n";
  94                  }
  95                  $return .= '</struct>';
  96                  return $return;
  97                  break;
  98              case 'date':
  99              case 'base64':
 100                  return $this->data->getXml();
 101                  break;
 102          }
 103          return false;
 104      }
 105      function isStruct($array) {
 106          /* Nasty function to check if an array is a struct or not */
 107          $expected = 0;
 108          foreach ($array as $key => $value) {
 109              if ((string)$key != (string)$expected) {
 110                  return true;
 111              }
 112              $expected++;
 113          }
 114          return false;
 115      }
 116  }
 117  
 118  
 119  class IXR_Message {
 120      var $message;
 121      var $messageType;  // methodCall / methodResponse / fault
 122      var $faultCode;
 123      var $faultString;
 124      var $methodName;
 125      var $params;
 126      var $rawmessage;
 127      // Current variable stacks
 128      var $_arraystructs = array();   // The stack used to keep track of the current array/struct
 129      var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array
 130      var $_currentStructName = array();  // A stack as well
 131      var $_param;
 132      var $_value;
 133      var $_currentTag;
 134      var $_currentTagContents;
 135      // The XML parser
 136      var $_parser;
 137      function IXR_Message ($message) {
 138          $this->message = $message;
 139          $this->rawmessage = $message;
 140      }
 141      function parse() {
 142          // first remove the XML declaration
 143          $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message);
 144          if (trim($this->message) == '') {
 145              return false;
 146          }
 147          $this->_parser = xml_parser_create();
 148          // Set XML parser to take the case of tags in to account
 149          xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
 150          // Set XML parser callback functions
 151          xml_set_object($this->_parser, $this);
 152          xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
 153          xml_set_character_data_handler($this->_parser, 'cdata');
 154          if (!xml_parse($this->_parser, $this->message)) {
 155              /* die(sprintf('XML error: %s at line %d',
 156                  xml_error_string(xml_get_error_code($this->_parser)),
 157                  xml_get_current_line_number($this->_parser))); */
 158              return false;
 159          }
 160          xml_parser_free($this->_parser);
 161          // Grab the error messages, if any
 162          if ($this->messageType == 'fault') {
 163              $this->faultCode = $this->params[0]['faultCode'];
 164              $this->faultString = $this->params[0]['faultString'];
 165          }
 166          return true;
 167      }
 168      function tag_open($parser, $tag, $attr) {
 169          $this->currentTag = $tag;
 170          switch($tag) {
 171              case 'methodCall':
 172              case 'methodResponse':
 173              case 'fault':
 174                  $this->messageType = $tag;
 175                  break;
 176              /* Deal with stacks of arrays and structs */
 177              case 'data':    // data is to all intents and puposes more interesting than array
 178                  $this->_arraystructstypes[] = 'array';
 179                  $this->_arraystructs[] = array();
 180                  break;
 181              case 'struct':
 182                  $this->_arraystructstypes[] = 'struct';
 183                  $this->_arraystructs[] = array();
 184                  break;
 185          }
 186      }
 187      function cdata($parser, $cdata) {
 188          $this->_currentTagContents .= $cdata;
 189      }
 190      function tag_close($parser, $tag) {
 191          $valueFlag = false;
 192          switch($tag) {
 193              case 'int':
 194              case 'i4':
 195                  $value = (int)trim($this->_currentTagContents);
 196                  $this->_currentTagContents = '';
 197                  $valueFlag = true;
 198                  break;
 199              case 'double':
 200                  $value = (double)trim($this->_currentTagContents);
 201                  $this->_currentTagContents = '';
 202                  $valueFlag = true;
 203                  break;
 204              case 'string':
 205                  $value = (string)trim($this->_currentTagContents);
 206                  $this->_currentTagContents = '';
 207                  $valueFlag = true;
 208                  break;
 209              case 'dateTime.iso8601':
 210                  $value = new IXR_Date(trim($this->_currentTagContents));
 211                  // $value = $iso->getTimestamp();
 212                  $this->_currentTagContents = '';
 213                  $valueFlag = true;
 214                  break;
 215              case 'value':
 216                  // "If no type is indicated, the type is string."
 217                  if (trim($this->_currentTagContents) != '') {
 218                      $value = (string)$this->_currentTagContents;
 219                      $this->_currentTagContents = '';
 220                      $valueFlag = true;
 221                  }
 222                  break;
 223              case 'boolean':
 224                  $value = (boolean)trim($this->_currentTagContents);
 225                  $this->_currentTagContents = '';
 226                  $valueFlag = true;
 227                  break;
 228              case 'base64':
 229                  $value = base64_decode($this->_currentTagContents);
 230                  $this->_currentTagContents = '';
 231                  $valueFlag = true;
 232                  break;
 233              /* Deal with stacks of arrays and structs */
 234              case 'data':
 235              case 'struct':
 236                  $value = array_pop($this->_arraystructs);
 237                  array_pop($this->_arraystructstypes);
 238                  $valueFlag = true;
 239                  break;
 240              case 'member':
 241                  array_pop($this->_currentStructName);
 242                  break;
 243              case 'name':
 244                  $this->_currentStructName[] = trim($this->_currentTagContents);
 245                  $this->_currentTagContents = '';
 246                  break;
 247              case 'methodName':
 248                  $this->methodName = trim($this->_currentTagContents);
 249                  $this->_currentTagContents = '';
 250                  break;
 251          }
 252          if ($valueFlag) {
 253              /*
 254              if (!is_array($value) && !is_object($value)) {
 255                  $value = trim($value);
 256              }
 257              */
 258              if (count($this->_arraystructs) > 0) {
 259                  // Add value to struct or array
 260                  if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') {
 261                      // Add to struct
 262                      $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value;
 263                  } else {
 264                      // Add to array
 265                      $this->_arraystructs[count($this->_arraystructs)-1][] = $value;
 266                  }
 267              } else {
 268                  // Just add as a paramater
 269                  $this->params[] = $value;
 270              }
 271          }
 272      }       
 273  }
 274  
 275  
 276  class IXR_Server {
 277      var $data;
 278      var $callbacks = array();
 279      var $message;
 280      var $capabilities;
 281      var $defencoding = 'iso-8859-1';
 282      function IXR_Server($callbacks = false, $data = false) {
 283          $this->setCapabilities();
 284          if ($callbacks) {
 285              $this->callbacks = $callbacks;
 286          }
 287          $this->setCallbacks();
 288          $this->serve($data);
 289      }
 290      function serve($data = false) {
 291          if (!$data) {
 292              global $HTTP_RAW_POST_DATA;
 293              if (!$HTTP_RAW_POST_DATA) {
 294                 die('XML-RPC server accepts POST requests only.');
 295              }
 296              $data = $HTTP_RAW_POST_DATA;
 297          }
 298          $this->message = new IXR_Message($data);
 299          if (!$this->message->parse()) {
 300              $this->error(-32700, 'parse error. not well formed');
 301          }
 302          if ($this->message->messageType != 'methodCall') {
 303              $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall');
 304          }
 305          $result = $this->call($this->message->methodName, $this->message->params);
 306          // Is the result an error?
 307          if (is_a($result, 'IXR_Error')) {
 308              $this->error($result);
 309          }
 310          // Encode the result
 311          $r = new IXR_Value($result);
 312          $resultxml = $r->getXml();
 313          // Create the XML
 314          $xml = <<<EOD
 315  <methodResponse>
 316    <params>
 317      <param>
 318        <value>
 319          $resultxml
 320        </value>
 321      </param>
 322    </params>
 323  </methodResponse>
 324  
 325  EOD;
 326          // Send it
 327          $this->output($xml);
 328      }
 329      function call($methodname, $args) {
 330          if (!$this->hasMethod($methodname)) {
 331              return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.');
 332          }
 333          $method = $this->callbacks[$methodname];
 334          // Perform the callback and send the response
 335          if (count($args) == 1) {
 336              // If only one paramater just send that instead of the whole array
 337              $args = $args[0];
 338          }
 339          // Are we dealing with a function or a method?
 340          if (substr($method, 0, 5) == 'this:') {
 341              // It's a class method - check it exists
 342              $method = substr($method, 5);
 343              if (!method_exists($this, $method)) {
 344                  return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.');
 345              }
 346              // Call the method
 347              $result = $this->$method($args);
 348          } else {
 349              // It's a function - does it exist?
 350              if (!function_exists($method)) {
 351                  return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.');
 352              }
 353              // Call the function
 354              $result = $method($args);
 355          }
 356          return $result;
 357      }
 358  
 359      function error($error, $message = false) {
 360          // Accepts either an error object or an error code and message
 361          if ($message && !is_object($error)) {
 362              $error = new IXR_Error($error, $message);
 363          }
 364          $this->output($error->getXml());
 365      }
 366      function output($xml) {
 367          $xml = '<?xml version="1.0" encoding="'.$this->defencoding.'"?>'."\n".$xml;
 368          $length = strlen($xml);
 369          header('Connection: close');
 370          header('Content-Length: '.$length);
 371          header('Content-Type: text/xml');
 372          header('Date: '.date('r'));
 373          echo $xml;
 374          exit;
 375      }
 376      function hasMethod($method) {
 377          return in_array($method, array_keys($this->callbacks));
 378      }
 379      function setCapabilities() {
 380          // Initialises capabilities array
 381          $this->capabilities = array(
 382              'xmlrpc' => array(
 383                  'specUrl' => 'http://www.xmlrpc.com/spec',
 384                  'specVersion' => 1
 385              ),
 386              'faults_interop' => array(
 387                  'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
 388                  'specVersion' => 20010516
 389              ),
 390              'system.multicall' => array(
 391                  'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
 392                  'specVersion' => 1
 393              ),
 394          );   
 395      }
 396      function getCapabilities($args) {
 397          return $this->capabilities;
 398      }
 399      function setCallbacks() {
 400          $this->callbacks['system.getCapabilities'] = 'this:getCapabilities';
 401          $this->callbacks['system.listMethods'] = 'this:listMethods';
 402          $this->callbacks['system.multicall'] = 'this:multiCall';
 403      }
 404      function listMethods($args) {
 405          // Returns a list of methods - uses array_reverse to ensure user defined
 406          // methods are listed before server defined methods
 407          return array_reverse(array_keys($this->callbacks));
 408      }
 409      function multiCall($methodcalls) {
 410          // See http://www.xmlrpc.com/discuss/msgReader$1208
 411          $return = array();
 412          foreach ($methodcalls as $call) {
 413              $method = $call['methodName'];
 414              $params = $call['params'];
 415              if ($method == 'system.multicall') {
 416                  $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden');
 417              } else {
 418                  $result = $this->call($method, $params);
 419              }
 420              if (is_a($result, 'IXR_Error')) {
 421                  $return[] = array(
 422                      'faultCode' => $result->code,
 423                      'faultString' => $result->message
 424                  );
 425              } else {
 426                  $return[] = array($result);
 427              }
 428          }
 429          return $return;
 430      }
 431  }
 432  
 433  class IXR_Request {
 434      var $method;
 435      var $args;
 436      var $xml;
 437      function IXR_Request($method, $args) {
 438          $this->method = $method;
 439          $this->args = $args;
 440          $this->xml = <<<EOD
 441  <?xml version="1.0"?>
 442  <methodCall>
 443  <methodName>{$this->method}</methodName>
 444  <params>
 445  
 446  EOD;
 447          foreach ($this->args as $arg) {
 448              $this->xml .= '<param><value>';
 449              $v = new IXR_Value($arg);
 450              $this->xml .= $v->getXml();
 451              $this->xml .= "</value></param>\n";
 452          }
 453          $this->xml .= '</params></methodCall>';
 454      }
 455      function getLength() {
 456          return strlen($this->xml);
 457      }
 458      function getXml() {
 459          return $this->xml;
 460      }
 461  }
 462  
 463  
 464  class IXR_Client {
 465      var $server;
 466      var $port;
 467      var $path;
 468      var $useragent;
 469      var $response;
 470      var $message = false;
 471      var $debug = false;
 472      // Storage place for an error message
 473      var $error = false;
 474      function IXR_Client($server, $path = false, $port = 80) {
 475          if (!$path) {
 476              // Assume we have been given a URL instead
 477              $bits = parse_url($server);
 478              $this->server = $bits['host'];
 479              $this->port = isset($bits['port']) ? $bits['port'] : 80;
 480              $this->path = isset($bits['path']) ? $bits['path'] : '/';
 481              // Make absolutely sure we have a path
 482              if (!$this->path) {
 483                  $this->path = '/';
 484              }
 485          } else {
 486              $this->server = $server;
 487              $this->path = $path;
 488              $this->port = $port;
 489          }
 490          $this->useragent = 'The Incutio XML-RPC PHP Library';
 491      }
 492      function query() {
 493          $args = func_get_args();
 494          $method = array_shift($args);
 495          $request = new IXR_Request($method, $args);
 496          $length = $request->getLength();
 497          $xml = $request->getXml();
 498          $r = "\r\n";
 499          $request  = "POST {$this->path} HTTP/1.0$r";
 500          $request .= "Host: {$this->server}$r";
 501          $request .= "Content-Type: text/xml$r";
 502          $request .= "User-Agent: {$this->useragent}$r";
 503          $request .= "Content-length: {$length}$r$r";
 504          $request .= $xml;
 505          // Now send the request
 506          if ($this->debug) {
 507              echo '<pre>'.htmlspecialchars($request)."\n</pre>\n\n";
 508          }
 509          $fp = @fsockopen($this->server, $this->port);
 510          if (!$fp) {
 511              $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
 512              return false;
 513          }
 514          fputs($fp, $request);
 515          $contents = '';
 516          $gotFirstLine = false;
 517          $gettingHeaders = true;
 518          while (!feof($fp)) {
 519              $line = fgets($fp, 4096);
 520              if (!$gotFirstLine) {
 521                  // Check line for '200'
 522                  if (strstr($line, '200') === false) {
 523                      $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
 524                      return false;
 525                  }
 526                  $gotFirstLine = true;
 527              }
 528              if (trim($line) == '') {
 529                  $gettingHeaders = false;
 530              }
 531              if (!$gettingHeaders) {
 532                  $contents .= trim($line)."\n";
 533              }
 534          }
 535          if ($this->debug) {
 536              echo '<pre>'.htmlspecialchars($contents)."\n</pre>\n\n";
 537          }
 538          // Now parse what we've got back
 539          $this->message = new IXR_Message($contents);
 540          if (!$this->message->parse()) {
 541              // XML error
 542              $this->error = new IXR_Error(-32700, 'parse error. not well formed');
 543              return false;
 544          }
 545          // Is the message a fault?
 546          if ($this->message->messageType == 'fault') {
 547              $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);
 548              return false;
 549          }
 550          // Message must be OK
 551          return true;
 552      }
 553      function getResponse() {
 554          // methodResponses can only have one param - return that
 555          return $this->message->params[0];
 556      }
 557      function isError() {
 558          return (is_object($this->error));
 559      }
 560      function getErrorCode() {
 561          return $this->error->code;
 562      }
 563      function getErrorMessage() {
 564          return $this->error->message;
 565      }
 566  }
 567  
 568  
 569  class IXR_Error {
 570      var $code;
 571      var $message;
 572      function IXR_Error($code, $message) {
 573          $this->code = $code;
 574          $this->message = $message;
 575      }
 576      function getXml() {
 577          $xml = <<<EOD
 578  <methodResponse>
 579    <fault>
 580      <value>
 581        <struct>
 582          <member>
 583            <name>faultCode</name>
 584            <value><int>{$this->code}</int></value>
 585          </member>
 586          <member>
 587            <name>faultString</name>
 588            <value><string>{$this->message}</string></value>
 589          </member>
 590        </struct>
 591      </value>
 592    </fault>
 593  </methodResponse> 
 594  
 595  EOD;
 596          return $xml;
 597      }
 598  }
 599  
 600  
 601  class IXR_Date {
 602      var $year;
 603      var $month;
 604      var $day;
 605      var $hour;
 606      var $minute;
 607      var $second;
 608      function IXR_Date($time) {
 609          // $time can be a PHP timestamp or an ISO one
 610          if (is_numeric($time)) {
 611              $this->parseTimestamp($time);
 612          } else {
 613              $this->parseIso($time);
 614          }
 615      }
 616      function parseTimestamp($timestamp) {
 617          // bug corrected here
 618          $this->year = date('Y', $timestamp);
 619          $this->month = date('m', $timestamp);
 620          $this->day = date('d', $timestamp);
 621          $this->hour = date('H', $timestamp);
 622          $this->minute = date('i', $timestamp);
 623          $this->second = date('s', $timestamp);
 624      }
 625      function parseIso($iso) {
 626          $this->year = substr($iso, 0, 4);
 627          $this->month = substr($iso, 4, 2); 
 628          $this->day = substr($iso, 6, 2);
 629          $this->hour = substr($iso, 9, 2);
 630          $this->minute = substr($iso, 12, 2);
 631          $this->second = substr($iso, 15, 2);
 632      }
 633      function getIso() {
 634          return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second;
 635      }
 636      function getXml() {
 637          return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>';
 638      }
 639      function getTimestamp() {
 640          return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year);
 641      }
 642  }
 643  
 644  
 645  class IXR_Base64 {
 646      var $data;
 647      function IXR_Base64($data) {
 648          $this->data = $data;
 649      }
 650      function getXml() {
 651          return '<base64>'.base64_encode($this->data).'</base64>';
 652      }
 653  }
 654  
 655  
 656  class IXR_IntrospectionServer extends IXR_Server {
 657      var $signatures;
 658      var $help;
 659      function IXR_IntrospectionServer() {
 660          $this->setCallbacks();
 661          $this->setCapabilities();
 662          $this->capabilities['introspection'] = array(
 663              'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html',
 664              'specVersion' => 1
 665          );
 666          $this->addCallback(
 667              'system.methodSignature', 
 668              'this:methodSignature', 
 669              array('array', 'string'), 
 670              'Returns an array describing the return type and required parameters of a method'
 671          );
 672          $this->addCallback(
 673              'system.getCapabilities', 
 674              'this:getCapabilities', 
 675              array('struct'), 
 676              'Returns a struct describing the XML-RPC specifications supported by this server'
 677          );
 678          $this->addCallback(
 679              'system.listMethods', 
 680              'this:listMethods', 
 681              array('array'), 
 682              'Returns an array of available methods on this server'
 683          );
 684          $this->addCallback(
 685              'system.methodHelp', 
 686              'this:methodHelp', 
 687              array('string', 'string'), 
 688              'Returns a documentation string for the specified method'
 689          );
 690      }
 691      function addCallback($method, $callback, $args, $help) {
 692          $this->callbacks[$method] = $callback;
 693          $this->signatures[$method] = $args;
 694          $this->help[$method] = $help;
 695      }
 696      function call($methodname, $args) {
 697          // Make sure it's in an array
 698          if ($args && !is_array($args)) {
 699              $args = array($args);
 700          }
 701          // Over-rides default call method, adds signature check
 702          if (!$this->hasMethod($methodname)) {
 703              return new IXR_Error(-32601, 'server error. requested method "'.$this->message->methodName.'" not specified.');
 704          }
 705          $method = $this->callbacks[$methodname];
 706          $signature = $this->signatures[$methodname];
 707          $returnType = array_shift($signature);
 708          // Check the number of arguments
 709          if (count($args) != count($signature)) {
 710              // print 'Num of args: '.count($args).' Num in signature: '.count($signature);
 711              return new IXR_Error(-32602, 'server error. wrong number of method parameters');
 712          }
 713          // Check the argument types
 714          $ok = true;
 715          $argsbackup = $args;
 716          for ($i = 0, $j = count($args); $i < $j; $i++) {
 717              $arg = array_shift($args);
 718              $type = array_shift($signature);
 719              switch ($type) {
 720                  case 'int':
 721                  case 'i4':
 722                      if (is_array($arg) || !is_int($arg)) {
 723                          $ok = false;
 724                      }
 725                      break;
 726                  case 'base64':
 727                  case 'string':
 728                      if (!is_string($arg)) {
 729                          $ok = false;
 730                      }
 731                      break;
 732                  case 'boolean':
 733                      if ($arg !== false && $arg !== true) {
 734                          $ok = false;
 735                      }
 736                      break;
 737                  case 'float':
 738                  case 'double':
 739                      if (!is_float($arg)) {
 740                          $ok = false;
 741                      }
 742                      break;
 743                  case 'date':
 744                  case 'dateTime.iso8601':
 745                      if (!is_a($arg, 'IXR_Date')) {
 746                          $ok = false;
 747                      }
 748                      break;
 749              }
 750              if (!$ok) {
 751                  return new IXR_Error(-32602, 'server error. invalid method parameters');
 752              }
 753          }
 754          // It passed the test - run the "real" method call
 755          return parent::call($methodname, $argsbackup);
 756      }
 757      function methodSignature($method) {
 758          if (!$this->hasMethod($method)) {
 759              return new IXR_Error(-32601, 'server error. requested method "'.$method.'" not specified.');
 760          }
 761          // We should be returning an array of types
 762          $types = $this->signatures[$method];
 763          $return = array();
 764          foreach ($types as $type) {
 765              switch ($type) {
 766                  case 'string':
 767                      $return[] = 'string';
 768                      break;
 769                  case 'int':
 770                  case 'i4':
 771                      $return[] = 42;
 772                      break;
 773                  case 'double':
 774                      $return[] = 3.1415;
 775                      break;
 776                  case 'dateTime.iso8601':
 777                      $return[] = new IXR_Date(time());
 778                      break;
 779                  case 'boolean':
 780                      $return[] = true;
 781                      break;
 782                  case 'base64':
 783                      $return[] = new IXR_Base64('base64');
 784                      break;
 785                  case 'array':
 786                      $return[] = array('array');
 787                      break;
 788                  case 'struct':
 789                      $return[] = array('struct' => 'struct');
 790                      break;
 791              }
 792          }
 793          return $return;
 794      }
 795      function methodHelp($method) {
 796          return $this->help[$method];
 797      }
 798  }
 799  
 800  
 801  class IXR_ClientMulticall extends IXR_Client {
 802      var $calls = array();
 803      function IXR_ClientMulticall($server, $path = false, $port = 80) {
 804          parent::IXR_Client($server, $path, $port);
 805          $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
 806      }
 807      function addCall() {
 808          $args = func_get_args();
 809          $methodName = array_shift($args);
 810          $struct = array(
 811              'methodName' => $methodName,
 812              'params' => $args
 813          );
 814          $this->calls[] = $struct;
 815      }
 816      function query() {
 817          // Prepare multicall, then call the parent::query() method
 818          return parent::query('system.multicall', $this->calls);
 819      }
 820  }
 821  
 822  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics