EVM_syslog(LOG_DEBUG, "DBEVENT Terminating.\n");
ev_cleanup_stop(event_db, &IO->db_abort_by_shutdown);
- assert(IO->Terminate);
- IO->Terminate(IO);
+ assert(IO->DBTerminate);
+ IO->DBTerminate(IO);
}
void
IO_CallBack SendDone,
IO_CallBack ReadDone,
IO_CallBack Terminate,
+ IO_CallBack DBTerminate,
IO_CallBack ConnFail,
IO_CallBack Timeout,
IO_CallBack ShutdownAbort)
IO->SendDone = SendDone;
IO->ReadDone = ReadDone;
IO->Terminate = Terminate;
+ IO->DBTerminate = DBTerminate;
IO->LineReader = LineReader;
IO->ConnFail = ConnFail;
IO->Timeout = Timeout;
const char* Desc,
IO_CallBack SendDone,
IO_CallBack Terminate,
+ IO_CallBack DBTerminate,
IO_CallBack ShutdownAbort)
{
IO->Data = Data;
IO->CitContext = CloneContext(CC);
((CitContext *)IO->CitContext)->session_specific_data = (char*) Data;
- IO->SendDone = SendDone;
- IO->Terminate = Terminate;
+ IO->SendDone = SendDone;
+ IO->Terminate = Terminate;
+ IO->DBTerminate = DBTerminate;
IO->ShutdownAbort = ShutdownAbort;
strcpy(IO->HttpReq.errdesc, Desc);
IO_CallBack ReadDone, /* Theres new data to read... */
SendDone, /* we may send more data */
Terminate, /* shutting down... */
+ DBTerminate, /* shutting down... */
Timeout, /* Timeout handler;may also be conn. timeout */
ConnFail, /* What to do when one connection failed? */
ShutdownAbort,/* we're going down. make your piece. */
IO_CallBack SendDone,
IO_CallBack ReadDone,
IO_CallBack Terminate,
+ IO_CallBack DBTerminate,
IO_CallBack ConnFail,
IO_CallBack Timeout,
IO_CallBack ShutdownAbort);
const char* Desc,
IO_CallBack SendDone,
IO_CallBack Terminate,
+ IO_CallBack DBTerminate,
IO_CallBack ShutdownAbort);
eNextState ReAttachIO(AsyncIO *IO,
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
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;
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
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;
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__);
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;
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
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;
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
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;
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
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;
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;
eNextState EvaluateResult(AsyncIO *IO);
eNextState ExtNotifyTerminate(AsyncIO *IO);
+eNextState ExtNotifyTerminateDB(AsyncIO *IO);
eNextState ExtNotifyShutdownAbort(AsyncIO *IO);
/*
"Citadel ExtNotify",
EvaluateResult,
ExtNotifyTerminate,
+ ExtNotifyTerminateDB,
ExtNotifyShutdownAbort))
{
syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
return 0;
}
+eNextState ExtNotifyTerminateDB(AsyncIO *IO)
+{
+ free(IO);
+ return eAbort;
+}
eNextState ExtNotifyTerminate(AsyncIO *IO)
{
free(IO);
FreeStrBuf(&NW->port);
FreeStrBuf(&NW->secret);
FreeStrBuf(&NW->Url);
+ FreeStrBuf(&NW->IO.ErrMsg);
FreeAsyncIOContents(&NW->IO);
free(NW);
}
return eAbort;
}
+eNextState NWC_TerminateDB(AsyncIO *IO)
+{
+ EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
+ FinalizeNetworker(IO);
+ return eAbort;
+}
+
eNextState NWC_Timeout(AsyncIO *IO)
{
AsyncNetworker *NW = IO->Data;
NWC_DispatchWriteDone,
NWC_DispatchReadDone,
NWC_Terminate,
+ NWC_TerminateDB,
NWC_ConnFail,
NWC_Timeout,
NWC_Shutdown);
FinalizePOP3AggrRun(IO);
return eAbort;
}
+eNextState POP3_C_TerminateDB(AsyncIO *IO)
+{
+/// pop3aggr *pMsg = (pop3aggr *)IO->Data;
+
+ syslog(LOG_DEBUG, "POP3: %s\n", __FUNCTION__);
+ FinalizePOP3AggrRun(IO);
+ return eAbort;
+}
eNextState POP3_C_Timeout(AsyncIO *IO)
{
pop3aggr *pMsg = IO->Data;
POP3_C_DispatchWriteDone,
POP3_C_DispatchReadDone,
POP3_C_Terminate,
+ POP3_C_TerminateDB,
POP3_C_ConnFail,
POP3_C_Timeout,
POP3_C_Shutdown);
HashList *RSSFetchUrls = NULL; /*->rss_aggregator;->RefCount access locked*/
eNextState RSSAggregator_Terminate(AsyncIO *IO);
+eNextState RSSAggregator_TerminateDB(AsyncIO *IO);
eNextState RSSAggregator_ShutdownAbort(AsyncIO *IO);
struct CitContext rss_CC;
return eAbort;
}
+eNextState RSSAggregator_TerminateDB(AsyncIO *IO)
+{
+ rss_aggregator *RSSAggr = (rss_aggregator *)IO->Data;
+
+ EVM_syslog(LOG_DEBUG, "RSS: Terminating.\n");
+
+
+ UnlinkRSSAggregator(RSSAggr);
+ return eAbort;
+}
+
eNextState RSSAggregator_ShutdownAbort(AsyncIO *IO)
{
const char *pUrl;
"Citadel RSS Client",
RSSAggregator_ParseReply,
RSSAggregator_Terminate,
+ RSSAggregator_TerminateDB,
RSSAggregator_ShutdownAbort))
{
syslog(LOG_ALERT, "Unable to initialize libcurl.\n");
eNextState SMTP_C_DispatchWriteDone(AsyncIO *IO);
eNextState SMTP_C_DNSFail(AsyncIO *IO);
eNextState SMTP_C_Terminate(AsyncIO *IO);
+eNextState SMTP_C_TerminateDB(AsyncIO *IO);
eReadState SMTP_C_ReadServerStatus(AsyncIO *IO);
eNextState mx_connect_ip(AsyncIO *IO);
eNextState get_one_mx_host_ip(AsyncIO *IO);
+eNextState FinalizeMessageSendDB(AsyncIO *IO);
+eNextState FinalizeMessageSend_DB1(AsyncIO *IO);
+eNextState FinalizeMessageSend_DB2(AsyncIO *IO);
+eNextState FinalizeMessageSend_DB3(AsyncIO *IO);
/******************************************************************************
* So, we're finished with sending (regardless of success or failure) *
* we need to free the memory and send bounce messages (on terminal failure) *
* else we just free our SMTP-Message struct. *
******************************************************************************/
-void FinalizeMessageSend(SmtpOutMsg *Msg)
+inline void FinalizeMessageSend_1(AsyncIO *IO)
{
- int IDestructQueItem;
- int nRemain;
- StrBuf *MsgData;
- AsyncIO *IO = &Msg->IO;
-
- IDestructQueItem = DecreaseQReference(Msg->MyQItem);
+ SmtpOutMsg *Msg = IO->Data;
+ Msg->IDestructQueItem = DecreaseQReference(Msg->MyQItem);
- nRemain = CountActiveQueueEntries(Msg->MyQItem);
+ Msg->nRemain = CountActiveQueueEntries(Msg->MyQItem);
if (Msg->MyQEntry->Active &&
CheckQEntryIsBounce(Msg->MyQEntry))
Msg->MyQItem->SendBounceMail |= (1<<Msg->MyQEntry->Status);
}
- if ((nRemain > 0) || IDestructQueItem)
- MsgData = SerializeQueueItem(Msg->MyQItem);
+ if ((Msg->nRemain > 0) || Msg->IDestructQueItem)
+ Msg->QMsgData = SerializeQueueItem(Msg->MyQItem);
else
- MsgData = NULL;
+ Msg->QMsgData = NULL;
+}
+eNextState FinalizeMessageSend(SmtpOutMsg *Msg)
+{
+ return QueueDBOperation(&Msg->IO, FinalizeMessageSend_DB1);
+}
+
+inline void FinalizeMessageSend_DB_1(AsyncIO *IO)
+{
+ SmtpOutMsg *Msg = IO->Data;
/*
* Uncompleted delivery instructions remain, so delete the old
*/
EVS_syslog(LOG_DEBUG, "SMTPQD: %ld", Msg->MyQItem->QueMsgID);
CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &Msg->MyQItem->QueMsgID, 1, "");
+}
+eNextState FinalizeMessageSend_DB1(AsyncIO *IO)
+{
+ FinalizeMessageSend_1(IO);
+ FinalizeMessageSend_DB_1(IO);
+ return NextDBOperation(IO, FinalizeMessageSend_DB2);
+}
+
- if (IDestructQueItem)
+inline void FinalizeMessageSend_DB_2(AsyncIO *IO)
+{
+ SmtpOutMsg *Msg = IO->Data;
+
+ if (Msg->IDestructQueItem)
smtpq_do_bounce(Msg->MyQItem, Msg->msgtext);
+}
+eNextState FinalizeMessageSend_DB2(AsyncIO *IO)
+{
+ FinalizeMessageSend_DB_2(IO);
+
+ return NextDBOperation(IO, FinalizeMessageSend_DB3);
+}
+
+
+inline void FinalizeMessageSend_DB_3(AsyncIO *IO)
+{
+ SmtpOutMsg *Msg = IO->Data;
- if (nRemain > 0)
+ if (Msg->nRemain > 0)
{
struct CtdlMessage *msg;
msg = malloc(sizeof(struct CtdlMessage));
msg->cm_magic = CTDLMESSAGE_MAGIC;
msg->cm_anon_type = MES_NORMAL;
msg->cm_format_type = FMT_RFC822;
- msg->cm_fields['M'] = SmashStrBuf(&MsgData);
+ msg->cm_fields['M'] = SmashStrBuf(&Msg->QMsgData);
msg->cm_fields['U'] = strdup("QMSG");
Msg->MyQItem->QueMsgID =
CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, QP_EADDR);
&Msg->MyQItem->MessageID,
1,
"");
- FreeStrBuf(&MsgData);
+ FreeStrBuf(&Msg->QMsgData);
}
+}
+eNextState FinalizeMessageSend_DB3(AsyncIO *IO)
+{
+ FinalizeMessageSend_DB_3(IO);
+ return eAbort;
+}
+
+eNextState FinalizeMessageSend_DB(AsyncIO *IO)
+{
+ SmtpOutMsg *Msg = IO->Data;
+
RemoveContext(Msg->IO.CitContext);
- if (IDestructQueItem)
+ if (Msg->IDestructQueItem)
RemoveQItem(Msg->MyQItem);
DeleteSmtpOutMsg(Msg);
+ return eAbort;
}
eNextState FailOneAttempt(AsyncIO *IO)
SMTP_C_DispatchWriteDone,
SMTP_C_DispatchReadDone,
SMTP_C_Terminate,
+ SMTP_C_TerminateDB,
SMTP_C_ConnFail,
SMTP_C_Timeout,
SMTP_C_Shutdown);
StrBufPlain(Msg->MyQEntry->StatusMessage,
HKEY("Invalid Recipient!"));
}
- FinalizeMessageSend(Msg);
+ FinalizeMessageSend_1(&Msg->IO);
+ FinalizeMessageSend_DB_1(&Msg->IO);
+ FinalizeMessageSend_DB_2(&Msg->IO);
+ FinalizeMessageSend_DB_3(&Msg->IO);
+ FinalizeMessageSend_DB(&Msg->IO);
}
}
SmtpOutMsg *Msg = IO->Data;
EVS_syslog(LOG_DEBUG, "SMTP: %s\n", __FUNCTION__);
- FinalizeMessageSend(Msg);
- return eAbort;
+ return FinalizeMessageSend(Msg);
+}
+eNextState SMTP_C_TerminateDB(AsyncIO *IO)
+{
+ EVS_syslog(LOG_DEBUG, "SMTP: %s\n", __FUNCTION__);
+ return FinalizeMessageSend_DB(IO);
}
eNextState SMTP_C_Timeout(AsyncIO *IO)
{
Msg->MyQEntry->Status = 3;
StrBufPlain(Msg->MyQEntry->StatusMessage,
HKEY("server shutdown during message submit."));
- FinalizeMessageSend(Msg);
- return eAbort;
+ return FinalizeMessageSend(Msg);
}
long n;
AsyncIO IO;
long CXFlags;
+ int IDestructQueItem;
+ int nRemain;
eSMTP_C_States State;
ParsedURL *Relay;
ParsedURL *pCurrRelay;
StrBuf *msgtext;
+ StrBuf *QMsgData;
const char *envelope_from;
+
char user[1024];
char node[1024];
char name[1024];
char mailfrom[1024];
+
long Flags;
} SmtpOutMsg;
//TOOD
return eAbort;
}
+eNextState TerminateLookupUrlDB(AsyncIO *IO)
+{
+//TOOD
+ return eAbort;
+}
eNextState LookupUrlResult(AsyncIO *IO)
{
return eTerminateConnection; /// /TODO
"Citadel RSS ShorterURL Expander",
LookupUrlResult,
TerminateLookupUrl,
+ TerminateLookupUrlDB,
ShutdownLookuUrl))
{
syslog(LOG_ALERT, "Unable to initialize libcurl.\n");