blob: 5d01d374d34b24178fa410fe0c3d2ce188a37f6b [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();
Andrey Andreev56454792012-05-17 14:32:19 +030057
Timothy Warren0688ac92012-04-20 10:25:04 -040058 /**
59 * Debug Message
60 *
61 * @var string
62 */
63 public $debug_msg = '';
Andrey Andreev56454792012-05-17 14:32:19 +030064
Timothy Warren0688ac92012-04-20 10:25:04 -040065 /**
66 * XML RPC Server methods
67 *
68 * @var array
69 */
70 public $system_methods = array();
Andrey Andreev56454792012-05-17 14:32:19 +030071
Timothy Warren0688ac92012-04-20 10:25:04 -040072 /**
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 *
Andrey Andreev56454792012-05-17 14:32:19 +030082 * @param array $config
83 * @return void
Timothy Warren0688ac92012-04-20 10:25:04 -040084 */
Andrey Andreev52278372012-03-26 16:02:30 +030085 public function __construct($config = array())
Barry Mienydd671972010-10-04 16:33:58 +020086 {
Greg Akera9263282010-11-10 15:26:43 -060087 parent::__construct();
Derek Allard2067d1a2008-11-13 22:59:24 +000088 $this->set_system_methods();
Barry Mienydd671972010-10-04 16:33:58 +020089
Derek Allard2067d1a2008-11-13 22:59:24 +000090 if (isset($config['functions']) && is_array($config['functions']))
91 {
92 $this->methods = array_merge($this->methods, $config['functions']);
93 }
Barry Mienydd671972010-10-04 16:33:58 +020094
Andrey Andreev52278372012-03-26 16:02:30 +030095 log_message('debug', 'XML-RPC Server Class Initialized');
Derek Allard2067d1a2008-11-13 22:59:24 +000096 }
Barry Mienydd671972010-10-04 16:33:58 +020097
Pascal Kriete68d29872011-02-14 13:39:06 -050098 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +020099
Pascal Kriete68d29872011-02-14 13:39:06 -0500100 /**
101 * Initialize Prefs and Serve
102 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500103 * @param mixed
104 * @return void
105 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200106 public function initialize($config = array())
Barry Mienydd671972010-10-04 16:33:58 +0200107 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000108 if (isset($config['functions']) && is_array($config['functions']))
109 {
110 $this->methods = array_merge($this->methods, $config['functions']);
111 }
Barry Mienydd671972010-10-04 16:33:58 +0200112
Derek Allard2067d1a2008-11-13 22:59:24 +0000113 if (isset($config['debug']))
114 {
115 $this->debug = $config['debug'];
116 }
Barry Mienydd671972010-10-04 16:33:58 +0200117
Derek Allard2067d1a2008-11-13 22:59:24 +0000118 if (isset($config['object']) && is_object($config['object']))
119 {
120 $this->object = $config['object'];
121 }
Barry Mienydd671972010-10-04 16:33:58 +0200122
Robin Sowell66a3fc02010-03-18 09:44:55 -0400123 if (isset($config['xss_clean']))
124 {
125 $this->xss_clean = $config['xss_clean'];
126 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000127 }
Barry Mienydd671972010-10-04 16:33:58 +0200128
Pascal Kriete68d29872011-02-14 13:39:06 -0500129 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200130
Pascal Kriete68d29872011-02-14 13:39:06 -0500131 /**
132 * Setting of System Methods
133 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500134 * @return void
135 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200136 public function set_system_methods()
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 {
138 $this->methods = array(
139 'system.listMethods' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200140 'function' => 'this.listMethods',
141 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)),
142 'docstring' => 'Returns an array of available methods on this server'),
143 'system.methodHelp' => array(
144 'function' => 'this.methodHelp',
145 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)),
146 'docstring' => 'Returns a documentation string for the specified method'),
Derek Allard2067d1a2008-11-13 22:59:24 +0000147 'system.methodSignature' => array(
Andrey Andreev56e32142011-12-25 18:36:31 +0200148 'function' => 'this.methodSignature',
149 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)),
150 'docstring' => 'Returns an array describing the return type and required parameters of a method'),
151 'system.multicall' => array(
152 'function' => 'this.multicall',
153 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)),
154 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details')
155 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 }
157
Pascal Kriete68d29872011-02-14 13:39:06 -0500158 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000159
Pascal Kriete68d29872011-02-14 13:39:06 -0500160 /**
161 * Main Server Function
162 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500163 * @return void
164 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200165 public function serve()
Derek Allard2067d1a2008-11-13 22:59:24 +0000166 {
167 $r = $this->parseRequest();
Andrey Andreev56e32142011-12-25 18:36:31 +0200168 $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response();
Barry Mienydd671972010-10-04 16:33:58 +0200169
Andrey Andreev52278372012-03-26 16:02:30 +0300170 header('Content-Type: text/xml');
171 header('Content-Length: '.strlen($payload));
Derek Jonesb8d3c3d2009-06-24 15:27:01 +0000172 exit($payload);
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 }
174
Pascal Kriete68d29872011-02-14 13:39:06 -0500175 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200176
Pascal Kriete68d29872011-02-14 13:39:06 -0500177 /**
178 * Add Method to Class
179 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500180 * @param string method name
181 * @param string function
182 * @param string signature
183 * @param string docstring
184 * @return void
185 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200186 public function add_to_map($methodname, $function, $sig, $doc)
Derek Allard2067d1a2008-11-13 22:59:24 +0000187 {
188 $this->methods[$methodname] = array(
Derek Jones37f4b9c2011-07-01 17:56:50 -0500189 'function' => $function,
Derek Allard2067d1a2008-11-13 22:59:24 +0000190 'signature' => $sig,
191 'docstring' => $doc
192 );
193 }
194
Pascal Kriete68d29872011-02-14 13:39:06 -0500195 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000196
Pascal Kriete68d29872011-02-14 13:39:06 -0500197 /**
198 * Parse Server Request
199 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500200 * @param string data
201 * @return object xmlrpc response
202 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200203 public function parseRequest($data = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 {
205 global $HTTP_RAW_POST_DATA;
Barry Mienydd671972010-10-04 16:33:58 +0200206
Derek Allard2067d1a2008-11-13 22:59:24 +0000207 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500208 // Get Data
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 //-------------------------------------
210
Alex Bilbied261b1e2012-06-02 11:12:16 +0100211 if ($data === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000212 {
213 $data = $HTTP_RAW_POST_DATA;
214 }
215
216 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500217 // Set up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000218 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200219
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 $parser = xml_parser_create($this->xmlrpc_defencoding);
Andrey Andreev52278372012-03-26 16:02:30 +0300221 $parser_object = new XML_RPC_Message('filler');
Barry Mienydd671972010-10-04 16:33:58 +0200222
Andrey Andreev56e32142011-12-25 18:36:31 +0200223 $parser_object->xh[$parser] = array(
224 'isf' => 0,
225 'isf_reason' => '',
226 'params' => array(),
227 'stack' => array(),
228 'valuestack' => array(),
229 'method' => ''
230 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000231
232 xml_set_object($parser, $parser_object);
Alex Bilbieafee2262012-07-15 18:59:01 +0100233 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
235 xml_set_character_data_handler($parser, 'character_data');
236 //xml_set_default_handler($parser, 'default_handler');
Barry Mienydd671972010-10-04 16:33:58 +0200237
Derek Allard2067d1a2008-11-13 22:59:24 +0000238 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500239 // PARSE + PROCESS XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200240 //-------------------------------------
241
Derek Allard2067d1a2008-11-13 22:59:24 +0000242 if ( ! xml_parse($parser, $data, 1))
243 {
244 // return XML error as a faultCode
245 $r = new XML_RPC_Response(0,
246 $this->xmlrpcerrxml + xml_get_error_code($parser),
247 sprintf('XML error: %s at line %d',
248 xml_error_string(xml_get_error_code($parser)),
249 xml_get_current_line_number($parser)));
250 xml_parser_free($parser);
251 }
Pascal Kriete68d29872011-02-14 13:39:06 -0500252 elseif ($parser_object->xh[$parser]['isf'])
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 {
254 return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
255 }
256 else
257 {
258 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200259
Derek Allard2067d1a2008-11-13 22:59:24 +0000260 $m = new XML_RPC_Message($parser_object->xh[$parser]['method']);
261 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200262
Andrey Andreev56e32142011-12-25 18:36:31 +0200263 for ($i = 0, $c = count($parser_object->xh[$parser]['params']); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000264 {
265 if ($this->debug === TRUE)
266 {
Andrey Andreev52278372012-03-26 16:02:30 +0300267 $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$parser]['params'][$i]), TRUE).";\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000268 }
Barry Mienydd671972010-10-04 16:33:58 +0200269
Derek Allard2067d1a2008-11-13 22:59:24 +0000270 $m->addParam($parser_object->xh[$parser]['params'][$i]);
271 }
Barry Mienydd671972010-10-04 16:33:58 +0200272
Derek Allard2067d1a2008-11-13 22:59:24 +0000273 if ($this->debug === TRUE)
274 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200275 echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 }
Barry Mienydd671972010-10-04 16:33:58 +0200277
Derek Allard2067d1a2008-11-13 22:59:24 +0000278 $r = $this->_execute($m);
279 }
Barry Mienydd671972010-10-04 16:33:58 +0200280
Derek Allard2067d1a2008-11-13 22:59:24 +0000281 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500282 // SET DEBUGGING MESSAGE
Barry Mienydd671972010-10-04 16:33:58 +0200283 //-------------------------------------
284
Derek Allard2067d1a2008-11-13 22:59:24 +0000285 if ($this->debug === TRUE)
286 {
287 $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n";
288 }
Barry Mienydd671972010-10-04 16:33:58 +0200289
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 return $r;
291 }
292
Pascal Kriete68d29872011-02-14 13:39:06 -0500293 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200294
Pascal Kriete68d29872011-02-14 13:39:06 -0500295 /**
296 * Executes the Method
297 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500298 * @param object
299 * @return mixed
300 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200301 protected function _execute($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000302 {
303 $methName = $m->method_name;
Barry Mienydd671972010-10-04 16:33:58 +0200304
Derek Allard2067d1a2008-11-13 22:59:24 +0000305 // Check to see if it is a system call
Andrey Andreev3dad2e72012-06-14 15:10:56 +0300306 $system_call = (strpos($methName, 'system') === 0);
Barry Mienydd671972010-10-04 16:33:58 +0200307
Alex Bilbied261b1e2012-06-02 11:12:16 +0100308 if ($this->xss_clean === FALSE)
Robin Sowell66a3fc02010-03-18 09:44:55 -0400309 {
310 $m->xss_clean = FALSE;
311 }
312
Derek Allard2067d1a2008-11-13 22:59:24 +0000313 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500314 // Valid Method
Derek Allard2067d1a2008-11-13 22:59:24 +0000315 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200316
Derek Allard2067d1a2008-11-13 22:59:24 +0000317 if ( ! isset($this->methods[$methName]['function']))
318 {
319 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
320 }
Barry Mienydd671972010-10-04 16:33:58 +0200321
Derek Allard2067d1a2008-11-13 22:59:24 +0000322 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500323 // Check for Method (and Object)
Derek Allard2067d1a2008-11-13 22:59:24 +0000324 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200325
Andrey Andreev52278372012-03-26 16:02:30 +0300326 $method_parts = explode('.', $this->methods[$methName]['function']);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100327 $objectCall = (isset($method_parts[1]) && $method_parts[1] !== '');
Barry Mienydd671972010-10-04 16:33:58 +0200328
Derek Allard2067d1a2008-11-13 22:59:24 +0000329 if ($system_call === TRUE)
330 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200331 if ( ! is_callable(array($this,$method_parts[1])))
Derek Allard2067d1a2008-11-13 22:59:24 +0000332 {
333 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
334 }
335 }
Andrey Andreev52278372012-03-26 16:02:30 +0300336 elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1])))
337 OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function']))
338 )
Derek Allard2067d1a2008-11-13 22:59:24 +0000339 {
Andrey Andreev52278372012-03-26 16:02:30 +0300340 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 }
Barry Mienydd671972010-10-04 16:33:58 +0200342
Derek Allard2067d1a2008-11-13 22:59:24 +0000343 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500344 // Checking Methods Signature
Derek Allard2067d1a2008-11-13 22:59:24 +0000345 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200346
Derek Allard2067d1a2008-11-13 22:59:24 +0000347 if (isset($this->methods[$methName]['signature']))
348 {
349 $sig = $this->methods[$methName]['signature'];
Andrey Andreev56e32142011-12-25 18:36:31 +0200350 for ($i = 0, $c = count($sig); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000351 {
352 $current_sig = $sig[$i];
Barry Mienydd671972010-10-04 16:33:58 +0200353
Andrey Andreev56e32142011-12-25 18:36:31 +0200354 if (count($current_sig) === count($m->params)+1)
Derek Allard2067d1a2008-11-13 22:59:24 +0000355 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200356 for ($n = 0, $mc = count($m->params); $n < $mc; $n++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000357 {
358 $p = $m->params[$n];
Alex Bilbied261b1e2012-06-02 11:12:16 +0100359 $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf();
Barry Mienydd671972010-10-04 16:33:58 +0200360
Alex Bilbied261b1e2012-06-02 11:12:16 +0100361 if ($pt !== $current_sig[$n+1])
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 {
363 $pno = $n+1;
364 $wanted = $current_sig[$n+1];
Barry Mienydd671972010-10-04 16:33:58 +0200365
Derek Allard2067d1a2008-11-13 22:59:24 +0000366 return new XML_RPC_Response(0,
367 $this->xmlrpcerr['incorrect_params'],
368 $this->xmlrpcstr['incorrect_params'] .
Andrey Andreev52278372012-03-26 16:02:30 +0300369 ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')');
Derek Allard2067d1a2008-11-13 22:59:24 +0000370 }
371 }
372 }
373 }
374 }
375
376 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500377 // Calls the Function
Derek Allard2067d1a2008-11-13 22:59:24 +0000378 //-------------------------------------
379
380 if ($objectCall === TRUE)
381 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200382 if ($method_parts[0] === 'this' && $system_call === TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 {
384 return call_user_func(array($this, $method_parts[1]), $m);
385 }
386 else
387 {
388 if ($this->object === FALSE)
389 {
390 $CI =& get_instance();
Andrey Andreev56e32142011-12-25 18:36:31 +0200391 return $CI->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000392 }
393 else
394 {
Andrey Andreev56e32142011-12-25 18:36:31 +0200395 return $this->object->$method_parts[1]($m);
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 //return call_user_func(array(&$method_parts['0'],$method_parts['1']), $m);
397 }
398 }
399 }
400 else
401 {
402 return call_user_func($this->methods[$methName]['function'], $m);
403 }
404 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200405
Pascal Kriete68d29872011-02-14 13:39:06 -0500406 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200407
Pascal Kriete68d29872011-02-14 13:39:06 -0500408 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500409 * Server Function: List Methods
Pascal Kriete68d29872011-02-14 13:39:06 -0500410 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500411 * @param mixed
412 * @return object
413 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200414 public function listMethods($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000415 {
416 $v = new XML_RPC_Values();
417 $output = array();
Barry Mienydd671972010-10-04 16:33:58 +0200418
Pascal Kriete68d29872011-02-14 13:39:06 -0500419 foreach ($this->methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000420 {
421 $output[] = new XML_RPC_Values($key, 'string');
422 }
Barry Mienydd671972010-10-04 16:33:58 +0200423
Pascal Kriete68d29872011-02-14 13:39:06 -0500424 foreach ($this->system_methods as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000425 {
Andrey Andreev52278372012-03-26 16:02:30 +0300426 $output[] = new XML_RPC_Values($key, 'string');
Derek Allard2067d1a2008-11-13 22:59:24 +0000427 }
428
429 $v->addArray($output);
430 return new XML_RPC_Response($v);
431 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200432
Pascal Kriete68d29872011-02-14 13:39:06 -0500433 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200434
Pascal Kriete68d29872011-02-14 13:39:06 -0500435 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500436 * Server Function: Return Signature for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500437 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500438 * @param mixed
439 * @return object
440 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200441 public function methodSignature($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000442 {
443 $parameters = $m->output_parameters();
444 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200445
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 if (isset($this->methods[$method_name]))
447 {
448 if ($this->methods[$method_name]['signature'])
449 {
450 $sigs = array();
451 $signature = $this->methods[$method_name]['signature'];
Barry Mienydd671972010-10-04 16:33:58 +0200452
Andrey Andreev56e32142011-12-25 18:36:31 +0200453 for ($i = 0, $c = count($signature); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
455 $cursig = array();
456 $inSig = $signature[$i];
Andrey Andreev56e32142011-12-25 18:36:31 +0200457 for ($j = 0, $jc = count($inSig); $j < $jc; $j++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000458 {
459 $cursig[]= new XML_RPC_Values($inSig[$j], 'string');
460 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200461 $sigs[] = new XML_RPC_Values($cursig, 'array');
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 }
Andrey Andreev52278372012-03-26 16:02:30 +0300463
464 return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 }
Andrey Andreev52278372012-03-26 16:02:30 +0300466
467 return new XML_RPC_Response(new XML_RPC_Values('undef', 'string'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000468 }
Andrey Andreev52278372012-03-26 16:02:30 +0300469
470 return new XML_RPC_Response(0,$this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
Derek Allard2067d1a2008-11-13 22:59:24 +0000471 }
Barry Mienydd671972010-10-04 16:33:58 +0200472
Pascal Kriete68d29872011-02-14 13:39:06 -0500473 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200474
Pascal Kriete68d29872011-02-14 13:39:06 -0500475 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500476 * Server Function: Doc String for Method
Pascal Kriete68d29872011-02-14 13:39:06 -0500477 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500478 * @param mixed
479 * @return object
480 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200481 public function methodHelp($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000482 {
483 $parameters = $m->output_parameters();
484 $method_name = $parameters[0];
Barry Mienydd671972010-10-04 16:33:58 +0200485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 if (isset($this->methods[$method_name]))
487 {
488 $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : '';
Barry Mienydd671972010-10-04 16:33:58 +0200489
Derek Allard2067d1a2008-11-13 22:59:24 +0000490 return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string'));
491 }
492 else
493 {
494 return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']);
495 }
496 }
Andrey Andreev56e32142011-12-25 18:36:31 +0200497
Pascal Kriete68d29872011-02-14 13:39:06 -0500498 // --------------------------------------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000499
Pascal Kriete68d29872011-02-14 13:39:06 -0500500 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500501 * Server Function: Multi-call
Pascal Kriete68d29872011-02-14 13:39:06 -0500502 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500503 * @param mixed
504 * @return object
505 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200506 public function multicall($m)
Derek Allard2067d1a2008-11-13 22:59:24 +0000507 {
508 // Disabled
509 return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']);
Barry Mienydd671972010-10-04 16:33:58 +0200510
Derek Allard2067d1a2008-11-13 22:59:24 +0000511 $parameters = $m->output_parameters();
512 $calls = $parameters[0];
513
514 $result = array();
515
516 foreach ($calls as $value)
517 {
518 //$attempt = $this->_execute(new XML_RPC_Message($value[0], $value[1]));
Barry Mienydd671972010-10-04 16:33:58 +0200519
Derek Allard2067d1a2008-11-13 22:59:24 +0000520 $m = new XML_RPC_Message($value[0]);
521 $plist='';
Barry Mienydd671972010-10-04 16:33:58 +0200522
Andrey Andreev56e32142011-12-25 18:36:31 +0200523 for ($i = 0, $c = count($value[1]); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000524 {
525 $m->addParam(new XML_RPC_Values($value[1][$i], 'string'));
526 }
Barry Mienydd671972010-10-04 16:33:58 +0200527
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 $attempt = $this->_execute($m);
529
Alex Bilbied261b1e2012-06-02 11:12:16 +0100530 if ($attempt->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000531 {
532 return $attempt;
533 }
534
535 $result[] = new XML_RPC_Values(array($attempt->value()), 'array');
536 }
537
538 return new XML_RPC_Response(new XML_RPC_Values($result, 'array'));
539 }
Barry Mienydd671972010-10-04 16:33:58 +0200540
Pascal Kriete68d29872011-02-14 13:39:06 -0500541 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200542
Pascal Kriete68d29872011-02-14 13:39:06 -0500543 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500544 * Multi-call Function: Error Handling
Pascal Kriete68d29872011-02-14 13:39:06 -0500545 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500546 * @param mixed
547 * @return object
548 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200549 public function multicall_error($err)
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 {
Derek Jones37f4b9c2011-07-01 17:56:50 -0500551 $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString();
Derek Allard2067d1a2008-11-13 22:59:24 +0000552 $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode();
Barry Mienydd671972010-10-04 16:33:58 +0200553
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 $struct['faultCode'] = new XML_RPC_Values($code, 'int');
555 $struct['faultString'] = new XML_RPC_Values($str, 'string');
Barry Mienydd671972010-10-04 16:33:58 +0200556
Derek Allard2067d1a2008-11-13 22:59:24 +0000557 return new XML_RPC_Values($struct, 'struct');
558 }
Barry Mienydd671972010-10-04 16:33:58 +0200559
Pascal Kriete68d29872011-02-14 13:39:06 -0500560 // --------------------------------------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200561
Pascal Kriete68d29872011-02-14 13:39:06 -0500562 /**
Derek Jones37f4b9c2011-07-01 17:56:50 -0500563 * Multi-call Function: Processes method
Pascal Kriete68d29872011-02-14 13:39:06 -0500564 *
Pascal Kriete68d29872011-02-14 13:39:06 -0500565 * @param mixed
566 * @return object
567 */
Andrey Andreev56e32142011-12-25 18:36:31 +0200568 public function do_multicall($call)
Derek Allard2067d1a2008-11-13 22:59:24 +0000569 {
Alex Bilbied261b1e2012-06-02 11:12:16 +0100570 if ($call->kindOf() !== 'struct')
Pascal Kriete68d29872011-02-14 13:39:06 -0500571 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000572 return $this->multicall_error('notstruct');
Pascal Kriete68d29872011-02-14 13:39:06 -0500573 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000574 elseif ( ! $methName = $call->me['struct']['methodName'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500575 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000576 return $this->multicall_error('nomethod');
Pascal Kriete68d29872011-02-14 13:39:06 -0500577 }
Barry Mienydd671972010-10-04 16:33:58 +0200578
Derek Allard2067d1a2008-11-13 22:59:24 +0000579 list($scalar_type,$scalar_value)=each($methName->me);
Alex Bilbied261b1e2012-06-02 11:12:16 +0100580 $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type;
Barry Mienydd671972010-10-04 16:33:58 +0200581
Alex Bilbied261b1e2012-06-02 11:12:16 +0100582 if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string')
Pascal Kriete68d29872011-02-14 13:39:06 -0500583 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000584 return $this->multicall_error('notstring');
Pascal Kriete68d29872011-02-14 13:39:06 -0500585 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100586 elseif ($scalar_value === 'system.multicall')
Pascal Kriete68d29872011-02-14 13:39:06 -0500587 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000588 return $this->multicall_error('recursion');
Pascal Kriete68d29872011-02-14 13:39:06 -0500589 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000590 elseif ( ! $params = $call->me['struct']['params'])
Pascal Kriete68d29872011-02-14 13:39:06 -0500591 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 return $this->multicall_error('noparams');
Pascal Kriete68d29872011-02-14 13:39:06 -0500593 }
Alex Bilbied261b1e2012-06-02 11:12:16 +0100594 elseif ($params->kindOf() !== 'array')
Pascal Kriete68d29872011-02-14 13:39:06 -0500595 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 return $this->multicall_error('notarray');
Pascal Kriete68d29872011-02-14 13:39:06 -0500597 }
Barry Mienydd671972010-10-04 16:33:58 +0200598
Andrey Andreev56e32142011-12-25 18:36:31 +0200599 list($a,$b) = each($params->me);
Derek Allard2067d1a2008-11-13 22:59:24 +0000600
601 $msg = new XML_RPC_Message($scalar_value);
Andrey Andreev56e32142011-12-25 18:36:31 +0200602 for ($i = 0, $numParams = count($b); $i < $numParams; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000603 {
604 $msg->params[] = $params->me['array'][$i];
605 }
606
607 $result = $this->_execute($msg);
608
Alex Bilbied261b1e2012-06-02 11:12:16 +0100609 if ($result->faultCode() !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000610 {
611 return $this->multicall_error($result);
612 }
613
614 return new XML_RPC_Values(array($result->value()), 'array');
Barry Mienydd671972010-10-04 16:33:58 +0200615 }
616
Derek Allard2067d1a2008-11-13 22:59:24 +0000617}
Derek Allard2067d1a2008-11-13 22:59:24 +0000618
Derek Allard2067d1a2008-11-13 22:59:24 +0000619/* End of file Xmlrpcs.php */
Andrey Andreev52278372012-03-26 16:02:30 +0300620/* Location: ./system/libraries/Xmlrpcs.php */