blob: 2804e6685fa693c0dea366ef859c458311b3e1f6 [file] [log] [blame]
Andrey Andreeva30faf92011-12-25 18:15:34 +02001<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Greg Aker741de1c2010-11-10 14:52:57 -06005 * An open source application development framework for PHP 5.1.6 or newer
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05007 * NOTICE OF LICENSE
Andrey Andreeva30faf92011-12-25 18:15:34 +02008 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -05009 * Licensed under the Open Software License version 3.0
Andrey Andreeva30faf92011-12-25 18:15:34 +020010 *
Derek Jonesf4a4bd82011-10-20 12:18:42 -050011 * 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 Allard2067d1a2008-11-13 22:59:24 +000019 * @package CodeIgniter
Derek Jonesf4a4bd82011-10-20 12:18:42 -050020 * @author EllisLab Dev Team
21 * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/)
22 * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
Derek Allard2067d1a2008-11-13 22:59:24 +000023 * @link http://codeigniter.com
24 * @since Version 1.0
25 * @filesource
26 */
27
28if ( ! function_exists('xml_parser_create'))
Barry Mienydd671972010-10-04 16:33:58 +020029{
Derek Allard2067d1a2008-11-13 22:59:24 +000030 show_error('Your PHP installation does not support XML');
31}
32
33
34// ------------------------------------------------------------------------
35
36/**
37 * XML-RPC request handler class
38 *
39 * @package CodeIgniter
40 * @subpackage Libraries
41 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -050042 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000043 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
44 */
45class CI_Xmlrpc {
46
Andrey Andreeva30faf92011-12-25 18:15:34 +020047 public $debug = FALSE; // Debugging on or off
48 public $xmlrpcI4 = 'i4';
49 public $xmlrpcInt = 'int';
50 public $xmlrpcBoolean = 'boolean';
51 public $xmlrpcDouble = 'double';
52 public $xmlrpcString = 'string';
53 public $xmlrpcDateTime = 'dateTime.iso8601';
54 public $xmlrpcBase64 = 'base64';
55 public $xmlrpcArray = 'array';
56 public $xmlrpcStruct = 'struct';
Barry Mienydd671972010-10-04 16:33:58 +020057
Andrey Andreeva30faf92011-12-25 18:15:34 +020058 public $xmlrpcTypes = array();
59 public $valid_parents = array();
60 public $xmlrpcerr = array(); // Response numbers
61 public $xmlrpcstr = array(); // Response strings
Barry Mienydd671972010-10-04 16:33:58 +020062
Andrey Andreeva30faf92011-12-25 18:15:34 +020063 public $xmlrpc_defencoding = 'UTF-8';
64 public $xmlrpcName = 'XML-RPC for CodeIgniter';
65 public $xmlrpcVersion = '1.1';
66 public $xmlrpcerruser = 800; // Start of user errors
67 public $xmlrpcerrxml = 100; // Start of XML Parse errors
68 public $xmlrpc_backslash = ''; // formulate backslashes for escaping regexp
Barry Mienydd671972010-10-04 16:33:58 +020069
Andrey Andreeva30faf92011-12-25 18:15:34 +020070 public $client;
71 public $method;
72 public $data;
73 public $message = '';
74 public $error = ''; // Error string for request
75 public $result;
76 public $response = array(); // Response from remote server
Derek Allard2067d1a2008-11-13 22:59:24 +000077
Andrey Andreeva30faf92011-12-25 18:15:34 +020078 public $xss_clean = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +000079
80 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -050081 // VALUES THAT MULTIPLE CLASSES NEED
Derek Allard2067d1a2008-11-13 22:59:24 +000082 //-------------------------------------
83
Greg Akera9263282010-11-10 15:26:43 -060084 public function __construct($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000085 {
Andrey Andreeva30faf92011-12-25 18:15:34 +020086 $this->xmlrpcName = $this->xmlrpcName;
Derek Allard2067d1a2008-11-13 22:59:24 +000087 $this->xmlrpc_backslash = chr(92).chr(92);
Barry Mienydd671972010-10-04 16:33:58 +020088
Derek Allard2067d1a2008-11-13 22:59:24 +000089 // Types for info sent back and forth
90 $this->xmlrpcTypes = array(
Barry Mienydd671972010-10-04 16:33:58 +020091 $this->xmlrpcI4 => '1',
92 $this->xmlrpcInt => '1',
93 $this->xmlrpcBoolean => '1',
94 $this->xmlrpcString => '1',
95 $this->xmlrpcDouble => '1',
96 $this->xmlrpcDateTime => '1',
97 $this->xmlrpcBase64 => '1',
98 $this->xmlrpcArray => '2',
99 $this->xmlrpcStruct => '3'
Derek Allard2067d1a2008-11-13 22:59:24 +0000100 );
Barry Mienydd671972010-10-04 16:33:58 +0200101
Derek Allard2067d1a2008-11-13 22:59:24 +0000102 // Array of Valid Parents for Various XML-RPC elements
103 $this->valid_parents = array('BOOLEAN' => array('VALUE'),
Andrey Andreeva30faf92011-12-25 18:15:34 +0200104 'I4' => array('VALUE'),
105 'INT' => array('VALUE'),
106 'STRING' => array('VALUE'),
107 'DOUBLE' => array('VALUE'),
108 'DATETIME.ISO8601' => array('VALUE'),
109 'BASE64' => array('VALUE'),
110 'ARRAY' => array('VALUE'),
111 'STRUCT' => array('VALUE'),
112 'PARAM' => array('PARAMS'),
113 'METHODNAME' => array('METHODCALL'),
114 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
115 'MEMBER' => array('STRUCT'),
116 'NAME' => array('MEMBER'),
117 'DATA' => array('ARRAY'),
118 'FAULT' => array('METHODRESPONSE'),
119 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT')
120 );
Barry Mienydd671972010-10-04 16:33:58 +0200121
122
Derek Allard2067d1a2008-11-13 22:59:24 +0000123 // XML-RPC Responses
124 $this->xmlrpcerr['unknown_method'] = '1';
125 $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server';
126 $this->xmlrpcerr['invalid_return'] = '2';
Derek Jones37f4b9c2011-07-01 17:56:50 -0500127 $this->xmlrpcstr['invalid_return'] = 'The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.';
Derek Allard2067d1a2008-11-13 22:59:24 +0000128 $this->xmlrpcerr['incorrect_params'] = '3';
129 $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method';
130 $this->xmlrpcerr['introspect_unknown'] = '4';
Andrey Andreeva30faf92011-12-25 18:15:34 +0200131 $this->xmlrpcstr['introspect_unknown'] = 'Cannot inspect signature for request: method unknown';
Derek Allard2067d1a2008-11-13 22:59:24 +0000132 $this->xmlrpcerr['http_error'] = '5';
133 $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server.";
134 $this->xmlrpcerr['no_data'] = '6';
135 $this->xmlrpcstr['no_data'] ='No data received from server.';
Barry Mienydd671972010-10-04 16:33:58 +0200136
Derek Allard2067d1a2008-11-13 22:59:24 +0000137 $this->initialize($config);
Barry Mienydd671972010-10-04 16:33:58 +0200138
Derek Allard2067d1a2008-11-13 22:59:24 +0000139 log_message('debug', "XML-RPC Class Initialized");
140 }
Barry Mienydd671972010-10-04 16:33:58 +0200141
142
Derek Allard2067d1a2008-11-13 22:59:24 +0000143 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500144 // Initialize Prefs
Derek Allard2067d1a2008-11-13 22:59:24 +0000145 //-------------------------------------
146
Andrey Andreeva30faf92011-12-25 18:15:34 +0200147 public function initialize($config = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000148 {
Derek Jones33559102009-02-02 18:50:38 +0000149 if (count($config) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000150 {
151 foreach ($config as $key => $val)
152 {
153 if (isset($this->$key))
154 {
Barry Mienydd671972010-10-04 16:33:58 +0200155 $this->$key = $val;
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 }
157 }
158 }
159 }
160 // END
Barry Mienydd671972010-10-04 16:33:58 +0200161
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500163 // Take URL and parse it
Derek Allard2067d1a2008-11-13 22:59:24 +0000164 //-------------------------------------
165
Andrey Andreeva30faf92011-12-25 18:15:34 +0200166 public function server($url, $port=80)
Derek Allard2067d1a2008-11-13 22:59:24 +0000167 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200168 if (strpos($url, 'http') !== 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000169 {
170 $url = "http://".$url;
171 }
Barry Mienydd671972010-10-04 16:33:58 +0200172
Derek Allard2067d1a2008-11-13 22:59:24 +0000173 $parts = parse_url($url);
Barry Mienydd671972010-10-04 16:33:58 +0200174
Derek Allard2067d1a2008-11-13 22:59:24 +0000175 $path = ( ! isset($parts['path'])) ? '/' : $parts['path'];
Barry Mienydd671972010-10-04 16:33:58 +0200176
Derek Allard2067d1a2008-11-13 22:59:24 +0000177 if (isset($parts['query']) && $parts['query'] != '')
178 {
179 $path .= '?'.$parts['query'];
Barry Mienydd671972010-10-04 16:33:58 +0200180 }
181
Derek Allard2067d1a2008-11-13 22:59:24 +0000182 $this->client = new XML_RPC_Client($path, $parts['host'], $port);
183 }
184 // END
Barry Mienydd671972010-10-04 16:33:58 +0200185
Derek Allard2067d1a2008-11-13 22:59:24 +0000186 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500187 // Set Timeout
Derek Allard2067d1a2008-11-13 22:59:24 +0000188 //-------------------------------------
189
Andrey Andreeva30faf92011-12-25 18:15:34 +0200190 public function timeout($seconds = 5)
Derek Allard2067d1a2008-11-13 22:59:24 +0000191 {
192 if ( ! is_null($this->client) && is_int($seconds))
193 {
194 $this->client->timeout = $seconds;
195 }
196 }
197 // END
Barry Mienydd671972010-10-04 16:33:58 +0200198
Derek Allard2067d1a2008-11-13 22:59:24 +0000199 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500200 // Set Methods
Derek Allard2067d1a2008-11-13 22:59:24 +0000201 //-------------------------------------
202
Andrey Andreeva30faf92011-12-25 18:15:34 +0200203 public function method($function)
Derek Allard2067d1a2008-11-13 22:59:24 +0000204 {
205 $this->method = $function;
206 }
207 // END
Barry Mienydd671972010-10-04 16:33:58 +0200208
Derek Allard2067d1a2008-11-13 22:59:24 +0000209 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500210 // Take Array of Data and Create Objects
Derek Allard2067d1a2008-11-13 22:59:24 +0000211 //-------------------------------------
212
Andrey Andreeva30faf92011-12-25 18:15:34 +0200213 public function request($incoming)
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 {
215 if ( ! is_array($incoming))
216 {
217 // Send Error
218 }
Barry Mienydd671972010-10-04 16:33:58 +0200219
Derek Allard2067d1a2008-11-13 22:59:24 +0000220 $this->data = array();
Barry Mienydd671972010-10-04 16:33:58 +0200221
Pascal Kriete14287f32011-02-14 13:39:34 -0500222 foreach ($incoming as $key => $value)
Derek Allard2067d1a2008-11-13 22:59:24 +0000223 {
224 $this->data[$key] = $this->values_parsing($value);
225 }
226 }
227 // END
Barry Mienydd671972010-10-04 16:33:58 +0200228
229
Derek Allard2067d1a2008-11-13 22:59:24 +0000230 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500231 // Set Debug
Derek Allard2067d1a2008-11-13 22:59:24 +0000232 //-------------------------------------
233
Andrey Andreeva30faf92011-12-25 18:15:34 +0200234 public function set_debug($flag = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000235 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200236 $this->debug = ($flag == TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000237 }
Barry Mienydd671972010-10-04 16:33:58 +0200238
Derek Allard2067d1a2008-11-13 22:59:24 +0000239 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500240 // Values Parsing
Derek Allard2067d1a2008-11-13 22:59:24 +0000241 //-------------------------------------
242
Andrey Andreeva30faf92011-12-25 18:15:34 +0200243 public function values_parsing($value, $return = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000244 {
Derek Jones8c4b5e72010-01-06 22:21:41 +0000245 if (is_array($value) && array_key_exists(0, $value))
Derek Allard2067d1a2008-11-13 22:59:24 +0000246 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200247 if ( ! isset($value[1]) OR ( ! isset($this->xmlrpcTypes[$value[1]])))
Derek Allard2067d1a2008-11-13 22:59:24 +0000248 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200249 $temp = new XML_RPC_Values($value[0], (is_array($value[0]) ? 'array' : 'string'));
Derek Allard2067d1a2008-11-13 22:59:24 +0000250 }
251 else
252 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200253 if (is_array($value[0]) && ($value[1] == 'struct' OR $value[1] == 'array'))
254 {
255 while (list($k) = each($value[0]))
256 {
257 $value[0][$k] = $this->values_parsing($value[0][$k], TRUE);
258 }
259 }
260
261 $temp = new XML_RPC_Values($value[0], $value[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 }
263 }
264 else
265 {
266 $temp = new XML_RPC_Values($value, 'string');
267 }
268
269 return $temp;
270 }
271 // END
272
273
274 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500275 // Sends XML-RPC Request
Derek Allard2067d1a2008-11-13 22:59:24 +0000276 //-------------------------------------
277
Andrey Andreeva30faf92011-12-25 18:15:34 +0200278 public function send_request()
Derek Allard2067d1a2008-11-13 22:59:24 +0000279 {
280 $this->message = new XML_RPC_Message($this->method,$this->data);
281 $this->message->debug = $this->debug;
Barry Mienydd671972010-10-04 16:33:58 +0200282
Andrey Andreeva30faf92011-12-25 18:15:34 +0200283 if ( ! $this->result = $this->client->send($this->message) OR ! is_object($this->result->val))
Derek Allard2067d1a2008-11-13 22:59:24 +0000284 {
285 $this->error = $this->result->errstr;
286 return FALSE;
287 }
Barry Mienydd671972010-10-04 16:33:58 +0200288
Derek Allard2067d1a2008-11-13 22:59:24 +0000289 $this->response = $this->result->decode();
Derek Allard2067d1a2008-11-13 22:59:24 +0000290 return TRUE;
291 }
292 // END
Barry Mienydd671972010-10-04 16:33:58 +0200293
Derek Allard2067d1a2008-11-13 22:59:24 +0000294 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500295 // Returns Error
Derek Allard2067d1a2008-11-13 22:59:24 +0000296 //-------------------------------------
297
Andrey Andreeva30faf92011-12-25 18:15:34 +0200298 public function display_error()
Derek Allard2067d1a2008-11-13 22:59:24 +0000299 {
300 return $this->error;
301 }
302 // END
Barry Mienydd671972010-10-04 16:33:58 +0200303
Derek Allard2067d1a2008-11-13 22:59:24 +0000304 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500305 // Returns Remote Server Response
Derek Allard2067d1a2008-11-13 22:59:24 +0000306 //-------------------------------------
307
Andrey Andreeva30faf92011-12-25 18:15:34 +0200308 public function display_response()
Derek Allard2067d1a2008-11-13 22:59:24 +0000309 {
310 return $this->response;
311 }
312 // END
Barry Mienydd671972010-10-04 16:33:58 +0200313
Derek Allard2067d1a2008-11-13 22:59:24 +0000314 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500315 // Sends an Error Message for Server Request
Derek Allard2067d1a2008-11-13 22:59:24 +0000316 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200317
Andrey Andreeva30faf92011-12-25 18:15:34 +0200318 public function send_error_message($number, $message)
Derek Allard2067d1a2008-11-13 22:59:24 +0000319 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200320 return new XML_RPC_Response(0, $number, $message);
Derek Allard2067d1a2008-11-13 22:59:24 +0000321 }
322 // END
Barry Mienydd671972010-10-04 16:33:58 +0200323
324
Derek Allard2067d1a2008-11-13 22:59:24 +0000325 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500326 // Send Response for Server Request
Derek Allard2067d1a2008-11-13 22:59:24 +0000327 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200328
Andrey Andreeva30faf92011-12-25 18:15:34 +0200329 public function send_response($response)
Derek Allard2067d1a2008-11-13 22:59:24 +0000330 {
331 // $response should be array of values, which will be parsed
332 // based on their data and type into a valid group of XML-RPC values
Andrey Andreeva30faf92011-12-25 18:15:34 +0200333 return new XML_RPC_Response($this->values_parsing($response));
Derek Allard2067d1a2008-11-13 22:59:24 +0000334 }
335 // END
Barry Mienydd671972010-10-04 16:33:58 +0200336
Derek Allard2067d1a2008-11-13 22:59:24 +0000337} // END XML_RPC Class
338
Barry Mienydd671972010-10-04 16:33:58 +0200339
340
Derek Allard2067d1a2008-11-13 22:59:24 +0000341/**
342 * XML-RPC Client class
343 *
344 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -0500345 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +0000346 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
347 */
348class XML_RPC_Client extends CI_Xmlrpc
349{
Andrey Andreeva30faf92011-12-25 18:15:34 +0200350 public $path = '';
351 public $server = '';
352 public $port = 80;
353 public $errno = '';
354 public $errstring = '';
355 public $timeout = 5;
356 public $no_multicall = FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000357
Greg Akera9263282010-11-10 15:26:43 -0600358 public function __construct($path, $server, $port=80)
Derek Allard2067d1a2008-11-13 22:59:24 +0000359 {
Greg Akera9263282010-11-10 15:26:43 -0600360 parent::__construct();
Barry Mienydd671972010-10-04 16:33:58 +0200361
Derek Allard2067d1a2008-11-13 22:59:24 +0000362 $this->port = $port;
363 $this->server = $server;
364 $this->path = $path;
365 }
Barry Mienydd671972010-10-04 16:33:58 +0200366
Andrey Andreeva30faf92011-12-25 18:15:34 +0200367 public function send($msg)
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
369 if (is_array($msg))
370 {
371 // Multi-call disabled
372 $r = new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'],$this->xmlrpcstr['multicall_recursion']);
373 return $r;
374 }
375
376 return $this->sendPayload($msg);
377 }
378
Andrey Andreeva30faf92011-12-25 18:15:34 +0200379 public function sendPayload($msg)
Barry Mienydd671972010-10-04 16:33:58 +0200380 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000381 $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout);
Barry Mienydd671972010-10-04 16:33:58 +0200382
Derek Allard2067d1a2008-11-13 22:59:24 +0000383 if ( ! is_resource($fp))
384 {
385 error_log($this->xmlrpcstr['http_error']);
386 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'],$this->xmlrpcstr['http_error']);
387 return $r;
388 }
Barry Mienydd671972010-10-04 16:33:58 +0200389
Pascal Kriete14287f32011-02-14 13:39:34 -0500390 if (empty($msg->payload))
Derek Allard2067d1a2008-11-13 22:59:24 +0000391 {
392 // $msg = XML_RPC_Messages
393 $msg->createPayload();
394 }
Barry Mienydd671972010-10-04 16:33:58 +0200395
Derek Allard2067d1a2008-11-13 22:59:24 +0000396 $r = "\r\n";
Andrey Andreeva30faf92011-12-25 18:15:34 +0200397 $op = "POST {$this->path} HTTP/1.0$r"
398 . "Host: {$this->server}$r"
399 . "Content-Type: text/xml$r"
400 . "User-Agent: {$this->xmlrpcName}$r"
401 . "Content-Length: ".strlen($msg->payload)."$r$r"
402 . $msg->payload;
Barry Mienydd671972010-10-04 16:33:58 +0200403
Derek Allard2067d1a2008-11-13 22:59:24 +0000404
405 if ( ! fputs($fp, $op, strlen($op)))
406 {
407 error_log($this->xmlrpcstr['http_error']);
408 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']);
409 return $r;
410 }
411 $resp = $msg->parseResponse($fp);
412 fclose($fp);
413 return $resp;
414 }
415
Andrey Andreeva30faf92011-12-25 18:15:34 +0200416}
417// end class XML_RPC_Client
Derek Allard2067d1a2008-11-13 22:59:24 +0000418
419/**
420 * XML-RPC Response class
421 *
422 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -0500423 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +0000424 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
425 */
426class XML_RPC_Response
427{
Andrey Andreeva30faf92011-12-25 18:15:34 +0200428 public $val = 0;
429 public $errno = 0;
430 public $errstr = '';
431 public $headers = array();
432 public $xss_clean = TRUE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000433
Greg Akera9263282010-11-10 15:26:43 -0600434 public function __construct($val, $code = 0, $fstr = '')
Barry Mienydd671972010-10-04 16:33:58 +0200435 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000436 if ($code != 0)
437 {
438 // error
439 $this->errno = $code;
440 $this->errstr = htmlentities($fstr);
441 }
442 else if ( ! is_object($val))
443 {
444 // programmer error, not an object
Derek Jones37f4b9c2011-07-01 17:56:50 -0500445 error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value.");
Derek Allard2067d1a2008-11-13 22:59:24 +0000446 $this->val = new XML_RPC_Values();
447 }
448 else
449 {
450 $this->val = $val;
451 }
452 }
453
Andrey Andreeva30faf92011-12-25 18:15:34 +0200454 public function faultCode()
Derek Allard2067d1a2008-11-13 22:59:24 +0000455 {
456 return $this->errno;
457 }
458
Andrey Andreeva30faf92011-12-25 18:15:34 +0200459 public function faultString()
Derek Allard2067d1a2008-11-13 22:59:24 +0000460 {
461 return $this->errstr;
462 }
463
Andrey Andreeva30faf92011-12-25 18:15:34 +0200464 public function value()
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 {
466 return $this->val;
467 }
Barry Mienydd671972010-10-04 16:33:58 +0200468
Andrey Andreeva30faf92011-12-25 18:15:34 +0200469 public function prepare_response()
Derek Allard2067d1a2008-11-13 22:59:24 +0000470 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200471 return "<methodResponse>\n"
472 . ($this->errno
473 ? '<fault>
Derek Allard2067d1a2008-11-13 22:59:24 +0000474 <value>
475 <struct>
476 <member>
477 <name>faultCode</name>
478 <value><int>' . $this->errno . '</int></value>
479 </member>
480 <member>
481 <name>faultString</name>
482 <value><string>' . $this->errstr . '</string></value>
483 </member>
484 </struct>
485 </value>
Andrey Andreeva30faf92011-12-25 18:15:34 +0200486</fault>'
487 : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>")
488 . "\n</methodResponse>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000489 }
Barry Mienydd671972010-10-04 16:33:58 +0200490
Andrey Andreeva30faf92011-12-25 18:15:34 +0200491 public function decode($array = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000492 {
493 $CI =& get_instance();
Andrey Andreeva30faf92011-12-25 18:15:34 +0200494
495 if (is_array($array))
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 {
497 while (list($key) = each($array))
498 {
499 if (is_array($array[$key]))
500 {
501 $array[$key] = $this->decode($array[$key]);
502 }
503 else
504 {
Robin Sowell66a3fc02010-03-18 09:44:55 -0400505 $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000506 }
507 }
Barry Mienydd671972010-10-04 16:33:58 +0200508
Derek Allard2067d1a2008-11-13 22:59:24 +0000509 $result = $array;
510 }
511 else
512 {
513 $result = $this->xmlrpc_decoder($this->val);
Barry Mienydd671972010-10-04 16:33:58 +0200514
Derek Allard2067d1a2008-11-13 22:59:24 +0000515 if (is_array($result))
516 {
517 $result = $this->decode($result);
518 }
519 else
520 {
Robin Sowell66a3fc02010-03-18 09:44:55 -0400521 $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 }
523 }
Barry Mienydd671972010-10-04 16:33:58 +0200524
Derek Allard2067d1a2008-11-13 22:59:24 +0000525 return $result;
526 }
527
Barry Mienydd671972010-10-04 16:33:58 +0200528
529
Derek Allard2067d1a2008-11-13 22:59:24 +0000530 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500531 // XML-RPC Object to PHP Types
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 //-------------------------------------
533
Andrey Andreeva30faf92011-12-25 18:15:34 +0200534 public function xmlrpc_decoder($xmlrpc_val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000535 {
536 $kind = $xmlrpc_val->kindOf();
537
Pascal Kriete14287f32011-02-14 13:39:34 -0500538 if ($kind == 'scalar')
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 {
540 return $xmlrpc_val->scalarval();
541 }
Pascal Kriete14287f32011-02-14 13:39:34 -0500542 elseif ($kind == 'array')
Derek Allard2067d1a2008-11-13 22:59:24 +0000543 {
544 reset($xmlrpc_val->me);
Andrey Andreev62090152011-12-30 12:49:27 +0200545 list(, $b) = each($xmlrpc_val->me);
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 $arr = array();
547
Andrey Andreeva30faf92011-12-25 18:15:34 +0200548 for ($i = 0, $size = count($b); $i < $size; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000549 {
550 $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]);
551 }
552 return $arr;
553 }
Pascal Kriete14287f32011-02-14 13:39:34 -0500554 elseif ($kind == 'struct')
Derek Allard2067d1a2008-11-13 22:59:24 +0000555 {
556 reset($xmlrpc_val->me['struct']);
557 $arr = array();
558
Pascal Kriete14287f32011-02-14 13:39:34 -0500559 while (list($key,$value) = each($xmlrpc_val->me['struct']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000560 {
561 $arr[$key] = $this->xmlrpc_decoder($value);
562 }
563 return $arr;
564 }
565 }
Barry Mienydd671972010-10-04 16:33:58 +0200566
567
Derek Allard2067d1a2008-11-13 22:59:24 +0000568 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500569 // ISO-8601 time to server or UTC time
Derek Allard2067d1a2008-11-13 22:59:24 +0000570 //-------------------------------------
571
Andrey Andreeva30faf92011-12-25 18:15:34 +0200572 public function iso8601_decode($time, $utc = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000573 {
574 // return a timet in the localtime, or UTC
575 $t = 0;
576 if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs))
577 {
Pascal Kriete14287f32011-02-14 13:39:34 -0500578 $fnc = ($utc == 1) ? 'gmmktime' : 'mktime';
579 $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 }
581 return $t;
582 }
Barry Mienydd671972010-10-04 16:33:58 +0200583
Andrey Andreeva30faf92011-12-25 18:15:34 +0200584}
585// End Response Class
Derek Allard2067d1a2008-11-13 22:59:24 +0000586
587/**
588 * XML-RPC Message class
589 *
590 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -0500591 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +0000592 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
593 */
594class XML_RPC_Message extends CI_Xmlrpc
595{
Andrey Andreeva30faf92011-12-25 18:15:34 +0200596 public $payload;
597 public $method_name;
598 public $params = array();
599 public $xh = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000600
Greg Akera9263282010-11-10 15:26:43 -0600601 public function __construct($method, $pars=0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000602 {
Greg Akera9263282010-11-10 15:26:43 -0600603 parent::__construct();
Barry Mienydd671972010-10-04 16:33:58 +0200604
Derek Allard2067d1a2008-11-13 22:59:24 +0000605 $this->method_name = $method;
Derek Jones33559102009-02-02 18:50:38 +0000606 if (is_array($pars) && count($pars) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000607 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200608 for ($i = 0, $c = count($pars); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 {
610 // $pars[$i] = XML_RPC_Values
611 $this->params[] = $pars[$i];
612 }
613 }
614 }
Barry Mienydd671972010-10-04 16:33:58 +0200615
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500617 // Create Payload to Send
Derek Allard2067d1a2008-11-13 22:59:24 +0000618 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200619
Andrey Andreeva30faf92011-12-25 18:15:34 +0200620 public function createPayload()
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200622 $this->payload = "<?xml version=\"1.0\"?".">\r\n<methodCall>\r\n"
623 . '<methodName>'.$this->method_name."</methodName>\r\n"
624 . "<params>\r\n";
Barry Mienydd671972010-10-04 16:33:58 +0200625
Andrey Andreeva30faf92011-12-25 18:15:34 +0200626 for ($i = 0, $c = count($this->params); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 {
628 // $p = XML_RPC_Values
629 $p = $this->params[$i];
630 $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n";
631 }
Barry Mienydd671972010-10-04 16:33:58 +0200632
Derek Allard2067d1a2008-11-13 22:59:24 +0000633 $this->payload .= "</params>\r\n</methodCall>\r\n";
634 }
Barry Mienydd671972010-10-04 16:33:58 +0200635
Derek Allard2067d1a2008-11-13 22:59:24 +0000636 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500637 // Parse External XML-RPC Server's Response
Derek Allard2067d1a2008-11-13 22:59:24 +0000638 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200639
Andrey Andreeva30faf92011-12-25 18:15:34 +0200640 public function parseResponse($fp)
Derek Allard2067d1a2008-11-13 22:59:24 +0000641 {
642 $data = '';
Barry Mienydd671972010-10-04 16:33:58 +0200643
Pascal Kriete14287f32011-02-14 13:39:34 -0500644 while ($datum = fread($fp, 4096))
Derek Allard2067d1a2008-11-13 22:59:24 +0000645 {
646 $data .= $datum;
647 }
Barry Mienydd671972010-10-04 16:33:58 +0200648
Derek Allard2067d1a2008-11-13 22:59:24 +0000649 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500650 // DISPLAY HTTP CONTENT for DEBUGGING
Derek Allard2067d1a2008-11-13 22:59:24 +0000651 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200652
Derek Allard2067d1a2008-11-13 22:59:24 +0000653 if ($this->debug === TRUE)
654 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200655 echo "<pre>---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000656 }
Barry Mienydd671972010-10-04 16:33:58 +0200657
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500659 // Check for data
Derek Allard2067d1a2008-11-13 22:59:24 +0000660 //-------------------------------------
661
Andrey Andreeva30faf92011-12-25 18:15:34 +0200662 if ($data === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 {
664 error_log($this->xmlrpcstr['no_data']);
665 $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']);
666 return $r;
667 }
Barry Mienydd671972010-10-04 16:33:58 +0200668
669
Derek Allard2067d1a2008-11-13 22:59:24 +0000670 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500671 // Check for HTTP 200 Response
Derek Allard2067d1a2008-11-13 22:59:24 +0000672 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200673
Andrey Andreeva30faf92011-12-25 18:15:34 +0200674 if (strncmp($data, 'HTTP', 4) === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data))
Derek Allard2067d1a2008-11-13 22:59:24 +0000675 {
676 $errstr= substr($data, 0, strpos($data, "\n")-1);
677 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')');
678 return $r;
679 }
Barry Mienydd671972010-10-04 16:33:58 +0200680
Derek Allard2067d1a2008-11-13 22:59:24 +0000681 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500682 // Create and Set Up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000683 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200684
Derek Allard2067d1a2008-11-13 22:59:24 +0000685 $parser = xml_parser_create($this->xmlrpc_defencoding);
686
Andrey Andreeva30faf92011-12-25 18:15:34 +0200687 $this->xh[$parser] = array(
688 'isf' => 0,
689 'ac' => '',
690 'headers' => array(),
691 'stack' => array(),
692 'valuestack' => array(),
693 'isf_reason' => 0
694 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000695
696 xml_set_object($parser, $this);
697 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
698 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
699 xml_set_character_data_handler($parser, 'character_data');
700 //xml_set_default_handler($parser, 'default_handler');
701
702
703 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500704 // GET HEADERS
Derek Allard2067d1a2008-11-13 22:59:24 +0000705 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200706
Derek Allard2067d1a2008-11-13 22:59:24 +0000707 $lines = explode("\r\n", $data);
708 while (($line = array_shift($lines)))
709 {
710 if (strlen($line) < 1)
711 {
712 break;
713 }
714 $this->xh[$parser]['headers'][] = $line;
715 }
716 $data = implode("\r\n", $lines);
Barry Mienydd671972010-10-04 16:33:58 +0200717
718
Derek Allard2067d1a2008-11-13 22:59:24 +0000719 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500720 // PARSE XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200721 //-------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000722
Derek Jones33559102009-02-02 18:50:38 +0000723 if ( ! xml_parse($parser, $data, count($data)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000724 {
725 $errstr = sprintf('XML error: %s at line %d',
726 xml_error_string(xml_get_error_code($parser)),
727 xml_get_current_line_number($parser));
728 //error_log($errstr);
729 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
730 xml_parser_free($parser);
731 return $r;
732 }
733 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200734
Derek Allard2067d1a2008-11-13 22:59:24 +0000735 // ---------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500736 // Got Ourselves Some Badness, It Seems
Derek Allard2067d1a2008-11-13 22:59:24 +0000737 // ---------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200738
Derek Allard2067d1a2008-11-13 22:59:24 +0000739 if ($this->xh[$parser]['isf'] > 1)
740 {
741 if ($this->debug === TRUE)
742 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200743 echo "---Invalid Return---\n".$this->xh[$parser]['isf_reason']."---Invalid Return---\n\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000744 }
Barry Mienydd671972010-10-04 16:33:58 +0200745
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
747 return $r;
748 }
749 elseif ( ! is_object($this->xh[$parser]['value']))
750 {
751 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
752 return $r;
753 }
Barry Mienydd671972010-10-04 16:33:58 +0200754
Derek Allard2067d1a2008-11-13 22:59:24 +0000755 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500756 // DISPLAY XML CONTENT for DEBUGGING
Barry Mienydd671972010-10-04 16:33:58 +0200757 //-------------------------------------
758
Derek Allard2067d1a2008-11-13 22:59:24 +0000759 if ($this->debug === TRUE)
760 {
761 echo "<pre>";
Barry Mienydd671972010-10-04 16:33:58 +0200762
Derek Allard2067d1a2008-11-13 22:59:24 +0000763 if (count($this->xh[$parser]['headers'] > 0))
764 {
765 echo "---HEADERS---\n";
766 foreach ($this->xh[$parser]['headers'] as $header)
767 {
768 echo "$header\n";
769 }
770 echo "---END HEADERS---\n\n";
771 }
Barry Mienydd671972010-10-04 16:33:58 +0200772
Andrey Andreeva30faf92011-12-25 18:15:34 +0200773 echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000774 var_dump($this->xh[$parser]['value']);
775 echo "\n---END PARSED---</pre>";
776 }
Barry Mienydd671972010-10-04 16:33:58 +0200777
Derek Allard2067d1a2008-11-13 22:59:24 +0000778 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500779 // SEND RESPONSE
Derek Allard2067d1a2008-11-13 22:59:24 +0000780 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200781
Derek Allard2067d1a2008-11-13 22:59:24 +0000782 $v = $this->xh[$parser]['value'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000783 if ($this->xh[$parser]['isf'])
784 {
785 $errno_v = $v->me['struct']['faultCode'];
786 $errstr_v = $v->me['struct']['faultString'];
787 $errno = $errno_v->scalarval();
788
789 if ($errno == 0)
790 {
791 // FAULT returned, errno needs to reflect that
792 $errno = -1;
793 }
794
795 $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval());
796 }
797 else
798 {
799 $r = new XML_RPC_Response($v);
800 }
801
802 $r->headers = $this->xh[$parser]['headers'];
803 return $r;
804 }
Barry Mienydd671972010-10-04 16:33:58 +0200805
Derek Allard2067d1a2008-11-13 22:59:24 +0000806 // ------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500807 // Begin Return Message Parsing section
Derek Allard2067d1a2008-11-13 22:59:24 +0000808 // ------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200809
Derek Allard2067d1a2008-11-13 22:59:24 +0000810 // quick explanation of components:
Derek Jones37f4b9c2011-07-01 17:56:50 -0500811 // ac - used to accumulate values
812 // isf - used to indicate a fault
813 // lv - used to indicate "looking for a value": implements
Derek Allard2067d1a2008-11-13 22:59:24 +0000814 // the logic to allow values with no types to be strings
Derek Jones37f4b9c2011-07-01 17:56:50 -0500815 // params - used to store parameters in method calls
816 // method - used to store method name
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 // stack - array with parent tree of the xml element,
818 // used to validate the nesting of elements
819
820 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500821 // Start Element Handler
Derek Allard2067d1a2008-11-13 22:59:24 +0000822 //-------------------------------------
823
Andrey Andreeva30faf92011-12-25 18:15:34 +0200824 public function open_tag($the_parser, $name, $attrs)
Derek Allard2067d1a2008-11-13 22:59:24 +0000825 {
826 // If invalid nesting, then return
827 if ($this->xh[$the_parser]['isf'] > 1) return;
Barry Mienydd671972010-10-04 16:33:58 +0200828
Derek Allard2067d1a2008-11-13 22:59:24 +0000829 // Evaluate and check for correct nesting of XML elements
Barry Mienydd671972010-10-04 16:33:58 +0200830
Derek Allard2067d1a2008-11-13 22:59:24 +0000831 if (count($this->xh[$the_parser]['stack']) == 0)
832 {
833 if ($name != 'METHODRESPONSE' && $name != 'METHODCALL')
834 {
835 $this->xh[$the_parser]['isf'] = 2;
836 $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
837 return;
838 }
839 }
840 else
841 {
842 // not top level element: see if parent is OK
843 if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
844 {
845 $this->xh[$the_parser]['isf'] = 2;
846 $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0];
847 return;
848 }
849 }
Barry Mienydd671972010-10-04 16:33:58 +0200850
Derek Allard2067d1a2008-11-13 22:59:24 +0000851 switch($name)
852 {
853 case 'STRUCT':
854 case 'ARRAY':
855 // Creates array for child elements
Barry Mienydd671972010-10-04 16:33:58 +0200856
Derek Allard2067d1a2008-11-13 22:59:24 +0000857 $cur_val = array('value' => array(),
858 'type' => $name);
Barry Mienydd671972010-10-04 16:33:58 +0200859
Derek Allard2067d1a2008-11-13 22:59:24 +0000860 array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
861 break;
862 case 'METHODNAME':
863 case 'NAME':
864 $this->xh[$the_parser]['ac'] = '';
865 break;
866 case 'FAULT':
867 $this->xh[$the_parser]['isf'] = 1;
868 break;
869 case 'PARAM':
Pascal Kriete8761ef52011-02-14 13:13:52 -0500870 $this->xh[$the_parser]['value'] = NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000871 break;
872 case 'VALUE':
873 $this->xh[$the_parser]['vt'] = 'value';
874 $this->xh[$the_parser]['ac'] = '';
875 $this->xh[$the_parser]['lv'] = 1;
876 break;
877 case 'I4':
878 case 'INT':
879 case 'STRING':
880 case 'BOOLEAN':
881 case 'DOUBLE':
882 case 'DATETIME.ISO8601':
883 case 'BASE64':
884 if ($this->xh[$the_parser]['vt'] != 'value')
885 {
886 //two data elements inside a value: an error occurred!
887 $this->xh[$the_parser]['isf'] = 2;
888 $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value";
889 return;
890 }
Barry Mienydd671972010-10-04 16:33:58 +0200891
Derek Allard2067d1a2008-11-13 22:59:24 +0000892 $this->xh[$the_parser]['ac'] = '';
893 break;
894 case 'MEMBER':
895 // Set name of <member> to nothing to prevent errors later if no <name> is found
896 $this->xh[$the_parser]['valuestack'][0]['name'] = '';
Barry Mienydd671972010-10-04 16:33:58 +0200897
Derek Allard2067d1a2008-11-13 22:59:24 +0000898 // Set NULL value to check to see if value passed for this param/member
Pascal Kriete8761ef52011-02-14 13:13:52 -0500899 $this->xh[$the_parser]['value'] = NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000900 break;
901 case 'DATA':
902 case 'METHODCALL':
903 case 'METHODRESPONSE':
904 case 'PARAMS':
905 // valid elements that add little to processing
906 break;
907 default:
908 /// An Invalid Element is Found, so we have trouble
909 $this->xh[$the_parser]['isf'] = 2;
910 $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name";
911 break;
912 }
Barry Mienydd671972010-10-04 16:33:58 +0200913
Derek Allard2067d1a2008-11-13 22:59:24 +0000914 // Add current element name to stack, to allow validation of nesting
915 array_unshift($this->xh[$the_parser]['stack'], $name);
916
917 if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0;
918 }
919 // END
920
921
922 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500923 // End Element Handler
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 //-------------------------------------
925
Andrey Andreeva30faf92011-12-25 18:15:34 +0200926 public function closing_tag($the_parser, $name)
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 {
928 if ($this->xh[$the_parser]['isf'] > 1) return;
Barry Mienydd671972010-10-04 16:33:58 +0200929
Derek Allard2067d1a2008-11-13 22:59:24 +0000930 // Remove current element from stack and set variable
931 // NOTE: If the XML validates, then we do not have to worry about
Derek Jones37f4b9c2011-07-01 17:56:50 -0500932 // the opening and closing of elements. Nesting is checked on the opening
Derek Allard2067d1a2008-11-13 22:59:24 +0000933 // tag so we be safe there as well.
Barry Mienydd671972010-10-04 16:33:58 +0200934
Derek Allard2067d1a2008-11-13 22:59:24 +0000935 $curr_elem = array_shift($this->xh[$the_parser]['stack']);
Barry Mienydd671972010-10-04 16:33:58 +0200936
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 switch($name)
938 {
939 case 'STRUCT':
940 case 'ARRAY':
941 $cur_val = array_shift($this->xh[$the_parser]['valuestack']);
942 $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values'];
943 $this->xh[$the_parser]['vt'] = strtolower($name);
944 break;
945 case 'NAME':
946 $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac'];
947 break;
948 case 'BOOLEAN':
949 case 'I4':
950 case 'INT':
951 case 'STRING':
952 case 'DOUBLE':
953 case 'DATETIME.ISO8601':
954 case 'BASE64':
955 $this->xh[$the_parser]['vt'] = strtolower($name);
Barry Mienydd671972010-10-04 16:33:58 +0200956
Derek Allard2067d1a2008-11-13 22:59:24 +0000957 if ($name == 'STRING')
958 {
959 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
960 }
961 elseif ($name=='DATETIME.ISO8601')
962 {
963 $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime;
964 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
965 }
966 elseif ($name=='BASE64')
967 {
968 $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']);
969 }
970 elseif ($name=='BOOLEAN')
971 {
972 // Translated BOOLEAN values to TRUE AND FALSE
973 if ($this->xh[$the_parser]['ac'] == '1')
974 {
975 $this->xh[$the_parser]['value'] = TRUE;
976 }
977 else
978 {
979 $this->xh[$the_parser]['value'] = FALSE;
980 }
981 }
982 elseif ($name=='DOUBLE')
983 {
984 // we have a DOUBLE
985 // we must check that only 0123456789-.<space> are characters here
986 if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']))
987 {
988 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
989 }
990 else
991 {
992 $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac'];
993 }
994 }
995 else
996 {
997 // we have an I4/INT
998 // we must check that only 0123456789-<space> are characters here
999 if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']))
1000 {
1001 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
1002 }
1003 else
1004 {
1005 $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac'];
1006 }
1007 }
1008 $this->xh[$the_parser]['ac'] = '';
1009 $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value
1010 break;
1011 case 'VALUE':
1012 // This if() detects if no scalar was inside <VALUE></VALUE>
1013 if ($this->xh[$the_parser]['vt']=='value')
1014 {
1015 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
1016 $this->xh[$the_parser]['vt'] = $this->xmlrpcString;
1017 }
Barry Mienydd671972010-10-04 16:33:58 +02001018
Derek Allard2067d1a2008-11-13 22:59:24 +00001019 // build the XML-RPC value out of the data received, and substitute it
1020 $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']);
Barry Mienydd671972010-10-04 16:33:58 +02001021
Derek Allard2067d1a2008-11-13 22:59:24 +00001022 if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY')
1023 {
1024 // Array
1025 $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp;
1026 }
1027 else
1028 {
1029 // Struct
1030 $this->xh[$the_parser]['value'] = $temp;
1031 }
1032 break;
1033 case 'MEMBER':
1034 $this->xh[$the_parser]['ac']='';
Barry Mienydd671972010-10-04 16:33:58 +02001035
Derek Allard2067d1a2008-11-13 22:59:24 +00001036 // If value add to array in the stack for the last element built
1037 if ($this->xh[$the_parser]['value'])
1038 {
1039 $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value'];
1040 }
1041 break;
1042 case 'DATA':
1043 $this->xh[$the_parser]['ac']='';
1044 break;
1045 case 'PARAM':
1046 if ($this->xh[$the_parser]['value'])
1047 {
1048 $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value'];
1049 }
1050 break;
1051 case 'METHODNAME':
1052 $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']);
1053 break;
1054 case 'PARAMS':
1055 case 'FAULT':
1056 case 'METHODCALL':
1057 case 'METHORESPONSE':
1058 // We're all good kids with nuthin' to do
1059 break;
1060 default:
Derek Jones37f4b9c2011-07-01 17:56:50 -05001061 // End of an Invalid Element. Taken care of during the opening tag though
Derek Allard2067d1a2008-11-13 22:59:24 +00001062 break;
1063 }
1064 }
1065
1066 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -05001067 // Parses Character Data
Derek Allard2067d1a2008-11-13 22:59:24 +00001068 //-------------------------------------
1069
Andrey Andreeva30faf92011-12-25 18:15:34 +02001070 public function character_data($the_parser, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001071 {
1072 if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already
Barry Mienydd671972010-10-04 16:33:58 +02001073
Derek Allard2067d1a2008-11-13 22:59:24 +00001074 // If a value has not been found
1075 if ($this->xh[$the_parser]['lv'] != 3)
1076 {
1077 if ($this->xh[$the_parser]['lv'] == 1)
1078 {
1079 $this->xh[$the_parser]['lv'] = 2; // Found a value
1080 }
Barry Mienydd671972010-10-04 16:33:58 +02001081
Pascal Kriete14287f32011-02-14 13:39:34 -05001082 if ( ! @isset($this->xh[$the_parser]['ac']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001083 {
1084 $this->xh[$the_parser]['ac'] = '';
1085 }
Barry Mienydd671972010-10-04 16:33:58 +02001086
Derek Allard2067d1a2008-11-13 22:59:24 +00001087 $this->xh[$the_parser]['ac'] .= $data;
1088 }
1089 }
Barry Mienydd671972010-10-04 16:33:58 +02001090
1091
Andrey Andreeva30faf92011-12-25 18:15:34 +02001092 public function addParam($par)
1093 {
1094 $this->params[] = $par;
1095 }
Barry Mienydd671972010-10-04 16:33:58 +02001096
Andrey Andreeva30faf92011-12-25 18:15:34 +02001097 public function output_parameters($array = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001098 {
Barry Mienydd671972010-10-04 16:33:58 +02001099 $CI =& get_instance();
Andrey Andreeva30faf92011-12-25 18:15:34 +02001100
1101 if (is_array($array))
Derek Allard2067d1a2008-11-13 22:59:24 +00001102 {
1103 while (list($key) = each($array))
1104 {
1105 if (is_array($array[$key]))
1106 {
1107 $array[$key] = $this->output_parameters($array[$key]);
1108 }
1109 else
1110 {
Derek Jonesa9647e82010-03-02 22:59:07 -06001111 // 'bits' is for the MetaWeblog API image bits
1112 // @todo - this needs to be made more general purpose
Robin Sowell66a3fc02010-03-18 09:44:55 -04001113 $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001114 }
1115 }
Barry Mienydd671972010-10-04 16:33:58 +02001116
Derek Allard2067d1a2008-11-13 22:59:24 +00001117 $parameters = $array;
1118 }
1119 else
1120 {
1121 $parameters = array();
Barry Mienydd671972010-10-04 16:33:58 +02001122
Andrey Andreeva30faf92011-12-25 18:15:34 +02001123 for ($i = 0, $c = count($this->params); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 {
1125 $a_param = $this->decode_message($this->params[$i]);
Barry Mienydd671972010-10-04 16:33:58 +02001126
Derek Allard2067d1a2008-11-13 22:59:24 +00001127 if (is_array($a_param))
1128 {
1129 $parameters[] = $this->output_parameters($a_param);
1130 }
1131 else
1132 {
Robin Sowell66a3fc02010-03-18 09:44:55 -04001133 $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param;
Derek Allard2067d1a2008-11-13 22:59:24 +00001134 }
Barry Mienydd671972010-10-04 16:33:58 +02001135 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001136 }
Barry Mienydd671972010-10-04 16:33:58 +02001137
Derek Allard2067d1a2008-11-13 22:59:24 +00001138 return $parameters;
1139 }
Barry Mienydd671972010-10-04 16:33:58 +02001140
1141
Andrey Andreeva30faf92011-12-25 18:15:34 +02001142 public function decode_message($param)
Derek Allard2067d1a2008-11-13 22:59:24 +00001143 {
1144 $kind = $param->kindOf();
1145
Pascal Kriete14287f32011-02-14 13:39:34 -05001146 if ($kind == 'scalar')
Derek Allard2067d1a2008-11-13 22:59:24 +00001147 {
1148 return $param->scalarval();
1149 }
Pascal Kriete14287f32011-02-14 13:39:34 -05001150 elseif ($kind == 'array')
Derek Allard2067d1a2008-11-13 22:59:24 +00001151 {
1152 reset($param->me);
Andrey Andreev62090152011-12-30 12:49:27 +02001153 list(, $b) = each($param->me);
Barry Mienydd671972010-10-04 16:33:58 +02001154
Derek Allard2067d1a2008-11-13 22:59:24 +00001155 $arr = array();
1156
Andrey Andreeva30faf92011-12-25 18:15:34 +02001157 for($i = 0, $c = count($b); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001158 {
1159 $arr[] = $this->decode_message($param->me['array'][$i]);
1160 }
Barry Mienydd671972010-10-04 16:33:58 +02001161
Derek Allard2067d1a2008-11-13 22:59:24 +00001162 return $arr;
1163 }
Pascal Kriete14287f32011-02-14 13:39:34 -05001164 elseif ($kind == 'struct')
Derek Allard2067d1a2008-11-13 22:59:24 +00001165 {
1166 reset($param->me['struct']);
Barry Mienydd671972010-10-04 16:33:58 +02001167
Derek Allard2067d1a2008-11-13 22:59:24 +00001168 $arr = array();
1169
Pascal Kriete14287f32011-02-14 13:39:34 -05001170 while (list($key,$value) = each($param->me['struct']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001171 {
1172 $arr[$key] = $this->decode_message($value);
1173 }
Barry Mienydd671972010-10-04 16:33:58 +02001174
Derek Allard2067d1a2008-11-13 22:59:24 +00001175 return $arr;
1176 }
1177 }
Barry Mienydd671972010-10-04 16:33:58 +02001178
Andrey Andreeva30faf92011-12-25 18:15:34 +02001179}
1180// End XML_RPC_Messages class
Derek Allard2067d1a2008-11-13 22:59:24 +00001181
1182/**
1183 * XML-RPC Values class
1184 *
1185 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -05001186 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +00001187 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
1188 */
1189class XML_RPC_Values extends CI_Xmlrpc
1190{
Andrey Andreeva30faf92011-12-25 18:15:34 +02001191 public $me = array();
1192 public $mytype = 0;
Derek Allard2067d1a2008-11-13 22:59:24 +00001193
Andrey Andreeva30faf92011-12-25 18:15:34 +02001194 public function __construct($val = -1, $type = '')
Barry Mienydd671972010-10-04 16:33:58 +02001195 {
Greg Akera9263282010-11-10 15:26:43 -06001196 parent::__construct();
Barry Mienydd671972010-10-04 16:33:58 +02001197
Derek Allard2067d1a2008-11-13 22:59:24 +00001198 if ($val != -1 OR $type != '')
1199 {
1200 $type = $type == '' ? 'string' : $type;
Barry Mienydd671972010-10-04 16:33:58 +02001201
Derek Allard2067d1a2008-11-13 22:59:24 +00001202 if ($this->xmlrpcTypes[$type] == 1)
1203 {
1204 $this->addScalar($val,$type);
1205 }
1206 elseif ($this->xmlrpcTypes[$type] == 2)
1207 {
1208 $this->addArray($val);
1209 }
1210 elseif ($this->xmlrpcTypes[$type] == 3)
1211 {
1212 $this->addStruct($val);
1213 }
1214 }
1215 }
1216
Andrey Andreeva30faf92011-12-25 18:15:34 +02001217 public function addScalar($val, $type = 'string')
Derek Allard2067d1a2008-11-13 22:59:24 +00001218 {
1219 $typeof = $this->xmlrpcTypes[$type];
Barry Mienydd671972010-10-04 16:33:58 +02001220
Derek Allard2067d1a2008-11-13 22:59:24 +00001221 if ($this->mytype==1)
1222 {
1223 echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />';
1224 return 0;
1225 }
Barry Mienydd671972010-10-04 16:33:58 +02001226
Derek Allard2067d1a2008-11-13 22:59:24 +00001227 if ($typeof != 1)
1228 {
1229 echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />';
1230 return 0;
1231 }
1232
1233 if ($type == $this->xmlrpcBoolean)
1234 {
Andrey Andreeva30faf92011-12-25 18:15:34 +02001235 $val = (strcasecmp($val,'true') === 0 OR $val == 1 OR ($val == true && strcasecmp($val, 'false'))) ? 1 : 0;
Derek Allard2067d1a2008-11-13 22:59:24 +00001236 }
1237
1238 if ($this->mytype == 2)
1239 {
1240 // adding to an array here
1241 $ar = $this->me['array'];
1242 $ar[] = new XML_RPC_Values($val, $type);
1243 $this->me['array'] = $ar;
1244 }
1245 else
1246 {
1247 // a scalar, so set the value and remember we're scalar
1248 $this->me[$type] = $val;
1249 $this->mytype = $typeof;
1250 }
1251 return 1;
1252 }
1253
Andrey Andreeva30faf92011-12-25 18:15:34 +02001254 public function addArray($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001255 {
1256 if ($this->mytype != 0)
1257 {
1258 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
1259 return 0;
1260 }
1261
1262 $this->mytype = $this->xmlrpcTypes['array'];
1263 $this->me['array'] = $vals;
1264 return 1;
1265 }
1266
Andrey Andreeva30faf92011-12-25 18:15:34 +02001267 public function addStruct($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001268 {
1269 if ($this->mytype != 0)
1270 {
1271 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
1272 return 0;
1273 }
1274 $this->mytype = $this->xmlrpcTypes['struct'];
1275 $this->me['struct'] = $vals;
1276 return 1;
1277 }
1278
Andrey Andreeva30faf92011-12-25 18:15:34 +02001279 public function kindOf()
Derek Allard2067d1a2008-11-13 22:59:24 +00001280 {
1281 switch($this->mytype)
1282 {
1283 case 3:
1284 return 'struct';
1285 break;
1286 case 2:
1287 return 'array';
1288 break;
1289 case 1:
1290 return 'scalar';
1291 break;
1292 default:
1293 return 'undef';
1294 }
1295 }
1296
Andrey Andreeva30faf92011-12-25 18:15:34 +02001297 public function serializedata($typ, $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001298 {
1299 $rs = '';
Derek Jonesa9647e82010-03-02 22:59:07 -06001300
Derek Allard2067d1a2008-11-13 22:59:24 +00001301 switch($this->xmlrpcTypes[$typ])
1302 {
1303 case 3:
1304 // struct
1305 $rs .= "<struct>\n";
1306 reset($val);
Pascal Kriete14287f32011-02-14 13:39:34 -05001307 while (list($key2, $val2) = each($val))
Derek Allard2067d1a2008-11-13 22:59:24 +00001308 {
Andrey Andreeva30faf92011-12-25 18:15:34 +02001309 $rs .= "<member>\n<name>{$key2}</name>\n".$this->serializeval($val2)."</member>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001310 }
1311 $rs .= '</struct>';
1312 break;
1313 case 2:
1314 // array
1315 $rs .= "<array>\n<data>\n";
Andrey Andreeva30faf92011-12-25 18:15:34 +02001316 for($i = 0, $c = count($val); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001317 {
1318 $rs .= $this->serializeval($val[$i]);
1319 }
Andrey Andreeva30faf92011-12-25 18:15:34 +02001320 $rs .= "</data>\n</array>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001321 break;
1322 case 1:
1323 // others
1324 switch ($typ)
1325 {
1326 case $this->xmlrpcBase64:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001327 $rs .= "<{$typ}>" . base64_encode((string)$val) . "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001328 break;
1329 case $this->xmlrpcBoolean:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001330 $rs .= "<{$typ}>" . ((bool)$val ? '1' : '0') . "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001331 break;
1332 case $this->xmlrpcString:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001333 $rs .= "<{$typ}>" . htmlspecialchars((string)$val). "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001334 break;
1335 default:
1336 $rs .= "<{$typ}>{$val}</{$typ}>\n";
1337 break;
1338 }
1339 default:
1340 break;
1341 }
1342 return $rs;
1343 }
1344
Andrey Andreeva30faf92011-12-25 18:15:34 +02001345 public function serialize_class()
Derek Allard2067d1a2008-11-13 22:59:24 +00001346 {
1347 return $this->serializeval($this);
1348 }
1349
Andrey Andreeva30faf92011-12-25 18:15:34 +02001350 public function serializeval($o)
Derek Allard2067d1a2008-11-13 22:59:24 +00001351 {
1352 $ar = $o->me;
1353 reset($ar);
Barry Mienydd671972010-10-04 16:33:58 +02001354
Derek Allard2067d1a2008-11-13 22:59:24 +00001355 list($typ, $val) = each($ar);
Andrey Andreeva30faf92011-12-25 18:15:34 +02001356 return "<value>\n".$this->serializedata($typ, $val)."</value>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001357 }
Barry Mienydd671972010-10-04 16:33:58 +02001358
Andrey Andreeva30faf92011-12-25 18:15:34 +02001359 public function scalarval()
Derek Allard2067d1a2008-11-13 22:59:24 +00001360 {
1361 reset($this->me);
Andrey Andreev62090152011-12-30 12:49:27 +02001362 list(, $b) = each($this->me);
Derek Allard2067d1a2008-11-13 22:59:24 +00001363 return $b;
1364 }
1365
1366
1367 //-------------------------------------
1368 // Encode time in ISO-8601 form.
1369 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001370
Derek Allard2067d1a2008-11-13 22:59:24 +00001371 // Useful for sending time in XML-RPC
1372
Andrey Andreev62090152011-12-30 12:49:27 +02001373 public function iso8601_encode($time, $utc = 0)
Barry Mienydd671972010-10-04 16:33:58 +02001374 {
Andrey Andreev62090152011-12-30 12:49:27 +02001375 return ($utc) ? strftime('%Y%m%dT%H:%i:%s', $time) : gmstrftime('%Y%m%dT%H:%i:%s', $time);
Derek Allard2067d1a2008-11-13 22:59:24 +00001376 }
Barry Mienydd671972010-10-04 16:33:58 +02001377
Derek Allard2067d1a2008-11-13 22:59:24 +00001378}
1379// END XML_RPC_Values Class
1380
1381/* End of file Xmlrpc.php */
Andrey Andreeva30faf92011-12-25 18:15:34 +02001382/* Location: ./system/libraries/Xmlrpc.php */