Skip to content

Commit

Permalink
feature: added support for TXT queries and records.
Browse files Browse the repository at this point in the history
  • Loading branch information
agentzh committed Aug 24, 2012
1 parent 164f3a3 commit d40f290
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ which usually takes some of the following fields:
A domain-name which specifies a host which should be authoritative for the specified class and domain. Usually present for `NS` type records.
* `rdata`
The raw resource data (RDATA) for resource records that are not recognized.
* `txt`
The record value for `TXT` records.

This method also takes an optional `options` argument table, which takes the following fields:

Expand Down Expand Up @@ -192,6 +194,11 @@ TYPE_NS

The `NS` resource record type, equal to the decimal number `2`.

TYPE_TXT
--------

The `TXT` resource record type, equal to the decimal number `16`.

TYPE_AAAA
---------
`syntax: typ = r.TYPE_AAAA`
Expand Down Expand Up @@ -222,7 +229,7 @@ TODO
====

* Concurrent (or parallel) query mode
* Better support for other resource record types like `PTR`, and `TXT`.
* Better support for other resource record types like `PTR`.
* Support for the DNS inverse queries

Author
Expand Down
6 changes: 6 additions & 0 deletions lib/resty/dns/resolver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TYPE_A = 1
TYPE_NS = 2
TYPE_CNAME = 5
TYPE_MX = 15
TYPE_TXT = 16
TYPE_AAAA = 28

CLASS_IN = 1
Expand Down Expand Up @@ -509,6 +510,11 @@ local function parse_response(buf, id)

ans.nsdname = name

elseif typ == TYPE_TXT then

ans.txt = substr(buf, pos, pos + len - 1)
pos = pos + len

else
-- for unknown types, just forward the raw value

Expand Down
64 changes: 64 additions & 0 deletions t/sanity.t
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,67 @@ GET /t
--- no_error_log
[error]



=== TEST 8: TXT query (no ans)
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resolver = require "resty.dns.resolver"
local r, err = resolver:new{ nameservers = { "$TEST_NGINX_RESOLVER" } }
if not r then
ngx.say("failed to instantiate resolver: ", err)
return
end
local ans, err = r:query("agentzh.org", { qtype = r.TYPE_TXT })
if not ans then
ngx.say("failed to query: ", err)
return
end
local cjson = require "cjson"
ngx.say("records: ", cjson.encode(ans))
';
}
--- request
GET /t
--- response_body
records: {}
--- no_error_log
[error]



=== TEST 9: TXT query (with ans)
--- http_config eval: $::HttpConfig
--- config
location /t {
content_by_lua '
local resolver = require "resty.dns.resolver"
local r, err = resolver:new{ nameservers = { "$TEST_NGINX_RESOLVER" } }
if not r then
ngx.say("failed to instantiate resolver: ", err)
return
end
local ans, err = r:query("gmail.com", { qtype = r.TYPE_TXT })
if not ans then
ngx.say("failed to query: ", err)
return
end
local cjson = require "cjson"
ngx.say("records: ", cjson.encode(ans))
';
}
--- request
GET /t
--- response_body_like chop
^records: \[\{.*?"txt":"[^"]+".*?\}\]$
--- no_error_log
[error]

0 comments on commit d40f290

Please sign in to comment.