Fixes for NNTP. Was not returning results. Also, cleanups and now meets coding standards.

This commit is contained in:
skeeter 2001-03-30 00:58:38 +00:00
parent e274ab6a23
commit 2026b25976

View File

@ -43,7 +43,8 @@ class network
function add_crlf($str) function add_crlf($str)
{ {
if($this->addcrlf) { if($this->addcrlf)
{
$str .= "\r\n"; $str .= "\r\n";
} }
return $str; return $str;
@ -51,10 +52,10 @@ class network
function set_error($code,$msg,$desc) function set_error($code,$msg,$desc)
{ {
$this->error = array("code","msg","desc"); $this->error = array('code','msg','desc');
$this->error["code"] = $code; $this->error['code'] = $code;
$this->error["msg"] = $msg; $this->error['msg'] = $msg;
$this->error["desc"] = $desc; $this->error['desc'] = $desc;
// $this->close_port(); // $this->close_port();
$this->errorset = 1; $this->errorset = 1;
return 0; return 0;
@ -64,23 +65,32 @@ class network
{ {
global $phpgw_info; global $phpgw_info;
switch($port) { switch($port)
{
case 80: case 80:
case 443: case 443:
if((isset($phpgw_info["server"]["httpproxy_server"]) && $phpgw_info["server"]["httpproxy_server"]) && if((isset($phpgw_info['server']['httpproxy_server']) && $phpgw_info['server']['httpproxy_server']) &&
(isset($phpgw_info["server"]["httpproxy_port"]) && $phpgw_info["server"]["httpproxy_port"])) { (isset($phpgw_info['server']['httpproxy_port']) && $phpgw_info['server']['httpproxy_port']))
$server = $phpgw_info["server"]["httpproxy_server"]; {
$port = (int)$phpgw_info["server"]["httpproxy_port"]; $server = $phpgw_info['server']['httpproxy_server'];
$port = (int)$phpgw_info['server']['httpproxy_port'];
} }
break; break;
} }
if(floor(phpversion()) == 4) if(floor(phpversion()) == 4)
{
$this->socket = fsockopen($server,$port,&$errcode,&$errmsg,$timeout); $this->socket = fsockopen($server,$port,&$errcode,&$errmsg,$timeout);
}
else else
{
$this->socket = fsockopen($server,$port,&$errcode,&$errmsg); $this->socket = fsockopen($server,$port,&$errcode,&$errmsg);
if (!$this->socket) { }
return $this->set_error("Error","$errcode:$errmsg","Connection to $server:$port failed - could not open socket."); if (!$this->socket)
} else { {
return $this->set_error('Error',$errcode.':'.$errmsg,'Connection to '.$server.':'.$port.' failed - could not open socket.');
}
else
{
return 1; return 1;
} }
} }
@ -105,8 +115,10 @@ class network
$ok = fputs($this->socket,$this->add_crlf($str)); $ok = fputs($this->socket,$this->add_crlf($str));
if (!$ok) if (!$ok)
{ {
return $this->set_error("Error","Connection Lost","lost connection to server"); return $this->set_error('Error','Connection Lost','lost connection to server');
} else { }
else
{
return 1; return 1;
} }
} }
@ -114,46 +126,55 @@ class network
function bs_write_port($str,$bytes=0) function bs_write_port($str,$bytes=0)
{ {
if ($bytes) if ($bytes)
{
$ok = fwrite($this->socket,$this->add_crlf($str),$bytes); $ok = fwrite($this->socket,$this->add_crlf($str),$bytes);
}
else else
{
$ok = fwrite($this->socket,$this->add_crlf($str)); $ok = fwrite($this->socket,$this->add_crlf($str));
}
if (!$ok) if (!$ok)
{ {
return $this->set_error("Error","Connection Lost","lost connection to server"); return $this->set_error('Error','Connection Lost','lost connection to server');
} else { }
else
{
return 1; return 1;
} }
} }
function msg2socket($str,$expected_response,$response) function msg2socket($str,$expected_response,&$response)
{ {
if(!$this->socket && substr($expected_response,1,1) == "+") { if(!$this->socket && substr($expected_response,1,1) == '+')
return $this->set_error("521", {
"socket does not exist", return $this->set_error('521','socket does not exist',
"The required socket does not exist. The settings for your mail server may be wrong."); 'The required socked does not exist. The settings for your mail server may be wrong.');
} }
if (!$this->write_port($str)) { if (!$this->write_port($str))
if(substr($expected_response,1,1) == "+") { {
return $this->set_error("420", if(substr($expected_response,1,1) == '+')
"lost connection", {
"Lost connection to pop server."); return $this->set_error('420','lost connection','Lost connection to pop server.');
} else { }
else
{
return 0; return 0;
} }
} }
$response = $this->read_port(); $response = $this->read_port();
if (!ereg(strtoupper($expected_response),strtoupper($response))) { if (!ereg(strtoupper($expected_response),strtoupper($response)))
if(substr($expected_response,1,1) == "+") { {
return $this->set_error("550", if(substr($expected_response,1,1) == '+')
"", {
""); return $this->set_error('550','','');
} }
$pos = strpos(" ",$response); $pos = strpos(' ',$response);
return $this->set_error(substr($response,0,$pos), return $this->set_error(substr($response,0,$pos),
"invalid response($expected_response)", 'invalid response('.$expected_response.')',
substr($response,($pos + 1),(strlen($response)-$pos))); substr($response,($pos + 1),(strlen($response)-$pos)));
} else { }
else
{
return 1; return 1;
} }
} }
@ -163,17 +184,22 @@ class network
{ {
global $phpgw_info; global $phpgw_info;
$server = str_replace("http://","",$file); $server = str_replace('http://','',$file);
$file = strstr($server,"/"); $file = strstr($server,'/');
$server = str_replace("$file","",$server); $server = str_replace($file,'',$server);
if ($phpgw_info["server"]["httpproxy_server"]) { if ($phpgw_info['server']['httpproxy_server'])
if ($this->open_port($server,80, 15)) { {
if (! $this->write_port("GET http://" . $server . $file . " HTTP/1.0\n\n")) { if ($this->open_port($server,80, 15))
{
if (! $this->write_port('GET http://' . $server . $file . ' HTTP/1.0'."\n\n"))
{
return False; return False;
} }
$i = 0; $i = 0;
while ($line = $this->read_port()) { while ($line = $this->read_port())
if (feof($this->socket)) { {
if (feof($this->socket))
{
break; break;
} }
$lines[] = $line; $lines[] = $line;
@ -181,20 +207,29 @@ class network
} }
$this->close_port(); $this->close_port();
return $lines; return $lines;
} else { }
else
{
return False; return False;
} }
} else { }
if ($this->open_port($server, 80, 15)) { else
if (!$this->write_port("GET $file HTTP/1.0\nHost: $server\n\n")) { {
if ($this->open_port($server, 80, 15))
{
if (!$this->write_port('GET '.$file.' HTTP/1.0'."\n".'Host: '.$server."\n\n"))
{
return 0; return 0;
} }
while ($line = $this->read_port()) { while ($line = $this->read_port())
{
$lines[] = $line; $lines[] = $line;
} }
$this->close_port(); $this->close_port();
return $lines; return $lines;
} else { }
else
{
return 0; return 0;
} }
} }