You are here

function xmlrpc_message_parse in Drupal 4

Same name and namespace in other branches
  1. 5 includes/xmlrpc.inc \xmlrpc_message_parse()
  2. 6 includes/xmlrpc.inc \xmlrpc_message_parse()
  3. 7 includes/xmlrpc.inc \xmlrpc_message_parse()

Parse an XML-RPC message. If parsing fails, the faultCode and faultString will be added to the message object.

Parameters

$xmlrpc_message: Object generated by xmlrpc_message()

Return value

TRUE if parsing succeeded; FALSE otherwise

2 calls to xmlrpc_message_parse()
xmlrpc_server in includes/xmlrpcs.inc
The main entry point for XML-RPC requests.
_xmlrpc in includes/xmlrpc.inc
Execute an XML remote procedural call. This is private function; call xmlrpc() in common.inc instead of this functino.

File

includes/xmlrpc.inc, line 157

Code

function xmlrpc_message_parse(&$xmlrpc_message) {

  // First remove the XML declaration
  $xmlrpc_message->message = preg_replace('/<\\?xml(.*)?\\?' . '>/', '', $xmlrpc_message->message);
  if (trim($xmlrpc_message->message) == '') {
    return FALSE;
  }
  $xmlrpc_message->_parser = xml_parser_create();

  // Set XML parser to take the case of tags into account
  xml_parser_set_option($xmlrpc_message->_parser, XML_OPTION_CASE_FOLDING, FALSE);

  // Set XML parser callback functions

  /* Do not set object. $xmlrpc_message does not have member functions any more
    xml_set_object($xmlrpc_message->_parser, $xmlrpc_message); */
  xml_set_element_handler($xmlrpc_message->_parser, 'xmlrpc_message_tag_open', 'xmlrpc_message_tag_close');
  xml_set_character_data_handler($xmlrpc_message->_parser, 'xmlrpc_message_cdata');
  xmlrpc_message_set($xmlrpc_message);
  if (!xml_parse($xmlrpc_message->_parser, $xmlrpc_message->message)) {
    return FALSE;
  }
  xml_parser_free($xmlrpc_message->_parser);

  // Grab the error messages, if any
  $xmlrpc_message = xmlrpc_message_get();
  if ($xmlrpc_message->messagetype == 'fault') {
    $xmlrpc_message->fault_code = $xmlrpc_message->params[0]['faultCode'];
    $xmlrpc_message->fault_string = $xmlrpc_message->params[0]['faultString'];
  }
  return TRUE;
}