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/builtin/dns.bi | |
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/builtin/dns.bi')
-rw-r--r-- | src/builtin/dns.bi | 74 |
1 files changed, 29 insertions, 45 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), |