diff options
author | Seth Mos <seth.mos@xs4all.nl> | 2007-05-09 17:01:04 +0000 |
---|---|---|
committer | Seth Mos <seth.mos@xs4all.nl> | 2007-05-09 17:01:04 +0000 |
commit | 9c22a703bc7d3fff540c64fe3f0e5e1fd3db0a45 (patch) | |
tree | e30b549106d184efb0cd58f3aea880687e3c56e7 /etc/inc | |
parent | 9534ea8b210f0e4f525f342d8356743208a38cb2 (diff) | |
download | pfsense-9c22a703bc7d3fff540c64fe3f0e5e1fd3db0a45.zip pfsense-9c22a703bc7d3fff540c64fe3f0e5e1fd3db0a45.tar.gz |
Update XML_RPC to 1.5.1
This fixes sync issues on configs > 500KB
Diffstat (limited to 'etc/inc')
-rw-r--r-- | etc/inc/xmlrpc_client.inc | 254 | ||||
-rw-r--r-- | etc/inc/xmlrpc_server.inc | 56 |
2 files changed, 235 insertions, 75 deletions
diff --git a/etc/inc/xmlrpc_client.inc b/etc/inc/xmlrpc_client.inc index bc41db6..be514c1 100644 --- a/etc/inc/xmlrpc_client.inc +++ b/etc/inc/xmlrpc_client.inc @@ -31,13 +31,14 @@ * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group * @version CVS: $Id$ * @link http://pear.php.net/package/XML_RPC */ if (!function_exists('xml_parser_create')) { + include_once 'PEAR.inc'; PEAR::loadExtension('xml'); } @@ -198,6 +199,35 @@ $GLOBALS['XML_RPC_errxml'] = 100; $GLOBALS['XML_RPC_backslash'] = chr(92) . chr(92); +/**#@+ + * Which functions to use, depending on whether mbstring is enabled or not. + */ +if (function_exists('mb_ereg')) { + /** @global string $GLOBALS['XML_RPC_func_ereg'] */ + $GLOBALS['XML_RPC_func_ereg'] = 'mb_eregi'; + /** @global string $GLOBALS['XML_RPC_func_ereg_replace'] */ + $GLOBALS['XML_RPC_func_ereg_replace'] = 'mb_eregi_replace'; + /** @global string $GLOBALS['XML_RPC_func_split'] */ + $GLOBALS['XML_RPC_func_split'] = 'mb_split'; +} else { + /** @ignore */ + $GLOBALS['XML_RPC_func_ereg'] = 'eregi'; + /** @ignore */ + $GLOBALS['XML_RPC_func_ereg_replace'] = 'eregi_replace'; + /** @ignore */ + $GLOBALS['XML_RPC_func_split'] = 'split'; +} +/**#@-*/ + + +/** + * Should we automatically base64 encode strings that contain characters + * which can cause PHP's SAX-based XML parser to break? + * @global boolean $GLOBALS['XML_RPC_auto_base64'] + */ +$GLOBALS['XML_RPC_auto_base64'] = false; + + /** * Valid parents of XML elements * @global array $GLOBALS['XML_RPC_valid_parents'] @@ -248,7 +278,8 @@ $GLOBALS['XML_RPC_xh'] = array(); */ function XML_RPC_se($parser_resource, $name, $attrs) { - global $XML_RPC_xh, $XML_RPC_DateTime, $XML_RPC_String, $XML_RPC_valid_parents; + global $XML_RPC_xh, $XML_RPC_valid_parents; + $parser = (int) $parser_resource; // if invalid xmlrpc already detected, skip all processing @@ -267,7 +298,7 @@ function XML_RPC_se($parser_resource, $name, $attrs) } else { // not top level element: see if parent is OK if (!in_array($XML_RPC_xh[$parser]['stack'][0], $XML_RPC_valid_parents[$name])) { - $name = preg_replace('[^a-zA-Z0-9._-]', '', $name); + $name = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name); $XML_RPC_xh[$parser]['isf'] = 2; $XML_RPC_xh[$parser]['isf_reason'] = "xmlrpc element $name cannot be child of {$XML_RPC_xh[$parser]['stack'][0]}"; return; @@ -313,7 +344,7 @@ function XML_RPC_se($parser_resource, $name, $attrs) case 'VALUE': $XML_RPC_xh[$parser]['lv'] = 1; - $XML_RPC_xh[$parser]['vt'] = $XML_RPC_String; + $XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_String']; $XML_RPC_xh[$parser]['ac'] = ''; $XML_RPC_xh[$parser]['qt'] = 0; // look for a value: if this is still 1 by the @@ -334,7 +365,7 @@ function XML_RPC_se($parser_resource, $name, $attrs) $XML_RPC_xh[$parser]['qt'] = 1; if ($name == 'DATETIME.ISO8601') { - $XML_RPC_xh[$parser]['vt'] = $XML_RPC_DateTime; + $XML_RPC_xh[$parser]['vt'] = $GLOBALS['XML_RPC_DateTime']; } } elseif ($name == 'BASE64') { @@ -376,7 +407,8 @@ function XML_RPC_se($parser_resource, $name, $attrs) */ function XML_RPC_ee($parser_resource, $name) { - global $XML_RPC_xh, $XML_RPC_Types, $XML_RPC_String; + global $XML_RPC_xh; + $parser = (int) $parser_resource; if ($XML_RPC_xh[$parser]['isf'] >= 2) { @@ -430,7 +462,7 @@ function XML_RPC_ee($parser_resource, $name) } else { // we have an I4, INT or a DOUBLE // we must check that only 0123456789-.<space> are characters here - if (!ereg("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) { + if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) { XML_RPC_Base::raiseError('Non-numeric value received in INT or DOUBLE', XML_RPC_ERROR_NON_NUMERIC_FOUND); $XML_RPC_xh[$parser]['value'] = XML_RPC_ERROR_NON_NUMERIC_FOUND; @@ -446,7 +478,7 @@ function XML_RPC_ee($parser_resource, $name) break; case 'VALUE': - if ($XML_RPC_xh[$parser]['vt'] == $XML_RPC_String) { + if ($XML_RPC_xh[$parser]['vt'] == $GLOBALS['XML_RPC_String']) { if (strlen($XML_RPC_xh[$parser]['ac']) > 0) { $XML_RPC_xh[$parser]['value'] = $XML_RPC_xh[$parser]['ac']; } elseif ($XML_RPC_xh[$parser]['lv'] == 1) { @@ -494,13 +526,13 @@ function XML_RPC_ee($parser_resource, $name) case 'METHODNAME': case 'RPCMETHODNAME': - $XML_RPC_xh[$parser]['method'] = ereg_replace("^[\n\r\t ]+", '', + $XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '', $XML_RPC_xh[$parser]['ac']); break; } // if it's a valid type name, set the type - if (isset($XML_RPC_Types[strtolower($name)])) { + if (isset($GLOBALS['XML_RPC_Types'][strtolower($name)])) { $XML_RPC_xh[$parser]['vt'] = strtolower($name); } } @@ -513,6 +545,7 @@ function XML_RPC_ee($parser_resource, $name) function XML_RPC_cd($parser_resource, $data) { global $XML_RPC_xh, $XML_RPC_backslash; + $parser = (int) $parser_resource; if ($XML_RPC_xh[$parser]['lv'] != 3) { @@ -545,8 +578,8 @@ function XML_RPC_cd($parser_resource, $data) * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Base { @@ -590,8 +623,8 @@ class XML_RPC_Base { * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Client extends XML_RPC_Base { @@ -729,8 +762,7 @@ class XML_RPC_Client extends XML_RPC_Base { $this->proxy_user = $proxy_user; $this->proxy_pass = $proxy_pass; - $match = ""; - preg_match('@^(http://|https://|ssl://)?(.*)$@', $server, $match); + $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $server, $match); if ($match[1] == '') { if ($port == 443) { $this->server = $match[2]; @@ -758,7 +790,7 @@ class XML_RPC_Client extends XML_RPC_Base { } if ($proxy) { - preg_match('@^(http://|https://|ssl://)?(.*)$@', $proxy, $match); + $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match); if ($match[1] == '') { if ($proxy_port == 443) { $this->proxy = $match[2]; @@ -804,6 +836,26 @@ class XML_RPC_Client extends XML_RPC_Base { } /** + * Sets whether strings that contain characters which may cause PHP's + * SAX-based XML parser to break should be automatically base64 encoded + * + * This is is a workaround for systems that don't have PHP's mbstring + * extension available. + * + * @param int $in where 1 = on, 0 = off + * + * @return void + */ + function setAutoBase64($in) + { + if ($in) { + $GLOBALS['XML_RPC_auto_base64'] = true; + } else { + $GLOBALS['XML_RPC_auto_base64'] = false; + } + } + + /** * Set username and password properties for connecting to the RPC server * * @param string $u the user name @@ -1013,8 +1065,8 @@ class XML_RPC_Client extends XML_RPC_Base { * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Response extends XML_RPC_Base @@ -1104,13 +1156,22 @@ class XML_RPC_Response extends XML_RPC_Base * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Message extends XML_RPC_Base { /** + * Should the payload's content be passed through mb_convert_encoding()? + * + * @see XML_RPC_Message::setConvertPayloadEncoding() + * @since Property available since Release 1.5.1 + * @var boolean + */ + var $convert_payload_encoding = false; + + /** * The current debug mode (1 = on, 0 = off) * @var integer */ @@ -1145,6 +1206,21 @@ class XML_RPC_Message extends XML_RPC_Base var $payload = ''; /** + * Should extra line breaks be removed from the payload? + * @since Property available since Release 1.4.6 + * @var boolean + */ + var $remove_extra_lines = true; + + /** + * The XML response from the remote server + * @since Property available since Release 1.4.6 + * @var string + */ + var $response_payload = ''; + + + /** * @return void */ function XML_RPC_Message($meth, $pars = 0) @@ -1172,6 +1248,7 @@ class XML_RPC_Message extends XML_RPC_Base function xml_header() { global $XML_RPC_defencoding; + if (!$this->send_encoding) { $this->send_encoding = $XML_RPC_defencoding; } @@ -1188,9 +1265,22 @@ class XML_RPC_Message extends XML_RPC_Base } /** + * Fills the XML_RPC_Message::$payload property + * + * Part of the process makes sure all line endings are in DOS format + * (CRLF), which is probably required by specifications. + * + * If XML_RPC_Message::setConvertPayloadEncoding() was set to true, + * the payload gets passed through mb_convert_encoding() + * to ensure the payload matches the encoding set in the + * XML declaration. The encoding type can be manually set via + * XML_RPC_Message::setSendEncoding(). + * * @return void * * @uses XML_RPC_Message::xml_header(), XML_RPC_Message::xml_footer() + * @see XML_RPC_Message::setSendEncoding(), $GLOBALS['XML_RPC_defencoding'], + * XML_RPC_Message::setConvertPayloadEncoding() */ function createPayload() { @@ -1203,7 +1293,14 @@ class XML_RPC_Message extends XML_RPC_Base } $this->payload .= "</params>\n"; $this->payload .= $this->xml_footer(); - $this->payload = ereg_replace("[\r\n]+", "\r\n", $this->payload); + if ($this->remove_extra_lines) { + $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload); + } else { + $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("\r\n|\n|\r|\n\r", "\r\n", $this->payload); + } + if ($this->convert_payload_encoding) { + $this->payload = mb_convert_encoding($this->payload, $this->send_encoding); + } } /** @@ -1267,13 +1364,35 @@ class XML_RPC_Message extends XML_RPC_Base } /** + * Sets whether the payload's content gets passed through + * mb_convert_encoding() + * + * Returns PEAR_ERROR object if mb_convert_encoding() isn't available. + * + * @param int $in where 1 = on, 0 = off + * + * @return void + * + * @see XML_RPC_Message::setSendEncoding() + * @since Method available since Release 1.5.1 + */ + function setConvertPayloadEncoding($in) + { + if ($in && !function_exists('mb_convert_encoding')) { + return $this->raiseError('mb_convert_encoding() is not available', + XML_RPC_ERROR_PROGRAMMING); + } + $this->convert_payload_encoding = $in; + } + + /** * Sets the XML declaration's encoding attribute * * @param string $type the encoding type (ISO-8859-1, UTF-8 or US-ASCII) * * @return void * - * @see XML_RPC_Message::$send_encoding, XML_RPC_Message::xml_header() + * @see XML_RPC_Message::setConvertPayloadEncoding(), XML_RPC_Message::xml_header() * @since Method available since Release 1.2.0 */ function setSendEncoding($type) @@ -1298,8 +1417,8 @@ class XML_RPC_Message extends XML_RPC_Base function getEncoding($data) { global $XML_RPC_defencoding; - $match = ""; - if (preg_match('/<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]/i', + + if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]', $data, $match)) { $match[1] = trim(strtoupper($match[1])); @@ -1308,6 +1427,7 @@ class XML_RPC_Message extends XML_RPC_Base case 'UTF-8': case 'US-ASCII': return $match[1]; + break; default: return $XML_RPC_defencoding; @@ -1363,9 +1483,9 @@ class XML_RPC_Message extends XML_RPC_Base // See if response is a 200 or a 100 then a 200, else raise error. // But only do this if we're using the HTTP protocol. - if (ereg('^HTTP', $data) && - !ereg('^HTTP/[0-9\.]+ 200 ', $data) && - !preg_match('@^HTTP/[0-9\.]+ 10[0-9]([A-Za-z ]+)?[\r\n]+HTTP/[0-9\.]+ 200@', $data)) + if ($GLOBALS['XML_RPC_func_ereg']('^HTTP', $data) && + !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 200 ', $data) && + !$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200', $data)) { $errstr = substr($data, 0, strpos($data, "\n") - 1); error_log('HTTP error, got response: ' . $errstr); @@ -1389,6 +1509,7 @@ class XML_RPC_Message extends XML_RPC_Base * thanks to Luca Mariano <luca.mariano@email.it> */ $data = substr($data, 0, strpos($data, "</methodResponse>") + 17); + $this->response_payload = $data; if (!xml_parse($parser_resource, $data, sizeof($data))) { // thanks to Peter Kocks <peter.kocks@baygate.com> @@ -1425,7 +1546,6 @@ class XML_RPC_Message extends XML_RPC_Base $XML_RPC_str['invalid_return']); } else { $v = $XML_RPC_xh[$parser]['value']; - $allOK=1; if ($XML_RPC_xh[$parser]['isf']) { $f = $v->structmem('faultCode'); $fs = $v->structmem('faultString'); @@ -1449,8 +1569,8 @@ class XML_RPC_Message extends XML_RPC_Base * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Value extends XML_RPC_Base @@ -1463,21 +1583,20 @@ class XML_RPC_Value extends XML_RPC_Base */ function XML_RPC_Value($val = -1, $type = '') { - global $XML_RPC_Types; $this->me = array(); $this->mytype = 0; if ($val != -1 || $type != '') { if ($type == '') { $type = 'string'; } - if (!array_key_exists($type, $XML_RPC_Types)) { + if (!array_key_exists($type, $GLOBALS['XML_RPC_Types'])) { // XXX // need some way to report this error - } elseif ($XML_RPC_Types[$type] == 1) { + } elseif ($GLOBALS['XML_RPC_Types'][$type] == 1) { $this->addScalar($val, $type); - } elseif ($XML_RPC_Types[$type] == 2) { + } elseif ($GLOBALS['XML_RPC_Types'][$type] == 2) { $this->addArray($val); - } elseif ($XML_RPC_Types[$type] == 3) { + } elseif ($GLOBALS['XML_RPC_Types'][$type] == 3) { $this->addStruct($val); } } @@ -1488,21 +1607,19 @@ class XML_RPC_Value extends XML_RPC_Base */ function addScalar($val, $type = 'string') { - global $XML_RPC_Types, $XML_RPC_Boolean; - if ($this->mytype == 1) { $this->raiseError('Scalar can have only one value', XML_RPC_ERROR_INVALID_TYPE); return 0; } - $typeof = $XML_RPC_Types[$type]; + $typeof = $GLOBALS['XML_RPC_Types'][$type]; if ($typeof != 1) { $this->raiseError("Not a scalar type (${typeof})", XML_RPC_ERROR_INVALID_TYPE); return 0; } - if ($type == $XML_RPC_Boolean) { + if ($type == $GLOBALS['XML_RPC_Boolean']) { if (strcasecmp($val, 'true') == 0 || $val == 1 || ($val == true && strcasecmp($val, 'false'))) @@ -1531,14 +1648,13 @@ class XML_RPC_Value extends XML_RPC_Base */ function addArray($vals) { - global $XML_RPC_Types; if ($this->mytype != 0) { $this->raiseError( 'Already initialized as a [' . $this->kindOf() . ']', XML_RPC_ERROR_ALREADY_INITIALIZED); return 0; } - $this->mytype = $XML_RPC_Types['array']; + $this->mytype = $GLOBALS['XML_RPC_Types']['array']; $this->me['array'] = $vals; return 1; } @@ -1548,14 +1664,13 @@ class XML_RPC_Value extends XML_RPC_Base */ function addStruct($vals) { - global $XML_RPC_Types; if ($this->mytype != 0) { $this->raiseError( 'Already initialized as a [' . $this->kindOf() . ']', XML_RPC_ERROR_ALREADY_INITIALIZED); return 0; } - $this->mytype = $XML_RPC_Types['struct']; + $this->mytype = $GLOBALS['XML_RPC_Types']['struct']; $this->me['struct'] = $vals; return 1; } @@ -1602,13 +1717,12 @@ class XML_RPC_Value extends XML_RPC_Base function serializedata($typ, $val) { $rs = ''; - global $XML_RPC_Types, $XML_RPC_Base64, $XML_RPC_String, $XML_RPC_Boolean; - if (!array_key_exists($typ, $XML_RPC_Types)) { + if (!array_key_exists($typ, $GLOBALS['XML_RPC_Types'])) { // XXX // need some way to report this error return; } - switch ($XML_RPC_Types[$typ]) { + switch ($GLOBALS['XML_RPC_Types'][$typ]) { case 3: // struct $rs .= "<struct>\n"; @@ -1632,13 +1746,13 @@ class XML_RPC_Value extends XML_RPC_Base case 1: switch ($typ) { - case $XML_RPC_Base64: + case $GLOBALS['XML_RPC_Base64']: $rs .= "<${typ}>" . base64_encode($val) . "</${typ}>"; break; - case $XML_RPC_Boolean: + case $GLOBALS['XML_RPC_Boolean']: $rs .= "<${typ}>" . ($val ? '1' : '0') . "</${typ}>"; break; - case $XML_RPC_String: + case $GLOBALS['XML_RPC_String']: $rs .= "<${typ}>" . htmlspecialchars($val). "</${typ}>"; break; default: @@ -1700,7 +1814,6 @@ class XML_RPC_Value extends XML_RPC_Base function getval() { // UNSTABLE - global $XML_RPC_BOOLEAN, $XML_RPC_Base64; reset($this->me); $b = current($this->me); @@ -1732,13 +1845,17 @@ class XML_RPC_Value extends XML_RPC_Base } /** - * @return mixed + * @return mixed the current element's scalar value. If the value is + * not scalar, FALSE is returned. */ function scalarval() { - global $XML_RPC_Boolean, $XML_RPC_Base64; reset($this->me); - return current($this->me); + $v = current($this->me); + if (!is_scalar($v)) { + $v = false; + } + return $v; } /** @@ -1746,11 +1863,10 @@ class XML_RPC_Value extends XML_RPC_Base */ function scalartyp() { - global $XML_RPC_I4, $XML_RPC_Int; reset($this->me); $a = key($this->me); - if ($a == $XML_RPC_I4) { - $a = $XML_RPC_Int; + if ($a == $GLOBALS['XML_RPC_I4']) { + $a = $GLOBALS['XML_RPC_Int']; } return $a; } @@ -1834,8 +1950,7 @@ function XML_RPC_iso8601_encode($timet, $utc = 0) function XML_RPC_iso8601_decode($idate, $utc = 0) { $t = 0; - $regs = ""; - if (ereg('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) { + if ($GLOBALS['XML_RPC_func_ereg']('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) { if ($utc) { $t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]); } else { @@ -1886,9 +2001,6 @@ function XML_RPC_decode($XML_RPC_val) */ function XML_RPC_encode($php_val) { - global $XML_RPC_Boolean, $XML_RPC_Int, $XML_RPC_Double, $XML_RPC_String, - $XML_RPC_Array, $XML_RPC_Struct, $XML_RPC_DateTime; - $type = gettype($php_val); $XML_RPC_val = new XML_RPC_Value; @@ -1918,19 +2030,25 @@ function XML_RPC_encode($php_val) break; case 'integer': - $XML_RPC_val->addScalar($php_val, $XML_RPC_Int); + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Int']); break; case 'double': - $XML_RPC_val->addScalar($php_val, $XML_RPC_Double); + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Double']); break; case 'string': case 'NULL': - if(ereg('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) { - $XML_RPC_val->addScalar($php_val, $XML_RPC_DateTime); + if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) { + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']); + } elseif ($GLOBALS['XML_RPC_auto_base64'] + && $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val)) + { + // Characters other than alpha-numeric, punctuation, SP, TAB, + // LF and CR break the XML parser, encode value via Base 64. + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Base64']); } else { - $XML_RPC_val->addScalar($php_val, $XML_RPC_String); + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_String']); } break; @@ -1938,7 +2056,7 @@ function XML_RPC_encode($php_val) // Add support for encoding/decoding of booleans, since they // are supported in PHP // by <G_Giunta_2001-02-29> - $XML_RPC_val->addScalar($php_val, $XML_RPC_Boolean); + $XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_Boolean']); break; case 'unknown type': diff --git a/etc/inc/xmlrpc_server.inc b/etc/inc/xmlrpc_server.inc index 3cdce84..eb667ff 100644 --- a/etc/inc/xmlrpc_server.inc +++ b/etc/inc/xmlrpc_server.inc @@ -31,7 +31,7 @@ * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group * @version CVS: $Id$ * @link http://pear.php.net/package/XML_RPC */ @@ -269,13 +269,22 @@ function XML_RPC_Server_debugmsg($m) * @author Stig Bakken <stig@php.net> * @author Martin Jansen <mj@php.net> * @author Daniel Convissor <danielc@php.net> - * @copyright 1999-2001 Edd Dumbill, 2001-2005 The PHP Group - * @version Release: 1.4.5 + * @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group + * @version Release: 1.5.1 * @link http://pear.php.net/package/XML_RPC */ class XML_RPC_Server { /** + * Should the payload's content be passed through mb_convert_encoding()? + * + * @see XML_RPC_Server::setConvertPayloadEncoding() + * @since Property available since Release 1.5.1 + * @var boolean + */ + var $convert_payload_encoding = false; + + /** * The dispatch map, listing the methods this server provides. * @var array */ @@ -365,7 +374,7 @@ class XML_RPC_Server if ($XML_RPC_Server_debuginfo != '') { return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n" - . preg_replace('/-(?=-)/', '- ', $XML_RPC_Server_debuginfo) + . $GLOBALS['XML_RPC_func_ereg_replace']('--', '- - ', $XML_RPC_Server_debuginfo) . "-->\n"; } else { return ''; @@ -373,6 +382,28 @@ class XML_RPC_Server } /** + * Sets whether the payload's content gets passed through + * mb_convert_encoding() + * + * Returns PEAR_ERROR object if mb_convert_encoding() isn't available. + * + * @param int $in where 1 = on, 0 = off + * + * @return void + * + * @see XML_RPC_Message::getEncoding() + * @since Method available since Release 1.5.1 + */ + function setConvertPayloadEncoding($in) + { + if ($in && !function_exists('mb_convert_encoding')) { + return $this->raiseError('mb_convert_encoding() is not available', + XML_RPC_ERROR_PROGRAMMING); + } + $this->convert_payload_encoding = $in; + } + + /** * Sends the response * * The encoding and content-type are determined by @@ -400,9 +431,9 @@ class XML_RPC_Server * that someone composed a single header with multiple lines, which * the RFCs allow. */ - $this->server_headers = preg_replace("/[\r\n]+[ \t]+/", ' ', - trim($this->server_headers)); - $headers = preg_split("/[\r\n]+/", $this->server_headers); + $this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+[ \t]+", + ' ', trim($this->server_headers)); + $headers = $GLOBALS['XML_RPC_func_split']("[\r\n]+", $this->server_headers); foreach ($headers as $header) { header($header); @@ -414,10 +445,17 @@ class XML_RPC_Server /** * Generates the payload and puts it in the $server_payload property * + * If XML_RPC_Server::setConvertPayloadEncoding() was set to true, + * the payload gets passed through mb_convert_encoding() + * to ensure the payload matches the encoding set in the + * XML declaration. The encoding type can be manually set via + * XML_RPC_Message::setSendEncoding(). + * * @return void * * @uses XML_RPC_Server::parseRequest(), XML_RPC_Server::$encoding, * XML_RPC_Response::serialize(), XML_RPC_Server::serializeDebug() + * @see XML_RPC_Server::setConvertPayloadEncoding() */ function createServerPayload() { @@ -426,6 +464,10 @@ class XML_RPC_Server . $this->encoding . '"?>' . "\n" . $this->serializeDebug() . $r->serialize(); + if ($this->convert_payload_encoding) { + $this->server_payload = mb_convert_encoding($this->server_payload, + $this->encoding); + } } /** |