Bump requirements to 5.1.0; grammar fixes in comments
[plcapi.git] / lib / xmlrpc.inc
index 79dbafb..aeaf4be 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
 \r
                /**\r
                * Enables/disables the echoing to screen of the xmlrpc responses received\r
-               * @param integer $debug values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)\r
+               * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)\r
                * @access public\r
                */\r
                function setDebug($in)\r
 \r
                /**\r
                * Add a CA certificate to verify server with (see man page about\r
-               * CURLOPT_CAINFO for more details\r
+               * CURLOPT_CAINFO for more details)\r
                * @param string $cacert certificate file name (or dir holding certificates)\r
                * @param bool $is_dir set to true to indicate cacert is a dir. defaults to false\r
                * @access public\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
                /**\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
+               * @param array $options\r
                */\r
                function SetCurlOptions( $options )\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
                        }\r
                        else\r
                        {\r
-                               // reset errno and errstr on succesful socket connection\r
+                               // reset errno and errstr on successful socket connection\r
                                $this->errstr = '';\r
                        }\r
                        // G. Giunta 2005/10/24: close socket before parsing.\r
-                       // should yeld slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)\r
+                       // should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)\r
                        $ipd='';\r
                        do\r
                        {\r
                        // return the header too\r
                        curl_setopt($curl, CURLOPT_HEADER, 1);\r
 \r
-                       // will only work with PHP >= 5.0\r
                        // NB: if we set an empty string, CURL will add http header indicating\r
                        // ALL methods it is supporting. This is possibly a better option than\r
                        // letting the user tell what curl can / cannot do...\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
                * @param array $msgs an array of xmlrpcmsg objects\r
                * @param integer $timeout connection timeout (in seconds)\r
                * @param string $method the http protocol variant to be used\r
-               * @param boolean fallback When true, upon receiveing an error during multicall, multiple single calls will be attempted\r
+               * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted\r
                * @return array\r
                * @access public\r
                */\r
                                                case 1:\r
                                                        if(!isset($val[0]))\r
                                                        {\r
-\r
                                                                return false;           // Bad value\r
                                                        }\r
                                                        // Normal return value\r
                * with attributes being e.g. 'expires', 'path', domain'.\r
                * NB: cookies sent as 'expired' by the server (i.e. with an expiry date in the past)\r
                * are still present in the array. It is up to the user-defined code to decide\r
-               * how to use the received cookies, and wheter they have to be sent back with the next\r
+               * how to use the received cookies, and whether they have to be sent back with the next\r
                * request to the server (using xmlrpc_client::setCookie) or not\r
                * @return array array of cookies received from the server\r
                * @access public\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
@@ -2114,7 +2114,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 \r
                /**\r
                * @param string $meth the name of the method to invoke\r
-               * @param array $pars array of parameters to be paased to the method (xmlrpcval objects)\r
+               * @param array $pars array of parameters to be passed to the method (xmlrpcval objects)\r
                */\r
                function xmlrpcmsg($meth, $pars=0)\r
                {\r
@@ -2198,6 +2198,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 \r
                /**\r
                * Returns xml representation of the message. XML prologue included\r
+               * @param string $charset_encoding\r
                * @return string the xml representation of the message, xml prologue included\r
                * @access public\r
                */\r
@@ -2251,6 +2252,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                *      infinite loop in that case, because we cannot trust the caller\r
                *      to give us a valid pointer to an open file...\r
                * @access public\r
+               * @param resource $fp stream pointer\r
                * @return xmlrpcresp\r
                * @todo add 2nd & 3rd param to be passed to ParseResponse() ???\r
                */\r
@@ -3080,7 +3082,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                }\r
 \r
                /**\r
-               * Checks wheter a struct member with a given name is present.\r
+               * Checks whether a struct member with a given name is present.\r
                * Works only on xmlrpcvals of type struct.\r
                * @param string $m the name of the struct member to be looked up\r
                * @return boolean\r
@@ -3524,7 +3526,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
@@ -3680,9 +3681,10 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
        * we SHOULD assume it is strictly US-ASCII. But we try to be more tolerant of unconforming (legacy?) clients/servers,\r
        * which will be most probably using UTF-8 anyway...\r
        *\r
-       * @param string $httpheaders the http Content-type header\r
+       * @param string $httpheader the http Content-type header\r
        * @param string $xmlchunk xml content buffer\r
        * @param string $encoding_prefs comma separated list of character encodings to be used as default (when mb extension is enabled)\r
+       * @return string\r
        *\r
        * @todo explore usage of mb_http_input(): does it detect http headers + post data? if so, use it instead of hand-detection!!!\r
        */\r
@@ -3726,7 +3728,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
@@ -3776,6 +3777,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
        * if it is a valid subset of any encoding in the list\r
        * @param string $encoding charset to be tested\r
        * @param mixed $validlist comma separated list of valid charsets (or array of charsets)\r
+       * @return bool\r
        */\r
        function is_valid_charset($encoding, $validlist)\r
        {\r
@@ -3796,7 +3798,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                foreach ($validlist as $allowed)\r
                                        if (in_array($allowed, $charset_supersets[$encoding]))\r
                                                return true;\r
-                               return false;\r
+                       return false;\r
                }\r
        }\r
 \r