Mercurial > hg > mlmmj
changeset 110:6bbaadfb1c43
Make checkwait_smtpreply return the string that it gets from the mailserver
in case of error. That way we can check if the relayhost is bouncing local
addresses before accepting it.
author | mmj |
---|---|
date | Thu, 27 May 2004 09:29:09 +1000 |
parents | e4ae5f67cb9e |
children | f8e554e122a1 |
files | src/checkwait_smtpreply.c |
diffstat | 1 files changed, 23 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/checkwait_smtpreply.c Thu May 27 09:27:32 2004 +1000 +++ b/src/checkwait_smtpreply.c Thu May 27 09:29:09 2004 +1000 @@ -8,73 +8,81 @@ #include <stdio.h> #include <unistd.h> +#include <string.h> #include "checkwait_smtpreply.h" #include "config.h" #define USEC_WAIT 1 #define LOOP_WAIT 10000 -int checkwait_smtpreply(int sockfd, int replytype) +#define RFC_REPLY_SIZE 512 + +char *checkwait_smtpreply(int sockfd, int replytype) { size_t len = 0; - char smtpreply[READ_BUFSIZE]; + char smtpreply[RFC_REPLY_SIZE + 1]; int timer = 0; + smtpreply[RFC_REPLY_SIZE] = '\0'; + do { if(replytype != MLMMJ_QUIT && timer > 10) { usleep(USEC_WAIT); timer++; } - len += read(sockfd, (smtpreply+len), READ_BUFSIZE-len); + len += read(sockfd, (smtpreply+len), RFC_REPLY_SIZE - len); } while(smtpreply[len-1] != '\n' && timer < LOOP_WAIT); - smtpreply[len] = 0; + smtpreply[len] = '\0'; #if 0 printf("replytype = [%d], smtpreply = [%s]\n", replytype, smtpreply); #endif if(timer > LOOP_WAIT) { printf("Timed out in waiting for reply--will try later\n"); - return -1; + return (char *)-1; } - printf("%s", smtpreply); + fprintf(stderr, "%s", smtpreply); + /* This case might seem like (and is ATM) total overkill. But it's + * easy for us to extend it later on if needed. + */ switch(replytype) { case MLMMJ_CONNECT: if(smtpreply[0] != '2' || smtpreply[1] != '2') - return MLMMJ_CONNECT; + return strdup(smtpreply); break; case MLMMJ_HELO: if(smtpreply[0] != '2' || smtpreply[1] != '5') - return MLMMJ_HELO; + return strdup(smtpreply); break; case MLMMJ_FROM: if(smtpreply[0] != '2' || smtpreply[1] != '5') - return MLMMJ_FROM; + return strdup(smtpreply); break; case MLMMJ_RCPTTO: if(smtpreply[0] != '2' || smtpreply[1] != '5') - return MLMMJ_RCPTTO; + return strdup(smtpreply); break; case MLMMJ_DATA: if(smtpreply[0] != '3' || smtpreply[1] != '5') - return MLMMJ_DATA; + return strdup(smtpreply); break; case MLMMJ_DOT: if(smtpreply[0] != '2' || smtpreply[1] != '5') - return MLMMJ_DOT; + return strdup(smtpreply); break; case MLMMJ_QUIT: if(smtpreply[0] != '2' || smtpreply[1] != '2') - return MLMMJ_QUIT; + return (char *)0xDEADBEEF; break; case MLMMJ_RSET: if(smtpreply[0] != '2' || smtpreply[1] != '5') - return MLMMJ_RSET; + return (char *)0xDEADBEEF; break; default: break; } - return 0; + return NULL; }