_xmlrpc

Versions
mediamosa-21
_xmlrpc()

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

See also

xmlrpc_error()

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

Either the return value of the method on success, or FALSE. If FALSE is returned, see xmlrpc_errno() and xmlrpc_error_msg().

  • For a non-multicall request: the result just as if this had been a local function call.
  • For a multicall request: an array of results. Each result will either be a one-element array containing the result returned by the method called, or an xmlrpc_error object if the call failed.

Code

includes/xmlrpc.inc, line 450

<?php
function _xmlrpc() {
  $args = func_get_args();
  $url = array_shift($args);
  xmlrpc_clear_error();
  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;
  }
  // We now know that the message is well-formed and a non-fault result.
  if ($method == 'system.multicall') {
    // Return per-method results or error objects.
    $return = array();
    foreach ($message->params[0] as $result) {
      if (array_keys($result) == array(0)) {
        $return[] = $result[0];
      }
      else {
        $return[] = xmlrpc_error($result['faultCode'], $result['faultString']);
      }
    }
  }
  else {
    $return = $message->params[0];
  }
  return $return;
}
?>