Remove $id$ tag now that we are on git; update copyright notice to year 2013
[plcapi.git] / lib / xmlrpc.inc
index 74c2c25..5b39a26 100644 (file)
@@ -1,7 +1,6 @@
 <?php\r
 // by Edd Dumbill (C) 1999-2002\r
 // <edd@usefulinc.com>\r
-// $Id: xmlrpc.inc,v 1.174 2009/03/16 19:36:38 ggiunta Exp $\r
 \r
 // Copyright (c) 1999,2000,2002 Edd Dumbill.\r
 // All rights reserved.\r
 \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
                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
                        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
                                $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
                                $this->content_type = 'text/xml; charset=' . $charset_encoding;\r
                        else\r
                                $this->content_type = 'text/xml';\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 +3336,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 +3485,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