1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
|
From 7371a2180c18e347639c3f76be8bb3414344039c Mon Sep 17 00:00:00 2001
From: George Petculescu <gxgpet@gmail.com>
Date: Sat, 10 Feb 2024 14:52:41 +0200
Subject: [PATCH 1/2] Fixes XML-RPC compatibility with PHP 8
Origin: https://github.com/bcit-ci/CodeIgniter/issues/6264
---
system/libraries/Xmlrpc.php | 161 +++++++++++++++++------------------
system/libraries/Xmlrpcs.php | 13 ++-
2 files changed, 83 insertions(+), 91 deletions(-)
--- a/system/libraries/Xmlrpc.php
+++ b/system/libraries/Xmlrpc.php
@@ -1153,8 +1153,7 @@
//-------------------------------------
$parser = xml_parser_create($this->xmlrpc_defencoding);
- $pname = (string) $parser;
- $this->xh[$pname] = array(
+ $this->xh = array(
'isf' => 0,
'ac' => '',
'headers' => array(),
@@ -1177,7 +1176,7 @@
{
break;
}
- $this->xh[$pname]['headers'][] = $line;
+ $this->xh['headers'][] = $line;
}
$data = implode("\r\n", $lines);
@@ -1195,18 +1194,18 @@
xml_parser_free($parser);
// Got ourselves some badness, it seems
- if ($this->xh[$pname]['isf'] > 1)
+ if ($this->xh['isf'] > 1)
{
if ($this->debug === TRUE)
{
- echo "---Invalid Return---\n".$this->xh[$pname]['isf_reason']."---Invalid Return---\n\n";
+ echo "---Invalid Return---\n".$this->xh['isf_reason']."---Invalid Return---\n\n";
}
- return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$pname]['isf_reason']);
+ return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh['isf_reason']);
}
- elseif ( ! is_object($this->xh[$pname]['value']))
+ elseif ( ! is_object($this->xh['value']))
{
- return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh[$pname]['isf_reason']);
+ return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return'].' '.$this->xh['isf_reason']);
}
// Display XML content for debugging
@@ -1214,10 +1213,10 @@
{
echo '<pre>';
- if (count($this->xh[$pname]['headers']) > 0)
+ if (count($this->xh['headers']) > 0)
{
echo "---HEADERS---\n";
- foreach ($this->xh[$pname]['headers'] as $header)
+ foreach ($this->xh['headers'] as $header)
{
echo $header."\n";
}
@@ -1225,13 +1224,13 @@
}
echo "---DATA---\n".htmlspecialchars($data)."\n---END DATA---\n\n---PARSED---\n";
- var_dump($this->xh[$pname]['value']);
+ var_dump($this->xh['value']);
echo "\n---END PARSED---</pre>";
}
// Send response
- $v = $this->xh[$pname]['value'];
- if ($this->xh[$pname]['isf'])
+ $v = $this->xh['value'];
+ if ($this->xh['isf'])
{
$errno_v = $v->me['struct']['faultCode'];
$errstr_v = $v->me['struct']['faultString'];
@@ -1250,7 +1249,7 @@
$r = new XML_RPC_Response($v);
}
- $r->headers = $this->xh[$pname]['headers'];
+ $r->headers = $this->xh['headers'];
return $r;
}
@@ -1281,26 +1280,24 @@
*/
public function open_tag($the_parser, $name)
{
- $the_parser = (string) $the_parser;
-
// If invalid nesting, then return
- if ($this->xh[$the_parser]['isf'] > 1) return;
+ if ($this->xh['isf'] > 1) return;
// Evaluate and check for correct nesting of XML elements
- if (count($this->xh[$the_parser]['stack']) === 0)
+ if (count($this->xh['stack']) === 0)
{
if ($name !== 'METHODRESPONSE' && $name !== 'METHODCALL')
{
- $this->xh[$the_parser]['isf'] = 2;
- $this->xh[$the_parser]['isf_reason'] = 'Top level XML-RPC element is missing';
+ $this->xh['isf'] = 2;
+ $this->xh['isf_reason'] = 'Top level XML-RPC element is missing';
return;
}
}
// not top level element: see if parent is OK
- elseif ( ! in_array($this->xh[$the_parser]['stack'][0], $this->valid_parents[$name], TRUE))
+ elseif ( ! in_array($this->xh['stack'][0], $this->valid_parents[$name], TRUE))
{
- $this->xh[$the_parser]['isf'] = 2;
- $this->xh[$the_parser]['isf_reason'] = 'XML-RPC element '.$name.' cannot be child of '.$this->xh[$the_parser]['stack'][0];
+ $this->xh['isf'] = 2;
+ $this->xh['isf_reason'] = 'XML-RPC element '.$name.' cannot be child of '.$this->xh['stack'][0];
return;
}
@@ -1310,22 +1307,22 @@
case 'ARRAY':
// Creates array for child elements
$cur_val = array('value' => array(), 'type' => $name);
- array_unshift($this->xh[$the_parser]['valuestack'], $cur_val);
+ array_unshift($this->xh['valuestack'], $cur_val);
break;
case 'METHODNAME':
case 'NAME':
- $this->xh[$the_parser]['ac'] = '';
+ $this->xh['ac'] = '';
break;
case 'FAULT':
- $this->xh[$the_parser]['isf'] = 1;
+ $this->xh['isf'] = 1;
break;
case 'PARAM':
- $this->xh[$the_parser]['value'] = NULL;
+ $this->xh['value'] = NULL;
break;
case 'VALUE':
- $this->xh[$the_parser]['vt'] = 'value';
- $this->xh[$the_parser]['ac'] = '';
- $this->xh[$the_parser]['lv'] = 1;
+ $this->xh['vt'] = 'value';
+ $this->xh['ac'] = '';
+ $this->xh['lv'] = 1;
break;
case 'I4':
case 'INT':
@@ -1334,23 +1331,23 @@
case 'DOUBLE':
case 'DATETIME.ISO8601':
case 'BASE64':
- if ($this->xh[$the_parser]['vt'] !== 'value')
+ if ($this->xh['vt'] !== 'value')
{
//two data elements inside a value: an error occurred!
- $this->xh[$the_parser]['isf'] = 2;
- $this->xh[$the_parser]['isf_reason'] = 'There is a '.$name.' element following a '
- .$this->xh[$the_parser]['vt'].' element inside a single value';
+ $this->xh['isf'] = 2;
+ $this->xh['isf_reason'] = 'There is a '.$name.' element following a '
+ .$this->xh['vt'].' element inside a single value';
return;
}
- $this->xh[$the_parser]['ac'] = '';
+ $this->xh['ac'] = '';
break;
case 'MEMBER':
// Set name of <member> to nothing to prevent errors later if no <name> is found
- $this->xh[$the_parser]['valuestack'][0]['name'] = '';
+ $this->xh['valuestack'][0]['name'] = '';
// Set NULL value to check to see if value passed for this param/member
- $this->xh[$the_parser]['value'] = NULL;
+ $this->xh['value'] = NULL;
break;
case 'DATA':
case 'METHODCALL':
@@ -1360,15 +1357,15 @@
break;
default:
/// An Invalid Element is Found, so we have trouble
- $this->xh[$the_parser]['isf'] = 2;
- $this->xh[$the_parser]['isf_reason'] = 'Invalid XML-RPC element found: '.$name;
+ $this->xh['isf'] = 2;
+ $this->xh['isf_reason'] = 'Invalid XML-RPC element found: '.$name;
break;
}
// Add current element name to stack, to allow validation of nesting
- array_unshift($this->xh[$the_parser]['stack'], $name);
+ array_unshift($this->xh['stack'], $name);
- $name === 'VALUE' OR $this->xh[$the_parser]['lv'] = 0;
+ $name === 'VALUE' OR $this->xh['lv'] = 0;
}
// --------------------------------------------------------------------
@@ -1382,27 +1379,25 @@
*/
public function closing_tag($the_parser, $name)
{
- $the_parser = (string) $the_parser;
-
- if ($this->xh[$the_parser]['isf'] > 1) return;
+ if ($this->xh['isf'] > 1) return;
// Remove current element from stack and set variable
// NOTE: If the XML validates, then we do not have to worry about
// the opening and closing of elements. Nesting is checked on the opening
// tag so we be safe there as well.
- $curr_elem = array_shift($this->xh[$the_parser]['stack']);
+ $curr_elem = array_shift($this->xh['stack']);
switch ($name)
{
case 'STRUCT':
case 'ARRAY':
- $cur_val = array_shift($this->xh[$the_parser]['valuestack']);
- $this->xh[$the_parser]['value'] = isset($cur_val['values']) ? $cur_val['values'] : array();
- $this->xh[$the_parser]['vt'] = strtolower($name);
+ $cur_val = array_shift($this->xh['valuestack']);
+ $this->xh['value'] = isset($cur_val['values']) ? $cur_val['values'] : array();
+ $this->xh['vt'] = strtolower($name);
break;
case 'NAME':
- $this->xh[$the_parser]['valuestack'][0]['name'] = $this->xh[$the_parser]['ac'];
+ $this->xh['valuestack'][0]['name'] = $this->xh['ac'];
break;
case 'BOOLEAN':
case 'I4':
@@ -1411,87 +1406,87 @@
case 'DOUBLE':
case 'DATETIME.ISO8601':
case 'BASE64':
- $this->xh[$the_parser]['vt'] = strtolower($name);
+ $this->xh['vt'] = strtolower($name);
if ($name === 'STRING')
{
- $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
+ $this->xh['value'] = $this->xh['ac'];
}
elseif ($name === 'DATETIME.ISO8601')
{
- $this->xh[$the_parser]['vt'] = $this->xmlrpcDateTime;
- $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
+ $this->xh['vt'] = $this->xmlrpcDateTime;
+ $this->xh['value'] = $this->xh['ac'];
}
elseif ($name === 'BASE64')
{
- $this->xh[$the_parser]['value'] = base64_decode($this->xh[$the_parser]['ac']);
+ $this->xh['value'] = base64_decode($this->xh['ac']);
}
elseif ($name === 'BOOLEAN')
{
// Translated BOOLEAN values to TRUE AND FALSE
- $this->xh[$the_parser]['value'] = (bool) $this->xh[$the_parser]['ac'];
+ $this->xh['value'] = (bool) $this->xh['ac'];
}
elseif ($name=='DOUBLE')
{
// we have a DOUBLE
// we must check that only 0123456789-.<space> are characters here
- $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh[$the_parser]['ac'])
- ? (float) $this->xh[$the_parser]['ac']
+ $this->xh['value'] = preg_match('/^[+-]?[eE0-9\t \.]+$/', $this->xh['ac'])
+ ? (float) $this->xh['ac']
: 'ERROR_NON_NUMERIC_FOUND';
}
else
{
// we have an I4/INT
// we must check that only 0123456789-<space> are characters here
- $this->xh[$the_parser]['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh[$the_parser]['ac'])
- ? (int) $this->xh[$the_parser]['ac']
+ $this->xh['value'] = preg_match('/^[+-]?[0-9\t ]+$/', $this->xh['ac'])
+ ? (int) $this->xh['ac']
: 'ERROR_NON_NUMERIC_FOUND';
}
- $this->xh[$the_parser]['ac'] = '';
- $this->xh[$the_parser]['lv'] = 3; // indicate we've found a value
+ $this->xh['ac'] = '';
+ $this->xh['lv'] = 3; // indicate we've found a value
break;
case 'VALUE':
// This if() detects if no scalar was inside <VALUE></VALUE>
- if ($this->xh[$the_parser]['vt'] == 'value')
+ if ($this->xh['vt'] == 'value')
{
- $this->xh[$the_parser]['value'] = $this->xh[$the_parser]['ac'];
- $this->xh[$the_parser]['vt'] = $this->xmlrpcString;
+ $this->xh['value'] = $this->xh['ac'];
+ $this->xh['vt'] = $this->xmlrpcString;
}
// build the XML-RPC value out of the data received, and substitute it
- $temp = new XML_RPC_Values($this->xh[$the_parser]['value'], $this->xh[$the_parser]['vt']);
+ $temp = new XML_RPC_Values($this->xh['value'], $this->xh['vt']);
- if (count($this->xh[$the_parser]['valuestack']) && $this->xh[$the_parser]['valuestack'][0]['type'] === 'ARRAY')
+ if (count($this->xh['valuestack']) && $this->xh['valuestack'][0]['type'] === 'ARRAY')
{
// Array
- $this->xh[$the_parser]['valuestack'][0]['values'][] = $temp;
+ $this->xh['valuestack'][0]['values'][] = $temp;
}
else
{
// Struct
- $this->xh[$the_parser]['value'] = $temp;
+ $this->xh['value'] = $temp;
}
break;
case 'MEMBER':
- $this->xh[$the_parser]['ac'] = '';
+ $this->xh['ac'] = '';
// If value add to array in the stack for the last element built
- if ($this->xh[$the_parser]['value'])
+ if ($this->xh['value'])
{
- $this->xh[$the_parser]['valuestack'][0]['values'][$this->xh[$the_parser]['valuestack'][0]['name']] = $this->xh[$the_parser]['value'];
+ $this->xh['valuestack'][0]['values'][$this->xh['valuestack'][0]['name']] = $this->xh['value'];
}
break;
case 'DATA':
- $this->xh[$the_parser]['ac'] = '';
+ $this->xh['ac'] = '';
break;
case 'PARAM':
- if ($this->xh[$the_parser]['value'])
+ if ($this->xh['value'])
{
- $this->xh[$the_parser]['params'][] = $this->xh[$the_parser]['value'];
+ $this->xh['params'][] = $this->xh['value'];
}
break;
case 'METHODNAME':
- $this->xh[$the_parser]['method'] = ltrim($this->xh[$the_parser]['ac']);
+ $this->xh['method'] = ltrim($this->xh['ac']);
break;
case 'PARAMS':
case 'FAULT':
@@ -1516,24 +1511,22 @@
*/
public function character_data($the_parser, $data)
{
- $the_parser = (string) $the_parser;
-
- if ($this->xh[$the_parser]['isf'] > 1) return; // XML Fault found already
+ if ($this->xh['isf'] > 1) return; // XML Fault found already
// If a value has not been found
- if ($this->xh[$the_parser]['lv'] !== 3)
+ if ($this->xh['lv'] !== 3)
{
- if ($this->xh[$the_parser]['lv'] === 1)
+ if ($this->xh['lv'] === 1)
{
- $this->xh[$the_parser]['lv'] = 2; // Found a value
+ $this->xh['lv'] = 2; // Found a value
}
- if ( ! isset($this->xh[$the_parser]['ac']))
+ if ( ! isset($this->xh['ac']))
{
- $this->xh[$the_parser]['ac'] = '';
+ $this->xh['ac'] = '';
}
- $this->xh[$the_parser]['ac'] .= $data;
+ $this->xh['ac'] .= $data;
}
}
--- a/system/libraries/Xmlrpcs.php
+++ b/system/libraries/Xmlrpcs.php
@@ -234,9 +234,8 @@
$parser = xml_parser_create($this->xmlrpc_defencoding);
$parser_object = new XML_RPC_Message('filler');
- $pname = (string) $parser;
- $parser_object->xh[$pname] = array(
+ $parser_object->xh = array(
'isf' => 0,
'isf_reason' => '',
'params' => array(),
@@ -265,7 +264,7 @@
xml_get_current_line_number($parser)));
xml_parser_free($parser);
}
- elseif ($parser_object->xh[$pname]['isf'])
+ elseif ($parser_object->xh['isf'])
{
return new XML_RPC_Response(0, $this->xmlrpcerr['invalid_return'], $this->xmlrpcstr['invalid_return']);
}
@@ -273,17 +272,17 @@
{
xml_parser_free($parser);
- $m = new XML_RPC_Message($parser_object->xh[$pname]['method']);
+ $m = new XML_RPC_Message($parser_object->xh['method']);
$plist = '';
- for ($i = 0, $c = count($parser_object->xh[$pname]['params']); $i < $c; $i++)
+ for ($i = 0, $c = count($parser_object->xh['params']); $i < $c; $i++)
{
if ($this->debug === TRUE)
{
- $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh[$pname]['params'][$i]), TRUE).";\n";
+ $plist .= $i.' - '.print_r(get_object_vars($parser_object->xh['params'][$i]), TRUE).";\n";
}
- $m->addParam($parser_object->xh[$pname]['params'][$i]);
+ $m->addParam($parser_object->xh['params'][$i]);
}
if ($this->debug === TRUE)
|