commit b3c6aec945bd17943ca6fd8ab1b8d59a6215d39e
Author: Seth Mos <seth.mos@dds.nl>
Date:   Thu Nov 11 21:27:53 2010 +0100

    Update the current XML RPC client and server parts from the PEAR library, now version 1.5.4

diff --git a/etc/inc/xmlrpc_client.inc b/etc/inc/xmlrpc_client.inc
index bac5e1fd50..463d947fb4 100644
--- a/etc/inc/xmlrpc_client.inc
+++ b/etc/inc/xmlrpc_client.inc
@@ -10,38 +10,21 @@
  *
  * PHP versions 4 and 5
  *
- * LICENSE: License is granted to use or modify this software
- * ("XML-RPC for PHP") for commercial or non-commercial use provided the
- * copyright of the author is preserved in any distributed or derivative work.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
  * @category   Web Services
  * @package    XML_RPC
  * @author     Edd Dumbill <edd@usefulinc.com>
  * @author     Stig Bakken <stig@php.net>
  * @author     Martin Jansen <mj@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1999-2001 Edd Dumbill, 2001-2006 The PHP Group
- * @version    CVS: $Id$
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    SVN: $Id: RPC.php 300961 2010-07-03 02:17:34Z danielc $
  * @link       http://pear.php.net/package/XML_RPC
  */
 
-/*
-	pfSense_MODULE:	utils
-*/
 
 if (!function_exists('xml_parser_create')) {
-    include_once 'PEAR.inc';
+    include_once 'PEAR.php';
     PEAR::loadExtension('xml');
 }
 
