_xmlrpc

Versions
4.7 – 7
_xmlrpc()

Performs one or more XML-RPC request(s).

Parameters

$url An absolute URL of the XML-RPC endpoint. Example: http://www.example.com/xmlrpc.php

... For one request: The method name followed by a variable number of arguments to the method. For multiple requests (system.multicall): An array of call arrays. Each call array follows the pattern of the single request: method name followed by the arguments to the method.

Return value

For one request: Either the return value of the method on success, or FALSE. If FALSE is returned, see xmlrpc_errno() and xmlrpc_error_msg(). For multiple requests: An array of results. Each result will either be the result returned by the method called, or an xmlrpc_error object if the call failed. See xmlrpc_error().

Code

includes/xmlrpc.inc, line 440

<?php
function _xmlrpc() {
  $args = func_get_args();
  $url = array_shift($args);
  if (is_array($args[0])) {
    $method = 'system.multicall';
    $multicall_args = array();
    foreach ($args[0] as $call) {
      $multicall_args[] = array('methodName' => array_shift($call), 'params' => $call);
    }
    $args = array($multicall_args);
  }
  else {
    $method = array_shift($args);
  }
  $xmlrpc_request = xmlrpc_request($method, $args);
  $options = array(
    'headers' => array('Content-Type' => 'text/xml'),
    'method' => 'POST',
    'data' => $xmlrpc_request->xml,
  );
  $result = drupal_http_request($url, $options);
  if ($result->code != 200) {
    xmlrpc_error($result->code, $result->error);
    return FALSE;
  }
  $message = xmlrpc_message($result->data);
  // Now parse what we've got back
  if (!xmlrpc_message_parse($message)) {
    // XML error
    xmlrpc_error(-32700, t('Parse error. Not well formed'));
    return FALSE;
  }
  // Is the message a fault?
  if ($message->messagetype == 'fault') {
    xmlrpc_error($message->fault_code, $message->fault_string);
    return FALSE;
  }
  // Message must be OK
  return $message->params[0];
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.