Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Phil Sturgeon | 07c1ac8 | 2012-03-09 17:03:37 +0000 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.2.4 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 8 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 9 | * Licensed under the Open Software License version 3.0 |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 10 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
Andrey Andreev | 80500af | 2013-01-01 08:16:53 +0200 | [diff] [blame] | 21 | * @copyright Copyright (c) 2008 - 2013, EllisLab, Inc. (http://ellislab.com/) |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 27 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 28 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 29 | if ( ! function_exists('xml_parser_create')) |
| 30 | { |
| 31 | show_error('Your PHP installation does not support XML'); |
| 32 | } |
| 33 | |
| 34 | // ------------------------------------------------------------------------ |
| 35 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 36 | /** |
| 37 | * XML-RPC request handler class |
| 38 | * |
| 39 | * @package CodeIgniter |
| 40 | * @subpackage Libraries |
| 41 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 42 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 43 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 44 | */ |
| 45 | class CI_Xmlrpc { |
| 46 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 47 | /** |
| 48 | * Debug flag |
| 49 | * |
| 50 | * @var bool |
| 51 | */ |
| 52 | public $debug = FALSE; |
| 53 | |
| 54 | /** |
| 55 | * I4 data type |
| 56 | * |
| 57 | * @var string |
| 58 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 59 | public $xmlrpcI4 = 'i4'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Integer data type |
| 63 | * |
| 64 | * @var string |
| 65 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 66 | public $xmlrpcInt = 'int'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * Boolean data type |
| 70 | * |
| 71 | * @var string |
| 72 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 73 | public $xmlrpcBoolean = 'boolean'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Double data type |
| 77 | * |
| 78 | * @var string |
| 79 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 80 | public $xmlrpcDouble = 'double'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * String data type |
| 84 | * |
| 85 | * @var string |
| 86 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 87 | public $xmlrpcString = 'string'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * DateTime format |
| 91 | * |
| 92 | * @var string |
| 93 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 94 | public $xmlrpcDateTime = 'dateTime.iso8601'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 95 | |
| 96 | /** |
| 97 | * Base64 data type |
| 98 | * |
| 99 | * @var string |
| 100 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 101 | public $xmlrpcBase64 = 'base64'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Array data type |
| 105 | * |
| 106 | * @var string |
| 107 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 108 | public $xmlrpcArray = 'array'; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 109 | |
| 110 | /** |
| 111 | * Struct data type |
| 112 | * |
| 113 | * @var string |
| 114 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 115 | public $xmlrpcStruct = 'struct'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 116 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 117 | /** |
| 118 | * Data types list |
| 119 | * |
| 120 | * @var array |
| 121 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 122 | public $xmlrpcTypes = array(); |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * Valid parents list |
| 126 | * |
| 127 | * @var array |
| 128 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 129 | public $valid_parents = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 130 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 131 | /** |
| 132 | * Response error numbers list |
| 133 | * |
| 134 | * @var array |
| 135 | */ |
| 136 | public $xmlrpcerr = array(); |
| 137 | |
| 138 | /** |
| 139 | * Response error messages list |
| 140 | * |
| 141 | * @var string[] |
| 142 | */ |
| 143 | public $xmlrpcstr = array(); |
| 144 | |
| 145 | /** |
| 146 | * Encoding charset |
| 147 | * |
| 148 | * @var string |
| 149 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 150 | public $xmlrpc_defencoding = 'UTF-8'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 151 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 152 | /** |
| 153 | * XML-RPC client name |
| 154 | * |
| 155 | * @var string |
| 156 | */ |
| 157 | public $xmlrpcName = 'XML-RPC for CodeIgniter'; |
| 158 | |
| 159 | /** |
| 160 | * XML-RPC version |
| 161 | * |
| 162 | * @var string |
| 163 | */ |
| 164 | public $xmlrpcVersion = '1.1'; |
| 165 | |
| 166 | /** |
| 167 | * Start of user errors |
| 168 | * |
| 169 | * @var int |
| 170 | */ |
| 171 | public $xmlrpcerruser = 800; |
| 172 | |
| 173 | /** |
| 174 | * Start of XML parse errors |
| 175 | * |
| 176 | * @var int |
| 177 | */ |
| 178 | public $xmlrpcerrxml = 100; |
| 179 | |
| 180 | /** |
| 181 | * Backslash replacement value |
| 182 | * |
| 183 | * @var string |
| 184 | */ |
| 185 | public $xmlrpc_backslash = ''; |
| 186 | |
| 187 | /** |
| 188 | * XML-RPC Client object |
| 189 | * |
| 190 | * @var object |
| 191 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 192 | public $client; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * XML-RPC Method name |
| 196 | * |
| 197 | * @var string |
| 198 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 199 | public $method; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * XML-RPC Data |
| 203 | * |
| 204 | * @var array |
| 205 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 206 | public $data; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * XML-RPC Message |
| 210 | * |
| 211 | * @var string |
| 212 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 213 | public $message = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 214 | |
| 215 | /** |
| 216 | * Request error message |
| 217 | * |
| 218 | * @var string |
| 219 | */ |
| 220 | public $error = ''; |
| 221 | |
| 222 | /** |
| 223 | * XML-RPC result object |
| 224 | * |
| 225 | * @var object |
| 226 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 227 | public $result; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 228 | |
| 229 | /** |
| 230 | * XML-RPC Reponse |
| 231 | * |
| 232 | * @var array |
| 233 | */ |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 234 | public $response = array(); // Response from remote server |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 235 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 236 | /** |
| 237 | * XSS Filter flag |
| 238 | * |
| 239 | * @var bool |
| 240 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 241 | public $xss_clean = TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 242 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 243 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 244 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 245 | /** |
| 246 | * Constructor |
| 247 | * |
| 248 | * Initializes property default values |
| 249 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 250 | * @param array $config |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 251 | * @return void |
| 252 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 253 | public function __construct($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 254 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | $this->xmlrpc_backslash = chr(92).chr(92); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 256 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | // Types for info sent back and forth |
| 258 | $this->xmlrpcTypes = array( |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 259 | $this->xmlrpcI4 => '1', |
| 260 | $this->xmlrpcInt => '1', |
| 261 | $this->xmlrpcBoolean => '1', |
| 262 | $this->xmlrpcString => '1', |
| 263 | $this->xmlrpcDouble => '1', |
| 264 | $this->xmlrpcDateTime => '1', |
| 265 | $this->xmlrpcBase64 => '1', |
| 266 | $this->xmlrpcArray => '2', |
| 267 | $this->xmlrpcStruct => '3' |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 268 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 269 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 270 | // Array of Valid Parents for Various XML-RPC elements |
Timothy Warren | 0688ac9 | 2012-04-20 10:25:04 -0400 | [diff] [blame] | 271 | $this->valid_parents = array('BOOLEAN' => array('VALUE'), |
| 272 | 'I4' => array('VALUE'), |
| 273 | 'INT' => array('VALUE'), |
| 274 | 'STRING' => array('VALUE'), |
| 275 | 'DOUBLE' => array('VALUE'), |
| 276 | 'DATETIME.ISO8601' => array('VALUE'), |
| 277 | 'BASE64' => array('VALUE'), |
| 278 | 'ARRAY' => array('VALUE'), |
| 279 | 'STRUCT' => array('VALUE'), |
| 280 | 'PARAM' => array('PARAMS'), |
| 281 | 'METHODNAME' => array('METHODCALL'), |
| 282 | 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'), |
| 283 | 'MEMBER' => array('STRUCT'), |
| 284 | 'NAME' => array('MEMBER'), |
| 285 | 'DATA' => array('ARRAY'), |
| 286 | 'FAULT' => array('METHODRESPONSE'), |
| 287 | 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT') |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 288 | ); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 289 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 290 | // XML-RPC Responses |
| 291 | $this->xmlrpcerr['unknown_method'] = '1'; |
| 292 | $this->xmlrpcstr['unknown_method'] = 'This is not a known method for this XML-RPC Server'; |
| 293 | $this->xmlrpcerr['invalid_return'] = '2'; |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 294 | $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 Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 295 | $this->xmlrpcerr['incorrect_params'] = '3'; |
| 296 | $this->xmlrpcstr['incorrect_params'] = 'Incorrect parameters were passed to method'; |
| 297 | $this->xmlrpcerr['introspect_unknown'] = '4'; |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 298 | $this->xmlrpcstr['introspect_unknown'] = 'Cannot inspect signature for request: method unknown'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 299 | $this->xmlrpcerr['http_error'] = '5'; |
| 300 | $this->xmlrpcstr['http_error'] = "Did not receive a '200 OK' response from remote server."; |
| 301 | $this->xmlrpcerr['no_data'] = '6'; |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 302 | $this->xmlrpcstr['no_data'] = 'No data received from server.'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 303 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 304 | $this->initialize($config); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 305 | |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 306 | log_message('debug', 'XML-RPC Class Initialized'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 307 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 308 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 309 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 310 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 311 | /** |
| 312 | * Initialize |
| 313 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 314 | * @param array $config |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 315 | * @return void |
| 316 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 317 | public function initialize($config = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 318 | { |
Derek Jones | 3355910 | 2009-02-02 18:50:38 +0000 | [diff] [blame] | 319 | if (count($config) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 320 | { |
| 321 | foreach ($config as $key => $val) |
| 322 | { |
| 323 | if (isset($this->$key)) |
| 324 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 325 | $this->$key = $val; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
| 329 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 330 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 331 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 332 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 333 | /** |
| 334 | * Parse server URL |
| 335 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 336 | * @param string $url |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 337 | * @param int $port |
| 338 | * @param string $proxy |
| 339 | * @param int $proxy_port |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 340 | * @return void |
| 341 | */ |
Valentin Sheyretski | cfcf34e | 2012-07-02 12:04:36 +0300 | [diff] [blame] | 342 | public function server($url, $port = 80, $proxy = FALSE, $proxy_port = 8080) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 343 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 344 | if (strpos($url, 'http') !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 345 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 346 | $url = 'http://'.$url; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 347 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 348 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 349 | $parts = parse_url($url); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 350 | |
Andrey Andreev | dc53d7b | 2014-01-07 12:12:11 +0200 | [diff] [blame] | 351 | if (isset($parts['user'], $parts['pass'])) |
| 352 | { |
| 353 | $parts['host'] = $parts['user'].':'.$parts['pass'].'@'.$parts['host']; |
| 354 | } |
| 355 | |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 356 | $path = isset($parts['path']) ? $parts['path'] : '/'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 357 | |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 358 | if ( ! empty($parts['query'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 359 | { |
| 360 | $path .= '?'.$parts['query']; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 361 | } |
| 362 | |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 363 | $this->client = new XML_RPC_Client($path, $parts['host'], $port, $proxy, $proxy_port); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 364 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 365 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 366 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 367 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 368 | /** |
| 369 | * Set Timeout |
| 370 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 371 | * @param int $seconds |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 372 | * @return void |
| 373 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 374 | public function timeout($seconds = 5) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | { |
vlakoff | 1228fe2 | 2013-01-14 01:30:09 +0100 | [diff] [blame] | 376 | if ($this->client !== NULL && is_int($seconds)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 377 | { |
| 378 | $this->client->timeout = $seconds; |
| 379 | } |
| 380 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 381 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 382 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 384 | /** |
| 385 | * Set Methods |
| 386 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 387 | * @param string $function Method name |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 388 | * @return void |
| 389 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 390 | public function method($function) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 391 | { |
| 392 | $this->method = $function; |
| 393 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 394 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 395 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 396 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 397 | /** |
| 398 | * Take Array of Data and Create Objects |
| 399 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 400 | * @param array $incoming |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 401 | * @return void |
| 402 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 403 | public function request($incoming) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 404 | { |
| 405 | if ( ! is_array($incoming)) |
| 406 | { |
| 407 | // Send Error |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 408 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 409 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 410 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | $this->data = array(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 412 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 413 | foreach ($incoming as $key => $value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | { |
| 415 | $this->data[$key] = $this->values_parsing($value); |
| 416 | } |
| 417 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 418 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 419 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 420 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 421 | /** |
| 422 | * Set Debug |
| 423 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 424 | * @param bool $flag |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 425 | * @return void |
| 426 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 427 | public function set_debug($flag = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 428 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 429 | $this->debug = ($flag === TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 431 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 432 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 434 | /** |
| 435 | * Values Parsing |
| 436 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 437 | * @param mixed $value |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 438 | * @return object |
| 439 | */ |
| 440 | public function values_parsing($value) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 441 | { |
Derek Jones | 8c4b5e7 | 2010-01-06 22:21:41 +0000 | [diff] [blame] | 442 | if (is_array($value) && array_key_exists(0, $value)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 443 | { |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 444 | if ( ! isset($value[1], $this->xmlrpcTypes[$value[1]])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 445 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 446 | $temp = new XML_RPC_Values($value[0], (is_array($value[0]) ? 'array' : 'string')); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 447 | } |
| 448 | else |
| 449 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 450 | if (is_array($value[0]) && ($value[1] === 'struct' OR $value[1] === 'array')) |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 451 | { |
| 452 | while (list($k) = each($value[0])) |
| 453 | { |
Rasmus Lerdorf | 9986070 | 2013-05-18 10:27:12 -0400 | [diff] [blame] | 454 | $value[0][$k] = $this->values_parsing($value[0][$k]); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | $temp = new XML_RPC_Values($value[0], $value[1]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | $temp = new XML_RPC_Values($value, 'string'); |
| 464 | } |
| 465 | |
| 466 | return $temp; |
| 467 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 468 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 469 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 471 | /** |
| 472 | * Sends XML-RPC Request |
| 473 | * |
| 474 | * @return bool |
| 475 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 476 | public function send_request() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 478 | $this->message = new XML_RPC_Message($this->method, $this->data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | $this->message->debug = $this->debug; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 480 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 481 | if ( ! $this->result = $this->client->send($this->message) OR ! is_object($this->result->val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 482 | { |
| 483 | $this->error = $this->result->errstr; |
| 484 | return FALSE; |
| 485 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 486 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 487 | $this->response = $this->result->decode(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | return TRUE; |
| 489 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 490 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 491 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 492 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 493 | /** |
| 494 | * Returns Error |
| 495 | * |
| 496 | * @return string |
| 497 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 498 | public function display_error() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | { |
| 500 | return $this->error; |
| 501 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 502 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 503 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 504 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 505 | /** |
| 506 | * Returns Remote Server Response |
| 507 | * |
| 508 | * @return string |
| 509 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 510 | public function display_response() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 511 | { |
| 512 | return $this->response; |
| 513 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 514 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 515 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 516 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 517 | /** |
| 518 | * Sends an Error Message for Server Request |
| 519 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 520 | * @param int $number |
| 521 | * @param string $message |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 522 | * @return object |
| 523 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 524 | public function send_error_message($number, $message) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 525 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 526 | return new XML_RPC_Response(0, $number, $message); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 528 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 529 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 530 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 531 | /** |
| 532 | * Send Response for Server Request |
| 533 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 534 | * @param array $response |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 535 | * @return object |
| 536 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 537 | public function send_response($response) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 538 | { |
| 539 | // $response should be array of values, which will be parsed |
| 540 | // based on their data and type into a valid group of XML-RPC values |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 541 | return new XML_RPC_Response($this->values_parsing($response)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 542 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 543 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 544 | } // END XML_RPC Class |
| 545 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 546 | /** |
| 547 | * XML-RPC Client class |
| 548 | * |
| 549 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 550 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 552 | */ |
| 553 | class XML_RPC_Client extends CI_Xmlrpc |
| 554 | { |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 555 | /** |
| 556 | * Path |
| 557 | * |
| 558 | * @var string |
| 559 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 560 | public $path = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 561 | |
| 562 | /** |
| 563 | * Server hostname |
| 564 | * |
| 565 | * @var string |
| 566 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 567 | public $server = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 568 | |
| 569 | /** |
| 570 | * Server port |
| 571 | * |
| 572 | * @var int |
| 573 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 574 | public $port = 80; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 575 | |
| 576 | /** |
Andrey Andreev | dc53d7b | 2014-01-07 12:12:11 +0200 | [diff] [blame] | 577 | * |
| 578 | * Server username |
| 579 | * |
| 580 | * @var string |
| 581 | */ |
| 582 | public $username; |
| 583 | |
| 584 | /** |
| 585 | * Server password |
| 586 | * |
| 587 | * @var string |
| 588 | */ |
| 589 | public $password; |
| 590 | |
| 591 | /** |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 592 | * Proxy hostname |
| 593 | * |
| 594 | * @var string |
| 595 | */ |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 596 | public $proxy = FALSE; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 597 | |
| 598 | /** |
| 599 | * Proxy port |
| 600 | * |
| 601 | * @var int |
| 602 | */ |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 603 | public $proxy_port = 8080; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 604 | |
| 605 | /** |
| 606 | * Error number |
| 607 | * |
| 608 | * @var string |
| 609 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 610 | public $errno = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 611 | |
| 612 | /** |
| 613 | * Error message |
| 614 | * |
| 615 | * @var string |
| 616 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 617 | public $errstring = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * Timeout in seconds |
| 621 | * |
| 622 | * @var int |
| 623 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 624 | public $timeout = 5; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 625 | |
| 626 | /** |
| 627 | * No Multicall flag |
| 628 | * |
| 629 | * @var bool |
| 630 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 631 | public $no_multicall = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 632 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 633 | // -------------------------------------------------------------------- |
| 634 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 635 | /** |
| 636 | * Constructor |
| 637 | * |
Andrey Andreev | 5fd3ae8 | 2012-10-24 14:55:35 +0300 | [diff] [blame] | 638 | * @param string $path |
| 639 | * @param object $server |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 640 | * @param int $port |
| 641 | * @param string $proxy |
| 642 | * @param int $proxy_port |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 643 | * @return void |
| 644 | */ |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 645 | public function __construct($path, $server, $port = 80, $proxy = FALSE, $proxy_port = 8080) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 646 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 647 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 648 | |
Andrey Andreev | dc53d7b | 2014-01-07 12:12:11 +0200 | [diff] [blame] | 649 | $url = parse_url('http://'.$server); |
| 650 | |
| 651 | if (isset($url['user'], $url['pass'])) |
| 652 | { |
| 653 | $this->username = $url['user']; |
| 654 | $this->password = $url['pass']; |
| 655 | } |
| 656 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 657 | $this->port = $port; |
Andrey Andreev | dc53d7b | 2014-01-07 12:12:11 +0200 | [diff] [blame] | 658 | $this->server = $url['host']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 659 | $this->path = $path; |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 660 | $this->proxy = $proxy; |
| 661 | $this->proxy_port = $proxy_port; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 662 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 663 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 664 | // -------------------------------------------------------------------- |
| 665 | |
| 666 | /** |
| 667 | * Send message |
| 668 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 669 | * @param mixed $msg |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 670 | * @return object |
| 671 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 672 | public function send($msg) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 673 | { |
| 674 | if (is_array($msg)) |
| 675 | { |
| 676 | // Multi-call disabled |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 677 | return new XML_RPC_Response(0, $this->xmlrpcerr['multicall_recursion'], $this->xmlrpcstr['multicall_recursion']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | return $this->sendPayload($msg); |
| 681 | } |
| 682 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 683 | // -------------------------------------------------------------------- |
| 684 | |
| 685 | /** |
| 686 | * Send payload |
| 687 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 688 | * @param object $msg |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 689 | * @return object |
| 690 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 691 | public function sendPayload($msg) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 692 | { |
Andrey Andreev | c02e7c5 | 2012-07-02 16:43:43 +0300 | [diff] [blame] | 693 | if ($this->proxy === FALSE) |
Valentin Sheyretski | cfcf34e | 2012-07-02 12:04:36 +0300 | [diff] [blame] | 694 | { |
| 695 | $server = $this->server; |
| 696 | $port = $this->port; |
Valentin Sheyretski | 09217ce | 2012-07-02 16:27:01 +0300 | [diff] [blame] | 697 | } |
| 698 | else |
| 699 | { |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 700 | $server = $this->proxy; |
| 701 | $port = $this->proxy_port; |
| 702 | } |
Valentin Sheyretski | cfcf34e | 2012-07-02 12:04:36 +0300 | [diff] [blame] | 703 | |
Valio | 9dee535 | 2012-07-02 10:42:28 +0300 | [diff] [blame] | 704 | $fp = @fsockopen($server, $port, $this->errno, $this->errstring, $this->timeout); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 705 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 706 | if ( ! is_resource($fp)) |
| 707 | { |
| 708 | error_log($this->xmlrpcstr['http_error']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 709 | return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 710 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 711 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 712 | if (empty($msg->payload)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 713 | { |
| 714 | // $msg = XML_RPC_Messages |
| 715 | $msg->createPayload(); |
| 716 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 717 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 718 | $r = "\r\n"; |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 719 | $op = 'POST '.$this->path.' HTTP/1.0'.$r |
| 720 | .'Host: '.$this->server.$r |
| 721 | .'Content-Type: text/xml'.$r |
Andrey Andreev | dc53d7b | 2014-01-07 12:12:11 +0200 | [diff] [blame] | 722 | .(isset($this->username, $this->password) ? 'Authorization: Basic '.base64_encode($this->username.':'.$this->password).$r : '') |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 723 | .'User-Agent: '.$this->xmlrpcName.$r |
| 724 | .'Content-Length: '.strlen($msg->payload).$r.$r |
| 725 | .$msg->payload; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 726 | |
George Petsagourakis | 306b378 | 2012-05-02 20:31:08 +0300 | [diff] [blame] | 727 | if ( ! fwrite($fp, $op, strlen($op))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 728 | { |
| 729 | error_log($this->xmlrpcstr['http_error']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 730 | return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 731 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 732 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 733 | $resp = $msg->parseResponse($fp); |
| 734 | fclose($fp); |
| 735 | return $resp; |
| 736 | } |
| 737 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 738 | } // END XML_RPC_Client Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 739 | |
| 740 | /** |
| 741 | * XML-RPC Response class |
| 742 | * |
| 743 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 744 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 745 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 746 | */ |
| 747 | class XML_RPC_Response |
| 748 | { |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 749 | |
| 750 | /** |
| 751 | * Value |
| 752 | * |
| 753 | * @var mixed |
| 754 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 755 | public $val = 0; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 756 | |
| 757 | /** |
| 758 | * Error number |
| 759 | * |
| 760 | * @var int |
| 761 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 762 | public $errno = 0; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 763 | |
| 764 | /** |
| 765 | * Error message |
| 766 | * |
| 767 | * @var string |
| 768 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 769 | public $errstr = ''; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 770 | |
| 771 | /** |
| 772 | * Headers list |
| 773 | * |
| 774 | * @var array |
| 775 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 776 | public $headers = array(); |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 777 | |
| 778 | /** |
| 779 | * XSS Filter flag |
| 780 | * |
| 781 | * @var bool |
| 782 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 783 | public $xss_clean = TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 784 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 785 | // -------------------------------------------------------------------- |
| 786 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 787 | /** |
| 788 | * Constructor |
| 789 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 790 | * @param mixed $val |
| 791 | * @param int $code |
| 792 | * @param string $fstr |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 793 | * @return void |
| 794 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 795 | public function __construct($val, $code = 0, $fstr = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 796 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 797 | if ($code !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 798 | { |
| 799 | // error |
| 800 | $this->errno = $code; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 801 | $this->errstr = htmlspecialchars($fstr, |
| 802 | (is_php('5.4') ? ENT_XML1 | ENT_NOQUOTES : ENT_NOQUOTES), |
| 803 | 'UTF-8'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 804 | } |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 805 | elseif ( ! is_object($val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 806 | { |
| 807 | // programmer error, not an object |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 808 | error_log("Invalid type '".gettype($val)."' (value: ".$val.') passed to XML_RPC_Response. Defaulting to empty value.'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 809 | $this->val = new XML_RPC_Values(); |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | $this->val = $val; |
| 814 | } |
| 815 | } |
| 816 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 817 | // -------------------------------------------------------------------- |
| 818 | |
| 819 | /** |
| 820 | * Fault code |
| 821 | * |
| 822 | * @return int |
| 823 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 824 | public function faultCode() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 825 | { |
| 826 | return $this->errno; |
| 827 | } |
| 828 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 829 | // -------------------------------------------------------------------- |
| 830 | |
| 831 | /** |
| 832 | * Fault string |
| 833 | * |
| 834 | * @return string |
| 835 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 836 | public function faultString() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 837 | { |
| 838 | return $this->errstr; |
| 839 | } |
| 840 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 841 | // -------------------------------------------------------------------- |
| 842 | |
| 843 | /** |
| 844 | * Value |
| 845 | * |
| 846 | * @return mixed |
| 847 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 848 | public function value() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 849 | { |
| 850 | return $this->val; |
| 851 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 852 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 853 | // -------------------------------------------------------------------- |
| 854 | |
| 855 | /** |
| 856 | * Prepare response |
| 857 | * |
| 858 | * @return string xml |
| 859 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 860 | public function prepare_response() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 861 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 862 | return "<methodResponse>\n" |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 863 | .($this->errno |
| 864 | ? '<fault> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 865 | <value> |
| 866 | <struct> |
| 867 | <member> |
| 868 | <name>faultCode</name> |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 869 | <value><int>'.$this->errno.'</int></value> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 870 | </member> |
| 871 | <member> |
| 872 | <name>faultString</name> |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 873 | <value><string>'.$this->errstr.'</string></value> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 874 | </member> |
| 875 | </struct> |
| 876 | </value> |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 877 | </fault>' |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 878 | : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>") |
| 879 | ."\n</methodResponse>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 880 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 881 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 882 | // -------------------------------------------------------------------- |
| 883 | |
| 884 | /** |
| 885 | * Decode |
| 886 | * |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 887 | * @param mixed $array |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 888 | * @return array |
| 889 | */ |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 890 | public function decode($array = NULL) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 891 | { |
| 892 | $CI =& get_instance(); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 893 | |
| 894 | if (is_array($array)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 895 | { |
| 896 | while (list($key) = each($array)) |
| 897 | { |
| 898 | if (is_array($array[$key])) |
| 899 | { |
| 900 | $array[$key] = $this->decode($array[$key]); |
| 901 | } |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 902 | elseif ($this->xss_clean) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 903 | { |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 904 | $array[$key] = $CI->security->xss_clean($array[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 905 | } |
| 906 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 907 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 908 | return $array; |
| 909 | } |
| 910 | |
| 911 | $result = $this->xmlrpc_decoder($this->val); |
| 912 | |
| 913 | if (is_array($result)) |
| 914 | { |
| 915 | $result = $this->decode($result); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 916 | } |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 917 | elseif ($this->xss_clean) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 918 | { |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 919 | $result = $CI->security->xss_clean($result); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 920 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 921 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 922 | return $result; |
| 923 | } |
| 924 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 925 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 926 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 927 | /** |
| 928 | * XML-RPC Object to PHP Types |
| 929 | * |
| 930 | * @param object |
| 931 | * @return array |
| 932 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 933 | public function xmlrpc_decoder($xmlrpc_val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 934 | { |
| 935 | $kind = $xmlrpc_val->kindOf(); |
| 936 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 937 | if ($kind === 'scalar') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 938 | { |
| 939 | return $xmlrpc_val->scalarval(); |
| 940 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 941 | elseif ($kind === 'array') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 942 | { |
| 943 | reset($xmlrpc_val->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 944 | $b = current($xmlrpc_val->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 945 | $arr = array(); |
| 946 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 947 | for ($i = 0, $size = count($b); $i < $size; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 948 | { |
| 949 | $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); |
| 950 | } |
| 951 | return $arr; |
| 952 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 953 | elseif ($kind === 'struct') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 954 | { |
| 955 | reset($xmlrpc_val->me['struct']); |
| 956 | $arr = array(); |
| 957 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 958 | while (list($key,$value) = each($xmlrpc_val->me['struct'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 959 | { |
| 960 | $arr[$key] = $this->xmlrpc_decoder($value); |
| 961 | } |
| 962 | return $arr; |
| 963 | } |
| 964 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 965 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 966 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 967 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 968 | /** |
| 969 | * ISO-8601 time to server or UTC time |
| 970 | * |
| 971 | * @param string |
| 972 | * @param bool |
| 973 | * @return int unix timestamp |
| 974 | */ |
| 975 | public function iso8601_decode($time, $utc = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 976 | { |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 977 | // Return a time in the localtime, or UTC |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 978 | $t = 0; |
| 979 | if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) |
| 980 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 981 | $fnc = ($utc === TRUE) ? 'gmmktime' : 'mktime'; |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 982 | $t = $fnc($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 983 | } |
| 984 | return $t; |
| 985 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 986 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 987 | } // END XML_RPC_Response Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 988 | |
| 989 | /** |
| 990 | * XML-RPC Message class |
| 991 | * |
| 992 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 993 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 994 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 995 | */ |
| 996 | class XML_RPC_Message extends CI_Xmlrpc |
| 997 | { |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 998 | |
| 999 | /** |
| 1000 | * Payload |
| 1001 | * |
| 1002 | * @var string |
| 1003 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1004 | public $payload; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1005 | |
| 1006 | /** |
| 1007 | * Method name |
| 1008 | * |
| 1009 | * @var string |
| 1010 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1011 | public $method_name; |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1012 | |
| 1013 | /** |
| 1014 | * Parameter list |
| 1015 | * |
| 1016 | * @var array |
| 1017 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1018 | public $params = array(); |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1019 | |
| 1020 | /** |
| 1021 | * XH? |
| 1022 | * |
| 1023 | * @var array |
| 1024 | */ |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1025 | public $xh = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1027 | // -------------------------------------------------------------------- |
| 1028 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1029 | /** |
| 1030 | * Constructor |
| 1031 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1032 | * @param string $method |
| 1033 | * @param array $pars |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1034 | * @return void |
| 1035 | */ |
| 1036 | public function __construct($method, $pars = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1037 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 1038 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1039 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1040 | $this->method_name = $method; |
Derek Jones | 3355910 | 2009-02-02 18:50:38 +0000 | [diff] [blame] | 1041 | if (is_array($pars) && count($pars) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1042 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1043 | for ($i = 0, $c = count($pars); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1044 | { |
| 1045 | // $pars[$i] = XML_RPC_Values |
| 1046 | $this->params[] = $pars[$i]; |
| 1047 | } |
| 1048 | } |
| 1049 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1050 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1051 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1052 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1053 | /** |
| 1054 | * Create Payload to Send |
| 1055 | * |
| 1056 | * @return void |
| 1057 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1058 | public function createPayload() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1059 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1060 | $this->payload = '<?xml version="1.0"?'.">\r\n<methodCall>\r\n" |
| 1061 | .'<methodName>'.$this->method_name."</methodName>\r\n" |
| 1062 | ."<params>\r\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1063 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1064 | for ($i = 0, $c = count($this->params); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1065 | { |
| 1066 | // $p = XML_RPC_Values |
| 1067 | $p = $this->params[$i]; |
| 1068 | $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n"; |
| 1069 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1070 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1071 | $this->payload .= "</params>\r\n</methodCall>\r\n"; |
| 1072 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1073 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1074 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1075 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1076 | /** |
| 1077 | * Parse External XML-RPC Server's Response |
| 1078 | * |
| 1079 | * @param resource |
| 1080 | * @return object |
| 1081 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1082 | public function parseResponse($fp) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1083 | { |
| 1084 | $data = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1085 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1086 | while ($datum = fread($fp, 4096)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1087 | { |
| 1088 | $data .= $datum; |
| 1089 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1090 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1091 | // Display HTTP content for debugging |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1092 | if ($this->debug === TRUE) |
| 1093 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1094 | echo "<pre>---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n</pre>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1095 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1096 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1097 | // Check for data |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1098 | if ($data === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1099 | { |
| 1100 | error_log($this->xmlrpcstr['no_data']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1101 | return new XML_RPC_Response(0, $this->xmlrpcerr['no_data'], $this->xmlrpcstr['no_data']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1102 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1103 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1104 | // Check for HTTP 200 Response |
Andrey Andreev | 3dad2e7 | 2012-06-14 15:10:56 +0300 | [diff] [blame] | 1105 | if (strpos($data, 'HTTP') === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1106 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1107 | $errstr = substr($data, 0, strpos($data, "\n")-1); |
| 1108 | return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error'].' ('.$errstr.')'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1109 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1110 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1111 | //------------------------------------- |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1112 | // Create and Set Up XML Parser |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1113 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1114 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1115 | $parser = xml_parser_create($this->xmlrpc_defencoding); |
| 1116 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1117 | $this->xh[$parser] = array( |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1118 | 'isf' => 0, |
| 1119 | 'ac' => '', |
| 1120 | 'headers' => array(), |
| 1121 | 'stack' => array(), |
| 1122 | 'valuestack' => array(), |
| 1123 | 'isf_reason' => 0 |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1124 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1125 | |
| 1126 | xml_set_object($parser, $this); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1127 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1128 | xml_set_element_handler($parser, 'open_tag', 'closing_tag'); |
| 1129 | xml_set_character_data_handler($parser, 'character_data'); |
| 1130 | //xml_set_default_handler($parser, 'default_handler'); |
| 1131 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1132 | // Get headers |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1133 | $lines = explode("\r\n", $data); |
| 1134 | while (($line = array_shift($lines))) |
| 1135 | { |
| 1136 | if (strlen($line) < 1) |
| 1137 | { |
| 1138 | break; |
| 1139 | } |
| 1140 | $this->xh[$parser]['headers'][] = $line; |
| 1141 | } |
| 1142 | $data = implode("\r\n", $lines); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1143 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1144 | // Parse XML data |
Derek Jones | 3355910 | 2009-02-02 18:50:38 +0000 | [diff] [blame] | 1145 | if ( ! xml_parse($parser, $data, count($data))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1146 | { |
| 1147 | $errstr = sprintf('XML error: %s at line %d', |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1148 | xml_error_string(xml_get_error_code($parser)), |
| 1149 | xml_get_current_line_number($parser)); |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1150 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1151 | $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); |
| 1152 | xml_parser_free($parser); |
| 1153 | return $r; |
| 1154 | } |
| 1155 | xml_parser_free($parser); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1156 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1157 | // Got ourselves some badness, it seems |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1158 | if ($this->xh[$parser]['isf'] > 1) |
| 1159 | { |
| 1160 | if ($this->debug === TRUE) |
| 1161 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1162 | echo "---Invalid Return---\n".$this->xh[$parser]['isf_reason']."---Invalid Return---\n\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1163 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1164 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1165 | return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1166 | } |
| 1167 | elseif ( ! is_object($this->xh[$parser]['value'])) |
| 1168 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1169 | return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$parser]['isf_reason']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1170 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1171 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1172 | // Display XML content for debugging |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1173 | if ($this->debug === TRUE) |
| 1174 | { |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 1175 | echo '<pre>'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1176 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1177 | if (count($this->xh[$parser]['headers'] > 0)) |
| 1178 | { |
| 1179 | echo "---HEADERS---\n"; |
| 1180 | foreach ($this->xh[$parser]['headers'] as $header) |
| 1181 | { |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 1182 | echo $header."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1183 | } |
| 1184 | echo "---END HEADERS---\n\n"; |
| 1185 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1186 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1187 | echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1188 | var_dump($this->xh[$parser]['value']); |
| 1189 | echo "\n---END PARSED---</pre>"; |
| 1190 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1191 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1192 | // Send response |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1193 | $v = $this->xh[$parser]['value']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1194 | if ($this->xh[$parser]['isf']) |
| 1195 | { |
| 1196 | $errno_v = $v->me['struct']['faultCode']; |
| 1197 | $errstr_v = $v->me['struct']['faultString']; |
| 1198 | $errno = $errno_v->scalarval(); |
| 1199 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1200 | if ($errno === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1201 | { |
| 1202 | // FAULT returned, errno needs to reflect that |
| 1203 | $errno = -1; |
| 1204 | } |
| 1205 | |
| 1206 | $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); |
| 1207 | } |
| 1208 | else |
| 1209 | { |
| 1210 | $r = new XML_RPC_Response($v); |
| 1211 | } |
| 1212 | |
| 1213 | $r->headers = $this->xh[$parser]['headers']; |
| 1214 | return $r; |
| 1215 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1216 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1217 | // -------------------------------------------------------------------- |
| 1218 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1219 | // ------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1220 | // Begin Return Message Parsing section |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1221 | // ------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1222 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1223 | // quick explanation of components: |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1224 | // ac - used to accumulate values |
| 1225 | // isf - used to indicate a fault |
| 1226 | // lv - used to indicate "looking for a value": implements |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1227 | // the logic to allow values with no types to be strings |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1228 | // params - used to store parameters in method calls |
| 1229 | // method - used to store method name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1230 | // stack - array with parent tree of the xml element, |
| 1231 | // used to validate the nesting of elements |
| 1232 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1233 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1234 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1235 | /** |
| 1236 | * Start Element Handler |
| 1237 | * |
| 1238 | * @param string |
| 1239 | * @param string |
| 1240 | * @return void |
| 1241 | */ |
| 1242 | public function open_tag($the_parser, $name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1243 | { |
| 1244 | // If invalid nesting, then return |
| 1245 | if ($this->xh[$the_parser]['isf'] > 1) return; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1246 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1247 | // Evaluate and check for correct nesting of XML elements |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1248 | if (count($this->xh[$the_parser]['stack']) === 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1249 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1250 | if ($name !== 'METHODRESPONSE' && $name !== 'METHODCALL') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1251 | { |
| 1252 | $this->xh[$the_parser]['isf'] = 2; |
| 1253 | $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; |
| 1254 | return; |
| 1255 | } |
| 1256 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1257 | // not top level element: see if parent is OK |
| 1258 | elseif ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1259 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1260 | $this->xh[$the_parser]['isf'] = 2; |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1261 | $this->xh[$the_parser]['isf_reason'] = 'XML-RPC element '.$name.' cannot be child of '.$this->xh[$the_parser]['stack'][0]; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1262 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1263 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1264 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1265 | switch ($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1266 | { |
| 1267 | case 'STRUCT': |
| 1268 | case 'ARRAY': |
| 1269 | // Creates array for child elements |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 1270 | $cur_val = array('value' => array(), 'type' => $name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1271 | array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1272 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1273 | case 'METHODNAME': |
| 1274 | case 'NAME': |
| 1275 | $this->xh[$the_parser]['ac'] = ''; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1276 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1277 | case 'FAULT': |
| 1278 | $this->xh[$the_parser]['isf'] = 1; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1279 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1280 | case 'PARAM': |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 1281 | $this->xh[$the_parser]['value'] = NULL; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1282 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1283 | case 'VALUE': |
| 1284 | $this->xh[$the_parser]['vt'] = 'value'; |
| 1285 | $this->xh[$the_parser]['ac'] = ''; |
| 1286 | $this->xh[$the_parser]['lv'] = 1; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1287 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1288 | case 'I4': |
| 1289 | case 'INT': |
| 1290 | case 'STRING': |
| 1291 | case 'BOOLEAN': |
| 1292 | case 'DOUBLE': |
| 1293 | case 'DATETIME.ISO8601': |
| 1294 | case 'BASE64': |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1295 | if ($this->xh[$the_parser]['vt'] !== 'value') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1296 | { |
| 1297 | //two data elements inside a value: an error occurred! |
| 1298 | $this->xh[$the_parser]['isf'] = 2; |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1299 | $this->xh[$the_parser]['isf_reason'] = 'There is a '.$name.' element following a ' |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1300 | .$this->xh[$the_parser]['vt'].' element inside a single value'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1301 | return; |
| 1302 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1303 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1304 | $this->xh[$the_parser]['ac'] = ''; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1305 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1306 | case 'MEMBER': |
| 1307 | // Set name of <member> to nothing to prevent errors later if no <name> is found |
| 1308 | $this->xh[$the_parser]['valuestack'][0]['name'] = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1309 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1310 | // Set NULL value to check to see if value passed for this param/member |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 1311 | $this->xh[$the_parser]['value'] = NULL; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1312 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1313 | case 'DATA': |
| 1314 | case 'METHODCALL': |
| 1315 | case 'METHODRESPONSE': |
| 1316 | case 'PARAMS': |
| 1317 | // valid elements that add little to processing |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1318 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1319 | default: |
| 1320 | /// An Invalid Element is Found, so we have trouble |
| 1321 | $this->xh[$the_parser]['isf'] = 2; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1322 | $this->xh[$the_parser]['isf_reason'] = 'Invalid XML-RPC element found: '.$name; |
| 1323 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1324 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1325 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1326 | // Add current element name to stack, to allow validation of nesting |
| 1327 | array_unshift($this->xh[$the_parser]['stack'], $name); |
| 1328 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1329 | $name === 'VALUE' OR $this->xh[$the_parser]['lv'] = 0; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1330 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1331 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1332 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1333 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1334 | /** |
| 1335 | * End Element Handler |
| 1336 | * |
| 1337 | * @param string |
| 1338 | * @param string |
| 1339 | * @return void |
| 1340 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1341 | public function closing_tag($the_parser, $name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1342 | { |
| 1343 | if ($this->xh[$the_parser]['isf'] > 1) return; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1344 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1345 | // Remove current element from stack and set variable |
| 1346 | // NOTE: If the XML validates, then we do not have to worry about |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1347 | // the opening and closing of elements. Nesting is checked on the opening |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1348 | // tag so we be safe there as well. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1349 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1350 | $curr_elem = array_shift($this->xh[$the_parser]['stack']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1351 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1352 | switch ($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1353 | { |
| 1354 | case 'STRUCT': |
| 1355 | case 'ARRAY': |
| 1356 | $cur_val = array_shift($this->xh[$the_parser]['valuestack']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1357 | $this->xh[$the_parser]['value'] = isset($cur_val['values']) ? $cur_val['values'] : array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1358 | $this->xh[$the_parser]['vt'] = strtolower($name); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1359 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1360 | case 'NAME': |
| 1361 | $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1362 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1363 | case 'BOOLEAN': |
| 1364 | case 'I4': |
| 1365 | case 'INT': |
| 1366 | case 'STRING': |
| 1367 | case 'DOUBLE': |
| 1368 | case 'DATETIME.ISO8601': |
| 1369 | case 'BASE64': |
| 1370 | $this->xh[$the_parser]['vt'] = strtolower($name); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1371 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1372 | if ($name === 'STRING') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1373 | { |
| 1374 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1375 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1376 | elseif ($name === 'DATETIME.ISO8601') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1377 | { |
| 1378 | $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; |
| 1379 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1380 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1381 | elseif ($name === 'BASE64') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1382 | { |
| 1383 | $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); |
| 1384 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1385 | elseif ($name === 'BOOLEAN') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1386 | { |
| 1387 | // Translated BOOLEAN values to TRUE AND FALSE |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1388 | $this->xh[$the_parser]['value'] = (bool) $this->xh[$the_parser]['ac']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1389 | } |
| 1390 | elseif ($name=='DOUBLE') |
| 1391 | { |
| 1392 | // we have a DOUBLE |
| 1393 | // we must check that only 0123456789-.<space> are characters here |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1394 | $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']) |
| 1395 | ? (float) $this->xh[$the_parser]['ac'] |
| 1396 | : 'ERROR_NON_NUMERIC_FOUND'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1397 | } |
| 1398 | else |
| 1399 | { |
| 1400 | // we have an I4/INT |
| 1401 | // we must check that only 0123456789-<space> are characters here |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1402 | $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']) |
George Petsagourakis | 306b378 | 2012-05-02 20:31:08 +0300 | [diff] [blame] | 1403 | ? (int) $this->xh[$the_parser]['ac'] |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1404 | : 'ERROR_NON_NUMERIC_FOUND'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1405 | } |
| 1406 | $this->xh[$the_parser]['ac'] = ''; |
| 1407 | $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1408 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1409 | case 'VALUE': |
| 1410 | // This if() detects if no scalar was inside <VALUE></VALUE> |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1411 | if ($this->xh[$the_parser]['vt'] == 'value') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1412 | { |
| 1413 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1414 | $this->xh[$the_parser]['vt'] = $this->xmlrpcString; |
| 1415 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1416 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1417 | // build the XML-RPC value out of the data received, and substitute it |
| 1418 | $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1419 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1420 | if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] === 'ARRAY') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1421 | { |
| 1422 | // Array |
| 1423 | $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; |
| 1424 | } |
| 1425 | else |
| 1426 | { |
| 1427 | // Struct |
| 1428 | $this->xh[$the_parser]['value'] = $temp; |
| 1429 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1430 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1431 | case 'MEMBER': |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1432 | $this->xh[$the_parser]['ac'] = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1433 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1434 | // If value add to array in the stack for the last element built |
| 1435 | if ($this->xh[$the_parser]['value']) |
| 1436 | { |
| 1437 | $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; |
| 1438 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1439 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1440 | case 'DATA': |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1441 | $this->xh[$the_parser]['ac'] = ''; |
| 1442 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1443 | case 'PARAM': |
| 1444 | if ($this->xh[$the_parser]['value']) |
| 1445 | { |
| 1446 | $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; |
| 1447 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1448 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1449 | case 'METHODNAME': |
| 1450 | $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1451 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1452 | case 'PARAMS': |
| 1453 | case 'FAULT': |
| 1454 | case 'METHODCALL': |
| 1455 | case 'METHORESPONSE': |
| 1456 | // We're all good kids with nuthin' to do |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1457 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1458 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1459 | // End of an Invalid Element. Taken care of during the opening tag though |
| 1460 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1464 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1465 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1466 | /** |
| 1467 | * Parse character data |
| 1468 | * |
| 1469 | * @param string |
| 1470 | * @param string |
| 1471 | * @return void |
| 1472 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1473 | public function character_data($the_parser, $data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1474 | { |
| 1475 | if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1476 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1477 | // If a value has not been found |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1478 | if ($this->xh[$the_parser]['lv'] !== 3) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1479 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1480 | if ($this->xh[$the_parser]['lv'] === 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1481 | { |
| 1482 | $this->xh[$the_parser]['lv'] = 2; // Found a value |
| 1483 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1484 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1485 | if ( ! isset($this->xh[$the_parser]['ac'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1486 | { |
| 1487 | $this->xh[$the_parser]['ac'] = ''; |
| 1488 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1489 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1490 | $this->xh[$the_parser]['ac'] .= $data; |
| 1491 | } |
| 1492 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1493 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1494 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1495 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1496 | /** |
| 1497 | * Add parameter |
| 1498 | * |
| 1499 | * @param mixed |
| 1500 | * @return void |
| 1501 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1502 | public function addParam($par) |
| 1503 | { |
| 1504 | $this->params[] = $par; |
| 1505 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1506 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1507 | // -------------------------------------------------------------------- |
| 1508 | |
| 1509 | /** |
| 1510 | * Output parameters |
| 1511 | * |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 1512 | * @param array $array |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1513 | * @return array |
| 1514 | */ |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 1515 | public function output_parameters(array $array = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1516 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1517 | $CI =& get_instance(); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1518 | |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 1519 | if ( ! empty($array)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1520 | { |
| 1521 | while (list($key) = each($array)) |
| 1522 | { |
| 1523 | if (is_array($array[$key])) |
| 1524 | { |
| 1525 | $array[$key] = $this->output_parameters($array[$key]); |
| 1526 | } |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 1527 | elseif ($key !== 'bits' && $this->xss_clean) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1528 | { |
Derek Jones | a9647e8 | 2010-03-02 22:59:07 -0600 | [diff] [blame] | 1529 | // 'bits' is for the MetaWeblog API image bits |
| 1530 | // @todo - this needs to be made more general purpose |
Andrey Andreev | e417f04 | 2014-01-08 14:48:01 +0200 | [diff] [blame^] | 1531 | $array[$key] = $CI->security->xss_clean($array[$key]); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1532 | } |
| 1533 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1534 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1535 | return $array; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1536 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1537 | |
| 1538 | $parameters = array(); |
| 1539 | |
| 1540 | for ($i = 0, $c = count($this->params); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1541 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1542 | $a_param = $this->decode_message($this->params[$i]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1543 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1544 | if (is_array($a_param)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1545 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1546 | $parameters[] = $this->output_parameters($a_param); |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1551 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1552 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1553 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1554 | return $parameters; |
| 1555 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1556 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1557 | // -------------------------------------------------------------------- |
| 1558 | |
| 1559 | /** |
| 1560 | * Decode message |
| 1561 | * |
| 1562 | * @param object |
| 1563 | * @return mixed |
| 1564 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1565 | public function decode_message($param) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1566 | { |
| 1567 | $kind = $param->kindOf(); |
| 1568 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1569 | if ($kind === 'scalar') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1570 | { |
| 1571 | return $param->scalarval(); |
| 1572 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1573 | elseif ($kind === 'array') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1574 | { |
| 1575 | reset($param->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 1576 | $b = current($param->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1577 | $arr = array(); |
| 1578 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1579 | for ($i = 0, $c = count($b); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1580 | { |
| 1581 | $arr[] = $this->decode_message($param->me['array'][$i]); |
| 1582 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1583 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1584 | return $arr; |
| 1585 | } |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1586 | elseif ($kind === 'struct') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1587 | { |
| 1588 | reset($param->me['struct']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1589 | $arr = array(); |
| 1590 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1591 | while (list($key,$value) = each($param->me['struct'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1592 | { |
| 1593 | $arr[$key] = $this->decode_message($value); |
| 1594 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1595 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1596 | return $arr; |
| 1597 | } |
| 1598 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1599 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1600 | } // END XML_RPC_Message Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1601 | |
| 1602 | /** |
| 1603 | * XML-RPC Values class |
| 1604 | * |
| 1605 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 1606 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1607 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 1608 | */ |
| 1609 | class XML_RPC_Values extends CI_Xmlrpc |
| 1610 | { |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1611 | /** |
| 1612 | * Value data |
| 1613 | * |
| 1614 | * @var array |
| 1615 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1616 | public $me = array(); |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1617 | |
| 1618 | /** |
| 1619 | * Value type |
| 1620 | * |
| 1621 | * @var int |
| 1622 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1623 | public $mytype = 0; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1624 | |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1625 | // -------------------------------------------------------------------- |
| 1626 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1627 | /** |
| 1628 | * Constructor |
| 1629 | * |
Andrey Andreev | f5ccd12 | 2012-11-02 00:17:39 +0200 | [diff] [blame] | 1630 | * @param mixed $val |
| 1631 | * @param string $type |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1632 | * @return void |
| 1633 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1634 | public function __construct($val = -1, $type = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1635 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 1636 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1637 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1638 | if ($val !== -1 OR $type !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1639 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1640 | $type = $type === '' ? 'string' : $type; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1641 | |
Dimitar | 740480a | 2012-10-05 13:24:59 +0300 | [diff] [blame] | 1642 | if ($this->xmlrpcTypes[$type] == 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1643 | { |
vkeranov | b497d2b | 2012-11-23 23:27:33 +0200 | [diff] [blame] | 1644 | $this->addScalar($val, $type); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1645 | } |
Dimitar | 740480a | 2012-10-05 13:24:59 +0300 | [diff] [blame] | 1646 | elseif ($this->xmlrpcTypes[$type] == 2) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1647 | { |
| 1648 | $this->addArray($val); |
| 1649 | } |
Dimitar | 740480a | 2012-10-05 13:24:59 +0300 | [diff] [blame] | 1650 | elseif ($this->xmlrpcTypes[$type] == 3) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1651 | { |
| 1652 | $this->addStruct($val); |
| 1653 | } |
| 1654 | } |
| 1655 | } |
| 1656 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1657 | // -------------------------------------------------------------------- |
| 1658 | |
| 1659 | /** |
| 1660 | * Add scalar value |
| 1661 | * |
| 1662 | * @param scalar |
| 1663 | * @param string |
| 1664 | * @return int |
| 1665 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1666 | public function addScalar($val, $type = 'string') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1667 | { |
| 1668 | $typeof = $this->xmlrpcTypes[$type]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1669 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1670 | if ($this->mytype === 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1671 | { |
| 1672 | echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />'; |
| 1673 | return 0; |
| 1674 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1675 | |
Dimitar | 740480a | 2012-10-05 13:24:59 +0300 | [diff] [blame] | 1676 | if ($typeof != 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1677 | { |
| 1678 | echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />'; |
| 1679 | return 0; |
| 1680 | } |
| 1681 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1682 | if ($type === $this->xmlrpcBoolean) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1683 | { |
Andrey Andreev | 3f3f135 | 2012-09-05 16:39:28 +0300 | [diff] [blame] | 1684 | $val = (int) (strcasecmp($val, 'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false'))); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1687 | if ($this->mytype === 2) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1688 | { |
| 1689 | // adding to an array here |
| 1690 | $ar = $this->me['array']; |
| 1691 | $ar[] = new XML_RPC_Values($val, $type); |
| 1692 | $this->me['array'] = $ar; |
| 1693 | } |
| 1694 | else |
| 1695 | { |
| 1696 | // a scalar, so set the value and remember we're scalar |
| 1697 | $this->me[$type] = $val; |
| 1698 | $this->mytype = $typeof; |
| 1699 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1700 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1701 | return 1; |
| 1702 | } |
| 1703 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1704 | // -------------------------------------------------------------------- |
| 1705 | |
| 1706 | /** |
| 1707 | * Add array value |
| 1708 | * |
| 1709 | * @param array |
| 1710 | * @return int |
| 1711 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1712 | public function addArray($vals) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1713 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1714 | if ($this->mytype !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1715 | { |
Andrey Andreev | 3ca060a | 2013-11-27 16:30:31 +0200 | [diff] [blame] | 1716 | echo '<strong>XML_RPC_Values</strong>: already initialized as a ['.$this->kindOf().']<br />'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1717 | return 0; |
| 1718 | } |
| 1719 | |
| 1720 | $this->mytype = $this->xmlrpcTypes['array']; |
| 1721 | $this->me['array'] = $vals; |
| 1722 | return 1; |
| 1723 | } |
| 1724 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1725 | // -------------------------------------------------------------------- |
| 1726 | |
| 1727 | /** |
| 1728 | * Add struct value |
| 1729 | * |
| 1730 | * @param object |
| 1731 | * @return int |
| 1732 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1733 | public function addStruct($vals) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1734 | { |
Alex Bilbie | d261b1e | 2012-06-02 11:12:16 +0100 | [diff] [blame] | 1735 | if ($this->mytype !== 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1736 | { |
Andrey Andreev | 3ca060a | 2013-11-27 16:30:31 +0200 | [diff] [blame] | 1737 | echo '<strong>XML_RPC_Values</strong>: already initialized as a ['.$this->kindOf().']<br />'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
| 1740 | $this->mytype = $this->xmlrpcTypes['struct']; |
| 1741 | $this->me['struct'] = $vals; |
| 1742 | return 1; |
| 1743 | } |
| 1744 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1745 | // -------------------------------------------------------------------- |
| 1746 | |
| 1747 | /** |
| 1748 | * Get value type |
| 1749 | * |
| 1750 | * @return string |
| 1751 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1752 | public function kindOf() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1753 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1754 | switch ($this->mytype) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1755 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1756 | case 3: return 'struct'; |
| 1757 | case 2: return 'array'; |
| 1758 | case 1: return 'scalar'; |
| 1759 | default: return 'undef'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1760 | } |
| 1761 | } |
| 1762 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1763 | // -------------------------------------------------------------------- |
| 1764 | |
| 1765 | /** |
| 1766 | * Serialize data |
| 1767 | * |
| 1768 | * @param string |
| 1769 | * @param mixed |
| 1770 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1771 | public function serializedata($typ, $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1772 | { |
| 1773 | $rs = ''; |
Derek Jones | a9647e8 | 2010-03-02 22:59:07 -0600 | [diff] [blame] | 1774 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1775 | switch ($this->xmlrpcTypes[$typ]) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1776 | { |
| 1777 | case 3: |
| 1778 | // struct |
| 1779 | $rs .= "<struct>\n"; |
| 1780 | reset($val); |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1781 | while (list($key2, $val2) = each($val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1782 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1783 | $rs .= "<member>\n<name>{$key2}</name>\n".$this->serializeval($val2)."</member>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1784 | } |
| 1785 | $rs .= '</struct>'; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1786 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1787 | case 2: |
| 1788 | // array |
| 1789 | $rs .= "<array>\n<data>\n"; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1790 | for ($i = 0, $c = count($val); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1791 | { |
| 1792 | $rs .= $this->serializeval($val[$i]); |
| 1793 | } |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1794 | $rs .= "</data>\n</array>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1795 | break; |
| 1796 | case 1: |
| 1797 | // others |
| 1798 | switch ($typ) |
| 1799 | { |
| 1800 | case $this->xmlrpcBase64: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1801 | $rs .= '<'.$typ.'>'.base64_encode( (string) $val).'</'.$typ.">\n"; |
| 1802 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1803 | case $this->xmlrpcBoolean: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1804 | $rs .= '<'.$typ.'>'.( (bool) $val ? '1' : '0').'</'.$typ.">\n"; |
| 1805 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1806 | case $this->xmlrpcString: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1807 | $rs .= '<'.$typ.'>'.htmlspecialchars( (string) $val).'</'.$typ.">\n"; |
| 1808 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1809 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1810 | $rs .= '<'.$typ.'>'.$val.'</'.$typ.">\n"; |
| 1811 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1812 | } |
| 1813 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1814 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1815 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1816 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1817 | return $rs; |
| 1818 | } |
| 1819 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1820 | // -------------------------------------------------------------------- |
| 1821 | |
| 1822 | /** |
| 1823 | * Serialize class |
| 1824 | * |
| 1825 | * @return string |
| 1826 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1827 | public function serialize_class() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1828 | { |
| 1829 | return $this->serializeval($this); |
| 1830 | } |
| 1831 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1832 | // -------------------------------------------------------------------- |
| 1833 | |
| 1834 | /** |
| 1835 | * Serialize value |
| 1836 | * |
| 1837 | * @param object |
| 1838 | * @return string |
| 1839 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1840 | public function serializeval($o) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1841 | { |
| 1842 | $ar = $o->me; |
| 1843 | reset($ar); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1844 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1845 | list($typ, $val) = each($ar); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1846 | return "<value>\n".$this->serializedata($typ, $val)."</value>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1847 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1848 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1849 | // -------------------------------------------------------------------- |
| 1850 | |
| 1851 | /** |
| 1852 | * Scalar value |
| 1853 | * |
| 1854 | * @return mixed |
| 1855 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1856 | public function scalarval() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1857 | { |
| 1858 | reset($this->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 1859 | return current($this->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1862 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1863 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1864 | /** |
| 1865 | * Encode time in ISO-8601 form. |
| 1866 | * Useful for sending time in XML-RPC |
| 1867 | * |
| 1868 | * @param int unix timestamp |
| 1869 | * @param bool |
| 1870 | * @return string |
| 1871 | */ |
| 1872 | public function iso8601_encode($time, $utc = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1873 | { |
Andrey Andreev | 6209015 | 2011-12-30 12:49:27 +0200 | [diff] [blame] | 1874 | return ($utc) ? strftime('%Y%m%dT%H:%i:%s', $time) : gmstrftime('%Y%m%dT%H:%i:%s', $time); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1875 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1876 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame] | 1877 | } // END XML_RPC_Values Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1878 | |
| 1879 | /* End of file Xmlrpc.php */ |
Andrey Andreev | c5a7c5f | 2013-07-17 20:10:09 +0300 | [diff] [blame] | 1880 | /* Location: ./system/libraries/Xmlrpc.php */ |