- xmlrpc.inc: add support for the <ex:nil/> from the apache library, both in input...
[plcapi.git] / lib / xmlrpc.inc
index b02eae2..a4c9ef2 100644 (file)
@@ -89,7 +89,8 @@
                'METHODNAME' => array('METHODCALL'),\r
                'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),\r
                'FAULT' => array('METHODRESPONSE'),\r
-               'NIL' => array('VALUE') // only used when extension activated\r
+               'NIL' => array('VALUE'), // only used when extension activated\r
+               'EX:NIL' => array('VALUE') // only used when extension activated\r
        );\r
 \r
        // define extra types for supporting NULL (useful for json or <NIL/>)\r
        /// @deprecated\r
        $GLOBALS['xmlrpc_backslash']=chr(92).chr(92);\r
 \r
-       // set to TRUE to enable correct decoding of <NIL/> values\r
+       // set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values\r
        $GLOBALS['xmlrpc_null_extension']=false;\r
 \r
+       // set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>\r
+       $GLOBALS['xmlrpc_null_apache_encoding']=false;\r
+\r
        // used to store state during parsing\r
        // quick explanation of components:\r
        //   ac - used to accumulate values\r
                                        $GLOBALS['_xh']['vt']=null;\r
                                        break;\r
                                case 'NIL':\r
+                               case 'EX:NIL':\r
                                        if ($GLOBALS['xmlrpc_null_extension'])\r
                                        {\r
                                                if ($GLOBALS['_xh']['vt']!='value')\r
                                        $GLOBALS['_xh']['method']=preg_replace('/^[\n\r\t ]+/', '', $GLOBALS['_xh']['ac']);\r
                                        break;\r
                                case 'NIL':\r
+                               case 'EX:NIL':\r
                                        if ($GLOBALS['xmlrpc_null_extension'])\r
                                        {\r
                                                $GLOBALS['_xh']['vt']='null';\r
@@ -2289,7 +2295,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                        }\r
                                }\r
                                // be tolerant to line endings, and extra empty lines\r
-                               $ar = split("\r?\n", trim(substr($data, 0, $pos)));\r
+                               $ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));\r
                                while(list(,$line) = @each($ar))\r
                                {\r
                                        // take care of multi-line headers and cookies\r
@@ -2922,7 +2928,14 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                                $rs.="<${typ}>".preg_replace('/\\.?0+$/','',number_format((double)$val, 128, '.', ''))."</${typ}>";\r
                                                        break;\r
                                                case $GLOBALS['xmlrpcNull']:\r
-                                                       $rs.="<nil/>";\r
+                                                   if ($GLOBALS['xmlrpc_null_apache_encoding'])\r
+                                                   {\r
+                                                       $rs.="<ex:nil/>";\r
+                                                   }\r
+                                                   else\r
+                            {\r
+                                $rs.="<nil/>";\r
+                            }\r
                                                        break;\r
                                                default:\r
                                                        // no standard type value should arrive here, but provide a possibility\r
@@ -3399,7 +3412,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                {\r
                                        $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcString']);\r
                                }\r
-                               if (in_array('null_extension', $options))\r
+                               else if (in_array('null_extension', $options))\r
                                {\r
                                        $xmlrpc_val = new xmlrpcval('', $GLOBALS['xmlrpcNull']);\r
                                }\r