Fix: php_2_xmlrpc_type is not a public function anymore
[plcapi.git] / src / Server.php
index ec9ebb4..2280847 100644 (file)
@@ -342,7 +342,7 @@ class Server
      *
      * @return mixed null on success or a Response
      */
-    protected function parseRequestHeaders(&$data, &$reqEncoding, &$respEncoding, &$resp_compression)
+    protected function parseRequestHeaders(&$data, &$reqEncoding, &$respEncoding, &$respCompression)
     {
         // check if $_SERVER is populated: it might have been disabled via ini file
         // (this is true even when in CLI mode)
@@ -360,22 +360,22 @@ class Server
         }
 
         if (isset($_SERVER['HTTP_CONTENT_ENCODING'])) {
-            $content_encoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
+            $contentEncoding = str_replace('x-', '', $_SERVER['HTTP_CONTENT_ENCODING']);
         } else {
-            $content_encoding = '';
+            $contentEncoding = '';
         }
 
         // check if request body has been compressed and decompress it
-        if ($content_encoding != '' && strlen($data)) {
-            if ($content_encoding == 'deflate' || $content_encoding == 'gzip') {
+        if ($contentEncoding != '' && strlen($data)) {
+            if ($contentEncoding == 'deflate' || $contentEncoding == 'gzip') {
                 // if decoding works, use it. else assume data wasn't gzencoded
-                if (function_exists('gzinflate') && in_array($content_encoding, $this->accepted_compression)) {
-                    if ($content_encoding == 'deflate' && $degzdata = @gzuncompress($data)) {
+                if (function_exists('gzinflate') && in_array($contentEncoding, $this->accepted_compression)) {
+                    if ($contentEncoding == 'deflate' && $degzdata = @gzuncompress($data)) {
                         $data = $degzdata;
                         if ($this->debug > 1) {
                             $this->debugmsg("\n+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
                         }
-                    } elseif ($content_encoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
+                    } elseif ($contentEncoding == 'gzip' && $degzdata = @gzinflate(substr($data, 10))) {
                         $data = $degzdata;
                         if ($this->debug > 1) {
                             $this->debugmsg("+++INFLATED REQUEST+++[" . strlen($data) . " chars]+++\n" . $data . "\n+++END+++");
@@ -402,11 +402,11 @@ class Server
                 // here we should check if we can match the client-requested encoding
                 // with the encodings we know we can generate.
                 /// @todo we should parse q=0.x preferences instead of getting first charset specified...
-                $client_accepted_charsets = explode(',', strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
+                $clientAcceptedCharsets = explode(',', strtoupper($_SERVER['HTTP_ACCEPT_CHARSET']));
                 // Give preference to internal encoding
-                $known_charsets = array(PhpXmlRpc::$xmlrpc_internalencoding, 'UTF-8', 'ISO-8859-1', 'US-ASCII');
-                foreach ($known_charsets as $charset) {
-                    foreach ($client_accepted_charsets as $accepted) {
+                $knownCharsets = array(PhpXmlRpc::$xmlrpc_internalencoding, 'UTF-8', 'ISO-8859-1', 'US-ASCII');
+                foreach ($knownCharsets as $charset) {
+                    foreach ($clientAcceptedCharsets as $accepted) {
                         if (strpos($accepted, $charset) === 0) {
                             $respEncoding = $charset;
                             break;
@@ -422,14 +422,14 @@ class Server
         }
 
         if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
-            $resp_compression = $_SERVER['HTTP_ACCEPT_ENCODING'];
+            $respCompression = $_SERVER['HTTP_ACCEPT_ENCODING'];
         } else {
-            $resp_compression = '';
+            $respCompression = '';
         }
 
         // 'guestimate' request encoding
         /// @todo check if mbstring is enabled and automagic input conversion is on: it might mingle with this check???
-        $reqEncoding = Encoder::guess_encoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '',
+        $reqEncoding = XMLParser::guessEncoding(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '',
             $data);
 
         return;
@@ -446,34 +446,28 @@ class Server
      */
     public function parseRequest($data, $reqEncoding = '')
     {
-        // 2005/05/07 commented and moved into caller function code
-        //if($data=='')
-        //{
-        //    $data=$GLOBALS['HTTP_RAW_POST_DATA'];
-        //}
-
-        // G. Giunta 2005/02/13: we do NOT expect to receive html entities
-        // so we do not try to convert them into xml character entities
-        //$data = xmlrpc_html_entity_xlate($data);
-
         // decompose incoming XML into request structure
-        if ($reqEncoding != '') {
-            if (!in_array($reqEncoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII'))) {
-                // the following code might be better for mb_string enabled installs, but
-                // makes the lib about 200% slower...
-                //if (!is_valid_charset($reqEncoding, array('UTF-8', 'ISO-8859-1', 'US-ASCII')))
 
-                error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
-                $reqEncoding = PhpXmlRpc::$xmlrpc_defencoding;
+        if ($reqEncoding != '') {
+            // Since parsing will fail if charset is not specified in the xml prologue,
+            // the encoding is not UTF8 and there are non-ascii chars in the text, we try to work round that...
+            // The following code might be better for mb_string enabled installs, but
+            // makes the lib about 200% slower...
+            //if (!is_valid_charset($reqEncoding, array('UTF-8')))
+            if (!in_array($reqEncoding, array('UTF-8', 'US-ASCII')) && !XMLParser::hasEncoding($data)) {
+                if ($reqEncoding == 'ISO-8859-1') {
+                    $data = utf8_encode($data);
+                } else {
+                    if (extension_loaded('mbstring')) {
+                        $data = mb_convert_encoding($data, 'UTF-8', $reqEncoding);
+                    } else {
+                        error_log('XML-RPC: ' . __METHOD__ . ': invalid charset encoding of received request: ' . $reqEncoding);
+                    }
+                }
             }
-            /// @BUG this will fail on PHP 5 if charset is not specified in the xml prologue,
-            // the encoding is not UTF8 and there are non-ascii chars in the text...
-            /// @todo use an empty string for php 5 ???
-            $parser = xml_parser_create($reqEncoding);
-        } else {
-            $parser = xml_parser_create();
         }
 
+        $parser = xml_parser_create();
         xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, true);
         // G. Giunta 2005/02/13: PHP internally uses ISO-8859-1, so we have to tell
         // the xml parser to give us back data in the expected charset
@@ -936,8 +930,9 @@ class Server
         // base64 or datetime values, but they will be listed as strings here...
         $numParams = count($call['params']);
         $pt = array();
+        $wrapper = new Wrapper();
         foreach ($call['params'] as $val) {
-            $pt[] = php_2_xmlrpc_type(gettype($val));
+            $pt[] = $wrapper->php_2_xmlrpc_type(gettype($val));
         }
 
         $result = $server->execute($call['methodName'], $call['params'], $pt);