/** * Executes multiple methods in sequence and returns the results * (implements http://www.xmlrpc.com/discuss/msgReader$1208) * * @return object a new XML_RPC_Response object */ function XML_RPC_Server_system_multiCall($server, $msg) { $dmap = $server->dmap; $array = $msg; for ($i = 0; $i < $array->getNumParams(); $i++) { $details = $array->getParam($i); if ($details->kindOf() != 'struct') { $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() expects _only_ struct datatypes wrapped in one array."); } elseif ($details->arraysize() >= 1) { // check if method name a string pointing to valid function if (!is_a($method_obj = $details->structmem('methodName'), 'XML_RPC_value') || $method_obj->kindOf() != 'scalar' || !($method = $method_obj->scalarVal()) || !strlen($function = $dmap[$method]['function'])) { $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() method call '{$method}' type '" . gettype($method) . "' resolves to an invalid function. Parameter or dmap configuration problem?"); } elseif (($params = $details->structmem('params')) && (!is_a($params, 'XML_RPC_Value') || $params->kindOf() != 'array')) { $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() method call '{$function}' parameters container " . "is not a XML_RPC_Value type '{$GLOBALS['XML_RPC_Array']}'."); } elseif (preg_match("/\\bsystem_multiCall\$/i", $function)) { $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() must not be called recursively."); } else { // build array containing xml_rpc_value of each param $params_list = array(); for ($j = 0; isset($params) && $j < $params->arraysize(); $j++) { $params_list[] = $param = $params->arraymem($j); } $msg = new XML_RPC_Message($method, $params_list); $msg->setSendEncoding($server->encoding); $resp = $server->execute($function, $msg); } } else { $resp = new XML_RPC_Response(0, $GLOBALS['XML_RPC_err']['incorrect_params'], "system_multiCall() must be called with at" . "least the functions name as parameter 1"); } // convert error to struct (multiCall Spec) if (!$resp->faultCode()) { $xml_response = array(); $xml_response[] = $resp->value(); $values[] = new XML_RPC_Value($xml_response, 'array'); //$values[] = $resp->value(); } else { $value = new XML_RPC_Value(); $value->addStruct(array('faultCode' => new XML_RPC_Value($resp->faultCode(), $GLOBALS['XML_RPC_Int']), 'faultString' => new XML_RPC_Value($resp->faultString(), $GLOBALS['XML_RPC_String']))); $values[] = $value; } } $v = new XML_RPC_Value(); $v->addArray($values); return new XML_RPC_Response($v); }