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