Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.756.2.97 diff -u -p -r1.756.2.97 common.inc --- includes/common.inc 11 Aug 2010 21:10:41 -0000 1.756.2.97 +++ includes/common.inc 14 Aug 2010 13:04:44 -0000 @@ -2618,16 +2618,22 @@ function drupal_valid_token($token, $val /** * Performs one or more XML-RPC request(s). * + * Usage example: + * @code + * $result = xmlrpc('http://example.com/xmlrpc.php', array( + * 'service.methodName' => array($parameter, $second, $third), + * )); + * @endcode + * * @param $url * An absolute URL of the XML-RPC endpoint. - * Example: - * http://www.example.com/xmlrpc.php - * @param ... - * 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. + * @param $args + * An associative array whose keys are the methods to call and whose values + * are the arguments to pass to the respective method. If multiple methods + * are specified, a system.multicall is performed. + * @param $options + * (optional) An array of options to pass along to drupal_http_request(). + * * @return * For one request: * Either the return value of the method on success, or FALSE. @@ -2637,10 +2643,30 @@ function drupal_valid_token($token, $val * returned by the method called, or an xmlrpc_error object if the call * failed. See xmlrpc_error(). */ -function xmlrpc($url) { +function xmlrpc($url, $args, $options = array()) { require_once './includes/xmlrpc.inc'; - $args = func_get_args(); - return call_user_func_array('_xmlrpc', $args); + + // Backwards compatibility for function arguments used in Drupal <6.20. + if (is_string($args) || isset($args[0][0])) { + $old_args = func_get_args(); + array_shift($old_args); + $options = array(); + // Old single request syntax ($args is method name to call). + if (is_string($args)) { + $method = array_shift($old_args); + $args = array($method => $old_args); + } + // Old multicall syntax ($args is an indexed array). + elseif (isset($args[0][0])) { + $args = array(); + foreach (array_shift($old_args) as $call_args) { + $method = array_shift($call_args); + $args[$method] = array($call_args); + } + } + } + + return _xmlrpc($url, $args, $options); } function _drupal_bootstrap_full() { Index: includes/xmlrpc.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/xmlrpc.inc,v retrieving revision 1.47.2.6 diff -u -p -r1.47.2.6 xmlrpc.inc --- includes/xmlrpc.inc 2 Jun 2010 12:22:02 -0000 1.47.2.6 +++ includes/xmlrpc.inc 14 Aug 2010 12:57:53 -0000 @@ -424,23 +424,25 @@ function xmlrpc_base64_get_xml($xmlrpc_b * @return * A $xmlrpc_message object if the call succeeded; FALSE if the call failed */ -function _xmlrpc() { - $args = func_get_args(); - $url = array_shift($args); +function _xmlrpc($url, $args, $options = array()) { xmlrpc_clear_error(); - if (is_array($args[0])) { - $method = 'system.multicall'; + if (count($args) > 1) { $multicall_args = array(); - foreach ($args[0] as $call) { - $multicall_args[] = array('methodName' => array_shift($call), 'params' => $call); + foreach ($args as $method => $call) { + $multicall_args[] = array('methodName' => $method, 'params' => $call); } + $method = 'system.multicall'; $args = array($multicall_args); } else { - $method = array_shift($args); + $method = key($args); + $args = $args[$method]; } $xmlrpc_request = xmlrpc_request($method, $args); - $result = drupal_http_request($url, array("Content-Type" => "text/xml"), 'POST', $xmlrpc_request->xml); + // Required options which will replace any that are passed in. + $options['headers']['Content-Type'] = 'text/xml'; + $retry = (isset($options['retry']) ? $options['retry'] : 3); + $result = drupal_http_request($url, $options['headers'], 'POST', $xmlrpc_request->xml, $retry); if ($result->code != 200) { xmlrpc_error($result->code, $result->error); return FALSE;