Prepare docs for release of version 4.0
[plcapi.git] / src / Client.php
index c0d86c3..8fce704 100644 (file)
@@ -137,6 +137,16 @@ class Client
         // by default the xml parser can support these 3 charset encodings
         $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
 
+        // Add all charsets which mbstring can handle, but remove junk not found in IANA registry at
+        // in http://www.iana.org/assignments/character-sets/character-sets.xhtml
+        // NB: this is disabled to avoid making all the requests sent huge... mbstring supports more than 80 charsets!
+        /*if (function_exists('mb_list_encodings')) {
+
+            $encodings = array_diff(mb_list_encodings(), array('pass', 'auto', 'wchar', 'BASE64', 'UUENCODE', 'ASCII',
+                'HTML-ENTITIES', 'Quoted-Printable', '7bit','8bit', 'byte2be', 'byte2le', 'byte4be', 'byte4le'));
+            $this->accepted_charset_encodings = array_unique(array_merge($this->accepted_charset_encodings, $encodings));
+        }*/
+
         // initialize user_agent string
         $this->user_agent = PhpXmlRpc::$xmlrpcName . ' ' . PhpXmlRpc::$xmlrpcVersion;
     }
@@ -422,7 +432,8 @@ class Client
                 $this->proxyport,
                 $this->proxy_user,
                 $this->proxy_pass,
-                $this->proxy_authtype
+                $this->proxy_authtype,
+                $method
             );
         }
 
@@ -442,14 +453,16 @@ class Client
      * @param string $proxyUsername
      * @param string $proxyPassword
      * @param int $proxyAuthType
+     * @param string $method
      * @return Response
      */
     protected function sendPayloadHTTP10($req, $server, $port, $timeout = 0,
                                        $username = '', $password = '', $authType = 1, $proxyHost = '',
-                                       $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1)
+                                       $proxyPort = 0, $proxyUsername = '', $proxyPassword = '', $proxyAuthType = 1,
+                                       $method='http')
     {
         if ($port == 0) {
-            $port = 80;
+            $port = ( $method === "https" ) ? 443 : 80;
         }
 
         // Only create the payload if it was not created previously
@@ -498,6 +511,7 @@ class Client
             }
             $connectServer = $proxyHost;
             $connectPort = $proxyPort;
+            $transport = "tcp";
             $uri = 'http://' . $server . ':' . $port . $this->path;
             if ($proxyUsername != '') {
                 if ($proxyAuthType != 1) {
@@ -508,6 +522,8 @@ class Client
         } else {
             $connectServer = $server;
             $connectPort = $port;
+            /// @todo if supporting https, we should support all its current options as well: peer name verification etc...
+            $transport = ( $method === "https" ) ? "tls" : "tcp";
             $uri = $this->path;
         }
 
@@ -557,12 +573,12 @@ class Client
         }
 
         if ($timeout > 0) {
-            $fp = @fsockopen($connectServer, $connectPort, $this->errno, $this->errstr, $timeout);
+            $fp = @stream_socket_client("$transport://$connectServer:$connectPort", $this->errno, $this->errstr, $timeout);
         } else {
-            $fp = @fsockopen($connectServer, $connectPort, $this->errno, $this->errstr);
+            $fp = @stream_socket_client("$transport://$connectServer:$connectPort", $this->errno, $this->errstr);
         }
         if ($fp) {
-            if ($timeout > 0 && function_exists('stream_set_timeout')) {
+            if ($timeout > 0) {
                 stream_set_timeout($fp, $timeout);
             }
         } else {
@@ -1037,32 +1053,31 @@ class Client
             if ($rets->kindOf() != 'array') {
                 return false;       // bad return type from system.multicall
             }
-            $numRets = $rets->arraysize();
+            $numRets = $rets->count();
             if ($numRets != count($reqs)) {
                 return false;       // wrong number of return values.
             }
 
             $response = array();
-            for ($i = 0; $i < $numRets; $i++) {
-                $val = $rets->arraymem($i);
+            foreach($rets as $val) {
                 switch ($val->kindOf()) {
                     case 'array':
-                        if ($val->arraysize() != 1) {
+                        if ($val->count() != 1) {
                             return false;       // Bad value
                         }
                         // Normal return value
-                        $response[$i] = new Response($val->arraymem(0));
+                        $response[] = new Response($val[0]);
                         break;
                     case 'struct':
-                        $code = $val->structmem('faultCode');
+                        $code = $val['faultCode'];
                         if ($code->kindOf() != 'scalar' || $code->scalartyp() != 'int') {
                             return false;
                         }
-                        $str = $val->structmem('faultString');
+                        $str = $val['faultString'];
                         if ($str->kindOf() != 'scalar' || $str->scalartyp() != 'string') {
                             return false;
                         }
-                        $response[$i] = new Response(0, $code->scalarval(), $str->scalarval());
+                        $response[] = new Response(0, $code->scalarval(), $str->scalarval());
                         break;
                     default:
                         return false;