libev migration / c-ares migration
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 23 Jan 2011 22:10:51 +0000 (23:10 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 23 Jan 2011 22:10:51 +0000 (23:10 +0100)
  - free c-ares structs and its watchers in appropriate places
  - finalize relaying

citadel/event_client.c
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c

index 4dca578f7232122e63c0ab301d7cd5b6e1cfc5c8..60f74282df813cee217614d2ba6af44c1b8e4403 100644 (file)
@@ -119,7 +119,6 @@ void FreeAsyncIOContents(AsyncIO *IO)
        FreeStrBuf(&IO->IOBuf);
        FreeStrBuf(&IO->SendBuf.Buf);
        FreeStrBuf(&IO->RecvBuf.Buf);
-       ares_destroy(IO->DNSChannel);
 }
 
 
@@ -137,6 +136,12 @@ void ShutDownCLient(AsyncIO *IO)
                IO->SendBuf.fd = 0;
                IO->RecvBuf.fd = 0;
        }
+       if (IO->DNSChannel != NULL) {
+               ares_destroy(IO->DNSChannel);
+               ev_io_stop(event_base, &IO->dns_recv_event);
+               ev_io_stop(event_base, &IO->dns_send_event);
+               IO->DNSChannel = NULL;
+       }
        assert(IO->Terminate);
        IO->Terminate(IO);
        
@@ -430,7 +435,5 @@ eNextState InitEventIO(AsyncIO *IO,
        else {
                IO->NextState = eSendReply;
        }
-       IO->IP6 = IO->HEnt->h_addrtype == AF_INET6;
-//     IO->res = HEnt->h_addr_list[0];
        return event_connect_socket(IO, conn_timeout, first_rw_timeout);
 }
index 591d5d59d03f4b2229f3e6b5eaf9bf0f2d46de12..e09080200425d99808625e57f31546cd00961a57 100644 (file)
@@ -268,39 +268,16 @@ void SetConnectStatus(AsyncIO *IO)
                src = &IO->Addr.sin6_addr;
        }
        else {
-               unsigned long psaddr;
                struct sockaddr_in *addr = (struct sockaddr_in *)&IO->Addr;
 
                src = &addr->sin_addr.s_addr;
-               memcpy(&psaddr, &addr->sin_addr.s_addr, sizeof(psaddr));
-///            psaddr = ntohl(psaddr); 
-/*
-               CtdlLogPrintf(CTDL_DEBUG, 
-                             "SMTP client[%ld]: connecting to %s [%ld.%ld.%ld.%ld:%d] ...\n", 
-                             SendMsg->n, 
-                             SendMsg->mx_host, 
-                             (psaddr >> 24) & 0xFF,
-                             (psaddr >> 16) & 0xFF,
-                             (psaddr >>  8) & 0xFF,
-                             (psaddr >>  0) & 0xFF,
-                             SendMsg->IO.dport);
-
-               SendMsg->MyQEntry->Status = 5; 
-               StrBufPrintf(SendMsg->MyQEntry->StatusMessage, 
-                            "Timeout while connecting %s [%ld.%ld.%ld.%ld:%d] ", 
-                            SendMsg->mx_host,
-                            (psaddr >> 24) & 0xFF,
-                            (psaddr >> 16) & 0xFF,
-                            (psaddr >>  8) & 0xFF,
-                            (psaddr >>  0) & 0xFF,
-                            SendMsg->IO.dport);
-
-*/
        }
 
        inet_ntop((IO->IP6)?AF_INET6:AF_INET,
                  src,
                  buf, sizeof(buf));
+       if (SendMsg->mx_host == NULL)
+               SendMsg->mx_host = "<no name>";
 
        CtdlLogPrintf(CTDL_DEBUG, 
                      "SMTP client[%ld]: connecting to %s [%s]:%d ...\n", 
@@ -397,7 +374,7 @@ void get_one_mx_host_ip_done(void *Ctx,
                                   SMTP_C_ReadTimeouts[0],
                                   1);
        }
-       if (State == eAbort)
+       if ((State == eAbort) && (IO->sock != -1))
                SMTP_C_Terminate(IO);
 }
 
@@ -415,7 +392,11 @@ eNextState get_one_mx_host_ip(AsyncIO *IO)
                SendMsg->CurrMX = SendMsg->CurrMX->next;
        }
 
-       if (SendMsg->pCurrRelay != NULL) Hostname = SendMsg->pCurrRelay->Host;
+       if (SendMsg->pCurrRelay != NULL) {
+               SendMsg->mx_host = Hostname = SendMsg->pCurrRelay->Host;
+               if (SendMsg->pCurrRelay->Port != 0)
+                       SendMsg->IO.dport = SendMsg->pCurrRelay->Port;
+       }
                else if (SendMsg->mx_host != NULL) Hostname = SendMsg->mx_host;
        else Hostname = SendMsg->node;
 
