From: Zack Allen Date: Mon, 30 Dec 2013 17:09:06 +0000 (-0500) Subject: Added enum namespace to lua-pdns to prevent magic number usage when referring to... X-Git-Tag: rec-3.6.0-rc1~261^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92c0733106d24e39189644ca722e613c343e04ba;p=pdns Added enum namespace to lua-pdns to prevent magic number usage when referring to pdns_recursor return types for pdns.DROP and pdns.PASS --- diff --git a/pdns/lua-pdns.cc b/pdns/lua-pdns.cc index 9ea66fe0f..1935730e2 100644 --- a/pdns/lua-pdns.cc +++ b/pdns/lua-pdns.cc @@ -299,9 +299,9 @@ PowerDNSLua::PowerDNSLua(const std::string& fname) // set syslog codes used by Logger/enum Urgency pushSyslogSecurityLevelTable(d_lua); lua_setfield(d_lua, -2, "loglevels"); - lua_pushnumber(d_lua, -1); + lua_pushnumber(d_lua, RecursorBehavior::PASS); lua_setfield(d_lua, -2, "PASS"); - lua_pushnumber(d_lua, -2); + lua_pushnumber(d_lua, RecursorBehavior::DROP); lua_setfield(d_lua, -2, "DROP"); lua_setglobal(d_lua, "pdns"); diff --git a/pdns/lua-pdns.hh b/pdns/lua-pdns.hh index de9bdbfb1..14a3e0539 100644 --- a/pdns/lua-pdns.hh +++ b/pdns/lua-pdns.hh @@ -30,7 +30,8 @@ protected: // FIXME? bool d_variable; ComboAddress d_local; }; - +// this enum creates constants to track the pdns_recursor behavior when returned from the Lua call +namespace RecursorBehavior { enum returnTypes{PASS=-1,DROP=-2}; }; void pushResourceRecordsTable(lua_State* lua, const vector& records); void popResourceRecordsTable(lua_State *lua, const string &query, vector& ret); void pushSyslogSecurityLevelTable(lua_State *lua); diff --git a/pdns/lua-recursor.hh b/pdns/lua-recursor.hh index 62eaead2a..1dd885107 100644 --- a/pdns/lua-recursor.hh +++ b/pdns/lua-recursor.hh @@ -13,9 +13,7 @@ public: bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector& res, int& ret, bool* variable); bool nodata(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector& res, int& ret, bool* variable); bool postresolve(const ComboAddress& remote, const ComboAddress& local, const string& query, const QType& qtype, vector& res, int& ret, bool* variable); - private: bool passthrough(const string& func, const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector& ret, int& res, bool* variable); }; - #endif diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index aae499d57..31c3cb90f 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -563,12 +563,12 @@ void startDoResolve(void *p) } } - if(res == -2) { + if(res == RecursorBehavior::DROP) { delete dc; dc=0; return; } - if(tracedQuery || res < 0 || res == RCode::ServFail || pw.getHeader()->rcode == RCode::ServFail) + if(tracedQuery || res == RecursorBehavior::PASS || res == RCode::ServFail || pw.getHeader()->rcode == RCode::ServFail) { string trace(sr.getTrace()); if(!trace.empty()) { @@ -581,7 +581,7 @@ void startDoResolve(void *p) } } - if(res < 0) { + if(res == RecursorBehavior::PASS) { pw.getHeader()->rcode=RCode::ServFail; // no commit here, because no record g_stats.servFails++;