Commit c03800e0 authored by Dries's avatar Dries

- Patch #861420 by sun: coder_format() on xmlrpc(s).inc.

parent d79dff03
......@@ -65,7 +65,7 @@ function xmlrpc_value_calculate_type($xmlrpc_value) {
return 'double';
}
if (is_int($xmlrpc_value->data)) {
return 'int';
return 'int';
}
if (is_array($xmlrpc_value->data)) {
// empty or integer-indexed arrays are 'array', string-indexed arrays 'struct'
......@@ -98,18 +98,18 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
switch ($xmlrpc_value->type) {
case 'boolean':
return '<boolean>' . (($xmlrpc_value->data) ? '1' : '0') . '</boolean>';
break;
case 'int':
return '<int>' . $xmlrpc_value->data . '</int>';
break;
case 'double':
return '<double>' . $xmlrpc_value->data . '</double>';
break;
case 'string':
// Note: we don't escape apostrophes because of the many blogging clients
// that don't support numerical entities (and XML in general) properly.
return '<string>' . htmlspecialchars($xmlrpc_value->data) . '</string>';
break;
case 'array':
$return = '<array><data>' . "\n";
foreach ($xmlrpc_value->data as $item) {
......@@ -117,7 +117,7 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
}
$return .= '</data></array>';
return $return;
break;
case 'struct':
$return = '<struct>' . "\n";
foreach ($xmlrpc_value->data as $name => $value) {
......@@ -126,13 +126,12 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
}
$return .= '</struct>';
return $return;
break;
case 'date':
return xmlrpc_date_get_xml($xmlrpc_value->data);
break;
case 'base64':
return xmlrpc_base64_get_xml($xmlrpc_value->data);
break;
}
return FALSE;
}
......@@ -150,9 +149,12 @@ function xmlrpc_value_get_xml($xmlrpc_value) {
*/
function xmlrpc_message($message) {
$xmlrpc_message = new stdClass();
$xmlrpc_message->array_structs = array(); // The stack used to keep track of the current array/struct
$xmlrpc_message->array_structs_types = array(); // The stack used to keep track of if things are structs or array
$xmlrpc_message->current_struct_name = array(); // A stack as well
// The stack used to keep track of the current array/struct
$xmlrpc_message->array_structs = array();
// The stack used to keep track of if things are structs or array
$xmlrpc_message->array_structs_types = array();
// A stack as well
$xmlrpc_message->current_struct_name = array();
$xmlrpc_message->message = $message;
return $xmlrpc_message;
}
......@@ -238,11 +240,13 @@ function xmlrpc_message_tag_open($parser, $tag, $attr) {
case 'fault':
$xmlrpc_message->messagetype = $tag;
break;
// Deal with stacks of arrays and structs
case 'data':
$xmlrpc_message->array_structs_types[] = 'array';
$xmlrpc_message->array_structs[] = array();
break;
case 'struct':
$xmlrpc_message->array_structs_types[] = 'struct';
$xmlrpc_message->array_structs[] = array();
......@@ -272,19 +276,23 @@ function xmlrpc_message_tag_close($parser, $tag) {
$value = (int)trim($xmlrpc_message->current_tag_contents);
$value_flag = TRUE;
break;
case 'double':
$value = (double)trim($xmlrpc_message->current_tag_contents);
$value_flag = TRUE;
break;
case 'string':
$value = $xmlrpc_message->current_tag_contents;
$value_flag = TRUE;
break;
case 'dateTime.iso8601':
$value = xmlrpc_date(trim($xmlrpc_message->current_tag_contents));
// $value = $iso->getTimestamp();
$value_flag = TRUE;
break;
case 'value':
// If no type is indicated, the type is string
// We take special care for empty values
......@@ -294,41 +302,47 @@ function xmlrpc_message_tag_close($parser, $tag) {
}
unset($xmlrpc_message->last_open);
break;
case 'boolean':
$value = (boolean)trim($xmlrpc_message->current_tag_contents);
$value_flag = TRUE;
break;
case 'base64':
$value = base64_decode(trim($xmlrpc_message->current_tag_contents));
$value_flag = TRUE;
break;
// Deal with stacks of arrays and structs
case 'data':
case 'struct':
$value = array_pop($xmlrpc_message->array_structs );
$value = array_pop($xmlrpc_message->array_structs);
array_pop($xmlrpc_message->array_structs_types);
$value_flag = TRUE;
break;
case 'member':
array_pop($xmlrpc_message->current_struct_name);
break;
case 'name':
$xmlrpc_message->current_struct_name[] = trim($xmlrpc_message->current_tag_contents);
break;
case 'methodName':
$xmlrpc_message->methodname = trim($xmlrpc_message->current_tag_contents);
break;
}
if ($value_flag) {
if (count($xmlrpc_message->array_structs ) > 0) {
if (count($xmlrpc_message->array_structs) > 0) {
// Add value to struct or array
if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types)-1] == 'struct') {
if ($xmlrpc_message->array_structs_types[count($xmlrpc_message->array_structs_types) - 1] == 'struct') {
// Add to struct
$xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name)-1]] = $value;
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][$xmlrpc_message->current_struct_name[count($xmlrpc_message->current_struct_name) - 1]] = $value;
}
else {
// Add to array
$xmlrpc_message->array_structs [count($xmlrpc_message->array_structs )-1][] = $value;
$xmlrpc_message->array_structs[count($xmlrpc_message->array_structs) - 1][] = $value;
}
}
else {
......@@ -611,3 +625,4 @@ function xmlrpc_error_msg() {
function xmlrpc_clear_error() {
xmlrpc_error(NULL, NULL, TRUE);
}
......@@ -16,29 +16,31 @@ function xmlrpc_server($callbacks) {
$xmlrpc_server = new stdClass();
// Define built-in XML-RPC method names
$defaults = array(
'system.multicall' => 'xmlrpc_server_multicall',
'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.'
'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.'
'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.'),
'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.')
'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.
......@@ -86,9 +88,7 @@ function xmlrpc_server($callbacks) {
<methodResponse>
<params>
<param>
<value>' .
xmlrpc_value_get_xml($r)
. '</value>
<value>' . xmlrpc_value_get_xml($r) . '</value>
</param>
</params>
</methodResponse>
......@@ -181,23 +181,27 @@ function xmlrpc_server_call($xmlrpc_server, $methodname, $args) {
$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) {
......@@ -239,7 +243,7 @@ function xmlrpc_server_multicall($methodcalls) {
if (is_object($result) && !empty($result->is_error)) {
$return[] = array(
'faultCode' => $result->code,
'faultString' => $result->message
'faultString' => $result->message,
);
}
else {
......@@ -249,7 +253,6 @@ function xmlrpc_server_multicall($methodcalls) {
return $return;
}
/**
* XML-RPC method system.listMethods maps to this function.
*/
......@@ -267,20 +270,20 @@ function xmlrpc_server_get_capabilities() {
return array(
'xmlrpc' => array(
'specUrl' => 'http://www.xmlrpc.com/spec',
'specVersion' => 1
'specVersion' => 1,
),
'faults_interop' => array(
'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php',
'specVersion' => 20010516
'specVersion' => 20010516,
),
'system.multicall' => array(
'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208',
'specVersion' => 1
'specVersion' => 1,
),
'introspection' => array(
'specUrl' => 'http://scripts.incutio.com/xmlrpc/introspection.html',
'specVersion' => 1
)
'specUrl' => 'http://scripts.incutio.com/xmlrpc/introspection.html',
'specVersion' => 1,
),
);
}
......@@ -289,6 +292,7 @@ function xmlrpc_server_get_capabilities() {
*
* @param $methodname
* Name of method for which we return a method signature.
*
* @return
* An array of types representing the method signature of the
* function that the methodname maps to. The methodSignature of
......@@ -321,3 +325,4 @@ function xmlrpc_server_method_help($method) {
$xmlrpc_server = xmlrpc_server_get();
return $xmlrpc_server->help[$method];
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment