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