- when using curl and keepalive, reset curl handle if we did not get back an http...
[plcapi.git] / lib / xmlrpc.inc
index 5deade3..c3c8995 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
                                        $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
                * http://curl.haxx.se/docs/faq.html#7.3)\r
                */\r
                var $xmlrpc_curl_handle = null;\r
-               /// Wheter to use persistent connections for http 1.1 and https\r
+               /// Whether to use persistent connections for http 1.1 and https\r
                var $keepalive = false;\r
                /// Charset encodings that can be decoded without problems by the client\r
                var $accepted_charset_encodings = array();\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
-                           if ($compmethod == false )\r
-                               $this->accepted_compression = array();\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
                        $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
+                       // omit port if 80\r
+                       $port = ($port == 80) ? '' : (':' . $port);\r
 \r
                        $op= 'POST ' . $uri. " HTTP/1.0\r\n" .\r
                                'User-Agent: ' . $this->user_agent . "\r\n" .\r
                                        curl_close($curl);\r
                                }\r
                                $resp =& $msg->parseResponse($result, true, $this->return_type);\r
+                // if we got back a 302, we can not reuse the curl handle for later calls\r
+                if($resp->faultCode() == $GLOBALS['xmlrpcerr']['http_error'] && $keepalive)\r
+                {\r
+                    curl_close($curl);\r
+                    $this->xmlrpc_curl_handle = null;\r
+                }\r
                        }\r
                        return $resp;\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
-                   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 ($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
@@ -3524,7 +3525,6 @@ 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
@@ -3726,7 +3726,6 @@ 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