]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Added function to populate a DNSResourceRecord.
authortcely <tcely@users.noreply.github.com>
Tue, 1 Aug 2017 01:59:19 +0000 (21:59 -0400)
committertcely <tcely@users.noreply.github.com>
Thu, 24 May 2018 15:29:28 +0000 (11:29 -0400)
modules/luabackend/luabackend.hh
modules/luabackend/private.cc

index 9f335db5f0e1cc3217e8261b23f2a0efca360c12..7d5f76c769a5705c0931539a3e420f2cd850fa24 100644 (file)
@@ -180,6 +180,7 @@ private:
     bool domaininfo_from_table(DomainInfo *di);
     void domains_from_table(vector<DomainInfo>* 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);
index a23e5d20c61627fac8c2c76131df550fc5dea3ea..31401792256f916a59f6eb72911459b0fed9c261 100644 (file)
@@ -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;
+
+}