]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: make lua actions second return value optional
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 16 Mar 2018 03:43:13 +0000 (04:43 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Mon, 19 Mar 2018 08:54:13 +0000 (09:54 +0100)
pdns/dnsdist-lua-actions.cc
pdns/dnsdist-lua.hh

index 9a9339f495fb8c1c4d0359ab6eb9aeb072837af2..fa937924ac5c851e380a8c59355a965806f783d0 100644 (file)
@@ -29,6 +29,7 @@
 #include "ednsoptions.hh"
 #include "fstrm_logger.hh"
 #include "remote_logger.hh"
+#include "boost/optional/optional_io.hpp"
 
 class DropAction : public DNSAction
 {
@@ -311,8 +312,15 @@ DNSAction::Action LuaAction::operator()(DNSQuestion* dq, string* ruleresult) con
   std::lock_guard<std::mutex> lock(g_luamutex);
   try {
     auto ret = d_func(dq);
-    if(ruleresult)
-      *ruleresult=std::get<1>(ret);
+    if (ruleresult) {
+      if (boost::optional<string> rule = std::get<1>(ret)) {
+        *ruleresult = *rule;
+      }
+      else {
+        // default to empty string
+        ruleresult->clear();
+      }
+    }
     return (Action)std::get<0>(ret);
   } catch (std::exception &e) {
     warnlog("LuaAction failed inside lua, returning ServFail: %s", e.what());
@@ -327,8 +335,15 @@ DNSResponseAction::Action LuaResponseAction::operator()(DNSResponse* dr, string*
   std::lock_guard<std::mutex> lock(g_luamutex);
   try {
     auto ret = d_func(dr);
-    if(ruleresult)
-      *ruleresult=std::get<1>(ret);
+    if(ruleresult) {
+      if (boost::optional<string> rule = std::get<1>(ret)) {
+        *ruleresult = *rule;
+      }
+      else {
+        // default to empty string
+        ruleresult->clear();
+      }
+    }
     return (Action)std::get<0>(ret);
   } catch (std::exception &e) {
     warnlog("LuaResponseAction failed inside lua, returning ServFail: %s", e.what());
index 5c7d73c1daafcdd2cf095ced12957cdc4e46d80b..97c6fb29f7a85e3f866fb2ab34acf7041634c4ac 100644 (file)
@@ -24,7 +24,7 @@
 class LuaAction : public DNSAction
 {
 public:
-  typedef std::function<std::tuple<int, string>(DNSQuestion* dq)> func_t;
+  typedef std::function<std::tuple<int, boost::optional<string> >(DNSQuestion* dr)> func_t;
   LuaAction(LuaAction::func_t func) : d_func(func)
   {}
   Action operator()(DNSQuestion* dq, string* ruleresult) const override;
@@ -39,7 +39,7 @@ private:
 class LuaResponseAction : public DNSResponseAction
 {
 public:
-  typedef std::function<std::tuple<int, string>(DNSResponse* dr)> func_t;
+  typedef std::function<std::tuple<int, boost::optional<string> >(DNSResponse* dr)> func_t;
   LuaResponseAction(LuaResponseAction::func_t func) : d_func(func)
   {}
   Action operator()(DNSResponse* dr, string* ruleresult) const override;