]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Move Lua(Response)Action operator() out of header file 6287/head
authorChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 20 Feb 2018 09:29:26 +0000 (10:29 +0100)
committerChris Hofstaedtler <chris.hofstaedtler@deduktiva.com>
Tue, 20 Feb 2018 09:29:26 +0000 (10:29 +0100)
pdns/dnsdist-lua-actions.cc
pdns/dnsdist-lua.hh

index 8d25ae8742f45917a8eee1b10bbdae99a4f86ce1..4be1d0302e5e8fe47728d29dcffc508a510dc366 100644 (file)
@@ -306,6 +306,38 @@ public:
   }
 };
 
+DNSAction::Action LuaAction::operator()(DNSQuestion* dq, string* ruleresult) const
+{
+  std::lock_guard<std::mutex> lock(g_luamutex);
+  try {
+    auto ret = d_func(dq);
+    if(ruleresult)
+      *ruleresult=std::get<1>(ret);
+    return (Action)std::get<0>(ret);
+  } catch (std::exception &e) {
+    warnlog("LuaAction failed inside lua, returning ServFail: %s", e.what());
+  } catch (...) {
+    warnlog("LuaAction failed inside lua, returning ServFail: [unknown exception]");
+  }
+  return DNSAction::Action::ServFail;
+}
+
+DNSResponseAction::Action LuaResponseAction::operator()(DNSResponse* dr, string* ruleresult) const
+{
+  std::lock_guard<std::mutex> lock(g_luamutex);
+  try {
+    auto ret = d_func(dr);
+    if(ruleresult)
+      *ruleresult=std::get<1>(ret);
+    return (Action)std::get<0>(ret);
+  } catch (std::exception &e) {
+    warnlog("LuaResponseAction failed inside lua, returning ServFail: %s", e.what());
+  } catch (...) {
+    warnlog("LuaResponseAction failed inside lua, returning ServFail: [unknown exception]");
+  }
+  return DNSResponseAction::Action::ServFail;
+}
+
 DNSAction::Action SpoofAction::operator()(DNSQuestion* dq, string* ruleresult) const
 {
   uint16_t qtype = dq->qtype;
index 49751916680127ea908069c9f1f6187ec55ac501..5c7d73c1daafcdd2cf095ced12957cdc4e46d80b 100644 (file)
  */
 #pragma once
 
-#include "dolog.hh"
-
 class LuaAction : public DNSAction
 {
 public:
   typedef std::function<std::tuple<int, string>(DNSQuestion* dq)> func_t;
   LuaAction(LuaAction::func_t func) : d_func(func)
   {}
-
-  Action operator()(DNSQuestion* dq, string* ruleresult) const override
-  {
-    std::lock_guard<std::mutex> lock(g_luamutex);
-    try {
-      auto ret = d_func(dq);
-      if(ruleresult)
-        *ruleresult=std::get<1>(ret);
-      return (Action)std::get<0>(ret);
-    } catch (std::exception &e) {
-      warnlog("LuaAction failed inside lua, returning ServFail: %s", e.what());
-    } catch (...) {
-      warnlog("LuaAction failed inside lua, returning ServFail: [unknown exception]");
-    }
-    return DNSAction::Action::ServFail;
-  }
-
+  Action operator()(DNSQuestion* dq, string* ruleresult) const override;
   string toString() const override
   {
     return "Lua script";
   }
-
 private:
   func_t d_func;
 };
@@ -61,28 +42,11 @@ public:
   typedef std::function<std::tuple<int, string>(DNSResponse* dr)> func_t;
   LuaResponseAction(LuaResponseAction::func_t func) : d_func(func)
   {}
-
-  Action operator()(DNSResponse* dr, string* ruleresult) const override
-  {
-    std::lock_guard<std::mutex> lock(g_luamutex);
-    try {
-      auto ret = d_func(dr);
-      if(ruleresult)
-        *ruleresult=std::get<1>(ret);
-      return (Action)std::get<0>(ret);
-    } catch (std::exception &e) {
-      warnlog("LuaResponseAction failed inside lua, returning ServFail: %s", e.what());
-    } catch (...) {
-      warnlog("LuaResponseAction failed inside lua, returning ServFail: [unknown exception]");
-    }
-    return DNSResponseAction::Action::ServFail;
-  }
-
+  Action operator()(DNSResponse* dr, string* ruleresult) const override;
   string toString() const override
   {
     return "Lua response script";
   }
-
 private:
   func_t d_func;
 };