diff options
author | Eric S. Raymond <esr@thyrsus.com> | 1996-12-17 20:53:10 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 1996-12-17 20:53:10 +0000 |
commit | b85d71b67a2743272f46c85bf479b1051171193d (patch) | |
tree | f828606268e283fa4d36ec6fb91ffc5fb19d9402 | |
parent | f034d4af6612be9fc2b393855ec5ac95d548d5d8 (diff) | |
download | fetchmail-b85d71b67a2743272f46c85bf479b1051171193d.tar.gz fetchmail-b85d71b67a2743272f46c85bf479b1051171193d.tar.bz2 fetchmail-b85d71b67a2743272f46c85bf479b1051171193d.zip |
SockGets is gone.
svn path=/trunk/; revision=650
-rw-r--r-- | driver.c | 24 | ||||
-rw-r--r-- | imap.c | 8 | ||||
-rw-r--r-- | pop2.c | 2 | ||||
-rw-r--r-- | pop3.c | 6 | ||||
-rw-r--r-- | smtp.c | 7 | ||||
-rw-r--r-- | socket.c | 23 | ||||
-rw-r--r-- | socket.h | 15 |
7 files changed, 38 insertions, 47 deletions
@@ -276,7 +276,7 @@ static FILE *smtp_open(struct query *ctl) /* if no socket to this host is already set up, try to open one */ if (ctl->smtp_sockfp == (FILE *)NULL) { - if ((ctl->smtp_sockfp = Socket(ctl->smtphost, SMTP_PORT)) == (FILE *)NULL) + if ((ctl->smtp_sockfp = sockopen(ctl->smtphost, SMTP_PORT)) == (FILE *)NULL) return((FILE *)NULL); else if (SMTP_ok(ctl->smtp_sockfp) != SM_OK || SMTP_helo(ctl->smtp_sockfp, ctl->servernames->id) != SM_OK) @@ -289,6 +289,26 @@ static FILE *smtp_open(struct query *ctl) return(ctl->smtp_sockfp); } +static int SockGets(char *buf, int len, FILE *sockfp) +/* get a LF-terminated line, removing \r characters */ +{ + int rdlen = 0; + + while (--len) + { + if ((*buf = fgetc(sockfp)) == EOF) + return -1; + else + rdlen++; + if (*buf == '\n') + break; + if (*buf != '\r') /* remove all CRs */ + buf++; + } + *buf = 0; + return rdlen; +} + static int gen_readmsg (sockfp, len, delimited, ctl) /* read message content and ship to SMTP or MDA */ FILE *sockfp; /* to which the server is connected */ @@ -861,7 +881,7 @@ const struct method *proto; /* protocol method table */ FILE *sockfp; /* open a socket to the mail server */ - if ((sockfp = Socket(ctl->servernames->id, + if ((sockfp = sockopen(ctl->servernames->id, ctl->port ? ctl->port : protocol->port)) == NULL) { error(0, errno, "connecting to host"); @@ -25,7 +25,7 @@ int imap_ok (FILE *sockfp, char *argbuf) seen = 0; do { - if (SockGets(buf, sizeof(buf), sockfp) < 0) + if (!fgets(buf, sizeof(buf), sockfp)) return(PS_SOCKET); if (outlevel == O_VERBOSE) @@ -118,7 +118,7 @@ static int imap_getsizes(FILE *sockfp, int count, int *sizes) char buf [POPBUFSIZE+1]; gen_send(sockfp, "FETCH 1:%d RFC822.SIZE", count); - while (SockGets(buf, sizeof(buf), sockfp) >= 0) + while (fgets(buf, sizeof(buf), sockfp)) { int num, size; @@ -165,7 +165,7 @@ static int imap_fetch(FILE *sockfp, int number, int *lenp) /* looking for FETCH response */ do { - if (SockGets(buf, sizeof(buf), sockfp) < 0) + if (!fgets(buf, sizeof(buf), sockfp)) return(PS_SOCKET); } while (sscanf(buf+2, "%d FETCH (RFC822 {%d}", &num, lenp) != 2); @@ -181,7 +181,7 @@ static int imap_trail(FILE *sockfp, struct query *ctl, int number) { char buf [POPBUFSIZE+1]; - if (SockGets(buf, sizeof(buf), sockfp) < 0) + if (!fgets(buf, sizeof(buf), sockfp)) return(PS_SOCKET); else return(0); @@ -23,7 +23,7 @@ int pop2_ok (FILE *sockfp, char *argbuf) char buf [POPBUFSIZE+1]; pound_arg = equal_arg = -1; - if (SockGets(buf, sizeof(buf), sockfp) >= 0) { + if (fgets(buf, sizeof(buf), sockfp)) { if (outlevel == O_VERBOSE) error(0, 0, "POP2< %s", buf); @@ -30,7 +30,7 @@ int pop3_ok (FILE *sockfp, char *argbuf) char buf [POPBUFSIZE+1]; char *bufp; - if (SockGets(buf, sizeof(buf), sockfp) >= 0) { + if (fgets(buf, sizeof(buf), sockfp)) { if (outlevel == O_VERBOSE) error(0, 0, "POP3< %s", buf); @@ -165,7 +165,7 @@ static int pop3_getrange(FILE *sockfp, struct query *ctl, int*countp, int*newp) int num; *newp = 0; - while (SockGets(buf, sizeof(buf), sockfp) >= 0) + while (fgets(buf, sizeof(buf), sockfp)) { if (outlevel == O_VERBOSE) error(0, 0, "POP3< %s", buf); @@ -196,7 +196,7 @@ static int pop3_getsizes(FILE *sockfp, int count, int *sizes) { char buf [POPBUFSIZE+1]; - while (SockGets(buf, sizeof(buf), sockfp) >= 0) + while (fgets(buf, sizeof(buf), sockfp)) { int num, size; @@ -95,11 +95,12 @@ int SMTP_eom(FILE *sockfp) int SMTP_ok(FILE *sockfp) /* returns status of SMTP connection */ { - int n; - char buf[SMTPBUFSIZE]; + char buf[SMTPBUFSIZE], *ip; - while ((n = SockGets(buf, sizeof(buf)-1, sockfp)) > 0) + while ((ip = fgets(buf, sizeof(buf)-1, sockfp))) { + int n = strlen(ip); + if (n < 4) return SM_ERROR; buf[n] = '\0'; @@ -44,9 +44,10 @@ * * #define INTERNAL_BUFSIZE 2048 * + * Note that stdio's 1024-byte default is just fine. */ -FILE *Socket(char *host, int clientPort) +FILE *sockopen(char *host, int clientPort) { int sock; unsigned long inaddr; @@ -79,24 +80,4 @@ FILE *Socket(char *host, int clientPort) return fdopen(sock, "r+"); } - -int SockGets(char *buf, int len, FILE *sockfp) -{ - int rdlen = 0; - - while (--len) - { - if ((*buf = fgetc(sockfp)) == EOF) - return -1; - else - rdlen++; - if (*buf == '\n') - break; - if (*buf != '\r') /* remove all CRs */ - buf++; - } - *buf = 0; - return rdlen; -} - /* socket.c ends here */ @@ -7,18 +7,7 @@ #ifndef SOCKET__ #define SOCKET__ -/* -Create a new client socket -returns (FILE *)NULL on error -*/ -FILE *Socket(char *host, int clientPort); - -/* -Get a string terminated by an '\n', delete any '\r' and the '\n'. -Pass it a valid socket, a buffer for the string, and -the length of the buffer (including the trailing \0) -returns 0 for success. -*/ -int SockGets(char *buf, int len, FILE *sockfp); +/* Create a new client socket; returns (FILE *)NULL on error */ +FILE *sockopen(char *host, int clientPort); #endif /* SOCKET__ */ |