You are here

function _acquia_agent_xmlrpc in Acquia Connector 6

Same name and namespace in other branches
  1. 6.2 acquia_agent/acquia_agent_streams.inc \_acquia_agent_xmlrpc()

Performs one or more XML-RPC request(s), using a PHP stream context when creating the socket. This function is copied and modified from Drupal 6's common.inc and xmlrpc.inc.

This function should never be called directly - use acquia_agent_call().

Parameters

$context: A PHP stream context created with stream_create_context(). This context will be used when a socket connection to the XML-RPC endpoint is created.

...: The rest of the parameters and return values are the same as xmlrpc().

1 call to _acquia_agent_xmlrpc()
_acquia_agent_request in acquia_agent/acquia_agent_streams.inc
Send a XML-RPC request.

File

acquia_agent/acquia_agent_streams.inc, line 28
XML-RPC communication functions for Acquia communication.

Code

function _acquia_agent_xmlrpc() {
  require_once './includes/xmlrpc.inc';
  $args = func_get_args();
  $context = array_shift($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);
  $result = acquia_agent_http_request($context, $url, array(
    "Content-Type" => "text/xml",
  ), 'POST', $xmlrpc_request->xml);
  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];
}