blob: bed18ebaefc87d4c63323d0d850aaad24b40eade [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
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
darwinel871754a2014-02-11 17:34:57 +010021 * @copyright Copyright (c) 2008 - 2014, 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 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020027defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000028
29if ( ! function_exists('xml_parser_create'))
Barry Mienydd671972010-10-04 16:33:58 +020030{
Derek Allard2067d1a2008-11-13 22:59:24 +000031 show_error('Your PHP installation does not support XML');
32}
33
Andrey Andreev49e68de2013-02-21 16:30:55 +020034if ( ! class_exists('CI_Xmlrpc', FALSE))
Derek Allard2067d1a2008-11-13 22:59:24 +000035{
36 show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.');
37}
38
39// ------------------------------------------------------------------------
40
41/**
42 * XML-RPC server class
43 *
44 * @package CodeIgniter
45 * @subpackage Libraries
46 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -050047 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000048 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
49 */
vkeranov52de3792012-11-23 23:48:35 +020050class CI_Xmlrpcs extends CI_Xmlrpc {
51
Timothy Warren0688ac92012-04-20 10:25:04 -040052 /**
vkeranov52de3792012-11-23 23:48:35 +020053 * Array of methods mapped to function names and signatures
Timothy Warren0688ac92012-04-20 10:25:04 -040054 *
55 * @var array
56 */
57 public $methods = array();
Andrey Andreev56454792012-05-17 14:32:19 +030058
Timothy Warren0688ac92012-04-20 10:25:04 -040059 /**
60 * Debug Message
61 *
62 * @var string
63 */
64 public $debug_msg = '';
Andrey Andreev56454792012-05-17 14:32:19 +030065
Timothy Warren0688ac92012-04-20 10:25:04 -040066 /**
67 * XML RPC Server methods
68 *
69 * @var array
70 */
71 public $system_methods = array();
Andrey Andreev56454792012-05-17 14:32:19 +030072
Timothy Warren0688ac92012-04-20 10:25:04 -040073 /**
74 * Configuration object
75 *
76 * @var object
77 */
78 public $object = FALSE;
Derek Jonesc4c34ee2010-03-02 23:00:28 -060079
Timothy Warren0688ac92012-04-20 10:25:04 -040080 /**
81 * Initialize XMLRPC class
82 *
Andrey Andreev56454792012-05-17 14:32:19 +030083 * @param array $config
84 * @return void
Timothy Warren0688ac92012-04-20 10:25:04 -040085 */
Andrey Andreev52278372012-03-26 16:02:30 +030086 public function __construct($config = array())
Barry Mienydd671972010-10-04 16:33:58 +020087 {
Greg Akera9263282010-11-10 15:26:43 -060088 parent::__construct();
Derek Allard2067d1a2008-11-13 22:59:24 +000089 $this->set_system_methods();
Barry Mienydd671972010-10-04 16:33:58 +020090
Derek Allard2067d1a2008-11-13 22:59:24 +000091 if (isset($config['functions']) && is_array($config['functions']))
92 {
93 $this->methods = array_merge($this->methods, $config['functions']);
94 }
Barry Mienydd671972010-10-04 16:33:58 +020095
Andrey Andreev52278372012-03-26 16:02:30 +030096 log_message('debug', 'XML-RPC Server Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000097 }
Barry Mienydd671972010-10-04 16:33:58 +020098
Pascal Kriete68d29872011-02-14 13:39:06 -050099 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200100
Pascal Kriete68d29872011-02-14 13:39:06 -0500101 /**
102 * Initialize Prefs and Serve
103 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500104 * @param mixed
105 * @return void
106 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200107 public function initialize($config = array())
Barry Mienydd671972010-10-04 16:33:58 +0200108 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000109 if (isset($config['functions']) && is_array($config['functions']))
110 {
111 $this->methods = array_merge($this->methods, $config['functions']);
112 }
Barry Mienydd671972010-10-04 16:33:58 +0200113
Derek Allard2067d1a2008-11-13 22:59:24 +0000114 if (isset($config['debug']))
115 {
116 $this->debug = $config['debug'];
117 }
Barry Mienydd671972010-10-04 16:33:58 +0200118
Derek Allard2067d1a2008-11-13 22:59:24 +0000119 if (isset($config['object']) && is_object($config['object']))
120 {
121 $this->object = $config['object'];
122 }
Barry Mienydd671972010-10-04 16:33:58 +0200123
Robin Sowell66a3fc02010-03-18 09:44:55 -0400124 if (isset($config['xss_clean']))
125 {
126 $this->xss_clean = $config['xss_clean'];
127 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 }
Barry Mienydd671972010-10-04 16:33:58 +0200129
Pascal Kriete68d29872011-02-14 13:39:06 -0500130 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200131
Pascal Kriete68d29872011-02-14 13:39:06 -0500132 /**
133 * Setting of System Methods
134 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500135 * @return void
136 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200137 public function set_system_methods()
Derek Allard2067d1a2008-11-13 22:59:24 +0000138 {
139 $this->methods = array(
140 'system.listMethods' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200141 'function' => 'this.listMethods',
142 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
143 'docstring' => 'Returns an array of available methods on this server'),
144 'system.methodHelp' => array(
145 'function' => 'this.methodHelp',
146 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
147 'docstring' => 'Returns a documentation string for the specified method'),
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 'system.methodSignature' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200149 'function' => 'this.methodSignature',
150 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
151 'docstring' => 'Returns an array describing the return type and required parameters of a method'),
152 'system.multicall' => array(
153 'function' => 'this.multicall',
154 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
155 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
156 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000157 }
158
Pascal Kriete68d29872011-02-14 13:39:06 -0500159 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000160
Pascal Kriete68d29872011-02-14 13:39:06 -0500161 /**
162 * Main Server Function
163 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500164 * @return void
165 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200166 public function serve()
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
168 $r = $this->parseRequest();
Andrey Andreev56e32142011-12-25 18:36:31 +0200169 $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response();
Barry Mienydd671972010-10-04 16:33:58 +0200170
Andrey Andreev52278372012-03-26 16:02:30 +0300171 header('Content-Type: text/xml');
172 header('Content-Length: '.strlen($payload));
Derek Jonesb8d3c3d2009-06-24 15:27:01 +0000173 exit($payload);
Derek Allard2067d1a2008-11-13 22:59:24 +0000174 }
175
Pascal Kriete68d29872011-02-14 13:39:06 -0500176 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200177
Pascal Kriete68d29872011-02-14 13:39:06 -0500178 /**
179 * Add Method to Class
180 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500181 * @param string method name
182 * @param string function
183 * @param string signature
184 * @param string docstring
185 * @return void
186 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200187 public function add_to_map($methodname, $function, $sig, $doc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 {
189 $this->methods[$methodname] = array(
vkeranov52de3792012-11-23 23:48:35 +0200190 'function' => $function,
191 'signature' => $sig,
192 'docstring' => $doc
Derek Allard2067d1a2008-11-13 22:59:24 +0000193 );
194 }
195
Pascal Kriete68d29872011-02-14 13:39:06 -0500196 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000197
Pascal Kriete68d29872011-02-14 13:39:06 -0500198 /**
199 * Parse Server Request
200 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500201 * @param string data
202 * @return object xmlrpc response
203 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200204 public function parseRequest($data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000205 {
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
Alex Bilbied261b1e2012-06-02 11:12:16 +0100210 if ($data === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 {
Andrey Andreev20e802e2014-02-24 12:16:48 +0200212 $CI =& get_instance();
213 if ($CI->input->method() === 'post')
214 {
215 $data = http_build_query($CI->input->input_stream(NULL, FALSE));
216 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000217 }
218
219 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500220 // Set up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000221 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200222
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 $parser = xml_parser_create($this->xmlrpc_defencoding);
Andrey Andreev52278372012-03-26 16:02:30 +0300224 $parser_object = new XML_RPC_Message('filler');
Barry Mienydd671972010-10-04 16:33:58 +0200225
Andrey Andreev56e32142011-12-25 18:36:31 +0200226 $parser_object->xh[$parser] = array(
Andrey Andreev20e802e2014-02-24 12:16:48 +0200227 'isf' => 0,
228 'isf_reason' => '',
229 'params' => array(),
230 'stack' => array(),
231 'valuestack' => array(),
232 'method' => ''
233 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000234
235 xml_set_object($parser, $parser_object);
Alex Bilbieafee2262012-07-15 18:59:01 +0100236 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
238 xml_set_character_data_handler($parser, 'character_data');
239 //xml_set_default_handler($parser, 'default_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200242 // PARSE + PROCESS XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200243 //-------------------------------------
244
Derek Allard2067d1a2008-11-13 22:59:24 +0000245 if ( ! xml_parse($parser, $data, 1))
246 {
vkeranov52de3792012-11-23 23:48:35 +0200247 // Return XML error as a faultCode
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 $r = new XML_RPC_Response(0,
vkeranov52de3792012-11-23 23:48:35 +0200249 $this->xmlrpcerrxml + xml_get_error_code($parser),
250 sprintf('XML error: %s at line %d',
Derek Allard2067d1a2008-11-13 22:59:24 +0000251 xml_error_string(xml_get_error_code($parser)),
252 xml_get_current_line_number($parser)));
253 xml_parser_free($parser);
254 }
Pascal Kriete68d29872011-02-14 13:39:06 -0500255 elseif ($parser_object->xh[$parser]['isf'])
Derek Allard2067d1a2008-11-13 22:59:24 +0000256 {
257 return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
258 }
259 else
260 {
261 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200262
Derek Allard2067d1a2008-11-13 22:59:24 +0000263 $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
vkeranov52de3792012-11-23 23:48:35 +0200264 $plist = '';
Barry Mienydd671972010-10-04 16:33:58 +0200265
Andrey Andreev56e32142011-12-25 18:36:31 +0200266 for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000267 {
268 if ($this->debug === TRUE)
269 {
Andrey Andreev52278372012-03-26 16:02:30 +0300270 $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE).";\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000271 }
Barry Mienydd671972010-10-04 16:33:58 +0200272
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 $m->addParam($parser_object->xh[$parser]['params'][$i]);
274 }
Barry Mienydd671972010-10-04 16:33:58 +0200275
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 if ($this->debug === TRUE)
277 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200278 echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 }
Barry Mienydd671972010-10-04 16:33:58 +0200280
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 $r = $this->_execute($m);
282 }
Barry Mienydd671972010-10-04 16:33:58 +0200283
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200285 // SET DEBUGGING MESSAGE
Barry Mienydd671972010-10-04 16:33:58 +0200286 //-------------------------------------
287
Derek Allard2067d1a2008-11-13 22:59:24 +0000288 if ($this->debug === TRUE)
289 {
290 $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
291 }
Barry Mienydd671972010-10-04 16:33:58 +0200292
Derek Allard2067d1a2008-11-13 22:59:24 +0000293 return $r;
294 }
295
Pascal Kriete68d29872011-02-14 13:39:06 -0500296 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200297
Pascal Kriete68d29872011-02-14 13:39:06 -0500298 /**
299 * Executes the Method
300 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500301 * @param object
302 * @return mixed
303 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200304 protected function _execute($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 {
306 $methName = $m->method_name;
Barry Mienydd671972010-10-04 16:33:58 +0200307
Derek Allard2067d1a2008-11-13 22:59:24 +0000308 // Check to see if it is a system call
Andrey Andreev3dad2e72012-06-14 15:10:56 +0300309 $system_call = (strpos($methName, 'system') === 0);
Barry Mienydd671972010-10-04 16:33:58 +0200310
Alex Bilbied261b1e2012-06-02 11:12:16 +0100311 if ($this->xss_clean === FALSE)
Robin Sowell66a3fc02010-03-18 09:44:55 -0400312 {
313 $m->xss_clean = FALSE;
314 }
315
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200317 // Valid Method
Derek Allard2067d1a2008-11-13 22:59:24 +0000318 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200319
Derek Allard2067d1a2008-11-13 22:59:24 +0000320 if ( ! isset($this->methods[$methName]['function']))
321 {
322 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
323 }
Barry Mienydd671972010-10-04 16:33:58 +0200324
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200326 // Check for Method (and Object)
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200328
Andrey Andreev52278372012-03-26 16:02:30 +0300329 $method_parts = explode('.', $this->methods[$methName]['function']);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100330 $objectCall = (isset($method_parts[1]) && $method_parts[1] !== '');
Barry Mienydd671972010-10-04 16:33:58 +0200331
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 if ($system_call === TRUE)
333 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200334 if ( ! is_callable(array($this,$method_parts[1])))
Derek Allard2067d1a2008-11-13 22:59:24 +0000335 {
336 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
337 }
338 }
Andrey Andreev52278372012-03-26 16:02:30 +0300339 elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1])))
340 OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
341 )
Derek Allard2067d1a2008-11-13 22:59:24 +0000342 {
Andrey Andreev52278372012-03-26 16:02:30 +0300343 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000344 }
Barry Mienydd671972010-10-04 16:33:58 +0200345
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200347 // Checking Methods Signature
Derek Allard2067d1a2008-11-13 22:59:24 +0000348 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200349
Derek Allard2067d1a2008-11-13 22:59:24 +0000350 if (isset($this->methods[$methName]['signature']))
351 {
352 $sig = $this->methods[$methName]['signature'];
Andrey Andreev56e32142011-12-25 18:36:31 +0200353 for ($i = 0, $c = count($sig); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000354 {
355 $current_sig = $sig[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200356
Andrey Andreev56e32142011-12-25 18:36:31 +0200357 if (count($current_sig) === count($m->params)+1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000358 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200359 for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000360 {
361 $p = $m->params[$n];
Alex Bilbied261b1e2012-06-02 11:12:16 +0100362 $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf();
Barry Mienydd671972010-10-04 16:33:58 +0200363
Alex Bilbied261b1e2012-06-02 11:12:16 +0100364 if ($pt !== $current_sig[$n+1])
Derek Allard2067d1a2008-11-13 22:59:24 +0000365 {
366 $pno = $n+1;
367 $wanted = $current_sig[$n+1];
Barry Mienydd671972010-10-04 16:33:58 +0200368
Derek Allard2067d1a2008-11-13 22:59:24 +0000369 return new XML_RPC_Response(0,
370 $this->xmlrpcerr['incorrect_params'],
371 $this->xmlrpcstr['incorrect_params'] .
Andrey Andreev52278372012-03-26 16:02:30 +0300372 ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')');
Derek Allard2067d1a2008-11-13 22:59:24 +0000373 }
374 }
375 }
376 }
377 }
378
379 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200380 // Calls the Function
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 //-------------------------------------
382
383 if ($objectCall === TRUE)
384 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200385 if ($method_parts[0] === 'this' && $system_call === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000386 {
387 return call_user_func(array($this, $method_parts[1]), $m);
388 }
Andrey Andreev119d8a72014-01-08 15:27:53 +0200389 elseif ($this->object === FALSE)
390 {
391 return get_instance()->$method_parts[1]($m);
392 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000393 else
394 {
Andrey Andreev119d8a72014-01-08 15:27:53 +0200395 return $this->object->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 }
397 }
398 else
399 {
400 return call_user_func($this->methods[$methName]['function'], $m);
401 }
402 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200403
Pascal Kriete68d29872011-02-14 13:39:06 -0500404 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200405
Pascal Kriete68d29872011-02-14 13:39:06 -0500406 /**
vkeranov52de3792012-11-23 23:48:35 +0200407 * Server Function: List Methods
Pascal Kriete68d29872011-02-14 13:39:06 -0500408 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500409 * @param mixed
410 * @return object
411 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200412 public function listMethods($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000413 {
414 $v = new XML_RPC_Values();
415 $output = array();
Barry Mienydd671972010-10-04 16:33:58 +0200416
Pascal Kriete68d29872011-02-14 13:39:06 -0500417 foreach ($this->methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000418 {
419 $output[] = new XML_RPC_Values($key, 'string');
420 }
Barry Mienydd671972010-10-04 16:33:58 +0200421
Pascal Kriete68d29872011-02-14 13:39:06 -0500422 foreach ($this->system_methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000423 {
Andrey Andreev52278372012-03-26 16:02:30 +0300424 $output[] = new XML_RPC_Values($key, 'string');
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 }
426
427 $v->addArray($output);
428 return new XML_RPC_Response($v);
429 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200430
Pascal Kriete68d29872011-02-14 13:39:06 -0500431 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200432
Pascal Kriete68d29872011-02-14 13:39:06 -0500433 /**
vkeranov52de3792012-11-23 23:48:35 +0200434 * Server Function: Return Signature for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500435 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500436 * @param mixed
437 * @return object
438 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200439 public function methodSignature($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 $parameters = $m->output_parameters();
442 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200443
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 if (isset($this->methods[$method_name]))
445 {
446 if ($this->methods[$method_name]['signature'])
447 {
448 $sigs = array();
449 $signature = $this->methods[$method_name]['signature'];
Barry Mienydd671972010-10-04 16:33:58 +0200450
Andrey Andreev56e32142011-12-25 18:36:31 +0200451 for ($i = 0, $c = count($signature); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000452 {
453 $cursig = array();
454 $inSig = $signature[$i];
Andrey Andreev56e32142011-12-25 18:36:31 +0200455 for ($j = 0, $jc = count($inSig); $j < $jc; $j++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000456 {
457 $cursig[]= new XML_RPC_Values($inSig[$j], 'string');
458 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200459 $sigs[] = new XML_RPC_Values($cursig, 'array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 }
Andrey Andreev52278372012-03-26 16:02:30 +0300461
462 return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000463 }
Andrey Andreev52278372012-03-26 16:02:30 +0300464
465 return new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 }
Andrey Andreev52278372012-03-26 16:02:30 +0300467
vkeranov52de3792012-11-23 23:48:35 +0200468 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 }
Barry Mienydd671972010-10-04 16:33:58 +0200470
Pascal Kriete68d29872011-02-14 13:39:06 -0500471 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200472
Pascal Kriete68d29872011-02-14 13:39:06 -0500473 /**
vkeranov52de3792012-11-23 23:48:35 +0200474 * Server Function: Doc String for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500475 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500476 * @param mixed
477 * @return object
478 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200479 public function methodHelp($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000480 {
481 $parameters = $m->output_parameters();
482 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200483
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 if (isset($this->methods[$method_name]))
485 {
486 $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
Barry Mienydd671972010-10-04 16:33:58 +0200487
Derek Allard2067d1a2008-11-13 22:59:24 +0000488 return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
489 }
490 else
491 {
492 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
493 }
494 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200495
Pascal Kriete68d29872011-02-14 13:39:06 -0500496 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000497
Pascal Kriete68d29872011-02-14 13:39:06 -0500498 /**
vkeranov52de3792012-11-23 23:48:35 +0200499 * Server Function: Multi-call
Pascal Kriete68d29872011-02-14 13:39:06 -0500500 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500501 * @param mixed
502 * @return object
503 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200504 public function multicall($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000505 {
506 // Disabled
507 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Barry Mienydd671972010-10-04 16:33:58 +0200508
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 $parameters = $m->output_parameters();
510 $calls = $parameters[0];
511
512 $result = array();
513
514 foreach ($calls as $value)
515 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 $m = new XML_RPC_Message($value[0]);
vkeranov52de3792012-11-23 23:48:35 +0200517 $plist = '';
Barry Mienydd671972010-10-04 16:33:58 +0200518
Andrey Andreev56e32142011-12-25 18:36:31 +0200519 for ($i = 0, $c = count($value[1]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 {
521 $m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
522 }
Barry Mienydd671972010-10-04 16:33:58 +0200523
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 $attempt = $this->_execute($m);
525
Alex Bilbied261b1e2012-06-02 11:12:16 +0100526 if ($attempt->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000527 {
528 return $attempt;
529 }
530
531 $result[] = new XML_RPC_Values(array($attempt->value()), 'array');
532 }
533
534 return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
535 }
Barry Mienydd671972010-10-04 16:33:58 +0200536
Pascal Kriete68d29872011-02-14 13:39:06 -0500537 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200538
Pascal Kriete68d29872011-02-14 13:39:06 -0500539 /**
vkeranov52de3792012-11-23 23:48:35 +0200540 * Multi-call Function: Error Handling
Pascal Kriete68d29872011-02-14 13:39:06 -0500541 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500542 * @param mixed
543 * @return object
544 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200545 public function multicall_error($err)
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 {
vkeranov52de3792012-11-23 23:48:35 +0200547 $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
Derek Allard2067d1a2008-11-13 22:59:24 +0000548 $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
Barry Mienydd671972010-10-04 16:33:58 +0200549
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 $struct['faultCode'] = new XML_RPC_Values($code, 'int');
551 $struct['faultString'] = new XML_RPC_Values($str, 'string');
Barry Mienydd671972010-10-04 16:33:58 +0200552
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 return new XML_RPC_Values($struct, 'struct');
554 }
Barry Mienydd671972010-10-04 16:33:58 +0200555
Pascal Kriete68d29872011-02-14 13:39:06 -0500556 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200557
Pascal Kriete68d29872011-02-14 13:39:06 -0500558 /**
vkeranov52de3792012-11-23 23:48:35 +0200559 * Multi-call Function: Processes method
Pascal Kriete68d29872011-02-14 13:39:06 -0500560 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500561 * @param mixed
562 * @return object
563 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200564 public function do_multicall($call)
Derek Allard2067d1a2008-11-13 22:59:24 +0000565 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100566 if ($call->kindOf() !== 'struct')
Pascal Kriete68d29872011-02-14 13:39:06 -0500567 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 return $this->multicall_error('notstruct');
Pascal Kriete68d29872011-02-14 13:39:06 -0500569 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000570 elseif ( ! $methName = $call->me['struct']['methodName'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500571 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 return $this->multicall_error('nomethod');
Pascal Kriete68d29872011-02-14 13:39:06 -0500573 }
Barry Mienydd671972010-10-04 16:33:58 +0200574
vkeranov52de3792012-11-23 23:48:35 +0200575 list($scalar_type, $scalar_value) = each($methName->me);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100576 $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
Barry Mienydd671972010-10-04 16:33:58 +0200577
Alex Bilbied261b1e2012-06-02 11:12:16 +0100578 if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string')
Pascal Kriete68d29872011-02-14 13:39:06 -0500579 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 return $this->multicall_error('notstring');
Pascal Kriete68d29872011-02-14 13:39:06 -0500581 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100582 elseif ($scalar_value === 'system.multicall')
Pascal Kriete68d29872011-02-14 13:39:06 -0500583 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 return $this->multicall_error('recursion');
Pascal Kriete68d29872011-02-14 13:39:06 -0500585 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000586 elseif ( ! $params = $call->me['struct']['params'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500587 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 return $this->multicall_error('noparams');
Pascal Kriete68d29872011-02-14 13:39:06 -0500589 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100590 elseif ($params->kindOf() !== 'array')
Pascal Kriete68d29872011-02-14 13:39:06 -0500591 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 return $this->multicall_error('notarray');
Pascal Kriete68d29872011-02-14 13:39:06 -0500593 }
Barry Mienydd671972010-10-04 16:33:58 +0200594
vkeranov52de3792012-11-23 23:48:35 +0200595 list($a, $b) = each($params->me);
Derek Allard2067d1a2008-11-13 22:59:24 +0000596
597 $msg = new XML_RPC_Message($scalar_value);
Andrey Andreev56e32142011-12-25 18:36:31 +0200598 for ($i = 0, $numParams = count($b); $i < $numParams; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000599 {
600 $msg->params[] = $params->me['array'][$i];
601 }
602
603 $result = $this->_execute($msg);
604
Alex Bilbied261b1e2012-06-02 11:12:16 +0100605 if ($result->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000606 {
607 return $this->multicall_error($result);
608 }
609
610 return new XML_RPC_Values(array($result->value()), 'array');
Barry Mienydd671972010-10-04 16:33:58 +0200611 }
612
Derek Allard2067d1a2008-11-13 22:59:24 +0000613}
Derek Allard2067d1a2008-11-13 22:59:24 +0000614
Derek Allard2067d1a2008-11-13 22:59:24 +0000615/* End of file Xmlrpcs.php */
Andrey Andreev52278372012-03-26 16:02:30 +0300616/* Location: ./system/libraries/Xmlrpcs.php */