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