FreeStrBuf(&IO->IOBuf);
FreeStrBuf(&IO->SendBuf.Buf);
FreeStrBuf(&IO->RecvBuf.Buf);
+ FreeStrBuf(&IO->ErrMsg);
+ ares_destroy(IO->DNSChannel);
}
int event_connect_socket(AsyncIO *IO)
{
+ struct sockaddr_in saddr;
int fdflags;
int rc = -1;
- IO->SendBuf.fd =
- IO->RecvBuf.fd =
+ IO->SendBuf.fd = IO->RecvBuf.fd =
IO->sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
/*
IO->curr_ai->ai_family,
ev_io_init(&IO->send_event, IO_send_callback, IO->sock, EV_WRITE);
IO->send_event.data = IO;
- unsigned short dport = atoi("25"); ///todo
- struct sockaddr_in saddr;
memset( (struct sockaddr_in *)&saddr, '\0', sizeof( saddr ) );
memcpy(&saddr.sin_addr,
// saddr.sin_addr.s_addr = inet_addr("85.88.5.80");
saddr.sin_family = AF_INET;
- saddr.sin_port = htons(dport);/// TODO
+ saddr.sin_port = htons(IO->dport);
rc = connect(IO->sock,
(struct sockaddr *) &saddr,
/// TODO: ipv6?? (IO->HEnt->h_addrtype == AF_INET6)?
else {
IO->NextState = eSendReply;
}
-// IO->IP6 = IO->HEnt->h_addrtype == AF_INET6;
+ IO->IP6 = IO->HEnt->h_addrtype == AF_INET6;
// IO->res = HEnt->h_addr_list[0];
event_connect_socket(IO);
}
struct hostent *OneMX;
-
char mx_user[1024];
char mx_pass[1024];
StrBuf *msgtext;
void DeleteSmtpOutMsg(void *v)
{
SmtpOutMsg *Msg = v;
+
+ ares_free_data(Msg->AllMX);
FreeStrBuf(&Msg->msgtext);
FreeAsyncIOContents(&Msg->IO);
free(Msg);
#define SMTP_DBG_SEND() CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: > %s\n", SendMsg->n, ChrPtr(SendMsg->IO.IOBuf))
#define SMTP_DBG_READ() CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: < %s\n", SendMsg->n, ChrPtr(SendMsg->IO.IOBuf))
-/*
-void connect_one_smtpsrv_xamine_result(void *Ctx,
- int status,
- int timeouts,
- struct hostent *hostent)
-{
- SmtpOutMsg *SendMsg = Ctx;
-
- CtdlLogPrintf(CTDL_DEBUG, "SMTP client[%ld]: connecting [%s:%s]!\n",
- SendMsg->n, SendMsg->mx_host, SendMsg->mx_port);
-
- SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
- SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
- SendMsg->IO.IOBuf = NewStrBuf();
- SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
-
-
- SendMsg->IO.SendBuf.fd =
- SendMsg->IO.RecvBuf.fd =
- SendMsg->IO.sock = sock_connect(SendMsg->mx_host, SendMsg->mx_port);
-
- StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
- "Could not connect: %s", strerror(errno));
-
-
- if (SendMsg->IO.sock < 0) {
- if (errno > 0) {
- StrBufPlain(SendMsg->MyQEntry->StatusMessage,
- strerror(errno), -1);
- }
- else {
- StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
- "Unable to connect to %s : %s\n",
- SendMsg->mx_host, SendMsg->mx_port);
- }
- }
- /// hier: naechsten mx ausprobieren.
- if (SendMsg->IO.sock < 0) {
- SendMsg->MyQEntry->Status = 4; /* dsn is already filled in * /
- //// hier: abbrechen & bounce.
- return;
- }
-/*
-
- InitEventIO(&SendMsg->IO, SendMsg,
- SMTP_C_DispatchReadDone,
- SMTP_C_DispatchWriteDone,
- SMTP_C_Terminate,
- SMTP_C_Timeout,
- SMTP_C_ConnFail,
- SMTP_C_MXLookup,
- SMTP_C_ReadServerStatus,
- 1);
-* /
- return;
-}
-*/
-
void get_one_mx_host_name_done(void *Ctx,
int status,
int timeouts,
SmtpOutMsg *SendMsg = IO->Data;
if ((status == ARES_SUCCESS) && (hostent != NULL) ) {
- SendMsg->IO.HEnt = hostent;
- InitEventIO(IO, SendMsg,
- SMTP_C_DispatchReadDone,
- SMTP_C_DispatchWriteDone,
- SMTP_C_Terminate,
- SMTP_C_Timeout,
- SMTP_C_ConnFail,
- SMTP_C_ReadServerStatus,
- 1);
+ SendMsg->IO.HEnt = hostent;
+ InitEventIO(IO, SendMsg,
+ SMTP_C_DispatchReadDone,
+ SMTP_C_DispatchWriteDone,
+ SMTP_C_Terminate,
+ SMTP_C_Timeout,
+ SMTP_C_ConnFail,
+ SMTP_C_ReadServerStatus,
+ 1);
}
}
-const char *DefaultMXPort = "25";
+const unsigned short DefaultMXPort = 25;
void connect_one_smtpsrv(SmtpOutMsg *SendMsg)
{
//char *endpart;
//char buf[SIZ];
- SendMsg->mx_port = DefaultMXPort;
+ SendMsg->IO.dport = DefaultMXPort;
/* TODO: Relay!
SendMsg->CurrMX = SendMsg->CurrMX->next;
CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: connecting to %s : %s ...\n",
+ "SMTP client[%ld]: connecting to %s : %d ...\n",
SendMsg->n,
SendMsg->mx_host,
- SendMsg->mx_port);
+ SendMsg->IO.dport);
ares_gethostbyname(SendMsg->IO.DNSChannel,
SendMsg->mx_host,
int resolve_mx_records(void *Ctx)
{
SmtpOutMsg * SendMsg = Ctx;
-/*//TMP
- SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
- SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
- SendMsg->IO.IOBuf = NewStrBuf();
- SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
- InitEventIO(&SendMsg->IO, SendMsg,
- SMTP_C_DispatchReadDone,
- SMTP_C_DispatchWriteDone,
- SMTP_C_Terminate,
- SMTP_C_Timeout,
- SMTP_C_ConnFail,
- SMTP_C_ReadServerStatus,
- 1);
- return 0;
-/// END TMP */
if (!QueueQuery(ns_t_mx,
SendMsg->node,
&SendMsg->IO,
QueueEventContext(SendMsg,
&SendMsg->IO,
resolve_mx_records);
-
-
}
}
+void smtp_evc_cleanup(void)
+{
+ DeleteHash(&QItemHandlers);
+ DeleteHash(&ActiveQItems);
+}
+
#endif
CTDL_MODULE_INIT(smtp_eventclient)
{
smtp_init_spoolout();
+
+ CtdlRegisterCleanupHook(smtp_evc_cleanup);
CtdlThreadCreate("SMTPEvent Send", CTDLTHREAD_BIGSTACK, smtp_queue_thread, NULL);
CtdlRegisterProtoHook(cmd_smtp, "SMTP", "SMTP utility commands");