From: ggiunta <ggiunta@013ecfd8-0664-425d-a759-9c98391dc3f9>
Date: Thu, 16 Jul 2009 22:33:31 +0000 (+0000)
Subject: - xmlrpc.inc: add support for the <ex:nil/> from the apache library, both in input... 
X-Git-Tag: 3.0.0-beta~23
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2df63e76b84037b28b9a534d9df06c75537caefb;p=plcapi.git

- xmlrpc.inc: add support for the <ex:nil/> from the apache library, both in input and output
- xmlrpc.inc, testsuite.php: remove usage of split(), deprecated in php 5.3
- testsuite.php: flush better results with output_buffering on
- server: php: avoid one warning about static function calls


git-svn-id: https://svn.code.sf.net/p/phpxmlrpc/code/trunk/xmlrpc@23 013ecfd8-0664-425d-a759-9c98391dc3f9
---

diff --git a/ChangeLog b/ChangeLog
index da7d5f5a..b7227b64 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-07-16 - G. Giunta (giunta.gaetano@gmail.com) thanks Jean-Jacques Sarton
+
+	* xmlrpc.inc: add support for the <ex:nil/> from the apache library, both
+	in input and output
+
+	* xmlrpc.inc, testsuite.php: remove usage of split(), deprecated in php 5.3
+
+	* testsuite.php: flush better results with output_buffering on
+
+	* server: php: avoid one warning about static function calls
+
 2009-07-02 - G. Giunta (giunta.gaetano@gmail.com) thanks Heiko Stuebner
 
 	* xmlrpc.inc: fix: when checking the parameters against the signatures xmlrpc
@@ -12,7 +23,7 @@
 
 	* create php4 branch, rename trunk to 3.0.0beta - it will be the php5-only version
 
-	* xmlrpc.inc: removed test fpr php version and inclusion of compat patches for really
+	* xmlrpc.inc: removed test for php version and inclusion of compat patches for really
 	really old versions of php 4
 
 2009-03-16 - G. Giunta (giunta.gaetano@gmail.com) thanks Tommaso Trani
diff --git a/demo/server/server.php b/demo/server/server.php
index 2a8d1859..3a42ad38 100644
--- a/demo/server/server.php
+++ b/demo/server/server.php
@@ -36,14 +36,14 @@ if ($_SERVER['REQUEST_METHOD'] != 'POST' && isset($_GET['showSource']))
 			return new xmlrpcresp(new xmlrpcval(1, 'boolean'));
 		}
 
-        /**
-        * a PHP version of the state-number server. Send me an integer and i'll sell you a state
-        * @param integer $s
-        * @return string
-        * */
-		function findstate($s)
-        {
-		    return inner_findstate($s);
+		/**
+		* a PHP version of the state-number server. Send me an integer and i'll sell you a state
+		* @param integer $s
+		* @return string
+		* */
+		static function findstate($s)
+		{
+			return inner_findstate($s);
 		}
 	}
 
@@ -129,7 +129,7 @@ in an alphabetic order.';
 
 	$findstate3_sig = wrap_php_function(array('xmlrpc_server_methods_container', 'findstate'));
 
-    $obj = new xmlrpc_server_methods_container();
+	$obj = new xmlrpc_server_methods_container();
 
 	$findstate4_sig = wrap_php_function(array($obj, 'findstate'));
 
@@ -241,7 +241,7 @@ in an alphabetic order.';
 	$agesorter_doc='Send this method an array of [string, int] structs, eg:
 <pre>
  Dave   35
- Edd    45
+ Edd	45
  Fred   23
  Barney 37
 </pre>
@@ -570,9 +570,9 @@ mimetype, a string, is a standard MIME type, for example, text/plain.
 		return new xmlrpcresp(new xmlrpcval(array(
 			"ctLeftAngleBrackets"  => new xmlrpcval($lt, "int"),
 			"ctRightAngleBrackets" => new xmlrpcval($gt, "int"),
-			"ctAmpersands"         => new xmlrpcval($amp, "int"),
-			"ctApostrophes"        => new xmlrpcval($ap, "int"),
-			"ctQuotes"             => new xmlrpcval($qu, "int")),
+			"ctAmpersands"		 => new xmlrpcval($amp, "int"),
+			"ctApostrophes"		=> new xmlrpcval($ap, "int"),
+			"ctQuotes"			 => new xmlrpcval($qu, "int")),
 			"struct"
 		));
 	}
diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc
index b02eae2f..a4c9ef22 100644
--- a/lib/xmlrpc.inc
+++ b/lib/xmlrpc.inc
@@ -89,7 +89,8 @@
 		'METHODNAME' => array('METHODCALL'),
 		'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
 		'FAULT' => array('METHODRESPONSE'),
-		'NIL' => array('VALUE') // only used when extension activated
+		'NIL' => array('VALUE'), // only used when extension activated
+		'EX:NIL' => array('VALUE') // only used when extension activated
 	);
 
 	// define extra types for supporting NULL (useful for json or <NIL/>)
