5 /// @todo: do these need to be public?
22 public $verifypeer=true;
24 public $no_multicall=false;
27 public $proxy_user='';
28 public $proxy_pass='';
29 public $proxy_authtype=1;
30 public $cookies=array();
31 public $extracurlopts=array();
34 * List of http compression methods accepted by the client for responses.
35 * NB: PHP supports deflate, gzip compressions out of the box if compiled w. zlib
37 * NNB: you can set it to any non-empty array for HTTP11 and HTTPS, since
38 * in those cases it will be up to CURL to decide the compression methods
39 * it supports. You might check for the presence of 'zlib' in the output of
40 * curl_version() to determine wheter compression is supported or not
42 public $accepted_compression = array();
44 * Name of compression scheme to be used for sending requests.
45 * Either null, gzip or deflate
47 public $request_compression = '';
49 * CURL handle: used for keep-alive connections (PHP 4.3.8 up, see:
50 * http://curl.haxx.se/docs/faq.html#7.3)
52 public $xmlrpc_curl_handle = null;
53 /// Whether to use persistent connections for http 1.1 and https
54 public $keepalive = false;
55 /// Charset encodings that can be decoded without problems by the client
56 public $accepted_charset_encodings = array();
57 /// Charset encoding to be used in serializing request. NULL = use ASCII
58 public $request_charset_encoding = '';
60 * Decides the content of xmlrpcresp objects returned by calls to send()
61 * valid strings are 'xmlrpcvals', 'phpvals' or 'xml'
63 public $return_type = 'xmlrpcvals';
65 * Sent to servers in http headers
70 * @param string $path either the complete server URL or the PATH part of the xmlrc server URL, e.g. /xmlrpc/server.php
71 * @param string $server the server name / ip address
72 * @param integer $port the port the server is listening on, defaults to 80 or 443 depending on protocol used
73 * @param string $method the http protocol variant: defaults to 'http', 'https' and 'http11' can be used if CURL is installed
75 function __construct($path, $server='', $port='', $method='')
77 $xmlrpc = Phpxmlrpc::instance();
79 // allow user to specify all params in $path
80 if($server == '' and $port == '' and $method == '')
82 $parts = parse_url($path);
83 $server = $parts['host'];
84 $path = isset($parts['path']) ? $parts['path'] : '';
85 if(isset($parts['query']))
87 $path .= '?'.$parts['query'];
89 if(isset($parts['fragment']))
91 $path .= '#'.$parts['fragment'];
93 if(isset($parts['port']))
95 $port = $parts['port'];
97 if(isset($parts['scheme']))
99 $method = $parts['scheme'];
101 if(isset($parts['user']))
103 $this->username = $parts['user'];
105 if(isset($parts['pass']))
107 $this->password = $parts['pass'];
110 if($path == '' || $path[0] != '/')
112 $this->path='/'.$path;
118 $this->server=$server;
125 $this->method=$method;
128 // if ZLIB is enabled, let the client by default accept compressed responses
129 if(function_exists('gzinflate') || (
130 function_exists('curl_init') && (($info = curl_version()) &&
131 ((is_string($info) && strpos($info, 'zlib') !== null) || isset($info['libz_version'])))
134 $this->accepted_compression = array('gzip', 'deflate');
137 // keepalives: enabled by default
138 $this->keepalive = true;
140 // by default the xml parser can support these 3 charset encodings
141 $this->accepted_charset_encodings = array('UTF-8', 'ISO-8859-1', 'US-ASCII');
143 // initialize user_agent string
144 $this->user_agent = $xmlrpc->xmlrpcName . ' ' . $xmlrpc->xmlrpcVersion;
148 * Enables/disables the echoing to screen of the xmlrpc responses received
149 * @param integer $in values 0, 1 and 2 are supported (2 = echo sent msg too, before received response)
151 public function setDebug($in)
157 * Add some http BASIC AUTH credentials, used by the client to authenticate
158 * @param string $u username
159 * @param string $p password
160 * @param integer $t auth type. See curl_setopt man page for supported auth types. Defaults to CURLAUTH_BASIC (basic auth)
162 public function setCredentials($u, $p, $t=1)
170 * Add a client-side https certificate
171 * @param string $cert
172 * @param string $certpass
174 public function setCertificate($cert, $certpass)
177 $this->certpass = $certpass;
181 * Add a CA certificate to verify server with (see man page about
182 * CURLOPT_CAINFO for more details)
183 * @param string $cacert certificate file name (or dir holding certificates)
184 * @param bool $is_dir set to true to indicate cacert is a dir. defaults to false
186 public function setCaCertificate($cacert, $is_dir=false)
190 $this->cacertdir = $cacert;
194 $this->cacert = $cacert;
199 * Set attributes for SSL communication: private SSL key
200 * NB: does not work in older php/curl installs
201 * Thanks to Daniel Convissor
202 * @param string $key The name of a file containing a private SSL key
203 * @param string $keypass The secret password needed to use the private SSL key
205 public function setKey($key, $keypass)
208 $this->keypass = $keypass;
212 * Set attributes for SSL communication: verify server certificate
213 * @param bool $i enable/disable verification of peer certificate
215 public function setSSLVerifyPeer($i)
217 $this->verifypeer = $i;
221 * Set attributes for SSL communication: verify match of server cert w. hostname
224 public function setSSLVerifyHost($i)
226 $this->verifyhost = $i;
231 * @param string $proxyhost
232 * @param string $proxyport Defaults to 8080 for HTTP and 443 for HTTPS
233 * @param string $proxyusername Leave blank if proxy has public access
234 * @param string $proxypassword Leave blank if proxy has public access
235 * @param int $proxyauthtype set to constant CURLAUTH_NTLM to use NTLM auth with proxy
237 public function setProxy($proxyhost, $proxyport, $proxyusername = '', $proxypassword = '', $proxyauthtype = 1)
239 $this->proxy = $proxyhost;
240 $this->proxyport = $proxyport;
241 $this->proxy_user = $proxyusername;
242 $this->proxy_pass = $proxypassword;
243 $this->proxy_authtype = $proxyauthtype;
247 * Enables/disables reception of compressed xmlrpc responses.
248 * Note that enabling reception of compressed responses merely adds some standard
249 * http headers to xmlrpc requests. It is up to the xmlrpc server to return
250 * compressed responses when receiving such requests.
251 * @param string $compmethod either 'gzip', 'deflate', 'any' or ''
253 public function setAcceptedCompression($compmethod)
255 if ($compmethod == 'any')
256 $this->accepted_compression = array('gzip', 'deflate');
258 if ($compmethod == false )
259 $this->accepted_compression = array();
261 $this->accepted_compression = array($compmethod);
265 * Enables/disables http compression of xmlrpc request.
266 * Take care when sending compressed requests: servers might not support them
267 * (and automatic fallback to uncompressed requests is not yet implemented)
268 * @param string $compmethod either 'gzip', 'deflate' or ''
270 public function setRequestCompression($compmethod)
272 $this->request_compression = $compmethod;
276 * Adds a cookie to list of cookies that will be sent to server.
277 * NB: setting any param but name and value will turn the cookie into a 'version 1' cookie:
278 * do not do it unless you know what you are doing
279 * @param string $name
280 * @param string $value
281 * @param string $path
282 * @param string $domain
285 * @todo check correctness of urlencoding cookie value (copied from php way of doing it...)
287 public function setCookie($name, $value='', $path='', $domain='', $port=null)
289 $this->cookies[$name]['value'] = urlencode($value);
290 if ($path || $domain || $port)
292 $this->cookies[$name]['path'] = $path;
293 $this->cookies[$name]['domain'] = $domain;
294 $this->cookies[$name]['port'] = $port;
295 $this->cookies[$name]['version'] = 1;
299 $this->cookies[$name]['version'] = 0;
304 * Directly set cURL options, for extra flexibility
305 * It allows eg. to bind client to a specific IP interface / address
306 * @param array $options
308 function SetCurlOptions( $options )
310 $this->extracurlopts = $options;
314 * Set user-agent string that will be used by this client instance
315 * in http headers sent to the server
317 function SetUserAgent( $agentstring )
319 $this->user_agent = $agentstring;
323 * Send an xmlrpc request
324 * @param mixed $msg The message object, or an array of messages for using multicall, or the complete xml representation of a request
325 * @param integer $timeout Connection timeout, in seconds, If unspecified, a platform specific timeout will apply
326 * @param string $method if left unspecified, the http protocol chosen during creation of the object will be used
329 public function& send($msg, $timeout=0, $method='')
331 // if user deos not specify http protocol, use native method of this client
332 // (i.e. method set during call to constructor)
335 $method = $this->method;
340 // $msg is an array of xmlrpcmsg's
341 $r = $this->multicall($msg, $timeout, $method);
344 elseif(is_string($msg))
346 $n = new xmlrpcmsg('');
351 // where msg is an xmlrpcmsg
352 $msg->debug=$this->debug;
354 if($method == 'https')
356 $r =& $this->sendPayloadHTTPS(
372 $this->proxy_authtype,
378 elseif($method == 'http11')
380 $r =& $this->sendPayloadCURL(
396 $this->proxy_authtype,
403 $r =& $this->sendPayloadHTTP10(
415 $this->proxy_authtype
422 private function &sendPayloadHTTP10($msg, $server, $port, $timeout=0,
423 $username='', $password='', $authtype=1, $proxyhost='',
424 $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1)
426 $xmlrpc = Phpxmlrpc::instance();
433 // Only create the payload if it was not created previously
434 if(empty($msg->payload))
436 $msg->createPayload($this->request_charset_encoding);
439 $payload = $msg->payload;
440 // Deflate request body and set appropriate request headers
441 if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
443 if($this->request_compression == 'gzip')
445 $a = @gzencode($payload);
449 $encoding_hdr = "Content-Encoding: gzip\r\n";
454 $a = @gzcompress($payload);
458 $encoding_hdr = "Content-Encoding: deflate\r\n";
467 // thanks to Grant Rauscher <grant7@firstworld.net> for this
471 $credentials='Authorization: Basic ' . base64_encode($username . ':' . $password) . "\r\n";
474 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported with HTTP 1.0');
478 $accepted_encoding = '';
479 if(is_array($this->accepted_compression) && count($this->accepted_compression))
481 $accepted_encoding = 'Accept-Encoding: ' . implode(', ', $this->accepted_compression) . "\r\n";
484 $proxy_credentials = '';
491 $connectserver = $proxyhost;
492 $connectport = $proxyport;
493 $uri = 'http://'.$server.':'.$port.$this->path;
494 if($proxyusername != '')
496 if ($proxyauthtype != 1)
498 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported with HTTP 1.0');
500 $proxy_credentials = 'Proxy-Authorization: Basic ' . base64_encode($proxyusername.':'.$proxypassword) . "\r\n";
505 $connectserver = $server;
506 $connectport = $port;
510 // Cookie generation, as per rfc2965 (version 1 cookies) or
511 // netscape's rules (version 0 cookies)
513 if (count($this->cookies))
516 foreach ($this->cookies as $name => $cookie)
518 if ($cookie['version'])
520 $version = ' $Version="' . $cookie['version'] . '";';
521 $cookieheader .= ' ' . $name . '="' . $cookie['value'] . '";';
523 $cookieheader .= ' $Path="' . $cookie['path'] . '";';
524 if ($cookie['domain'])
525 $cookieheader .= ' $Domain="' . $cookie['domain'] . '";';
527 $cookieheader .= ' $Port="' . $cookie['port'] . '";';
531 $cookieheader .= ' ' . $name . '=' . $cookie['value'] . ";";
534 $cookieheader = 'Cookie:' . $version . substr($cookieheader, 0, -1) . "\r\n";
538 $port = ($port == 80) ? '' : (':' . $port);
540 $op= 'POST ' . $uri. " HTTP/1.0\r\n" .
541 'User-Agent: ' . $this->user_agent . "\r\n" .
542 'Host: '. $server . $port . "\r\n" .
547 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings) . "\r\n" .
549 'Content-Type: ' . $msg->content_type . "\r\nContent-Length: " .
550 strlen($payload) . "\r\n\r\n" .
555 print "<PRE>\n---SENDING---\n" . htmlentities($op) . "\n---END---\n</PRE>";
556 // let the client see this now in case http times out...
562 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
566 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
570 if($timeout>0 && function_exists('stream_set_timeout'))
572 stream_set_timeout($fp, $timeout);
577 $this->errstr='Connect error: '.$this->errstr;
578 $r=new xmlrpcresp(0, $xmlrpc->xmlrpcerr['http_error'], $this->errstr . ' (' . $this->errno . ')');
582 if(!fputs($fp, $op, strlen($op)))
585 $this->errstr='Write error';
586 $r=new xmlrpcresp(0, $xmlrpc->xmlrpcerr['http_error'], $this->errstr);
591 // reset errno and errstr on successful socket connection
594 // G. Giunta 2005/10/24: close socket before parsing.
595 // should yield slightly better execution times, and make easier recursive calls (e.g. to follow http redirects)
599 // shall we check for $data === FALSE?
600 // as per the manual, it signals an error
601 $ipd.=fread($fp, 32768);
604 $r =& $msg->parseResponse($ipd, false, $this->return_type);
609 private function &sendPayloadHTTPS($msg, $server, $port, $timeout=0, $username='',
610 $password='', $authtype=1, $cert='',$certpass='', $cacert='', $cacertdir='',
611 $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1,
612 $keepalive=false, $key='', $keypass='')
614 $r =& $this->sendPayloadCURL($msg, $server, $port, $timeout, $username,
615 $password, $authtype, $cert, $certpass, $cacert, $cacertdir, $proxyhost, $proxyport,
616 $proxyusername, $proxypassword, $proxyauthtype, 'https', $keepalive, $key, $keypass);
621 * Contributed by Justin Miller <justin@voxel.net>
622 * Requires curl to be built into PHP
623 * NB: CURL versions before 7.11.10 cannot use proxy to talk to https servers!
625 private function &sendPayloadCURL($msg, $server, $port, $timeout=0, $username='',
626 $password='', $authtype=1, $cert='', $certpass='', $cacert='', $cacertdir='',
627 $proxyhost='', $proxyport=0, $proxyusername='', $proxypassword='', $proxyauthtype=1, $method='https',
628 $keepalive=false, $key='', $keypass='')
630 $xmlrpc = Phpxmlrpc::instance();
632 if(!function_exists('curl_init'))
634 $this->errstr='CURL unavailable on this install';
635 $r=new xmlrpcresp(0, $xmlrpc->xmlrpcerr['no_curl'], $xmlrpc->xmlrpcstr['no_curl']);
638 if($method == 'https')
640 if(($info = curl_version()) &&
641 ((is_string($info) && strpos($info, 'OpenSSL') === null) || (is_array($info) && !isset($info['ssl_version']))))
643 $this->errstr='SSL unavailable on this install';
644 $r=new xmlrpcresp(0, $xmlrpc->xmlrpcerr['no_ssl'], $xmlrpc->xmlrpcstr['no_ssl']);
651 if($method == 'http')
661 // Only create the payload if it was not created previously
662 if(empty($msg->payload))
664 $msg->createPayload($this->request_charset_encoding);
667 // Deflate request body and set appropriate request headers
668 $payload = $msg->payload;
669 if(function_exists('gzdeflate') && ($this->request_compression == 'gzip' || $this->request_compression == 'deflate'))
671 if($this->request_compression == 'gzip')
673 $a = @gzencode($payload);
677 $encoding_hdr = 'Content-Encoding: gzip';
682 $a = @gzcompress($payload);
686 $encoding_hdr = 'Content-Encoding: deflate';
697 print "<PRE>\n---SENDING---\n" . htmlentities($payload) . "\n---END---\n</PRE>";
698 // let the client see this now in case http times out...
702 if(!$keepalive || !$this->xmlrpc_curl_handle)
704 $curl = curl_init($method . '://' . $server . ':' . $port . $this->path);
707 $this->xmlrpc_curl_handle = $curl;
712 $curl = $this->xmlrpc_curl_handle;
715 // results into variable
716 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
720 curl_setopt($curl, CURLOPT_VERBOSE, 1);
722 curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent);
723 // required for XMLRPC: post the data
724 curl_setopt($curl, CURLOPT_POST, 1);
726 curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
728 // return the header too
729 curl_setopt($curl, CURLOPT_HEADER, 1);
731 // NB: if we set an empty string, CURL will add http header indicating
732 // ALL methods it is supporting. This is possibly a better option than
733 // letting the user tell what curl can / cannot do...
734 if(is_array($this->accepted_compression) && count($this->accepted_compression))
736 //curl_setopt($curl, CURLOPT_ENCODING, implode(',', $this->accepted_compression));
737 // empty string means 'any supported by CURL' (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
738 if (count($this->accepted_compression) == 1)
740 curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
743 curl_setopt($curl, CURLOPT_ENCODING, '');
746 $headers = array('Content-Type: ' . $msg->content_type , 'Accept-Charset: ' . implode(',', $this->accepted_charset_encodings));
747 // if no keepalive is wanted, let the server know it in advance
750 $headers[] = 'Connection: close';
752 // request compression header
755 $headers[] = $encoding_hdr;
758 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
762 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
765 if($username && $password)
767 curl_setopt($curl, CURLOPT_USERPWD, $username.':'.$password);
768 if (defined('CURLOPT_HTTPAUTH'))
770 curl_setopt($curl, CURLOPT_HTTPAUTH, $authtype);
772 else if ($authtype != 1)
774 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth is supported by the current PHP/curl install');
778 if($method == 'https')
783 curl_setopt($curl, CURLOPT_SSLCERT, $cert);
788 curl_setopt($curl, CURLOPT_SSLCERTPASSWD, $certpass);
790 // whether to verify remote host's cert
791 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
792 // set ca certificates file/dir
795 curl_setopt($curl, CURLOPT_CAINFO, $cacert);
799 curl_setopt($curl, CURLOPT_CAPATH, $cacertdir);
801 // set key file (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
804 curl_setopt($curl, CURLOPT_SSLKEY, $key);
806 // set key password (shall we catch errors in case CURLOPT_SSLKEY undefined ?)
809 curl_setopt($curl, CURLOPT_SSLKEYPASSWD, $keypass);
811 // 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
812 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
820 $proxyport = 8080; // NB: even for HTTPS, local connection is on port 8080
822 curl_setopt($curl, CURLOPT_PROXY, $proxyhost.':'.$proxyport);
823 //curl_setopt($curl, CURLOPT_PROXYPORT,$proxyport);
826 curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.':'.$proxypassword);
827 if (defined('CURLOPT_PROXYAUTH'))
829 curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
831 else if ($proxyauthtype != 1)
833 error_log('XML-RPC: '.__METHOD__.': warning. Only Basic auth to proxy is supported by the current PHP/curl install');
838 // NB: should we build cookie http headers by hand rather than let CURL do it?
839 // the following code does not honour 'expires', 'path' and 'domain' cookie attributes
840 // set to client obj the the user...
841 if (count($this->cookies))
844 foreach ($this->cookies as $name => $cookie)
846 $cookieheader .= $name . '=' . $cookie['value'] . '; ';
848 curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
851 foreach ($this->extracurlopts as $opt => $val)
853 curl_setopt($curl, $opt, $val);
856 $result = curl_exec($curl);
858 if ($this->debug > 1)
860 print "<PRE>\n---CURL INFO---\n";
861 foreach(curl_getinfo($curl) as $name => $val)
865 $val = implode("\n", $val);
867 print $name . ': ' . htmlentities($val) . "\n";
870 print "---END---\n</PRE>";
873 if(!$result) /// @todo we should use a better check here - what if we get back '' or '0'?
875 $this->errstr='no response';
876 $resp=new xmlrpcresp(0, $xmlrpc->xmlrpcerr['curl_fail'], $xmlrpc->xmlrpcstr['curl_fail']. ': '. curl_error($curl));
880 $this->xmlrpc_curl_handle = null;
889 $resp =& $msg->parseResponse($result, true, $this->return_type);
890 // if we got back a 302, we can not reuse the curl handle for later calls
891 if($resp->faultCode() == $xmlrpc->xmlrpcerr['http_error'] && $keepalive)
894 $this->xmlrpc_curl_handle = null;
901 * Send an array of request messages and return an array of responses.
902 * Unless $this->no_multicall has been set to true, it will try first
903 * to use one single xmlrpc call to server method system.multicall, and
904 * revert to sending many successive calls in case of failure.
905 * This failure is also stored in $this->no_multicall for subsequent calls.
906 * Unfortunately, there is no server error code universally used to denote
907 * the fact that multicall is unsupported, so there is no way to reliably
908 * distinguish between that and a temporary failure.
909 * If you are sure that server supports multicall and do not want to
910 * fallback to using many single calls, set the fourth parameter to FALSE.
912 * NB: trying to shoehorn extra functionality into existing syntax has resulted
913 * in pretty much convoluted code...
915 * @param array $msgs an array of xmlrpcmsg objects
916 * @param integer $timeout connection timeout (in seconds)
917 * @param string $method the http protocol variant to be used
918 * @param boolean fallback When true, upon receiving an error during multicall, multiple single calls will be attempted
921 public function multicall($msgs, $timeout=0, $method='', $fallback=true)
923 $xmlrpc = Phpxmlrpc::instance();
927 $method = $this->method;
929 if(!$this->no_multicall)
931 $results = $this->_try_multicall($msgs, $timeout, $method);
932 if(is_array($results))
934 // System.multicall succeeded
939 // either system.multicall is unsupported by server,
940 // or call failed for some other reason.
943 // Don't try it next time...
944 $this->no_multicall = true;
948 if (is_a($results, 'xmlrpcresp'))
954 $result = new xmlrpcresp(0, $xmlrpc->xmlrpcerr['multicall_error'], $xmlrpc->xmlrpcstr['multicall_error']);
961 // override fallback, in case careless user tries to do two
962 // opposite things at the same time
969 // system.multicall is (probably) unsupported by server:
970 // emulate multicall via multiple requests
971 foreach($msgs as $msg)
973 $results[] =& $this->send($msg, $timeout, $method);
978 // user does NOT want to fallback on many single calls:
979 // since we should always return an array of responses,
980 // return an array with the same error repeated n times
981 foreach($msgs as $msg)
983 $results[] = $result;
990 * Attempt to boxcar $msgs via system.multicall.
991 * Returns either an array of xmlrpcreponses, an xmlrpc error response
992 * or false (when received response does not respect valid multicall syntax)
994 private function _try_multicall($msgs, $timeout, $method)
996 // Construct multicall message
998 foreach($msgs as $msg)
1000 $call['methodName'] = new xmlrpcval($msg->method(),'string');
1001 $numParams = $msg->getNumParams();
1003 for($i = 0; $i < $numParams; $i++)
1005 $params[$i] = $msg->getParam($i);
1007 $call['params'] = new xmlrpcval($params, 'array');
1008 $calls[] = new xmlrpcval($call, 'struct');
1010 $multicall = new xmlrpcmsg('system.multicall');
1011 $multicall->addParam(new xmlrpcval($calls, 'array'));
1014 $result =& $this->send($multicall, $timeout, $method);
1016 if($result->faultCode() != 0)
1018 // call to system.multicall failed
1022 // Unpack responses.
1023 $rets = $result->value();
1025 if ($this->return_type == 'xml')
1029 else if ($this->return_type == 'phpvals')
1031 ///@todo test this code branch...
1032 $rets = $result->value();
1033 if(!is_array($rets))
1035 return false; // bad return type from system.multicall
1037 $numRets = count($rets);
1038 if($numRets != count($msgs))
1040 return false; // wrong number of return values.
1043 $response = array();
1044 for($i = 0; $i < $numRets; $i++)
1047 if (!is_array($val)) {
1055 return false; // Bad value
1057 // Normal return value
1058 $response[$i] = new xmlrpcresp($val[0], 0, '', 'phpvals');
1061 /// @todo remove usage of @: it is apparently quite slow
1062 $code = @$val['faultCode'];
1067 $str = @$val['faultString'];
1068 if(!is_string($str))
1072 $response[$i] = new xmlrpcresp(0, $code, $str);
1080 else // return type == 'xmlrpcvals'
1082 $rets = $result->value();
1083 if($rets->kindOf() != 'array')
1085 return false; // bad return type from system.multicall
1087 $numRets = $rets->arraysize();
1088 if($numRets != count($msgs))
1090 return false; // wrong number of return values.
1093 $response = array();
1094 for($i = 0; $i < $numRets; $i++)
1096 $val = $rets->arraymem($i);
1097 switch($val->kindOf())
1100 if($val->arraysize() != 1)
1102 return false; // Bad value
1104 // Normal return value
1105 $response[$i] = new xmlrpcresp($val->arraymem(0));
1108 $code = $val->structmem('faultCode');
1109 if($code->kindOf() != 'scalar' || $code->scalartyp() != 'int')
1113 $str = $val->structmem('faultString');
1114 if($str->kindOf() != 'scalar' || $str->scalartyp() != 'string')
1118 $response[$i] = new xmlrpcresp(0, $code->scalarval(), $str->scalarval());