cvs: php-src /pear/PEAR Remote.php
| From: | Tomas V.V.Cox | Date: | Sat, 12 Jul 2003 14:25:06 +0000 |
| Subject: | cvs: php-src /pear/PEAR Remote.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-11465@lists.php.net to get a copy of this message | ||
cox Sat Jul 12 10:25:06 2003 EDT
Modified files:
/php-src/pear/PEAR Remote.php
Log:
Added proxy support for remote commands using the xmlrcp C ext
(contribution by Adam Ashley <aashley@optimiser.com>)
Index: php-src/pear/PEAR/Remote.php
diff -u php-src/pear/PEAR/Remote.php:1.40 php-src/pear/PEAR/Remote.php:1.41
--- php-src/pear/PEAR/Remote.php:1.40 Tue Jun 10 16:03:43 2003
+++ php-src/pear/PEAR/Remote.php Sat Jul 12 10:25:06 2003
@@ -16,7 +16,7 @@
// | Author: Stig Bakken <ssb@php.net> |
// +----------------------------------------------------------------------+
//
-// $Id: Remote.php,v 1.40 2003/06/10 20:03:43 imajes Exp $
+// $Id: Remote.php,v 1.41 2003/07/12 14:25:06 cox Exp $
require_once 'PEAR.php';
require_once 'PEAR/Config.php';
@@ -50,7 +50,7 @@
// {{{ getCache()
-
+
function getCache($args)
{
$id = md5(serialize($args));
@@ -62,7 +62,7 @@
if (!file_exists($filename)) {
return null;
};
-
+
$fp = fopen($filename, "rb");
if ($fp === null) {
return null;
@@ -78,7 +78,7 @@
}
// }}}
-
+
// {{{ saveCache()
function saveCache($args, $data)
@@ -89,7 +89,7 @@
System::mkdir('-p '.$cachedir);
}
$filename = $cachedir.'/xmlrpc_cache_'.$id;
-
+
$fp = @fopen($filename, "wb");
if ($fp !== null) {
fwrite($fp, serialize($data));
@@ -98,20 +98,20 @@
}
// }}}
-
+
// {{{ call(method, [args...])
function call($method)
{
$_args = $args = func_get_args();
-
+
$this->cache = $this->getCache($args);
$cachettl = $this->config->get('cache_ttl');
// If cache is newer than $cachettl seconds, we use the cache!
if ($this->cache !== null && $this->cache['age'] < $cachettl) {
return $this->cache['content'];
};
-
+
if (extension_loaded("xmlrpc")) {
$result = call_user_func_array(array(&$this, 'call_epi'), $args);
if (!PEAR::isError($result)) {
@@ -140,7 +140,7 @@
$proxy_port = @$proxy['port'];
$proxy_user = @$proxy['user'];
$proxy_pass = @$proxy['pass'];
- }
+ }
$c = new XML_RPC_Client('/xmlrpc.php'.$maxAge, $server_host, 80, $proxy_host,
$proxy_port, $proxy_user, $proxy_pass);
if ($username && $password) {
$c->setCredentials($username, $password);
@@ -204,8 +204,21 @@
return $this->raiseError("PEAR_Remote::call: no master_server
configured");
}
$server_port = 80;
- $fp = @fsockopen($server_host, $server_port);
- if (!$fp) {
+ $proxy_host = $proxy_port = $proxy_user = $proxy_pass = '';
+ if ($proxy = parse_url($this->config->get('http_proxy'))) {
+ $proxy_host = @$proxy['host'];
+ $proxy_port = @$proxy['port'];
+ $proxy_user = @$proxy['user'];
+ $proxy_pass = @$proxy['pass'];
+ }
+ if ($proxy != '') {
+ $fp = @fsockopen($proxy_host, $proxy_port);
+ } else {
+ $fp = @fsockopen($server_host, $server_port);
+ }
+ if (!$fp && $proxy_host != '') {
+ return $this->raiseError("PEAR_Remote::call: fsockopen(`$proxy_host',
$proxy_port) failed");
+ } elseif (!$fp) {
return $this->raiseError("PEAR_Remote::call: fsockopen(`$server_host',
$server_port) failed");
}
$len = strlen($request);
@@ -224,15 +237,30 @@
} else {
$maxAge = '';
};
-
+
+ if ($proxy_host != '' && $proxy_user != '') {
+ $req_headers .= 'Proxy-Authorization: Basic '
+ .base64_encode($proxy_user.':'.$proxy_pass)
+ ."\r\n";
+ }
+
if ($this->config->get('verbose') > 3) {
print "XMLRPC REQUEST HEADERS:\n";
var_dump($req_headers);
print "XMLRPC REQUEST BODY:\n";
var_dump($request);
}
-
- fwrite($fp, ("POST /xmlrpc.php$maxAge HTTP/1.0\r\n$req_headers\r\n$request"));
+
+ if ($proxy_host != '') {
+ $post_string = "POST http://".$server_host;
+ if ($proxy_port > '') {
+ $post_string .= ':'.$server_port;
+ }
+ } else {
+ $post_string = "POST ";
+ }
+
+ fwrite($fp, ($post_string."/xmlrpc.php$maxAge
HTTP/1.0\r\n$req_headers\r\n$request"));
$response = '';
$line1 = fgets($fp, 2048);
if (!preg_match('!^HTTP/[0-9\.]+ (\d+) (.*)!', $line1, $matches)) {