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