From a5bf74b2b6b9955a9ff2a359e93c8e2e15399a41 Mon Sep 17 00:00:00 2001 From: Simone Mainardi Date: Thu, 18 Jul 2019 17:27:57 +0200 Subject: [PATCH] Makes AlertCheckLuaEngine a subclass of LuaEngine --- include/AlertCheckLuaEngine.h | 4 +--- include/LuaEngine.h | 2 +- src/AlertCheckLuaEngine.cpp | 15 ++++----------- src/NetworkInterface.cpp | 7 ------- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/include/AlertCheckLuaEngine.h b/include/AlertCheckLuaEngine.h index 8309adf578..21243d8d9f 100644 --- a/include/AlertCheckLuaEngine.h +++ b/include/AlertCheckLuaEngine.h @@ -22,11 +22,10 @@ #ifndef _ALERT_CHECK_LUA_ENGINE_H_ #define _ALERT_CHECK_LUA_ENGINE_H_ -class AlertCheckLuaEngine { +class AlertCheckLuaEngine : public LuaEngine { private: ScriptPeriodicity p; char script_path[MAX_PATH]; - LuaEngine le; public: AlertCheckLuaEngine(AlertEntity alert_entity, ScriptPeriodicity p, NetworkInterface *iface); @@ -36,7 +35,6 @@ class AlertCheckLuaEngine { ScriptPeriodicity getPeriodicity() const; const char * getGranularity() const; - lua_State * getState() const; }; #endif diff --git a/include/LuaEngine.h b/include/LuaEngine.h index 0dfef48622..bd4d5c4ab5 100644 --- a/include/LuaEngine.h +++ b/include/LuaEngine.h @@ -37,7 +37,7 @@ */ class LuaEngine { - private: + protected: lua_State *L; /**< The LuaEngine state.*/ void lua_register_classes(lua_State *L, bool http_mode); diff --git a/src/AlertCheckLuaEngine.cpp b/src/AlertCheckLuaEngine.cpp index 69482adff0..7b4c199dfe 100644 --- a/src/AlertCheckLuaEngine.cpp +++ b/src/AlertCheckLuaEngine.cpp @@ -23,7 +23,7 @@ /* ****************************************** */ -AlertCheckLuaEngine::AlertCheckLuaEngine(AlertEntity alert_entity, ScriptPeriodicity script_periodicity, NetworkInterface *iface) { +AlertCheckLuaEngine::AlertCheckLuaEngine(AlertEntity alert_entity, ScriptPeriodicity script_periodicity, NetworkInterface *iface) : LuaEngine() { const char *lua_file = NULL; p = script_periodicity; @@ -50,8 +50,7 @@ AlertCheckLuaEngine::AlertCheckLuaEngine(AlertEntity alert_entity, ScriptPeriodi lua_file); ntop->fixPath(script_path); - le.load_script(script_path, iface); - lua_State *L = le.getState(); + load_script(script_path, iface); lua_getglobal(L, "setup"); /* Called function */ lua_pushstring(L, Utils::periodicityToScriptName(p)); /* push 1st argument */ @@ -80,15 +79,9 @@ const char * AlertCheckLuaEngine::getGranularity() const { /* ****************************************** */ -lua_State * AlertCheckLuaEngine::getState() const { - return le.getState(); -} - -/* ****************************************** */ - void AlertCheckLuaEngine::setEntity(AlertableEntity *al) { if(Host *h = dynamic_cast(al)) - le.setHost(h); + setHost(h); else if(NetworkStats *ns = dynamic_cast(al)) - le.setNetwork(ns); + setNetwork(ns); } diff --git a/src/NetworkInterface.cpp b/src/NetworkInterface.cpp index da2c5c2e9b..9197182b37 100644 --- a/src/NetworkInterface.cpp +++ b/src/NetworkInterface.cpp @@ -7596,13 +7596,6 @@ bool NetworkInterface::dequeueeBPFFlow(ParsedFlow **f) { /* *************************************** */ -struct alert_check_param { - ScriptPeriodicity p; - char script_path[MAX_PATH]; - const char *granularity; - LuaEngine *le; -}; - static bool host_alert_check(GenericHashEntry *h, void *user_data, bool *matched) { AlertCheckLuaEngine *acle = (AlertCheckLuaEngine*)user_data; lua_State *L = acle->getState();