blob: f0c5b48e71cb63efc6dcdd068c5334d92511738e [file] [log] [blame]
Andrey Andreev56e32142011-12-25 18:36:31 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreev56e32142011-12-25 18:36:31 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreev56e32142011-12-25 18:36:31 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * This source file is subject to the Open Software License (OSL 3.0) that is
12 * bundled with this package in the files license.txt / license.rst. It is
13 * also available through the world wide web at this URL:
14 * http://opensource.org/licenses/OSL-3.0
15 * If you did not receive a copy of the license and are unable to obtain it
16 * through the world wide web, please send an email to
17 * licensing@ellislab.com so we can send you a copy immediately.
18 *
Derek Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28if ( ! function_exists('xml_parser_create'))
Barry Mienydd671972010-10-04 16:33:58 +020029{
Derek Allard2067d1a2008-11-13 22:59:24 +000030 show_error('Your PHP installation does not support XML');
31}
32
33if ( ! class_exists('CI_Xmlrpc'))
34{
35 show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.');
36}
37
38// ------------------------------------------------------------------------
39
40/**
41 * XML-RPC server class
42 *
43 * @package CodeIgniter
44 * @subpackage Libraries
45 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -050046 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000047 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
48 */
49class CI_Xmlrpcs extends CI_Xmlrpc
50{
Timothy Warren0688ac92012-04-20 10:25:04 -040051 /**
52 * array of methods mapped to function names and signatures
53 *
54 * @var array
55 */
56 public $methods = array();
57
58 /**
59 * Debug Message
60 *
61 * @var string
62 */
63 public $debug_msg = '';
64
65 /**
66 * XML RPC Server methods
67 *
68 * @var array
69 */
70 public $system_methods = array();
71
72 /**
73 * Configuration object
74 *
75 * @var object
76 */
77 public $object = FALSE;
Derek Jonesc4c34ee2010-03-02 23:00:28 -060078
Timothy Warren0688ac92012-04-20 10:25:04 -040079 /**
80 * Initialize XMLRPC class
81 *
82 * @param array $config
83 */
Andrey Andreev52278372012-03-26 16:02:30 +030084 public function __construct($config = array())
Barry Mienydd671972010-10-04 16:33:58 +020085 {
Greg Akera9263282010-11-10 15:26:43 -060086 parent::__construct();
Derek Allard2067d1a2008-11-13 22:59:24 +000087 $this->set_system_methods();
Barry Mienydd671972010-10-04 16:33:58 +020088
Derek Allard2067d1a2008-11-13 22:59:24 +000089 if (isset($config['functions']) && is_array($config['functions']))
90 {
91 $this->methods = array_merge($this->methods, $config['functions']);
92 }
Barry Mienydd671972010-10-04 16:33:58 +020093
Andrey Andreev52278372012-03-26 16:02:30 +030094 log_message('debug', 'XML-RPC Server Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000095 }
Barry Mienydd671972010-10-04 16:33:58 +020096
Pascal Kriete68d29872011-02-14 13:39:06 -050097 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020098
Pascal Kriete68d29872011-02-14 13:39:06 -050099 /**
100 * Initialize Prefs and Serve
101 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500102 * @param mixed
103 * @return void
104 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200105 public function initialize($config = array())
Barry Mienydd671972010-10-04 16:33:58 +0200106 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 if (isset($config['functions']) && is_array($config['functions']))
108 {
109 $this->methods = array_merge($this->methods, $config['functions']);
110 }
Barry Mienydd671972010-10-04 16:33:58 +0200111
Derek Allard2067d1a2008-11-13 22:59:24 +0000112 if (isset($config['debug']))
113 {
114 $this->debug = $config['debug'];
115 }
Barry Mienydd671972010-10-04 16:33:58 +0200116
Derek Allard2067d1a2008-11-13 22:59:24 +0000117 if (isset($config['object']) && is_object($config['object']))
118 {
119 $this->object = $config['object'];
120 }
Barry Mienydd671972010-10-04 16:33:58 +0200121
Robin Sowell66a3fc02010-03-18 09:44:55 -0400122 if (isset($config['xss_clean']))
123 {
124 $this->xss_clean = $config['xss_clean'];
125 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 }
Barry Mienydd671972010-10-04 16:33:58 +0200127
Pascal Kriete68d29872011-02-14 13:39:06 -0500128 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200129
Pascal Kriete68d29872011-02-14 13:39:06 -0500130 /**
131 * Setting of System Methods
132 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500133 * @return void
134 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200135 public function set_system_methods()
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 {
137 $this->methods = array(
138 'system.listMethods' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200139 'function' => 'this.listMethods',
140 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
141 'docstring' => 'Returns an array of available methods on this server'),
142 'system.methodHelp' => array(
143 'function' => 'this.methodHelp',
144 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
145 'docstring' => 'Returns a documentation string for the specified method'),
Derek Allard2067d1a2008-11-13 22:59:24 +0000146 'system.methodSignature' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200147 'function' => 'this.methodSignature',
148 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
149 'docstring' => 'Returns an array describing the return type and required parameters of a method'),
150 'system.multicall' => array(
151 'function' => 'this.multicall',
152 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
153 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
154 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000155 }
156
Pascal Kriete68d29872011-02-14 13:39:06 -0500157 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000158
Pascal Kriete68d29872011-02-14 13:39:06 -0500159 /**
160 * Main Server Function
161 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500162 * @return void
163 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200164 public function serve()
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 {
166 $r = $this->parseRequest();
Andrey Andreev56e32142011-12-25 18:36:31 +0200167 $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response();
Barry Mienydd671972010-10-04 16:33:58 +0200168
Andrey Andreev52278372012-03-26 16:02:30 +0300169 header('Content-Type: text/xml');
170 header('Content-Length: '.strlen($payload));
Derek Jonesb8d3c3d2009-06-24 15:27:01 +0000171 exit($payload);
Derek Allard2067d1a2008-11-13 22:59:24 +0000172 }
173
Pascal Kriete68d29872011-02-14 13:39:06 -0500174 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200175
Pascal Kriete68d29872011-02-14 13:39:06 -0500176 /**
177 * Add Method to Class
178 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500179 * @param string method name
180 * @param string function
181 * @param string signature
182 * @param string docstring
183 * @return void
184 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200185 public function add_to_map($methodname, $function, $sig, $doc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 {
187 $this->methods[$methodname] = array(
Derek Jones37f4b9c2011-07-01 17:56:50 -0500188 'function' => $function,
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 'signature' => $sig,
190 'docstring' => $doc
191 );
192 }
193
Pascal Kriete68d29872011-02-14 13:39:06 -0500194 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000195
Pascal Kriete68d29872011-02-14 13:39:06 -0500196 /**
197 * Parse Server Request
198 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500199 * @param string data
200 * @return object xmlrpc response
201 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200202 public function parseRequest($data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 {
204 global $HTTP_RAW_POST_DATA;
Barry Mienydd671972010-10-04 16:33:58 +0200205
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500207 // Get Data
Derek Allard2067d1a2008-11-13 22:59:24 +0000208 //-------------------------------------
209
210 if ($data == '')
211 {
212 $data = $HTTP_RAW_POST_DATA;
213 }
214
215 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500216 // Set up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219 $parser = xml_parser_create($this->xmlrpc_defencoding);
Andrey Andreev52278372012-03-26 16:02:30 +0300220 $parser_object = new XML_RPC_Message('filler');
Barry Mienydd671972010-10-04 16:33:58 +0200221
Andrey Andreev56e32142011-12-25 18:36:31 +0200222 $parser_object->xh[$parser] = array(
223 'isf' => 0,
224 'isf_reason' => '',
225 'params' => array(),
226 'stack' => array(),
227 'valuestack' => array(),
228 'method' => ''
229 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000230
231 xml_set_object($parser, $parser_object);
232 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
233 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
234 xml_set_character_data_handler($parser, 'character_data');
235 //xml_set_default_handler($parser, 'default_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200236
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500238 // PARSE + PROCESS XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200239 //-------------------------------------
240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 if ( ! xml_parse($parser, $data, 1))
242 {
243 // return XML error as a faultCode
244 $r = new XML_RPC_Response(0,
245 $this->xmlrpcerrxml + xml_get_error_code($parser),
246 sprintf('XML error: %s at line %d',
247 xml_error_string(xml_get_error_code($parser)),
248 xml_get_current_line_number($parser)));
249 xml_parser_free($parser);
250 }
Pascal Kriete68d29872011-02-14 13:39:06 -0500251 elseif ($parser_object->xh[$parser]['isf'])
Derek Allard2067d1a2008-11-13 22:59:24 +0000252 {
253 return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
254 }
255 else
256 {
257 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200258
Derek Allard2067d1a2008-11-13 22:59:24 +0000259 $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
260 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200261
Andrey Andreev56e32142011-12-25 18:36:31 +0200262 for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 {
264 if ($this->debug === TRUE)
265 {
Andrey Andreev52278372012-03-26 16:02:30 +0300266 $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE).";\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 }
Barry Mienydd671972010-10-04 16:33:58 +0200268
Derek Allard2067d1a2008-11-13 22:59:24 +0000269 $m->addParam($parser_object->xh[$parser]['params'][$i]);
270 }
Barry Mienydd671972010-10-04 16:33:58 +0200271
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 if ($this->debug === TRUE)
273 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200274 echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 }
Barry Mienydd671972010-10-04 16:33:58 +0200276
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 $r = $this->_execute($m);
278 }
Barry Mienydd671972010-10-04 16:33:58 +0200279
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500281 // SET DEBUGGING MESSAGE
Barry Mienydd671972010-10-04 16:33:58 +0200282 //-------------------------------------
283
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 if ($this->debug === TRUE)
285 {
286 $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 return $r;
290 }
291
Pascal Kriete68d29872011-02-14 13:39:06 -0500292 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200293
Pascal Kriete68d29872011-02-14 13:39:06 -0500294 /**
295 * Executes the Method
296 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500297 * @param object
298 * @return mixed
299 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200300 protected function _execute($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000301 {
302 $methName = $m->method_name;
Barry Mienydd671972010-10-04 16:33:58 +0200303
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 // Check to see if it is a system call
Andrey Andreev56e32142011-12-25 18:36:31 +0200305 $system_call = (strncmp($methName, 'system', 5) === 0);
Barry Mienydd671972010-10-04 16:33:58 +0200306
Robin Sowell66a3fc02010-03-18 09:44:55 -0400307 if ($this->xss_clean == FALSE)
308 {
309 $m->xss_clean = FALSE;
310 }
311
Derek Allard2067d1a2008-11-13 22:59:24 +0000312 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500313 // Valid Method
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 if ( ! isset($this->methods[$methName]['function']))
317 {
318 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
319 }
Barry Mienydd671972010-10-04 16:33:58 +0200320
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500322 // Check for Method (and Object)
Derek Allard2067d1a2008-11-13 22:59:24 +0000323 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200324
Andrey Andreev52278372012-03-26 16:02:30 +0300325 $method_parts = explode('.', $this->methods[$methName]['function']);
Andrey Andreev56e32142011-12-25 18:36:31 +0200326 $objectCall = (isset($method_parts[1]) && $method_parts[1] != '');
Barry Mienydd671972010-10-04 16:33:58 +0200327
Derek Allard2067d1a2008-11-13 22:59:24 +0000328 if ($system_call === TRUE)
329 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200330 if ( ! is_callable(array($this,$method_parts[1])))
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 {
332 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
333 }
334 }
Andrey Andreev52278372012-03-26 16:02:30 +0300335 elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1])))
336 OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
337 )
Derek Allard2067d1a2008-11-13 22:59:24 +0000338 {
Andrey Andreev52278372012-03-26 16:02:30 +0300339 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000340 }
Barry Mienydd671972010-10-04 16:33:58 +0200341
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500343 // Checking Methods Signature
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200345
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 if (isset($this->methods[$methName]['signature']))
347 {
348 $sig = $this->methods[$methName]['signature'];
Andrey Andreev56e32142011-12-25 18:36:31 +0200349 for ($i = 0, $c = count($sig); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 {
351 $current_sig = $sig[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200352
Andrey Andreev56e32142011-12-25 18:36:31 +0200353 if (count($current_sig) === count($m->params)+1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200355 for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000356 {
357 $p = $m->params[$n];
358 $pt = ($p->kindOf() == 'scalar') ? $p->scalarval() : $p->kindOf();
Barry Mienydd671972010-10-04 16:33:58 +0200359
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 if ($pt != $current_sig[$n+1])
361 {
362 $pno = $n+1;
363 $wanted = $current_sig[$n+1];
Barry Mienydd671972010-10-04 16:33:58 +0200364
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 return new XML_RPC_Response(0,
366 $this->xmlrpcerr['incorrect_params'],
367 $this->xmlrpcstr['incorrect_params'] .
Andrey Andreev52278372012-03-26 16:02:30 +0300368 ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')');
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 }
370 }
371 }
372 }
373 }
374
375 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500376 // Calls the Function
Derek Allard2067d1a2008-11-13 22:59:24 +0000377 //-------------------------------------
378
379 if ($objectCall === TRUE)
380 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200381 if ($method_parts[0] === 'this' && $system_call === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000382 {
383 return call_user_func(array($this, $method_parts[1]), $m);
384 }
385 else
386 {
387 if ($this->object === FALSE)
388 {
389 $CI =& get_instance();
Andrey Andreev56e32142011-12-25 18:36:31 +0200390 return $CI->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 }
392 else
393 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200394 return $this->object->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000395 //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
396 }
397 }
398 }
399 else
400 {
401 return call_user_func($this->methods[$methName]['function'], $m);
402 }
403 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200404
Pascal Kriete68d29872011-02-14 13:39:06 -0500405 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200406
Pascal Kriete68d29872011-02-14 13:39:06 -0500407 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500408 * Server Function: List Methods
Pascal Kriete68d29872011-02-14 13:39:06 -0500409 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500410 * @param mixed
411 * @return object
412 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200413 public function listMethods($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000414 {
415 $v = new XML_RPC_Values();
416 $output = array();
Barry Mienydd671972010-10-04 16:33:58 +0200417
Pascal Kriete68d29872011-02-14 13:39:06 -0500418 foreach ($this->methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 {
420 $output[] = new XML_RPC_Values($key, 'string');
421 }
Barry Mienydd671972010-10-04 16:33:58 +0200422
Pascal Kriete68d29872011-02-14 13:39:06 -0500423 foreach ($this->system_methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 {
Andrey Andreev52278372012-03-26 16:02:30 +0300425 $output[] = new XML_RPC_Values($key, 'string');
Derek Allard2067d1a2008-11-13 22:59:24 +0000426 }
427
428 $v->addArray($output);
429 return new XML_RPC_Response($v);
430 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200431
Pascal Kriete68d29872011-02-14 13:39:06 -0500432 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200433
Pascal Kriete68d29872011-02-14 13:39:06 -0500434 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500435 * Server Function: Return Signature for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500436 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500437 * @param mixed
438 * @return object
439 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200440 public function methodSignature($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000441 {
442 $parameters = $m->output_parameters();
443 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200444
Derek Allard2067d1a2008-11-13 22:59:24 +0000445 if (isset($this->methods[$method_name]))
446 {
447 if ($this->methods[$method_name]['signature'])
448 {
449 $sigs = array();
450 $signature = $this->methods[$method_name]['signature'];
Barry Mienydd671972010-10-04 16:33:58 +0200451
Andrey Andreev56e32142011-12-25 18:36:31 +0200452 for ($i = 0, $c = count($signature); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 {
454 $cursig = array();
455 $inSig = $signature[$i];
Andrey Andreev56e32142011-12-25 18:36:31 +0200456 for ($j = 0, $jc = count($inSig); $j < $jc; $j++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000457 {
458 $cursig[]= new XML_RPC_Values($inSig[$j], 'string');
459 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200460 $sigs[] = new XML_RPC_Values($cursig, 'array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000461 }
Andrey Andreev52278372012-03-26 16:02:30 +0300462
463 return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000464 }
Andrey Andreev52278372012-03-26 16:02:30 +0300465
466 return new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 }
Andrey Andreev52278372012-03-26 16:02:30 +0300468
469 return new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 }
Barry Mienydd671972010-10-04 16:33:58 +0200471
Pascal Kriete68d29872011-02-14 13:39:06 -0500472 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200473
Pascal Kriete68d29872011-02-14 13:39:06 -0500474 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500475 * Server Function: Doc String for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500476 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500477 * @param mixed
478 * @return object
479 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200480 public function methodHelp($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 {
482 $parameters = $m->output_parameters();
483 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200484
Derek Allard2067d1a2008-11-13 22:59:24 +0000485 if (isset($this->methods[$method_name]))
486 {
487 $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
Barry Mienydd671972010-10-04 16:33:58 +0200488
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
490 }
491 else
492 {
493 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
494 }
495 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200496
Pascal Kriete68d29872011-02-14 13:39:06 -0500497 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000498
Pascal Kriete68d29872011-02-14 13:39:06 -0500499 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500500 * Server Function: Multi-call
Pascal Kriete68d29872011-02-14 13:39:06 -0500501 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500502 * @param mixed
503 * @return object
504 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200505 public function multicall($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 {
507 // Disabled
508 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Barry Mienydd671972010-10-04 16:33:58 +0200509
Derek Allard2067d1a2008-11-13 22:59:24 +0000510 $parameters = $m->output_parameters();
511 $calls = $parameters[0];
512
513 $result = array();
514
515 foreach ($calls as $value)
516 {
517 //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1]));
Barry Mienydd671972010-10-04 16:33:58 +0200518
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 $m = new XML_RPC_Message($value[0]);
520 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200521
Andrey Andreev56e32142011-12-25 18:36:31 +0200522 for ($i = 0, $c = count($value[1]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000523 {
524 $m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
525 }
Barry Mienydd671972010-10-04 16:33:58 +0200526
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 $attempt = $this->_execute($m);
528
529 if ($attempt->faultCode() != 0)
530 {
531 return $attempt;
532 }
533
534 $result[] = new XML_RPC_Values(array($attempt->value()), 'array');
535 }
536
537 return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
538 }
Barry Mienydd671972010-10-04 16:33:58 +0200539
Pascal Kriete68d29872011-02-14 13:39:06 -0500540 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200541
Pascal Kriete68d29872011-02-14 13:39:06 -0500542 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500543 * Multi-call Function: Error Handling
Pascal Kriete68d29872011-02-14 13:39:06 -0500544 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500545 * @param mixed
546 * @return object
547 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200548 public function multicall_error($err)
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500550 $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
Derek Allard2067d1a2008-11-13 22:59:24 +0000551 $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
Barry Mienydd671972010-10-04 16:33:58 +0200552
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 $struct['faultCode'] = new XML_RPC_Values($code, 'int');
554 $struct['faultString'] = new XML_RPC_Values($str, 'string');
Barry Mienydd671972010-10-04 16:33:58 +0200555
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 return new XML_RPC_Values($struct, 'struct');
557 }
Barry Mienydd671972010-10-04 16:33:58 +0200558
Pascal Kriete68d29872011-02-14 13:39:06 -0500559 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200560
Pascal Kriete68d29872011-02-14 13:39:06 -0500561 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500562 * Multi-call Function: Processes method
Pascal Kriete68d29872011-02-14 13:39:06 -0500563 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500564 * @param mixed
565 * @return object
566 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200567 public function do_multicall($call)
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 {
569 if ($call->kindOf() != 'struct')
Pascal Kriete68d29872011-02-14 13:39:06 -0500570 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000571 return $this->multicall_error('notstruct');
Pascal Kriete68d29872011-02-14 13:39:06 -0500572 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 elseif ( ! $methName = $call->me['struct']['methodName'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500574 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 return $this->multicall_error('nomethod');
Pascal Kriete68d29872011-02-14 13:39:06 -0500576 }
Barry Mienydd671972010-10-04 16:33:58 +0200577
Derek Allard2067d1a2008-11-13 22:59:24 +0000578 list($scalar_type,$scalar_value)=each($methName->me);
579 $scalar_type = $scalar_type == $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
Barry Mienydd671972010-10-04 16:33:58 +0200580
Derek Allard2067d1a2008-11-13 22:59:24 +0000581 if ($methName->kindOf() != 'scalar' OR $scalar_type != 'string')
Pascal Kriete68d29872011-02-14 13:39:06 -0500582 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000583 return $this->multicall_error('notstring');
Pascal Kriete68d29872011-02-14 13:39:06 -0500584 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 elseif ($scalar_value == 'system.multicall')
Pascal Kriete68d29872011-02-14 13:39:06 -0500586 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 return $this->multicall_error('recursion');
Pascal Kriete68d29872011-02-14 13:39:06 -0500588 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000589 elseif ( ! $params = $call->me['struct']['params'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500590 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 return $this->multicall_error('noparams');
Pascal Kriete68d29872011-02-14 13:39:06 -0500592 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000593 elseif ($params->kindOf() != 'array')
Pascal Kriete68d29872011-02-14 13:39:06 -0500594 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000595 return $this->multicall_error('notarray');
Pascal Kriete68d29872011-02-14 13:39:06 -0500596 }
Barry Mienydd671972010-10-04 16:33:58 +0200597
Andrey Andreev56e32142011-12-25 18:36:31 +0200598 list($a,$b) = each($params->me);
Derek Allard2067d1a2008-11-13 22:59:24 +0000599
600 $msg = new XML_RPC_Message($scalar_value);
Andrey Andreev56e32142011-12-25 18:36:31 +0200601 for ($i = 0, $numParams = count($b); $i < $numParams; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 {
603 $msg->params[] = $params->me['array'][$i];
604 }
605
606 $result = $this->_execute($msg);
607
608 if ($result->faultCode() != 0)
609 {
610 return $this->multicall_error($result);
611 }
612
613 return new XML_RPC_Values(array($result->value()), 'array');
Barry Mienydd671972010-10-04 16:33:58 +0200614 }
615
Derek Allard2067d1a2008-11-13 22:59:24 +0000616}
Derek Allard2067d1a2008-11-13 22:59:24 +0000617
Derek Allard2067d1a2008-11-13 22:59:24 +0000618/* End of file Xmlrpcs.php */
Andrey Andreev52278372012-03-26 16:02:30 +0300619/* Location: ./system/libraries/Xmlrpcs.php */