From: tcely Date: Tue, 1 Aug 2017 01:59:19 +0000 (-0400) Subject: Added function to populate a DNSResourceRecord. X-Git-Tag: dnsdist-1.4.0-rc3~42^2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68df5ed6038e801407a21bfd27e85b79c3be6011;p=thirdparty%2Fpdns.git Added function to populate a DNSResourceRecord. --- diff --git a/modules/luabackend/luabackend.hh b/modules/luabackend/luabackend.hh index 9f335db5f0..7d5f76c769 100644 --- a/modules/luabackend/luabackend.hh +++ b/modules/luabackend/luabackend.hh @@ -180,6 +180,7 @@ private: bool domaininfo_from_table(DomainInfo *di); void domains_from_table(vector* domains, const char *f_name); void dnsrr_to_table(lua_State *lua, const DNSResourceRecord *rr); + bool dnsrr_from_table(lua_State *lua, DNSResourceRecord &rr); //reload.cc void get_lua_function(lua_State *lua, const char *name, int *function); diff --git a/modules/luabackend/private.cc b/modules/luabackend/private.cc index a23e5d20c6..3140179225 100644 --- a/modules/luabackend/private.cc +++ b/modules/luabackend/private.cc @@ -131,3 +131,49 @@ void LUABackend::dnsrr_to_table(lua_State *lua, const DNSResourceRecord *rr) { lua_settable(lua, -3); } + +bool dnsrr_from_table(lua_State *lua, DNSResourceRecord &rr) { + + bool got_content = false; + string qt_name; + uint16_t qt_code; + + // look for qname key first + // try name key if qname wasn't set + if (!getValueFromTable(lua, "qname", rr.qname)) + getValueFromTable(lua, "name", rr.qname); + + // qtype is either a table, string or number + // when it's a table prefer the code key + lua_pushliteral(lua, "qtype"); + lua_gettable(lua, -2); + returnedwhat = lua_type(lua, -1); + if (LUA_TTABLE == returnedwhat) { + if (getValueFromTable(lua, "code", qt_code)) + rr.qtype = qt_code; + else + if (getValueFromTable(lua, "name", qt_name)) + rr.qtype = qt_name; + lua_pop(lua, 1); + } else if (LUA_TNUMBER == returnedwhat) { + lua_pop(lua, 1); + if (getValueFromTable(lua, "qtype", qt_code)) + rr.qtype = qt_code; + } else { + lua_pop(lua, 1); + if (getValueFromTable(lua, "qtype", qt_name)) + rr.qtype = qt_name; + } + + getValueFromTable(lua, "qclass", rr.qclass); + getValueFromTable(lua, "domain_id", rr.domain_id); + getValueFromTable(lua, "auth", rr.auth); + getValueFromTable(lua, "last_modified", rr.last_modified); + + getValueFromTable(lua, "ttl", rr.ttl); + got_content = getValueFromTable(lua, "content", rr.content); + getValueFromTable(lua, "scopeMask", rr.scopeMask); + + return got_content; + +}