libev/libc-ares migration
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 3 Jan 2011 23:00:47 +0000 (00:00 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 3 Jan 2011 23:00:47 +0000 (00:00 +0100)
  - move c-ares query into the eventqueue context
  - queueing of the new context via the pipe doesn't work anymore with libev

citadel/event_client.h
citadel/modules/c-ares-dns/serv_c-ares-dns.c
citadel/modules/smtp/serv_smtpeventclient.c

index 0e6cae95323fec8a2918ce2db7901c7959cd2b1b..39a9c11bebc57294fce34681e22484c6755a25aa 100644 (file)
@@ -2,6 +2,8 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
+#include <arpa/nameser.h>
+#include <ares.h>
 
 typedef struct AsyncIO AsyncIO;
 
@@ -16,6 +18,8 @@ typedef enum _eNextState {
 typedef int (*EventContextAttach)(void *Data);
 typedef eNextState (*IO_CallBack)(void *Data);
 typedef eReadState (*IO_LineReaderCallback)(AsyncIO *IO);
+typedef void (*ParseDNSAnswerCb)(AsyncIO*, unsigned char*, int);
+typedef void (*FreeDNSReply)(void *DNSData);
 
 struct AsyncIO {
        StrBuf *Host;
@@ -49,6 +53,14 @@ struct AsyncIO {
 
        IO_LineReaderCallback LineReader; /* if we have linereaders, maybe we want to read more lines before the real application logic is called? */
 
+       struct ares_options DNSOptions;
+       ares_channel DNSChannel;
+       ParseDNSAnswerCb DNS_CB;
+       IO_CallBack PostDNS;
+       int DNSStatus;
+       void *VParsedDNSReply;
+       FreeDNSReply DNSReplyFree;
+
        /* Custom data; its expected to contain  AsyncIO so we can save malloc()s... */
        DeleteHashDataFunc DeleteData; /* so if we have to destroy you, what to do... */
        void *Data; /* application specific data */
@@ -74,3 +86,5 @@ void InitEventIO(AsyncIO *IO,
                 IO_CallBack CustomDNS,
                 IO_LineReaderCallback LineReader,
                 int ReadFirst);
+
+int QueueQuery(ns_type Type, char *name, AsyncIO *IO, IO_CallBack PostDNS);
index 737f40452101aefb67b8c83df1b84f29aad48eaa..2de80574df85bd3d6693459e10ad3cf1548278cf 100644 (file)
@@ -465,6 +465,7 @@ int QueueQuery(ns_type Type, char *name, AsyncIO *IO, IO_CallBack PostDNS)
        int length, family;
        char address_b[sizeof(struct in6_addr)];
        int optmask = 0;
+       int rfd, wfd;
 
        optmask |= ARES_OPT_SOCK_STATE_CB;
        IO->DNSOptions.sock_state_cb = SockStateCb;
@@ -522,6 +523,7 @@ int QueueQuery(ns_type Type, char *name, AsyncIO *IO, IO_CallBack PostDNS)
                return 0;
        }
        ares_query(IO->DNSChannel, name, ns_c_in, Type, QueryCb, IO);
+       ares_fds(IO->DNSChannel, &rfd, &wfd);
        return 1;
 }
 
index 5a4a51439eb3720da4df94f5a5dac0db6b8ca593..ffc18bc87c6d0a350f5b51de76ab7833559c7dbd 100644 (file)
@@ -924,6 +924,28 @@ eNextState SMTPC_send_dummy(SmtpOutMsg *SendMsg)
        return eReadMessage;
 }
 
+eNextState smtp_resolve_one_smtpsrv_start(void *data)
+{
+       AsyncIO *IO = data;
+       SmtpOutMsg * SendMsg = IO->Data;
+///    resolve_mx_hosts(SendMsg);
+       //// connect_one_smtpsrv_xamine_result
+
+       connect_one_smtpsrv(SendMsg);
+}
+
+int resolve_mx_records(void *Ctx)
+{
+       SmtpOutMsg * SendMsg;
+       if (!QueueQuery(ns_t_mx, 
+                       SendMsg->node, 
+                       &SendMsg->IO, 
+                       smtp_resolve_one_smtpsrv_start))
+       {
+               /// TODO: abort
+       }
+}
+
 void smtp_try(OneQueItem *MyQItem, 
              MailQEntry *MyQEntry, 
              StrBuf *MsgText, 
@@ -943,11 +965,12 @@ void smtp_try(OneQueItem *MyQItem,
                SendMsg->msgtext = NewStrBufDup(MsgText);
 
        smtp_resolve_recipients(SendMsg);
-       resolve_mx_hosts(SendMsg);
-       connect_one_smtpsrv(SendMsg);
+
        QueueEventContext(SendMsg, 
                          &SendMsg->IO,
-                         connect_one_smtpsrv_xamine_result);
+                         resolve_mx_records);
+
+
 }