@@ -442,9 +423,6 @@ eNextState smtp_resolve_mx_done(AsyncIO *IO)
 
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
 
-       SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
-       SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
-       SendMsg->IO.IOBuf = NewStrBuf();
        SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
 
        SendMsg->CurrMX = SendMsg->AllMX = IO->VParsedDNSReply;
@@ -583,6 +561,9 @@ void smtp_try(OneQueItem *MyQItem,
        SendMsg->IO.LineReader  = SMTP_C_ReadServerStatus;
        SendMsg->IO.ConnFail    = SMTP_C_ConnFail;
        SendMsg->IO.Timeout     = SMTP_C_Timeout;
+       SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
+       SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
+       SendMsg->IO.IOBuf       = NewStrBuf();
 
        if (KeepMsgText) {
                SendMsg->msgtext    = MsgText;
index 273cc6fb46dfa3b7ce5b1fa5b5524229d2f79066..26c7e555dd47a7f141aae25da3fffb1ab236f4c4 100644 (file)
@@ -138,7 +138,12 @@ void RemoveQItem(OneQueItem *MyQItem)
        DeleteHashPos(&It);
 }
 
-
+void FreeURL(ParsedURL** Url)
+{
+       FreeStrBuf(&(*Url)->URL);
+       free(*Url);
+       *Url = NULL;
+}
 
 void FreeMailQEntry(void *qv)
 {
@@ -152,6 +157,7 @@ void FreeQueItem(OneQueItem **Item)
        DeleteHash(&(*Item)->MailQEntries);
        FreeStrBuf(&(*Item)->EnvelopeFrom);
        FreeStrBuf(&(*Item)->BounceTo);
+       FreeURL(&(*Item)->URL);
        free(*Item);
        Item = NULL;
 }
@@ -613,7 +619,7 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, short DefaultPort)
                }
        }
        if (url->LocalPart == NULL) {
-               url->LocalPart = pch + StrLength(UrlStr);
+               url->LocalPart = pch + StrLength(url->URL);
        }
 
        pCredEnd = strchr(pch, '@');
@@ -630,8 +636,8 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, short DefaultPort)
                else {
                        url->Pass = pUserEnd + 1;
                }
-               StrBufPeek(UrlStr, pUserEnd, 0, '\0');
-               StrBufPeek(UrlStr, pCredEnd, 0, '\0');          
+               StrBufPeek(url->URL, pUserEnd, 0, '\0');
+               StrBufPeek(url->URL, pCredEnd, 0, '\0');                
        }
        
        pPort = NULL;
@@ -642,18 +648,23 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, short DefaultPort)
                        free(url);
                        return 0; /* invalid syntax, no ipv6 */
                }
-               if (*(pEndHost + 1) == ':')
+               if (*(pEndHost + 1) == ':'){
+                       StrBufPeek(url->URL, pEndHost + 1, 0, '\0');
                        pPort = pEndHost + 2;
+               }
                url->af = AF_INET6;
        }
        else {
                pPort = strchr(url->Host, ':');
-               if (pPort != NULL)
+               if (pPort != NULL) {
+                       StrBufPeek(url->URL, pPort, 0, '\0');
                        pPort ++;
+               }
        }
        if (pPort != NULL)
                url->Port = atol(pPort);
-       url->IsIP = inet_pton(url->af, url->Host, &url->Addr);  
+       url->IsIP = inet_pton(url->af, url->Host, &url->Addr);
+       *Url = url;
        return 1;
 }
 /*
@@ -749,7 +760,7 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
 
        {
                char mxbuf[SIZ];
-               ParsedURL **Url = &RelayUrls; ///&MyQItem->Relay;
+               ParsedURL **Url = &MyQItem->URL;
                nRelays = get_hosts(mxbuf, "smarthost");
                if (nRelays > 0) {
                        StrBuf *All;
@@ -758,13 +769,15 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                        All = NewStrBufPlain(mxbuf, -1);
                        One = NewStrBufPlain(NULL, StrLength(All) + 1);
                        
-                       while (Pos != StrBufNOTNULL) {
+                       while ((Pos != StrBufNOTNULL) && ((Pos == NULL) || !IsEmptyStr(Pos))) {
                                StrBufExtract_NextToken(One, All, &Pos, '|');
                                if (!ParseURL(Url, One, 25))
                                        CtdlLogPrintf(CTDL_DEBUG, "Failed to parse: %s\n", ChrPtr(One));
                                else 
                                        Url = &(*Url)->Next;
                        }
+                       FreeStrBuf(&All);
+                       FreeStrBuf(&One);
                }
        }