Skip to content
This repository

DNS NAPTR, targets #3177 #4033

Closed
wants to merge 3 commits into from

4 participants

Pavel Lang Saúl Ibarra Corretgé Isaac Z. Schlueter Fedor Indutny
Pavel Lang

Test not working, probably sip.voice.google.com has no NAPTR record?

Can anybody take valid NAPTR query into test?

targets #3177, #3170

@johntdyer, @ssuda can test this?

Saúl Ibarra Corretgé

You can use the sip2sip.info domain.

 dig -t naptr sip2sip.info

; <<>> DiG 9.6-ESV-R4-P3 <<>> -t naptr sip2sip.info
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43840
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 3, ADDITIONAL: 2

;; QUESTION SECTION:
;sip2sip.info.                  IN      NAPTR

;; ANSWER SECTION:
sip2sip.info.           3600    IN      NAPTR   30 100 "s" "SIP+D2U" "" _sip._udp.sip2sip.info.
sip2sip.info.           3600    IN      NAPTR   10 100 "s" "SIP+D2T" "" _sip._tcp.sip2sip.info.
sip2sip.info.           3600    IN      NAPTR   20 100 "s" "SIPS+D2T" "" _sips._tcp.sip2sip.info.

;; AUTHORITY SECTION:
sip2sip.info.           9828    IN      NS      ns7.dns-hosting.info.
sip2sip.info.           9828    IN      NS      ns1.dns-hosting.info.
sip2sip.info.           9828    IN      NS      ns2.dns-hosting.info.

;; ADDITIONAL SECTION:
ns1.dns-hosting.info.   251     IN      A       81.23.228.131
_sip._udp.sip2sip.info. 1974    IN      SRV     100 100 5060 proxy.sipthor.net.

;; Query time: 44 msec
;; SERVER: 192.168.99.101#53(192.168.99.101)
;; WHEN: Wed Oct 24 23:40:42 2012
;; MSG SIZE  rcvd: 304
Pavel Lang

Working, still can be merged without conflicts.
Can someone review? @bnoordhuis @isaacs?

Isaac Z. Schlueter
Collaborator

This looks good to me. (Should be squashed into one commit, but I can do that easily enough.)

I'd like to get #4933 in first, though.

Fedor Indutny
Collaborator

LGTM, squashed and landed as 2ad9872 (with some small style fixes).

Fedor Indutny indutny closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 3 unique commits by 1 author.

Sep 18, 2012
Pavel Lang langpavel DNS: Support NAPTR queries
This reverts commit a90bc78.
3a05f8e
Pavel Lang langpavel Typecasts 195fd37
Oct 25, 2012
Pavel Lang langpavel test DNS NAPTR working 0caf220
This page is out of date. Refresh to see the latest.
1  lib/dns.js
@@ -169,6 +169,7 @@ exports.resolveMx = resolveMap.MX = resolver('queryMx');
169 169 exports.resolveNs = resolveMap.NS = resolver('queryNs');
170 170 exports.resolveTxt = resolveMap.TXT = resolver('queryTxt');
171 171 exports.resolveSrv = resolveMap.SRV = resolver('querySrv');
  172 +exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr');
