Switch handling to have a pointer to the target address
authorWilfried Goesgens <dothebart@citadel.org>
Fri, 1 Apr 2011 19:56:20 +0000 (21:56 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Fri, 1 Apr 2011 19:56:20 +0000 (21:56 +0200)
 - change URL struct to contain sockaddr_in6
 - change URL-Parsing to add that indirection
 - change all pointer indirections so the new way fits

citadel/event_client.c
citadel/event_client.h
citadel/modules/smtp/serv_smtpeventclient.c
citadel/modules/smtp/serv_smtpqueue.c
libcitadel/lib/libcitadel.h
libcitadel/lib/urlhandling.c

index 4a20ba1ba317b935bf5a0173121a47e99b98be76..dd0fa7c976bf9fbe2fd0f77a277dff8c1297b20f 100644 (file)
@@ -396,9 +396,9 @@ eNextState event_connect_socket(AsyncIO *IO, double conn_timeout, double first_r
        IO->rw_timeout.data = IO;
 
        if (IO->IP6)
-               rc = connect(IO->sock, &IO->Addr, sizeof(struct sockaddr_in6));
+               rc = connect(IO->sock, IO->Addr, sizeof(struct sockaddr_in6));
        else
-               rc = connect(IO->sock, (struct sockaddr_in *)&IO->Addr, sizeof(struct sockaddr_in));
+               rc = connect(IO->sock, (struct sockaddr_in *)IO->Addr, sizeof(struct sockaddr_in));
 
        if (rc >= 0){
 ////           freeaddrinfo(res);
index e98a13a8d574a1acddbc248a64633f8fdca83d45..4bd86bd9f52171e8b6a5742ad0503a6a467232a8 100644 (file)
@@ -42,7 +42,7 @@ struct AsyncIO {
 
        /* connection related */
        int IP6;
-       struct sockaddr_in6 Addr;
+       struct sockaddr_in6 *Addr;
 
        int sock;
        unsigned short dport;
index 2e1dcbbed148ecb9f6d98e773b594f67addef786..7b5ced26fb2fff85de1897889c32e0f88418baa1 100644 (file)
@@ -180,10 +180,10 @@ void SetConnectStatus(AsyncIO *IO)
        buf[0] = '\0';
 
        if (IO->IP6) {
-               src = &IO->Addr.sin6_addr;
+               src = &IO->Addr->sin6_addr;
        }
        else {
-               struct sockaddr_in *addr = (struct sockaddr_in *)&IO->Addr;
+               struct sockaddr_in *addr = (struct sockaddr_in *)IO->Addr;
 
                src = &addr->sin_addr.s_addr;
        }
@@ -214,7 +214,7 @@ void SetConnectStatus(AsyncIO *IO)
  *****************************************************************************/
 eNextState mx_connect_relay_ip(AsyncIO *IO)
 {
-       
+       /*
        SmtpOutMsg *SendMsg = IO->Data;
 
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
@@ -235,7 +235,7 @@ eNextState mx_connect_relay_ip(AsyncIO *IO)
        }
        else {
                struct sockaddr_in *addr = (struct sockaddr_in*) &IO->Addr;
-               /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
+               /*  Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); * /
                memcpy(&addr->sin_addr,///.s_addr, 
                       &SendMsg->pCurrRelay->Addr,
                       sizeof(struct in_addr));
@@ -250,6 +250,7 @@ eNextState mx_connect_relay_ip(AsyncIO *IO)
                           SMTP_C_ConnTimeout, 
                           SMTP_C_ReadTimeouts[0],
                           1);
+               */
 }
 
 eNextState get_one_mx_host_ip_done(AsyncIO *IO)
@@ -263,20 +264,24 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO)
        if ((SendMsg->HostLookup.DNSStatus == ARES_SUCCESS) && 
            (hostent != NULL) ) {
                
-               IO->IP6  = hostent->h_addrtype == AF_INET6;
+///            IO->IP6  = hostent->h_addrtype == AF_INET6;
                ////IO->HEnt = hostent;
+               
+///            SendMsg->pCurrRelay->Addr
+
+
 
-               memset(&IO->Addr, 0, sizeof(struct in6_addr));
+               memset(&SendMsg->pCurrRelay->Addr, 0, sizeof(struct in6_addr));
                if (IO->IP6) {
-                       memcpy(&IO->Addr.sin6_addr.s6_addr, 
+                       memcpy(&SendMsg->pCurrRelay->Addr.sin6_addr.s6_addr, 
                               &hostent->h_addr_list[0],
                               sizeof(struct in6_addr));
                        
-                       IO->Addr.sin6_family = hostent->h_addrtype;
-                       IO->Addr.sin6_port   = htons(IO->dport);
+                       SendMsg->pCurrRelay->Addr.sin6_family = hostent->h_addrtype;
+                       SendMsg->pCurrRelay->Addr.sin6_port   = htons(IO->dport);
                }
                else {
-                       struct sockaddr_in *addr = (struct sockaddr_in*) &IO->Addr;
+                       struct sockaddr_in *addr = (struct sockaddr_in*) &SendMsg->pCurrRelay->Addr;
                        /* Bypass the ns lookup result like this: IO->Addr.sin_addr.s_addr = inet_addr("127.0.0.1"); */
 //                     addr->sin_addr.s_addr = htonl((uint32_t)&hostent->h_addr_list[0]);
                        memcpy(&addr->sin_addr.s_addr, 
@@ -288,6 +293,7 @@ eNextState get_one_mx_host_ip_done(AsyncIO *IO)
                        
                }
                ////SendMsg->IO.HEnt = hostent;
+               SendMsg->IO.Addr = &SendMsg->pCurrRelay->Addr;
                SetConnectStatus(IO);
                return InitEventIO(IO, 
                                   SendMsg, 
@@ -324,19 +330,16 @@ eNextState get_one_mx_host_ip(AsyncIO *IO)
 
        InitC_ares_dns(IO);
 
-       if (SendMsg->mx_host != NULL) Hostname = SendMsg->mx_host;
-       else Hostname = SendMsg->node;
-
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
 
        CtdlLogPrintf(CTDL_DEBUG, 
                      "SMTP client[%ld]: looking up %s : %d ...\n", 
                      SendMsg->n, 
-                     Hostname
+                     SendMsg->pCurrRelay->Host
                      SendMsg->IO.dport);
-// TODO: ns_t_aaaa
-       if (!QueueQuery(ns_t_a, 
-                       Hostname
+
+       if (!QueueQuery((SendMsg->pCurrRelay->IPv6)? ns_t_aaaa : ns_t_a, 
+                       SendMsg->pCurrRelay->Host
                        &SendMsg->IO, 
                        &SendMsg->HostLookup, 
                        get_one_mx_host_ip_done))
@@ -361,6 +364,7 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
        QueryCbDone(IO);
 
        CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
+       SendMsg->pCurrRelay = SendMsg->Relay;
        pp = &SendMsg->Relay;
        while ((pp != NULL) && (*pp != NULL) && ((*pp)->Next != NULL))
                pp = &(*pp)->Next;
@@ -370,7 +374,6 @@ eNextState smtp_resolve_mx_record_done(AsyncIO *IO)
        { /* ok, we found mx records. */
                SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
                
-
                SendMsg->CurrMX    = SendMsg->AllMX 
                                   = IO->DNSQuery->VParsedDNSReply;
                while (SendMsg->CurrMX) {
index 65cde8f15354eff3c15ed6e2066ab9bce9b4389e..5979d6fc5fd28c845e9fa0f0110e46f7b0589962 100644 (file)
@@ -695,8 +695,11 @@ void smtp_do_procmsg(long msgnum, void *userdata) {
                                StrBufExtract_NextToken(One, All, &Pos, '|');
                                if (!ParseURL(Url, One, 25))
                                        CtdlLogPrintf(CTDL_DEBUG, "Failed to parse: %s\n", ChrPtr(One));
-                               else 
+                               else {
+                                       ///if (!Url->IsIP)) /// todo dupe me fork ipv6
                                        Url = &(*Url)->Next;
+                                       
+                               }
                        }
                        FreeStrBuf(&All);
                        FreeStrBuf(&One);
index b16e3296c34f56f5b4a897b6690ffada67d2db88..1201a9be74abf773308201056da88bae16623880 100644 (file)
@@ -368,7 +368,7 @@ struct ParsedURL {
        int IPv6;
        int af;
        struct hostent *HEnt;
-       struct in6_addr Addr;
+       struct sockaddr_in6 Addr;
        ParsedURL *Next;
 };
 
index a8856fafd8991a4d4d79ee079fb47208a0e94ffb..6f7ebb58c628b945e7d20a36a668fba2b79b132c 100644 (file)
@@ -105,7 +105,7 @@ int ParseURL(ParsedURL **Url, StrBuf *UrlStr, unsigned short DefaultPort)
        }
        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.sin6_addr);
        *Url = url;
        return 1;
 }