Skip to content
Snippets Groups Projects
Verified Commit adaccb7f authored by Marek Vavruša's avatar Marek Vavruša Committed by Vladimír Čunát
Browse files

kres: added rr:rdcount() and tests

parent c4037c24
Branches
Tags
1 merge request!519Restore cache insert RR API
......@@ -256,7 +256,7 @@ end
-- RR sets created in Lua must have a destructor to release allocated memory
local function rrset_free(rr)
if rr._owner ~= nil then ffi.C.free(rr._owner) end
if rr.rrs.rr_count > 0 then ffi.C.free(rr.rrs.data) end
if rr:rdcount() > 0 then ffi.C.free(rr.rrs.data) end
end
-- Metatype for RR set. Beware, the indexing is 0-based (rdata, get, tostring).
......@@ -311,7 +311,7 @@ ffi.metatype( knot_rrset_t, {
end,
tostring = function(rr, i)
assert(ffi.istype(knot_rrset_t, rr))
if rr.rrs.rr_count > 0 then
if rr:rdcount() > 0 then
local ret
if i ~= nil then
ret = knot.knot_rrset_txt_dump_data(rr, i, rrset_buf, rrset_buflen, knot.KNOT_DUMP_STYLE_DEFAULT)
......@@ -339,6 +339,11 @@ ffi.metatype( knot_rrset_t, {
C.free(dump[0])
return result
end,
-- Return RDATA count for this RR set
rdcount = function(rr)
assert(ffi.istype(knot_rrset_t, rr))
return tonumber(rr.rrs.rr_count)
end,
-- Add binary RDATA to the RR set
add_rdata = function (rr, rdata, rdlen, ttl)
assert(ffi.istype(knot_rrset_t, rr))
......@@ -528,7 +533,7 @@ ffi.metatype( knot_pkt_t, {
local section = knot.knot_pkt_section(pkt, section_id)
for i = 1, section.count do
local rrset = knot.knot_pkt_rr(section, i - 1)
for k = 1, rrset.rrs.rr_count do
for k = 1, rrset:rdcount() do
table.insert(records, rrset:get(k - 1))
end
end
......
......@@ -52,6 +52,7 @@ local function test_rrset_functions()
-- create a dummy rrsig
local rrsig = kres.rrset(todname('com.'), kres.type.RRSIG, kres.class.IN)
rrsig:add_rdata('\0\1', 2, 0)
same(rr:rdcount(), 1, 'add_rdata really added RDATA')
-- check rrsig matching
same(rr.type, rrsig:type_covered(), 'rrsig type covered matches covered RR type')
ok(rr:is_covered_by(rrsig), 'rrsig is covering a record')
......@@ -59,6 +60,7 @@ local function test_rrset_functions()
local copy = kres.rrset(rr:owner(), rr.type)
ok(copy:add_rdata('\4\3\2\1', 4, 66), 'adding second RDATA works')
ok(rr:merge_rdata(copy), 'merge_rdata works')
same(rr:rdcount(), 2, 'RDATA count is correct after merge_rdata')
expect = 'com. 66 A 1.2.3.4\n' ..
'com. 66 A 4.3.2.1\n'
same(rr:txt_dump(), expect, 'merge_rdata actually merged RDATA')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment