]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/luabackend/private.cc
make DomainInfo not carry IP addresses as strings. And some subsequent cleanups..
[thirdparty/pdns.git] / modules / luabackend / private.cc
1 /*
2 * This file is part of PowerDNS or dnsdist.
3 * Copyright -- PowerDNS.COM B.V. and its contributors
4 * originally authored by Fredrik Danerklint
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * In addition, for the avoidance of any doubt, permission is granted to
11 * link this program with OpenSSL and to (re)distribute the binaries
12 * produced as the result of such linking.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 #include "luabackend.hh"
27
28 #include "pdns/logger.hh"
29 #include "pdns/arguments.hh"
30
31 string LUABackend::my_getArg(string a) {
32 return getArg(a);
33 }
34
35 bool LUABackend::my_mustDo(string a) {
36 return mustDo(a);
37 }
38
39 bool LUABackend::domaininfo_from_table(DomainInfo *di) {
40
41 di->backend = NULL;
42
43 if (!getValueFromTable(lua, "id", di->id))
44 return false;
45
46 if (!getValueFromTable(lua, "zone", di->zone))
47 return false;
48
49 if (!getValueFromTable(lua, "serial", di->serial))
50 return false;
51
52 getValueFromTable(lua, "notified_serial", di->notified_serial);
53 getValueFromTable(lua, "last_check", di->last_check);
54
55 di->kind = DomainInfo::Native;
56
57 string kind;
58 if (getValueFromTable(lua, "kind", kind)) {
59
60 if (kind == "MASTER")
61 di->kind = DomainInfo::Master;
62 else if (kind == "SLAVE")
63 di->kind = DomainInfo::Slave;
64 }
65
66 lua_pushstring(lua, "masters");
67 lua_gettable(lua, -2);
68
69 if(!lua_isnil(lua, -1)) {
70 lua_pushnil(lua);
71 const char *value;
72 while (lua_next(lua, -2)) {
73 value = lua_tostring(lua, -1);
74 lua_pop(lua,1);
75 di->masters.push_back(ComboAddress(value, 53));
76 }
77 }
78
79 lua_pop(lua, 1);
80
81 di->backend = this;
82
83 return true;
84 }
85
86 void LUABackend::domains_from_table(vector<DomainInfo>* domains, const char *f_name) {
87 lua_pushnil(lua);
88
89 size_t returnedwhat;
90
91 while (lua_next(lua, -2)) {
92 returnedwhat = lua_type(lua, -1);
93 if (returnedwhat == LUA_TTABLE) {
94 DomainInfo di;
95
96 if (domaininfo_from_table(&di))
97 domains->push_back(di);
98 }
99
100 lua_pop(lua,1);
101 }
102 }
103
104
105 void LUABackend::dnsrr_to_table(lua_State *lua, const DNSResourceRecord *rr) {
106
107 lua_newtable(lua);
108
109 lua_pushliteral(lua, "qtype");
110 lua_pushstring(lua, rr->qtype.getName().c_str());
111 lua_settable(lua, -3);
112
113 lua_pushliteral(lua, "qclass");
114 lua_pushinteger(lua, rr->qclass);
115 lua_settable(lua, -3);
116
117 lua_pushliteral(lua, "ttl");
118 lua_pushinteger(lua, rr->ttl);
119 lua_settable(lua, -3);
120
121 lua_pushliteral(lua, "auth");
122 lua_pushboolean(lua, rr->auth);
123 lua_settable(lua, -3);
124
125 lua_pushliteral(lua, "content");
126 lua_pushstring(lua, rr->content.c_str());
127 lua_settable(lua, -3);
128
129 }