Skip to content

Commit 6931c39

Browse files
committed
Docs added (NAPTR type), code style fixes
1 parent 5dcc817 commit 6931c39

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

README.markdown

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Table of Contents
2828
* [TYPE_TXT](#type_txt)
2929
* [TYPE_AAAA](#type_aaaa)
3030
* [TYPE_SRV](#type_srv)
31+
* [TYPE_NAPTR](#type_naptr)
3132
* [TYPE_SPF](#type_spf)
3233
* [CLASS_IN](#class_in)
3334
* [SECTION_AN](#section_an)
@@ -373,6 +374,16 @@ See RFC 2782 for details.
373374

374375
[Back to TOC](#table-of-contents)
375376

377+
TYPE_NAPTR
378+
----------
379+
`syntax: typ = r.TYPE_NAPTR`
380+
381+
The `NAPTR` resource record type, equal to the decimal number `35`.
382+
383+
See RFC 2915 for details.
384+
385+
[Back to TOC](#table-of-contents)
386+
376387
TYPE_SPF
377388
---------
378389
`syntax: typ = r.TYPE_SPF`

lib/resty/dns/resolver.lua

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -211,17 +211,22 @@ local function _encode_name(s)
211211
return char(#s) .. s
212212
end
213213

214+
214215
local function _decode_string(buf, pos)
215216
local slen = byte(buf, pos)
217+
216218
if slen == 0 then
217219
return "", pos + 1
218220
end
221+
219222
if pos + 1 + slen >= #buf then
220223
return nil, 'truncated'
221224
end
225+
222226
return sub(buf, pos + 1, pos + slen), pos + slen + 1
223227
end
224228

229+
225230
local function _decode_name(buf, pos)
226231
local labels = {}
227232
local nptrs = 0
@@ -501,34 +506,43 @@ local function parse_section(answers, section, buf, start_pos, size,
501506
return nil, "bad NAPTR record value length: " .. len
502507
end
503508

504-
local hi = byte(buf, pos)
505-
local lo = byte(buf, pos + 1)
506-
ans.order = lshift(hi, 8) + lo
509+
local order_hi = byte(buf, pos)
510+
local order_lo = byte(buf, pos + 1)
511+
ans.order = lshift(order_hi, 8) + order_lo
507512

508-
hi = byte(buf, pos + 2)
509-
lo = byte(buf, pos + 3)
510-
ans.preference = lshift(hi, 8) + lo
513+
local preference_hi = byte(buf, pos + 2)
514+
local preference_lo = byte(buf, pos + 3)
515+
ans.preference = lshift(preference_hi, 8) + preference_lo
511516

512-
local str, p = _decode_string(buf, pos + 4)
513-
if not str then return nil, pos end
514-
ans.flags = str
517+
local flags_str, p = _decode_string(buf, pos + 4)
518+
if not flags_str then
519+
return nil, pos
520+
end
521+
ans.flags = flags_str
515522

516-
str, p = _decode_string(buf, p)
517-
if not str then return nil, pos end
518-
ans.services = str
523+
local services_str, p = _decode_string(buf, p)
524+
if not services_str then
525+
return nil, pos
526+
end
527+
ans.services = services_str
519528

520-
str, p = _decode_string(buf, p)
521-
if not str then return nil, pos end
522-
ans.regexp = str
529+
local regexp_str, p = _decode_string(buf, p)
530+
if not regexp_str then
531+
return nil, pos
532+
end
533+
ans.regexp = regexp_str
523534

524535
if p - pos < len then
525-
str,p = _decode_name(buf, p)
526-
if not str then return nil, pos end
527-
ans.replacements = str
536+
local replacements_str,p = _decode_name(buf, p)
537+
if not replacements_str
538+
then return nil, pos
539+
end
540+
ans.replacements = replacements_str
528541
end
529542

530543
if p - pos ~= len then
531-
return nil, format("bad NAPTR record length: %d ~= %d", p - pos, len)
544+
return nil, format("bad NAPTR record length: %d ~= %d",
545+
p - pos, len)
532546
end
533547

534548
pos = p

0 commit comments

Comments
 (0)