more removing of each()
[plcapi.git] / lib / xmlrpc.inc
index 5afcc40..829a92d 100644 (file)
        $GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';\r
 \r
        $GLOBALS['xmlrpcName']='XML-RPC for PHP';\r
-       $GLOBALS['xmlrpcVersion']='3.0.1';\r
+       $GLOBALS['xmlrpcVersion']='3.1.1';\r
 \r
        // let user errors start at 800\r
        $GLOBALS['xmlrpcerruser']=800;\r
                var $keypass='';\r
                var $verifypeer=true;\r
                var $verifyhost=1;\r
+               var $sslversion=0; // corresponds to CURL_SSLVERSION_DEFAULT\r
                var $no_multicall=false;\r
                var $proxy='';\r
                var $proxyport=0;\r
                        $this->verifyhost = $i;\r
                }\r
 \r
+               /**\r
+               * Set attributes for SSL communication: SSL version to use. Best left at 0 (default value ): let cURL decide\r
+               *\r
+               * @param int $i\r
+               */\r
+               public function setSSLVersion($i)\r
+               {\r
+                       $this->sslversion = $i;\r
+               }\r
+\r
                /**\r
                * Set proxy info\r
                * @param string $proxyhost\r
                                        $this->proxy_authtype,\r
                                        $this->keepalive,\r
                                        $this->key,\r
-                                       $this->keypass\r
+                                       $this->keypass,\r
+                                       $this->sslversion\r
                                );\r
                        }\r
                        elseif($method == 'http11')\r
                function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',\r
                        $password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',\r
                        $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,\r
-                       $keepalive=false, $key='', $keypass='')\r
+                       $keepalive=false, $key='', $keypass='', $sslVersion = 0)\r
                {\r
                        $r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,\r
                                $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,\r
-                               $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);\r
+                               $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass, $sslVersion);\r
                        return $r;\r
                }\r
 \r
                function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',\r
                        $password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',\r
                        $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',\r
-                       $keepalive=false, $key='', $keypass='')\r
+                       $keepalive=false, $key='', $keypass='', $sslVersion = 0)\r
                {\r
                        if(!function_exists('curl_init'))\r
                        {\r
                                }\r
                                // whether to verify cert's common name (CN); 0 for no, 1 to verify that it exists, and 2 to verify that it matches the hostname used\r
                                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);\r
+                               // allow usage of different SSL versions\r
+                               curl_setopt($curl, CURLOPT_SSLVERSION, $sslVersion);\r
                        }\r
 \r
                        // proxy info\r
@@ -2388,7 +2402,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                }\r
                                // be tolerant to line endings, and extra empty lines\r
                                $ar = preg_split("/\r?\n/", trim(substr($data, 0, $pos)));\r
-                               while(list(,$line) = @each($ar))\r
+               foreach($ar as $line)\r
                                {\r
                                        // take care of multi-line headers and cookies\r
                                        $arr = explode(':',$line,2);\r
@@ -2670,7 +2684,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        xml_set_default_handler($parser, 'xmlrpc_dh');\r
 \r
                        // first error check: xml not well formed\r
-                       if(!xml_parse($parser, $data, count($data)))\r
+                       if(!xml_parse($parser, $data, 1))\r
                        {\r
                                // thanks to Peter Kocks <peter.kocks@baygate.com>\r
                                if((xml_get_current_line_number($parser)) == 1)\r
@@ -2962,7 +2976,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                echo "$key => $val<br />";\r
                                if($key == 'array')\r
                                {\r
-                                       while(list($key2, $val2) = each($val))\r
+                    foreach($val as $key2 => $val2)\r
                                        {\r
                                                echo "-- $key2 => $val2<br />";\r
                                        }\r
@@ -3108,8 +3122,8 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...\r
                        //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))\r
                        //{\r
-                               reset($this->me);\r
-                               list($typ, $val) = each($this->me);\r
+                               $val = reset($this->me);\r
+                               $typ = key($this->me);\r
                                return '<value>' . $this->serializedata($typ, $val, $charset_encoding) . "</value>\n";\r
                        //}\r
                }\r
@@ -3120,9 +3134,8 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        // add check? slower, but helps to avoid recursion in serializing broken xmlrpcvals...\r
                        //if (is_object($o) && (get_class($o) == 'xmlrpcval' || is_subclass_of($o, 'xmlrpcval')))\r
                        //{\r
-                               $ar=$o->me;\r
-                               reset($ar);\r
-                               list($typ, $val) = each($ar);\r
+                               $val = reset($o->me);\r
+                               $typ = key($o->me);\r
                                return '<value>' . $this->serializedata($typ, $val) . "</value>\n";\r
                        //}\r
                }\r
@@ -3175,8 +3188,8 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                function getval()\r
                {\r
                        // UNSTABLE\r
-                       reset($this->me);\r
-                       list($a,$b)=each($this->me);\r
+                       $b = reset($this->me);\r
+                       $a = key($this->me);\r
                        // contributed by I Sofer, 2001-03-24\r
                        // add support for nested arrays to scalarval\r
                        // i've created a new method here, so as to\r
@@ -3184,8 +3197,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
 \r
                        if(is_array($b))\r
                        {\r
-                               @reset($b);\r
-                               while(list($id,$cont) = @each($b))\r
+                               foreach($b as $id => $cont)\r
                                {\r
                                        $b[$id] = $cont->scalarval();\r
                                }\r
@@ -3195,13 +3207,11 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        if(is_object($b))\r
                        {\r
                                $t = get_object_vars($b);\r
-                               @reset($t);\r
-                               while(list($id,$cont) = @each($t))\r
+                               foreach($t as $id => $cont)\r
                                {\r
                                        $t[$id] = $cont->scalarval();\r
                                }\r
-                               @reset($t);\r
-                               while(list($id,$cont) = @each($t))\r
+                foreach($t as $id => $cont)\r
                                {\r
                                        @$b->$id = $cont;\r
                                }\r
@@ -3217,8 +3227,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                */\r
                function scalarval()\r
                {\r
-                       reset($this->me);\r
-                       list(,$b)=each($this->me);\r
+                       $b = reset($this->me);\r
                        return $b;\r
                }\r
 \r
@@ -3231,7 +3240,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                function scalartyp()\r
                {\r
                        reset($this->me);\r
-                       list($a,)=each($this->me);\r
+            $a = key($this->me);\r
                        if($a==$GLOBALS['xmlrpcI4'])\r
                        {\r
                                $a=$GLOBALS['xmlrpcInt'];\r
@@ -3364,8 +3373,8 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                        case 'scalar':\r
                                if (in_array('extension_api', $options))\r
                                {\r
-                                       reset($xmlrpc_val->me);\r
-                                       list($typ,$val) = each($xmlrpc_val->me);\r
+                    $val = reset($xmlrpc_val->me);\r
+                    $typ = key($xmlrpc_val->me);\r
                                        switch ($typ)\r
                                        {\r
                                                case 'dateTime.iso8601':\r
@@ -3538,8 +3547,7 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                                else\r
                                {\r
                                        $arr = array();\r
-                                       reset($php_val);\r
-                                       while(list($k,$v) = each($php_val))\r
+                    foreach($php_val as $k => $v)\r
                                        {\r
                                                $arr[$k] = php_xmlrpc_encode($v, $options);\r
                                        }\r
@@ -3905,4 +3913,4 @@ xmlrpc_encode_entitites($this->errstr, $GLOBALS['xmlrpc_internalencoding'], $cha
                }\r
        }\r
 \r
-?>
\ No newline at end of file
+?>\r