- xmlrpcs.inc: add a new member var in server class to allow fine-tuning of the encod...
authorggiunta <ggiunta@013ecfd8-0664-425d-a759-9c98391dc3f9>
Sun, 2 Aug 2009 23:07:01 +0000 (23:07 +0000)
committerggiunta <ggiunta@013ecfd8-0664-425d-a759-9c98391dc3f9>
Sun, 2 Aug 2009 23:07:01 +0000 (23:07 +0000)
- xmlrpc.inc: added new method xmrlpc_client::SetCurlOptions($array) to allow extra flexibility in tweaking http config, such as explicitly binding to an ip address (feature request #2787468); fix bad encoding if same object is encoded twice using php_xmlrpc_encode; removed some by-ref assignments and declarations

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

ChangeLog
lib/xmlrpc.inc
lib/xmlrpcs.inc

index 8b19297..d89df0a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-08-02 - G. Giunta (giunta.gaetano@gmail.com) thanks Laurens\r
+\r
+       * xmlrpcs.inc: add a new member var in server class to allow fine-tuning\r
+       of the encoding of returned values when the server is in 'phpvals' mode;\r
+       allow servers in 'xmlrpcvals' mode to also register plain php functions by\r
+       defining them in the dispatch map with an added option:\r
+       'parameters_type' => 'phpvals' (feature request #2806628)\r
+\r
+       * xmlrpc.inc: added new method xmrlpc_client::SetCurlOptions($array) to\r
+       allow extra flexibility in tweaking http config, such as explicitly\r
+       binding to an ip address (feature request #2787468); fix bad encoding if\r
+       same object is encoded twice using php_xmlrpc_encode; removed some by-ref\r
+       assignments and declarations\r
+\r
 2009-07-31 - G. Giunta (giunta.gaetano@gmail.com)\r
 \r
        * xmlrpc.inc: add support for dateTime objects in both in php_xmlrpc_encode\r
@@ -23,7 +37,7 @@
 2009-07-16 - G. Giunta (giunta.gaetano@gmail.com) thanks Jean-Jacques Sarton\r
 \r
        * xmlrpc.inc: add support for the <ex:nil/> from the apache library, both\r
-       in input and output\r
+       in input and output (feature request #...)\r
 \r
        * xmlrpc.inc, testsuite.php: remove usage of split(), deprecated in php 5.3\r
 \r
 \r
 2006-09-17 Gaetano Giunta <giunta.gaetano@gmail.com>\r
 \r
-       * xmlrpc.inc, xmlrpcs.inc, testsuite.php: added support for </NIL> and\r
+       * xmlrpc.inc, xmlrpcs.inc, testsuite.php: added support for <NIL/> and\r
        system.getCapabilities, and one more testcase to go with it\r
 \r
 2006-09-05 Gaetano Giunta <giunta.gaetano@gmail.com>\r
 2004-12-27  Miles Lott <milos@groupwhere.org>\r
        * xmlrpc.inc: A new constant, XMLRPC_EPI_ENABLED, is defined depending on\r
        the existence of the function, xmlrpc_decode.  This function will exist in\r
-       PHP if the      extension, XMLRPC-EPI (http://xmlrpc-epi.sourceforge.net), is\r
+       PHP if the extension, XMLRPC-EPI (http://xmlrpc-epi.sourceforge.net), is\r
        loaded.  It defines the functions xmlrpc_encode and xmlrpc_decode, which\r
        will conflict with functions of the same name in xmlrpc.inc.  If this\r
        extension is loaded, we instead use the names php_xmlrpc_encode and\r
index 8974fb2..4ac287a 100644 (file)
                var $proxy_pass='';\r
                var $proxy_authtype=1;\r
                var $cookies=array();\r
+           var $extracurlopts=array();\r
+\r
                /**\r
                * List of http compression methods accepted by the client for responses.\r
                * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib\r
                                $this->accepted_compression = array('gzip', 'deflate');\r
                        }\r
 \r
-                       // keepalives: enabled by default ONLY for PHP >= 4.3.8\r
+                       // keepalives: enabled by default\r
                        $this->keepalive = true;\r
 \r
                        // by default the xml parser can support these 3 charset encodings\r
                        }\r
                }\r
 \r
+           /**\r
+           * Directly set cURL options, for extra flexibility\r
+           * It allows eg. to bind client to a specific IP interface / address\r
+           * @param $options array\r
+           */\r
+           function SetCurlOptions( $options )\r
+           {\r
+               $this->extracurlopts = $options;\r
+           }\r
+\r
                /**\r
                * Send an xmlrpc request\r
                * @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request\r
                                curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));\r
                        }\r
 \r
+                   foreach ($this->extracurlopts as $opt => $val)\r
+                   {\r
+                       curl_setopt($curl, $opt, $val);\r
+                   }\r
+\r
                        $result = curl_exec($curl);\r
 \r
                        if ($this->debug > 1)\r
@@ -3377,7 +3394,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
        * @param array $options can include 'encode_php_objs', 'auto_dates', 'null_extension' or 'extension_api'\r
        * @return xmlrpcval\r
        */\r
-       function &php_xmlrpc_encode($php_val, $options=array())\r
+       function php_xmlrpc_encode($php_val, $options=array())\r
        {\r
                $type = gettype($php_val);\r
                switch($type)\r
@@ -3411,7 +3428,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                $ko = false;\r
                                foreach($php_val as $key => $val)\r
                                {\r
-                                       $arr[$key] =& php_xmlrpc_encode($val, $options);\r
+                                       $arr[$key] = php_xmlrpc_encode($val, $options);\r
                                        if(!$ko && $key !== $j)\r
                                        {\r
                                                $ko = true;\r
@@ -3439,6 +3456,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                else\r
                                {\r
                                        $arr = array();\r
+                                   reset($php_val);\r
                                        while(list($k,$v) = each($php_val))\r
                                        {\r
                                                $arr[$k] = php_xmlrpc_encode($v, $options);\r
index f124a01..ea6ec13 100644 (file)
 \r
        class xmlrpc_server\r
        {\r
-               /// array defining php functions exposed as xmlrpc methods by this server\r
+               /**\r
+               * Array defining php functions exposed as xmlrpc methods by this server\r
+               * @access private\r
+               */\r
                var $dmap=array();\r
                /**\r
                * Defines how functions in dmap will be invoked: either using an xmlrpc msg object\r
                * valid strings are 'xmlrpcvals', 'phpvals' or 'epivals'\r
                */\r
                var $functions_parameters_type='xmlrpcvals';\r
+           /**\r
+           * Option used for fine-tuning the encoding the php values returned from\r
+           * functions registered in the dispatch map when the functions_parameters_types\r
+           *  member is set to 'phpvals'\r
+           * @see php_xmlrpc_encode for a list of values\r
+           */\r
+           var $phpvals_encoding_options = array( 'auto_dates' );\r
                /// controls wether the server is going to echo debugging messages back to the client as comments in response body. valid values: 0,1,2,3\r
                var $debug = 1;\r
                /**\r
                * NB: pretty dangerous if you accept every charset and do not have mbstring enabled)\r
                */\r
                var $response_charset_encoding = '';\r
-               /// storage for internal debug info\r
+               /**\r
+               * Storage for internal debug info\r
+               * @access private\r
+               */\r
                var $debug_info = '';\r
-               /// extra data passed at runtime to method handling functions. Used only by EPI layer\r
+               /**\r
+               * Extra data passed at runtime to method handling functions. Used only by EPI layer\r
+               */\r
                var $user_data = null;\r
 \r
                /**\r
                        else\r
                        {\r
                                xml_parser_free($parser);\r
-                               if ($this->functions_parameters_type != 'xmlrpcvals')\r
+                           // small layering violation in favor of speed and memory usage:\r
+                           // we should allow the 'execute' method handle this, but in the\r
+                           // most common scenario (xmlrpcvals type server with some methods\r
+                           // registered as phpvals) that would mean a useless encode+decode pass\r
+                               if ($this->functions_parameters_type != 'xmlrpcvals' || (isset($this->dmap[$GLOBALS['_xh']['method']]['parameters_type']) && ($this->dmap[$GLOBALS['_xh']['method']]['parameters_type'] == 'phpvals')))\r
                                {\r
                                        if($this->debug > 1)\r
                                        {\r
                        {\r
                                $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler');\r
                        }\r
+                   // Allow mixed-convention servers\r
                        if (is_object($m))\r
                        {\r
                                if($sysCall)\r
                                {\r
                                        // what should we assume here about automatic encoding of datetimes\r
                                        // and php classes instances???\r
-                                       $r = new xmlrpcresp(php_xmlrpc_encode($r, array('auto_dates')));\r
+                                       $r = new xmlrpcresp(php_xmlrpc_encode($r, $this->phpvals_encoding_options));\r
                                }\r
                        }\r
                        if($this->debug > 2)\r