Software /
code /
prosody
Comparison
net/dns.lua @ 8902:ac21f13798ae
Merge 0.10->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 09 Jun 2018 15:47:59 +0200 |
parent | 8555:4f0f5b49bb03 |
parent | 8901:eae606b9266c |
child | 8903:c5d5dfaa8d38 |
comparison
equal
deleted
inserted
replaced
8896:739deb514140 | 8902:ac21f13798ae |
---|---|
86 local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte | 86 local function highbyte(i) -- - - - - - - - - - - - - - - - - - - highbyte |
87 return (i-(i%0x100))/0x100; | 87 return (i-(i%0x100))/0x100; |
88 end | 88 end |
89 | 89 |
90 | 90 |
91 local function augment (t) -- - - - - - - - - - - - - - - - - - - - augment | 91 local function augment (t, prefix) -- - - - - - - - - - - - - - - - - augment |
92 local a = {}; | 92 local a = {}; |
93 for i,s in pairs(t) do | 93 for i = 1, 0xffff do |
94 local s = t[i] or ("%s%d"):format(prefix, i); | |
94 a[i] = s; | 95 a[i] = s; |
95 a[s] = s; | 96 a[s] = s; |
96 a[string.lower(s)] = s; | 97 a[string.lower(s)] = s; |
97 end | 98 end |
98 return a; | 99 return a; |
119 | 120 |
120 | 121 |
121 dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; | 122 dns.classes = { 'IN', 'CS', 'CH', 'HS', [255] = '*' }; |
122 | 123 |
123 | 124 |
124 dns.type = augment (dns.types); | 125 dns.type = augment (dns.types, "TYPE"); |
125 dns.class = augment (dns.classes); | 126 dns.class = augment (dns.classes, "CLASS"); |
126 dns.typecode = encode (dns.types); | 127 dns.typecode = encode (dns.types); |
127 dns.classcode = encode (dns.classes); | 128 dns.classcode = encode (dns.classes); |
128 | 129 |
129 | 130 |
130 | 131 |
684 end | 685 end |
685 | 686 |
686 self.cache = self.cache or setmetatable({}, cache_metatable); | 687 self.cache = self.cache or setmetatable({}, cache_metatable); |
687 local rrs = get(self.cache, qclass, type, qname) or | 688 local rrs = get(self.cache, qclass, type, qname) or |
688 set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); | 689 set(self.cache, qclass, type, qname, setmetatable({}, rrs_metatable)); |
689 if not rrs[rr[qtype:lower()]] then | 690 if rr[qtype:lower()] and not rrs[rr[qtype:lower()]] then |
690 rrs[rr[qtype:lower()]] = true; | 691 rrs[rr[qtype:lower()]] = true; |
691 append(rrs, rr); | 692 append(rrs, rr); |
692 end | 693 end |
693 | 694 |
694 if type == 'MX' then self.unsorted[rrs] = true; end | 695 if type == 'MX' then self.unsorted[rrs] = true; end |
901 and self.active[response.header.id][response.question.raw] then | 902 and self.active[response.header.id][response.question.raw] then |
902 --print('received response'); | 903 --print('received response'); |
903 --self.print(response); | 904 --self.print(response); |
904 | 905 |
905 for _, rr in pairs(response.answer) do | 906 for _, rr in pairs(response.answer) do |
906 self:remember(rr, response.question[1].type); | 907 self:remember(rr, rr.type); |
908 end | |
909 | |
910 for _, rr in pairs(response.additional) do | |
911 self:remember(rr, rr.type); | |
907 end | 912 end |
908 | 913 |
909 -- retire the query | 914 -- retire the query |
910 local queries = self.active[response.header.id]; | 915 local queries = self.active[response.header.id]; |
911 queries[response.question.raw] = nil; | 916 queries[response.question.raw] = nil; |