#include "rec_channel.hh"
#include "ednssubnet.hh"
#include <unordered_set>
-#if !defined(HAVE_LUA)
+#if !defined(HAVE_LUA)
RecursorLua4::RecursorLua4(const std::string &fname)
{
throw std::runtime_error("Attempt to load a Lua script in a PowerDNS binary without Lua support");
RecursorLua4::RecursorLua4(const std::string& fname)
{
- d_lw = new LuaContext;
+ d_lw = std::unique_ptr<LuaContext>(new LuaContext);
d_lw->registerFunction<int(dnsheader::*)()>("getID", [](dnsheader& dh) { return dh.id; });
d_lw->registerFunction<bool(dnsheader::*)()>("getCD", [](dnsheader& dh) { return dh.cd; });
// see if they added followup work for us too
return handled;
}
+
#endif
+RecursorLua4::~RecursorLua4(){}
string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
class LuaContext;
+
class RecursorLua4 : public boost::noncopyable
{
+private:
+ std::unique_ptr<LuaContext> d_lw; // this is way on top because it must get destroyed _last_
+
public:
explicit RecursorLua4(const std::string& fname);
-
+ ~RecursorLua4(); // this is so unique_ptr works with an incomplete type
bool preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, unsigned int tag, int& ret, bool* variable);
bool nxdomain(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
bool nodata(const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
DNSName followupName;
};
- LuaContext* d_lw;
typedef std::function<bool(std::shared_ptr<DNSQuestion>)> luacall_t;
luacall_t d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery;
bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, const vector<pair<uint16_t,string> >* ednsOpts, unsigned int tag, int& ret, bool* variable);