Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 9 | * Copyright (c) 2014 - 2018, British Columbia Institute of Technology |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | cce6bd1 | 2018-01-09 11:32:02 +0200 | [diff] [blame^] | 32 | * @copyright Copyright (c) 2014 - 2018, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 35 | * @since Version 1.0.0 |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | * @filesource |
| 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
| 40 | if ( ! function_exists('xml_parser_create')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 41 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 42 | show_error('Your PHP installation does not support XML'); |
| 43 | } |
| 44 | |
Andrey Andreev | 49e68de | 2013-02-21 16:30:55 +0200 | [diff] [blame] | 45 | if ( ! class_exists('CI_Xmlrpc', FALSE)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 46 | { |
| 47 | show_error('You must load the Xmlrpc class before loading the Xmlrpcs class in order to create a server.'); |
| 48 | } |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
| 52 | /** |
| 53 | * XML-RPC server class |
| 54 | * |
| 55 | * @package CodeIgniter |
| 56 | * @subpackage Libraries |
| 57 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 58 | * @author EllisLab Dev Team |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 59 | * @link https://codeigniter.com/user_guide/libraries/xmlrpc.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | */ |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 61 | class CI_Xmlrpcs extends CI_Xmlrpc { |
| 62 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 63 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 64 | * Array of methods mapped to function names and signatures |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 65 | * |
| 66 | * @var array |
| 67 | */ |
| 68 | public $methods = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 69 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 70 | /** |
| 71 | * Debug Message |
| 72 | * |
| 73 | * @var string |
| 74 | */ |
| 75 | public $debug_msg = ''; |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 76 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 77 | /** |
| 78 | * XML RPC Server methods |
| 79 | * |
| 80 | * @var array |
| 81 | */ |
| 82 | public $system_methods = array(); |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 83 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 84 | /** |
| 85 | * Configuration object |
| 86 | * |
| 87 | * @var object |
| 88 | */ |
| 89 | public $object = FALSE; |
Derek Jones | c4c34ee | 2010-03-02 23:00:28 -0600 | [diff] [blame] | 90 | |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 91 | /** |
| 92 | * Initialize XMLRPC class |
| 93 | * |
Andrey Andreev | 5645479 | 2012-05-17 14:32:19 +0300 | [diff] [blame] | 94 | * @param array $config |
| 95 | * @return void |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 96 | */ |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 97 | public function __construct($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 98 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 99 | parent::__construct(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 100 | $this->set_system_methods(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 101 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 102 | if (isset($config['functions']) && is_array($config['functions'])) |
| 103 | { |
| 104 | $this->methods = array_merge($this->methods, $config['functions']); |
| 105 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 106 | |
Andrey Andreev | 90726b8 | 2015-01-20 12:39:22 +0200 | [diff] [blame] | 107 | log_message('info', 'XML-RPC Server Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 108 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 109 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 110 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 111 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 112 | /** |
| 113 | * Initialize Prefs and Serve |
| 114 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 115 | * @param mixed |
| 116 | * @return void |
| 117 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 118 | public function initialize($config = array()) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 119 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 120 | if (isset($config['functions']) && is_array($config['functions'])) |
| 121 | { |
| 122 | $this->methods = array_merge($this->methods, $config['functions']); |
| 123 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 124 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 125 | if (isset($config['debug'])) |
| 126 | { |
| 127 | $this->debug = $config['debug']; |
| 128 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 129 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 130 | if (isset($config['object']) && is_object($config['object'])) |
| 131 | { |
| 132 | $this->object = $config['object']; |
| 133 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 134 | |
Robin Sowell | 66a3fc0 | 2010-03-18 09:44:55 -0400 | [diff] [blame] | 135 | if (isset($config['xss_clean'])) |
| 136 | { |
| 137 | $this->xss_clean = $config['xss_clean']; |
| 138 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 139 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 140 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 141 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 142 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 143 | /** |
| 144 | * Setting of System Methods |
| 145 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 146 | * @return void |
| 147 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 148 | public function set_system_methods() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 149 | { |
| 150 | $this->methods = array( |
| 151 | 'system.listMethods' => array( |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 152 | 'function' => 'this.listMethods', |
| 153 | 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString), array($this->xmlrpcArray)), |
| 154 | 'docstring' => 'Returns an array of available methods on this server'), |
| 155 | 'system.methodHelp' => array( |
| 156 | 'function' => 'this.methodHelp', |
| 157 | 'signature' => array(array($this->xmlrpcString, $this->xmlrpcString)), |
| 158 | 'docstring' => 'Returns a documentation string for the specified method'), |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 159 | 'system.methodSignature' => array( |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 160 | 'function' => 'this.methodSignature', |
| 161 | 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcString)), |
| 162 | 'docstring' => 'Returns an array describing the return type and required parameters of a method'), |
| 163 | 'system.multicall' => array( |
| 164 | 'function' => 'this.multicall', |
| 165 | 'signature' => array(array($this->xmlrpcArray, $this->xmlrpcArray)), |
| 166 | 'docstring' => 'Combine multiple RPC calls in one request. See http://www.xmlrpc.com/discuss/msgReader$1208 for details') |
| 167 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 170 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 171 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 172 | /** |
| 173 | * Main Server Function |
| 174 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 175 | * @return void |
| 176 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 177 | public function serve() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 178 | { |
| 179 | $r = $this->parseRequest(); |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 180 | $payload = '<?xml version="1.0" encoding="'.$this->xmlrpc_defencoding.'"?'.'>'."\n".$this->debug_msg.$r->prepare_response(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 181 | |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 182 | header('Content-Type: text/xml'); |
| 183 | header('Content-Length: '.strlen($payload)); |
Derek Jones | b8d3c3d | 2009-06-24 15:27:01 +0000 | [diff] [blame] | 184 | exit($payload); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 187 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 188 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 189 | /** |
| 190 | * Add Method to Class |
| 191 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 192 | * @param string method name |
| 193 | * @param string function |
| 194 | * @param string signature |
| 195 | * @param string docstring |
| 196 | * @return void |
| 197 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 198 | public function add_to_map($methodname, $function, $sig, $doc) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 199 | { |
| 200 | $this->methods[$methodname] = array( |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 201 | 'function' => $function, |
| 202 | 'signature' => $sig, |
| 203 | 'docstring' => $doc |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 204 | ); |
| 205 | } |
| 206 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 207 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 208 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 209 | /** |
| 210 | * Parse Server Request |
| 211 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 212 | * @param string data |
| 213 | * @return object xmlrpc response |
| 214 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 215 | public function parseRequest($data = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 216 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | //------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 218 | // Get Data |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | //------------------------------------- |
| 220 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 221 | if ($data === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 222 | { |
Andrey Andreev | 20e802e | 2014-02-24 12:16:48 +0200 | [diff] [blame] | 223 | $CI =& get_instance(); |
| 224 | if ($CI->input->method() === 'post') |
| 225 | { |
Andrey Andreev | 7abc08a | 2015-03-26 21:10:49 +0200 | [diff] [blame] | 226 | $data = $CI->input->raw_input_stream; |
Andrey Andreev | 20e802e | 2014-02-24 12:16:48 +0200 | [diff] [blame] | 227 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | //------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 231 | // Set up XML Parser |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 233 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | $parser = xml_parser_create($this->xmlrpc_defencoding); |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 235 | $parser_object = new XML_RPC_Message('filler'); |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 236 | $pname = (string) $parser; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 237 | |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 238 | $parser_object->xh[$pname] = array( |
| 239 | 'isf' => 0, |
| 240 | 'isf_reason' => '', |
| 241 | 'params' => array(), |
| 242 | 'stack' => array(), |
| 243 | 'valuestack' => array(), |
| 244 | 'method' => '' |
Andrey Andreev | 20e802e | 2014-02-24 12:16:48 +0200 | [diff] [blame] | 245 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 246 | |
| 247 | xml_set_object($parser, $parser_object); |
Alex Bilbie | afee226 | 2012-07-15 18:59:01 +0100 | [diff] [blame] | 248 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 249 | xml_set_element_handler($parser, 'open_tag', 'closing_tag'); |
| 250 | xml_set_character_data_handler($parser, 'character_data'); |
| 251 | //xml_set_default_handler($parser, 'default_handler'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 252 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 254 | // PARSE + PROCESS XML DATA |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 255 | //------------------------------------- |
| 256 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | if ( ! xml_parse($parser, $data, 1)) |
| 258 | { |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 259 | // Return XML error as a faultCode |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 260 | $r = new XML_RPC_Response(0, |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 261 | $this->xmlrpcerrxml + xml_get_error_code($parser), |
| 262 | sprintf('XML error: %s at line %d', |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | xml_error_string(xml_get_error_code($parser)), |
| 264 | xml_get_current_line_number($parser))); |
| 265 | xml_parser_free($parser); |
| 266 | } |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 267 | elseif ($parser_object->xh[$pname]['isf']) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 268 | { |
| 269 | return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); |
| 270 | } |
| 271 | else |
| 272 | { |
| 273 | xml_parser_free($parser); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 274 | |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 275 | $m = new XML_RPC_Message($parser_object->xh[$pname]['method']); |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 276 | $plist = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 277 | |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 278 | for ($i = 0, $c = count($parser_object->xh[$pname]['params']); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 279 | { |
| 280 | if ($this->debug === TRUE) |
| 281 | { |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 282 | $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$pname]['params'][$i]), TRUE).";\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 283 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 284 | |
Andrey Andreev | 998608e | 2015-03-26 13:01:56 +0200 | [diff] [blame] | 285 | $m->addParam($parser_object->xh[$pname]['params'][$i]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 286 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 287 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | if ($this->debug === TRUE) |
| 289 | { |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 290 | echo "<pre>---PLIST---\n".$plist."\n---PLIST END---\n\n</pre>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 291 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 292 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 293 | $r = $this->_execute($m); |
| 294 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 295 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 296 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 297 | // SET DEBUGGING MESSAGE |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 298 | //------------------------------------- |
| 299 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 300 | if ($this->debug === TRUE) |
| 301 | { |
| 302 | $this->debug_msg = "<!-- DEBUG INFO:\n\n".$plist."\n END DEBUG-->\n"; |
| 303 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 304 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 305 | return $r; |
| 306 | } |
| 307 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 308 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 309 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 310 | /** |
| 311 | * Executes the Method |
| 312 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 313 | * @param object |
| 314 | * @return mixed |
| 315 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 316 | protected function _execute($m) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 317 | { |
| 318 | $methName = $m->method_name; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 319 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | // Check to see if it is a system call |
Andrey Andreev | 3dad2e7 | 2012-06-14 15:10:56 +0300 | [diff] [blame] | 321 | $system_call = (strpos($methName, 'system') === 0); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 322 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 323 | if ($this->xss_clean === FALSE) |
Robin Sowell | 66a3fc0 | 2010-03-18 09:44:55 -0400 | [diff] [blame] | 324 | { |
| 325 | $m->xss_clean = FALSE; |
| 326 | } |
| 327 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 328 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 329 | // Valid Method |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 330 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 331 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | if ( ! isset($this->methods[$methName]['function'])) |
| 333 | { |
| 334 | return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); |
| 335 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 336 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 337 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 338 | // Check for Method (and Object) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 339 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 340 | |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 341 | $method_parts = explode('.', $this->methods[$methName]['function']); |
Andrey Andreev | 14a6c2e | 2016-10-31 10:04:17 +0200 | [diff] [blame] | 342 | $objectCall = ! empty($method_parts[1]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 343 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 344 | if ($system_call === TRUE) |
| 345 | { |
Andrey Andreev | 14a6c2e | 2016-10-31 10:04:17 +0200 | [diff] [blame] | 346 | if ( ! is_callable(array($this, $method_parts[1]))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | { |
| 348 | return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); |
| 349 | } |
| 350 | } |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 351 | elseif (($objectCall && ! is_callable(array($method_parts[0], $method_parts[1]))) |
| 352 | OR ( ! $objectCall && ! is_callable($this->methods[$methName]['function'])) |
| 353 | ) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 354 | { |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 355 | return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 356 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 357 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 358 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 359 | // Checking Methods Signature |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 361 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | if (isset($this->methods[$methName]['signature'])) |
| 363 | { |
| 364 | $sig = $this->methods[$methName]['signature']; |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 365 | for ($i = 0, $c = count($sig); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 366 | { |
| 367 | $current_sig = $sig[$i]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 368 | |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 369 | if (count($current_sig) === count($m->params)+1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 370 | { |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 371 | for ($n = 0, $mc = count($m->params); $n < $mc; $n++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 372 | { |
| 373 | $p = $m->params[$n]; |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 374 | $pt = ($p->kindOf() === 'scalar') ? $p->scalarval() : $p->kindOf(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 375 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 376 | if ($pt !== $current_sig[$n+1]) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | { |
| 378 | $pno = $n+1; |
| 379 | $wanted = $current_sig[$n+1]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 380 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 381 | return new XML_RPC_Response(0, |
| 382 | $this->xmlrpcerr['incorrect_params'], |
| 383 | $this->xmlrpcstr['incorrect_params'] . |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 384 | ': Wanted '.$wanted.', got '.$pt.' at param '.$pno.')'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 385 | } |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | //------------------------------------- |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 392 | // Calls the Function |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 393 | //------------------------------------- |
| 394 | |
| 395 | if ($objectCall === TRUE) |
| 396 | { |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 397 | if ($method_parts[0] === 'this' && $system_call === TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 398 | { |
| 399 | return call_user_func(array($this, $method_parts[1]), $m); |
| 400 | } |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 401 | elseif ($this->object === FALSE) |
| 402 | { |
Andrey Andreev | 14a6c2e | 2016-10-31 10:04:17 +0200 | [diff] [blame] | 403 | return get_instance()->{$method_parts[1]}($m); |
Andrey Andreev | 119d8a7 | 2014-01-08 15:27:53 +0200 | [diff] [blame] | 404 | } |
Andrey Andreev | fbe4d79 | 2017-12-27 19:49:03 +0200 | [diff] [blame] | 405 | |
| 406 | return $this->object->{$method_parts[1]}($m); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 407 | } |
Andrey Andreev | fbe4d79 | 2017-12-27 19:49:03 +0200 | [diff] [blame] | 408 | |
| 409 | return call_user_func($this->methods[$methName]['function'], $m); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 410 | } |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 411 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 412 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 413 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 414 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 415 | * Server Function: List Methods |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 416 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 417 | * @param mixed |
| 418 | * @return object |
| 419 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 420 | public function listMethods($m) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 421 | { |
| 422 | $v = new XML_RPC_Values(); |
| 423 | $output = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 424 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 425 | foreach ($this->methods as $key => $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 426 | { |
| 427 | $output[] = new XML_RPC_Values($key, 'string'); |
| 428 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 429 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 430 | foreach ($this->system_methods as $key => $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 431 | { |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 432 | $output[] = new XML_RPC_Values($key, 'string'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | $v->addArray($output); |
| 436 | return new XML_RPC_Response($v); |
| 437 | } |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 438 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 439 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 440 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 441 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 442 | * Server Function: Return Signature for Method |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 443 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 444 | * @param mixed |
| 445 | * @return object |
| 446 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 447 | public function methodSignature($m) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | { |
| 449 | $parameters = $m->output_parameters(); |
| 450 | $method_name = $parameters[0]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 451 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 452 | if (isset($this->methods[$method_name])) |
| 453 | { |
| 454 | if ($this->methods[$method_name]['signature']) |
| 455 | { |
| 456 | $sigs = array(); |
| 457 | $signature = $this->methods[$method_name]['signature']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 458 | |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 459 | for ($i = 0, $c = count($signature); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 460 | { |
| 461 | $cursig = array(); |
| 462 | $inSig = $signature[$i]; |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 463 | for ($j = 0, $jc = count($inSig); $j < $jc; $j++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 464 | { |
| 465 | $cursig[]= new XML_RPC_Values($inSig[$j], 'string'); |
| 466 | } |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 467 | $sigs[] = new XML_RPC_Values($cursig, 'array'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | } |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 469 | |
| 470 | return new XML_RPC_Response(new XML_RPC_Values($sigs, 'array')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 471 | } |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 472 | |
| 473 | return new XML_RPC_Response(new XML_RPC_Values('undef', 'string')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | } |
Andrey Andreev | 5227837 | 2012-03-26 16:02:30 +0300 | [diff] [blame] | 475 | |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 476 | return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 478 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 479 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 480 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 481 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 482 | * Server Function: Doc String for Method |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 483 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 484 | * @param mixed |
| 485 | * @return object |
| 486 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 487 | public function methodHelp($m) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | { |
| 489 | $parameters = $m->output_parameters(); |
| 490 | $method_name = $parameters[0]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 491 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | if (isset($this->methods[$method_name])) |
| 493 | { |
| 494 | $docstring = isset($this->methods[$method_name]['docstring']) ? $this->methods[$method_name]['docstring'] : ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 495 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 496 | return new XML_RPC_Response(new XML_RPC_Values($docstring, 'string')); |
| 497 | } |
Andrey Andreev | fbe4d79 | 2017-12-27 19:49:03 +0200 | [diff] [blame] | 498 | |
| 499 | return new XML_RPC_Response(0, $this->xmlrpcerr['introspect_unknown'], $this->xmlrpcstr['introspect_unknown']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 500 | } |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 501 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 502 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 503 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 504 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 505 | * Server Function: Multi-call |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 506 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 507 | * @param mixed |
| 508 | * @return object |
| 509 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 510 | public function multicall($m) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | { |
| 512 | // Disabled |
| 513 | return new XML_RPC_Response(0, $this->xmlrpcerr['unknown_method'], $this->xmlrpcstr['unknown_method']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 514 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | $parameters = $m->output_parameters(); |
| 516 | $calls = $parameters[0]; |
| 517 | |
| 518 | $result = array(); |
| 519 | |
| 520 | foreach ($calls as $value) |
| 521 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 522 | $m = new XML_RPC_Message($value[0]); |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 523 | $plist = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 524 | |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 525 | for ($i = 0, $c = count($value[1]); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 526 | { |
| 527 | $m->addParam(new XML_RPC_Values($value[1][$i], 'string')); |
| 528 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 529 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 530 | $attempt = $this->_execute($m); |
| 531 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 532 | if ($attempt->faultCode() !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 533 | { |
| 534 | return $attempt; |
| 535 | } |
| 536 | |
| 537 | $result[] = new XML_RPC_Values(array($attempt->value()), 'array'); |
| 538 | } |
| 539 | |
| 540 | return new XML_RPC_Response(new XML_RPC_Values($result, 'array')); |
| 541 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 542 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 543 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 544 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 545 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 546 | * Multi-call Function: Error Handling |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 547 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 548 | * @param mixed |
| 549 | * @return object |
| 550 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 551 | public function multicall_error($err) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 552 | { |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 553 | $str = is_string($err) ? $this->xmlrpcstr["multicall_${err}"] : $err->faultString(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 554 | $code = is_string($err) ? $this->xmlrpcerr["multicall_${err}"] : $err->faultCode(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 555 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 556 | $struct['faultCode'] = new XML_RPC_Values($code, 'int'); |
| 557 | $struct['faultString'] = new XML_RPC_Values($str, 'string'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 558 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 559 | return new XML_RPC_Values($struct, 'struct'); |
| 560 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 561 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 562 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 563 | |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 564 | /** |
vkeranov | 52de379 | 2012-11-23 23:48:35 +0200 | [diff] [blame] | 565 | * Multi-call Function: Processes method |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 566 | * |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 567 | * @param mixed |
| 568 | * @return object |
| 569 | */ |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 570 | public function do_multicall($call) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 571 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 572 | if ($call->kindOf() !== 'struct') |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 573 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | return $this->multicall_error('notstruct'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 575 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 576 | elseif ( ! $methName = $call->me['struct']['methodName']) |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 577 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 578 | return $this->multicall_error('nomethod'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 579 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 580 | |
Andrey Andreev | 4316a15 | 2017-01-20 15:46:17 +0200 | [diff] [blame] | 581 | list($scalar_value, $scalar_type) = array(reset($methName->me), key($methName->me)); |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 582 | $scalar_type = $scalar_type === $this->xmlrpcI4 ? $this->xmlrpcInt : $scalar_type; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 583 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 584 | if ($methName->kindOf() !== 'scalar' OR $scalar_type !== 'string') |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 585 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 586 | return $this->multicall_error('notstring'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 587 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 588 | elseif ($scalar_value === 'system.multicall') |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 589 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 590 | return $this->multicall_error('recursion'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 591 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 592 | elseif ( ! $params = $call->me['struct']['params']) |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 593 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 594 | return $this->multicall_error('noparams'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 595 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 596 | elseif ($params->kindOf() !== 'array') |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 597 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | return $this->multicall_error('notarray'); |
Pascal Kriete | 68d2987 | 2011-02-14 13:39:06 -0500 | [diff] [blame] | 599 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 600 | |
Andrey Andreev | 4316a15 | 2017-01-20 15:46:17 +0200 | [diff] [blame] | 601 | list($b, $a) = array(reset($params->me), key($params->me)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 602 | |
| 603 | $msg = new XML_RPC_Message($scalar_value); |
Andrey Andreev | 56e3214 | 2011-12-25 18:36:31 +0200 | [diff] [blame] | 604 | for ($i = 0, $numParams = count($b); $i < $numParams; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 605 | { |
| 606 | $msg->params[] = $params->me['array'][$i]; |
| 607 | } |
| 608 | |
| 609 | $result = $this->_execute($msg); |
| 610 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 611 | if ($result->faultCode() !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 612 | { |
| 613 | return $this->multicall_error($result); |
| 614 | } |
| 615 | |
| 616 | return new XML_RPC_Values(array($result->value()), 'array'); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 617 | } |
| 618 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 619 | } |