X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=citadel%2Fmodules%2Fc-ares-dns%2Fserv_c-ares-dns.c;h=13e156a80879a3ecb17ceb7e8e318d839a59cea9;hb=72a4e9f304cff9f487b334f0d70f09142fee4183;hp=f48eac3877f71c6901a819f8731b9025c8ff0b98;hpb=d3a29d82d6492191ae8208617e8ac1f088bcf14a;p=citadel.git diff --git a/citadel/modules/c-ares-dns/serv_c-ares-dns.c b/citadel/modules/c-ares-dns/serv_c-ares-dns.c index f48eac387..13e156a80 100644 --- a/citadel/modules/c-ares-dns/serv_c-ares-dns.c +++ b/citadel/modules/c-ares-dns/serv_c-ares-dns.c @@ -57,6 +57,7 @@ #include "ctdl_module.h" #include "event_client.h" +int DebugCAres = 0; extern struct ev_loop *event_base; @@ -85,7 +86,7 @@ static void HostByAddrCb(void *data, static void ParseAnswerA(AsyncIO *IO, unsigned char* abuf, int alen) { - struct hostent* host; + struct hostent* host = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -100,6 +101,8 @@ static void ParseAnswerA(AsyncIO *IO, unsigned char* abuf, int alen) NULL, NULL); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (host != NULL) + ares_free_hostent(host); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -111,7 +114,7 @@ static void ParseAnswerA(AsyncIO *IO, unsigned char* abuf, int alen) static void ParseAnswerAAAA(AsyncIO *IO, unsigned char* abuf, int alen) { - struct hostent* host; + struct hostent* host = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -126,6 +129,8 @@ static void ParseAnswerAAAA(AsyncIO *IO, unsigned char* abuf, int alen) NULL, NULL); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (host != NULL) + ares_free_hostent(host); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -137,7 +142,7 @@ static void ParseAnswerAAAA(AsyncIO *IO, unsigned char* abuf, int alen) static void ParseAnswerCNAME(AsyncIO *IO, unsigned char* abuf, int alen) { - struct hostent* host; + struct hostent* host = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); @@ -153,6 +158,8 @@ static void ParseAnswerCNAME(AsyncIO *IO, unsigned char* abuf, int alen) NULL, NULL); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (host != NULL) + ares_free_hostent(host); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -166,7 +173,7 @@ static void ParseAnswerCNAME(AsyncIO *IO, unsigned char* abuf, int alen) static void ParseAnswerMX(AsyncIO *IO, unsigned char* abuf, int alen) { - struct ares_mx_reply *mx_out; + struct ares_mx_reply *mx_out = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -177,6 +184,8 @@ static void ParseAnswerMX(AsyncIO *IO, unsigned char* abuf, int alen) IO->DNS.Query->DNSStatus = ares_parse_mx_reply(abuf, alen, &mx_out); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (mx_out != NULL) + ares_free_data(mx_out); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -189,7 +198,7 @@ static void ParseAnswerMX(AsyncIO *IO, unsigned char* abuf, int alen) static void ParseAnswerNS(AsyncIO *IO, unsigned char* abuf, int alen) { - struct hostent* host; + struct hostent* host = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -200,6 +209,8 @@ static void ParseAnswerNS(AsyncIO *IO, unsigned char* abuf, int alen) IO->DNS.Query->DNSStatus = ares_parse_ns_reply(abuf, alen, &host); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (host != NULL) + ares_free_hostent(host); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -211,7 +222,7 @@ static void ParseAnswerNS(AsyncIO *IO, unsigned char* abuf, int alen) static void ParseAnswerSRV(AsyncIO *IO, unsigned char* abuf, int alen) { - struct ares_srv_reply *srv_out; + struct ares_srv_reply *srv_out = NULL; #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -222,6 +233,8 @@ static void ParseAnswerSRV(AsyncIO *IO, unsigned char* abuf, int alen) IO->DNS.Query->DNSStatus = ares_parse_srv_reply(abuf, alen, &srv_out); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (srv_out != NULL) + ares_free_data(srv_out); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -245,6 +258,8 @@ static void ParseAnswerTXT(AsyncIO *IO, unsigned char* abuf, int alen) IO->DNS.Query->DNSStatus = ares_parse_txt_reply(abuf, alen, &txt_out); if (IO->DNS.Query->DNSStatus != ARES_SUCCESS) { + if (txt_out != NULL) + ares_free_data(txt_out); StrBufPlain(IO->ErrMsg, ares_strerror(IO->DNS.Query->DNSStatus), -1); return; @@ -297,6 +312,16 @@ void QueryCbDone(AsyncIO *IO) void DestructCAres(AsyncIO *IO) { +#ifdef DEBUG_CARES + EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); + EV_DNS_LOGT_STOP(DNS.timeout); +#endif + EV_DNS_LOG_STOP(DNS.recv_event); + ev_io_stop(event_base, &IO->DNS.recv_event); + EV_DNS_LOG_STOP(DNS.send_event); + ev_io_stop(event_base, &IO->DNS.send_event); + ev_timer_stop (event_base, &IO->DNS.timeout); + ev_idle_stop(event_base, &IO->unwind_stack); ares_destroy_options(&IO->DNS.Options); } @@ -363,6 +388,7 @@ void QueueGetHostByNameDone(void *Ctx, EV_DNS_LOGT_INIT(unwind_stack); EV_DNS_LOGT_START(unwind_stack); ev_idle_start(event_base, &IO->unwind_stack); + ev_timer_stop (event_base, &IO->DNS.timeout); } void QueueGetHostByName(AsyncIO *IO, @@ -408,6 +434,7 @@ int QueueQuery(ns_type Type, IO->DNS.Query = QueryParts; IO->DNS.Query->PostDNS = PostDNS; + IO->DNS.Start = IO->Now; InitC_ares_dns(IO); @@ -496,6 +523,7 @@ static void DNS_send_callback(struct ev_loop *loop, ev_io *watcher, int revents) { AsyncIO *IO = watcher->data; + IO->Now = ev_now(event_base); #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -508,6 +536,8 @@ static void DNS_recv_callback(struct ev_loop *loop, ev_io *watcher, int revents) { AsyncIO *IO = watcher->data; + IO->Now = ev_now(event_base); + #ifdef DEBUG_CARES EV_syslog(LOG_DEBUG, "C-ARES: %s\n", __FUNCTION__); #endif @@ -539,6 +569,7 @@ void SockStateCb(void *data, int sock, int read, int write) IO->DNS.SourcePort); } #endif + IO->Now = ev_now(event_base); if (read) { if ((IO->DNS.recv_event.fd != sock) && @@ -579,11 +610,16 @@ void SockStateCb(void *data, int sock, int read, int write) ev_io_stop(event_base, &IO->DNS.send_event); } } +void EnableDebugCAres(void) +{ + DebugCAres = 1; +} CTDL_MODULE_INIT(c_ares_client) { if (!threading) { + CtdlRegisterDebugFlagHook(HKEY("cares"), EnableDebugCAres); int r = ares_library_init(ARES_LIB_INIT_ALL); if (0 != r) {