UNPKG

3.6 kBJavaScriptView Raw
1/*
2Copyright 2011 Timothy J Fontaine <tjfontaine@gmail.com>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
21*/
22
23"use strict";
24
25function reverse_map(src) {
26 var dst = {},
27 k;
28
29 for (k in src) {
30 if (src.hasOwnProperty(k)) {
31 dst[src[k]] = k;
32 }
33 }
34 return dst;
35}
36
37/* http://www.iana.org/assignments/dns-parameters */
38var NAME_TO_QTYPE = exports.NAME_TO_QTYPE = {
39 A: 1,
40 NS: 2,
41 MD: 3,
42 MF: 4,
43 CNAME: 5,
44 SOA: 6,
45 MB: 7,
46 MG: 8,
47 MR: 9,
48 "NULL": 10,
49 WKS: 11,
50 PTR: 12,
51 HINFO: 13,
52 MINFO: 14,
53 MX: 15,
54 TXT: 16,
55 RP: 17,
56 AFSDB: 18,
57 X25: 19,
58 ISDN: 20,
59 RT: 21,
60 NSAP: 22,
61 "NSAP-PTR": 23,
62 SIG: 24,
63 KEY: 25,
64 PX: 26,
65 GPOS: 27,
66 AAAA: 28,
67 LOC: 29,
68 NXT: 30,
69 EID: 31,
70 NIMLOC: 32,
71 SRV: 33,
72 ATMA: 34,
73 NAPTR: 35,
74 KX: 36,
75 CERT: 37,
76 A6: 38,
77 DNAME: 39,
78 SINK: 40,
79 OPT: 41,
80 APL: 42,
81 DS: 43,
82 SSHFP: 44,
83 IPSECKEY: 45,
84 RRSIG: 46,
85 NSEC: 47,
86 DNSKEY: 48,
87 DHCID: 49,
88 NSEC3: 50,
89 NSEC3PARAM: 51,
90 HIP: 55,
91 NINFO: 56,
92 RKEY: 57,
93 TALINK: 58,
94 CDS: 59,
95 SPF: 99,
96 UINFO: 100,
97 UID: 101,
98 GID: 102,
99 UNSPEC: 103,
100 TKEY: 249,
101 TSIG: 250,
102 IXFR: 251,
103 AXFR: 252,
104 MAILB: 253,
105 MAILA: 254,
106 ANY: 255,
107 URI: 256,
108 CAA: 257,
109 TA: 32768,
110 DLV: 32769,
111};
112exports.QTYPE_TO_NAME = reverse_map(NAME_TO_QTYPE);
113
114exports.nameToQtype = function (n) {
115 return NAME_TO_QTYPE[n.toUpperCase()];
116};
117
118exports.qtypeToName = function (t) {
119 return exports.QTYPE_TO_NAME[t];
120};
121
122var NAME_TO_QCLASS = exports.NAME_TO_QCLASS = {
123 IN: 1,
124};
125exports.QCLASS_TO_NAME = reverse_map(NAME_TO_QCLASS);
126
127exports.FAMILY_TO_QTYPE = {
128 4: NAME_TO_QTYPE.A,
129 6: NAME_TO_QTYPE.AAAA,
130};
131exports.QTYPE_TO_FAMILY = {};
132exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.A] = 4;
133exports.QTYPE_TO_FAMILY[exports.NAME_TO_QTYPE.AAAA] = 6;
134
135exports.NAME_TO_RCODE = {
136 NOERROR: 0,
137 FORMERR: 1,
138 SERVFAIL: 2,
139 NOTFOUND: 3,
140 NOTIMP: 4,
141 REFUSED: 5,
142 YXDOMAIN: 6, //Name Exists when it should not
143 YXRRSET: 7, //RR Set Exists when it should not
144 NXRRSET: 8, //RR Set that should exist does not
145 NOTAUTH: 9,
146 NOTZONE: 10,
147 BADVERS: 16,
148 BADSIG: 16, // really?
149 BADKEY: 17,
150 BADTIME: 18,
151 BADMODE: 19,
152 BADNAME: 20,
153 BADALG: 21,
154 BADTRUNC: 22,
155};
156exports.RCODE_TO_NAME = reverse_map(exports.NAME_TO_RCODE);
157
158exports.BADNAME = 'EBADNAME';
159exports.BADRESP = 'EBADRESP';
160exports.CONNREFUSED = 'ECONNREFUSED';
161exports.DESTRUCTION = 'EDESTRUCTION';
162exports.REFUSED = 'EREFUSED';
163exports.FORMERR = 'EFORMERR';
164exports.NODATA = 'ENODATA';
165exports.NOMEM = 'ENOMEM';
166exports.NOTFOUND = 'ENOTFOUND';
167exports.NOTIMP = 'ENOTIMP';
168exports.SERVFAIL = 'ESERVFAIL';
169exports.TIMEOUT = 'ETIMEOUT';