From: Charles-Henri Bruyand Date: Fri, 16 Mar 2018 03:43:13 +0000 (+0100) Subject: dnsdist: make lua actions second return value optional X-Git-Tag: dnsdist-1.3.0~46^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c134cbaac845a7b5d32ce825725ae5fea177fcca;p=thirdparty%2Fpdns.git dnsdist: make lua actions second return value optional --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 9a9339f495..fa937924ac 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -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 lock(g_luamutex); try { auto ret = d_func(dq); - if(ruleresult) - *ruleresult=std::get<1>(ret); + if (ruleresult) { + if (boost::optional 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 lock(g_luamutex); try { auto ret = d_func(dr); - if(ruleresult) - *ruleresult=std::get<1>(ret); + if(ruleresult) { + if (boost::optional 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()); diff --git a/pdns/dnsdist-lua.hh b/pdns/dnsdist-lua.hh index 5c7d73c1da..97c6fb29f7 100644 --- a/pdns/dnsdist-lua.hh +++ b/pdns/dnsdist-lua.hh @@ -24,7 +24,7 @@ class LuaAction : public DNSAction { public: - typedef std::function(DNSQuestion* dq)> func_t; + typedef std::function >(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(DNSResponse* dr)> func_t; + typedef std::function >(DNSResponse* dr)> func_t; LuaResponseAction(LuaResponseAction::func_t func) : d_func(func) {} Action operator()(DNSResponse* dr, string* ruleresult) const override;