diff --git a/src/cares_wrap.cc b/src/cares_wrap.cc index 01d7662e82c..efa83c02d6b 100644 --- a/src/cares_wrap.cc +++ b/src/cares_wrap.cc @@ -401,6 +401,38 @@ class QueryNsWrap: public QueryWrap { }; +class QueryTxtWrap: public QueryWrap { + public: + int Send(const char* name) { + 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* txt_out; + + int status = ares_parse_txt_reply(buf, len, &txt_out); + if (status != ARES_SUCCESS) { + this->ParseError(status); + return; + } + + Local txt_records = Array::New(); + + struct ares_txt_reply *current = txt_out; + for (int i = 0; current; ++i, current = current->next) { + Local txt = String::New(reinterpret_cast(current->txt)); + txt_records->Set(Integer::New(i), txt); + } + + ares_free_data(txt_out); + + this->CallOnComplete(txt_records); + } +}; + + class QuerySrvWrap: public QueryWrap { public: int Send(const char* name) { @@ -576,6 +608,7 @@ static void Initialize(Handle target) { NODE_SET_METHOD(target, "queryCname", Query); NODE_SET_METHOD(target, "queryMx", Query); NODE_SET_METHOD(target, "queryNs", Query); + NODE_SET_METHOD(target, "queryTxt", Query); NODE_SET_METHOD(target, "querySrv", Query); NODE_SET_METHOD(target, "getHostByAddr", Query); NODE_SET_METHOD(target, "getHostByName", QueryWithFamily);