blob: e150c13b72048f432f11b596c77fb72a07d2c317 [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
Andrey Andreev80500af2013-01-01 08:16:53 +020021 * @copyright Copyright (c) 2008 - 2013, 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));
Daniel Hunsaker353f9832013-01-24 17:09:10 -0700173 echo $payload;
Daniel Hunsaker3b5b7f42013-02-22 19:17:56 -0700174 exit(EXIT_SUCCESS);
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 }
176
Pascal Kriete68d29872011-02-14 13:39:06 -0500177 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200178
Pascal Kriete68d29872011-02-14 13:39:06 -0500179 /**
180 * Add Method to Class
181 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500182 * @param string method name
183 * @param string function
184 * @param string signature
185 * @param string docstring
186 * @return void
187 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200188 public function add_to_map($methodname, $function, $sig, $doc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000189 {
190 $this->methods[$methodname] = array(
vkeranov52de3792012-11-23 23:48:35 +0200191 'function' => $function,
192 'signature' => $sig,
193 'docstring' => $doc
Derek Allard2067d1a2008-11-13 22:59:24 +0000194 );
195 }
196
Pascal Kriete68d29872011-02-14 13:39:06 -0500197 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000198
Pascal Kriete68d29872011-02-14 13:39:06 -0500199 /**
200 * Parse Server Request
201 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500202 * @param string data
203 * @return object xmlrpc response
204 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200205 public function parseRequest($data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000206 {
207 global $HTTP_RAW_POST_DATA;
Barry Mienydd671972010-10-04 16:33:58 +0200208
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500210 // Get Data
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 //-------------------------------------
212
Alex Bilbied261b1e2012-06-02 11:12:16 +0100213 if ($data === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 {
215 $data = $HTTP_RAW_POST_DATA;
216 }
217
218 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500219 // Set up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200221
Derek Allard2067d1a2008-11-13 22:59:24 +0000222 $parser = xml_parser_create($this->xmlrpc_defencoding);
Andrey Andreev52278372012-03-26 16:02:30 +0300223 $parser_object = new XML_RPC_Message('filler');
Barry Mienydd671972010-10-04 16:33:58 +0200224
Andrey Andreev56e32142011-12-25 18:36:31 +0200225 $parser_object->xh[$parser] = array(
226 'isf' => 0,
227 'isf_reason' => '',
228 'params' => array(),
229 'stack' => array(),
230 'valuestack' => array(),
231 'method' => ''
232 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000233
234 xml_set_object($parser, $parser_object);
Alex Bilbieafee2262012-07-15 18:59:01 +0100235 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000236 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
237 xml_set_character_data_handler($parser, 'character_data');
238 //xml_set_default_handler($parser, 'default_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200239
Derek Allard2067d1a2008-11-13 22:59:24 +0000240 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200241 // PARSE + PROCESS XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200242 //-------------------------------------
243
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 if ( ! xml_parse($parser, $data, 1))
245 {
vkeranov52de3792012-11-23 23:48:35 +0200246 // Return XML error as a faultCode
Derek Allard2067d1a2008-11-13 22:59:24 +0000247 $r = new XML_RPC_Response(0,
vkeranov52de3792012-11-23 23:48:35 +0200248 $this->xmlrpcerrxml + xml_get_error_code($parser),
249 sprintf('XML error: %s at line %d',
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 xml_error_string(xml_get_error_code($parser)),
251 xml_get_current_line_number($parser)));
252 xml_parser_free($parser);
253 }
Pascal Kriete68d29872011-02-14 13:39:06 -0500254 elseif ($parser_object->xh[$parser]['isf'])
Derek Allard2067d1a2008-11-13 22:59:24 +0000255 {
256 return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
257 }
258 else
259 {
260 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200261
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
vkeranov52de3792012-11-23 23:48:35 +0200263 $plist = '';
Barry Mienydd671972010-10-04 16:33:58 +0200264
Andrey Andreev56e32142011-12-25 18:36:31 +0200265 for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000266 {
267 if ($this->debug === TRUE)
268 {
Andrey Andreev52278372012-03-26 16:02:30 +0300269 $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE).";\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 }
Barry Mienydd671972010-10-04 16:33:58 +0200271
Derek Allard2067d1a2008-11-13 22:59:24 +0000272 $m->addParam($parser_object->xh[$parser]['params'][$i]);
273 }
Barry Mienydd671972010-10-04 16:33:58 +0200274
Derek Allard2067d1a2008-11-13 22:59:24 +0000275 if ($this->debug === TRUE)
276 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200277 echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 }
Barry Mienydd671972010-10-04 16:33:58 +0200279
Derek Allard2067d1a2008-11-13 22:59:24 +0000280 $r = $this->_execute($m);
281 }
Barry Mienydd671972010-10-04 16:33:58 +0200282
Derek Allard2067d1a2008-11-13 22:59:24 +0000283 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200284 // SET DEBUGGING MESSAGE
Barry Mienydd671972010-10-04 16:33:58 +0200285 //-------------------------------------
286
Derek Allard2067d1a2008-11-13 22:59:24 +0000287 if ($this->debug === TRUE)
288 {
289 $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
290 }
Barry Mienydd671972010-10-04 16:33:58 +0200291
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 return $r;
293 }
294
Pascal Kriete68d29872011-02-14 13:39:06 -0500295 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200296
Pascal Kriete68d29872011-02-14 13:39:06 -0500297 /**
298 * Executes the Method
299 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500300 * @param object
301 * @return mixed
302 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200303 protected function _execute($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 {
305 $methName = $m->method_name;
Barry Mienydd671972010-10-04 16:33:58 +0200306
Derek Allard2067d1a2008-11-13 22:59:24 +0000307 // Check to see if it is a system call
Andrey Andreev3dad2e72012-06-14 15:10:56 +0300308 $system_call = (strpos($methName, 'system') === 0);
Barry Mienydd671972010-10-04 16:33:58 +0200309
Alex Bilbied261b1e2012-06-02 11:12:16 +0100310 if ($this->xss_clean === FALSE)
Robin Sowell66a3fc02010-03-18 09:44:55 -0400311 {
312 $m->xss_clean = FALSE;
313 }
314
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200316 // Valid Method
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200318
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 if ( ! isset($this->methods[$methName]['function']))
320 {
321 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
322 }
Barry Mienydd671972010-10-04 16:33:58 +0200323
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200325 // Check for Method (and Object)
Derek Allard2067d1a2008-11-13 22:59:24 +0000326 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200327
Andrey Andreev52278372012-03-26 16:02:30 +0300328 $method_parts = explode('.', $this->methods[$methName]['function']);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100329 $objectCall = (isset($method_parts[1]) && $method_parts[1] !== '');
Barry Mienydd671972010-10-04 16:33:58 +0200330
Derek Allard2067d1a2008-11-13 22:59:24 +0000331 if ($system_call === TRUE)
332 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200333 if ( ! is_callable(array($this,$method_parts[1])))
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 {
335 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
336 }
337 }
Andrey Andreev52278372012-03-26 16:02:30 +0300338 elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1])))
339 OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
340 )
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 {
Andrey Andreev52278372012-03-26 16:02:30 +0300342 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 }
Barry Mienydd671972010-10-04 16:33:58 +0200344
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200346 // Checking Methods Signature
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200348
Derek Allard2067d1a2008-11-13 22:59:24 +0000349 if (isset($this->methods[$methName]['signature']))
350 {
351 $sig = $this->methods[$methName]['signature'];
Andrey Andreev56e32142011-12-25 18:36:31 +0200352 for ($i = 0, $c = count($sig); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000353 {
354 $current_sig = $sig[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200355
Andrey Andreev56e32142011-12-25 18:36:31 +0200356 if (count($current_sig) === count($m->params)+1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200358 for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 {
360 $p = $m->params[$n];
Alex Bilbied261b1e2012-06-02 11:12:16 +0100361 $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf();
Barry Mienydd671972010-10-04 16:33:58 +0200362
Alex Bilbied261b1e2012-06-02 11:12:16 +0100363 if ($pt !== $current_sig[$n+1])
Derek Allard2067d1a2008-11-13 22:59:24 +0000364 {
365 $pno = $n+1;
366 $wanted = $current_sig[$n+1];
Barry Mienydd671972010-10-04 16:33:58 +0200367
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 return new XML_RPC_Response(0,
369 $this->xmlrpcerr['incorrect_params'],
370 $this->xmlrpcstr['incorrect_params'] .
Andrey Andreev52278372012-03-26 16:02:30 +0300371 ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')');
Derek Allard2067d1a2008-11-13 22:59:24 +0000372 }
373 }
374 }
375 }
376 }
377
378 //-------------------------------------
vkeranov52de3792012-11-23 23:48:35 +0200379 // Calls the Function
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 //-------------------------------------
381
382 if ($objectCall === TRUE)
383 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200384 if ($method_parts[0] === 'this' && $system_call === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000385 {
386 return call_user_func(array($this, $method_parts[1]), $m);
387 }
388 else
389 {
390 if ($this->object === FALSE)
391 {
392 $CI =& get_instance();
Andrey Andreev56e32142011-12-25 18:36:31 +0200393 return $CI->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000394 }
395 else
396 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200397 return $this->object->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000398 }
399 }
400 }
401 else
402 {
403 return call_user_func($this->methods[$methName]['function'], $m);
404 }
405 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200406
Pascal Kriete68d29872011-02-14 13:39:06 -0500407 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200408
Pascal Kriete68d29872011-02-14 13:39:06 -0500409 /**
vkeranov52de3792012-11-23 23:48:35 +0200410 * Server Function: List Methods
Pascal Kriete68d29872011-02-14 13:39:06 -0500411 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500412 * @param mixed
413 * @return object
414 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200415 public function listMethods($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 {
417 $v = new XML_RPC_Values();
418 $output = array();
Barry Mienydd671972010-10-04 16:33:58 +0200419
Pascal Kriete68d29872011-02-14 13:39:06 -0500420 foreach ($this->methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000421 {
422 $output[] = new XML_RPC_Values($key, 'string');
423 }
Barry Mienydd671972010-10-04 16:33:58 +0200424
Pascal Kriete68d29872011-02-14 13:39:06 -0500425 foreach ($this->system_methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000426 {
Andrey Andreev52278372012-03-26 16:02:30 +0300427 $output[] = new XML_RPC_Values($key, 'string');
Derek Allard2067d1a2008-11-13 22:59:24 +0000428 }
429
430 $v->addArray($output);
431 return new XML_RPC_Response($v);
432 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200433
Pascal Kriete68d29872011-02-14 13:39:06 -0500434 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200435
Pascal Kriete68d29872011-02-14 13:39:06 -0500436 /**
vkeranov52de3792012-11-23 23:48:35 +0200437 * Server Function: Return Signature for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500438 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500439 * @param mixed
440 * @return object
441 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200442 public function methodSignature($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000443 {
444 $parameters = $m->output_parameters();
445 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200446
Derek Allard2067d1a2008-11-13 22:59:24 +0000447 if (isset($this->methods[$method_name]))
448 {
449 if ($this->methods[$method_name]['signature'])
450 {
451 $sigs = array();
452 $signature = $this->methods[$method_name]['signature'];
Barry Mienydd671972010-10-04 16:33:58 +0200453
Andrey Andreev56e32142011-12-25 18:36:31 +0200454 for ($i = 0, $c = count($signature); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 {
456 $cursig = array();
457 $inSig = $signature[$i];
Andrey Andreev56e32142011-12-25 18:36:31 +0200458 for ($j = 0, $jc = count($inSig); $j < $jc; $j++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000459 {
460 $cursig[]= new XML_RPC_Values($inSig[$j], 'string');
461 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200462 $sigs[] = new XML_RPC_Values($cursig, '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($sigs, 'array'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000466 }
Andrey Andreev52278372012-03-26 16:02:30 +0300467
468 return new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000469 }
Andrey Andreev52278372012-03-26 16:02:30 +0300470
vkeranov52de3792012-11-23 23:48:35 +0200471 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 }
Barry Mienydd671972010-10-04 16:33:58 +0200473
Pascal Kriete68d29872011-02-14 13:39:06 -0500474 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200475
Pascal Kriete68d29872011-02-14 13:39:06 -0500476 /**
vkeranov52de3792012-11-23 23:48:35 +0200477 * Server Function: Doc String for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500478 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500479 * @param mixed
480 * @return object
481 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200482 public function methodHelp($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000483 {
484 $parameters = $m->output_parameters();
485 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200486
Derek Allard2067d1a2008-11-13 22:59:24 +0000487 if (isset($this->methods[$method_name]))
488 {
489 $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
Barry Mienydd671972010-10-04 16:33:58 +0200490
Derek Allard2067d1a2008-11-13 22:59:24 +0000491 return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
492 }
493 else
494 {
495 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
496 }
497 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200498
Pascal Kriete68d29872011-02-14 13:39:06 -0500499 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000500
Pascal Kriete68d29872011-02-14 13:39:06 -0500501 /**
vkeranov52de3792012-11-23 23:48:35 +0200502 * Server Function: Multi-call
Pascal Kriete68d29872011-02-14 13:39:06 -0500503 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500504 * @param mixed
505 * @return object
506 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200507 public function multicall($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000508 {
509 // Disabled
510 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Barry Mienydd671972010-10-04 16:33:58 +0200511
Derek Allard2067d1a2008-11-13 22:59:24 +0000512 $parameters = $m->output_parameters();
513 $calls = $parameters[0];
514
515 $result = array();
516
517 foreach ($calls as $value)
518 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000519 $m = new XML_RPC_Message($value[0]);
vkeranov52de3792012-11-23 23:48:35 +0200520 $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
Alex Bilbied261b1e2012-06-02 11:12:16 +0100529 if ($attempt->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 {
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 /**
vkeranov52de3792012-11-23 23:48:35 +0200543 * 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 {
vkeranov52de3792012-11-23 23:48:35 +0200550 $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 /**
vkeranov52de3792012-11-23 23:48:35 +0200562 * 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 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100569 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
vkeranov52de3792012-11-23 23:48:35 +0200578 list($scalar_type, $scalar_value) = each($methName->me);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100579 $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
Barry Mienydd671972010-10-04 16:33:58 +0200580
Alex Bilbied261b1e2012-06-02 11:12:16 +0100581 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 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100585 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 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100593 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
vkeranov52de3792012-11-23 23:48:35 +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
Alex Bilbied261b1e2012-06-02 11:12:16 +0100608 if ($result->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 {
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 */