Fix constructors to be compliant with php 7
[plcapi.git] / lib / xmlrpcs.inc
index 97035e4..0ab6d54 100644 (file)
@@ -1,7 +1,6 @@
 <?php\r
 // by Edd Dumbill (C) 1999-2002\r
 // <edd@usefulinc.com>\r
-// $Id: xmlrpcs.inc,v 1.71 2008/10/29 23:41:28 ggiunta Exp $\r
 \r
 // Copyright (c) 1999,2000,2002 Edd Dumbill.\r
 // All rights reserved.\r
        /**\r
        * Add a string to the debug info that can be later seralized by the server\r
        * as part of the response message.\r
-       * Note that for best compatbility, the debug string should be encoded using\r
+       * Note that for best compatibility, the debug string should be encoded using\r
        * the $GLOBALS['xmlrpc_internalencoding'] character set.\r
        * @param string $m\r
        * @access public\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
+               /// controls whether 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
                * Controls behaviour of server when invoked user function throws an exception:\r
                var $user_data = null;\r
 \r
                /**\r
-               * @param array $dispmap the dispatch map withd efinition of exposed services\r
-               * @param boolean $servicenow set to false to prevent the server from runnung upon construction\r
+               * @deprecated\r
                */\r
-               function xmlrpc_server($dispMap=null, $serviceNow=true)\r
+               function xmlrpc_client($dispMap=null, $serviceNow=true)\r
+               {\r
+                       self::__construct($dispMap, $serviceNow);\r
+               }\r
+\r
+               /**\r
+               * @param array $dispmap the dispatch map with definition of exposed services\r
+               * @param boolean $servicenow set to false to prevent the server from running upon construction\r
+               */\r
+               function __construct($dispMap=null, $serviceNow=true)\r
                {\r
                        // if ZLIB is enabled, let the server by default accept compressed requests,\r
                        // and compress responses sent to clients that support them\r
                * with the standard processing of the php function exposed as method. In\r
                * particular, triggering an USER_ERROR level error will not halt script\r
                * execution anymore, but just end up logged in the xmlrpc response)\r
-               * Note that info added at elevel 2 and 3 will be base64 encoded\r
+               * Note that info added at level 2 and 3 will be base64 encoded\r
                * @access public\r
                */\r
                function setDebug($in)\r
                        if ($data === null)\r
                        {\r
                                // workaround for a known bug in php ver. 5.2.2 that broke $HTTP_RAW_POST_DATA\r
-                $data = file_get_contents('php://input');\r
+                               $data = file_get_contents('php://input');\r
                        }\r
                        $raw_data = $data;\r
 \r
                * Verify type and number of parameters received against a list of known signatures\r
                * @param array $in array of either xmlrpcval objects or xmlrpc type definitions\r
                * @param array $sig array of known signatures to match against\r
+               * @return array\r
                * @access private\r
                */\r
                function verifySignature($in, $sig)\r
 \r
                /**\r
                * Parse http headers received along with xmlrpc request. If needed, inflate request\r
-               * @return null on success or an xmlrpcresp\r
+               * @return mixed null on success or an xmlrpcresp\r
                * @access private\r
                */\r
                function parseRequestHeaders(&$data, &$req_encoding, &$resp_encoding, &$resp_compression)\r
                        $GLOBALS['_xh']['rt']='';\r
 \r
                        // decompose incoming XML into request structure\r
+\r
                        if ($req_encoding != '')\r
                        {\r
-                               if (!in_array($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))\r
-                               // the following code might be better for mb_string enabled installs, but\r
+                               // Since parsing will fail if charset is not specified in the xml prologue,\r
+                               // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...\r
+                               // The following code might be better for mb_string enabled installs, but\r
                                // makes the lib about 200% slower...\r
-                               //if (!is_valid_charset($req_encoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))\r
-                               {\r
-                                       error_log('XML-RPC: '.__METHOD__.': invalid charset encoding of received request: '.$req_encoding);\r
-                                       $req_encoding = $GLOBALS['xmlrpc_defencoding'];\r
+                               //if (!is_valid_charset($req_encoding, array('UTF-8')))\r
+                               if (!in_array($req_encoding, array('UTF-8', 'US-ASCII')) && !has_encoding($data)) {\r
+                                       if ($req_encoding == 'ISO-8859-1') {\r
+                                               $data = utf8_encode($data);\r
+                                       } else {\r
+                                               if (extension_loaded('mbstring')) {\r
+                                                       $data = mb_convert_encoding($data, 'UTF-8', $req_encoding);\r
+                                               } else {\r
+                                                       error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $req_encoding);\r
+                                               }\r
+                                       }\r
                                }\r
-                               /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue,\r
-                               // the encoding is not UTF8 and there are non-ascii chars in the text...\r
-                               /// @todo use an ampty string for php 5 ???\r
-                               $parser = xml_parser_create($req_encoding);\r
-                       }\r
-                       else\r
-                       {\r
-                               $parser = xml_parser_create();\r
                        }\r
 \r
+                       $parser = xml_parser_create();\r
                        xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);\r
                        // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell\r
                        // the xml parser to give us back data in the expected charset\r
 \r
                /**\r
                * add a string to the 'internal debug message' (separate from 'user debug message')\r
-               * @param string $strings\r
+               * @param string $string\r
                * @access private\r
                */\r
                function debugmsg($string)\r