From a4fd2d2febc2942a7970f8ad6815f0d6cdf5871e Mon Sep 17 00:00:00 2001 From: Chris Hofstaedtler Date: Mon, 28 May 2018 16:11:40 +0200 Subject: [PATCH] dnsdist: Expose toString of various objects to Lua --- pdns/dnsdist-lua-bindings.cc | 4 ++++ pdns/dnsdist.hh | 3 +++ pdns/fstrm_logger.hh | 2 +- pdns/remote_logger.hh | 4 ++-- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pdns/dnsdist-lua-bindings.cc b/pdns/dnsdist-lua-bindings.cc index 988320621..f5229184b 100644 --- a/pdns/dnsdist-lua-bindings.cc +++ b/pdns/dnsdist-lua-bindings.cc @@ -64,6 +64,7 @@ void setupLuaBindings(bool client) g_lua.registerMember("name", &ServerPolicy::name); g_lua.registerMember("policy", &ServerPolicy::policy); g_lua.registerMember("isLua", &ServerPolicy::isLua); + g_lua.registerFunction("toString", &ServerPolicy::toString); g_lua.writeVariable("firstAvailable", ServerPolicy{"firstAvailable", firstAvailable, false}); g_lua.writeVariable("roundrobin", ServerPolicy{"roundrobin", roundrobin, false}); @@ -187,6 +188,7 @@ void setupLuaBindings(bool client) g_lua.registerFunction("match", (bool (NetmaskGroup::*)(const ComboAddress&) const)&NetmaskGroup::match); g_lua.registerFunction("size", &NetmaskGroup::size); g_lua.registerFunction("clear", &NetmaskGroup::clear); + g_lua.registerFunction("toString", [](const NetmaskGroup& nmg ) { return "NetmaskGroup " + nmg.toString(); }); /* QPSLimiter */ g_lua.writeFunction("newQPSLimiter", [](int rate, int burst) { return QPSLimiter(rate, burst); }); @@ -303,6 +305,8 @@ void setupLuaBindings(bool client) #endif /* HAVE_FSTRM */ }); + g_lua.registerFunction("toString", &RemoteLoggerInterface::toString); + #ifdef HAVE_DNSCRYPT /* DNSCryptContext bindings */ g_lua.registerFunction("getProviderName", [](const DNSCryptContext& ctx) { return ctx.getProviderName().toStringNoDot(); }); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 96a050b8d..b1828c907 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -610,6 +610,9 @@ struct ServerPolicy string name; policyfunc_t policy; bool isLua; + std::string toString() const { + return string("ServerPolicy") + (isLua ? " (Lua)" : "") + " \"" + name + "\""; + } }; struct ServerPool diff --git a/pdns/fstrm_logger.hh b/pdns/fstrm_logger.hh index 6f4c40a1e..240b3d6ad 100644 --- a/pdns/fstrm_logger.hh +++ b/pdns/fstrm_logger.hh @@ -38,7 +38,7 @@ public: FrameStreamLogger(int family, const std::string& address, bool connect); virtual ~FrameStreamLogger(); virtual void queueData(const std::string& data) override; - virtual std::string toString() override + virtual std::string toString() const override { return "FrameStreamLogger to " + d_address; } diff --git a/pdns/remote_logger.hh b/pdns/remote_logger.hh index a0fec492e..6037e484c 100644 --- a/pdns/remote_logger.hh +++ b/pdns/remote_logger.hh @@ -36,7 +36,7 @@ class RemoteLoggerInterface public: virtual ~RemoteLoggerInterface() {}; virtual void queueData(const std::string& data) = 0; - virtual std::string toString() = 0; + virtual std::string toString() const = 0; }; class RemoteLogger : public RemoteLoggerInterface @@ -45,7 +45,7 @@ public: RemoteLogger(const ComboAddress& remote, uint16_t timeout=2, uint64_t maxQueuedEntries=100, uint8_t reconnectWaitTime=1, bool asyncConnect=false); virtual ~RemoteLogger(); virtual void queueData(const std::string& data) override; - virtual std::string toString() override + virtual std::string toString() const override { return "RemoteLogger to " + d_remote.toStringWithPort(); } -- 2.40.0