- free c-ares structs and its watchers in appropriate places
- finalize relaying
FreeStrBuf(&IO->IOBuf);
FreeStrBuf(&IO->SendBuf.Buf);
FreeStrBuf(&IO->RecvBuf.Buf);
FreeStrBuf(&IO->IOBuf);
FreeStrBuf(&IO->SendBuf.Buf);
FreeStrBuf(&IO->RecvBuf.Buf);
- ares_destroy(IO->DNSChannel);
IO->SendBuf.fd = 0;
IO->RecvBuf.fd = 0;
}
IO->SendBuf.fd = 0;
IO->RecvBuf.fd = 0;
}
+ if (IO->DNSChannel != NULL) {
+ ares_destroy(IO->DNSChannel);
+ ev_io_stop(event_base, &IO->dns_recv_event);
+ ev_io_stop(event_base, &IO->dns_send_event);
+ IO->DNSChannel = NULL;
+ }
assert(IO->Terminate);
IO->Terminate(IO);
assert(IO->Terminate);
IO->Terminate(IO);
else {
IO->NextState = eSendReply;
}
else {
IO->NextState = eSendReply;
}
- IO->IP6 = IO->HEnt->h_addrtype == AF_INET6;
-// IO->res = HEnt->h_addr_list[0];
return event_connect_socket(IO, conn_timeout, first_rw_timeout);
}
return event_connect_socket(IO, conn_timeout, first_rw_timeout);
}
src = &IO->Addr.sin6_addr;
}
else {
src = &IO->Addr.sin6_addr;
}
else {
struct sockaddr_in *addr = (struct sockaddr_in *)&IO->Addr;
src = &addr->sin_addr.s_addr;
struct sockaddr_in *addr = (struct sockaddr_in *)&IO->Addr;
src = &addr->sin_addr.s_addr;
- memcpy(&psaddr, &addr->sin_addr.s_addr, sizeof(psaddr));
-/// psaddr = ntohl(psaddr);
-/*
- CtdlLogPrintf(CTDL_DEBUG,
- "SMTP client[%ld]: connecting to %s [%ld.%ld.%ld.%ld:%d] ...\n",
- SendMsg->n,
- SendMsg->mx_host,
- (psaddr >> 24) & 0xFF,
- (psaddr >> 16) & 0xFF,
- (psaddr >> 8) & 0xFF,
- (psaddr >> 0) & 0xFF,
- SendMsg->IO.dport);
-
- SendMsg->MyQEntry->Status = 5;
- StrBufPrintf(SendMsg->MyQEntry->StatusMessage,
- "Timeout while connecting %s [%ld.%ld.%ld.%ld:%d] ",
- SendMsg->mx_host,
- (psaddr >> 24) & 0xFF,
- (psaddr >> 16) & 0xFF,
- (psaddr >> 8) & 0xFF,
- (psaddr >> 0) & 0xFF,
- SendMsg->IO.dport);
-
-*/
}
inet_ntop((IO->IP6)?AF_INET6:AF_INET,
src,
buf, sizeof(buf));
}
inet_ntop((IO->IP6)?AF_INET6:AF_INET,
src,
buf, sizeof(buf));
+ if (SendMsg->mx_host == NULL)
+ SendMsg->mx_host = "<no name>";
CtdlLogPrintf(CTDL_DEBUG,
"SMTP client[%ld]: connecting to %s [%s]:%d ...\n",
CtdlLogPrintf(CTDL_DEBUG,
"SMTP client[%ld]: connecting to %s [%s]:%d ...\n",
SMTP_C_ReadTimeouts[0],
1);
}
SMTP_C_ReadTimeouts[0],
1);
}
+ if ((State == eAbort) && (IO->sock != -1))
SendMsg->CurrMX = SendMsg->CurrMX->next;
}
SendMsg->CurrMX = SendMsg->CurrMX->next;
}
- if (SendMsg->pCurrRelay != NULL) Hostname = SendMsg->pCurrRelay->Host;
+ if (SendMsg->pCurrRelay != NULL) {
+ SendMsg->mx_host = Hostname = SendMsg->pCurrRelay->Host;
+ if (SendMsg->pCurrRelay->Port != 0)
+ SendMsg->IO.dport = SendMsg->pCurrRelay->Port;
+ }
else if (SendMsg->mx_host != NULL) Hostname = SendMsg->mx_host;
else Hostname = SendMsg->node;
else if (SendMsg->mx_host != NULL) Hostname = SendMsg->mx_host;
else Hostname = SendMsg->node;
CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
CtdlLogPrintf(CTDL_DEBUG, "SMTP: %s\n", __FUNCTION__);
- 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->CurrMX = SendMsg->AllMX = IO->VParsedDNSReply;
SendMsg->IO.ErrMsg = SendMsg->MyQEntry->StatusMessage;
SendMsg->CurrMX = SendMsg->AllMX = IO->VParsedDNSReply;
SendMsg->IO.LineReader = SMTP_C_ReadServerStatus;
SendMsg->IO.ConnFail = SMTP_C_ConnFail;
SendMsg->IO.Timeout = SMTP_C_Timeout;
SendMsg->IO.LineReader = SMTP_C_ReadServerStatus;
SendMsg->IO.ConnFail = SMTP_C_ConnFail;
SendMsg->IO.Timeout = SMTP_C_Timeout;
+ SendMsg->IO.SendBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.RecvBuf.Buf = NewStrBufPlain(NULL, 1024);
+ SendMsg->IO.IOBuf = NewStrBuf();
if (KeepMsgText) {
SendMsg->msgtext = MsgText;
if (KeepMsgText) {
SendMsg->msgtext = MsgText;
+void FreeURL(ParsedURL** Url)
+{
+ FreeStrBuf(&(*Url)->URL);
+ free(*Url);
+ *Url = NULL;
+}
void FreeMailQEntry(void *qv)
{
void FreeMailQEntry(void *qv)
{
DeleteHash(&(*Item)->MailQEntries);
FreeStrBuf(&(*Item)->EnvelopeFrom);
FreeStrBuf(&(*Item)->BounceTo);
DeleteHash(&(*Item)->MailQEntries);
FreeStrBuf(&(*Item)->EnvelopeFrom);
FreeStrBuf(&(*Item)->BounceTo);
+ FreeURL(&(*Item)->URL);
free(*Item);
Item = NULL;
}
free(*Item);
Item = NULL;
}
}
}
if (url->LocalPart == NULL) {
}
}
if (url->LocalPart == NULL) {
- url->LocalPart = pch + StrLength(UrlStr);
+ url->LocalPart = pch + StrLength(url->URL);
}
pCredEnd = strchr(pch, '@');
}
pCredEnd = strchr(pch, '@');
else {
url->Pass = pUserEnd + 1;
}
else {
url->Pass = pUserEnd + 1;
}
- StrBufPeek(UrlStr, pUserEnd, 0, '\0');
- StrBufPeek(UrlStr, pCredEnd, 0, '\0');
+ StrBufPeek(url->URL, pUserEnd, 0, '\0');
+ StrBufPeek(url->URL, pCredEnd, 0, '\0');
free(url);
return 0; /* invalid syntax, no ipv6 */
}
free(url);
return 0; /* invalid syntax, no ipv6 */
}
- if (*(pEndHost + 1) == ':')
+ if (*(pEndHost + 1) == ':'){
+ StrBufPeek(url->URL, pEndHost + 1, 0, '\0');
url->af = AF_INET6;
}
else {
pPort = strchr(url->Host, ':');
url->af = AF_INET6;
}
else {
pPort = strchr(url->Host, ':');
+ if (pPort != NULL) {
+ StrBufPeek(url->URL, pPort, 0, '\0');
}
if (pPort != NULL)
url->Port = atol(pPort);
}
if (pPort != NULL)
url->Port = atol(pPort);
- url->IsIP = inet_pton(url->af, url->Host, &url->Addr);
+ url->IsIP = inet_pton(url->af, url->Host, &url->Addr);
+ *Url = url;
- ParsedURL **Url = &RelayUrls; ///&MyQItem->Relay;
+ ParsedURL **Url = &MyQItem->URL;
nRelays = get_hosts(mxbuf, "smarthost");
if (nRelays > 0) {
StrBuf *All;
nRelays = get_hosts(mxbuf, "smarthost");
if (nRelays > 0) {
StrBuf *All;
All = NewStrBufPlain(mxbuf, -1);
One = NewStrBufPlain(NULL, StrLength(All) + 1);
All = NewStrBufPlain(mxbuf, -1);
One = NewStrBufPlain(NULL, StrLength(All) + 1);
- while (Pos != StrBufNOTNULL) {
+ while ((Pos != StrBufNOTNULL) && ((Pos == NULL) || !IsEmptyStr(Pos))) {
StrBufExtract_NextToken(One, All, &Pos, '|');
if (!ParseURL(Url, One, 25))
CtdlLogPrintf(CTDL_DEBUG, "Failed to parse: %s\n", ChrPtr(One));
else
Url = &(*Url)->Next;
}
StrBufExtract_NextToken(One, All, &Pos, '|');
if (!ParseURL(Url, One, 25))
CtdlLogPrintf(CTDL_DEBUG, "Failed to parse: %s\n", ChrPtr(One));
else
Url = &(*Url)->Next;
}
+ FreeStrBuf(&All);
+ FreeStrBuf(&One);