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