summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2017-10-20 12:33:36 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-10-20 12:33:36 (GMT)
commit19cd80155ca451dbbfabd5f6d7084a6fcc737dbb (patch) (side-by-side diff)
tree056ec30078928f178f133314c1a72388270c854b /src
parent5cf28509ada303e8995113af9390d10553c60bef (diff)
downloadmailfromd-19cd80155ca451dbbfabd5f6d7084a6fcc737dbb.tar.gz
mailfromd-19cd80155ca451dbbfabd5f6d7084a6fcc737dbb.tar.bz2
Unify DNS reply types.
* lib/dns.h (mxbuf): Remove (mxbuf_init, mxbuf_free): Remove protos. (dns_get_mx_records): Remove the maxdepth parameter. Return MX names in struct dns_reply. All uses changed. (getmx,getmxip): Return MX names in struct dns_reply. All uses changed.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/builtin/dns.bi43
-rw-r--r--src/callout.c12
-rw-r--r--src/mailfromd.h3
-rw-r--r--src/prog.c10
-rw-r--r--src/spf.c10
5 files changed, 33 insertions, 45 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi
index c23aaf3..f63a236 100644
--- a/src/builtin/dns.bi
+++ b/src/builtin/dns.bi
@@ -149,17 +149,16 @@ END
MF_DEFUN(primitive_hasmx, NUMBER, STRING string)
{
- struct mxbuf mxbuf;
+ struct dns_reply repl;
mf_status mxstat;
- mxbuf.mx_flags = 0;
- mxstat = getmx(string, &mxbuf);
+ mxstat = getmx(string, &repl);
MF_ASSERT(mxstat == mf_success || mxstat == mf_not_found,
mf_status_to_exception(mxstat),
_("cannot get MX records for %s"),
string);
- mxbuf_free(&mxbuf);
+ dns_reply_free(&repl);
if (mxstat == mf_success) {
MF_RETURN(1);
}
@@ -170,12 +169,10 @@ END
MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
{
mf_status mxstat;
+ struct dns_reply repl;
if (MF_OPTVAL(no_resolve)) {
- GACOPYZ_UINT32_T *ipbuf;
- size_t ipcount;
-
- mxstat = getmxip(domain, &ipbuf, &ipcount);
+ mxstat = getmxip(domain, &repl);
if (!mf_resolved(mxstat)) {
MF_THROW(mf_status_to_exception(mxstat),
_("cannot get MX records for %s"), domain);
@@ -186,41 +183,37 @@ MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve)
int i;
MF_OBSTACK_BEGIN();
- for (i = 0; i < ipcount; i++) {
+ for (i = 0; i < repl.count; i++) {
struct in_addr s;
- s.s_addr = htonl(ipbuf[i]);
+ s.s_addr = htonl(repl.data.ip[i]);
if (i > 0)
MF_OBSTACK_1GROW(' ');
MF_OBSTACK_GROW(inet_ntoa(s));
}
- free(ipbuf);
MF_OBSTACK_1GROW(0);
+ dns_reply_free(&repl);
MF_RETURN_OBSTACK();
}
} else {
- struct mxbuf mxbuf;
-
- mxstat = getmx(domain, &mxbuf);
+ mxstat = getmx(domain, &repl);
if (!mf_resolved(mxstat)) {
- mxbuf_free(&mxbuf);
MF_THROW(mf_status_to_exception(mxstat),
_("cannot get MX records for %s"), domain);
}
if (mxstat == mf_not_found) {
- mxbuf_free(&mxbuf);
MF_RETURN("");
} else {
int i;
MF_OBSTACK_BEGIN();
- for (i = 0; i < mxbuf.mx_cnt; i++) {
+ for (i = 0; i < repl.count; i++) {
if (i > 0)
MF_OBSTACK_1GROW(' ');
- MF_OBSTACK_GROW(mxbuf.mx_buf[i]);
+ MF_OBSTACK_GROW(repl.data.str[i]);
}
MF_OBSTACK_1GROW(0);
- mxbuf_free(&mxbuf);
+ dns_reply_free(&repl);
MF_RETURN_OBSTACK();
}
}
@@ -256,8 +249,7 @@ resolve_host(const char *string, unsigned long *ip)
MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr)
{
- GACOPYZ_UINT32_T *ipbuf;
- size_t ipcount;
+ struct dns_reply reply;
mf_status mxstat;
unsigned long ip;
int rc = 0;
@@ -267,21 +259,20 @@ MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr)
_("cannot resolve host name %s"), ipstr);
ip = ntohl(ip);
- mxstat = getmxip(domain, &ipbuf, &ipcount);
+ mxstat = getmxip(domain, &reply);
if (mxstat != mf_success) {
MF_THROW(mf_status_to_exception(mxstat),
_("cannot get MXs for %s"), domain);
}
- for (i = 0; i < ipcount; i++) {
- if (ipbuf[i] == ip) {
+ for (i = 0; i < reply.count; i++) {
+ if (reply.data.ip[i] == ip) {
rc = 1;
break;
}
}
-
- free(ipbuf);
+ dns_reply_free(&reply);
MF_RETURN(rc);
}
END
diff --git a/src/callout.c b/src/callout.c
index 633a33b..1d46bc7 100644
--- a/src/callout.c
+++ b/src/callout.c
@@ -634,10 +634,10 @@ mf_status
callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount)
{
int i;
- struct mxbuf mxbuf;
+ struct dns_reply reply;
mf_status rc, mxstat;
- mxstat = getmx(hostname, &mxbuf);
+ mxstat = getmx(hostname, &reply);
if (pcount)
*pcount = 0;
@@ -646,20 +646,20 @@ callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount)
mu_debug(MF_SOURCE_CALLOUT, MU_DEBUG_TRACE1,
("Checking MX servers for %s", iop->email));
rc = mf_not_found;
- for (i = 0; i < mxbuf.mx_cnt; i++) {
- rc = callout_host(iop, mxbuf.mx_buf[i]);
+ for (i = 0; i < reply.count; i++) {
+ rc = callout_host(iop, reply.data.str[i]);
if (mf_resolved(rc))
break;
}
if (pcount)
- *pcount = mxbuf.mx_cnt;
+ *pcount = reply.count;
+ dns_reply_free(&reply);
break;
default:
rc = mxstat;
break;
}
- mxbuf_free(&mxbuf);
return rc;
}
diff --git a/src/mailfromd.h b/src/mailfromd.h
index 7f21e36..efea11a 100644
--- a/src/mailfromd.h
+++ b/src/mailfromd.h
@@ -75,9 +75,6 @@ mf_status resolve_ipstr_domain(const char *ipstr, const char *domain,
char **phbuf);
mf_status resolve_hostname(const char *host, char **pipbuf);
-mf_status getmx(const char *ipstr, struct mxbuf *mxbuf);
-mf_status getmxip(char *host, GACOPYZ_UINT32_T **ipbuf, size_t *pcount);
-
/* Debugging macros */
extern mu_debug_handle_t mfd_debug_handle;
diff --git a/src/prog.c b/src/prog.c
index 3e90472..932efd2 100644
--- a/src/prog.c
+++ b/src/prog.c
@@ -1594,7 +1594,7 @@ mx_match(eval_environ_t env, char *string,
int (*matcher)(const char *name, void *data), void *data)
{
int rc = 0;
- struct mxbuf mxbuf;
+ struct dns_reply reply;
mf_status mxstat;
char *p = strchr(string, '@');
@@ -1602,19 +1602,19 @@ mx_match(eval_environ_t env, char *string,
p++;
else
p = string;
- mxstat = getmx(p, &mxbuf);
+ mxstat = getmx(p, &reply);
rc = 0;
if (mxstat == mf_success) {
int i;
- for (i = 0; i < mxbuf.mx_cnt; i++) {
- if (matcher(mxbuf.mx_buf[i], data)) {
+ for (i = 0; i < reply.count; i++) {
+ if (matcher(reply.data.str[i], data)) {
rc = 1;
break;
}
}
}
- mxbuf_free(&mxbuf);
+ dns_reply_free(&reply);
if (!mf_resolved(mxstat))
env_throw(env, mf_status_to_exception(mxstat),
diff --git a/src/spf.c b/src/spf.c
index 05fbd53..0b570a0 100644
--- a/src/spf.c
+++ b/src/spf.c
@@ -659,7 +659,7 @@ static spf_term_result
mech_mx(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
{
unsigned long netmask = make_netmask(masklen);
- struct mxbuf mxbuf;
+ struct dns_reply reply;
size_t i;
spf_term_result result = spf_term_nomatch;
const char *domain_spec;
@@ -673,14 +673,14 @@ mech_mx(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
("MX domain_spec=%s, netmask=%lx",
domain_spec, netmask));
- DNS_CATCH(dns_get_mx_records(domain_spec, 1, &mxbuf));
+ DNS_CATCH(dns_get_mx_records(domain_spec, &reply));
- for (i = 0; i < mxbuf.mx_cnt; i++) {
+ for (i = 0; i < reply.count; i++) {
spf_term_arg targ;
spf_term_result res;
targ.type = spf_arg_domain_spec;
- targ.v.domain_spec = mxbuf.mx_buf[i];
+ targ.v.domain_spec = reply.data.str[i];
res = mech_a(dat, &targ, masklen);
if (res == spf_term_match) {
result = res;
@@ -688,7 +688,7 @@ mech_mx(spf_data *dat, spf_term_arg *arg, unsigned long masklen)
}
}
- mxbuf_free(&mxbuf);
+ dns_reply_free(&reply);
return result;
}

Return to:

Send suggestions and report system problems to the System administrator.