- changelog update
[plcapi.git] / lib / xmlrpc.inc
index 74c2c25..79dbafb 100644 (file)
 \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
+    $GLOBALS['xmlrpc_null_apache_encoding_ns']='http://ws.apache.org/xmlrpc/namespaces/extensions';\r
 \r
        // used to store state during parsing\r
        // quick explanation of components:\r
                                        $GLOBALS['_xh']['value'] = $curr_val['values'];\r
                                        $GLOBALS['_xh']['vt']=strtolower($name);\r
                                        if (isset($curr_val['php_class']))\r
+\r
                                        {\r
                                                $GLOBALS['_xh']['php_class'] = $curr_val['php_class'];\r
                                        }\r
                var $proxy_pass='';\r
                var $proxy_authtype=1;\r
                var $cookies=array();\r
-           var $extracurlopts=array();\r
+               var $extracurlopts=array();\r
 \r
                /**\r
                * List of http compression methods accepted by the client for responses.\r
                * valid strings are 'xmlrpcvals', 'phpvals' or 'xml'\r
                */\r
                var $return_type = 'xmlrpcvals';\r
+               /**\r
+               * Sent to servers in http headers\r
+               */\r
+               var $user_agent;\r
 \r
                /**\r
                * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php\r
 \r
                        // by default the xml parser can support these 3 charset encodings\r
                        $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');\r
+\r
+                       // initialize user_agent string\r
+                       $this->user_agent = $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'];\r
                }\r
 \r
                /**\r
                function setCaCertificate($cacert, $is_dir=false)\r
                {\r
                        if ($is_dir)\r
+\r
                        {\r
                                $this->cacertdir = $cacert;\r
                        }\r
                        if ($compmethod == 'any')\r
                                $this->accepted_compression = array('gzip', 'deflate');\r
                        else\r
-                               $this->accepted_compression = array($compmethod);\r
+                           if ($compmethod == false )\r
+                               $this->accepted_compression = array();\r
+                   else\r
+                               $this->accepted_compression = array($compmethod);\r
                }\r
 \r
                /**\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
+               * 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
+               * Set user-agent string that will be used by this client instance\r
+               * in http headers sent to the server\r
+               */\r
+               function SetUserAgent( $agentstring )\r
+               {\r
+                       $this->user_agent = $agentstring;\r
+               }\r
 \r
                /**\r
                * Send an xmlrpc request\r
                        $msg->debug=$this->debug;\r
 \r
                        if($method == 'https')\r
+\r
                        {\r
                                $r =& $this->sendPayloadHTTPS(\r
                                        $msg,\r
                                $cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";\r
                        }\r
 \r
+                   // omit port if 80\r
+                   $port = ($port == 80) ? '' : (':' . $port);\r
+\r
                        $op= 'POST ' . $uri. " HTTP/1.0\r\n" .\r
-                               'User-Agent: ' . $GLOBALS['xmlrpcName'] . ' ' . $GLOBALS['xmlrpcVersion'] . "\r\n" .\r
-                               'Host: '. $server . ':' . $port . "\r\n" .\r
+                               'User-Agent: ' . $this->user_agent . "\r\n" .\r
+                               'Host: '. $server . $port . "\r\n" .\r
                                $credentials .\r
                                $proxy_credentials .\r
                                $accepted_encoding .\r
                        {\r
                                curl_setopt($curl, CURLOPT_VERBOSE, 1);\r
                        }\r
-                       curl_setopt($curl, CURLOPT_USERAGENT, $GLOBALS['xmlrpcName'].' '.$GLOBALS['xmlrpcVersion']);\r
+                       curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);\r
                        // required for XMLRPC: post the data\r
                        curl_setopt($curl, CURLOPT_POST, 1);\r
                        // the data\r
                        {\r
                                print "<PRE>\n---CURL INFO---\n";\r
                                foreach(curl_getinfo($curl) as $name => $val)\r
-                                        print $name . ': ' . htmlentities($val). "\n";\r
+                               {\r
+                                       if (is_array($val))\r
+                                       {\r
+                                               $val = implode("\n", $val);\r
+                                       }\r
+                                       print $name . ': ' . htmlentities($val) . "\n";\r
+                               }\r
+\r
                                print "---END---\n</PRE>";\r
                        }\r
 \r
                                                case 1:\r
                                                        if(!isset($val[0]))\r
                                                        {\r
+\r
                                                                return false;           // Bad value\r
                                                        }\r
                                                        // Normal return value\r
                                $this->content_type = 'text/xml; charset=' . $charset_encoding;\r
                        else\r
                                $this->content_type = 'text/xml';\r
-                       $result = "<methodResponse>\n";\r
+                   if ($GLOBALS['xmlrpc_null_apache_encoding'])\r
+                   {\r
+                       $result = "<methodResponse xmlns:ex=\"".$GLOBALS['xmlrpc_null_apache_encoding_ns']."\">\n";\r
+                   }\r
+                   else\r
+                   {\r
+                       $result = "<methodResponse>\n";\r
+                   }\r
                        if($this->errno)\r
                        {\r
                                // G. Giunta 2005/2/13: let non-ASCII response messages be tolerated by clients\r
@@ -3300,7 +3341,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                        $out = $xmlrpc_val->scalarval();\r
                                        if (is_string($out))\r
                                        {\r
-                                               $out= strtotime($out);\r
+                                               $out = strtotime($out);\r
                                        }\r
                                        if (is_int($out))\r
                                        {\r
@@ -3449,7 +3490,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                else\r
                                {\r
                                        $arr = array();\r
-                                   reset($php_val);\r
+                                       reset($php_val);\r
                                        while(list($k,$v) = each($php_val))\r
                                        {\r
                                                $arr[$k] = php_xmlrpc_encode($v, $options);\r
@@ -3483,6 +3524,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                        $xmlrpc_val = new xmlrpcval((int)$php_val, $GLOBALS['xmlrpcInt']);\r
                                }\r
                                else\r
+\r
                                {\r
                                        $xmlrpc_val = new xmlrpcval();\r
                                }\r
@@ -3684,6 +3726,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                }\r
                elseif(preg_match('/^(\xEF\xBB\xBF)/', $xmlchunk))\r
                {\r
+\r
                        return 'UTF-8';\r
                }\r
 \r