From: Ben Noordhuis Date: Tue, 15 Oct 2013 10:51:12 +0000 (+0200) Subject: dns: rename domain to hostname X-Git-Tag: v0.11.8~27 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ceb8740a636e59b1e34cb3db0c3c4c79bb501dfa;p=platform%2Fupstream%2Fnodejs.git dns: rename domain to hostname A follow-up commit will save the domain name on the request object but we can't call that property 'domain' because that gets intercepted by src/node.cc and lib/domain.js to implement the node.js feature of the same name. To avoid confusion, rename all variables called 'domain' to 'hostname'. --- diff --git a/doc/api/dns.markdown b/doc/api/dns.markdown index 8d2c401..805188c 100644 --- a/doc/api/dns.markdown +++ b/doc/api/dns.markdown @@ -21,19 +21,19 @@ resolves the IP addresses which are returned. console.log('addresses: ' + JSON.stringify(addresses)); addresses.forEach(function (a) { - dns.reverse(a, function (err, domains) { + dns.reverse(a, function (err, hostnames) { if (err) { throw err; } - console.log('reverse for ' + a + ': ' + JSON.stringify(domains)); + console.log('reverse for ' + a + ': ' + JSON.stringify(hostnames)); }); }); }); -## dns.lookup(domain, [family], callback) +## dns.lookup(hostname, [family], callback) -Resolves a domain (e.g. `'google.com'`) into the first found A (IPv4) or +Resolves a hostname (e.g. `'google.com'`) into the first found A (IPv4) or AAAA (IPv6) record. The `family` can be the integer `4` or `6`. Defaults to `null` that indicates both Ip v4 and v6 address family. @@ -45,13 +45,13 @@ necessarily the value initially passed to `lookup`). On error, `err` is an `Error` object, where `err.code` is the error code. Keep in mind that `err.code` will be set to `'ENOENT'` not only when -the domain does not exist but also when the lookup fails in other ways +the hostname does not exist but also when the lookup fails in other ways such as no available file descriptors. -## dns.resolve(domain, [rrtype], callback) +## dns.resolve(hostname, [rrtype], callback) -Resolves a domain (e.g. `'google.com'`) into an array of the record types +Resolves a hostname (e.g. `'google.com'`) into an array of the record types specified by rrtype. Valid rrtypes are `'A'` (IPV4 addresses, default), `'AAAA'` (IPV6 addresses), `'MX'` (mail exchange records), `'TXT'` (text records), `'SRV'` (SRV records), `'PTR'` (used for reverse IP lookups), @@ -65,54 +65,54 @@ On error, `err` is an `Error` object, where `err.code` is one of the error codes listed below. -## dns.resolve4(domain, callback) +## dns.resolve4(hostname, callback) The same as `dns.resolve()`, but only for IPv4 queries (`A` records). `addresses` is an array of IPv4 addresses (e.g. `['74.125.79.104', '74.125.79.105', '74.125.79.106']`). -## dns.resolve6(domain, callback) +## dns.resolve6(hostname, callback) The same as `dns.resolve4()` except for IPv6 queries (an `AAAA` query). -## dns.resolveMx(domain, callback) +## dns.resolveMx(hostname, callback) The same as `dns.resolve()`, but only for mail exchange queries (`MX` records). `addresses` is an array of MX records, each with a priority and an exchange attribute (e.g. `[{'priority': 10, 'exchange': 'mx.example.com'},...]`). -## dns.resolveTxt(domain, callback) +## dns.resolveTxt(hostname, callback) The same as `dns.resolve()`, but only for text queries (`TXT` records). -`addresses` is an array of the text records available for `domain` (e.g., +`addresses` is an array of the text records available for `hostname` (e.g., `['v=spf1 ip4:0.0.0.0 ~all']`). -## dns.resolveSrv(domain, callback) +## dns.resolveSrv(hostname, callback) The same as `dns.resolve()`, but only for service records (`SRV` records). -`addresses` is an array of the SRV records available for `domain`. Properties +`addresses` is an array of the SRV records available for `hostname`. Properties of SRV records are priority, weight, port, and name (e.g., `[{'priority': 10, {'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]`). -## dns.resolveNs(domain, callback) +## dns.resolveNs(hostname, callback) The same as `dns.resolve()`, but only for name server records (`NS` records). -`addresses` is an array of the name server records available for `domain` +`addresses` is an array of the name server records available for `hostname` (e.g., `['ns1.example.com', 'ns2.example.com']`). -## dns.resolveCname(domain, callback) +## dns.resolveCname(hostname, callback) The same as `dns.resolve()`, but only for canonical name records (`CNAME` records). `addresses` is an array of the canonical name records available for -`domain` (e.g., `['bar.example.com']`). +`hostname` (e.g., `['bar.example.com']`). ## dns.reverse(ip, callback) -Reverse resolves an ip address to an array of domain names. +Reverse resolves an ip address to an array of hostnames. -The callback has arguments `(err, domains)`. +The callback has arguments `(err, hostnames)`. On error, `err` is an `Error` object, where `err.code` is one of the error codes listed below. @@ -143,7 +143,7 @@ Each DNS query can return one of the following error codes: - `dns.NOTIMP`: DNS server does not implement requested operation. - `dns.REFUSED`: DNS server refused query. - `dns.BADQUERY`: Misformatted DNS query. -- `dns.BADNAME`: Misformatted domain name. +- `dns.BADNAME`: Misformatted hostname. - `dns.BADFAMILY`: Unsupported address family. - `dns.BADRESP`: Misformatted DNS reply. - `dns.CONNREFUSED`: Could not contact DNS servers. @@ -160,4 +160,3 @@ Each DNS query can return one of the following error codes: - `dns.LOADIPHLPAPI`: Error loading iphlpapi.dll. - `dns.ADDRGETNETWORKPARAMS`: Could not find GetNetworkParams function. - `dns.CANCELLED`: DNS query cancelled. - diff --git a/lib/dns.js b/lib/dns.js index 3e4b90f..9ced633 100644 --- a/lib/dns.js +++ b/lib/dns.js @@ -94,8 +94,8 @@ function onlookup(err, addresses) { // Easy DNS A/AAAA look up -// lookup(domain, [family,] callback) -exports.lookup = function(domain, family, callback) { +// lookup(hostname, [family,] callback) +exports.lookup = function(hostname, family, callback) { // parse arguments if (arguments.length === 2) { callback = family; @@ -110,7 +110,7 @@ exports.lookup = function(domain, family, callback) { } callback = makeAsync(callback); - if (!domain) { + if (!hostname) { callback(null, null, family === 6 ? 6 : 4); return {}; } @@ -119,14 +119,14 @@ exports.lookup = function(domain, family, callback) { // localhost entry from c:\WINDOWS\system32\drivers\etc\hosts // See http://daniel.haxx.se/blog/2011/02/21/localhost-hack-on-windows/ // TODO Remove this once c-ares handles this problem. - if (process.platform == 'win32' && domain == 'localhost') { + if (process.platform == 'win32' && hostname == 'localhost') { callback(null, '127.0.0.1', 4); return {}; } - var matchedFamily = net.isIP(domain); + var matchedFamily = net.isIP(hostname); if (matchedFamily) { - callback(null, domain, matchedFamily); + callback(null, hostname, matchedFamily); return {}; } @@ -135,7 +135,7 @@ exports.lookup = function(domain, family, callback) { family: family, oncomplete: onlookup }; - var err = cares.getaddrinfo(req, domain, family); + var err = cares.getaddrinfo(req, hostname, family); if (err) throw errnoException(err, 'getaddrinfo'); callback.immediately = true; @@ -181,7 +181,7 @@ exports.resolveNaptr = resolveMap.NAPTR = resolver('queryNaptr'); exports.reverse = resolveMap.PTR = resolver('getHostByAddr'); -exports.resolve = function(domain, type_, callback_) { +exports.resolve = function(hostname, type_, callback_) { var resolver, callback; if (util.isString(type_)) { resolver = resolveMap[type_]; @@ -192,7 +192,7 @@ exports.resolve = function(domain, type_, callback_) { } if (util.isFunction(resolver)) { - return resolver(domain, callback); + return resolver(hostname, callback); } else { throw new Error('Unknown type "' + type_ + '"'); }