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