10 |
10 |
*
|
11 |
11 |
* PHP versions 4 and 5
|
12 |
12 |
*
|
13 |
|
* LICENSE: License is granted to use or modify this software
|
14 |
|
* ("XML-RPC for PHP") for commercial or non-commercial use provided the
|
15 |
|
* copyright of the author is preserved in any distributed or derivative work.
|
16 |
|
*
|
17 |
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESSED OR
|
18 |
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
19 |
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
20 |
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
21 |
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
22 |
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
23 |
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
24 |
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
25 |
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
26 |
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
27 |
|
*
|
28 |
13 |
* @category Web Services
|
29 |
14 |
* @package XML_RPC
|
30 |
15 |
* @author Edd Dumbill <edd@usefulinc.com>
|
31 |
16 |
* @author Stig Bakken <stig@php.net>
|
32 |
17 |
* @author Martin Jansen <mj@php.net>
|
33 |
18 |
* @author Daniel Convissor <danielc@php.net>
|
34 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
35 |
|
* @version CVS: $Id$
|
|
19 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
20 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
21 |
* @version SVN: $Id: RPC.php 300961 2010-07-03 02:17:34Z danielc $
|
36 |
22 |
* @link http://pear.php.net/package/XML_RPC
|
37 |
23 |
*/
|
38 |
24 |
|
39 |
|
/*
|
40 |
|
pfSense_MODULE: utils
|
41 |
|
*/
|
42 |
25 |
|
43 |
26 |
if (!function_exists('xml_parser_create')) {
|
44 |
|
include_once 'PEAR.inc';
|
|
27 |
include_once 'PEAR.php';
|
45 |
28 |
PEAR::loadExtension('xml');
|
46 |
29 |
}
|
47 |
30 |
|
... | ... | |
202 |
185 |
$GLOBALS['XML_RPC_backslash'] = chr(92) . chr(92);
|
203 |
186 |
|
204 |
187 |
|
205 |
|
/**#@+
|
206 |
|
* Which functions to use, depending on whether mbstring is enabled or not.
|
207 |
|
*/
|
208 |
|
if (function_exists('mb_ereg')) {
|
209 |
|
/** @global string $GLOBALS['XML_RPC_func_ereg'] */
|
210 |
|
$GLOBALS['XML_RPC_func_ereg'] = 'mb_eregi';
|
211 |
|
/** @global string $GLOBALS['XML_RPC_func_ereg_replace'] */
|
212 |
|
$GLOBALS['XML_RPC_func_ereg_replace'] = 'mb_eregi_replace';
|
213 |
|
/** @global string $GLOBALS['XML_RPC_func_split'] */
|
214 |
|
$GLOBALS['XML_RPC_func_split'] = 'mb_split';
|
215 |
|
} else {
|
216 |
|
/** @ignore */
|
217 |
|
$GLOBALS['XML_RPC_func_ereg'] = 'eregi';
|
218 |
|
/** @ignore */
|
219 |
|
$GLOBALS['XML_RPC_func_ereg_replace'] = 'eregi_replace';
|
220 |
|
/** @ignore */
|
221 |
|
$GLOBALS['XML_RPC_func_split'] = 'split';
|
222 |
|
}
|
223 |
|
/**#@-*/
|
224 |
|
|
225 |
|
|
226 |
188 |
/**
|
227 |
189 |
* Should we automatically base64 encode strings that contain characters
|
228 |
190 |
* which can cause PHP's SAX-based XML parser to break?
|
... | ... | |
301 |
263 |
} else {
|
302 |
264 |
// not top level element: see if parent is OK
|
303 |
265 |
if (!in_array($XML_RPC_xh[$parser]['stack'][0], $XML_RPC_valid_parents[$name])) {
|
304 |
|
$name = $GLOBALS['XML_RPC_func_ereg_replace']('[^a-zA-Z0-9._-]', '', $name);
|
|
266 |
$name = preg_replace('@[^a-zA-Z0-9._-]@', '', $name);
|
305 |
267 |
$XML_RPC_xh[$parser]['isf'] = 2;
|
306 |
268 |
$XML_RPC_xh[$parser]['isf_reason'] = "xmlrpc element $name cannot be child of {$XML_RPC_xh[$parser]['stack'][0]}";
|
307 |
269 |
return;
|
... | ... | |
465 |
427 |
} else {
|
466 |
428 |
// we have an I4, INT or a DOUBLE
|
467 |
429 |
// we must check that only 0123456789-.<space> are characters here
|
468 |
|
if (!$GLOBALS['XML_RPC_func_ereg']("^[+-]?[0123456789 \t\.]+$", $XML_RPC_xh[$parser]['ac'])) {
|
|
430 |
if (!preg_match("@^[+-]?[0123456789 \t\.]+$@", $XML_RPC_xh[$parser]['ac'])) {
|
469 |
431 |
XML_RPC_Base::raiseError('Non-numeric value received in INT or DOUBLE',
|
470 |
432 |
XML_RPC_ERROR_NON_NUMERIC_FOUND);
|
471 |
433 |
$XML_RPC_xh[$parser]['value'] = XML_RPC_ERROR_NON_NUMERIC_FOUND;
|
... | ... | |
529 |
491 |
|
530 |
492 |
case 'METHODNAME':
|
531 |
493 |
case 'RPCMETHODNAME':
|
532 |
|
$XML_RPC_xh[$parser]['method'] = $GLOBALS['XML_RPC_func_ereg_replace']("^[\n\r\t ]+", '',
|
|
494 |
$XML_RPC_xh[$parser]['method'] = preg_replace("@^[\n\r\t ]+@", '',
|
533 |
495 |
$XML_RPC_xh[$parser]['ac']);
|
534 |
496 |
break;
|
535 |
497 |
}
|
... | ... | |
581 |
543 |
* @author Stig Bakken <stig@php.net>
|
582 |
544 |
* @author Martin Jansen <mj@php.net>
|
583 |
545 |
* @author Daniel Convissor <danielc@php.net>
|
584 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
585 |
|
* @version Release: 1.5.1
|
|
546 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
547 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
548 |
* @version Release: @package_version@
|
586 |
549 |
* @link http://pear.php.net/package/XML_RPC
|
587 |
550 |
*/
|
588 |
551 |
class XML_RPC_Base {
|
... | ... | |
594 |
557 |
*/
|
595 |
558 |
function raiseError($msg, $code)
|
596 |
559 |
{
|
597 |
|
include_once 'PEAR.inc';
|
|
560 |
include_once 'PEAR.php';
|
598 |
561 |
if (is_object(@$this)) {
|
599 |
562 |
return PEAR::raiseError(get_class($this) . ': ' . $msg, $code);
|
600 |
563 |
} else {
|
... | ... | |
626 |
589 |
* @author Stig Bakken <stig@php.net>
|
627 |
590 |
* @author Martin Jansen <mj@php.net>
|
628 |
591 |
* @author Daniel Convissor <danielc@php.net>
|
629 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
630 |
|
* @version Release: 1.5.1
|
|
592 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
593 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
594 |
* @version Release: @package_version@
|
631 |
595 |
* @link http://pear.php.net/package/XML_RPC
|
632 |
596 |
*/
|
633 |
597 |
class XML_RPC_Client extends XML_RPC_Base {
|
... | ... | |
765 |
729 |
$this->proxy_user = $proxy_user;
|
766 |
730 |
$this->proxy_pass = $proxy_pass;
|
767 |
731 |
|
768 |
|
$GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $server, $match);
|
|
732 |
preg_match('@^(http://|https://|ssl://)?(.*)$@', $server, $match);
|
769 |
733 |
if ($match[1] == '') {
|
770 |
734 |
if ($port == 443) {
|
771 |
735 |
$this->server = $match[2];
|
... | ... | |
793 |
757 |
}
|
794 |
758 |
|
795 |
759 |
if ($proxy) {
|
796 |
|
$GLOBALS['XML_RPC_func_ereg']('^(http://|https://|ssl://)?(.*)$', $proxy, $match);
|
|
760 |
preg_match('@^(http://|https://|ssl://)?(.*)$@', $proxy, $match);
|
797 |
761 |
if ($match[1] == '') {
|
798 |
762 |
if ($proxy_port == 443) {
|
799 |
763 |
$this->proxy = $match[2];
|
... | ... | |
923 |
887 |
function sendPayloadHTTP10($msg, $server, $port, $timeout = 0,
|
924 |
888 |
$username = '', $password = '')
|
925 |
889 |
{
|
|
890 |
// Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
|
|
891 |
if ($username != $this->username) {
|
|
892 |
$this->setCredentials($username, $password);
|
|
893 |
}
|
|
894 |
|
|
895 |
// Only create the payload if it was not created previously
|
|
896 |
if (empty($msg->payload)) {
|
|
897 |
$msg->createPayload();
|
|
898 |
}
|
|
899 |
$this->createHeaders($msg);
|
|
900 |
|
|
901 |
$op = $this->headers . "\r\n\r\n";
|
|
902 |
$op .= $msg->payload;
|
|
903 |
|
|
904 |
if ($this->debug) {
|
|
905 |
print "\n<pre>---SENT---\n";
|
|
906 |
print $op;
|
|
907 |
print "\n---END---</pre>\n";
|
|
908 |
}
|
|
909 |
|
926 |
910 |
/*
|
927 |
911 |
* If we're using a proxy open a socket to the proxy server
|
928 |
912 |
* instead to the xml-rpc server
|
... | ... | |
981 |
965 |
socket_set_timeout($fp, $timeout);
|
982 |
966 |
}
|
983 |
967 |
|
984 |
|
// Pre-emptive BC hacks for fools calling sendPayloadHTTP10() directly
|
985 |
|
if ($username != $this->username) {
|
986 |
|
$this->setCredentials($username, $password);
|
987 |
|
}
|
988 |
|
|
989 |
|
// Only create the payload if it was not created previously
|
990 |
|
if (empty($msg->payload)) {
|
991 |
|
$msg->createPayload();
|
992 |
|
}
|
993 |
|
$this->createHeaders($msg);
|
994 |
|
|
995 |
|
$op = $this->headers . "\r\n\r\n";
|
996 |
|
$op .= $msg->payload;
|
997 |
|
|
998 |
968 |
if (!fputs($fp, $op, strlen($op))) {
|
999 |
969 |
$this->errstr = 'Write error';
|
1000 |
970 |
return 0;
|
... | ... | |
1068 |
1038 |
* @author Stig Bakken <stig@php.net>
|
1069 |
1039 |
* @author Martin Jansen <mj@php.net>
|
1070 |
1040 |
* @author Daniel Convissor <danielc@php.net>
|
1071 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
1072 |
|
* @version Release: 1.5.1
|
|
1041 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
1042 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
1043 |
* @version Release: @package_version@
|
1073 |
1044 |
* @link http://pear.php.net/package/XML_RPC
|
1074 |
1045 |
*/
|
1075 |
1046 |
class XML_RPC_Response extends XML_RPC_Base
|
... | ... | |
1159 |
1130 |
* @author Stig Bakken <stig@php.net>
|
1160 |
1131 |
* @author Martin Jansen <mj@php.net>
|
1161 |
1132 |
* @author Daniel Convissor <danielc@php.net>
|
1162 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
1163 |
|
* @version Release: 1.5.1
|
|
1133 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
1134 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
1135 |
* @version Release: @package_version@
|
1164 |
1136 |
* @link http://pear.php.net/package/XML_RPC
|
1165 |
1137 |
*/
|
1166 |
1138 |
class XML_RPC_Message extends XML_RPC_Base
|
... | ... | |
1297 |
1269 |
$this->payload .= "</params>\n";
|
1298 |
1270 |
$this->payload .= $this->xml_footer();
|
1299 |
1271 |
if ($this->remove_extra_lines) {
|
1300 |
|
$this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("[\r\n]+", "\r\n", $this->payload);
|
|
1272 |
$this->payload = preg_replace("@[\r\n]+@", "\r\n", $this->payload);
|
1301 |
1273 |
} else {
|
1302 |
|
$this->payload = $GLOBALS['XML_RPC_func_ereg_replace']("\r\n|\n|\r|\n\r", "\r\n", $this->payload);
|
|
1274 |
$this->payload = preg_replace("@\r\n|\n|\r|\n\r@", "\r\n", $this->payload);
|
1303 |
1275 |
}
|
1304 |
1276 |
if ($this->convert_payload_encoding) {
|
1305 |
1277 |
$this->payload = mb_convert_encoding($this->payload, $this->send_encoding);
|
... | ... | |
1421 |
1393 |
{
|
1422 |
1394 |
global $XML_RPC_defencoding;
|
1423 |
1395 |
|
1424 |
|
if ($GLOBALS['XML_RPC_func_ereg']('<\?xml[^>]*[:space:]*encoding[:space:]*=[:space:]*[\'"]([^"\']*)[\'"]',
|
|
1396 |
if (preg_match('@<\?xml[^>]*\s*encoding\s*=\s*[\'"]([^"\']*)[\'"]@',
|
1425 |
1397 |
$data, $match))
|
1426 |
1398 |
{
|
1427 |
1399 |
$match[1] = trim(strtoupper($match[1]));
|
... | ... | |
1486 |
1458 |
|
1487 |
1459 |
// See if response is a 200 or a 100 then a 200, else raise error.
|
1488 |
1460 |
// But only do this if we're using the HTTP protocol.
|
1489 |
|
if ($GLOBALS['XML_RPC_func_ereg']('^HTTP', $data) &&
|
1490 |
|
!$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 200 ', $data) &&
|
1491 |
|
!$GLOBALS['XML_RPC_func_ereg']('^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200', $data))
|
|
1461 |
if (preg_match('@^HTTP@', $data) &&
|
|
1462 |
!preg_match('@^HTTP/[0-9\.]+ 200 @', $data) &&
|
|
1463 |
!preg_match('@^HTTP/[0-9\.]+ 10[0-9]([A-Z ]+)?[\r\n]+HTTP/[0-9\.]+ 200@', $data))
|
1492 |
1464 |
{
|
1493 |
1465 |
$errstr = substr($data, 0, strpos($data, "\n") - 1);
|
1494 |
1466 |
error_log('HTTP error, got response: ' . $errstr);
|
... | ... | |
1558 |
1530 |
$r = new XML_RPC_Response($v);
|
1559 |
1531 |
}
|
1560 |
1532 |
}
|
1561 |
|
$r->hdrs = split("\r?\n", $XML_RPC_xh[$parser]['ha'][1]);
|
|
1533 |
$r->hdrs = preg_split("@\r?\n@", $XML_RPC_xh[$parser]['ha'][1]);
|
1562 |
1534 |
return $r;
|
1563 |
1535 |
}
|
1564 |
1536 |
}
|
... | ... | |
1572 |
1544 |
* @author Stig Bakken <stig@php.net>
|
1573 |
1545 |
* @author Martin Jansen <mj@php.net>
|
1574 |
1546 |
* @author Daniel Convissor <danielc@php.net>
|
1575 |
|
* @copyright 1999-2001 Edd Dumbill, 2001-2006 The PHP Group
|
1576 |
|
* @version Release: 1.5.1
|
|
1547 |
* @copyright 1999-2001 Edd Dumbill, 2001-2010 The PHP Group
|
|
1548 |
* @license http://www.php.net/license/3_01.txt PHP License
|
|
1549 |
* @version Release: @package_version@
|
1577 |
1550 |
* @link http://pear.php.net/package/XML_RPC
|
1578 |
1551 |
*/
|
1579 |
1552 |
class XML_RPC_Value extends XML_RPC_Base
|
... | ... | |
1731 |
1704 |
$rs .= "<struct>\n";
|
1732 |
1705 |
reset($val);
|
1733 |
1706 |
foreach ($val as $key2 => $val2) {
|
1734 |
|
$rs .= "<member><name>${key2}</name>\n";
|
|
1707 |
$rs .= "<member><name>" . htmlspecialchars($key2) . "</name>\n";
|
1735 |
1708 |
$rs .= $this->serializeval($val2);
|
1736 |
1709 |
$rs .= "</member>\n";
|
1737 |
1710 |
}
|
... | ... | |
1741 |
1714 |
case 2:
|
1742 |
1715 |
// array
|
1743 |
1716 |
$rs .= "<array>\n<data>\n";
|
1744 |
|
for ($i = 0; $i < sizeof($val); $i++) {
|
1745 |
|
$rs .= $this->serializeval($val[$i]);
|
|
1717 |
foreach ($val as $value) {
|
|
1718 |
$rs .= $this->serializeval($value);
|
1746 |
1719 |
}
|
1747 |
1720 |
$rs .= "</data>\n</array>";
|
1748 |
1721 |
break;
|
... | ... | |
1953 |
1926 |
function XML_RPC_iso8601_decode($idate, $utc = 0)
|
1954 |
1927 |
{
|
1955 |
1928 |
$t = 0;
|
1956 |
|
if ($GLOBALS['XML_RPC_func_ereg']('([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})', $idate, $regs)) {
|
|
1929 |
if (preg_match('@([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})@', $idate, $regs)) {
|
1957 |
1930 |
if ($utc) {
|
1958 |
1931 |
$t = gmmktime($regs[4], $regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
|
1959 |
1932 |
} else {
|
... | ... | |
2042 |
2015 |
|
2043 |
2016 |
case 'string':
|
2044 |
2017 |
case 'NULL':
|
2045 |
|
if ($GLOBALS['XML_RPC_func_ereg']('^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$', $php_val)) {
|
|
2018 |
if (preg_match('@^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$@', $php_val)) {
|
2046 |
2019 |
$XML_RPC_val->addScalar($php_val, $GLOBALS['XML_RPC_DateTime']);
|
2047 |
2020 |
} elseif ($GLOBALS['XML_RPC_auto_base64']
|
2048 |
|
&& $GLOBALS['XML_RPC_func_ereg']("[^ -~\t\r\n]", $php_val))
|
|
2021 |
&& preg_match("@[^ -~\t\r\n]@", $php_val))
|
2049 |
2022 |
{
|
2050 |
2023 |
// Characters other than alpha-numeric, punctuation, SP, TAB,
|
2051 |
2024 |
// LF and CR break the XML parser, encode value via Base 64.
|
... | ... | |
2077 |
2050 |
* End:
|
2078 |
2051 |
*/
|
2079 |
2052 |
|
2080 |
|
?>
|
|
2053 |
?>
|
Update the current XML RPC client and server parts from the PEAR library, now version 1.5.4