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 |
| 107 | $this->valid_parents = array('BOOLEAN' => array('VALUE'), |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 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 | */ |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 177 | public function server($url, $port = 80) |
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 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | $this->client = new XML_RPC_Client($path, $parts['host'], $port); |
| 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 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [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 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 280 | if (is_array($value[0]) && ($value[1] == 'struct' OR $value[1] == 'array')) |
| 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; |
| 388 | public $errno = ''; |
| 389 | public $errstring = ''; |
| 390 | public $timeout = 5; |
| 391 | public $no_multicall = FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 392 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 393 | /** |
| 394 | * Constructor |
| 395 | * |
| 396 | * @param string |
| 397 | * @param object |
| 398 | * @param int |
| 399 | * @return void |
| 400 | */ |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 401 | public function __construct($path, $server, $port = 80) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 402 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 403 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 404 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 405 | $this->port = $port; |
| 406 | $this->server = $server; |
| 407 | $this->path = $path; |
| 408 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 409 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 410 | // -------------------------------------------------------------------- |
| 411 | |
| 412 | /** |
| 413 | * Send message |
| 414 | * |
| 415 | * @param mixed |
| 416 | * @return object |
| 417 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 418 | public function send($msg) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | { |
| 420 | if (is_array($msg)) |
| 421 | { |
| 422 | // Multi-call disabled |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 423 | 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] | 424 | } |
| 425 | |
| 426 | return $this->sendPayload($msg); |
| 427 | } |
| 428 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 429 | // -------------------------------------------------------------------- |
| 430 | |
| 431 | /** |
| 432 | * Send payload |
| 433 | * |
| 434 | * @param object |
| 435 | * @return object |
| 436 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 437 | public function sendPayload($msg) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 438 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | $fp = @fsockopen($this->server, $this->port,$this->errno, $this->errstr, $this->timeout); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 440 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 441 | if ( ! is_resource($fp)) |
| 442 | { |
| 443 | error_log($this->xmlrpcstr['http_error']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 444 | 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] | 445 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 446 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 447 | if (empty($msg->payload)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 448 | { |
| 449 | // $msg = XML_RPC_Messages |
| 450 | $msg->createPayload(); |
| 451 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 452 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 453 | $r = "\r\n"; |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 454 | $op = 'POST '.$this->path.' HTTP/1.0'.$r |
| 455 | .'Host: '.$this->server.$r |
| 456 | .'Content-Type: text/xml'.$r |
| 457 | .'User-Agent: '.$this->xmlrpcName.$r |
| 458 | .'Content-Length: '.strlen($msg->payload).$r.$r |
| 459 | .$msg->payload; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 460 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 461 | if ( ! fputs($fp, $op, strlen($op))) |
| 462 | { |
| 463 | error_log($this->xmlrpcstr['http_error']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 464 | return new XML_RPC_Response(0, $this->xmlrpcerr['http_error'], $this->xmlrpcstr['http_error']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 465 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 466 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 467 | $resp = $msg->parseResponse($fp); |
| 468 | fclose($fp); |
| 469 | return $resp; |
| 470 | } |
| 471 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 472 | } // END XML_RPC_Client Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 473 | |
| 474 | /** |
| 475 | * XML-RPC Response class |
| 476 | * |
| 477 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 478 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 480 | */ |
| 481 | class XML_RPC_Response |
| 482 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 483 | public $val = 0; |
| 484 | public $errno = 0; |
| 485 | public $errstr = ''; |
| 486 | public $headers = array(); |
| 487 | public $xss_clean = TRUE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 489 | /** |
| 490 | * Constructor |
| 491 | * |
| 492 | * @param mixed |
| 493 | * @param int |
| 494 | * @param string |
| 495 | * @return void |
| 496 | */ |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 497 | public function __construct($val, $code = 0, $fstr = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 498 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 499 | if ($code != 0) |
| 500 | { |
| 501 | // error |
| 502 | $this->errno = $code; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 503 | $this->errstr = htmlspecialchars($fstr, |
| 504 | (is_php('5.4') ? ENT_XML1 | ENT_NOQUOTES : ENT_NOQUOTES), |
| 505 | 'UTF-8'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 506 | } |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 507 | elseif ( ! is_object($val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 508 | { |
| 509 | // programmer error, not an object |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 510 | 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] | 511 | $this->val = new XML_RPC_Values(); |
| 512 | } |
| 513 | else |
| 514 | { |
| 515 | $this->val = $val; |
| 516 | } |
| 517 | } |
| 518 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 519 | // -------------------------------------------------------------------- |
| 520 | |
| 521 | /** |
| 522 | * Fault code |
| 523 | * |
| 524 | * @return int |
| 525 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 526 | public function faultCode() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 527 | { |
| 528 | return $this->errno; |
| 529 | } |
| 530 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 531 | // -------------------------------------------------------------------- |
| 532 | |
| 533 | /** |
| 534 | * Fault string |
| 535 | * |
| 536 | * @return string |
| 537 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 538 | public function faultString() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 539 | { |
| 540 | return $this->errstr; |
| 541 | } |
| 542 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 543 | // -------------------------------------------------------------------- |
| 544 | |
| 545 | /** |
| 546 | * Value |
| 547 | * |
| 548 | * @return mixed |
| 549 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 550 | public function value() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | { |
| 552 | return $this->val; |
| 553 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 554 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 555 | // -------------------------------------------------------------------- |
| 556 | |
| 557 | /** |
| 558 | * Prepare response |
| 559 | * |
| 560 | * @return string xml |
| 561 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 562 | public function prepare_response() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 563 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 564 | return "<methodResponse>\n" |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 565 | .($this->errno |
| 566 | ? '<fault> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 567 | <value> |
| 568 | <struct> |
| 569 | <member> |
| 570 | <name>faultCode</name> |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 571 | <value><int>'.$this->errno.'</int></value> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | </member> |
| 573 | <member> |
| 574 | <name>faultString</name> |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 575 | <value><string>'.$this->errstr.'</string></value> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 576 | </member> |
| 577 | </struct> |
| 578 | </value> |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 579 | </fault>' |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 580 | : "<params>\n<param>\n".$this->val->serialize_class()."</param>\n</params>") |
| 581 | ."\n</methodResponse>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 583 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 584 | // -------------------------------------------------------------------- |
| 585 | |
| 586 | /** |
| 587 | * Decode |
| 588 | * |
| 589 | * @param mixed |
| 590 | * @return array |
| 591 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 592 | public function decode($array = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 593 | { |
| 594 | $CI =& get_instance(); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 595 | |
| 596 | if (is_array($array)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 597 | { |
| 598 | while (list($key) = each($array)) |
| 599 | { |
| 600 | if (is_array($array[$key])) |
| 601 | { |
| 602 | $array[$key] = $this->decode($array[$key]); |
| 603 | } |
| 604 | else |
| 605 | { |
Robin Sowell | 66a3fc0 | 2010-03-18 09:44:55 -0400 | [diff] [blame] | 606 | $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] | 607 | } |
| 608 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 609 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 610 | return $array; |
| 611 | } |
| 612 | |
| 613 | $result = $this->xmlrpc_decoder($this->val); |
| 614 | |
| 615 | if (is_array($result)) |
| 616 | { |
| 617 | $result = $this->decode($result); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 618 | } |
| 619 | else |
| 620 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 621 | $result = ($this->xss_clean) ? $CI->security->xss_clean($result) : $result; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 622 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 623 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 624 | return $result; |
| 625 | } |
| 626 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 627 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 628 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 629 | /** |
| 630 | * XML-RPC Object to PHP Types |
| 631 | * |
| 632 | * @param object |
| 633 | * @return array |
| 634 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 635 | public function xmlrpc_decoder($xmlrpc_val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 636 | { |
| 637 | $kind = $xmlrpc_val->kindOf(); |
| 638 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 639 | if ($kind == 'scalar') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | { |
| 641 | return $xmlrpc_val->scalarval(); |
| 642 | } |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 643 | elseif ($kind == 'array') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 644 | { |
| 645 | reset($xmlrpc_val->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 646 | $b = current($xmlrpc_val->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 647 | $arr = array(); |
| 648 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 649 | for ($i = 0, $size = count($b); $i < $size; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 650 | { |
| 651 | $arr[] = $this->xmlrpc_decoder($xmlrpc_val->me['array'][$i]); |
| 652 | } |
| 653 | return $arr; |
| 654 | } |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 655 | elseif ($kind == 'struct') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 656 | { |
| 657 | reset($xmlrpc_val->me['struct']); |
| 658 | $arr = array(); |
| 659 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 660 | while (list($key,$value) = each($xmlrpc_val->me['struct'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 661 | { |
| 662 | $arr[$key] = $this->xmlrpc_decoder($value); |
| 663 | } |
| 664 | return $arr; |
| 665 | } |
| 666 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 667 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 668 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 669 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 670 | /** |
| 671 | * ISO-8601 time to server or UTC time |
| 672 | * |
| 673 | * @param string |
| 674 | * @param bool |
| 675 | * @return int unix timestamp |
| 676 | */ |
| 677 | public function iso8601_decode($time, $utc = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 678 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 679 | // return a time in the localtime, or UTC |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 680 | $t = 0; |
| 681 | if (preg_match('/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $time, $regs)) |
| 682 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 683 | $fnc = ($utc == TRUE) ? 'gmmktime' : 'mktime'; |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 684 | $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] | 685 | } |
| 686 | return $t; |
| 687 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 688 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 689 | } // END XML_RPC_Response Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 690 | |
| 691 | /** |
| 692 | * XML-RPC Message class |
| 693 | * |
| 694 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 695 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 696 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 697 | */ |
| 698 | class XML_RPC_Message extends CI_Xmlrpc |
| 699 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 700 | public $payload; |
| 701 | public $method_name; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 702 | public $params = array(); |
| 703 | public $xh = array(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 704 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 705 | /** |
| 706 | * Constructor |
| 707 | * |
| 708 | * @param string method name |
| 709 | * @param array |
| 710 | * @return void |
| 711 | */ |
| 712 | public function __construct($method, $pars = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 713 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 714 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 715 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 716 | $this->method_name = $method; |
Derek Jones | 3355910 | 2009-02-02 18:50:38 +0000 | [diff] [blame] | 717 | if (is_array($pars) && count($pars) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 718 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 719 | for ($i = 0, $c = count($pars); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 720 | { |
| 721 | // $pars[$i] = XML_RPC_Values |
| 722 | $this->params[] = $pars[$i]; |
| 723 | } |
| 724 | } |
| 725 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 726 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 727 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 728 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 729 | /** |
| 730 | * Create Payload to Send |
| 731 | * |
| 732 | * @return void |
| 733 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 734 | public function createPayload() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 735 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 736 | $this->payload = '<?xml version="1.0"?'.">\r\n<methodCall>\r\n" |
| 737 | .'<methodName>'.$this->method_name."</methodName>\r\n" |
| 738 | ."<params>\r\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 739 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 740 | for ($i = 0, $c = count($this->params); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 741 | { |
| 742 | // $p = XML_RPC_Values |
| 743 | $p = $this->params[$i]; |
| 744 | $this->payload .= "<param>\r\n".$p->serialize_class()."</param>\r\n"; |
| 745 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 746 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 747 | $this->payload .= "</params>\r\n</methodCall>\r\n"; |
| 748 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 749 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 750 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 751 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 752 | /** |
| 753 | * Parse External XML-RPC Server's Response |
| 754 | * |
| 755 | * @param resource |
| 756 | * @return object |
| 757 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 758 | public function parseResponse($fp) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 759 | { |
| 760 | $data = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 761 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 762 | while ($datum = fread($fp, 4096)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 763 | { |
| 764 | $data .= $datum; |
| 765 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 766 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 767 | // Display HTTP content for debugging |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 768 | if ($this->debug === TRUE) |
| 769 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 770 | echo "<pre>---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n</pre>"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 771 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 772 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 773 | // Check for data |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 774 | if ($data === '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 775 | { |
| 776 | error_log($this->xmlrpcstr['no_data']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 777 | 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] | 778 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 779 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 780 | // Check for HTTP 200 Response |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 781 | if (strncmp($data, 'HTTP', 4) === 0 && ! preg_match('/^HTTP\/[0-9\.]+ 200 /', $data)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 782 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 783 | $errstr = substr($data, 0, strpos($data, "\n")-1); |
| 784 | 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] | 785 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 786 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 787 | //------------------------------------- |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 788 | // Create and Set Up XML Parser |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 789 | //------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 790 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 791 | $parser = xml_parser_create($this->xmlrpc_defencoding); |
| 792 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 793 | $this->xh[$parser] = array( |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 794 | 'isf' => 0, |
| 795 | 'ac' => '', |
| 796 | 'headers' => array(), |
| 797 | 'stack' => array(), |
| 798 | 'valuestack' => array(), |
| 799 | 'isf_reason' => 0 |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 800 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 801 | |
| 802 | xml_set_object($parser, $this); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 803 | xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 804 | xml_set_element_handler($parser, 'open_tag', 'closing_tag'); |
| 805 | xml_set_character_data_handler($parser, 'character_data'); |
| 806 | //xml_set_default_handler($parser, 'default_handler'); |
| 807 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 808 | // Get headers |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 809 | $lines = explode("\r\n", $data); |
| 810 | while (($line = array_shift($lines))) |
| 811 | { |
| 812 | if (strlen($line) < 1) |
| 813 | { |
| 814 | break; |
| 815 | } |
| 816 | $this->xh[$parser]['headers'][] = $line; |
| 817 | } |
| 818 | $data = implode("\r\n", $lines); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 819 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 820 | // Parse XML data |
Derek Jones | 3355910 | 2009-02-02 18:50:38 +0000 | [diff] [blame] | 821 | if ( ! xml_parse($parser, $data, count($data))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 822 | { |
| 823 | $errstr = sprintf('XML error: %s at line %d', |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 824 | xml_error_string(xml_get_error_code($parser)), |
| 825 | xml_get_current_line_number($parser)); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 826 | //error_log($errstr); |
| 827 | $r = new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']); |
| 828 | xml_parser_free($parser); |
| 829 | return $r; |
| 830 | } |
| 831 | xml_parser_free($parser); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 832 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 833 | // Got ourselves some badness, it seems |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 834 | if ($this->xh[$parser]['isf'] > 1) |
| 835 | { |
| 836 | if ($this->debug === TRUE) |
| 837 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 838 | 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] | 839 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 840 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 841 | 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] | 842 | } |
| 843 | elseif ( ! is_object($this->xh[$parser]['value'])) |
| 844 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 845 | 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] | 846 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 847 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 848 | // Display XML content for debugging |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 849 | if ($this->debug === TRUE) |
| 850 | { |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 851 | echo '<pre>'; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 852 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 853 | if (count($this->xh[$parser]['headers'] > 0)) |
| 854 | { |
| 855 | echo "---HEADERS---\n"; |
| 856 | foreach ($this->xh[$parser]['headers'] as $header) |
| 857 | { |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 858 | echo $header."\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 859 | } |
| 860 | echo "---END HEADERS---\n\n"; |
| 861 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 862 | |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 863 | echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 864 | var_dump($this->xh[$parser]['value']); |
| 865 | echo "\n---END PARSED---</pre>"; |
| 866 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 867 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 868 | // Send response |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 869 | $v = $this->xh[$parser]['value']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 870 | if ($this->xh[$parser]['isf']) |
| 871 | { |
| 872 | $errno_v = $v->me['struct']['faultCode']; |
| 873 | $errstr_v = $v->me['struct']['faultString']; |
| 874 | $errno = $errno_v->scalarval(); |
| 875 | |
| 876 | if ($errno == 0) |
| 877 | { |
| 878 | // FAULT returned, errno needs to reflect that |
| 879 | $errno = -1; |
| 880 | } |
| 881 | |
| 882 | $r = new XML_RPC_Response($v, $errno, $errstr_v->scalarval()); |
| 883 | } |
| 884 | else |
| 885 | { |
| 886 | $r = new XML_RPC_Response($v); |
| 887 | } |
| 888 | |
| 889 | $r->headers = $this->xh[$parser]['headers']; |
| 890 | return $r; |
| 891 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 892 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 893 | // -------------------------------------------------------------------- |
| 894 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 895 | // ------------------------------------ |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 896 | // Begin Return Message Parsing section |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 897 | // ------------------------------------ |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 898 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 899 | // quick explanation of components: |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 900 | // ac - used to accumulate values |
| 901 | // isf - used to indicate a fault |
| 902 | // lv - used to indicate "looking for a value": implements |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 903 | // the logic to allow values with no types to be strings |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 904 | // params - used to store parameters in method calls |
| 905 | // method - used to store method name |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 906 | // stack - array with parent tree of the xml element, |
| 907 | // used to validate the nesting of elements |
| 908 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 909 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 910 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 911 | /** |
| 912 | * Start Element Handler |
| 913 | * |
| 914 | * @param string |
| 915 | * @param string |
| 916 | * @return void |
| 917 | */ |
| 918 | public function open_tag($the_parser, $name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 919 | { |
| 920 | // If invalid nesting, then return |
| 921 | if ($this->xh[$the_parser]['isf'] > 1) return; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 922 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 923 | // Evaluate and check for correct nesting of XML elements |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 924 | if (count($this->xh[$the_parser]['stack']) == 0) |
| 925 | { |
| 926 | if ($name != 'METHODRESPONSE' && $name != 'METHODCALL') |
| 927 | { |
| 928 | $this->xh[$the_parser]['isf'] = 2; |
| 929 | $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing'; |
| 930 | return; |
| 931 | } |
| 932 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 933 | // not top level element: see if parent is OK |
| 934 | 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] | 935 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 936 | $this->xh[$the_parser]['isf'] = 2; |
| 937 | $this->xh[$the_parser]['isf_reason'] = 'XML-RPC element $name cannot be child of '.$this->xh[$the_parser]['stack'][0]; |
| 938 | return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 939 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 940 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 941 | switch ($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 942 | { |
| 943 | case 'STRUCT': |
| 944 | case 'ARRAY': |
| 945 | // Creates array for child elements |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 946 | $cur_val = array('value' => array(), 'type' => $name); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 947 | array_unshift($this->xh[$the_parser]['valuestack'], $cur_val); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 948 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 949 | case 'METHODNAME': |
| 950 | case 'NAME': |
| 951 | $this->xh[$the_parser]['ac'] = ''; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 952 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 953 | case 'FAULT': |
| 954 | $this->xh[$the_parser]['isf'] = 1; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 955 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 956 | case 'PARAM': |
Pascal Kriete | 8761ef5 | 2011-02-14 13:13:52 -0500 | [diff] [blame] | 957 | $this->xh[$the_parser]['value'] = NULL; |
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 'VALUE': |
| 960 | $this->xh[$the_parser]['vt'] = 'value'; |
| 961 | $this->xh[$the_parser]['ac'] = ''; |
| 962 | $this->xh[$the_parser]['lv'] = 1; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 963 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 964 | case 'I4': |
| 965 | case 'INT': |
| 966 | case 'STRING': |
| 967 | case 'BOOLEAN': |
| 968 | case 'DOUBLE': |
| 969 | case 'DATETIME.ISO8601': |
| 970 | case 'BASE64': |
| 971 | if ($this->xh[$the_parser]['vt'] != 'value') |
| 972 | { |
| 973 | //two data elements inside a value: an error occurred! |
| 974 | $this->xh[$the_parser]['isf'] = 2; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 975 | $this->xh[$the_parser]['isf_reason'] = "'Twas a ".$name.' element following a ' |
| 976 | .$this->xh[$the_parser]['vt'].' element inside a single value'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 977 | return; |
| 978 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 979 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 980 | $this->xh[$the_parser]['ac'] = ''; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 981 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 982 | case 'MEMBER': |
| 983 | // Set name of <member> to nothing to prevent errors later if no <name> is found |
| 984 | $this->xh[$the_parser]['valuestack'][0]['name'] = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 985 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 986 | // 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] | 987 | $this->xh[$the_parser]['value'] = NULL; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 988 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 989 | case 'DATA': |
| 990 | case 'METHODCALL': |
| 991 | case 'METHODRESPONSE': |
| 992 | case 'PARAMS': |
| 993 | // valid elements that add little to processing |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 994 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 995 | default: |
| 996 | /// An Invalid Element is Found, so we have trouble |
| 997 | $this->xh[$the_parser]['isf'] = 2; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 998 | $this->xh[$the_parser]['isf_reason'] = 'Invalid XML-RPC element found: '.$name; |
| 999 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1000 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1001 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1002 | // Add current element name to stack, to allow validation of nesting |
| 1003 | array_unshift($this->xh[$the_parser]['stack'], $name); |
| 1004 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1005 | $name == 'VALUE' OR $this->xh[$the_parser]['lv'] = 0; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1006 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1007 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1008 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1009 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1010 | /** |
| 1011 | * End Element Handler |
| 1012 | * |
| 1013 | * @param string |
| 1014 | * @param string |
| 1015 | * @return void |
| 1016 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1017 | public function closing_tag($the_parser, $name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1018 | { |
| 1019 | if ($this->xh[$the_parser]['isf'] > 1) return; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1020 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1021 | // Remove current element from stack and set variable |
| 1022 | // 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^] | 1023 | // the opening and closing of elements. Nesting is checked on the opening |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1024 | // tag so we be safe there as well. |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1025 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1026 | $curr_elem = array_shift($this->xh[$the_parser]['stack']); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1027 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1028 | switch ($name) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1029 | { |
| 1030 | case 'STRUCT': |
| 1031 | case 'ARRAY': |
| 1032 | $cur_val = array_shift($this->xh[$the_parser]['valuestack']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1033 | $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] | 1034 | $this->xh[$the_parser]['vt'] = strtolower($name); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1035 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1036 | case 'NAME': |
| 1037 | $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac']; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1038 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1039 | case 'BOOLEAN': |
| 1040 | case 'I4': |
| 1041 | case 'INT': |
| 1042 | case 'STRING': |
| 1043 | case 'DOUBLE': |
| 1044 | case 'DATETIME.ISO8601': |
| 1045 | case 'BASE64': |
| 1046 | $this->xh[$the_parser]['vt'] = strtolower($name); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1047 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1048 | if ($name == 'STRING') |
| 1049 | { |
| 1050 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1051 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1052 | elseif ($name == 'DATETIME.ISO8601') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1053 | { |
| 1054 | $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime; |
| 1055 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1056 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1057 | elseif ($name == 'BASE64') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1058 | { |
| 1059 | $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']); |
| 1060 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1061 | elseif ($name == 'BOOLEAN') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1062 | { |
| 1063 | // Translated BOOLEAN values to TRUE AND FALSE |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1064 | $this->xh[$the_parser]['value'] = (bool) $this->xh[$the_parser]['ac']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1065 | } |
| 1066 | elseif ($name=='DOUBLE') |
| 1067 | { |
| 1068 | // we have a DOUBLE |
| 1069 | // we must check that only 0123456789-.<space> are characters here |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1070 | $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac']) |
| 1071 | ? (float) $this->xh[$the_parser]['ac'] |
| 1072 | : 'ERROR_NON_NUMERIC_FOUND'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1073 | } |
| 1074 | else |
| 1075 | { |
| 1076 | // we have an I4/INT |
| 1077 | // we must check that only 0123456789-<space> are characters here |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1078 | $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac']) |
| 1079 | ? (int) $this->xh[$the_parset]['ac'] |
| 1080 | : 'ERROR_NON_NUMERIC_FOUND'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1081 | } |
| 1082 | $this->xh[$the_parser]['ac'] = ''; |
| 1083 | $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1084 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1085 | case 'VALUE': |
| 1086 | // This if() detects if no scalar was inside <VALUE></VALUE> |
| 1087 | if ($this->xh[$the_parser]['vt']=='value') |
| 1088 | { |
| 1089 | $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac']; |
| 1090 | $this->xh[$the_parser]['vt'] = $this->xmlrpcString; |
| 1091 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1092 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1093 | // build the XML-RPC value out of the data received, and substitute it |
| 1094 | $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] | 1095 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1096 | if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] == 'ARRAY') |
| 1097 | { |
| 1098 | // Array |
| 1099 | $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp; |
| 1100 | } |
| 1101 | else |
| 1102 | { |
| 1103 | // Struct |
| 1104 | $this->xh[$the_parser]['value'] = $temp; |
| 1105 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1106 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1107 | case 'MEMBER': |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1108 | $this->xh[$the_parser]['ac'] = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1109 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1110 | // If value add to array in the stack for the last element built |
| 1111 | if ($this->xh[$the_parser]['value']) |
| 1112 | { |
| 1113 | $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value']; |
| 1114 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1115 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1116 | case 'DATA': |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1117 | $this->xh[$the_parser]['ac'] = ''; |
| 1118 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1119 | case 'PARAM': |
| 1120 | if ($this->xh[$the_parser]['value']) |
| 1121 | { |
| 1122 | $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value']; |
| 1123 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1124 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1125 | case 'METHODNAME': |
| 1126 | $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']); |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1127 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1128 | case 'PARAMS': |
| 1129 | case 'FAULT': |
| 1130 | case 'METHODCALL': |
| 1131 | case 'METHORESPONSE': |
| 1132 | // We're all good kids with nuthin' to do |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1133 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1134 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1135 | // End of an Invalid Element. Taken care of during the opening tag though |
| 1136 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1137 | } |
| 1138 | } |
| 1139 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1140 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1141 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1142 | /** |
| 1143 | * Parse character data |
| 1144 | * |
| 1145 | * @param string |
| 1146 | * @param string |
| 1147 | * @return void |
| 1148 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1149 | public function character_data($the_parser, $data) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1150 | { |
| 1151 | if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1152 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1153 | // If a value has not been found |
| 1154 | if ($this->xh[$the_parser]['lv'] != 3) |
| 1155 | { |
| 1156 | if ($this->xh[$the_parser]['lv'] == 1) |
| 1157 | { |
| 1158 | $this->xh[$the_parser]['lv'] = 2; // Found a value |
| 1159 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1160 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1161 | if ( ! isset($this->xh[$the_parser]['ac'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1162 | { |
| 1163 | $this->xh[$the_parser]['ac'] = ''; |
| 1164 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1165 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1166 | $this->xh[$the_parser]['ac'] .= $data; |
| 1167 | } |
| 1168 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1169 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1170 | // -------------------------------------------------------------------- |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1171 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1172 | /** |
| 1173 | * Add parameter |
| 1174 | * |
| 1175 | * @param mixed |
| 1176 | * @return void |
| 1177 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1178 | public function addParam($par) |
| 1179 | { |
| 1180 | $this->params[] = $par; |
| 1181 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1182 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1183 | // -------------------------------------------------------------------- |
| 1184 | |
| 1185 | /** |
| 1186 | * Output parameters |
| 1187 | * |
| 1188 | * @param array |
| 1189 | * @return array |
| 1190 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1191 | public function output_parameters($array = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1192 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1193 | $CI =& get_instance(); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1194 | |
| 1195 | if (is_array($array)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1196 | { |
| 1197 | while (list($key) = each($array)) |
| 1198 | { |
| 1199 | if (is_array($array[$key])) |
| 1200 | { |
| 1201 | $array[$key] = $this->output_parameters($array[$key]); |
| 1202 | } |
| 1203 | else |
| 1204 | { |
Derek Jones | a9647e8 | 2010-03-02 22:59:07 -0600 | [diff] [blame] | 1205 | // 'bits' is for the MetaWeblog API image bits |
| 1206 | // @todo - this needs to be made more general purpose |
Robin Sowell | 66a3fc0 | 2010-03-18 09:44:55 -0400 | [diff] [blame] | 1207 | $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] | 1208 | } |
| 1209 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1210 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1211 | return $array; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1212 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1213 | |
| 1214 | $parameters = array(); |
| 1215 | |
| 1216 | for ($i = 0, $c = count($this->params); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1217 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1218 | $a_param = $this->decode_message($this->params[$i]); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1219 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1220 | if (is_array($a_param)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1221 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1222 | $parameters[] = $this->output_parameters($a_param); |
| 1223 | } |
| 1224 | else |
| 1225 | { |
| 1226 | $parameters[] = ($this->xss_clean) ? $CI->security->xss_clean($a_param) : $a_param; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1227 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1228 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1229 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1230 | return $parameters; |
| 1231 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1232 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1233 | // -------------------------------------------------------------------- |
| 1234 | |
| 1235 | /** |
| 1236 | * Decode message |
| 1237 | * |
| 1238 | * @param object |
| 1239 | * @return mixed |
| 1240 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1241 | public function decode_message($param) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1242 | { |
| 1243 | $kind = $param->kindOf(); |
| 1244 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1245 | if ($kind == 'scalar') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1246 | { |
| 1247 | return $param->scalarval(); |
| 1248 | } |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1249 | elseif ($kind == 'array') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1250 | { |
| 1251 | reset($param->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 1252 | $b = current($param->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1253 | $arr = array(); |
| 1254 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1255 | for ($i = 0, $c = count($b); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1256 | { |
| 1257 | $arr[] = $this->decode_message($param->me['array'][$i]); |
| 1258 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1259 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1260 | return $arr; |
| 1261 | } |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1262 | elseif ($kind == 'struct') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1263 | { |
| 1264 | reset($param->me['struct']); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1265 | $arr = array(); |
| 1266 | |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1267 | while (list($key,$value) = each($param->me['struct'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1268 | { |
| 1269 | $arr[$key] = $this->decode_message($value); |
| 1270 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1271 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1272 | return $arr; |
| 1273 | } |
| 1274 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1275 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1276 | } // END XML_RPC_Message Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1277 | |
| 1278 | /** |
| 1279 | * XML-RPC Values class |
| 1280 | * |
| 1281 | * @category XML-RPC |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 1282 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1283 | * @link http://codeigniter.com/user_guide/libraries/xmlrpc.html |
| 1284 | */ |
| 1285 | class XML_RPC_Values extends CI_Xmlrpc |
| 1286 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1287 | public $me = array(); |
| 1288 | public $mytype = 0; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1289 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1290 | /** |
| 1291 | * Constructor |
| 1292 | * |
| 1293 | * @param mixed |
| 1294 | * @param string |
| 1295 | * @return void |
| 1296 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1297 | public function __construct($val = -1, $type = '') |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1298 | { |
Greg Aker | a926328 | 2010-11-10 15:26:43 -0600 | [diff] [blame] | 1299 | parent::__construct(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1300 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1301 | if ($val != -1 OR $type != '') |
| 1302 | { |
| 1303 | $type = $type == '' ? 'string' : $type; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1304 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1305 | if ($this->xmlrpcTypes[$type] == 1) |
| 1306 | { |
| 1307 | $this->addScalar($val,$type); |
| 1308 | } |
| 1309 | elseif ($this->xmlrpcTypes[$type] == 2) |
| 1310 | { |
| 1311 | $this->addArray($val); |
| 1312 | } |
| 1313 | elseif ($this->xmlrpcTypes[$type] == 3) |
| 1314 | { |
| 1315 | $this->addStruct($val); |
| 1316 | } |
| 1317 | } |
| 1318 | } |
| 1319 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1320 | // -------------------------------------------------------------------- |
| 1321 | |
| 1322 | /** |
| 1323 | * Add scalar value |
| 1324 | * |
| 1325 | * @param scalar |
| 1326 | * @param string |
| 1327 | * @return int |
| 1328 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1329 | public function addScalar($val, $type = 'string') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1330 | { |
| 1331 | $typeof = $this->xmlrpcTypes[$type]; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1332 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1333 | if ($this->mytype == 1) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1334 | { |
| 1335 | echo '<strong>XML_RPC_Values</strong>: scalar can have only one value<br />'; |
| 1336 | return 0; |
| 1337 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1338 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1339 | if ($typeof != 1) |
| 1340 | { |
| 1341 | echo '<strong>XML_RPC_Values</strong>: not a scalar type (${typeof})<br />'; |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
| 1345 | if ($type == $this->xmlrpcBoolean) |
| 1346 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1347 | $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] | 1348 | } |
| 1349 | |
| 1350 | if ($this->mytype == 2) |
| 1351 | { |
| 1352 | // adding to an array here |
| 1353 | $ar = $this->me['array']; |
| 1354 | $ar[] = new XML_RPC_Values($val, $type); |
| 1355 | $this->me['array'] = $ar; |
| 1356 | } |
| 1357 | else |
| 1358 | { |
| 1359 | // a scalar, so set the value and remember we're scalar |
| 1360 | $this->me[$type] = $val; |
| 1361 | $this->mytype = $typeof; |
| 1362 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1363 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1364 | return 1; |
| 1365 | } |
| 1366 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1367 | // -------------------------------------------------------------------- |
| 1368 | |
| 1369 | /** |
| 1370 | * Add array value |
| 1371 | * |
| 1372 | * @param array |
| 1373 | * @return int |
| 1374 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1375 | public function addArray($vals) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1376 | { |
| 1377 | if ($this->mytype != 0) |
| 1378 | { |
| 1379 | echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />'; |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | $this->mytype = $this->xmlrpcTypes['array']; |
| 1384 | $this->me['array'] = $vals; |
| 1385 | return 1; |
| 1386 | } |
| 1387 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1388 | // -------------------------------------------------------------------- |
| 1389 | |
| 1390 | /** |
| 1391 | * Add struct value |
| 1392 | * |
| 1393 | * @param object |
| 1394 | * @return int |
| 1395 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1396 | public function addStruct($vals) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1397 | { |
| 1398 | if ($this->mytype != 0) |
| 1399 | { |
| 1400 | echo '<strong>XML_RPC_Values</strong>: already initialized as a [' . $this->kindOf() . ']<br />'; |
| 1401 | return 0; |
| 1402 | } |
| 1403 | $this->mytype = $this->xmlrpcTypes['struct']; |
| 1404 | $this->me['struct'] = $vals; |
| 1405 | return 1; |
| 1406 | } |
| 1407 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1408 | // -------------------------------------------------------------------- |
| 1409 | |
| 1410 | /** |
| 1411 | * Get value type |
| 1412 | * |
| 1413 | * @return string |
| 1414 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1415 | public function kindOf() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1416 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1417 | switch ($this->mytype) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1418 | { |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1419 | case 3: return 'struct'; |
| 1420 | case 2: return 'array'; |
| 1421 | case 1: return 'scalar'; |
| 1422 | default: return 'undef'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1426 | // -------------------------------------------------------------------- |
| 1427 | |
| 1428 | /** |
| 1429 | * Serialize data |
| 1430 | * |
| 1431 | * @param string |
| 1432 | * @param mixed |
| 1433 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1434 | public function serializedata($typ, $val) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1435 | { |
| 1436 | $rs = ''; |
Derek Jones | a9647e8 | 2010-03-02 22:59:07 -0600 | [diff] [blame] | 1437 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1438 | switch ($this->xmlrpcTypes[$typ]) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1439 | { |
| 1440 | case 3: |
| 1441 | // struct |
| 1442 | $rs .= "<struct>\n"; |
| 1443 | reset($val); |
Pascal Kriete | 14287f3 | 2011-02-14 13:39:34 -0500 | [diff] [blame] | 1444 | while (list($key2, $val2) = each($val)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1445 | { |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1446 | $rs .= "<member>\n<name>{$key2}</name>\n".$this->serializeval($val2)."</member>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1447 | } |
| 1448 | $rs .= '</struct>'; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1449 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1450 | case 2: |
| 1451 | // array |
| 1452 | $rs .= "<array>\n<data>\n"; |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1453 | for ($i = 0, $c = count($val); $i < $c; $i++) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1454 | { |
| 1455 | $rs .= $this->serializeval($val[$i]); |
| 1456 | } |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1457 | $rs .= "</data>\n</array>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1458 | break; |
| 1459 | case 1: |
| 1460 | // others |
| 1461 | switch ($typ) |
| 1462 | { |
| 1463 | case $this->xmlrpcBase64: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1464 | $rs .= '<'.$typ.'>'.base64_encode( (string) $val).'</'.$typ.">\n"; |
| 1465 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1466 | case $this->xmlrpcBoolean: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1467 | $rs .= '<'.$typ.'>'.( (bool) $val ? '1' : '0').'</'.$typ.">\n"; |
| 1468 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1469 | case $this->xmlrpcString: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1470 | $rs .= '<'.$typ.'>'.htmlspecialchars( (string) $val).'</'.$typ.">\n"; |
| 1471 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1472 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1473 | $rs .= '<'.$typ.'>'.$val.'</'.$typ.">\n"; |
| 1474 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1475 | } |
| 1476 | default: |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1477 | break; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1478 | } |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1479 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1480 | return $rs; |
| 1481 | } |
| 1482 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1483 | // -------------------------------------------------------------------- |
| 1484 | |
| 1485 | /** |
| 1486 | * Serialize class |
| 1487 | * |
| 1488 | * @return string |
| 1489 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1490 | public function serialize_class() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1491 | { |
| 1492 | return $this->serializeval($this); |
| 1493 | } |
| 1494 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1495 | // -------------------------------------------------------------------- |
| 1496 | |
| 1497 | /** |
| 1498 | * Serialize value |
| 1499 | * |
| 1500 | * @param object |
| 1501 | * @return string |
| 1502 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1503 | public function serializeval($o) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1504 | { |
| 1505 | $ar = $o->me; |
| 1506 | reset($ar); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1507 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1508 | list($typ, $val) = each($ar); |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1509 | return "<value>\n".$this->serializedata($typ, $val)."</value>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1510 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1511 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1512 | // -------------------------------------------------------------------- |
| 1513 | |
| 1514 | /** |
| 1515 | * Scalar value |
| 1516 | * |
| 1517 | * @return mixed |
| 1518 | */ |
Andrey Andreev | a30faf9 | 2011-12-25 18:15:34 +0200 | [diff] [blame] | 1519 | public function scalarval() |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1520 | { |
| 1521 | reset($this->me); |
Andrey Andreev | adc1175 | 2011-12-30 14:46:08 +0200 | [diff] [blame] | 1522 | return current($this->me); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1525 | // -------------------------------------------------------------------- |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1526 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1527 | /** |
| 1528 | * Encode time in ISO-8601 form. |
| 1529 | * Useful for sending time in XML-RPC |
| 1530 | * |
| 1531 | * @param int unix timestamp |
| 1532 | * @param bool |
| 1533 | * @return string |
| 1534 | */ |
| 1535 | public function iso8601_encode($time, $utc = FALSE) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1536 | { |
Andrey Andreev | 6209015 | 2011-12-30 12:49:27 +0200 | [diff] [blame] | 1537 | 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] | 1538 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 1539 | |
Andrey Andreev | c870983 | 2012-04-04 13:43:53 +0300 | [diff] [blame^] | 1540 | } // END XML_RPC_Values Class |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1541 | |
| 1542 | /* End of file Xmlrpc.php */ |
Andrey Andreev | 8f50b6b | 2012-03-28 14:12:09 +0300 | [diff] [blame] | 1543 | /* Location: ./system/libraries/Xmlrpc.php */ |