Skip to content
Snippets Groups Projects
Commit 98fe34be authored by David Hedbor's avatar David Hedbor
Browse files

- Ident.pmod now uses Stdio.FILE->gets() instead of

  Stdio.File->read(), since the latter sometimes didn't work (blocked
  Stdio.File->indefinitely).
- NNTP.pmod now sends commands ending with \r\n instead of just \n.
- Added second argument, port, to SMTP.client.create to allow usage of
  non-standard ports.

Rev: lib/modules/Protocols.pmod/Ident.pmod:1.4
Rev: lib/modules/Protocols.pmod/NNTP.pmod:1.5
Rev: lib/modules/Protocols.pmod/SMTP.pmod:1.6
parent 0d64d2f2
No related branches found
No related tags found
No related merge requests found
// An implementation of the IDENT protocol, specified in RFC 931. // An implementation of the IDENT protocol, specified in RFC 931.
// //
// $Id: Ident.pmod,v 1.3 1998/04/08 17:25:12 neotron Exp $ // $Id: Ident.pmod,v 1.4 1998/05/27 05:47:41 neotron Exp $
int|array (string) lookup(object fd) int|array (string) lookup(object fd)
...@@ -9,6 +9,7 @@ int|array (string) lookup(object fd) ...@@ -9,6 +9,7 @@ int|array (string) lookup(object fd)
mixed laddr; // Local Address. mixed laddr; // Local Address.
array err; array err;
object remote_fd; object remote_fd;
int i;
if(!fd) if(!fd)
return 0; return 0;
err = catch(raddr = fd->query_address()); err = catch(raddr = fd->query_address());
...@@ -23,21 +24,25 @@ int|array (string) lookup(object fd) ...@@ -23,21 +24,25 @@ int|array (string) lookup(object fd)
laddr = laddr / " "; laddr = laddr / " ";
raddr = raddr / " "; raddr = raddr / " ";
remote_fd = Stdio.File(); remote_fd = Stdio.FILE();
if(!remote_fd->open_socket(0, laddr[0])) { if(!remote_fd->open_socket(0, laddr[0])) {
destruct(remote_fd); destruct(remote_fd);
throw(backtrace() +({ "Protocols.Ident: open_socket() failed."})); throw(backtrace() +({ "Protocols.Ident: open_socket() failed."}));
} }
if(err = catch(remote_fd->connect(raddr[0], 113))) if(err = catch(remote_fd->connect(raddr[0], 113)))
{ {
destruct(remote_fd); destruct(remote_fd);
throw(err); throw(err);
} }
if(remote_fd->write(raddr[1]+","+laddr[1]+"\r\n") == -1) { remote_fd->set_blocking();
string query = raddr[1]+","+laddr[1]+"\r\n";
int written;
if((written = remote_fd->write(query)) != strlen(query)) {
destruct(remote_fd); destruct(remote_fd);
throw(backtrace() +({ "Protocols.Ident: write failed."})); throw(backtrace() +({ "Protocols.Ident: short write ("+written+")."}));
} }
mixed response = remote_fd->read(); mixed response = remote_fd->gets();//0xefffffff, 1);
if(!response || !strlen(response)) if(!response || !strlen(response))
{ {
destruct(remote_fd); destruct(remote_fd);
...@@ -46,7 +51,7 @@ int|array (string) lookup(object fd) ...@@ -46,7 +51,7 @@ int|array (string) lookup(object fd)
remote_fd->close(); remote_fd->close();
destruct(remote_fd); destruct(remote_fd);
response -= " "; response -= " ";
response -= "\r\n"; response -= "\r";
response /= ":"; response /= ":";
if(sizeof(response) < 2) if(sizeof(response) < 2)
return ({ "ERROR", "UNKNOWN-ERROR" }); return ({ "ERROR", "UNKNOWN-ERROR" });
......
...@@ -21,7 +21,8 @@ class protocol ...@@ -21,7 +21,8 @@ class protocol
string *read_body_lines() string *read_body_lines()
{ {
string *ret=({}); string *ret=({});
while(string s=news::gets()) string s;
while(s = news::gets())
{ {
if(s=="." || s==".\r") return ret; if(s=="." || s==".\r") return ret;
sscanf(s,".%s",s); sscanf(s,".%s",s);
...@@ -53,7 +54,7 @@ class protocol ...@@ -53,7 +54,7 @@ class protocol
int command(string cmd) int command(string cmd)
{ {
news::write(cmd+"\n"); news::write(cmd+"\r\n");
return readreturncode(); return readreturncode();
} }
......
...@@ -50,7 +50,7 @@ class client ...@@ -50,7 +50,7 @@ class client
return r; return r;
} }
void create(void|string server) void create(void|string server, int|void port)
{ {
if(!server) if(!server)
{ {
...@@ -59,7 +59,10 @@ class client ...@@ -59,7 +59,10 @@ class client
server=dns->get_primary_mx(gethostname()); server=dns->get_primary_mx(gethostname());
} }
if(!connect(server,25)) if(!port)
port = 25;
if(!connect(server, port))
{ {
throw(({"Failed to connect to mail server.\n",backtrace()})); throw(({"Failed to connect to mail server.\n",backtrace()}));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment