]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/luabackend/master.cc
487030e91489649f0a62a8a5ec35ca935ba25778
[thirdparty/pdns.git] / modules / luabackend / master.cc
1 /*
2 Copyright (C) 2011 Fredrik Danerklint
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License version 2 as published
6 by the Free Software Foundation
7
8 Additionally, the license of this program contains a special
9 exception which allows to distribute the program in binary form when
10 it is linked against OpenSSL.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
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 /*
32 virtual void getUpdatedMasters(vector<DomainInfo>* domains);
33 virtual void setNotifed(int id, uint32_t serial);
34 */
35
36 void LUABackend::getUpdatedMasters(vector<DomainInfo>* domains) {
37
38 if (f_lua_getupdatedmasters == 0)
39 return;
40
41 if (logging)
42 L << Logger::Info << backend_name << "(getUpdatedMasters) BEGIN" << endl;
43
44 lua_rawgeti(lua, LUA_REGISTRYINDEX, f_lua_getupdatedmasters);
45
46 if(lua_pcall(lua, 0, 1, f_lua_exec_error) != 0) {
47 string e = backend_name + lua_tostring(lua, -1);
48 lua_pop(lua, 1);
49
50 throw runtime_error(e);
51 return;
52 }
53
54 size_t returnedwhat = lua_type(lua, -1);
55 if (returnedwhat != LUA_TTABLE) {
56 lua_pop(lua, 1 );
57 return;
58 }
59
60 domains_from_table(domains, "getUpdatedMasters");
61
62 if (logging)
63 L << Logger::Info << backend_name << "(getUpdatedMasters) END" << endl;
64 }
65
66 void LUABackend::setNotifed(int id, uint32_t serial) {
67
68 if (f_lua_setnotifed == 0)
69 return;
70
71 if (logging)
72 L << Logger::Info << backend_name << "(setNotifed) BEGIN" << endl;
73
74 lua_rawgeti(lua, LUA_REGISTRYINDEX, f_lua_setnotifed);
75
76 lua_pushinteger(lua, id);
77 lua_pushinteger(lua, serial);
78
79 if(lua_pcall(lua, 2, 0, f_lua_exec_error) != 0) {
80 string e = backend_name + lua_tostring(lua, -1);
81 lua_pop(lua, 1);
82
83 throw runtime_error(e);
84 return;
85 }
86
87 if (logging)
88 L << Logger::Info << backend_name << "(setNotifed) END" << endl;
89 }
90