From 98fe34becae383607a4cec2a7dac2b3c0c64adcd Mon Sep 17 00:00:00 2001 From: David Hedbor <david@hedbor.org> Date: Tue, 26 May 1998 22:47:43 -0700 Subject: [PATCH] - 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 --- lib/modules/Protocols.pmod/Ident.pmod | 17 +++++++++++------ lib/modules/Protocols.pmod/NNTP.pmod | 5 +++-- lib/modules/Protocols.pmod/SMTP.pmod | 7 +++++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/modules/Protocols.pmod/Ident.pmod b/lib/modules/Protocols.pmod/Ident.pmod index 9c48a1e0ec..556f1b72f8 100644 --- a/lib/modules/Protocols.pmod/Ident.pmod +++ b/lib/modules/Protocols.pmod/Ident.pmod @@ -1,6 +1,6 @@ // 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) @@ -9,6 +9,7 @@ int|array (string) lookup(object fd) mixed laddr; // Local Address. array err; object remote_fd; + int i; if(!fd) return 0; err = catch(raddr = fd->query_address()); @@ -23,21 +24,25 @@ int|array (string) lookup(object fd) laddr = laddr / " "; raddr = raddr / " "; - remote_fd = Stdio.File(); + remote_fd = Stdio.FILE(); if(!remote_fd->open_socket(0, laddr[0])) { destruct(remote_fd); throw(backtrace() +({ "Protocols.Ident: open_socket() failed."})); } + if(err = catch(remote_fd->connect(raddr[0], 113))) { destruct(remote_fd); 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); - 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)) { destruct(remote_fd); @@ -46,7 +51,7 @@ int|array (string) lookup(object fd) remote_fd->close(); destruct(remote_fd); response -= " "; - response -= "\r\n"; + response -= "\r"; response /= ":"; if(sizeof(response) < 2) return ({ "ERROR", "UNKNOWN-ERROR" }); diff --git a/lib/modules/Protocols.pmod/NNTP.pmod b/lib/modules/Protocols.pmod/NNTP.pmod index 0d17910ee3..f032fc5712 100644 --- a/lib/modules/Protocols.pmod/NNTP.pmod +++ b/lib/modules/Protocols.pmod/NNTP.pmod @@ -21,7 +21,8 @@ class protocol string *read_body_lines() { string *ret=({}); - while(string s=news::gets()) + string s; + while(s = news::gets()) { if(s=="." || s==".\r") return ret; sscanf(s,".%s",s); @@ -53,7 +54,7 @@ class protocol int command(string cmd) { - news::write(cmd+"\n"); + news::write(cmd+"\r\n"); return readreturncode(); } diff --git a/lib/modules/Protocols.pmod/SMTP.pmod b/lib/modules/Protocols.pmod/SMTP.pmod index 6550788856..b1d89bdafe 100644 --- a/lib/modules/Protocols.pmod/SMTP.pmod +++ b/lib/modules/Protocols.pmod/SMTP.pmod @@ -50,7 +50,7 @@ class client return r; } - void create(void|string server) + void create(void|string server, int|void port) { if(!server) { @@ -59,7 +59,10 @@ class client 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()})); } -- GitLab