+
+
+
+
+ faultCode
+ {$xmlrpc_error->code}
+
+
+ faultString
+ {$xmlrpc_error->message}
+
+
+
+
+
+
+EOD;
+}
+
+/**
+ * Converts a PHP or ISO date/time to an XML-RPC object.
+ *
+ * @param $time
+ * A PHP timestamp or an ISO date-time string.
+ *
+ * @return object
+ * An XML-RPC time/date object.
+ */
+function xmlrpc_date($time) {
+ $xmlrpc_date = new stdClass();
+ $xmlrpc_date->is_date = TRUE;
+ // $time can be a PHP timestamp or an ISO one
+ if (is_numeric($time)) {
+ $xmlrpc_date->year = gmdate('Y', $time);
+ $xmlrpc_date->month = gmdate('m', $time);
+ $xmlrpc_date->day = gmdate('d', $time);
+ $xmlrpc_date->hour = gmdate('H', $time);
+ $xmlrpc_date->minute = gmdate('i', $time);
+ $xmlrpc_date->second = gmdate('s', $time);
+ $xmlrpc_date->iso8601 = gmdate('Ymd\TH:i:s', $time);
+ }
+ else {
+ $xmlrpc_date->iso8601 = $time;
+ $time = str_replace(array('-', ':'), '', $time);
+ $xmlrpc_date->year = substr($time, 0, 4);
+ $xmlrpc_date->month = substr($time, 4, 2);
+ $xmlrpc_date->day = substr($time, 6, 2);
+ $xmlrpc_date->hour = substr($time, 9, 2);
+ $xmlrpc_date->minute = substr($time, 11, 2);
+ $xmlrpc_date->second = substr($time, 13, 2);
+ }
+ return $xmlrpc_date;
+}
+
+/**
+ * Converts an XML-RPC date-time object into XML.
+ *
+ * @param $xmlrpc_date
+ * The XML-RPC date-time object.
+ *
+ * @return string
+ * An XML representation of the date/time as XML.
+ */
+function xmlrpc_date_get_xml($xmlrpc_date) {
+ return '' . $xmlrpc_date->year . $xmlrpc_date->month . $xmlrpc_date->day . 'T' . $xmlrpc_date->hour . ':' . $xmlrpc_date->minute . ':' . $xmlrpc_date->second . '';
+}
+
+/**
+ * Returns an XML-RPC base 64 object.
+ *
+ * @param $data
+ * Base 64 data to store in returned object.
+ *
+ * @return object
+ * An XML-RPC base 64 object.
+ */
+function xmlrpc_base64($data) {
+ $xmlrpc_base64 = new stdClass();
+ $xmlrpc_base64->is_base64 = TRUE;
+ $xmlrpc_base64->data = $data;
+ return $xmlrpc_base64;
+}
+
+/**
+ * Converts an XML-RPC base 64 object into XML.
+ *
+ * @param $xmlrpc_base64
+ * The XML-RPC base 64 object.
+ *
+ * @return string
+ * An XML representation of the base 64 data as XML.
+ */
+function xmlrpc_base64_get_xml($xmlrpc_base64) {
+ return '' . base64_encode($xmlrpc_base64->data) . '';
+}
+
+/**
+ * Performs one or more XML-RPC requests.
+ *
+ * @param string $url
+ * An absolute URL of the XML-RPC endpoint, e.g.,
+ * http://example.com/xmlrpc.php
+ * @param array $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 array $headers
+ * (optional) An array of HTTP headers to pass along.
+ *
+ * @return
+ * A single response (single request) or an array of responses (multicall
+ * request). Each response is the return value of the method, just as if it
+ * has been a local function call, on success, or FALSE on failure. If FALSE
+ * is returned, see xmlrpc_errno() and xmlrpc_error_msg() to get more
+ * information.
+ */
+function _xmlrpc($url, array $args, array $headers = array()) {
+ xmlrpc_clear_error();
+ if (count($args) > 1) {
+ $multicall_args = array();
+ foreach ($args as $method => $call) {
+ $multicall_args[] = array('methodName' => $method, 'params' => $call);
+ }
+ $method = 'system.multicall';
+ $args = array($multicall_args);
+ }
+ else {
+ $method = key($args);
+ $args = $args[$method];
+ }
+ $xmlrpc_request = xmlrpc_request($method, $args);
+ $request = \Drupal::httpClient()->post($url, $headers, $xmlrpc_request->xml);
+ $request->setHeader('Content-Type', 'text/xml');
+ try {
+ $response = $request->send();
+ }
+ catch (BadResponseException $exception) {
+ $response = $exception->getResponse();
+ xmlrpc_error($response->getStatusCode(), $response->getReasonPhrase());
+ return FALSE;
+ }
+ catch (RequestException $exception) {
+ xmlrpc_error(NULL, $exception->getMethod());
+ return FALSE;
+ }
+ $message = xmlrpc_message($response->getBody(TRUE));
+ // 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;
+}
+
+/**
+ * Returns the last XML-RPC client error number.
+ */
+function xmlrpc_errno() {
+ $error = xmlrpc_error();
+ return ($error != NULL ? $error->code : NULL);
+}
+
+/**
+ * Returns the last XML-RPC client error message.
+ */
+function xmlrpc_error_msg() {
+ $error = xmlrpc_error();
+ return ($error != NULL ? $error->message : NULL);
+}
+
+/**
+ * Clears any previously-saved errors.
+ *
+ * @see xmlrpc_error()
+ */
+function xmlrpc_clear_error() {
+ xmlrpc_error(NULL, NULL, TRUE);
+}
reverted:
--- /dev/null
+++ a/core/modules/xmlrpc/xmlrpc.info.yml
@@ -0,0 +1,6 @@
+name: XML-RPC
+type: module
+description: 'Provides XML-RPC functionality.'
+package: Core
+version: VERSION
+core: 8.x
reverted:
--- /dev/null
+++ a/core/modules/xmlrpc/xmlrpc.module
@@ -0,0 +1,52 @@
+' . t('About') . '';
+ $output .= '' . t('The XML-RPC module gives external systems the opportunity to communicate with the site through the XML-RPC protocol. An XML-RPC client can communicate with the site by making a request to xmlrpc.php. For more information, see the online documentation for the XML-RPC module.', array('!xrphp' => \Drupal::url('xmlrpc.php'),'!xrdocs' => 'https://drupal.org/documentation/modules/xmlrpc')) . '
';
+ return $output;
+ }
+}
+
+/**
+ * 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 string $url
+ * An absolute URL of the XML-RPC endpoint.
+ * @param array $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 array $headers
+ * (optional) An array of headers to pass along.
+ *
+ * @return
+ * 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().
+ */
+function xmlrpc($url, array $args, array $headers = array()) {
+ module_load_include('inc', 'xmlrpc');
+ return _xmlrpc($url, $args, $headers);
+}
reverted:
--- /dev/null
+++ a/core/modules/xmlrpc/xmlrpc.routing.yml
@@ -0,0 +1,7 @@
+xmlrpc.php:
+ path: '/xmlrpc.php'
+ defaults:
+ _title: 'XML-RPC'
+ _content: '\Drupal\xmlrpc\Controller\XmlrpcController::php'
+ requirements:
+ _access: 'TRUE'
reverted:
--- /dev/null
+++ a/core/modules/xmlrpc/xmlrpc.server.inc
@@ -0,0 +1,410 @@
+invokeAll('xmlrpc'));
+}
+
+/**
+ * Invokes XML-RPC methods on this server.
+ *
+ * @param array $callbacks
+ * Array of external XML-RPC method names with the callbacks they map to.
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ * A Response object.
+ */
+function xmlrpc_server($callbacks) {
+ $xmlrpc_server = new stdClass();
+ // Define built-in XML-RPC method names
+ $defaults = array(
+ 'system.multicall' => 'xmlrpc_server_multicall',
+ array(
+ 'system.methodSignature',
+ 'xmlrpc_server_method_signature',
+ array('array', 'string'),
+ 'Returns an array describing the return type and required parameters of a method.',
+ ),
+ array(
+ 'system.getCapabilities',
+ 'xmlrpc_server_get_capabilities',
+ array('struct'),
+ 'Returns a struct describing the XML-RPC specifications supported by this server.',
+ ),
+ array(
+ 'system.listMethods',
+ 'xmlrpc_server_list_methods',
+ array('array'),
+ 'Returns an array of available methods on this server.',
+ ),
+ array(
+ 'system.methodHelp',
+ 'xmlrpc_server_method_help',
+ array('string', 'string'),
+ 'Returns a documentation string for the specified method.',
+ ),
+ );
+ // We build an array of all method names by combining the built-ins
+ // with those defined by modules implementing the _xmlrpc hook.
+ // Built-in methods are overridable.
+ $callbacks = array_merge($defaults, (array) $callbacks);
+ drupal_alter('xmlrpc', $callbacks);
+ foreach ($callbacks as $key => $callback) {
+ // we could check for is_array($callback)
+ if (is_int($key)) {
+ $method = $callback[0];
+ $xmlrpc_server->callbacks[$method] = $callback[1];
+ $xmlrpc_server->signatures[$method] = $callback[2];
+ $xmlrpc_server->help[$method] = $callback[3];
+ }
+ else {
+ $xmlrpc_server->callbacks[$key] = $callback;
+ $xmlrpc_server->signatures[$key] = '';
+ $xmlrpc_server->help[$key] = '';
+ }
+ }
+
+ $data = file_get_contents('php://input');
+ if (!$data) {
+ throw new BadRequestHttpException('XML-RPC server accepts POST requests only.');
+ }
+ $xmlrpc_server->message = xmlrpc_message($data);
+ if (!xmlrpc_message_parse($xmlrpc_server->message)) {
+ return xmlrpc_server_error(-32700, t('Parse error. Request not well formed.'));
+ }
+ if ($xmlrpc_server->message->messagetype != 'methodCall') {
+ return xmlrpc_server_error(-32600, t('Server error. Invalid XML-RPC. Request must be a methodCall.'));
+ }
+ if (!isset($xmlrpc_server->message->params)) {
+ $xmlrpc_server->message->params = array();
+ }
+ xmlrpc_server_set($xmlrpc_server);
+ $result = xmlrpc_server_call($xmlrpc_server, $xmlrpc_server->message->methodname, $xmlrpc_server->message->params);
+
+ if (is_object($result) && !empty($result->is_error)) {
+ return xmlrpc_server_error($result);
+ }
+ // Encode the result
+ $r = xmlrpc_value($result);
+ // Create the XML
+ $xml = '
+
+
+
+ ' . xmlrpc_value_get_xml($r) . '
+
+
+
+
+';
+ // Send it
+ return xmlrpc_server_output($xml);
+}
+
+/**
+ * Throws an XML-RPC error.
+ *
+ * @param $error
+ * An error object or integer error code.
+ * @param $message
+ * (optional) The description of the error. Used only if an integer error
+ * code was passed in.
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ * A Response object.
+ */
+function xmlrpc_server_error($error, $message = FALSE) {
+ if ($message && !is_object($error)) {
+ $error = xmlrpc_error($error, $message);
+ }
+ return xmlrpc_server_output(xmlrpc_error_get_xml($error));
+}
+
+/**
+ * Sends XML-RPC output to the browser.
+ *
+ * @param string $xml
+ * XML to send to the browser.
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ * A Response object.
+ */
+function xmlrpc_server_output($xml) {
+ $xml = '' . "\n" . $xml;
+ $headers = array(
+ 'Content-Length' => strlen($xml),
+ 'Content-Type' => 'text/xml'
+ );
+ return new Response($xml, 200, $headers);
+}
+
+/**
+ * Stores a copy of an XML-RPC request temporarily.
+ *
+ * @param object $xmlrpc_server
+ * (optional) Request object created by xmlrpc_server(). Omit to leave the
+ * previous server object saved.
+ *
+ * @return
+ * The latest stored request.
+ *
+ * @see xmlrpc_server_get()
+ */
+function xmlrpc_server_set($xmlrpc_server = NULL) {
+ static $server;
+ if (!isset($server)) {
+ $server = $xmlrpc_server;
+ }
+ return $server;
+}
+
+/**
+ * Retrieves the latest stored XML-RPC request.
+ *
+ * @return object
+ * The stored request.
+ *
+ * @see xmlrpc_server_set()
+ */
+function xmlrpc_server_get() {
+ return xmlrpc_server_set();
+}
+
+/**
+ * Dispatches an XML-RPC request and any parameters to the appropriate handler.
+ *
+ * @param object $xmlrpc_server
+ * Object containing information about this XML-RPC server, the methods it
+ * provides, their signatures, etc.
+ * @param string $methodname
+ * The external XML-RPC method name; e.g., 'system.methodHelp'.
+ * @param array $args
+ * Array containing any parameters that are to be sent along with the request.
+ *
+ * @return
+ * The results of the call.
+ */
+function xmlrpc_server_call($xmlrpc_server, $methodname, $args) {
+ // Make sure parameters are in an array
+ if ($args && !is_array($args)) {
+ $args = array($args);
+ }
+ // Has this method been mapped to a Drupal function by us or by modules?
+ if (!isset($xmlrpc_server->callbacks[$methodname])) {
+ return xmlrpc_error(-32601, t('Server error. Requested method @methodname not specified.', array("@methodname" => $xmlrpc_server->message->methodname)));
+ }
+ $method = $xmlrpc_server->callbacks[$methodname];
+ $signature = $xmlrpc_server->signatures[$methodname];
+
+ // If the method has a signature, validate the request against the signature
+ if (is_array($signature)) {
+ $ok = TRUE;
+ // Remove first element of $signature which is the unused 'return type'.
+ array_shift($signature);
+ // Check the number of arguments
+ if (count($args) != count($signature)) {
+ return xmlrpc_error(-32602, t('Server error. Wrong number of method parameters.'));
+ }
+ // Check the argument types
+ foreach ($signature as $key => $type) {
+ $arg = $args[$key];
+ switch ($type) {
+ case 'int':
+ case 'i4':
+ if (is_array($arg) || !is_int($arg)) {
+ $ok = FALSE;
+ }
+ break;
+
+ case 'base64':
+ case 'string':
+ if (!is_string($arg)) {
+ $ok = FALSE;
+ }
+ break;
+
+ case 'boolean':
+ if ($arg !== FALSE && $arg !== TRUE) {
+ $ok = FALSE;
+ }
+ break;
+
+ case 'float':
+ case 'double':
+ if (!is_float($arg)) {
+ $ok = FALSE;
+ }
+ break;
+
+ case 'date':
+ case 'dateTime.iso8601':
+ if (!$arg->is_date) {
+ $ok = FALSE;
+ }
+ break;
+ }
+ if (!$ok) {
+ return xmlrpc_error(-32602, t('Server error. Invalid method parameters.'));
+ }
+ }
+ }
+
+ if (!function_exists($method)) {
+ return xmlrpc_error(-32601, t('Server error. Requested function @method does not exist.', array("@method" => $method)));
+ }
+ // Call the mapped function
+ return call_user_func_array($method, $args);
+}
+
+/**
+ * Dispatches multiple XML-RPC requests.
+ *
+ * @param array $methodcalls
+ * An array of XML-RPC requests to make. Each request is an array with the
+ * following elements:
+ * - methodName: Name of the method to invoke.
+ * - params: Parameters to pass to the method.
+ *
+ * @return
+ * An array of the results of each request.
+ *
+ * @see xmlrpc_server_call()
+ */
+function xmlrpc_server_multicall($methodcalls) {
+ // See http://www.xmlrpc.com/discuss/msgReader$1208
+ $return = array();
+ $xmlrpc_server = xmlrpc_server_get();
+ foreach ($methodcalls as $call) {
+ $ok = TRUE;
+ if (!isset($call['methodName']) || !isset($call['params'])) {
+ $result = xmlrpc_error(3, t('Invalid syntax for system.multicall.'));
+ $ok = FALSE;
+ }
+ $method = $call['methodName'];
+ $params = $call['params'];
+ if ($method == 'system.multicall') {
+ $result = xmlrpc_error(-32600, t('Recursive calls to system.multicall are forbidden.'));
+ }
+ elseif ($ok) {
+ $result = xmlrpc_server_call($xmlrpc_server, $method, $params);
+ }
+ if (is_object($result) && !empty($result->is_error)) {
+ $return[] = array(
+ 'faultCode' => $result->code,
+ 'faultString' => $result->message,
+ );
+ }
+ else {
+ $return[] = array($result);
+ }
+ }
+ return $return;
+}
+
+/**
+ * Lists the methods available on this XML-RPC server.
+ *
+ * XML-RPC method system.listMethods maps to this function.
+ *
+ * @return array
+ * Array of the names of methods available on this server.
+ */
+function xmlrpc_server_list_methods() {
+ $xmlrpc_server = xmlrpc_server_get();
+ return array_keys($xmlrpc_server->callbacks);
+}
+
+/**
+ * Returns a list of the capabilities of this server.
+ *
+ * XML-RPC method system.getCapabilities maps to this function.
+ *
+ * @return array
+ * Array of server capabilities.
+ *
+ * @see http://groups.yahoo.com/group/xml-rpc/message/2897
+ */
+function xmlrpc_server_get_capabilities() {
+ return array(
+ 'xmlrpc' => array(
+ 'specUrl' => 'http://www.xmlrpc.com/spec',
+ 'specVersion' => 1,
+ ),
+ 'faults_interop' => array(
+ 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
+ 'specVersion' => 20010516,
+ ),
+ 'system.multicall' => array(
+ 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
+ 'specVersion' => 1,
+ ),
+ 'introspection' => array(
+ 'specUrl' => 'http://scripts.incutio.com/xmlrpc/introspection.html',
+ 'specVersion' => 1,
+ ),
+ );
+}
+
+/**
+ * Returns one method signature for a function.
+ *
+ * This is the function mapped to the XML-RPC method system.methodSignature.
+ *
+ * A method signature is an array of the input and output types of a method. For
+ * instance, the method signature of this function is array('array', 'string'),
+ * because it takes an array and returns a string.
+ *
+ * @param string $methodname
+ * Name of method to return a method signature for.
+ *
+ * @return array
+ * An array of arrays of types, each of the arrays representing one method
+ * signature of the function that $methodname maps to.
+ */
+function xmlrpc_server_method_signature($methodname) {
+ $xmlrpc_server = xmlrpc_server_get();
+ if (!isset($xmlrpc_server->callbacks[$methodname])) {
+ return xmlrpc_error(-32601, t('Server error. Requested method @methodname not specified.', array("@methodname" => $methodname)));
+ }
+ if (!is_array($xmlrpc_server->signatures[$methodname])) {
+ return xmlrpc_error(-32601, t('Server error. Requested method @methodname signature not specified.', array("@methodname" => $methodname)));
+ }
+ // We array of types
+ $return = array();
+ foreach ($xmlrpc_server->signatures[$methodname] as $type) {
+ $return[] = $type;
+ }
+ return array($return);
+}
+
+/**
+ * Returns the help for an XML-RPC method.
+ *
+ * XML-RPC method system.methodHelp maps to this function.
+ *
+ * @param string $method
+ * Name of method for which we return a help string.
+ *
+ * @return string
+ * Help text for $method.
+ */
+function xmlrpc_server_method_help($method) {
+ $xmlrpc_server = xmlrpc_server_get();
+ return $xmlrpc_server->help[$method];
+}