]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
Make checkwait_smtpreply return the string that it gets from the mailserver
authormmj <none@none>
Wed, 26 May 2004 23:29:09 +0000 (09:29 +1000)
committermmj <none@none>
Wed, 26 May 2004 23:29:09 +0000 (09:29 +1000)
in case of error. That way we can check if the relayhost is bouncing local
addresses before accepting it.

src/checkwait_smtpreply.c

index cc3532c476d3cacab9fd13290530de7474e5d2c1..2d955f5f5926ed4e7899cc7d0b195c08d3a4383f 100644 (file)
@@ -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;
 }