From: ggiunta Date: Sun, 2 Aug 2009 23:07:01 +0000 (+0000) Subject: - xmlrpcs.inc: add a new member var in server class to allow fine-tuning of the encod... X-Git-Tag: 3.0.0-beta~14 X-Git-Url: http://git.onelab.eu/?p=plcapi.git;a=commitdiff_plain;h=67bfb3d12c48ff14d7f0b3fdfb8512ab5ab335b5 - xmlrpcs.inc: add a new member var in server class to allow fine-tuning of the encoding of returned values when the server is in 'phpvals' mode; allow servers in 'xmlrpcvals' mode to also register plain php functions by defining them in the dispatch map with an added option: 'parameters_type' => 'phpvals' (feature request #2806628); - 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 --- diff --git a/ChangeLog b/ChangeLog index 8b19297..d89df0a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-08-02 - G. Giunta (giunta.gaetano@gmail.com) thanks Laurens + + * xmlrpcs.inc: add a new member var in server class to allow fine-tuning + of the encoding of returned values when the server is in 'phpvals' mode; + allow servers in 'xmlrpcvals' mode to also register plain php functions by + defining them in the dispatch map with an added option: + 'parameters_type' => 'phpvals' (feature request #2806628) + + * 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 + 2009-07-31 - G. Giunta (giunta.gaetano@gmail.com) * xmlrpc.inc: add support for dateTime objects in both in php_xmlrpc_encode @@ -23,7 +37,7 @@ 2009-07-16 - G. Giunta (giunta.gaetano@gmail.com) thanks Jean-Jacques Sarton * xmlrpc.inc: add support for the from the apache library, both - in input and output + in input and output (feature request #...) * xmlrpc.inc, testsuite.php: remove usage of split(), deprecated in php 5.3 @@ -203,7 +217,7 @@ 2006-09-17 Gaetano Giunta - * xmlrpc.inc, xmlrpcs.inc, testsuite.php: added support for and + * xmlrpc.inc, xmlrpcs.inc, testsuite.php: added support for and system.getCapabilities, and one more testcase to go with it 2006-09-05 Gaetano Giunta @@ -1250,7 +1264,7 @@ 2004-12-27 Miles Lott * xmlrpc.inc: A new constant, XMLRPC_EPI_ENABLED, is defined depending on the existence of the function, xmlrpc_decode. This function will exist in - PHP if the extension, XMLRPC-EPI (http://xmlrpc-epi.sourceforge.net), is + PHP if the extension, XMLRPC-EPI (http://xmlrpc-epi.sourceforge.net), is loaded. It defines the functions xmlrpc_encode and xmlrpc_decode, which will conflict with functions of the same name in xmlrpc.inc. If this extension is loaded, we instead use the names php_xmlrpc_encode and diff --git a/lib/xmlrpc.inc b/lib/xmlrpc.inc index 8974fb2..4ac287a 100644 --- a/lib/xmlrpc.inc +++ b/lib/xmlrpc.inc @@ -828,6 +828,8 @@ var $proxy_pass=''; var $proxy_authtype=1; var $cookies=array(); + var $extracurlopts=array(); + /** * List of http compression methods accepted by the client for responses. * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib @@ -926,7 +928,7 @@ $this->accepted_compression = array('gzip', 'deflate'); } - // keepalives: enabled by default ONLY for PHP >= 4.3.8 + // keepalives: enabled by default $this->keepalive = true; // by default the xml parser can support these 3 charset encodings @@ -1097,6 +1099,16 @@ } } + /** + * Directly set cURL options, for extra flexibility + * It allows eg. to bind client to a specific IP interface / address + * @param $options array + */ + function SetCurlOptions( $options ) + { + $this->extracurlopts = $options; + } + /** * Send an xmlrpc request * @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request @@ -1628,6 +1640,11 @@ curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2)); } + foreach ($this->extracurlopts as $opt => $val) + { + curl_setopt($curl, $opt, $val); + } + $result = curl_exec($curl); if ($this->debug > 1) @@ -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' * @return xmlrpcval */ - function &php_xmlrpc_encode($php_val, $options=array()) + function php_xmlrpc_encode($php_val, $options=array()) { $type = gettype($php_val); switch($type) @@ -3411,7 +3428,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha $ko = false; foreach($php_val as $key => $val) { - $arr[$key] =& php_xmlrpc_encode($val, $options); + $arr[$key] = php_xmlrpc_encode($val, $options); if(!$ko && $key !== $j) { $ko = true; @@ -3439,6 +3456,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha else { $arr = array(); + reset($php_val); while(list($k,$v) = each($php_val)) { $arr[$k] = php_xmlrpc_encode($v, $options); diff --git a/lib/xmlrpcs.inc b/lib/xmlrpcs.inc index f124a01..ea6ec13 100644 --- a/lib/xmlrpcs.inc +++ b/lib/xmlrpcs.inc @@ -432,7 +432,10 @@ class xmlrpc_server { - /// array defining php functions exposed as xmlrpc methods by this server + /** + * Array defining php functions exposed as xmlrpc methods by this server + * @access private + */ var $dmap=array(); /** * Defines how functions in dmap will be invoked: either using an xmlrpc msg object @@ -440,6 +443,13 @@ * valid strings are 'xmlrpcvals', 'phpvals' or 'epivals' */ var $functions_parameters_type='xmlrpcvals'; + /** + * Option used for fine-tuning the encoding the php values returned from + * functions registered in the dispatch map when the functions_parameters_types + * member is set to 'phpvals' + * @see php_xmlrpc_encode for a list of values + */ + var $phpvals_encoding_options = array( 'auto_dates' ); /// 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 var $debug = 1; /** @@ -466,9 +476,14 @@ * NB: pretty dangerous if you accept every charset and do not have mbstring enabled) */ var $response_charset_encoding = ''; - /// storage for internal debug info + /** + * Storage for internal debug info + * @access private + */ var $debug_info = ''; - /// extra data passed at runtime to method handling functions. Used only by EPI layer + /** + * Extra data passed at runtime to method handling functions. Used only by EPI layer + */ var $user_data = null; /** @@ -974,7 +989,11 @@ else { xml_parser_free($parser); - if ($this->functions_parameters_type != 'xmlrpcvals') + // small layering violation in favor of speed and memory usage: + // we should allow the 'execute' method handle this, but in the + // most common scenario (xmlrpcvals type server with some methods + // registered as phpvals) that would mean a useless encode+decode pass + if ($this->functions_parameters_type != 'xmlrpcvals' || (isset($this->dmap[$GLOBALS['_xh']['method']]['parameters_type']) && ($this->dmap[$GLOBALS['_xh']['method']]['parameters_type'] == 'phpvals'))) { if($this->debug > 1) { @@ -1077,6 +1096,7 @@ { $GLOBALS['_xmlrpcs_prev_ehandler'] = set_error_handler('_xmlrpcs_errorHandler'); } + // Allow mixed-convention servers if (is_object($m)) { if($sysCall) @@ -1141,7 +1161,7 @@ { // what should we assume here about automatic encoding of datetimes // and php classes instances??? - $r = new xmlrpcresp(php_xmlrpc_encode($r, array('auto_dates'))); + $r = new xmlrpcresp(php_xmlrpc_encode($r, $this->phpvals_encoding_options)); } } if($this->debug > 2)