@@ -220,9 +221,12 @@
 	/// @deprecated
 	$GLOBALS['xmlrpc_backslash']=chr(92).chr(92);
 
-	// set to TRUE to enable correct decoding of <NIL/> values
+	// set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
 	$GLOBALS['xmlrpc_null_extension']=false;
 
+	// set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
+	$GLOBALS['xmlrpc_null_apache_encoding']=false;
+
 	// used to store state during parsing
 	// quick explanation of components:
 	//   ac - used to accumulate values
@@ -495,6 +499,7 @@
 					$GLOBALS['_xh']['vt']=null;
 					break;
 				case 'NIL':
+				case 'EX:NIL':
 					if ($GLOBALS['xmlrpc_null_extension'])
 					{
 						if ($GLOBALS['_xh']['vt']!='value')
@@ -720,6 +725,7 @@
 					$GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);
 					break;
 				case 'NIL':
+				case 'EX:NIL':
 					if ($GLOBALS['xmlrpc_null_extension'])
 					{
 						$GLOBALS['_xh']['vt']='null';
@@ -2289,7 +2295,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 					}
 				}
 				// be tolerant to line endings, and extra empty lines
-				$ar = split("\r?\n", trim(substr($data, 0, $pos)));
+				$ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));
 				while(list(,$line) = @each($ar))
 				{
 					// take care of multi-line headers and cookies
@@ -2922,7 +2928,14 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
     						$rs.="<${typ}>".preg_replace('/\\.?0+$/','',number_format((double)$val, 128, '.', ''))."</${typ}>";
 							break;
 						case $GLOBALS['xmlrpcNull']:
-							$rs.="<nil/>";
+						    if ($GLOBALS['xmlrpc_null_apache_encoding'])
+						    {
+						        $rs.="<ex:nil/>";
+						    }
+						    else
+                            {
+                                $rs.="<nil/>";
+                            }
 							break;
 						default:
 							// no standard type value should arrive here, but provide a possibility
@@ -3399,7 +3412,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 				{
 					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);
 				}
-				if (in_array('null_extension', $options))
+				else if (in_array('null_extension', $options))
 				{
 					$xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);
 				}
diff --git a/test/PHPUnit/TestSuite.php b/test/PHPUnit/TestSuite.php
index f0618d08..629b3fc3 100644
--- a/test/PHPUnit/TestSuite.php
+++ b/test/PHPUnit/TestSuite.php
@@ -157,7 +157,7 @@ class PHPUnit_TestSuite {
         for ($i = 0; $i < sizeof($this->_tests) && !$result->shouldStop(); $i++) {
             $this->_tests[$i]->run($result);
             if ($show_progress != '') {
-                echo $show_progress; flush();
+                echo $show_progress; flush(); ob_flush();
             }
         }
     }
diff --git a/test/testsuite.php b/test/testsuite.php
index 93de1bd7..5784be4d 100644
--- a/test/testsuite.php
+++ b/test/testsuite.php
@@ -14,6 +14,7 @@
 	if ((int)ini_get('max_execution_time') < 180)
 		ini_set('max_execution_time', 180);
 
+	ini_set('max_execution_time', 180);
 
 	$suite = new PHPUnit_TestSuite();
 
@@ -51,7 +52,7 @@
 		function setUp()
 		{
 			global $DEBUG, $LOCALSERVER, $URI;
-			$server = split(':', $LOCALSERVER);
+			$server = explode(':', $LOCALSERVER);
 			if(count($server) > 1)
 			{
 				$this->client=new xmlrpc_client($URI, $server[0], $server[1]);
@@ -1307,7 +1308,7 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
 			$this->assertEquals(8, $r->faultCode());
 
 			// now test a successful connection
-			$server = split(':', $LOCALSERVER);
+			$server = explode(':', $LOCALSERVER);
 			if(count($server) > 1)
 			{
 				$this->client->port = $server[1];
@@ -1409,6 +1410,7 @@ $f = '<?xml version="1.0" encoding="utf-8"?><methodResponse><params><param><valu
 		echo "<h3>Using lib version: $xmlrpcVersion on PHP version: ".phpversion()."</h3>\n";
 		echo '<h3>Running '.$suite->testCount().' tests (some of which are multiple) against servers: http://'.htmlspecialchars($LOCALSERVER.$URI).' and https://'.htmlspecialchars($HTTPSSERVER.$HTTPSURI)."\n ...</h3>\n";
 		flush();
+	    ob_flush();
 	}
 	else
 	{
@@ -1470,4 +1472,4 @@ Proxy Server: <input name="PROXY" size="30" value="<?php echo isset($PROXY) ? ht
 <?php
 		echo $result->toHTML()."\n</body>\n</html>\n";
 	}
-?>
+?>
\ No newline at end of file