From: Bert Hubert Date: Thu, 12 Jun 2008 13:06:06 +0000 (+0000) Subject: initial Lua support X-Git-Tag: rec-3.1.7.1~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=827b769a3c008235a0f95a95b69d3309dac0695b;p=thirdparty%2Fpdns.git initial Lua support git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1191 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/lua-pdns-recursor.cc b/pdns/lua-pdns-recursor.cc new file mode 100644 index 0000000000..f1bc2974f6 --- /dev/null +++ b/pdns/lua-pdns-recursor.cc @@ -0,0 +1,142 @@ +#include "lua-pdns-recursor.hh" +extern "C" { +#undef L +/* Include the Lua API header files. */ +#include +#include +#include +} + +#include +#include +#include +#include + +using namespace std; + +extern "C" int netmaskMatchLua(lua_State *lua) +{ + bool result=false; + if(lua_gettop(lua) == 2) { + string ip=lua_tostring(lua, 1); + string netmask=lua_tostring(lua, 2); + + Netmask nm(netmask); + ComboAddress ca(ip); + + result = nm.match(ip); + } + lua_pushboolean(lua, result); + return 1; +} + +PowerDNSLua::PowerDNSLua() +{ + d_lua = lua_open(); + luaopen_base(d_lua); + lua_settop(d_lua, 0); + if(luaL_dofile(d_lua, "./script.lua")) { + cerr<<"Error loading LUA file: "; + if (lua_isstring(d_lua, -1)) + cerr<& ret, int& res) +{ + return passthrough("nxdomain", remote, query, qtype, ret, res); +} + +bool PowerDNSLua::prequery(const ComboAddress& remote, const string& query, const QType& qtype, vector& ret, int& res) +{ + return passthrough("prequery", remote, query, qtype, ret, res); +} + +bool PowerDNSLua::passthrough(const string& func, const ComboAddress& remote, const string& query, const QType& qtype, vector& ret, int& res) +{ + if(d_failed) + return false; + + /* the function name */ + lua_getglobal(d_lua, func.c_str()); + if(!lua_isfunction(d_lua, -1)) { + cerr<<"No such function '"<& res, int& ret); + bool nxdomain(const ComboAddress& remote, const string& query, const QType& qtype, vector& res, int& ret); +private: + lua_State* d_lua; + bool passthrough(const string& func, const ComboAddress& remote, const string& query, const QType& qtype, vector& ret, int& res); + bool d_failed; +}; + +#endif