blob: 32e2e523be9f0cd78a901a21b5678f56686896e2 [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 *
Phil Sturgeon07c1ac82012-03-09 17:03:37 +00005 * An open source application development framework for PHP 5.2.4 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
Greg Aker0defe5d2012-01-01 18:46:41 -060021 * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/)
Derek Jonesf4a4bd82011-10-20 12:18:42 -050022 * @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;
Andrey Andreevb1956372012-01-03 11:01:48 +0200440 if ( ! is_php('5.4'))
441 {
442 $this->errstr = htmlspecialchars($fstr, ENT_NOQUOTES, 'UTF-8');
443 }
444 else
445 {
446 $this->errstr = htmlspecialchars($fstr, ENT_XML1 | ENT_NOQUOTES, 'UTF-8');
447 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000448 }
449 else if ( ! is_object($val))
450 {
451 // programmer error, not an object
Derek Jones37f4b9c2011-07-01 17:56:50 -0500452 error_log("Invalid type '" . gettype($val) . "' (value: $val) passed to XML_RPC_Response. Defaulting to empty value.");
Derek Allard2067d1a2008-11-13 22:59:24 +0000453 $this->val = new XML_RPC_Values();
454 }
455 else
456 {
457 $this->val = $val;
458 }
459 }
460
Andrey Andreeva30faf92011-12-25 18:15:34 +0200461 public function faultCode()
Derek Allard2067d1a2008-11-13 22:59:24 +0000462 {
463 return $this->errno;
464 }
465
Andrey Andreeva30faf92011-12-25 18:15:34 +0200466 public function faultString()
Derek Allard2067d1a2008-11-13 22:59:24 +0000467 {
468 return $this->errstr;
469 }
470
Andrey Andreeva30faf92011-12-25 18:15:34 +0200471 public function value()
Derek Allard2067d1a2008-11-13 22:59:24 +0000472 {
473 return $this->val;
474 }
Barry Mienydd671972010-10-04 16:33:58 +0200475
Andrey Andreeva30faf92011-12-25 18:15:34 +0200476 public function prepare_response()
Derek Allard2067d1a2008-11-13 22:59:24 +0000477 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200478 return "<methodResponse>\n"
479 . ($this->errno
480 ? '<fault>
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 <value>
482 <struct>
483 <member>
484 <name>faultCode</name>
485 <value><int>' . $this->errno . '</int></value>
486 </member>
487 <member>
488 <name>faultString</name>
489 <value><string>' . $this->errstr . '</string></value>
490 </member>
491 </struct>
492 </value>
Andrey Andreeva30faf92011-12-25 18:15:34 +0200493</fault>'
494 : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>")
495 . "\n</methodResponse>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000496 }
Barry Mienydd671972010-10-04 16:33:58 +0200497
Andrey Andreeva30faf92011-12-25 18:15:34 +0200498 public function decode($array = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000499 {
500 $CI =& get_instance();
Andrey Andreeva30faf92011-12-25 18:15:34 +0200501
502 if (is_array($array))
Derek Allard2067d1a2008-11-13 22:59:24 +0000503 {
504 while (list($key) = each($array))
505 {
506 if (is_array($array[$key]))
507 {
508 $array[$key] = $this->decode($array[$key]);
509 }
510 else
511 {
Robin Sowell66a3fc02010-03-18 09:44:55 -0400512 $array[$key] = ($this->xss_clean) ? $CI->security->xss_clean($array[$key]) : $array[$key];
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 }
514 }
Barry Mienydd671972010-10-04 16:33:58 +0200515
Derek Allard2067d1a2008-11-13 22:59:24 +0000516 $result = $array;
517 }
518 else
519 {
520 $result = $this->xmlrpc_decoder($this->val);
Barry Mienydd671972010-10-04 16:33:58 +0200521
Derek Allard2067d1a2008-11-13 22:59:24 +0000522 if (is_array($result))
523 {
524 $result = $this->decode($result);
525 }
526 else
527 {
Robin Sowell66a3fc02010-03-18 09:44:55 -0400528 $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result;
Derek Allard2067d1a2008-11-13 22:59:24 +0000529 }
530 }
Barry Mienydd671972010-10-04 16:33:58 +0200531
Derek Allard2067d1a2008-11-13 22:59:24 +0000532 return $result;
533 }
534
Barry Mienydd671972010-10-04 16:33:58 +0200535
536
Derek Allard2067d1a2008-11-13 22:59:24 +0000537 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500538 // XML-RPC Object to PHP Types
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 //-------------------------------------
540
Andrey Andreeva30faf92011-12-25 18:15:34 +0200541 public function xmlrpc_decoder($xmlrpc_val)
Derek Allard2067d1a2008-11-13 22:59:24 +0000542 {
543 $kind = $xmlrpc_val->kindOf();
544
Pascal Kriete14287f32011-02-14 13:39:34 -0500545 if ($kind == 'scalar')
Derek Allard2067d1a2008-11-13 22:59:24 +0000546 {
547 return $xmlrpc_val->scalarval();
548 }
Pascal Kriete14287f32011-02-14 13:39:34 -0500549 elseif ($kind == 'array')
Derek Allard2067d1a2008-11-13 22:59:24 +0000550 {
551 reset($xmlrpc_val->me);
Andrey Andreevadc11752011-12-30 14:46:08 +0200552 $b = current($xmlrpc_val->me);
Derek Allard2067d1a2008-11-13 22:59:24 +0000553 $arr = array();
554
Andrey Andreeva30faf92011-12-25 18:15:34 +0200555 for ($i = 0, $size = count($b); $i < $size; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000556 {
557 $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]);
558 }
559 return $arr;
560 }
Pascal Kriete14287f32011-02-14 13:39:34 -0500561 elseif ($kind == 'struct')
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 {
563 reset($xmlrpc_val->me['struct']);
564 $arr = array();
565
Pascal Kriete14287f32011-02-14 13:39:34 -0500566 while (list($key,$value) = each($xmlrpc_val->me['struct']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000567 {
568 $arr[$key] = $this->xmlrpc_decoder($value);
569 }
570 return $arr;
571 }
572 }
Barry Mienydd671972010-10-04 16:33:58 +0200573
574
Derek Allard2067d1a2008-11-13 22:59:24 +0000575 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500576 // ISO-8601 time to server or UTC time
Derek Allard2067d1a2008-11-13 22:59:24 +0000577 //-------------------------------------
578
Andrey Andreeva30faf92011-12-25 18:15:34 +0200579 public function iso8601_decode($time, $utc = 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000580 {
581 // return a timet in the localtime, or UTC
582 $t = 0;
583 if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs))
584 {
Pascal Kriete14287f32011-02-14 13:39:34 -0500585 $fnc = ($utc == 1) ? 'gmmktime' : 'mktime';
586 $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
Derek Allard2067d1a2008-11-13 22:59:24 +0000587 }
588 return $t;
589 }
Barry Mienydd671972010-10-04 16:33:58 +0200590
Andrey Andreeva30faf92011-12-25 18:15:34 +0200591}
592// End Response Class
Derek Allard2067d1a2008-11-13 22:59:24 +0000593
594/**
595 * XML-RPC Message class
596 *
597 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -0500598 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +0000599 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
600 */
601class XML_RPC_Message extends CI_Xmlrpc
602{
Andrey Andreeva30faf92011-12-25 18:15:34 +0200603 public $payload;
604 public $method_name;
605 public $params = array();
606 public $xh = array();
Derek Allard2067d1a2008-11-13 22:59:24 +0000607
Greg Akera9263282010-11-10 15:26:43 -0600608 public function __construct($method, $pars=0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000609 {
Greg Akera9263282010-11-10 15:26:43 -0600610 parent::__construct();
Barry Mienydd671972010-10-04 16:33:58 +0200611
Derek Allard2067d1a2008-11-13 22:59:24 +0000612 $this->method_name = $method;
Derek Jones33559102009-02-02 18:50:38 +0000613 if (is_array($pars) && count($pars) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000614 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200615 for ($i = 0, $c = count($pars); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000616 {
617 // $pars[$i] = XML_RPC_Values
618 $this->params[] = $pars[$i];
619 }
620 }
621 }
Barry Mienydd671972010-10-04 16:33:58 +0200622
Derek Allard2067d1a2008-11-13 22:59:24 +0000623 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500624 // Create Payload to Send
Derek Allard2067d1a2008-11-13 22:59:24 +0000625 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200626
Andrey Andreeva30faf92011-12-25 18:15:34 +0200627 public function createPayload()
Derek Allard2067d1a2008-11-13 22:59:24 +0000628 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200629 $this->payload = "<?xml version=\"1.0\"?".">\r\n<methodCall>\r\n"
630 . '<methodName>'.$this->method_name."</methodName>\r\n"
631 . "<params>\r\n";
Barry Mienydd671972010-10-04 16:33:58 +0200632
Andrey Andreeva30faf92011-12-25 18:15:34 +0200633 for ($i = 0, $c = count($this->params); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +0000634 {
635 // $p = XML_RPC_Values
636 $p = $this->params[$i];
637 $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n";
638 }
Barry Mienydd671972010-10-04 16:33:58 +0200639
Derek Allard2067d1a2008-11-13 22:59:24 +0000640 $this->payload .= "</params>\r\n</methodCall>\r\n";
641 }
Barry Mienydd671972010-10-04 16:33:58 +0200642
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500644 // Parse External XML-RPC Server's Response
Derek Allard2067d1a2008-11-13 22:59:24 +0000645 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200646
Andrey Andreeva30faf92011-12-25 18:15:34 +0200647 public function parseResponse($fp)
Derek Allard2067d1a2008-11-13 22:59:24 +0000648 {
649 $data = '';
Barry Mienydd671972010-10-04 16:33:58 +0200650
Pascal Kriete14287f32011-02-14 13:39:34 -0500651 while ($datum = fread($fp, 4096))
Derek Allard2067d1a2008-11-13 22:59:24 +0000652 {
653 $data .= $datum;
654 }
Barry Mienydd671972010-10-04 16:33:58 +0200655
Derek Allard2067d1a2008-11-13 22:59:24 +0000656 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500657 // DISPLAY HTTP CONTENT for DEBUGGING
Derek Allard2067d1a2008-11-13 22:59:24 +0000658 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200659
Derek Allard2067d1a2008-11-13 22:59:24 +0000660 if ($this->debug === TRUE)
661 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200662 echo "<pre>---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n</pre>";
Derek Allard2067d1a2008-11-13 22:59:24 +0000663 }
Barry Mienydd671972010-10-04 16:33:58 +0200664
Derek Allard2067d1a2008-11-13 22:59:24 +0000665 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500666 // Check for data
Derek Allard2067d1a2008-11-13 22:59:24 +0000667 //-------------------------------------
668
Andrey Andreeva30faf92011-12-25 18:15:34 +0200669 if ($data === '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000670 {
671 error_log($this->xmlrpcstr['no_data']);
672 $r = new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']);
673 return $r;
674 }
Barry Mienydd671972010-10-04 16:33:58 +0200675
676
Derek Allard2067d1a2008-11-13 22:59:24 +0000677 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500678 // Check for HTTP 200 Response
Derek Allard2067d1a2008-11-13 22:59:24 +0000679 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200680
Andrey Andreeva30faf92011-12-25 18:15:34 +0200681 if (strncmp($data, 'HTTP', 4) === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data))
Derek Allard2067d1a2008-11-13 22:59:24 +0000682 {
683 $errstr= substr($data, 0, strpos($data, "\n")-1);
684 $r = new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']. ' (' . $errstr . ')');
685 return $r;
686 }
Barry Mienydd671972010-10-04 16:33:58 +0200687
Derek Allard2067d1a2008-11-13 22:59:24 +0000688 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500689 // Create and Set Up XML Parser
Derek Allard2067d1a2008-11-13 22:59:24 +0000690 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200691
Derek Allard2067d1a2008-11-13 22:59:24 +0000692 $parser = xml_parser_create($this->xmlrpc_defencoding);
693
Andrey Andreeva30faf92011-12-25 18:15:34 +0200694 $this->xh[$parser] = array(
695 'isf' => 0,
696 'ac' => '',
697 'headers' => array(),
698 'stack' => array(),
699 'valuestack' => array(),
700 'isf_reason' => 0
701 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000702
703 xml_set_object($parser, $this);
704 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
705 xml_set_element_handler($parser, 'open_tag', 'closing_tag');
706 xml_set_character_data_handler($parser, 'character_data');
707 //xml_set_default_handler($parser, 'default_handler');
708
709
710 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500711 // GET HEADERS
Derek Allard2067d1a2008-11-13 22:59:24 +0000712 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200713
Derek Allard2067d1a2008-11-13 22:59:24 +0000714 $lines = explode("\r\n", $data);
715 while (($line = array_shift($lines)))
716 {
717 if (strlen($line) < 1)
718 {
719 break;
720 }
721 $this->xh[$parser]['headers'][] = $line;
722 }
723 $data = implode("\r\n", $lines);
Barry Mienydd671972010-10-04 16:33:58 +0200724
725
Derek Allard2067d1a2008-11-13 22:59:24 +0000726 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500727 // PARSE XML DATA
Barry Mienydd671972010-10-04 16:33:58 +0200728 //-------------------------------------
Derek Allard2067d1a2008-11-13 22:59:24 +0000729
Derek Jones33559102009-02-02 18:50:38 +0000730 if ( ! xml_parse($parser, $data, count($data)))
Derek Allard2067d1a2008-11-13 22:59:24 +0000731 {
732 $errstr = sprintf('XML error: %s at line %d',
733 xml_error_string(xml_get_error_code($parser)),
734 xml_get_current_line_number($parser));
735 //error_log($errstr);
736 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
737 xml_parser_free($parser);
738 return $r;
739 }
740 xml_parser_free($parser);
Barry Mienydd671972010-10-04 16:33:58 +0200741
Derek Allard2067d1a2008-11-13 22:59:24 +0000742 // ---------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500743 // Got Ourselves Some Badness, It Seems
Derek Allard2067d1a2008-11-13 22:59:24 +0000744 // ---------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200745
Derek Allard2067d1a2008-11-13 22:59:24 +0000746 if ($this->xh[$parser]['isf'] > 1)
747 {
748 if ($this->debug === TRUE)
749 {
Andrey Andreeva30faf92011-12-25 18:15:34 +0200750 echo "---Invalid Return---\n".$this->xh[$parser]['isf_reason']."---Invalid Return---\n\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000751 }
Barry Mienydd671972010-10-04 16:33:58 +0200752
Derek Allard2067d1a2008-11-13 22:59:24 +0000753 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
754 return $r;
755 }
756 elseif ( ! is_object($this->xh[$parser]['value']))
757 {
758 $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'],$this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']);
759 return $r;
760 }
Barry Mienydd671972010-10-04 16:33:58 +0200761
Derek Allard2067d1a2008-11-13 22:59:24 +0000762 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500763 // DISPLAY XML CONTENT for DEBUGGING
Barry Mienydd671972010-10-04 16:33:58 +0200764 //-------------------------------------
765
Derek Allard2067d1a2008-11-13 22:59:24 +0000766 if ($this->debug === TRUE)
767 {
768 echo "<pre>";
Barry Mienydd671972010-10-04 16:33:58 +0200769
Derek Allard2067d1a2008-11-13 22:59:24 +0000770 if (count($this->xh[$parser]['headers'] > 0))
771 {
772 echo "---HEADERS---\n";
773 foreach ($this->xh[$parser]['headers'] as $header)
774 {
775 echo "$header\n";
776 }
777 echo "---END HEADERS---\n\n";
778 }
Barry Mienydd671972010-10-04 16:33:58 +0200779
Andrey Andreeva30faf92011-12-25 18:15:34 +0200780 echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000781 var_dump($this->xh[$parser]['value']);
782 echo "\n---END PARSED---</pre>";
783 }
Barry Mienydd671972010-10-04 16:33:58 +0200784
Derek Allard2067d1a2008-11-13 22:59:24 +0000785 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500786 // SEND RESPONSE
Derek Allard2067d1a2008-11-13 22:59:24 +0000787 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200788
Derek Allard2067d1a2008-11-13 22:59:24 +0000789 $v = $this->xh[$parser]['value'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000790 if ($this->xh[$parser]['isf'])
791 {
792 $errno_v = $v->me['struct']['faultCode'];
793 $errstr_v = $v->me['struct']['faultString'];
794 $errno = $errno_v->scalarval();
795
796 if ($errno == 0)
797 {
798 // FAULT returned, errno needs to reflect that
799 $errno = -1;
800 }
801
802 $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval());
803 }
804 else
805 {
806 $r = new XML_RPC_Response($v);
807 }
808
809 $r->headers = $this->xh[$parser]['headers'];
810 return $r;
811 }
Barry Mienydd671972010-10-04 16:33:58 +0200812
Derek Allard2067d1a2008-11-13 22:59:24 +0000813 // ------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500814 // Begin Return Message Parsing section
Derek Allard2067d1a2008-11-13 22:59:24 +0000815 // ------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +0200816
Derek Allard2067d1a2008-11-13 22:59:24 +0000817 // quick explanation of components:
Derek Jones37f4b9c2011-07-01 17:56:50 -0500818 // ac - used to accumulate values
819 // isf - used to indicate a fault
820 // lv - used to indicate "looking for a value": implements
Derek Allard2067d1a2008-11-13 22:59:24 +0000821 // the logic to allow values with no types to be strings
Derek Jones37f4b9c2011-07-01 17:56:50 -0500822 // params - used to store parameters in method calls
823 // method - used to store method name
Derek Allard2067d1a2008-11-13 22:59:24 +0000824 // stack - array with parent tree of the xml element,
825 // used to validate the nesting of elements
826
827 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500828 // Start Element Handler
Derek Allard2067d1a2008-11-13 22:59:24 +0000829 //-------------------------------------
830
Andrey Andreeva30faf92011-12-25 18:15:34 +0200831 public function open_tag($the_parser, $name, $attrs)
Derek Allard2067d1a2008-11-13 22:59:24 +0000832 {
833 // If invalid nesting, then return
834 if ($this->xh[$the_parser]['isf'] > 1) return;
Barry Mienydd671972010-10-04 16:33:58 +0200835
Derek Allard2067d1a2008-11-13 22:59:24 +0000836 // Evaluate and check for correct nesting of XML elements
Barry Mienydd671972010-10-04 16:33:58 +0200837
Derek Allard2067d1a2008-11-13 22:59:24 +0000838 if (count($this->xh[$the_parser]['stack']) == 0)
839 {
840 if ($name != 'METHODRESPONSE' && $name != 'METHODCALL')
841 {
842 $this->xh[$the_parser]['isf'] = 2;
843 $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
844 return;
845 }
846 }
847 else
848 {
849 // not top level element: see if parent is OK
850 if ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
851 {
852 $this->xh[$the_parser]['isf'] = 2;
853 $this->xh[$the_parser]['isf_reason'] = "XML-RPC element $name cannot be child of ".$this->xh[$the_parser]['stack'][0];
854 return;
855 }
856 }
Barry Mienydd671972010-10-04 16:33:58 +0200857
Derek Allard2067d1a2008-11-13 22:59:24 +0000858 switch($name)
859 {
860 case 'STRUCT':
861 case 'ARRAY':
862 // Creates array for child elements
Barry Mienydd671972010-10-04 16:33:58 +0200863
Derek Allard2067d1a2008-11-13 22:59:24 +0000864 $cur_val = array('value' => array(),
865 'type' => $name);
Barry Mienydd671972010-10-04 16:33:58 +0200866
Derek Allard2067d1a2008-11-13 22:59:24 +0000867 array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
868 break;
869 case 'METHODNAME':
870 case 'NAME':
871 $this->xh[$the_parser]['ac'] = '';
872 break;
873 case 'FAULT':
874 $this->xh[$the_parser]['isf'] = 1;
875 break;
876 case 'PARAM':
Pascal Kriete8761ef52011-02-14 13:13:52 -0500877 $this->xh[$the_parser]['value'] = NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000878 break;
879 case 'VALUE':
880 $this->xh[$the_parser]['vt'] = 'value';
881 $this->xh[$the_parser]['ac'] = '';
882 $this->xh[$the_parser]['lv'] = 1;
883 break;
884 case 'I4':
885 case 'INT':
886 case 'STRING':
887 case 'BOOLEAN':
888 case 'DOUBLE':
889 case 'DATETIME.ISO8601':
890 case 'BASE64':
891 if ($this->xh[$the_parser]['vt'] != 'value')
892 {
893 //two data elements inside a value: an error occurred!
894 $this->xh[$the_parser]['isf'] = 2;
895 $this->xh[$the_parser]['isf_reason'] = "'Twas a $name element following a ".$this->xh[$the_parser]['vt']." element inside a single value";
896 return;
897 }
Barry Mienydd671972010-10-04 16:33:58 +0200898
Derek Allard2067d1a2008-11-13 22:59:24 +0000899 $this->xh[$the_parser]['ac'] = '';
900 break;
901 case 'MEMBER':
902 // Set name of <member> to nothing to prevent errors later if no <name> is found
903 $this->xh[$the_parser]['valuestack'][0]['name'] = '';
Barry Mienydd671972010-10-04 16:33:58 +0200904
Derek Allard2067d1a2008-11-13 22:59:24 +0000905 // Set NULL value to check to see if value passed for this param/member
Pascal Kriete8761ef52011-02-14 13:13:52 -0500906 $this->xh[$the_parser]['value'] = NULL;
Derek Allard2067d1a2008-11-13 22:59:24 +0000907 break;
908 case 'DATA':
909 case 'METHODCALL':
910 case 'METHODRESPONSE':
911 case 'PARAMS':
912 // valid elements that add little to processing
913 break;
914 default:
915 /// An Invalid Element is Found, so we have trouble
916 $this->xh[$the_parser]['isf'] = 2;
917 $this->xh[$the_parser]['isf_reason'] = "Invalid XML-RPC element found: $name";
918 break;
919 }
Barry Mienydd671972010-10-04 16:33:58 +0200920
Derek Allard2067d1a2008-11-13 22:59:24 +0000921 // Add current element name to stack, to allow validation of nesting
922 array_unshift($this->xh[$the_parser]['stack'], $name);
923
924 if ($name != 'VALUE') $this->xh[$the_parser]['lv'] = 0;
925 }
926 // END
927
928
929 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -0500930 // End Element Handler
Derek Allard2067d1a2008-11-13 22:59:24 +0000931 //-------------------------------------
932
Andrey Andreeva30faf92011-12-25 18:15:34 +0200933 public function closing_tag($the_parser, $name)
Derek Allard2067d1a2008-11-13 22:59:24 +0000934 {
935 if ($this->xh[$the_parser]['isf'] > 1) return;
Barry Mienydd671972010-10-04 16:33:58 +0200936
Derek Allard2067d1a2008-11-13 22:59:24 +0000937 // Remove current element from stack and set variable
938 // NOTE: If the XML validates, then we do not have to worry about
Derek Jones37f4b9c2011-07-01 17:56:50 -0500939 // the opening and closing of elements. Nesting is checked on the opening
Derek Allard2067d1a2008-11-13 22:59:24 +0000940 // tag so we be safe there as well.
Barry Mienydd671972010-10-04 16:33:58 +0200941
Derek Allard2067d1a2008-11-13 22:59:24 +0000942 $curr_elem = array_shift($this->xh[$the_parser]['stack']);
Barry Mienydd671972010-10-04 16:33:58 +0200943
Derek Allard2067d1a2008-11-13 22:59:24 +0000944 switch($name)
945 {
946 case 'STRUCT':
947 case 'ARRAY':
948 $cur_val = array_shift($this->xh[$the_parser]['valuestack']);
949 $this->xh[$the_parser]['value'] = ( ! isset($cur_val['values'])) ? array() : $cur_val['values'];
950 $this->xh[$the_parser]['vt'] = strtolower($name);
951 break;
952 case 'NAME':
953 $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac'];
954 break;
955 case 'BOOLEAN':
956 case 'I4':
957 case 'INT':
958 case 'STRING':
959 case 'DOUBLE':
960 case 'DATETIME.ISO8601':
961 case 'BASE64':
962 $this->xh[$the_parser]['vt'] = strtolower($name);
Barry Mienydd671972010-10-04 16:33:58 +0200963
Derek Allard2067d1a2008-11-13 22:59:24 +0000964 if ($name == 'STRING')
965 {
966 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
967 }
968 elseif ($name=='DATETIME.ISO8601')
969 {
970 $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime;
971 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
972 }
973 elseif ($name=='BASE64')
974 {
975 $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']);
976 }
977 elseif ($name=='BOOLEAN')
978 {
979 // Translated BOOLEAN values to TRUE AND FALSE
980 if ($this->xh[$the_parser]['ac'] == '1')
981 {
982 $this->xh[$the_parser]['value'] = TRUE;
983 }
984 else
985 {
986 $this->xh[$the_parser]['value'] = FALSE;
987 }
988 }
989 elseif ($name=='DOUBLE')
990 {
991 // we have a DOUBLE
992 // we must check that only 0123456789-.<space> are characters here
993 if ( ! preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']))
994 {
995 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
996 }
997 else
998 {
999 $this->xh[$the_parser]['value'] = (double)$this->xh[$the_parser]['ac'];
1000 }
1001 }
1002 else
1003 {
1004 // we have an I4/INT
1005 // we must check that only 0123456789-<space> are characters here
1006 if ( ! preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']))
1007 {
1008 $this->xh[$the_parser]['value'] = 'ERROR_NON_NUMERIC_FOUND';
1009 }
1010 else
1011 {
1012 $this->xh[$the_parser]['value'] = (int)$this->xh[$the_parser]['ac'];
1013 }
1014 }
1015 $this->xh[$the_parser]['ac'] = '';
1016 $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value
1017 break;
1018 case 'VALUE':
1019 // This if() detects if no scalar was inside <VALUE></VALUE>
1020 if ($this->xh[$the_parser]['vt']=='value')
1021 {
1022 $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
1023 $this->xh[$the_parser]['vt'] = $this->xmlrpcString;
1024 }
Barry Mienydd671972010-10-04 16:33:58 +02001025
Derek Allard2067d1a2008-11-13 22:59:24 +00001026 // build the XML-RPC value out of the data received, and substitute it
1027 $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']);
Barry Mienydd671972010-10-04 16:33:58 +02001028
Derek Allard2067d1a2008-11-13 22:59:24 +00001029 if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY')
1030 {
1031 // Array
1032 $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp;
1033 }
1034 else
1035 {
1036 // Struct
1037 $this->xh[$the_parser]['value'] = $temp;
1038 }
1039 break;
1040 case 'MEMBER':
1041 $this->xh[$the_parser]['ac']='';
Barry Mienydd671972010-10-04 16:33:58 +02001042
Derek Allard2067d1a2008-11-13 22:59:24 +00001043 // If value add to array in the stack for the last element built
1044 if ($this->xh[$the_parser]['value'])
1045 {
1046 $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value'];
1047 }
1048 break;
1049 case 'DATA':
1050 $this->xh[$the_parser]['ac']='';
1051 break;
1052 case 'PARAM':
1053 if ($this->xh[$the_parser]['value'])
1054 {
1055 $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value'];
1056 }
1057 break;
1058 case 'METHODNAME':
1059 $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']);
1060 break;
1061 case 'PARAMS':
1062 case 'FAULT':
1063 case 'METHODCALL':
1064 case 'METHORESPONSE':
1065 // We're all good kids with nuthin' to do
1066 break;
1067 default:
Derek Jones37f4b9c2011-07-01 17:56:50 -05001068 // End of an Invalid Element. Taken care of during the opening tag though
Derek Allard2067d1a2008-11-13 22:59:24 +00001069 break;
1070 }
1071 }
1072
1073 //-------------------------------------
Derek Jones37f4b9c2011-07-01 17:56:50 -05001074 // Parses Character Data
Derek Allard2067d1a2008-11-13 22:59:24 +00001075 //-------------------------------------
1076
Andrey Andreeva30faf92011-12-25 18:15:34 +02001077 public function character_data($the_parser, $data)
Derek Allard2067d1a2008-11-13 22:59:24 +00001078 {
1079 if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already
Barry Mienydd671972010-10-04 16:33:58 +02001080
Derek Allard2067d1a2008-11-13 22:59:24 +00001081 // If a value has not been found
1082 if ($this->xh[$the_parser]['lv'] != 3)
1083 {
1084 if ($this->xh[$the_parser]['lv'] == 1)
1085 {
1086 $this->xh[$the_parser]['lv'] = 2; // Found a value
1087 }
Barry Mienydd671972010-10-04 16:33:58 +02001088
Pascal Kriete14287f32011-02-14 13:39:34 -05001089 if ( ! @isset($this->xh[$the_parser]['ac']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001090 {
1091 $this->xh[$the_parser]['ac'] = '';
1092 }
Barry Mienydd671972010-10-04 16:33:58 +02001093
Derek Allard2067d1a2008-11-13 22:59:24 +00001094 $this->xh[$the_parser]['ac'] .= $data;
1095 }
1096 }
Barry Mienydd671972010-10-04 16:33:58 +02001097
1098
Andrey Andreeva30faf92011-12-25 18:15:34 +02001099 public function addParam($par)
1100 {
1101 $this->params[] = $par;
1102 }
Barry Mienydd671972010-10-04 16:33:58 +02001103
Andrey Andreeva30faf92011-12-25 18:15:34 +02001104 public function output_parameters($array = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +00001105 {
Barry Mienydd671972010-10-04 16:33:58 +02001106 $CI =& get_instance();
Andrey Andreeva30faf92011-12-25 18:15:34 +02001107
1108 if (is_array($array))
Derek Allard2067d1a2008-11-13 22:59:24 +00001109 {
1110 while (list($key) = each($array))
1111 {
1112 if (is_array($array[$key]))
1113 {
1114 $array[$key] = $this->output_parameters($array[$key]);
1115 }
1116 else
1117 {
Derek Jonesa9647e82010-03-02 22:59:07 -06001118 // 'bits' is for the MetaWeblog API image bits
1119 // @todo - this needs to be made more general purpose
Robin Sowell66a3fc02010-03-18 09:44:55 -04001120 $array[$key] = ($key == 'bits' OR $this->xss_clean == FALSE) ? $array[$key] : $CI->security->xss_clean($array[$key]);
Derek Allard2067d1a2008-11-13 22:59:24 +00001121 }
1122 }
Barry Mienydd671972010-10-04 16:33:58 +02001123
Derek Allard2067d1a2008-11-13 22:59:24 +00001124 $parameters = $array;
1125 }
1126 else
1127 {
1128 $parameters = array();
Barry Mienydd671972010-10-04 16:33:58 +02001129
Andrey Andreeva30faf92011-12-25 18:15:34 +02001130 for ($i = 0, $c = count($this->params); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001131 {
1132 $a_param = $this->decode_message($this->params[$i]);
Barry Mienydd671972010-10-04 16:33:58 +02001133
Derek Allard2067d1a2008-11-13 22:59:24 +00001134 if (is_array($a_param))
1135 {
1136 $parameters[] = $this->output_parameters($a_param);
1137 }
1138 else
1139 {
Robin Sowell66a3fc02010-03-18 09:44:55 -04001140 $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param;
Derek Allard2067d1a2008-11-13 22:59:24 +00001141 }
Barry Mienydd671972010-10-04 16:33:58 +02001142 }
Derek Allard2067d1a2008-11-13 22:59:24 +00001143 }
Barry Mienydd671972010-10-04 16:33:58 +02001144
Derek Allard2067d1a2008-11-13 22:59:24 +00001145 return $parameters;
1146 }
Barry Mienydd671972010-10-04 16:33:58 +02001147
1148
Andrey Andreeva30faf92011-12-25 18:15:34 +02001149 public function decode_message($param)
Derek Allard2067d1a2008-11-13 22:59:24 +00001150 {
1151 $kind = $param->kindOf();
1152
Pascal Kriete14287f32011-02-14 13:39:34 -05001153 if ($kind == 'scalar')
Derek Allard2067d1a2008-11-13 22:59:24 +00001154 {
1155 return $param->scalarval();
1156 }
Pascal Kriete14287f32011-02-14 13:39:34 -05001157 elseif ($kind == 'array')
Derek Allard2067d1a2008-11-13 22:59:24 +00001158 {
1159 reset($param->me);
Andrey Andreevadc11752011-12-30 14:46:08 +02001160 $b = current($param->me);
Derek Allard2067d1a2008-11-13 22:59:24 +00001161 $arr = array();
1162
Andrey Andreeva30faf92011-12-25 18:15:34 +02001163 for($i = 0, $c = count($b); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001164 {
1165 $arr[] = $this->decode_message($param->me['array'][$i]);
1166 }
Barry Mienydd671972010-10-04 16:33:58 +02001167
Derek Allard2067d1a2008-11-13 22:59:24 +00001168 return $arr;
1169 }
Pascal Kriete14287f32011-02-14 13:39:34 -05001170 elseif ($kind == 'struct')
Derek Allard2067d1a2008-11-13 22:59:24 +00001171 {
1172 reset($param->me['struct']);
Derek Allard2067d1a2008-11-13 22:59:24 +00001173 $arr = array();
1174
Pascal Kriete14287f32011-02-14 13:39:34 -05001175 while (list($key,$value) = each($param->me['struct']))
Derek Allard2067d1a2008-11-13 22:59:24 +00001176 {
1177 $arr[$key] = $this->decode_message($value);
1178 }
Barry Mienydd671972010-10-04 16:33:58 +02001179
Derek Allard2067d1a2008-11-13 22:59:24 +00001180 return $arr;
1181 }
1182 }
Barry Mienydd671972010-10-04 16:33:58 +02001183
Andrey Andreeva30faf92011-12-25 18:15:34 +02001184}
1185// End XML_RPC_Messages class
Derek Allard2067d1a2008-11-13 22:59:24 +00001186
1187/**
1188 * XML-RPC Values class
1189 *
1190 * @category XML-RPC
Derek Jonesf4a4bd82011-10-20 12:18:42 -05001191 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +00001192 * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html
1193 */
1194class XML_RPC_Values extends CI_Xmlrpc
1195{
Andrey Andreeva30faf92011-12-25 18:15:34 +02001196 public $me = array();
1197 public $mytype = 0;
Derek Allard2067d1a2008-11-13 22:59:24 +00001198
Andrey Andreeva30faf92011-12-25 18:15:34 +02001199 public function __construct($val = -1, $type = '')
Barry Mienydd671972010-10-04 16:33:58 +02001200 {
Greg Akera9263282010-11-10 15:26:43 -06001201 parent::__construct();
Barry Mienydd671972010-10-04 16:33:58 +02001202
Derek Allard2067d1a2008-11-13 22:59:24 +00001203 if ($val != -1 OR $type != '')
1204 {
1205 $type = $type == '' ? 'string' : $type;
Barry Mienydd671972010-10-04 16:33:58 +02001206
Derek Allard2067d1a2008-11-13 22:59:24 +00001207 if ($this->xmlrpcTypes[$type] == 1)
1208 {
1209 $this->addScalar($val,$type);
1210 }
1211 elseif ($this->xmlrpcTypes[$type] == 2)
1212 {
1213 $this->addArray($val);
1214 }
1215 elseif ($this->xmlrpcTypes[$type] == 3)
1216 {
1217 $this->addStruct($val);
1218 }
1219 }
1220 }
1221
Andrey Andreeva30faf92011-12-25 18:15:34 +02001222 public function addScalar($val, $type = 'string')
Derek Allard2067d1a2008-11-13 22:59:24 +00001223 {
1224 $typeof = $this->xmlrpcTypes[$type];
Barry Mienydd671972010-10-04 16:33:58 +02001225
Derek Allard2067d1a2008-11-13 22:59:24 +00001226 if ($this->mytype==1)
1227 {
1228 echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />';
1229 return 0;
1230 }
Barry Mienydd671972010-10-04 16:33:58 +02001231
Derek Allard2067d1a2008-11-13 22:59:24 +00001232 if ($typeof != 1)
1233 {
1234 echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />';
1235 return 0;
1236 }
1237
1238 if ($type == $this->xmlrpcBoolean)
1239 {
Andrey Andreeva30faf92011-12-25 18:15:34 +02001240 $val = (strcasecmp($val,'true') === 0 OR $val == 1 OR ($val == true && strcasecmp($val, 'false'))) ? 1 : 0;
Derek Allard2067d1a2008-11-13 22:59:24 +00001241 }
1242
1243 if ($this->mytype == 2)
1244 {
1245 // adding to an array here
1246 $ar = $this->me['array'];
1247 $ar[] = new XML_RPC_Values($val, $type);
1248 $this->me['array'] = $ar;
1249 }
1250 else
1251 {
1252 // a scalar, so set the value and remember we're scalar
1253 $this->me[$type] = $val;
1254 $this->mytype = $typeof;
1255 }
1256 return 1;
1257 }
1258
Andrey Andreeva30faf92011-12-25 18:15:34 +02001259 public function addArray($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001260 {
1261 if ($this->mytype != 0)
1262 {
1263 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
1264 return 0;
1265 }
1266
1267 $this->mytype = $this->xmlrpcTypes['array'];
1268 $this->me['array'] = $vals;
1269 return 1;
1270 }
1271
Andrey Andreeva30faf92011-12-25 18:15:34 +02001272 public function addStruct($vals)
Derek Allard2067d1a2008-11-13 22:59:24 +00001273 {
1274 if ($this->mytype != 0)
1275 {
1276 echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />';
1277 return 0;
1278 }
1279 $this->mytype = $this->xmlrpcTypes['struct'];
1280 $this->me['struct'] = $vals;
1281 return 1;
1282 }
1283
Andrey Andreeva30faf92011-12-25 18:15:34 +02001284 public function kindOf()
Derek Allard2067d1a2008-11-13 22:59:24 +00001285 {
1286 switch($this->mytype)
1287 {
1288 case 3:
1289 return 'struct';
1290 break;
1291 case 2:
1292 return 'array';
1293 break;
1294 case 1:
1295 return 'scalar';
1296 break;
1297 default:
1298 return 'undef';
1299 }
1300 }
1301
Andrey Andreeva30faf92011-12-25 18:15:34 +02001302 public function serializedata($typ, $val)
Derek Allard2067d1a2008-11-13 22:59:24 +00001303 {
1304 $rs = '';
Derek Jonesa9647e82010-03-02 22:59:07 -06001305
Derek Allard2067d1a2008-11-13 22:59:24 +00001306 switch($this->xmlrpcTypes[$typ])
1307 {
1308 case 3:
1309 // struct
1310 $rs .= "<struct>\n";
1311 reset($val);
Pascal Kriete14287f32011-02-14 13:39:34 -05001312 while (list($key2, $val2) = each($val))
Derek Allard2067d1a2008-11-13 22:59:24 +00001313 {
Andrey Andreeva30faf92011-12-25 18:15:34 +02001314 $rs .= "<member>\n<name>{$key2}</name>\n".$this->serializeval($val2)."</member>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001315 }
1316 $rs .= '</struct>';
1317 break;
1318 case 2:
1319 // array
1320 $rs .= "<array>\n<data>\n";
Andrey Andreeva30faf92011-12-25 18:15:34 +02001321 for($i = 0, $c = count($val); $i < $c; $i++)
Derek Allard2067d1a2008-11-13 22:59:24 +00001322 {
1323 $rs .= $this->serializeval($val[$i]);
1324 }
Andrey Andreeva30faf92011-12-25 18:15:34 +02001325 $rs .= "</data>\n</array>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001326 break;
1327 case 1:
1328 // others
1329 switch ($typ)
1330 {
1331 case $this->xmlrpcBase64:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001332 $rs .= "<{$typ}>" . base64_encode((string)$val) . "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001333 break;
1334 case $this->xmlrpcBoolean:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001335 $rs .= "<{$typ}>" . ((bool)$val ? '1' : '0') . "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001336 break;
1337 case $this->xmlrpcString:
Derek Jonesb8d3c3d2009-06-24 15:27:01 +00001338 $rs .= "<{$typ}>" . htmlspecialchars((string)$val). "</{$typ}>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001339 break;
1340 default:
1341 $rs .= "<{$typ}>{$val}</{$typ}>\n";
1342 break;
1343 }
1344 default:
1345 break;
1346 }
1347 return $rs;
1348 }
1349
Andrey Andreeva30faf92011-12-25 18:15:34 +02001350 public function serialize_class()
Derek Allard2067d1a2008-11-13 22:59:24 +00001351 {
1352 return $this->serializeval($this);
1353 }
1354
Andrey Andreeva30faf92011-12-25 18:15:34 +02001355 public function serializeval($o)
Derek Allard2067d1a2008-11-13 22:59:24 +00001356 {
1357 $ar = $o->me;
1358 reset($ar);
Barry Mienydd671972010-10-04 16:33:58 +02001359
Derek Allard2067d1a2008-11-13 22:59:24 +00001360 list($typ, $val) = each($ar);
Andrey Andreeva30faf92011-12-25 18:15:34 +02001361 return "<value>\n".$this->serializedata($typ, $val)."</value>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +00001362 }
Barry Mienydd671972010-10-04 16:33:58 +02001363
Andrey Andreeva30faf92011-12-25 18:15:34 +02001364 public function scalarval()
Derek Allard2067d1a2008-11-13 22:59:24 +00001365 {
1366 reset($this->me);
Andrey Andreevadc11752011-12-30 14:46:08 +02001367 return current($this->me);
Derek Allard2067d1a2008-11-13 22:59:24 +00001368 }
1369
1370
1371 //-------------------------------------
1372 // Encode time in ISO-8601 form.
1373 //-------------------------------------
Barry Mienydd671972010-10-04 16:33:58 +02001374
Derek Allard2067d1a2008-11-13 22:59:24 +00001375 // Useful for sending time in XML-RPC
1376
Andrey Andreev62090152011-12-30 12:49:27 +02001377 public function iso8601_encode($time, $utc = 0)
Barry Mienydd671972010-10-04 16:33:58 +02001378 {
Andrey Andreev62090152011-12-30 12:49:27 +02001379 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 +00001380 }
Barry Mienydd671972010-10-04 16:33:58 +02001381
Derek Allard2067d1a2008-11-13 22:59:24 +00001382}
1383// END XML_RPC_Values Class
1384
1385/* End of file Xmlrpc.php */
Andrey Andreeva30faf92011-12-25 18:15:34 +02001386/* Location: ./system/libraries/Xmlrpc.php */