38 if(!function_exists(
'xml_parser_create'))
42 if(strtoupper(substr(PHP_OS, 0, 3) !=
'WIN'))
53 if(!defined(
'PHP_XMLRPC_COMPAT_DIR'))
55 define(
'PHP_XMLRPC_COMPAT_DIR',dirname(__FILE__).
'/compat/');
61 include(PHP_XMLRPC_COMPAT_DIR.
'is_callable.php');
63 include(PHP_XMLRPC_COMPAT_DIR.
'is_scalar.php');
64 include(PHP_XMLRPC_COMPAT_DIR.
'array_key_exists.php');
65 include(PHP_XMLRPC_COMPAT_DIR.
'version_compare.php');
67 include(PHP_XMLRPC_COMPAT_DIR.
'var_export.php');
68 include(PHP_XMLRPC_COMPAT_DIR.
'is_a.php');
98 'VALUE' => array(
'MEMBER',
'DATA',
'PARAM',
'FAULT'),
99 'BOOLEAN' => array(
'VALUE'),
100 'I4' => array(
'VALUE'),
101 'INT' => array(
'VALUE'),
102 'STRING' => array(
'VALUE'),
103 'DOUBLE' => array(
'VALUE'),
104 'DATETIME.ISO8601' => array(
'VALUE'),
105 'BASE64' => array(
'VALUE'),
106 'MEMBER' => array(
'STRUCT'),
107 'NAME' => array(
'MEMBER'),
108 'DATA' => array(
'ARRAY'),
109 'ARRAY' => array(
'VALUE'),
110 'STRUCT' => array(
'VALUE'),
111 'PARAM' => array(
'PARAMS'),
112 'METHODNAME' => array(
'METHODCALL'),
113 'PARAMS' => array(
'METHODCALL',
'METHODRESPONSE'),
114 'FAULT' => array(
'METHODRESPONSE'),
115 'NIL' => array(
'VALUE')
136 $GLOBALS[
'xml_iso88591_Entities'][
'out'] = array();
137 for ($i = 0; $i < 32; $i++)
139 $GLOBALS[
'xml_iso88591_Entities'][
'in'][] = chr($i);
140 $GLOBALS[
'xml_iso88591_Entities'][
'out'][] =
'&#'.$i.
';';
142 for ($i = 160; $i < 256; $i++)
144 $GLOBALS[
'xml_iso88591_Entities'][
'in'][] = chr($i);
145 $GLOBALS[
'xml_iso88591_Entities'][
'out'][] =
'&#'.$i.
';';
172 'incorrect_params'=>3,
173 'introspect_unknown'=>4,
178 'invalid_request'=>15,
181 'multicall_error'=>18,
182 'multicall_notstruct'=>9,
183 'multicall_nomethod'=>10,
184 'multicall_notstring'=>11,
185 'multicall_recursion'=>12,
186 'multicall_noparams'=>13,
187 'multicall_notarray'=>14,
189 'cannot_decompress'=>103,
190 'decompress_fail'=>104,
192 'server_cannot_decompress'=>106,
193 'server_decompress_fail'=>107
197 'unknown_method'=>
'Unknown method',
198 'invalid_return'=>
'Invalid return payload: enable debugging to examine incoming payload',
199 'incorrect_params'=>
'Incorrect parameters passed to method',
200 'introspect_unknown'=>
"Can't introspect: method unknown",
201 'http_error'=>
"Didn't receive 200 OK from remote server.",
202 'no_data'=>
'No data received from server.',
203 'no_ssl'=>
'No SSL support compiled in.',
204 'curl_fail'=>
'CURL error',
205 'invalid_request'=>
'Invalid request payload',
206 'no_curl'=>
'No CURL support compiled in.',
207 'server_error'=>
'Internal server error',
208 'multicall_error'=>
'Received from server invalid multicall response',
209 'multicall_notstruct'=>
'system.multicall expected struct',
210 'multicall_nomethod'=>
'missing methodName',
211 'multicall_notstring'=>
'methodName is not a string',
212 'multicall_recursion'=>
'recursive system.multicall forbidden',
213 'multicall_noparams'=>
'missing params',
214 'multicall_notarray'=>
'params is not an array',
216 'cannot_decompress'=>
'Received from server compressed HTTP and cannot decompress',
217 'decompress_fail'=>
'Received from server invalid compressed HTTP',
218 'dechunk_fail'=>
'Received from server invalid chunked HTTP',
219 'server_cannot_decompress'=>
'Received from client compressed HTTP request and cannot decompress',
220 'server_decompress_fail'=>
'Received from client invalid compressed HTTP request'
278 if ($src_encoding ==
'')
281 $src_encoding =
$GLOBALS[
'xmlrpc_internalencoding'];
284 switch(strtoupper($src_encoding.
'_'.$dest_encoding))
287 case 'ISO-8859-1_US-ASCII':
288 $escaped_data = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
289 $escaped_data = str_replace(
$GLOBALS[
'xml_iso88591_Entities'][
'in'],
$GLOBALS[
'xml_iso88591_Entities'][
'out'], $escaped_data);
291 case 'ISO-8859-1_UTF-8':
292 $escaped_data = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
293 $escaped_data = utf8_encode($escaped_data);
295 case 'ISO-8859-1_ISO-8859-1':
296 case 'US-ASCII_US-ASCII':
297 case 'US-ASCII_UTF-8':
299 case 'US-ASCII_ISO-8859-1':
302 $escaped_data = str_replace(array(
'&',
'"',
"'",
'<',
'>'), array(
'&',
'"',
''',
'<',
'>'), $data);
305 case 'UTF-8_US-ASCII':
306 case 'UTF-8_ISO-8859-1':
310 $data = (string) $data;
311 $ns = strlen ($data);
312 for ($nn = 0; $nn < $ns; $nn++)
322 $escaped_data .=
'"';
325 $escaped_data .=
'&';
328 $escaped_data .=
''';
331 $escaped_data .=
'<';
334 $escaped_data .=
'>';
337 $escaped_data .= $ch;
341 else if ($ii>>5 == 6)
344 $ii = ord($data[$nn+1]);
347 $ent = sprintf (
'&#%d;', $ii);
348 $escaped_data .= $ent;
352 else if ($ii>>4 == 14)
355 $ii = ord($data[$nn+1]);
357 $ii = ord($data[$nn+2]);
359 $ii = (((
$b1 * 64) +
$b2) * 64) + $b3;
360 $ent = sprintf (
'&#%d;', $ii);
361 $escaped_data .= $ent;
365 else if ($ii>>3 == 30)
368 $ii = ord($data[$nn+1]);
370 $ii = ord($data[$nn+2]);
372 $ii = ord($data[$nn+3]);
374 $ii = (((((
$b1 * 64) +
$b2) * 64) + $b3) * 64) + $b4;
375 $ent = sprintf (
'&#%d;', $ii);
376 $escaped_data .= $ent;
402 error_log(
"Converting from $src_encoding to $dest_encoding: not supported...");
404 return $escaped_data;
408 function xmlrpc_se($parser, $name, $attrs, $accept_single_vals=
false)
417 if (count(
$GLOBALS[
'_xh'][
'stack']) == 0)
419 if ($name !=
'METHODRESPONSE' && $name !=
'METHODCALL' && (
420 $name !=
'VALUE' && !$accept_single_vals))
423 $GLOBALS[
'_xh'][
'isf_reason'] =
'missing top level xmlrpc element';
428 $GLOBALS[
'_xh'][
'rt'] = strtolower($name);
434 $parent = end(
$GLOBALS[
'_xh'][
'stack']);
435 if (!array_key_exists($name,
$GLOBALS[
'xmlrpc_valid_parents']) || !in_array($parent,
$GLOBALS[
'xmlrpc_valid_parents'][$name]))
438 $GLOBALS[
'_xh'][
'isf_reason'] =
"xmlrpc element $name cannot be child of $parent";
458 case 'DATETIME.ISO8601':
464 $GLOBALS[
'_xh'][
'isf_reason'] =
"$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
475 $GLOBALS[
'_xh'][
'isf_reason'] =
"$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
480 $cur_val[
'values'] = array();
481 $cur_val[
'type'] = $name;
484 if (@isset($attrs[
'PHP_CLASS']))
486 $cur_val[
'php_class'] = $attrs[
'PHP_CLASS'];
488 $GLOBALS[
'_xh'][
'valuestack'][] = $cur_val;
496 $GLOBALS[
'_xh'][
'isf_reason'] =
"found two data elements inside an array element";
500 case 'METHODRESPONSE':
513 $GLOBALS[
'_xh'][
'valuestack'][count(
$GLOBALS[
'_xh'][
'valuestack'])-1][
'name']=
'';
521 if (
$GLOBALS[
'xmlrpc_null_extension'])
527 $GLOBALS[
'_xh'][
'isf_reason'] =
"$name element following a {$GLOBALS['_xh']['vt']} element inside a single value";
538 $GLOBALS[
'_xh'][
'isf_reason'] =
"found not-xmlrpc xml element $name";
560 function xmlrpc_ee($parser, $name, $rebuild_xmlrpcvals =
true)
568 $curr_elem = array_pop(
$GLOBALS[
'_xh'][
'stack']);
580 if ($rebuild_xmlrpcvals)
586 if (isset(
$GLOBALS[
'_xh'][
'php_class']))
587 $temp->_php_class =
$GLOBALS[
'_xh'][
'php_class'];
590 $vscount = count(
$GLOBALS[
'_xh'][
'valuestack']);
591 if ($vscount &&
$GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'type']==
'ARRAY')
593 $GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'values'][] = $temp;
605 if (isset(
$GLOBALS[
'_xh'][
'php_class']))
611 $vscount = count(
$GLOBALS[
'_xh'][
'valuestack']);
612 if ($vscount &&
$GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'type']==
'ARRAY')
614 $GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'values'][] =
$GLOBALS[
'_xh'][
'value'];
623 case 'DATETIME.ISO8601':
625 $GLOBALS[
'_xh'][
'vt']=strtolower($name);
632 elseif ($name==
'DATETIME.ISO8601')
634 if (!preg_match(
'/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/',
$GLOBALS[
'_xh'][
'ac']))
636 error_log(
'XML-RPC: invalid value received in DATETIME: '.
$GLOBALS[
'_xh'][
'ac']);
641 elseif ($name==
'BASE64')
646 elseif ($name==
'BOOLEAN')
654 if (
$GLOBALS[
'_xh'][
'ac']==
'1' || strcasecmp(
$GLOBALS[
'_xh'][
'ac'],
'true') == 0)
661 if (
$GLOBALS[
'_xh'][
'ac']!=
'0' && strcasecmp($_xh[$parser][
'ac'],
'false') != 0)
662 error_log(
'XML-RPC: invalid value received in BOOLEAN: '.
$GLOBALS[
'_xh'][
'ac']);
666 elseif ($name==
'DOUBLE')
671 if (!preg_match(
'/^[+-eE0123456789 \t.]+$/',
$GLOBALS[
'_xh'][
'ac']))
674 error_log(
'XML-RPC: non numeric value received in DOUBLE: '.
$GLOBALS[
'_xh'][
'ac']);
675 $GLOBALS[
'_xh'][
'value']=
'ERROR_NON_NUMERIC_FOUND';
687 if (!preg_match(
'/^[+-]?[0123456789 \t]+$/',
$GLOBALS[
'_xh'][
'ac']))
690 error_log(
'XML-RPC: non numeric value received in INT: '.
$GLOBALS[
'_xh'][
'ac']);
691 $GLOBALS[
'_xh'][
'value']=
'ERROR_NON_NUMERIC_FOUND';
711 $vscount = count(
$GLOBALS[
'_xh'][
'valuestack']);
712 $GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'values'][
$GLOBALS[
'_xh'][
'valuestack'][$vscount-1][
'name']] =
$GLOBALS[
'_xh'][
'value'];
714 error_log(
'XML-RPC: missing VALUE inside STRUCT in received xml');
723 $curr_val = array_pop(
$GLOBALS[
'_xh'][
'valuestack']);
724 $GLOBALS[
'_xh'][
'value'] = $curr_val[
'values'];
725 $GLOBALS[
'_xh'][
'vt']=strtolower($name);
726 if (isset($curr_val[
'php_class']))
728 $GLOBALS[
'_xh'][
'php_class'] = $curr_val[
'php_class'];
740 error_log(
'XML-RPC: missing VALUE inside PARAM in received xml');
743 $GLOBALS[
'_xh'][
'method']=preg_replace(
'/^[\n\r\t ]+/',
'',
$GLOBALS[
'_xh'][
'ac']);
746 if (
$GLOBALS[
'xmlrpc_null_extension'])
757 case 'METHORESPONSE':
807 if(substr($data, 0, 1) ==
'&' && substr($data, -1, 1) ==
';')
890 $parts = parse_url(
$path);
892 $path = isset($parts[
'path']) ? $parts[
'path'] :
'';
893 if(isset($parts[
'query']))
895 $path .=
'?'.$parts[
'query'];
897 if(isset($parts[
'fragment']))
899 $path .=
'#'.$parts[
'fragment'];
901 if(isset($parts[
'port']))
903 $port = $parts[
'port'];
905 if(isset($parts[
'scheme']))
909 if(isset($parts[
'user']))
911 $this->username = $parts[
'user'];
913 if(isset($parts[
'pass']))
915 $this->password = $parts[
'pass'];
920 $this->path=
'/'.$path;
937 if(function_exists(
'gzinflate') || (
938 function_exists(
'curl_init') && (($info = curl_version()) &&
939 ((is_string($info) && strpos($info,
'zlib') !==
null) || isset($info[
'libz_version'])))
942 $this->accepted_compression = array(
'gzip',
'deflate');
947 if(version_compare(phpversion(),
'4.3.8') >= 0)
949 $this->keepalive =
true;
953 $this->accepted_charset_encodings = array(
'UTF-8',
'ISO-8859-1',
'US-ASCII');
1032 $this->verifypeer = $i;
1042 $this->verifyhost = $i;
1056 $this->proxy = $proxyhost;
1058 $this->proxy_user = $proxyusername;
1059 $this->proxy_pass = $proxypassword;
1060 $this->proxy_authtype = $proxyauthtype;
1073 if ($compmethod ==
'any')
1074 $this->accepted_compression = array(
'gzip',
'deflate');
1076 $this->accepted_compression = array($compmethod);
1088 $this->request_compression = $compmethod;
1106 $this->cookies[$name][
'value'] = urlencode($value);
1109 $this->cookies[$name][
'path'] =
$path;
1110 $this->cookies[$name][
'domain'] = $domain;
1111 $this->cookies[$name][
'port'] =
$port;
1112 $this->cookies[$name][
'version'] = 1;
1116 $this->cookies[$name][
'version'] = 0;
1143 elseif(is_string($msg))
1171 $this->proxy_authtype,
1195 $this->proxy_authtype,
1214 $this->proxy_authtype
1226 $proxyport=0, $proxyusername=
'', $proxypassword=
'', $proxyauthtype=1)
1234 if(
empty($msg->payload))
1236 $msg->createPayload($this->request_charset_encoding);
1239 $payload = $msg->payload;
1241 if(function_exists(
'gzdeflate') && ($this->request_compression ==
'gzip' || $this->request_compression ==
'deflate'))
1243 if($this->request_compression ==
'gzip')
1245 $a = @gzencode($payload);
1249 $encoding_hdr =
"Content-Encoding: gzip\r\n";
1254 $a = @gzcompress($payload);
1258 $encoding_hdr =
"Content-Encoding: deflate\r\n";
1271 $credentials=
'Authorization: Basic ' . base64_encode(
$username .
':' .
$password) .
"\r\n";
1274 error_log(
'XML-RPC: xmlrpc_client::send: warning. Only Basic auth is supported with HTTP 1.0');
1278 $accepted_encoding =
'';
1279 if(is_array($this->accepted_compression) && count($this->accepted_compression))
1281 $accepted_encoding =
'Accept-Encoding: ' . implode(
', ', $this->accepted_compression) .
"\r\n";
1284 $proxy_credentials =
'';
1291 $connectserver = $proxyhost;
1293 $uri =
'http://'.$server.
':'.
$port.$this->path;
1294 if($proxyusername !=
'')
1296 if ($proxyauthtype != 1)
1298 error_log(
'XML-RPC: xmlrpc_client::send: warning. Only Basic auth to proxy is supported with HTTP 1.0');
1300 $proxy_credentials =
'Proxy-Authorization: Basic ' . base64_encode($proxyusername.
':'.$proxypassword) .
"\r\n";
1306 $connectport =
$port;
1313 if (count($this->cookies))
1316 foreach ($this->cookies
as $name => $cookie)
1318 if ($cookie[
'version'])
1320 $version =
' $Version="' . $cookie[
'version'] .
'";';
1321 $cookieheader .=
' ' . $name .
'="' . $cookie[
'value'] .
'";';
1322 if ($cookie[
'path'])
1323 $cookieheader .=
' $Path="' . $cookie[
'path'] .
'";';
1324 if ($cookie[
'domain'])
1325 $cookieheader .=
' $Domain="' . $cookie[
'domain'] .
'";';
1326 if ($cookie[
'port'])
1327 $cookieheader .=
' $Port="' . $cookie[
'port'] .
'";';
1331 $cookieheader .=
' ' . $name .
'=' . $cookie[
'value'] .
";";
1334 $cookieheader =
'Cookie:' . $version . substr($cookieheader, 0, -1) .
"\r\n";
1337 $op=
'POST ' . $uri.
" HTTP/1.0\r\n" .
1338 'User-Agent: ' .
$GLOBALS[
'xmlrpcName'] .
' ' .
$GLOBALS[
'xmlrpcVersion'] .
"\r\n" .
1341 $proxy_credentials .
1342 $accepted_encoding .
1344 'Accept-Charset: ' . implode(
',', $this->accepted_charset_encodings) .
"\r\n" .
1346 'Content-Type: ' . $msg->content_type .
"\r\nContent-Length: " .
1347 strlen($payload) .
"\r\n\r\n" .
1350 if($this->debug > 1)
1352 print
"<PRE>\n---SENDING---\n" . htmlentities($op) .
"\n---END---\n</PRE>";
1359 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr, $timeout);
1363 $fp=@fsockopen($connectserver, $connectport, $this->errno, $this->errstr);
1367 if($timeout>0 && function_exists(
'stream_set_timeout'))
1369 stream_set_timeout($fp, $timeout);
1374 $this->errstr=
'Connect error: '.$this->errstr;
1375 $r=
new xmlrpcresp(0,
$GLOBALS[
'xmlrpcerr'][
'http_error'], $this->errstr .
' (' . $this->errno .
')');
1379 if(!fputs($fp, $op, strlen($op)))
1381 $this->errstr=
'Write error';
1393 while($data=fread($fp, 32768))
1400 $r =& $msg->parseResponse($ipd,
false, $this->return_type);
1410 $proxyhost=
'',
$proxyport=0, $proxyusername=
'', $proxypassword=
'', $proxyauthtype=1,
1427 $proxyhost=
'',
$proxyport=0, $proxyusername=
'', $proxypassword=
'', $proxyauthtype=1,
$method=
'https',
1430 if(!function_exists(
'curl_init'))
1432 $this->errstr=
'CURL unavailable on this install';
1438 if(($info = curl_version()) &&
1439 ((is_string($info) && strpos($info,
'OpenSSL') ===
null) || (is_array($info) && !isset($info[
'ssl_version']))))
1441 $this->errstr=
'SSL unavailable on this install';
1460 if(
empty($msg->payload))
1462 $msg->createPayload($this->request_charset_encoding);
1466 $payload = $msg->payload;
1467 if(function_exists(
'gzdeflate') && ($this->request_compression ==
'gzip' || $this->request_compression ==
'deflate'))
1469 if($this->request_compression ==
'gzip')
1471 $a = @gzencode($payload);
1475 $encoding_hdr =
'Content-Encoding: gzip';
1480 $a = @gzcompress($payload);
1484 $encoding_hdr =
'Content-Encoding: deflate';
1493 if($this->debug > 1)
1495 print
"<PRE>\n---SENDING---\n" . htmlentities($payload) .
"\n---END---\n</PRE>";
1500 if(!
$keepalive || !$this->xmlrpc_curl_handle)
1505 $this->xmlrpc_curl_handle = $curl;
1514 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
1518 curl_setopt($curl, CURLOPT_VERBOSE, 1);
1520 curl_setopt($curl, CURLOPT_USERAGENT,
$GLOBALS[
'xmlrpcName'].
' '.
$GLOBALS[
'xmlrpcVersion']);
1522 curl_setopt($curl, CURLOPT_POST, 1);
1524 curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
1527 curl_setopt($curl, CURLOPT_HEADER, 1);
1533 if(is_array($this->accepted_compression) && count($this->accepted_compression))
1537 if (count($this->accepted_compression) == 1)
1539 curl_setopt($curl, CURLOPT_ENCODING, $this->accepted_compression[0]);
1542 curl_setopt($curl, CURLOPT_ENCODING,
'');
1545 $headers = array(
'Content-Type: ' . $msg->content_type ,
'Accept-Charset: ' . implode(
',', $this->accepted_charset_encodings));
1549 $headers[] =
'Connection: close';
1554 $headers[] = $encoding_hdr;
1557 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1561 curl_setopt($curl, CURLOPT_TIMEOUT, $timeout == 1 ? 1 : $timeout - 1);
1567 if (defined(
'CURLOPT_HTTPAUTH'))
1569 curl_setopt($curl, CURLOPT_HTTPAUTH,
$authtype);
1573 error_log(
'XML-RPC: xmlrpc_client::send: warning. Only Basic auth is supported by the current PHP/curl install');
1582 curl_setopt($curl, CURLOPT_SSLCERT,
$cert);
1587 curl_setopt($curl, CURLOPT_SSLCERTPASSWD,
$certpass);
1590 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
1594 curl_setopt($curl, CURLOPT_CAINFO,
$cacert);
1598 curl_setopt($curl, CURLOPT_CAPATH,
$cacertdir);
1603 curl_setopt($curl, CURLOPT_SSLKEY,
$key);
1608 curl_setopt($curl, CURLOPT_SSLKEYPASSWD,
$keypass);
1611 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
1621 curl_setopt($curl, CURLOPT_PROXY, $proxyhost.
':'.
$proxyport);
1625 curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyusername.
':'.$proxypassword);
1626 if (defined(
'CURLOPT_PROXYAUTH'))
1628 curl_setopt($curl, CURLOPT_PROXYAUTH, $proxyauthtype);
1630 else if ($proxyauthtype != 1)
1632 error_log(
'XML-RPC: xmlrpc_client::send: warning. Only Basic auth to proxy is supported by the current PHP/curl install');
1640 if (count($this->cookies))
1643 foreach ($this->cookies
as $name => $cookie)
1645 $cookieheader .= $name .
'=' . $cookie[
'value'] .
'; ';
1647 curl_setopt($curl, CURLOPT_COOKIE, substr($cookieheader, 0, -2));
1650 $result = curl_exec($curl);
1652 if ($this->debug > 1)
1654 print
"<PRE>\n---CURL INFO---\n";
1655 foreach(curl_getinfo($curl)
as $name => $val)
1656 print $name .
': ' . htmlentities($val).
"\n";
1657 print
"---END---\n</PRE>";
1662 $this->errstr=
'no response';
1667 $this->xmlrpc_curl_handle =
null;
1676 $resp =& $msg->parseResponse($result,
true, $this->return_type);
1709 if(!$this->no_multicall)
1712 if(is_array($results))
1724 $this->no_multicall =
true;
1728 if (is_a($results,
'xmlrpcresp'))
1751 foreach($msgs
as $msg)
1753 $results[] =& $this->
send($msg, $timeout,
$method);
1761 foreach($msgs
as $msg)
1763 $results[] = $result;
1779 foreach($msgs
as $msg)
1781 $call[
'methodName'] =
new xmlrpcval($msg->method(),
'string');
1782 $numParams = $msg->getNumParams();
1784 for($i = 0; $i < $numParams; $i++)
1786 $params[$i] = $msg->getParam($i);
1788 $call[
'params'] =
new xmlrpcval($params,
'array');
1789 $calls[] =
new xmlrpcval($call,
'struct');
1791 $multicall =
new xmlrpcmsg(
'system.multicall');
1792 $multicall->addParam(
new xmlrpcval($calls,
'array'));
1795 $result =& $this->
send($multicall, $timeout,
$method);
1797 if($result->faultCode() != 0)
1804 $rets = $result->value();
1806 if ($this->return_type ==
'xml')
1810 else if ($this->return_type ==
'phpvals')
1813 $rets = $result->value();
1814 if(!is_array($rets))
1818 $numRets = count($rets);
1819 if($numRets != count($msgs))
1824 $response = array();
1825 for($i = 0; $i < $numRets; $i++)
1828 if (!is_array($val)) {
1839 $response[$i] =
new xmlrpcresp($val[0], 0,
'',
'phpvals');
1843 $code = @$val[
'faultCode'];
1848 $str = @$val[
'faultString'];
1849 if(!is_string($str))
1853 $response[$i] =
new xmlrpcresp(0, $code, $str);
1863 $rets = $result->value();
1864 if($rets->kindOf() !=
'array')
1868 $numRets = $rets->arraysize();
1869 if($numRets != count($msgs))
1874 $response = array();
1875 for($i = 0; $i < $numRets; $i++)
1877 $val = $rets->arraymem($i);
1878 switch($val->kindOf())
1881 if($val->arraysize() != 1)
1886 $response[$i] =
new xmlrpcresp($val->arraymem(0));
1889 $code = $val->structmem(
'faultCode');
1890 if($code->kindOf() !=
'scalar' || $code->scalartyp() !=
'int')
1894 $str = $val->structmem(
'faultString');
1895 if($str->kindOf() !=
'scalar' || $str->scalartyp() !=
'string')
1899 $response[$i] =
new xmlrpcresp(0, $code->scalarval(), $str->scalarval());
1937 $this->errno = $fcode;
1938 $this->errstr = $fstr;
1948 if (is_object($this->val) && is_a($this->val,
'xmlrpcval'))
1950 $this->valtyp =
'xmlrpcvals';
1952 else if (is_string($this->val))
1954 $this->valtyp =
'xml';
1959 $this->valtyp =
'phpvals';
2024 if ($charset_encoding !=
'')
2025 $this->content_type =
'text/xml; charset=' . $charset_encoding;
2027 $this->content_type =
'text/xml';
2028 $result =
"<methodResponse>\n";
2033 $result .=
"<fault>\n" .
2034 "<value>\n<struct><member><name>faultCode</name>\n<value><int>" . $this->errno .
2035 "</int></value>\n</member>\n<member>\n<name>faultString</name>\n<value><string>" .
2036 xmlrpc_encode_entitites($this->errstr,
$GLOBALS[
'xmlrpc_internalencoding'], $charset_encoding) .
"</string></value>\n</member>\n" .
2037 "</struct>\n</value>\n</fault>";
2041 if(!is_object($this->val) || !is_a($this->val,
'xmlrpcval'))
2043 if (is_string($this->val) && $this->valtyp ==
'xml')
2045 $result .=
"<params>\n<param>\n" .
2047 "</param>\n</params>";
2052 die(
'cannot serialize xmlrpcresp objects whose content is native php values');
2057 $result .=
"<params>\n<param>\n" .
2058 $this->val->serialize($charset_encoding) .
2059 "</param>\n</params>";
2062 $result .=
"\n</methodResponse>";
2063 $this->payload = $result;
2082 $this->methodname=$meth;
2083 if(is_array($pars) && count($pars)>0)
2085 for($i=0; $i<count($pars); $i++)
2097 if ($charset_encoding !=
'')
2099 return "<?xml version=\"1.0\" encoding=\"$charset_encoding\" ?" .
">\n<methodCall>\n";
2103 return "<?xml version=\"1.0\"?" .
">\n<methodCall>\n";
2112 return '</methodCall>';
2128 if ($charset_encoding !=
'')
2129 $this->content_type =
'text/xml; charset=' . $charset_encoding;
2131 $this->content_type =
'text/xml';
2132 $this->payload=$this->
xml_header($charset_encoding);
2133 $this->payload.=
'<methodName>' . $this->methodname .
"</methodName>\n";
2134 $this->payload.=
"<params>\n";
2135 for($i=0; $i<count($this->params); $i++)
2137 $p=$this->params[$i];
2138 $this->payload.=
"<param>\n" . $p->serialize($charset_encoding) .
2141 $this->payload.=
"</params>\n";
2155 $this->methodname=$meth;
2180 if(is_object($par) && is_a($par,
'xmlrpcval'))
2182 $this->params[]=$par;
2216 while($data=fread($fp, 32768))
2232 if(preg_match(
'/^HTTP\/1\.[0-1] 200 Connection established/', $data))
2236 $pos = strpos($data,
"\r\n\r\n");
2237 if($pos || is_int($pos))
2243 $pos = strpos($data,
"\n\n");
2244 if($pos || is_int($pos))
2258 $data = substr($data, $bd);
2262 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: HTTPS via proxy error, tunnel connection possibly failed');
2263 $r=
new xmlrpcresp(0,
$GLOBALS[
'xmlrpcerr'][
'http_error'],
$GLOBALS[
'xmlrpcstr'][
'http_error'].
' (HTTPS via proxy error, tunnel connection possibly failed)');
2269 while(preg_match(
'/^HTTP\/1\.1 1[0-9]{2} /', $data))
2271 $pos = strpos($data,
'HTTP', 12);
2274 if(!$pos && !is_int($pos))
2278 $data = substr($data, $pos);
2280 if(!preg_match(
'/^HTTP\/[0-9.]+ 200 /', $data))
2282 $errstr= substr($data, 0, strpos($data,
"\n")-1);
2283 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: HTTP error, got response: ' .$errstr);
2288 $GLOBALS[
'_xh'][
'headers'] = array();
2289 $GLOBALS[
'_xh'][
'cookies'] = array();
2293 $pos = strpos($data,
"\r\n\r\n");
2294 if($pos || is_int($pos))
2300 $pos = strpos($data,
"\n\n");
2301 if($pos || is_int($pos))
2313 $ar = preg_split(
"/\r?\n/", trim(substr($data, 0, $pos)));
2314 while(list(,$line) = @each($ar))
2317 $arr = explode(
':',$line,2);
2320 $header_name = strtolower(trim($arr[0]));
2325 if ($header_name ==
'set-cookie' || $header_name ==
'set-cookie2')
2327 if ($header_name ==
'set-cookie2')
2331 $cookies = explode(
',', $arr[1]);
2335 $cookies = array($arr[1]);
2337 foreach ($cookies
as $cookie)
2341 if (isset(
$GLOBALS[
'_xh'][
'headers'][$header_name]))
2342 $GLOBALS[
'_xh'][
'headers'][$header_name] .=
', ' . trim($cookie);
2344 $GLOBALS[
'_xh'][
'headers'][$header_name] = trim($cookie);
2348 $cookie = explode(
';', $cookie);
2349 foreach ($cookie
as $pos => $val)
2351 $val = explode(
'=', $val, 2);
2352 $tag = trim($val[0]);
2353 $val = trim(@$val[1]);
2358 $GLOBALS[
'_xh'][
'cookies'][$tag] = array();
2359 $GLOBALS[
'_xh'][
'cookies'][$cookiename][
'value'] = urldecode($val);
2363 if ($tag !=
'value')
2365 $GLOBALS[
'_xh'][
'cookies'][$cookiename][$tag] = $val;
2373 $GLOBALS[
'_xh'][
'headers'][$header_name] = trim($arr[1]);
2376 elseif(isset($header_name))
2379 $GLOBALS[
'_xh'][
'headers'][$header_name] .=
' ' . trim($line);
2383 $data = substr($data, $bd);
2385 if($this->debug && count(
$GLOBALS[
'_xh'][
'headers']))
2388 foreach(
$GLOBALS[
'_xh'][
'headers']
as $header => $value)
2390 print htmlentities(
"HEADER: $header: $value\n");
2392 foreach(
$GLOBALS[
'_xh'][
'cookies']
as $header => $value)
2394 print htmlentities(
"COOKIE: $header={$value['value']}\n");
2401 if(!$headers_processed)
2404 if(isset(
$GLOBALS[
'_xh'][
'headers'][
'transfer-encoding']) &&
$GLOBALS[
'_xh'][
'headers'][
'transfer-encoding'] ==
'chunked')
2408 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: errors occurred when trying to rebuild the chunked data received from server');
2416 if(isset(
$GLOBALS[
'_xh'][
'headers'][
'content-encoding']))
2418 $GLOBALS[
'_xh'][
'headers'][
'content-encoding'] = str_replace(
'x-',
'',
$GLOBALS[
'_xh'][
'headers'][
'content-encoding']);
2419 if(
$GLOBALS[
'_xh'][
'headers'][
'content-encoding'] ==
'deflate' ||
$GLOBALS[
'_xh'][
'headers'][
'content-encoding'] ==
'gzip')
2422 if(function_exists(
'gzinflate'))
2424 if(
$GLOBALS[
'_xh'][
'headers'][
'content-encoding'] ==
'deflate' && $degzdata = @gzuncompress($data))
2428 print
"<PRE>---INFLATED RESPONSE---[".strlen($data).
" chars]---\n" . htmlentities($data) .
"\n---END---</PRE>";
2430 elseif(
$GLOBALS[
'_xh'][
'headers'][
'content-encoding'] ==
'gzip' && $degzdata = @gzinflate(substr($data, 10)))
2434 print
"<PRE>---INFLATED RESPONSE---[".strlen($data).
" chars]---\n" . htmlentities($data) .
"\n---END---</PRE>";
2438 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: errors occurred when trying to decode the deflated data received from server');
2445 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: the server sent deflated data. Your php install must have the Zlib extension compiled in to support this.');
2467 function &
parseResponse($data=
'', $headers_processed=
false, $return_type=
'xmlrpcvals')
2472 print
"<PRE>---GOT---\n" . htmlentities($data) .
"\n---END---\n</PRE>";
2477 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: no response received from server.');
2486 if(substr($data, 0, 4) ==
'HTTP')
2493 $r->raw_data = $data;
2499 $GLOBALS[
'_xh'][
'headers'] = array();
2500 $GLOBALS[
'_xh'][
'cookies'] = array();
2505 $start = strpos($data,
'<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2508 $start += strlen(
'<!-- SERVER DEBUG INFO (BASE64 ENCODED):');
2509 $end = strpos($data,
'-->', $start);
2510 $comments = substr($data, $start, $end-$start);
2511 print
"<PRE>---SERVER DEBUG INFO (DECODED) ---\n\t".htmlentities(str_replace(
"\n",
"\n\t", base64_decode($comments))).
"\n---END---\n</PRE>";
2516 $data = trim($data);
2524 $pos = strpos($data,
'</methodResponse>');
2525 while($pos || is_int($pos))
2528 $pos = strpos($data,
'</methodResponse>', $bd);
2532 $data = substr($data, 0, $bd);
2536 if ($return_type ==
'xml')
2539 $r->hdrs =
$GLOBALS[
'_xh'][
'headers'];
2540 $r->_cookies =
$GLOBALS[
'_xh'][
'cookies'];
2541 $r->raw_data = $raw_data;
2550 $GLOBALS[
'_xh'][
'stack'] = array();
2551 $GLOBALS[
'_xh'][
'valuestack'] = array();
2558 if (!in_array($resp_encoding, array(
'UTF-8',
'ISO-8859-1',
'US-ASCII')))
2563 error_log(
'XML-RPC: xmlrpcmsg::parseResponse: invalid charset encoding of received response: '.$resp_encoding);
2564 $resp_encoding =
$GLOBALS[
'xmlrpc_defencoding'];
2566 $parser = xml_parser_create($resp_encoding);
2567 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING,
true);
2574 if (!in_array(
$GLOBALS[
'xmlrpc_internalencoding'], array(
'UTF-8',
'ISO-8859-1',
'US-ASCII')))
2576 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
'UTF-8');
2580 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
$GLOBALS[
'xmlrpc_internalencoding']);
2583 if ($return_type ==
'phpvals')
2585 xml_set_element_handler($parser,
'xmlrpc_se',
'xmlrpc_ee_fast');
2589 xml_set_element_handler($parser,
'xmlrpc_se',
'xmlrpc_ee');
2592 xml_set_character_data_handler($parser,
'xmlrpc_cd');
2593 xml_set_default_handler($parser,
'xmlrpc_dh');
2596 if(!xml_parse($parser, $data, count($data)))
2599 if((xml_get_current_line_number($parser)) == 1)
2601 $errstr =
'XML error at line 1, check URL';
2605 $errstr = sprintf(
'XML error: %s at line %d, column %d',
2606 xml_error_string(xml_get_error_code($parser)),
2607 xml_get_current_line_number($parser), xml_get_current_column_number($parser));
2611 xml_parser_free($parser);
2616 $r->hdrs =
$GLOBALS[
'_xh'][
'headers'];
2617 $r->_cookies =
$GLOBALS[
'_xh'][
'cookies'];
2618 $r->raw_data = $raw_data;
2621 xml_parser_free($parser);
2631 $GLOBALS[
'xmlrpcstr'][
'invalid_return'] .
' ' .
$GLOBALS[
'_xh'][
'isf_reason']);
2635 elseif ($return_type ==
'xmlrpcvals' && !is_object(
$GLOBALS[
'_xh'][
'value']))
2641 $GLOBALS[
'xmlrpcstr'][
'invalid_return']);
2647 print
"<PRE>---PARSED---\n";
2650 print htmlspecialchars(var_export(
$GLOBALS[
'_xh'][
'value'],
true));
2651 print
"\n---END---</PRE>";
2661 if ($return_type ==
'xmlrpcvals')
2663 $errno_v = $v->structmem(
'faultCode');
2664 $errstr_v = $v->structmem(
'faultString');
2665 $errno = $errno_v->scalarval();
2666 $errstr = $errstr_v->scalarval();
2670 $errno = $v[
'faultCode'];
2671 $errstr = $v[
'faultString'];
2688 $r->hdrs =
$GLOBALS[
'_xh'][
'headers'];
2689 $r->_cookies =
$GLOBALS[
'_xh'][
'cookies'];
2690 $r->raw_data = $raw_data;
2709 if($val!==-1 || $type!=
'')
2716 $this->me[
'string']=$val;
2723 case 'dateTime.iso8601':
2727 $this->me[$type]=$val;
2731 $this->me[
'array']=$val;
2735 $this->me[
'struct']=$val;
2738 error_log(
"XML-RPC: xmlrpcval::xmlrpcval: not a known type ($type)");
2767 $typeof=@
$GLOBALS[
'xmlrpcTypes'][$type];
2770 error_log(
"XML-RPC: xmlrpcval::addScalar: not a scalar type ($type)");
2777 if($type==
$GLOBALS[
'xmlrpcBoolean'])
2779 if(strcasecmp($val,
'true')==0 || $val==1 || ($val==
true && strcasecmp($val,
'false')))
2789 switch($this->mytype)
2792 error_log(
'XML-RPC: xmlrpcval::addScalar: scalar xmlrpcval can have only one value');
2795 error_log(
'XML-RPC: xmlrpcval::addScalar: cannot add anonymous scalar to struct xmlrpcval');
2803 $this->me[
'array'][]=
new xmlrpcval($val, $type);
2807 $this->me[$type]=$val;
2808 $this->mytype=$typeof;
2823 if($this->mytype==0)
2825 $this->mytype=
$GLOBALS[
'xmlrpcTypes'][
'array'];
2826 $this->me[
'array']=$vals;
2829 elseif($this->mytype==2)
2832 $this->me[
'array'] = array_merge($this->me[
'array'], $vals);
2837 error_log(
'XML-RPC: xmlrpcval::addArray: already initialized as a [' . $this->
kindOf() .
']');
2852 if($this->mytype==0)
2854 $this->mytype=
$GLOBALS[
'xmlrpcTypes'][
'struct'];
2855 $this->me[
'struct']=$vals;
2858 elseif($this->mytype==3)
2861 $this->me[
'struct'] = array_merge($this->me[
'struct'], $vals);
2866 error_log(
'XML-RPC: xmlrpcval::addStruct: already initialized as a [' . $this->
kindOf() .
']');
2875 foreach($ar
as $key => $val)
2877 echo
"$key => $val<br />";
2880 while(list($key2, $val2) = each($val))
2882 echo
"-- $key2 => $val2<br />";
2895 switch($this->mytype)
2917 switch(@
$GLOBALS[
'xmlrpcTypes'][$typ])
2923 $rs.=
"<${typ}>" . base64_encode($val) .
"</${typ}>";
2926 $rs.=
"<${typ}>" . ($val ?
'1' :
'0') .
"</${typ}>";
2935 $rs.=
"<${typ}>".(int)$val.
"</${typ}>";
2938 $rs.=
"<${typ}>".(double)$val.
"</${typ}>";
2946 $rs.=
"<${typ}>${val}</${typ}>";
2951 if ($this->_php_class)
2953 $rs.=
'<struct php_class="' . $this->_php_class .
"\">\n";
2959 foreach($val
as $key2 => $val2)
2961 $rs.=
'<member><name>'.xmlrpc_encode_entitites($key2,
$GLOBALS[
'xmlrpc_internalencoding'], $charset_encoding).
"</name>\n";
2963 $rs.=$val2->serialize($charset_encoding);
2970 $rs.=
"<array>\n<data>\n";
2971 for($i=0; $i<count($val); $i++)
2974 $rs.=$val[$i]->serialize($charset_encoding);
2976 $rs.=
"</data>\n</array>";
2996 list($typ, $val) = each($this->me);
2997 return '<value>' . $this->
serializedata($typ, $val, $charset_encoding) .
"</value>\n";
3009 list($typ, $val) = each($ar);
3010 return '<value>' . $this->
serializedata($typ, $val) .
"</value>\n";
3023 return array_key_exists($m, $this->me[
'struct']);
3035 return $this->me[
'struct'][$m];
3044 reset($this->me[
'struct']);
3054 return each($this->me[
'struct']);
3063 list($a,$b)=each($this->me);
3072 while(list($id,$cont) = @each($b))
3074 $b[$id] = $cont->scalarval();
3081 $t = get_object_vars($b);
3083 while(list($id,$cont) = @each($t))
3085 $t[$id] = $cont->scalarval();
3088 while(list($id,$cont) = @each($t))
3105 list(,$b)=each($this->me);
3118 list($a,)=each($this->me);
3134 return $this->me[
'array'][$m];
3144 return count($this->me[
'array']);
3154 return count($this->me[
'struct']);
3182 $t=strftime(
"%Y%m%dT%H:%M:%S", $timet);
3186 if(function_exists(
'gmstrftime'))
3190 $t=gmstrftime(
"%Y%m%dT%H:%M:%S", $timet);
3194 $t=strftime(
"%Y%m%dT%H:%M:%S", $timet-date(
'Z'));
3209 if(preg_match(
'/([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})/', $idate, $regs))
3213 $t=gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3217 $t=mktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
3246 switch($xmlrpc_val->kindOf())
3249 if (in_array(
'extension_api', $options))
3251 reset($xmlrpc_val->me);
3252 list($typ,$val) = each($xmlrpc_val->me);
3255 case 'dateTime.iso8601':
3256 $xmlrpc_val->scalar = $val;
3257 $xmlrpc_val->xmlrpc_type =
'datetime';
3261 $xmlrpc_val->scalar = $val;
3262 $xmlrpc_val->type = $typ;
3265 return $xmlrpc_val->scalarval();
3268 return $xmlrpc_val->scalarval();
3270 $size = $xmlrpc_val->arraysize();
3272 for($i = 0; $i < $size; $i++)
3278 $xmlrpc_val->structreset();
3283 if (in_array(
'decode_php_objs', $options) && $xmlrpc_val->_php_class !=
''
3284 && class_exists($xmlrpc_val->_php_class))
3286 $obj = @
new $xmlrpc_val->_php_class;
3287 while(list($key,$value)=$xmlrpc_val->structeach())
3296 while(list($key,$value)=$xmlrpc_val->structeach())
3303 $paramcount = $xmlrpc_val->getNumParams();
3305 for($i = 0; $i < $paramcount; $i++)
3316 if(function_exists(
'xmlrpc_decode'))
3318 define(
'XMLRPC_EPI_ENABLED',
'1');
3322 define(
'XMLRPC_EPI_ENABLED',
'0');
3344 $type = gettype($php_val);
3348 if (in_array(
'auto_dates', $options) && preg_match(
'/^[0-9]{8}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/', $php_val))
3374 foreach($php_val
as $key => $val)
3377 if(!$ko && $key !== $j)
3393 if(is_a($php_val,
'xmlrpcval'))
3395 $xmlrpc_val = $php_val;
3400 while(list($k,$v) = each($php_val))
3405 if (in_array(
'encode_php_objs', $options))
3409 $xmlrpc_val->_php_class = get_class($php_val);
3414 if (in_array(
'extension_api', $options))
3418 if (in_array(
'null_extension', $options))
3428 if (in_array(
'extension_api', $options))
3458 $GLOBALS[
'_xh'][
'stack'] = array();
3459 $GLOBALS[
'_xh'][
'valuestack'] = array();
3460 $GLOBALS[
'_xh'][
'params'] = array();
3463 $GLOBALS[
'_xh'][
'isf_reason'] =
'';
3467 $parser = xml_parser_create();
3468 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING,
true);
3471 if (!in_array(
$GLOBALS[
'xmlrpc_internalencoding'], array(
'UTF-8',
'ISO-8859-1',
'US-ASCII')))
3473 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
'UTF-8');
3477 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING,
$GLOBALS[
'xmlrpc_internalencoding']);
3479 xml_set_element_handler($parser,
'xmlrpc_se_any',
'xmlrpc_ee');
3480 xml_set_character_data_handler($parser,
'xmlrpc_cd');
3481 xml_set_default_handler($parser,
'xmlrpc_dh');
3482 if(!xml_parse($parser, $xml_val, 1))
3484 $errstr = sprintf(
'XML error: %s at line %d, column %d',
3485 xml_error_string(xml_get_error_code($parser)),
3486 xml_get_current_line_number($parser), xml_get_current_column_number($parser));
3488 xml_parser_free($parser);
3491 xml_parser_free($parser);
3494 error_log(
$GLOBALS[
'_xh'][
'isf_reason']);
3499 case 'methodresponse':
3503 $vc = $v->structmem(
'faultCode');
3504 $vs = $v->structmem(
'faultString');
3505 $r =
new xmlrpcresp(0, $vc->scalarval(), $vs->scalarval());
3514 for($i=0; $i < count(
$GLOBALS[
'_xh'][
'params']); $i++)
3516 $m->addParam(
$GLOBALS[
'_xh'][
'params'][$i]);
3542 $chunkend = strpos($buffer,
"\r\n") + 2;
3543 $temp = substr($buffer,0,$chunkend);
3544 $chunk_size = hexdec( trim($temp) );
3545 $chunkstart = $chunkend;
3546 while($chunk_size > 0)
3548 $chunkend = strpos($buffer,
"\r\n", $chunkstart + $chunk_size);
3551 if($chunkend ==
false)
3553 $chunk = substr($buffer,$chunkstart);
3556 $length += strlen($chunk);
3561 $chunk = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3565 $length += strlen($chunk);
3567 $chunkstart = $chunkend + 2;
3569 $chunkend = strpos($buffer,
"\r\n",$chunkstart)+2;
3570 if($chunkend ==
false)
3574 $temp = substr($buffer,$chunkstart,$chunkend-$chunkstart);
3575 $chunk_size = hexdec( trim($temp) );
3576 $chunkstart = $chunkend;
3610 if(preg_match(
'/;\s*charset=([^;]+)/i', $httpheader, $matches))
3612 return strtoupper(trim($matches[1]));
3622 if(preg_match(
'/^(\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\x00\x00\xFF\xFE|\xFE\xFF\x00\x00)/', $xmlchunk))
3626 elseif(preg_match(
'/^(\xFE\xFF|\xFF\xFE)/', $xmlchunk))
3630 elseif(preg_match(
'/^(\xEF\xBB\xBF)/', $xmlchunk))
3639 if (preg_match(
'/^<\?xml\s+version\s*=\s*'.
"((?:\"[a-zA-Z0-9_.:-]+\")|(?:'[a-zA-Z0-9_.:-]+'))".
3640 '\s+encoding\s*=\s*' .
"((?:\"[A-Za-z][A-Za-z0-9._-]*\")|(?:'[A-Za-z][A-Za-z0-9._-]*'))/",
3641 $xmlchunk, $matches))
3643 return strtoupper(substr($matches[2], 1, -1));
3648 if(extension_loaded(
'mbstring'))
3652 $enc = mb_detect_encoding($xmlchunk, $encoding_prefs);
3656 $enc = mb_detect_encoding($xmlchunk);
3672 return $GLOBALS[
'xmlrpc_defencoding'];
3684 $charset_supersets = array(
3685 'US-ASCII' => array (
'ISO-8859-1',
'ISO-8859-2',
'ISO-8859-3',
'ISO-8859-4',
3686 'ISO-8859-5',
'ISO-8859-6',
'ISO-8859-7',
'ISO-8859-8',
3687 'ISO-8859-9',
'ISO-8859-10',
'ISO-8859-11',
'ISO-8859-12',
3688 'ISO-8859-13',
'ISO-8859-14',
'ISO-8859-15',
'UTF-8',
3689 'EUC-JP',
'EUC-',
'EUC-KR',
'EUC-CN')
3691 if (is_string($validlist))
3692 $validlist = explode(
',', $validlist);
3693 if (@in_array(strtoupper($encoding), $validlist))
3697 if (array_key_exists($encoding, $charset_supersets))
3698 foreach ($validlist
as $allowed)
3699 if (in_array($allowed, $charset_supersets[$encoding]))