diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-20 19:32:28 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-10-20 19:32:28 +0300 |
commit | b74300677afd3f489f6dc65959f722be28c2804b (patch) | |
tree | 39afd042f53ed37160031e2da1298d479be63765 /src | |
parent | ef49628b07df9ddb5f6035fc4941a10136a73b22 (diff) | |
download | mailfromd-b74300677afd3f489f6dc65959f722be28c2804b.tar.gz mailfromd-b74300677afd3f489f6dc65959f722be28c2804b.tar.bz2 |
Improve DNS API consistency
* lib/dns.c (dns_get_mx_records, getmx, getmxip): Replace
with a single function mx_lookup. All uses updated.
Diffstat (limited to 'src')
-rw-r--r-- | src/builtin/dns.bi | 74 | ||||
-rw-r--r-- | src/callout.c | 2 | ||||
-rw-r--r-- | src/prog.c | 2 | ||||
-rw-r--r-- | src/spf.c | 2 |
4 files changed, 32 insertions, 48 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi index 4bde9676..8d28748a 100644 --- a/src/builtin/dns.bi +++ b/src/builtin/dns.bi @@ -152,7 +152,7 @@ MF_DEFUN(primitive_hasmx, NUMBER, STRING string) struct dns_reply repl; mf_status mxstat; - mxstat = getmx(string, &repl); + mxstat = dns_to_mf_status(mx_lookup(string, 0, &repl)); MF_ASSERT(mxstat == mf_success || mxstat == mf_not_found, mf_status_to_exception(mxstat), @@ -166,57 +166,41 @@ MF_DEFUN(primitive_hasmx, NUMBER, STRING string) } END -MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER no_resolve) +MF_DEFUN(getmx, STRING, STRING domain, OPTIONAL, NUMBER resolve) { mf_status mxstat; struct dns_reply reply; - - if (MF_OPTVAL(no_resolve)) { - mxstat = getmxip(domain, &reply); - if (!mf_resolved(mxstat)) { - MF_THROW(mf_status_to_exception(mxstat), - _("cannot get MX records for %s"), domain); - } - if (mxstat == mf_not_found) { - MF_RETURN(""); - } else { - int i; + int i; + + mxstat = dns_to_mf_status(mx_lookup(domain, MF_OPTVAL(resolve), + &reply)); + if (!mf_resolved(mxstat)) { + MF_THROW(mf_status_to_exception(mxstat), + _("cannot get MX records for %s"), domain); + } + if (mxstat == mf_not_found) { + MF_RETURN(""); + } else if (reply.type == dns_reply_ip) { + MF_OBSTACK_BEGIN(); + for (i = 0; i < reply.count; i++) { + struct in_addr s; + s.s_addr = htonl(reply.data.ip[i]); - MF_OBSTACK_BEGIN(); - for (i = 0; i < reply.count; i++) { - struct in_addr s; - s.s_addr = htonl(reply.data.ip[i]); - - if (i > 0) - MF_OBSTACK_1GROW(' '); - MF_OBSTACK_GROW(inet_ntoa(s)); - } - MF_OBSTACK_1GROW(0); - dns_reply_free(&reply); - MF_RETURN_OBSTACK(); + if (i > 0) + MF_OBSTACK_1GROW(' '); + MF_OBSTACK_GROW(inet_ntoa(s)); } } else { - mxstat = getmx(domain, &reply); - if (!mf_resolved(mxstat)) { - MF_THROW(mf_status_to_exception(mxstat), - _("cannot get MX records for %s"), domain); - } - if (mxstat == mf_not_found) { - MF_RETURN(""); - } else { - int i; - - MF_OBSTACK_BEGIN(); - for (i = 0; i < reply.count; i++) { - if (i > 0) - MF_OBSTACK_1GROW(' '); - MF_OBSTACK_GROW(reply.data.str[i]); - } - MF_OBSTACK_1GROW(0); - dns_reply_free(&reply); - MF_RETURN_OBSTACK(); + MF_OBSTACK_BEGIN(); + for (i = 0; i < reply.count; i++) { + if (i > 0) + MF_OBSTACK_1GROW(' '); + MF_OBSTACK_GROW(reply.data.str[i]); } } + MF_OBSTACK_1GROW(0); + dns_reply_free(&reply); + MF_RETURN_OBSTACK(); } END @@ -259,7 +243,7 @@ MF_DEFUN(primitive_ismx, NUMBER, STRING domain, STRING ipstr) _("cannot resolve host name %s"), ipstr); ip = ntohl(ip); - mxstat = getmxip(domain, &reply); + mxstat = dns_to_mf_status(mx_lookup(domain, 1, &reply)); if (mxstat != mf_success) { MF_THROW(mf_status_to_exception(mxstat), diff --git a/src/callout.c b/src/callout.c index 1d46bc70..8b7cd3c1 100644 --- a/src/callout.c +++ b/src/callout.c @@ -637,7 +637,7 @@ callout_mx(struct smtp_io_data *iop, const char *hostname, int *pcount) struct dns_reply reply; mf_status rc, mxstat; - mxstat = getmx(hostname, &reply); + mxstat = dns_to_mf_status(mx_lookup(hostname, 0, &reply)); if (pcount) *pcount = 0; @@ -1602,7 +1602,7 @@ mx_match(eval_environ_t env, char *string, p++; else p = string; - mxstat = getmx(p, &reply); + mxstat = dns_to_mf_status(mx_lookup(p, 0, &reply)); rc = 0; if (mxstat == mf_success) { int i; @@ -672,7 +672,7 @@ 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, &reply)); + DNS_CATCH(mx_lookup(domain_spec, 0, &reply)); for (i = 0; i < reply.count; i++) { spf_term_arg targ; |