]> granicus.if.org Git - pdns/commitdiff
updates
authorBert Hubert <bert.hubert@netherlabs.nl>
Thu, 12 Jun 2008 13:50:40 +0000 (13:50 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Thu, 12 Jun 2008 13:50:40 +0000 (13:50 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1193 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/lua-pdns-recursor.cc
pdns/lua-pdns-recursor.hh

index f1bc2974f6c15aaf35f9e88e6f6f6d28e5e3240a..f6278df71d43a718323af25d48766f94c232de6a 100644 (file)
@@ -11,6 +11,7 @@ extern "C" {
 #include <stdio.h>
 #include <string>
 #include <vector>
+#include <stdexcept>
 
 using namespace std;
 
@@ -30,22 +31,16 @@ extern "C" int netmaskMatchLua(lua_State *lua)
   return 1;
 }
 
-PowerDNSLua::PowerDNSLua()
+PowerDNSLua::PowerDNSLua(const std::string& fname)
 {
   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<<lua_tostring(d_lua, -1);
-    cerr<<endl;
-
-    d_failed=true;
-  }
+  if(luaL_dofile(d_lua,  fname.c_str())) 
+    throw runtime_error(string("Error loading LUA file '")+fname+"': "+ string(lua_isstring(d_lua, -1) ? lua_tostring(d_lua, -1) : "unknown error"));
+  
   lua_pushcfunction(d_lua, netmaskMatchLua);
   lua_setglobal(d_lua, "matchnetmask");
-  d_failed=false;
 }
 
 bool PowerDNSLua::nxdomain(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& ret, int& res)
@@ -60,13 +55,9 @@ bool PowerDNSLua::prequery(const ComboAddress& remote, const string& query, cons
 
 bool PowerDNSLua::passthrough(const string& func, const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& 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 '"<<func<<"'\n";
+    //  cerr<<"No such function '"<<func<<"'\n";
     lua_pop(d_lua, 1);
     return false;
   }
index 99c9579e3dd8f901fb46d2c5de3b7f5c6622af45..b60824958e538bd3810d293d82793d9b4ab95817 100644 (file)
@@ -8,7 +8,7 @@ struct lua_State;
 class PowerDNSLua
 {
 public:
-  PowerDNSLua();
+  explicit PowerDNSLua(const std::string& fname);
   ~PowerDNSLua();
   void reload();
   bool prequery(const ComboAddress& remote, const string& query, const QType& qtype, vector<DNSResourceRecord>& res, int& ret);