// {{{ getCache()
-
+
function getCache($args)
{
$id = md5(serialize($args));
if (!file_exists($filename)) {
return null;
};
-
+
$fp = fopen($filename, "rb");
if ($fp === null) {
return null;
}
// }}}
-
+
// {{{ saveCache()
function saveCache($args, $data)
System::mkdir('-p '.$cachedir);
}
$filename = $cachedir.'/xmlrpc_cache_'.$id;
-
+
$fp = @fopen($filename, "wb");
if ($fp !== null) {
fwrite($fp, serialize($data));
}
// }}}
-
+
// {{{ 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)) {
$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);
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);
} 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)) {