From dd7d46e7a497e450ee94401428b177fb765bfec4 Mon Sep 17 00:00:00 2001 From: jons Date: Thu, 29 May 2014 00:11:31 +0000 Subject: [PATCH] add support for SPF records to DNS resolver --- lib/dns.js | 1 + src/cares_wrap.cc | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/dns.js b/lib/dns.js index ab80deb817e..25bda7b4f75 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -180,6 +180,7 @@ exports.resolveCname = resolveMap.CNAME = resolver('queryCname'); exports.resolveMx = resolveMap.MX = resolver('queryMx'); exports.resolveNs = resolveMap.NS = resolver('queryNs'); exports.resolveTxt = resolveMap.TXT = resolver('queryTxt'); +exports.resolveSpf = resolveMap.SPF = resolver('querySpf'); exports.resolveSrv = resolveMap.SRV = resolver('querySrv'); exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr'); exports.resolveSoa = resolveMap.SOA = resolver('querySoa'); diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 0f5987b01ab..146fb760531 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -601,6 +601,39 @@ class QueryTxtWrap: public QueryWrap { }; +class QuerySpfWrap: public QueryWrap { + public: + int Send(const char* name) { + // TODO: change ns_t_txt to ns_t_spf when arpa/nameser.h gets updated + ares_query(ares_channel, name, ns_c_in, ns_t_txt, Callback, GetQueryArg()); + return 0; + } + + protected: + void Parse(unsigned char* buf, int len) { + struct ares_txt_reply* spf_out; + + int status = ares_parse_txt_reply(buf, len, &spf_out); + if (status != ARES_SUCCESS) { + this->ParseError(status); + return; + } + + Local spf_records = Array::New(); + + struct ares_txt_reply *current = spf_out; + for (int i = 0; current; ++i, current = current->next) { + Local spf = String::New(reinterpret_cast(current->txt)); + spf_records->Set(Integer::New(i), spf); + } + + ares_free_data(spf_out); + + this->CallOnComplete(spf_records); + } +}; + + class QuerySrvWrap: public QueryWrap { public: explicit QuerySrvWrap(Environment* env, Local req_wrap_obj) @@ -1159,6 +1192,7 @@ static void Initialize(Handle target, NODE_SET_METHOD(target, "queryMx", Query); NODE_SET_METHOD(target, "queryNs", Query); NODE_SET_METHOD(target, "queryTxt", Query); + NODE_SET_METHOD(target, "querySpf", Query); NODE_SET_METHOD(target, "querySrv", Query); NODE_SET_METHOD(target, "queryNaptr", Query); NODE_SET_METHOD(target, "querySoa", Query);