Browse Source

Add support for MX queries in dns module, works with c-ares upstream patch.

v0.7.4-release
Jérémy Lal 15 years ago
committed by Ryan Dahl
parent
commit
5caf53a053
  1. 2
      lib/dns.js
  2. 35
      src/node_cares.cc
  3. 2
      test/disabled/test-dns.js

2
lib/dns.js

@ -124,6 +124,7 @@ exports.lookup = function (domain, callback) {
exports.resolve4 = function(domain, callback) { channel.query(domain, dns.A, callback) }; exports.resolve4 = function(domain, callback) { channel.query(domain, dns.A, callback) };
exports.resolve6 = function(domain, callback) { channel.query(domain, dns.AAAA, callback) }; exports.resolve6 = function(domain, callback) { channel.query(domain, dns.AAAA, callback) };
exports.resolveMx = function(domain, callback) { channel.query(domain, dns.MX, callback) };
exports.resolveTxt = function(domain, callback) { channel.query(domain, dns.TXT, callback) }; exports.resolveTxt = function(domain, callback) { channel.query(domain, dns.TXT, callback) };
exports.resolveSrv = function(domain, callback) { channel.query(domain, dns.SRV, callback) }; exports.resolveSrv = function(domain, callback) { channel.query(domain, dns.SRV, callback) };
exports.reverse = function(domain, callback) { channel.query(domain, dns.PTR, callback) }; exports.reverse = function(domain, callback) { channel.query(domain, dns.PTR, callback) };
@ -133,6 +134,7 @@ exports.resolveNs = function(domain, callback) { channel.query(domain, dns.NS,
var resolveMap = { var resolveMap = {
'A' : exports.resolve4, 'A' : exports.resolve4,
'AAAA': exports.resolve6, 'AAAA': exports.resolve6,
'MX' : exports.resolveMx,
'TXT' : exports.resolveTxt, 'TXT' : exports.resolveTxt,
'SRV' : exports.resolveSrv, 'SRV' : exports.resolveSrv,
'PTR' : exports.resolvePtr, 'PTR' : exports.resolvePtr,

35
src/node_cares.cc

@ -86,6 +86,7 @@ static Persistent<String> weight_symbol;
static Persistent<String> port_symbol; static Persistent<String> port_symbol;
static Persistent<String> name_symbol; static Persistent<String> name_symbol;
static Persistent<String> callback_symbol; static Persistent<String> callback_symbol;
static Persistent<String> exchange_symbol;
void Cares::Initialize(Handle<Object> target) { void Cares::Initialize(Handle<Object> target) {
@ -105,12 +106,14 @@ void Cares::Initialize(Handle<Object> target) {
weight_symbol = NODE_PSYMBOL("weight"); weight_symbol = NODE_PSYMBOL("weight");
port_symbol = NODE_PSYMBOL("port"); port_symbol = NODE_PSYMBOL("port");
name_symbol = NODE_PSYMBOL("name"); name_symbol = NODE_PSYMBOL("name");
exchange_symbol = NODE_PSYMBOL("exchange");
target->Set(String::NewSymbol("AF_INET"), Integer::New(AF_INET)); target->Set(String::NewSymbol("AF_INET"), Integer::New(AF_INET));
target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6)); target->Set(String::NewSymbol("AF_INET6"), Integer::New(AF_INET6));
target->Set(String::NewSymbol("A"), Integer::New(ns_t_a)); target->Set(String::NewSymbol("A"), Integer::New(ns_t_a));
target->Set(String::NewSymbol("AAAA"), Integer::New(ns_t_aaaa)); target->Set(String::NewSymbol("AAAA"), Integer::New(ns_t_aaaa));
target->Set(String::NewSymbol("MX"), Integer::New(ns_t_mx));
target->Set(String::NewSymbol("NS"), Integer::New(ns_t_ns)); target->Set(String::NewSymbol("NS"), Integer::New(ns_t_ns));
target->Set(String::NewSymbol("PTR"), Integer::New(ns_t_ptr)); target->Set(String::NewSymbol("PTR"), Integer::New(ns_t_ptr));
target->Set(String::NewSymbol("TXT"), Integer::New(ns_t_txt)); target->Set(String::NewSymbol("TXT"), Integer::New(ns_t_txt));
@ -288,6 +291,34 @@ static void ParseAnswerAAAA(QueryArg *arg, unsigned char* abuf, int alen) {
cb_call(arg->js_cb, 2, argv); cb_call(arg->js_cb, 2, argv);
} }
static void ParseAnswerMX(QueryArg *arg, unsigned char* abuf, int alen) {
HandleScope scope;
struct ares_mx_reply *mx_out;
int status = ares_parse_mx_reply(abuf, alen, &mx_out);
if (status != ARES_SUCCESS) {
ResolveError(arg->js_cb, status);
return;
}
Local<Array> mx_records = Array::New();
struct ares_mx_reply *current = mx_out;
for (int i = 0; current; ++i, current = current->next) {
Local<Object> mx = Object::New();
mx->Set(priority_symbol, Integer::New(current->priority));
mx->Set(exchange_symbol, String::New(current->host));
mx_records->Set(Integer::New(i), mx);
}
ares_free_data(mx_out);
Local<Value> argv[2] = { Local<Value>::New(Null()), mx_records };
cb_call(arg->js_cb, 2, argv);
}
static void ParseAnswerNS(QueryArg *arg, unsigned char* abuf, int alen) { static void ParseAnswerNS(QueryArg *arg, unsigned char* abuf, int alen) {
HandleScope scope; HandleScope scope;
@ -471,6 +502,10 @@ Handle<Value> Channel::Query(const Arguments& args) {
parse_cb = ParseAnswerAAAA; parse_cb = ParseAnswerAAAA;
break; break;
case ns_t_mx:
parse_cb = ParseAnswerMX;
break;
case ns_t_ns: case ns_t_ns:
parse_cb = ParseAnswerNS; parse_cb = ParseAnswerNS;
break; break;

2
test/disabled/test-dns.js

@ -21,7 +21,7 @@ var hosts = ['example.com', 'example.org',
'_xmpp-client._tcp.google.com', // SRV '_xmpp-client._tcp.google.com', // SRV
'oakalynhall.co.uk']; // Multiple PTR replies 'oakalynhall.co.uk']; // Multiple PTR replies
var records = ['A', 'AAAA', 'TXT', 'SRV']; var records = ['A', 'AAAA', 'MX', 'TXT', 'SRV'];
var i = hosts.length; var i = hosts.length;
while (i--) { while (i--) {

Loading…
Cancel
Save