172 173 exports.reverse = resolveMap.PTR = resolver('getHostByAddr');
173 174
174 175
56 src/cares_wrap.cc
@@ -605,6 +605,61 @@ class QuerySrvWrap: public QueryWrap {
605 605 }
606 606 };
607 607
  608 +class QueryNaptrWrap: public QueryWrap {
  609 + public:
  610 + int Send(const char* name) {
  611 + ares_query(ares_channel,
  612 + name,
  613 + ns_c_in,
  614 + ns_t_naptr,
  615 + Callback,
  616 + GetQueryArg());
  617 + return 0;
  618 + }
  619 +
  620 + protected:
  621 + void Parse(unsigned char* buf, int len) {
  622 + HandleScope scope;
  623 +
  624 + ares_naptr_reply* naptr_start;
  625 + int status = ares_parse_naptr_reply(buf, len, &naptr_start);
  626 +
  627 + if (status != ARES_SUCCESS) {
  628 + this->ParseError(status);
  629 + return;
  630 + }
  631 +
  632 + Local<Array> naptr_records = Array::New();
  633 + Local<String> flags_symbol = String::NewSymbol("flags");
  634 + Local<String> service_symbol = String::NewSymbol("service");
  635 + Local<String> regexp_symbol = String::NewSymbol("regexp");
  636 + Local<String> replacement_symbol = String::NewSymbol("replacement");
  637 + Local<String> order_symbol = String::NewSymbol("order");
  638 + Local<String> preference_symbol = String::NewSymbol("preference");
  639 +
  640 + int i = 0;
  641 + for (ares_naptr_reply* naptr_current = naptr_start;
  642 + naptr_current;
  643 + naptr_current = naptr_current->next) {
  644 +
  645 + Local<Object> naptr_record = Object::New();
  646 +
  647 + naptr_record->Set(flags_symbol, String::New(reinterpret_cast<char*>(naptr_current->flags)));
  648 + naptr_record->Set(service_symbol, String::New(reinterpret_cast<char*>(naptr_current->service)));
  649 + naptr_record->Set(regexp_symbol, String::New(reinterpret_cast<char*>(naptr_current->regexp)));
  650 + naptr_record->Set(replacement_symbol, String::New(naptr_current->replacement));
  651 + naptr_record->Set(order_symbol, Integer::New(naptr_current->order));
  652 + naptr_record->Set(preference_symbol, Integer::New(naptr_current->preference));
  653 +
  654 + naptr_records->Set(Integer::New(i++), naptr_record);
  655 + }
  656 +
  657 + ares_free_data(naptr_start);
  658 +
  659 + this->CallOnComplete(naptr_records);
  660 + }
  661 +};
  662 +
608 663
609 664 class GetHostByAddrWrap: public QueryWrap {
610 665 public:
@@ -882,6 +937,7 @@ static void Initialize(Handle<Object> target) {
882 937 NODE_SET_METHOD(target, "queryNs", Query<QueryNsWrap>);
883 938 NODE_SET_METHOD(target, "queryTxt", Query<QueryTxtWrap>);
884 939 NODE_SET_METHOD(target, "querySrv", Query<QuerySrvWrap>);
  940 + NODE_SET_METHOD(target, "queryNaptr", Query<QueryNaptrWrap>);
885 941 NODE_SET_METHOD(target, "getHostByAddr", Query<GetHostByAddrWrap>);
886 942 NODE_SET_METHOD(target, "getHostByName", QueryWithFamily<GetHostByNameWrap>);
887 943
24 test/internet/test-dns.js
@@ -219,6 +219,30 @@ TEST(function test_resolveSrv(done) {
219 219 checkWrap(req);
220 220 });
221 221
  222 +TEST(function test_resolveNaptr(done) {
  223 + var req = dns.resolveNaptr('sip2sip.info', function(err, result) {
  224 + if (err) throw err;
  225 +
  226 + assert.ok(result.length > 0);
  227 +
  228 + for (var i = 0; i < result.length; i++) {
  229 + var item = result[i];
  230 + assert.ok(item);
  231 + assert.ok(typeof item === 'object');
  232 +
  233 + assert.ok(typeof item.flags === 'string');
  234 + assert.ok(typeof item.service === 'string');
  235 + assert.ok(typeof item.regexp === 'string');
  236 + assert.ok(typeof item.replacement === 'string');
  237 + assert.ok(typeof item.order === 'number');
  238 + assert.ok(typeof item.preference === 'number');
  239 + }
  240 +
  241 + done();
  242 + });
  243 +
  244 + checkWrap(req);
  245 +});
222 246
223 247 TEST(function test_resolveCname(done) {
224 248 var req = dns.resolveCname('www.google.com', function(err, names) {

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.