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