You are here

function xmlrpc_server_call in xmlrpc 8

Dispatches an XML-RPC request and any parameters to the appropriate handler.

Parameters

object $xmlrpc_server: Object containing information about this XML-RPC server, the methods it provides, their signatures, etc.

string $method_name: The external XML-RPC method name; e.g., 'system.methodHelp'.

array $args: Array containing any parameters that are to be sent along with the request.

Return value

mixed The results of the call.

2 calls to xmlrpc_server_call()
xmlrpc_server in ./xmlrpc.server.inc
Invokes XML-RPC methods on this server.
xmlrpc_server_multicall in ./xmlrpc.server.inc
Dispatches multiple XML-RPC requests.

File

./xmlrpc.server.inc, line 192
Page callback file for the xmlrpc module.

Code

function xmlrpc_server_call($xmlrpc_server, $method_name, array $args) {

  // Make sure parameters are in an array.
  if ($args && !is_array($args)) {
    $args = [
      $args,
    ];
  }

  // Has this method been mapped to a Drupal function by us or by modules?
  if (!isset($xmlrpc_server->callbacks[$method_name])) {
    return xmlrpc_error(-32601, t('Server error. Requested method @method_name not specified.', [
      "@method_name" => $xmlrpc_server->message->methodname,
    ]));
  }
  $method = $xmlrpc_server->callbacks[$method_name];
  $signature = $xmlrpc_server->signatures[$method_name];

  // 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.', [
      "@method" => $method,
    ]));
  }

  // Call the mapped function.
  return call_user_func_array($method, $args);
}