0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

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

This commit is contained in:
Jérémy Lal 2010-04-26 22:26:16 +02:00 committed by Ryan Dahl
parent 14d1ab5a3e
commit 5caf53a053
3 changed files with 38 additions and 1 deletions

View File

@ -124,6 +124,7 @@ exports.lookup = function (domain, callback) {
exports.resolve4 = function(domain, callback) { channel.query(domain, dns.A, 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.resolveSrv = function(domain, callback) { channel.query(domain, dns.SRV, 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 = {
'A' : exports.resolve4,
'AAAA': exports.resolve6,
'MX' : exports.resolveMx,
'TXT' : exports.resolveTxt,
'SRV' : exports.resolveSrv,
'PTR' : exports.resolvePtr,

View File

@ -86,6 +86,7 @@ static Persistent<String> weight_symbol;
static Persistent<String> port_symbol;
static Persistent<String> name_symbol;
static Persistent<String> callback_symbol;
static Persistent<String> exchange_symbol;
void Cares::Initialize(Handle<Object> target) {
@ -105,12 +106,14 @@ void Cares::Initialize(Handle<Object> target) {
weight_symbol = NODE_PSYMBOL("weight");
port_symbol = NODE_PSYMBOL("port");
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_INET6"), Integer::New(AF_INET6));
target->Set(String::NewSymbol("A"), Integer::New(ns_t_a));
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("PTR"), Integer::New(ns_t_ptr));
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);
}
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) {
HandleScope scope;
@ -471,6 +502,10 @@ Handle<Value> Channel::Query(const Arguments& args) {
parse_cb = ParseAnswerAAAA;
break;
case ns_t_mx:
parse_cb = ParseAnswerMX;
break;
case ns_t_ns:
parse_cb = ParseAnswerNS;
break;

View File

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