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