diff --git includes/common.inc includes/common.inc index 37a0504..7dcd559 100644 --- includes/common.inc +++ includes/common.inc @@ -6751,12 +6751,16 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st * An absolute URL of the XML-RPC endpoint. * Example: * http://www.example.com/xmlrpc.php - * @param ... + * @param $args + * An array of arguments. * 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 $options + * Optional array of options for drupal_http_request(). + * * @return * For one request: * Either the return value of the method on success, or FALSE. @@ -6766,10 +6770,9 @@ function entity_form_submit_build_entity($entity_type, $entity, $form, &$form_st * 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 DRUPAL_ROOT . '/includes/xmlrpc.inc'; - $args = func_get_args(); - return call_user_func_array('_xmlrpc', $args); + return _xmlrpc($url, $args, $options); } /** diff --git includes/xmlrpc.inc includes/xmlrpc.inc index 20c2aab..12e1aab 100644 --- includes/xmlrpc.inc +++ includes/xmlrpc.inc @@ -530,12 +530,15 @@ function xmlrpc_base64_get_xml($xmlrpc_base64) { * @param $url * The absolute URL of the XML-RPC endpoint. Example: * http://www.example.com/xmlrpc.php - * @param ... + * @param $args + * Array of arguments. * - 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 $options + * Array of options for drupal_http_request(). * * @return * A single response (single request) or an array of responses (multicall @@ -544,9 +547,7 @@ function xmlrpc_base64_get_xml($xmlrpc_base64) { * is returned, see xmlrpc_errno() and xmlrpc_error_msg() to get more * information. */ -function _xmlrpc() { - $args = func_get_args(); - $url = array_shift($args); +function _xmlrpc($url, $args, $options) { xmlrpc_clear_error(); if (is_array($args[0])) { $method = 'system.multicall'; @@ -560,11 +561,10 @@ function _xmlrpc() { $method = array_shift($args); } $xmlrpc_request = xmlrpc_request($method, $args); - $options = array( - 'headers' => array('Content-Type' => 'text/xml'), - 'method' => 'POST', - 'data' => $xmlrpc_request->xml, - ); + // Required options which will replace any that are passed in. + $options['method'] = 'POST'; + $options['headers']['Content-Type'] = 'text/xml'; + $options['data'] = $xmlrpc_request->xml; $result = drupal_http_request($url, $options); if ($result->code != 200) { xmlrpc_error($result->code, $result->error); diff --git modules/simpletest/tests/xmlrpc.test modules/simpletest/tests/xmlrpc.test index 4f41ba2..b6a64a2 100644 --- modules/simpletest/tests/xmlrpc.test +++ modules/simpletest/tests/xmlrpc.test @@ -29,7 +29,7 @@ class XMLRPCBasicTestCase extends DrupalWebTestCase { // Invoke XML-RPC call to get list of methods. $url = url(NULL, array('absolute' => TRUE)) . 'xmlrpc.php'; - $methods = xmlrpc($url, 'system.listMethods'); + $methods = xmlrpc($url, array('system.listMethods')); // Ensure that the minimum methods were found. $count = 0; @@ -102,19 +102,19 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { array('larry' => mt_rand(-100, 100))); shuffle($array_1); $l_res_1 = xmlrpc_test_arrayOfStructsTest($array_1); - $r_res_1 = xmlrpc($xml_url, 'validator1.arrayOfStructsTest', $array_1); + $r_res_1 = xmlrpc($xml_url, array('validator1.arrayOfStructsTest', $array_1)); $this->assertIdentical($l_res_1, $r_res_1, 'array of structs test: %s'); $string_2 = 't\'&>>zf"md>yr>xlcev">>uai"np&s>>q\'&b<>"&&&'; $l_res_2 = xmlrpc_test_countTheEntities($string_2); - $r_res_2 = xmlrpc($xml_url, 'validator1.countTheEntities', $string_2); + $r_res_2 = xmlrpc($xml_url, array('validator1.countTheEntities', $string_2)); $this->assertIdentical($l_res_2, $r_res_2, 'count the entities test: %s'); $struct_3 = array('moe' => mt_rand(-100, 100), 'larry' => mt_rand(-100, 100), 'curly' => mt_rand(-100, 100), 'homer' => mt_rand(-100, 100)); $l_res_3 = xmlrpc_test_easyStructTest($struct_3); - $r_res_3 = xmlrpc($xml_url, 'validator1.easyStructTest', $struct_3); + $r_res_3 = xmlrpc($xml_url, array('validator1.easyStructTest', $struct_3)); $this->assertIdentical($l_res_3, $r_res_3, 'easy struct test: %s'); @@ -123,7 +123,7 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { 'sub3' => array('foo' => 1, 'baz' => 2), 'sub4' => array('ss' => array('sss' => array('ssss' => 'sssss')))); $l_res_4 = xmlrpc_test_echoStructTest($struct_4); - $r_res_4 = xmlrpc($xml_url, 'validator1.echoStructTest', $struct_4); + $r_res_4 = xmlrpc($xml_url, array('validator1.echoStructTest', $struct_4)); $this->assertIdentical($l_res_4, $r_res_4, 'echo struct test: %s'); $int_5 = mt_rand(-100, 100); @@ -134,7 +134,7 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { $base64_5 = $this->randomName(100); $l_res_5 = xmlrpc_test_manyTypesTest($int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), $base64_5); $l_res_5[5] = $l_res_5[5]->data; /* override warpping */ - $r_res_5 = xmlrpc($xml_url, 'validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5)); + $r_res_5 = xmlrpc($xml_url, array('validator1.manyTypesTest', $int_5, $bool_5, $string_5, $double_5, xmlrpc_date($time_5), xmlrpc_base64($base64_5))); /* Contains objects, objects are not equal */ // See http://drupal.org/node/37766 why this currently fails $this->assertEqual($l_res_5, $r_res_5, 'many types test: %s'); @@ -147,7 +147,7 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { } $l_res_6 = xmlrpc_test_moderateSizeArrayCheck($array_6); - $r_res_6 = xmlrpc($xml_url, 'validator1.moderateSizeArrayCheck', $array_6); + $r_res_6 = xmlrpc($xml_url, array('validator1.moderateSizeArrayCheck', $array_6)); $this->assertIdentical($l_res_6, $r_res_6, 'moderate size array check: %s'); @@ -165,13 +165,13 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { } } $l_res_7 = xmlrpc_test_nestedStructTest($struct_7); - $r_res_7 = xmlrpc($xml_url, 'validator1.nestedStructTest', $struct_7); + $r_res_7 = xmlrpc($xml_url, array('validator1.nestedStructTest', $struct_7)); $this->assertIdentical($l_res_7, $r_res_7, 'nested struct test: %s'); $int_8 = mt_rand(-100, 100); $l_res_8 = xmlrpc_test_simpleStructReturnTest($int_8); - $r_res_8 = xmlrpc($xml_url, 'validator1.simpleStructReturnTest', $int_8); + $r_res_8 = xmlrpc($xml_url, array('validator1.simpleStructReturnTest', $int_8)); $this->assertIdentical($l_res_8, $r_res_8, 'simple struct test: %s'); /* Now test multicall */ @@ -186,7 +186,7 @@ class XMLRPCValidator1IncTestCase extends DrupalWebTestCase { $x[] = array('validator1.simpleStructReturnTest', $int_8); $a_l_res = array($l_res_1, $l_res_2, $l_res_3, $l_res_4, $l_res_5, $l_res_6, $l_res_7, $l_res_8); - $a_r_res = xmlrpc($xml_url, $x); + $a_r_res = xmlrpc($xml_url, array($x)); $this->assertEqual($a_l_res, $a_r_res, 'multicall equals result'); } } @@ -212,7 +212,7 @@ class XMLRPCMessagesTestCase extends DrupalWebTestCase { $sizes = array(8, 80, 160); foreach ($sizes as $size) { $xml_message_l = xmlrpc_test_message_sized_in_kb($size); - $xml_message_r = xmlrpc($xml_url, 'messages.messageSizedInKB', $size); + $xml_message_r = xmlrpc($xml_url, array('messages.messageSizedInKB', $size)); $this->assertEqual($xml_message_l, $xml_message_r, t('XML-RPC messages.messageSizedInKB of %s Kb size received', array('%s' => $size))); }