]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/smtp/serv_smtpeventclient.c
work on errorhandling for the smtp event client
[citadel.git] / citadel / modules / smtp / serv_smtpeventclient.c
index 15a55e79960758b4237ccdbf1b209c9dc6fab30b..a523f9347f8da87ec204caff45a783479d3c4d33 100644 (file)
@@ -101,6 +101,7 @@ void DeleteSmtpOutMsg(void *v)
                Msg->HostLookup.DNSReplyFree(Msg->HostLookup.VParsedDNSReply);
        FreeStrBuf(&Msg->msgtext);
        FreeAsyncIOContents(&Msg->IO);
+       memset (Msg, 0, sizeof(SmtpOutMsg)); /* just to be shure... */
        free(Msg);
 }
 
@@ -158,6 +159,8 @@ void FinalizeMessageSend(SmtpOutMsg *Msg)
 
                RemoveQItem(Msg->MyQItem);
        }
+
+       RemoveContext(Msg->IO.CitContext);
        DeleteSmtpOutMsg(Msg);
 }
 
@@ -168,8 +171,11 @@ eNextState FailOneAttempt(AsyncIO *IO)
         * possible ways here: 
         * - connection timeout 
         * - 
-        */     
-       SendMsg->pCurrRelay = SendMsg->pCurrRelay->Next;
+        */
+       StopClientWatchers(IO);
+
+       if (SendMsg->pCurrRelay != NULL)
+               SendMsg->pCurrRelay = SendMsg->pCurrRelay->Next;
 
        if (SendMsg->pCurrRelay == NULL)
                return eAbort;
@@ -204,7 +210,7 @@ void SetConnectStatus(AsyncIO *IO)
                  sizeof(buf));
 
        if (SendMsg->mx_host == NULL)
-               SendMsg->mx_host = "<no name>";
+               SendMsg->mx_host = "<no MX-Record>";
 
        CtdlLogPrintf(CTDL_DEBUG, 
                      "SMTP client[%ld]: connecting to %s [%s]:%d ...\n", 
@@ -219,6 +225,7 @@ void SetConnectStatus(AsyncIO *IO)
                     SendMsg->mx_host,
                     buf,
                     SendMsg->IO.ConnectMe->Port);
+       SendMsg->IO.NextState = eConnect;
 }
 
 /*****************************************************************************
@@ -272,6 +279,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO)
                        addr->sin_port   = htons(DefaultMXPort);
                        
                }
+               SendMsg->mx_host = SendMsg->pCurrRelay->Host;
                return mx_connect_ip(IO);
        }
        else // TODO: here we need to find out whether there are more mx'es, backup relay, and so on
@@ -293,8 +301,9 @@ eNextState get_one_mx_host_ip(AsyncIO *IO)
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
 
        CtdlLogPrintf(CTDL_DEBUG, 
-                     "SMTP client[%ld]: looking up %s : %d ...\n", 
+                     "SMTP client[%ld]: looking up %s-Record %s : %d ...\n", 
                      SendMsg->n, 
+                     (SendMsg->pCurrRelay->IPv6)? "aaaa": "a",
                      SendMsg->pCurrRelay->Host, 
                      SendMsg->pCurrRelay->Port);
 
@@ -307,8 +316,10 @@ eNextState get_one_mx_host_ip(AsyncIO *IO)
                SendMsg->MyQEntry->Status = 5;
                StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
                             "No MX hosts found for <%s>", SendMsg->node);
+               SendMsg->IO.NextState = eTerminateConnection;
                return IO->NextState;
        }
+       IO->NextState = eReadDNSReply;
        return IO->NextState;
 }
 
@@ -393,7 +404,8 @@ eNextState resolve_mx_records(AsyncIO *IO)
                             "No MX hosts found for <%s>", SendMsg->node);
                return IO->NextState;
        }
-       return eAbort;
+       SendMsg->IO.NextState = eReadDNSReply;
+       return IO->NextState;
 }
 
 
@@ -450,9 +462,10 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
        else             SendMsg->msgtext = NewStrBufDup(MsgText);
        
        if (smtp_resolve_recipients(SendMsg)) {
-
-               
-
+               CitContext *SubC;
+               SubC = CloneContext (CC);
+               SubC->session_specific_data = (char*) SendMsg;
+               SendMsg->IO.CitContext = SubC;
 
                if (SendMsg->pCurrRelay == NULL)
                        QueueEventContext(&SendMsg->IO,
@@ -491,8 +504,10 @@ void smtp_try_one_queue_entry(OneQueItem *MyQItem,
 
 void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *pMsg)
 {
+       double Timeout = 0.0;
+
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
-       double Timeout;
+
        switch (NextTCPState) {
        case eSendReply:
        case eSendMore:
@@ -512,6 +527,9 @@ void SMTPSetTimeout(eNextState NextTCPState, SmtpOutMsg *pMsg)
                        Timeout += StrLength(pMsg->msgtext) / 1024;
                }
                break;
+       case eSendDNSQuery:
+       case eReadDNSReply:
+       case eConnect:
        case eTerminateConnection:
        case eAbort:
                return;