blob: 555ec749503fb3576a7ee88d5c1a75600b5634b0 [file] [log] [blame]
Derek Allard2067d1a2008-11-13 22:59:24 +00001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
7 * @package CodeIgniter
8 * @author ExpressionEngine Dev Team
Derek Jones7f3719f2010-01-05 13:35:37 +00009 * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc.
Derek Allard2067d1a2008-11-13 22:59:24 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16if ( ! function_exists('xml_parser_create'))
Barry Mienydd671972010-10-04 16:33:58 +020017{
Derek Allard2067d1a2008-11-13 22:59:24 +000018 show_error('Your PHP installation does not support XML');
19}
20
21if ( ! class_exists('CI_Xmlrpc'))
22{
23 show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.');
24}
25
26// ------------------------------------------------------------------------
27
28/**
29 * XML-RPC server class
30 *
31 * @package CodeIgniter
32 * @subpackage Libraries
33 * @category XML-RPC
34 * @author ExpressionEngine Dev Team
35 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
36 */
37class CI_Xmlrpcs extends CI_Xmlrpc
38{
Barry Mienydd671972010-10-04 16:33:58 +020039 var $methods = array(); //array of methods mapped to function names and signatures
Derek Allard2067d1a2008-11-13 22:59:24 +000040 var $debug_msg = ''; // Debug Message
Barry Mienydd671972010-10-04 16:33:58 +020041 var $system_methods = array(); // XML RPC Server methods
Derek Allard2067d1a2008-11-13 22:59:24 +000042 var $controller_obj;
Barry Mienydd671972010-10-04 16:33:58 +020043
Derek Allard2067d1a2008-11-13 22:59:24 +000044 var $object = FALSE;
Derek Jonesc4c34ee2010-03-02 23:00:28 -060045
Greg Akera9263282010-11-10 15:26:43 -060046 /**
47 * Constructor
48 */
49 public function __construct($config=array())
Barry Mienydd671972010-10-04 16:33:58 +020050 {
Greg Akera9263282010-11-10 15:26:43 -060051 parent::__construct();
Derek Allard2067d1a2008-11-13 22:59:24 +000052 $this->set_system_methods();
Barry Mienydd671972010-10-04 16:33:58 +020053
Derek Allard2067d1a2008-11-13 22:59:24 +000054 if (isset($config['functions']) && is_array($config['functions']))
55 {
56 $this->methods = array_merge($this->methods, $config['functions']);
57 }
Barry Mienydd671972010-10-04 16:33:58 +020058
Derek Allard2067d1a2008-11-13 22:59:24 +000059 log_message('debug', "XML-RPC Server Class Initialized");
60 }
Barry Mienydd671972010-10-04 16:33:58 +020061
Derek Allard2067d1a2008-11-13 22:59:24 +000062 //-------------------------------------
63 // Initialize Prefs and Serve
64 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020065
Derek Allard2067d1a2008-11-13 22:59:24 +000066 function initialize($config=array())
Barry Mienydd671972010-10-04 16:33:58 +020067 {
Derek Allard2067d1a2008-11-13 22:59:24 +000068 if (isset($config['functions']) && is_array($config['functions']))
69 {
70 $this->methods = array_merge($this->methods, $config['functions']);
71 }
Barry Mienydd671972010-10-04 16:33:58 +020072
Derek Allard2067d1a2008-11-13 22:59:24 +000073 if (isset($config['debug']))
74 {
75 $this->debug = $config['debug'];
76 }
Barry Mienydd671972010-10-04 16:33:58 +020077
Derek Allard2067d1a2008-11-13 22:59:24 +000078 if (isset($config['object']) && is_object($config['object']))
79 {
80 $this->object = $config['object'];
81 }
Barry Mienydd671972010-10-04 16:33:58 +020082
Robin Sowell66a3fc02010-03-18 09:44:55 -040083 if (isset($config['xss_clean']))
84 {
85 $this->xss_clean = $config['xss_clean'];
86 }
Derek Allard2067d1a2008-11-13 22:59:24 +000087 }
Barry Mienydd671972010-10-04 16:33:58 +020088
Derek Allard2067d1a2008-11-13 22:59:24 +000089 //-------------------------------------
90 // Setting of System Methods
91 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020092
Derek Allard2067d1a2008-11-13 22:59:24 +000093 function set_system_methods ()
94 {
95 $this->methods = array(
96 'system.listMethods' => array(
97 'function' => 'this.listMethods',
98 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
99 'docstring' => 'Returns an array of available methods on this server'),
100 'system.methodHelp' => array(
101 'function' => 'this.methodHelp',
102 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
103 'docstring' => 'Returns a documentation string for the specified method'),
104 'system.methodSignature' => array(
105 'function' => 'this.methodSignature',
106 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
107 'docstring' => 'Returns an array describing the return type and required parameters of a method'),
108 'system.multicall' => array(
109 'function' => 'this.multicall',
110 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
111 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
112 );
113 }
114
115
116 //-------------------------------------
117 // Main Server Function
118 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200119
Derek Allard2067d1a2008-11-13 22:59:24 +0000120 function serve()
121 {
122 $r = $this->parseRequest();
123 $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n";
124 $payload .= $this->debug_msg;
125 $payload .= $r->prepare_response();
Barry Mienydd671972010-10-04 16:33:58 +0200126
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 header("Content-Type: text/xml");
128 header("Content-Length: ".strlen($payload));
Derek Jonesb8d3c3d2009-06-24 15:27:01 +0000129 exit($payload);
Derek Allard2067d1a2008-11-13 22:59:24 +0000130 }
131
132 //-------------------------------------
133 // Add Method to Class
134 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 function add_to_map($methodname,$function,$sig,$doc)
137 {
138 $this->methods[$methodname] = array(
139 'function' => $function,
140 'signature' => $sig,
141 'docstring' => $doc
142 );
143 }
144
145
146 //-------------------------------------
147 // Parse Server Request
148 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200149
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 function parseRequest($data='')
151 {
152 global $HTTP_RAW_POST_DATA;
Barry Mienydd671972010-10-04 16:33:58 +0200153
Derek Allard2067d1a2008-11-13 22:59:24 +0000154 //-------------------------------------
155 // Get Data
156 //-------------------------------------
157
158 if ($data == '')
159 {
160 $data = $HTTP_RAW_POST_DATA;
161 }
162
163 //-------------------------------------
164 // Set up XML Parser
165 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200166
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 $parser = xml_parser_create($this->xmlrpc_defencoding);
168 $parser_object = new XML_RPC_Message("filler");
Barry Mienydd671972010-10-04 16:33:58 +0200169
Derek Allard2067d1a2008-11-13 22:59:24 +0000170 $parser_object->xh[$parser] = array();
171 $parser_object->xh[$parser]['isf'] = 0;
172 $parser_object->xh[$parser]['isf_reason'] = '';
173 $parser_object->xh[$parser]['params'] = array();
174 $parser_object->xh[$parser]['stack'] = array();
175 $parser_object->xh[$parser]['valuestack'] = array();
176 $parser_object->xh[$parser]['method'] = '';
177
178 xml_set_object($parser, $parser_object);
179 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
180 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
181 xml_set_character_data_handler($parser, 'character_data');
182 //xml_set_default_handler($parser, 'default_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200183
184
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 //-------------------------------------
186 // PARSE + PROCESS XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200187 //-------------------------------------
188
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 if ( ! xml_parse($parser, $data, 1))
190 {
191 // return XML error as a faultCode
192 $r = new XML_RPC_Response(0,
193 $this->xmlrpcerrxml + xml_get_error_code($parser),
194 sprintf('XML error: %s at line %d',
195 xml_error_string(xml_get_error_code($parser)),
196 xml_get_current_line_number($parser)));
197 xml_parser_free($parser);
198 }
199 elseif($parser_object->xh[$parser]['isf'])
200 {
201 return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
202 }
203 else
204 {
205 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
208 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200209
Derek Jones33559102009-02-02 18:50:38 +0000210 for($i=0; $i < count($parser_object->xh[$parser]['params']); $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 {
212 if ($this->debug === TRUE)
213 {
214 $plist .= "$i - " . print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE). ";\n";
215 }
Barry Mienydd671972010-10-04 16:33:58 +0200216
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 $m->addParam($parser_object->xh[$parser]['params'][$i]);
218 }
Barry Mienydd671972010-10-04 16:33:58 +0200219
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 if ($this->debug === TRUE)
221 {
222 echo "<pre>";
223 echo "---PLIST---\n" . $plist . "\n---PLIST END---\n\n";
224 echo "</pre>";
225 }
Barry Mienydd671972010-10-04 16:33:58 +0200226
Derek Allard2067d1a2008-11-13 22:59:24 +0000227 $r = $this->_execute($m);
228 }
Barry Mienydd671972010-10-04 16:33:58 +0200229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 //-------------------------------------
231 // SET DEBUGGING MESSAGE
Barry Mienydd671972010-10-04 16:33:58 +0200232 //-------------------------------------
233
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 if ($this->debug === TRUE)
235 {
236 $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
237 }
Barry Mienydd671972010-10-04 16:33:58 +0200238
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 return $r;
240 }
241
242 //-------------------------------------
243 // Executes the Method
244 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200245
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 function _execute($m)
247 {
248 $methName = $m->method_name;
Barry Mienydd671972010-10-04 16:33:58 +0200249
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 // Check to see if it is a system call
251 $system_call = (strncmp($methName, 'system', 5) == 0) ? TRUE : FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200252
Robin Sowell66a3fc02010-03-18 09:44:55 -0400253 if ($this->xss_clean == FALSE)
254 {
255 $m->xss_clean = FALSE;
256 }
257
Derek Allard2067d1a2008-11-13 22:59:24 +0000258 //-------------------------------------
259 // Valid Method
260 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 if ( ! isset($this->methods[$methName]['function']))
263 {
264 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
265 }
Barry Mienydd671972010-10-04 16:33:58 +0200266
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 //-------------------------------------
268 // Check for Method (and Object)
269 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200270
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 $method_parts = explode(".", $this->methods[$methName]['function']);
272 $objectCall = (isset($method_parts['1']) && $method_parts['1'] != "") ? TRUE : FALSE;
Barry Mienydd671972010-10-04 16:33:58 +0200273
Derek Allard2067d1a2008-11-13 22:59:24 +0000274 if ($system_call === TRUE)
275 {
276 if ( ! is_callable(array($this,$method_parts['1'])))
277 {
278 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
279 }
280 }
281 else
282 {
283 if ($objectCall && ! is_callable(array($method_parts['0'],$method_parts['1'])))
284 {
285 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
286 }
287 elseif ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
288 {
289 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
290 }
291 }
Barry Mienydd671972010-10-04 16:33:58 +0200292
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 //-------------------------------------
294 // Checking Methods Signature
295 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200296
Derek Allard2067d1a2008-11-13 22:59:24 +0000297 if (isset($this->methods[$methName]['signature']))
298 {
299 $sig = $this->methods[$methName]['signature'];
Derek Jones33559102009-02-02 18:50:38 +0000300 for($i=0; $i<count($sig); $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 {
302 $current_sig = $sig[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200303
Derek Jones33559102009-02-02 18:50:38 +0000304 if (count($current_sig) == count($m->params)+1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 {
Derek Jones33559102009-02-02 18:50:38 +0000306 for($n=0; $n < count($m->params); $n++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 {
308 $p = $m->params[$n];
309 $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf();
Barry Mienydd671972010-10-04 16:33:58 +0200310
Derek Allard2067d1a2008-11-13 22:59:24 +0000311 if ($pt != $current_sig[$n+1])
312 {
313 $pno = $n+1;
314 $wanted = $current_sig[$n+1];
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 return new XML_RPC_Response(0,
317 $this->xmlrpcerr['incorrect_params'],
318 $this->xmlrpcstr['incorrect_params'] .
319 ": Wanted {$wanted}, got {$pt} at param {$pno})");
320 }
321 }
322 }
323 }
324 }
325
326 //-------------------------------------
327 // Calls the Function
328 //-------------------------------------
329
330 if ($objectCall === TRUE)
331 {
332 if ($method_parts[0] == "this" && $system_call == TRUE)
333 {
334 return call_user_func(array($this, $method_parts[1]), $m);
335 }
336 else
337 {
338 if ($this->object === FALSE)
339 {
340 $CI =& get_instance();
341 return $CI->$method_parts['1']($m);
342 }
343 else
344 {
345 return $this->object->$method_parts['1']($m);
346 //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
347 }
348 }
349 }
350 else
351 {
352 return call_user_func($this->methods[$methName]['function'], $m);
353 }
354 }
Barry Mienydd671972010-10-04 16:33:58 +0200355
356
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 //-------------------------------------
358 // Server Function: List Methods
359 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200360
Derek Allard2067d1a2008-11-13 22:59:24 +0000361 function listMethods($m)
362 {
363 $v = new XML_RPC_Values();
364 $output = array();
Barry Mienydd671972010-10-04 16:33:58 +0200365
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 foreach($this->methods as $key => $value)
367 {
368 $output[] = new XML_RPC_Values($key, 'string');
369 }
Barry Mienydd671972010-10-04 16:33:58 +0200370
Derek Allard2067d1a2008-11-13 22:59:24 +0000371 foreach($this->system_methods as $key => $value)
372 {
373 $output[]= new XML_RPC_Values($key, 'string');
374 }
375
376 $v->addArray($output);
377 return new XML_RPC_Response($v);
378 }
Barry Mienydd671972010-10-04 16:33:58 +0200379
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 //-------------------------------------
381 // Server Function: Return Signature for Method
382 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200383
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 function methodSignature($m)
385 {
386 $parameters = $m->output_parameters();
387 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200388
Derek Allard2067d1a2008-11-13 22:59:24 +0000389 if (isset($this->methods[$method_name]))
390 {
391 if ($this->methods[$method_name]['signature'])
392 {
393 $sigs = array();
394 $signature = $this->methods[$method_name]['signature'];
Barry Mienydd671972010-10-04 16:33:58 +0200395
Derek Jones33559102009-02-02 18:50:38 +0000396 for($i=0; $i < count($signature); $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000397 {
398 $cursig = array();
399 $inSig = $signature[$i];
Derek Jones33559102009-02-02 18:50:38 +0000400 for($j=0; $j<count($inSig); $j++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000401 {
402 $cursig[]= new XML_RPC_Values($inSig[$j], 'string');
403 }
404 $sigs[]= new XML_RPC_Values($cursig, 'array');
405 }
406 $r = new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
407 }
408 else
409 {
410 $r = new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
411 }
412 }
413 else
414 {
415 $r = new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
416 }
417 return $r;
418 }
Barry Mienydd671972010-10-04 16:33:58 +0200419
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 //-------------------------------------
421 // Server Function: Doc String for Method
422 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 function methodHelp($m)
425 {
426 $parameters = $m->output_parameters();
427 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200428
Derek Allard2067d1a2008-11-13 22:59:24 +0000429 if (isset($this->methods[$method_name]))
430 {
431 $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
Barry Mienydd671972010-10-04 16:33:58 +0200432
Derek Allard2067d1a2008-11-13 22:59:24 +0000433 return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
434 }
435 else
436 {
437 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
438 }
439 }
440
441 //-------------------------------------
442 // Server Function: Multi-call
443 //-------------------------------------
444
445 function multicall($m)
446 {
447 // Disabled
448 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Barry Mienydd671972010-10-04 16:33:58 +0200449
Derek Allard2067d1a2008-11-13 22:59:24 +0000450 $parameters = $m->output_parameters();
451 $calls = $parameters[0];
452
453 $result = array();
454
455 foreach ($calls as $value)
456 {
457 //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1]));
Barry Mienydd671972010-10-04 16:33:58 +0200458
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 $m = new XML_RPC_Message($value[0]);
460 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200461
Derek Jones33559102009-02-02 18:50:38 +0000462 for($i=0; $i < count($value[1]); $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 {
464 $m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
465 }
Barry Mienydd671972010-10-04 16:33:58 +0200466
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 $attempt = $this->_execute($m);
468
469 if ($attempt->faultCode() != 0)
470 {
471 return $attempt;
472 }
473
474 $result[] = new XML_RPC_Values(array($attempt->value()), 'array');
475 }
476
477 return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
478 }
Barry Mienydd671972010-10-04 16:33:58 +0200479
480
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 //-------------------------------------
482 // Multi-call Function: Error Handling
483 //-------------------------------------
484
485 function multicall_error($err)
486 {
487 $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
488 $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
Barry Mienydd671972010-10-04 16:33:58 +0200489
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 $struct['faultCode'] = new XML_RPC_Values($code, 'int');
491 $struct['faultString'] = new XML_RPC_Values($str, 'string');
Barry Mienydd671972010-10-04 16:33:58 +0200492
Derek Allard2067d1a2008-11-13 22:59:24 +0000493 return new XML_RPC_Values($struct, 'struct');
494 }
Barry Mienydd671972010-10-04 16:33:58 +0200495
496
Derek Allard2067d1a2008-11-13 22:59:24 +0000497 //-------------------------------------
498 // Multi-call Function: Processes method
499 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200500
Derek Allard2067d1a2008-11-13 22:59:24 +0000501 function do_multicall($call)
502 {
503 if ($call->kindOf() != 'struct')
504 return $this->multicall_error('notstruct');
505 elseif ( ! $methName = $call->me['struct']['methodName'])
506 return $this->multicall_error('nomethod');
Barry Mienydd671972010-10-04 16:33:58 +0200507
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 list($scalar_type,$scalar_value)=each($methName->me);
509 $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
Barry Mienydd671972010-10-04 16:33:58 +0200510
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string')
512 return $this->multicall_error('notstring');
513 elseif ($scalar_value == 'system.multicall')
514 return $this->multicall_error('recursion');
515 elseif ( ! $params = $call->me['struct']['params'])
516 return $this->multicall_error('noparams');
517 elseif ($params->kindOf() != 'array')
518 return $this->multicall_error('notarray');
Barry Mienydd671972010-10-04 16:33:58 +0200519
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 list($a,$b)=each($params->me);
Derek Jones33559102009-02-02 18:50:38 +0000521 $numParams = count($b);
Derek Allard2067d1a2008-11-13 22:59:24 +0000522
523 $msg = new XML_RPC_Message($scalar_value);
524 for ($i = 0; $i < $numParams; $i++)
525 {
526 $msg->params[] = $params->me['array'][$i];
527 }
528
529 $result = $this->_execute($msg);
530
531 if ($result->faultCode() != 0)
532 {
533 return $this->multicall_error($result);
534 }
535
536 return new XML_RPC_Values(array($result->value()), 'array');
Barry Mienydd671972010-10-04 16:33:58 +0200537 }
538
Derek Allard2067d1a2008-11-13 22:59:24 +0000539}
540// END XML_RPC_Server class
541
542
543/* End of file Xmlrpcs.php */
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000544/* Location: ./system/libraries/Xmlrpcs.php */