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