From 36111d9ace0953d536650249f7339a52b0bed77d Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Fri, 16 Sep 2011 18:39:36 +0000 Subject: [PATCH] Add error handler for failing DNS requests; the Client should be able to take its individual decision whats to be done on fail. --- citadel/event_client.c | 4 ++-- citadel/event_client.h | 1 + citadel/modules/pop3client/serv_pop3client.c | 10 ++++++++++ citadel/modules/smtp/serv_smtpeventclient.c | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/citadel/event_client.c b/citadel/event_client.c index a265f30be..f1abcbef7 100644 --- a/citadel/event_client.c +++ b/citadel/event_client.c @@ -591,11 +591,11 @@ IO_postdns_callback(struct ev_loop *loop, ev_idle *watcher, int revents) AsyncIO *IO = watcher->data; syslog(LOG_DEBUG, "event: %s\n", __FUNCTION__); become_session(IO->CitContext); - + assert(IO->DNSFail); switch (IO->DNSQuery->PostDNS(IO)) { case eAbort: - ShutDownCLient(IO); + IO->DNSFail(IO); default: break; } diff --git a/citadel/event_client.h b/citadel/event_client.h index de36f29ed..b2c368db2 100644 --- a/citadel/event_client.h +++ b/citadel/event_client.h @@ -102,6 +102,7 @@ struct AsyncIO { Terminate, /* shutting down... */ Timeout, /* Timeout handler; may also be connection timeout */ ConnFail, /* What to do when one connection failed? */ + DNSFail, /* the dns lookup didn't work out. */ ShutdownAbort,/* we're going down. make your piece. */ NextDBOperation; /* Perform Database IO */ diff --git a/citadel/modules/pop3client/serv_pop3client.c b/citadel/modules/pop3client/serv_pop3client.c index ef811b7ed..18e4bdf8b 100644 --- a/citadel/modules/pop3client/serv_pop3client.c +++ b/citadel/modules/pop3client/serv_pop3client.c @@ -145,6 +145,7 @@ typedef eNextState(*Pop3ClientHandler)(pop3aggr* RecvMsg); eNextState POP3_C_Shutdown(AsyncIO *IO); eNextState POP3_C_Timeout(AsyncIO *IO); eNextState POP3_C_ConnFail(AsyncIO *IO); +eNextState POP3_C_DNSFail(AsyncIO *IO); eNextState POP3_C_DispatchReadDone(AsyncIO *IO); eNextState POP3_C_DispatchWriteDone(AsyncIO *IO); eNextState POP3_C_Terminate(AsyncIO *IO); @@ -680,6 +681,14 @@ eNextState POP3_C_ConnFail(AsyncIO *IO) StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); return FailAggregationRun(IO); } +eNextState POP3_C_DNSFail(AsyncIO *IO) +{ + pop3aggr *pMsg = (pop3aggr *)IO->Data; + + syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); + StrBufPlain(IO->ErrMsg, CKEY(POP3C_ReadErrors[pMsg->State])); + return FailAggregationRun(IO); +} eNextState POP3_C_Shutdown(AsyncIO *IO) { syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__); @@ -836,6 +845,7 @@ int pop3_do_fetching(pop3aggr *cpptr) cpptr->IO.Terminate = POP3_C_Terminate; cpptr->IO.LineReader = POP3_C_ReadServerStatus; cpptr->IO.ConnFail = POP3_C_ConnFail; + cpptr->IO.DNSFail = POP3_C_DNSFail; cpptr->IO.Timeout = POP3_C_Timeout; cpptr->IO.ShutdownAbort = POP3_C_Shutdown; diff --git a/citadel/modules/smtp/serv_smtpeventclient.c b/citadel/modules/smtp/serv_smtpeventclient.c index 22c18628a..0dbbf359c 100644 --- a/citadel/modules/smtp/serv_smtpeventclient.c +++ b/citadel/modules/smtp/serv_smtpeventclient.c @@ -110,6 +110,7 @@ eNextState SMTP_C_Timeout(AsyncIO *IO); eNextState SMTP_C_ConnFail(AsyncIO *IO); eNextState SMTP_C_DispatchReadDone(AsyncIO *IO); eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO); +eNextState SMTP_C_DNSFail(AsyncIO *IO); eNextState SMTP_C_Terminate(AsyncIO *IO); eReadState SMTP_C_ReadServerStatus(AsyncIO *IO); @@ -435,6 +436,7 @@ SmtpOutMsg *new_smtp_outmsg(OneQueItem *MyQItem, SendMsg->IO.Terminate = SMTP_C_Terminate; SendMsg->IO.LineReader = SMTP_C_ReadServerStatus; SendMsg->IO.ConnFail = SMTP_C_ConnFail; + SendMsg->IO.DNSFail = SMTP_C_DNSFail; SendMsg->IO.Timeout = SMTP_C_Timeout; SendMsg->IO.ShutdownAbort = SMTP_C_Shutdown; @@ -589,6 +591,14 @@ eNextState SMTP_C_ConnFail(AsyncIO *IO) StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State])); return FailOneAttempt(IO); } +eNextState SMTP_C_DNSFail(AsyncIO *IO) +{ + SmtpOutMsg *pMsg = IO->Data; + + syslog(LOG_DEBUG, "SMTP: %s\n", __FUNCTION__); + StrBufPlain(IO->ErrMsg, CKEY(ReadErrors[pMsg->State])); + return FailOneAttempt(IO); +} eNextState SMTP_C_Shutdown(AsyncIO *IO) { syslog(LOG_DEBUG, "SMTP: %s\n", __FUNCTION__); -- 2.30.2