]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/luabackend/master.cc
9b5293fdd121f666c31b5707cc423be6c21ca1a5
[thirdparty/pdns.git] / modules / luabackend / master.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 void LUABackend::getUpdatedMasters(vector<DomainInfo>* domains) {
32
33 if (f_lua_getupdatedmasters == 0)
34 return;
35
36 if (logging)
37 L << Logger::Info << backend_name << "(getUpdatedMasters) BEGIN" << endl;
38
39 lua_rawgeti(lua, LUA_REGISTRYINDEX, f_lua_getupdatedmasters);
40
41 if(lua_pcall(lua, 0, 1, f_lua_exec_error) != 0) {
42 string e = backend_name + lua_tostring(lua, -1);
43 lua_pop(lua, 1);
44
45 throw runtime_error(e);
46 return;
47 }
48
49 size_t returnedwhat = lua_type(lua, -1);
50 if (returnedwhat != LUA_TTABLE) {
51 lua_pop(lua, 1 );
52 return;
53 }
54
55 domains_from_table(domains, "getUpdatedMasters");
56
57 if (logging)
58 L << Logger::Info << backend_name << "(getUpdatedMasters) END" << endl;
59 }
60
61 void LUABackend::setNotified(uint32_t id, uint32_t serial) {
62
63 if (f_lua_setnotified == 0)
64 return;
65
66 if (logging)
67 L << Logger::Info << backend_name << "(setNotified) BEGIN" << endl;
68
69 lua_rawgeti(lua, LUA_REGISTRYINDEX, f_lua_setnotified);
70
71 lua_pushinteger(lua, id);
72 lua_pushinteger(lua, serial);
73
74 if(lua_pcall(lua, 2, 0, f_lua_exec_error) != 0) {
75 string e = backend_name + lua_tostring(lua, -1);
76 lua_pop(lua, 1);
77
78 throw runtime_error(e);
79 return;
80 }
81
82 if (logging)
83 L << Logger::Info << backend_name << "(setNotified) END" << endl;
84 }
85