@@ -202,27 +185,6 @@ $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?
@@ -301,7 +263,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 = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name);
+            $name = preg_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;
@@ -465,7 +427,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 (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
+            if (!preg_match("@^[+-]?[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;
@@ -529,7 +491,7 @@ function XML_RPC_ee($parser_resource, $name)
 
     case 'METHODNAME':
     case 'RPCMETHODNAME':
-        $XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '',
+        $XML_RPC_xh[$parser]['method'] = preg_replace("@^[\n\r\t ]+@", '',
                                                       $XML_RPC_xh[$parser]['ac']);
         break;
     }
@@ -581,8 +543,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Base {
@@ -594,7 +557,7 @@ class XML_RPC_Base {
      */
     function raiseError($msg, $code)
     {
-        include_once 'PEAR.inc';
+        include_once 'PEAR.php';
         if (is_object(@$this)) {
             return PEAR::raiseError(get_class($this) . ': ' . $msg, $code);
         } else {
@@ -626,8 +589,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Client extends XML_RPC_Base {
@@ -765,7 +729,7 @@ class XML_RPC_Client extends XML_RPC_Base {
         $this->proxy_user = $proxy_user;
         $this->proxy_pass = $proxy_pass;
 
-        $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $server, $match);
+        preg_match('@^(http://|https://|ssl://)?(.*)$@', $server, $match);
         if ($match[1] == '') {
             if ($port == 443) {
                 $this->server   = $match[2];
@@ -793,7 +757,7 @@ class XML_RPC_Client extends XML_RPC_Base {
         }
 
         if ($proxy) {
-            $GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match);
+            preg_match('@^(http://|https://|ssl://)?(.*)$@', $proxy, $match);
             if ($match[1] == '') {
                 if ($proxy_port == 443) {
                     $this->proxy          = $match[2];
@@ -923,6 +887,26 @@ class XML_RPC_Client extends XML_RPC_Base {
     function sendPayloadHTTP10($msg, $server, $port, $timeout = 0,
                                $username = '', $password = '')
     {
+        // Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
+        if ($username != $this->username) {
+            $this->setCredentials($username, $password);
+        }
+
+        // Only create the payload if it was not created previously
+        if (empty($msg->payload)) {
+            $msg->createPayload();
+        }
+        $this->createHeaders($msg);
+
+        $op  = $this->headers . "\r\n\r\n";
+        $op .= $msg->payload;
+
+        if ($this->debug) {
+            print "\n<pre>---SENT---\n";
+            print $op;
+            print "\n---END---</pre>\n";
+        }
+
         /*
          * If we're using a proxy open a socket to the proxy server
          * instead to the xml-rpc server
@@ -981,20 +965,6 @@ class XML_RPC_Client extends XML_RPC_Base {
             socket_set_timeout($fp, $timeout);
         }
 
-        // Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
-        if ($username != $this->username) {
-            $this->setCredentials($username, $password);
-        }
-
-        // Only create the payload if it was not created previously
-        if (empty($msg->payload)) {
-            $msg->createPayload();
-        }
-        $this->createHeaders($msg);
-
-        $op  = $this->headers . "\r\n\r\n";
-        $op .= $msg->payload;
-
         if (!fputs($fp, $op, strlen($op))) {
             $this->errstr = 'Write error';
             return 0;
@@ -1068,8 +1038,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Response extends XML_RPC_Base
@@ -1159,8 +1130,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Message extends XML_RPC_Base
@@ -1297,9 +1269,9 @@ class XML_RPC_Message extends XML_RPC_Base
         $this->payload .= "</params>\n";
         $this->payload .= $this->xml_footer();
         if ($this->remove_extra_lines) {
-            $this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload);
+            $this->payload = preg_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);
+            $this->payload = preg_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);
@@ -1421,7 +1393,7 @@ class XML_RPC_Message extends XML_RPC_Base
     {
         global $XML_RPC_defencoding;
 
-        if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]',
+        if (preg_match('@<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]@',
                        $data, $match))
         {
             $match[1] = trim(strtoupper($match[1]));
@@ -1486,9 +1458,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 ($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))
+        if (preg_match('@^HTTP@', $data) &&
+            !preg_match('@^HTTP/[0-9\.]+ 200 @', $data) &&
+            !preg_match('@^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);
@@ -1558,7 +1530,7 @@ class XML_RPC_Message extends XML_RPC_Base
                 $r = new XML_RPC_Response($v);
             }
         }
-        $r->hdrs = split("\r?\n", $XML_RPC_xh[$parser]['ha'][1]);
+        $r->hdrs = preg_split("@\r?\n@", $XML_RPC_xh[$parser]['ha'][1]);
         return $r;
     }
 }
@@ -1572,8 +1544,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Value extends XML_RPC_Base
@@ -1731,7 +1704,7 @@ class XML_RPC_Value extends XML_RPC_Base
             $rs .= "<struct>\n";
             reset($val);
             foreach ($val as $key2 => $val2) {
-                $rs .= "<member><name>${key2}</name>\n";
+                $rs .= "<member><name>" . htmlspecialchars($key2) . "</name>\n";
                 $rs .= $this->serializeval($val2);
                 $rs .= "</member>\n";
             }
@@ -1741,8 +1714,8 @@ class XML_RPC_Value extends XML_RPC_Base
         case 2:
             // array
             $rs .= "<array>\n<data>\n";
-            for ($i = 0; $i < sizeof($val); $i++) {
-                $rs .= $this->serializeval($val[$i]);
+            foreach ($val as $value) {
+                $rs .= $this->serializeval($value);
             }
             $rs .= "</data>\n</array>";
             break;
@@ -1953,7 +1926,7 @@ function XML_RPC_iso8601_encode($timet, $utc = 0)
 function XML_RPC_iso8601_decode($idate, $utc = 0)
 {
     $t = 0;
-    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 (preg_match('@([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 {
@@ -2042,10 +2015,10 @@ function XML_RPC_encode($php_val)
 
     case 'string':
     case 'NULL':
-        if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {
+        if (preg_match('@^[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))
+                  && preg_match("@[^ -~\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.
@@ -2077,4 +2050,4 @@ function XML_RPC_encode($php_val)
  * End:
  */
 
-?>
\ No newline at end of file
+?>
diff --git a/etc/inc/xmlrpc_server.inc b/etc/inc/xmlrpc_server.inc
index 8887bdfc66..22673b3998 100644
--- a/etc/inc/xmlrpc_server.inc
+++ b/etc/inc/xmlrpc_server.inc
@@ -10,40 +10,23 @@
  *
  * PHP versions 4 and 5
  *
- * LICENSE: License is granted to use or modify this software
- * ("XML-RPC for PHP") for commercial or non-commercial use provided the
- * copyright of the author is preserved in any distributed or derivative work.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
  * @category   Web Services
  * @package    XML_RPC
  * @author     Edd Dumbill <edd@usefulinc.com>
  * @author     Stig Bakken <stig@php.net>
  * @author     Martin Jansen <mj@php.net>
  * @author     Daniel Convissor <danielc@php.net>
- * @copyright  1999-2001 Edd Dumbill, 2001-2006 The PHP Group
- * @version    CVS: $Id$
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    SVN: $Id: Server.php 300961 2010-07-03 02:17:34Z danielc $
  * @link       http://pear.php.net/package/XML_RPC
  */
 
-/*
-	pfSense_MODULE:	utils
-*/
 
 /**
  * Pull in the XML_RPC class
  */
-require_once 'xmlrpc_client.inc';
+require_once 'XML/RPC.php';
 
 
 /**
@@ -272,8 +255,9 @@ 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-2006 The PHP Group
- * @version    Release: 1.5.1
+ * @copyright  1999-2001 Edd Dumbill, 2001-2010 The PHP Group
+ * @license    http://www.php.net/license/3_01.txt  PHP License
+ * @version    Release: @package_version@
  * @link       http://pear.php.net/package/XML_RPC
  */
 class XML_RPC_Server
@@ -377,7 +361,7 @@ class XML_RPC_Server
 
         if ($XML_RPC_Server_debuginfo != '') {
             return "<!-- PEAR XML_RPC SERVER DEBUG INFO:\n\n"
-                   . $GLOBALS['XML_RPC_func_ereg_replace']('--', '- - ', $XML_RPC_Server_debuginfo)
+                   . str_replace('--', '- - ', $XML_RPC_Server_debuginfo)
                    . "-->\n";
         } else {
             return '';
@@ -434,9 +418,9 @@ class XML_RPC_Server
          * that someone composed a single header with multiple lines, which
          * the RFCs allow.
          */
-        $this->server_headers = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+[ \t]+",
+        $this->server_headers = preg_replace("@[\r\n]+[ \t]+@",
                                 ' ', trim($this->server_headers));
-        $headers = $GLOBALS['XML_RPC_func_split']("[\r\n]+", $this->server_headers);
+        $headers = preg_split("@[\r\n]+@", $this->server_headers);
         foreach ($headers as $header)
         {
             header($header);
@@ -685,4 +669,4 @@ class XML_RPC_Server
  * End:
  */
 
-?>
\ No newline at end of file
+?>
