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