diff options
Diffstat (limited to 'src/builtin/dns.bi')
-rw-r--r-- | src/builtin/dns.bi | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/src/builtin/dns.bi b/src/builtin/dns.bi index c23aaf31..f63a2361 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 |