}
}
+#ifdef PIGLET
+// FIXIT-M duplicates logic in void InspectorManager::instantiate()
+
+Inspector* InspectorManager::instantiate(
+ const char* name, Module* mod, SnortConfig* sc)
+{
+ auto ppc = get_class(name, sc->framework_config);
+
+ if ( !ppc )
+ return nullptr;
+
+ auto fp = get_inspection_policy()->framework_policy;
+ auto ppi = get_new(ppc, fp, name, mod);
+
+ if ( !ppi )
+ return nullptr;
+
+ ppi->set_name(name);
+
+ // FIXIT-L can't we just unify PHInstance and InspectorWrapper?
+ return ppi->handler;
+}
+#endif
+
// create default binding for wizard and configured services
static void instantiate_binder(SnortConfig* sc, FrameworkPolicy* fp)
{
s_clear = false;
}
-#ifdef PIGLET
-
-InspectorWrapper* InspectorManager::instantiate(const char* name, Module* m)
-{
- auto api = ::get_plugin(name);
- if ( !api || !api->ctor )
- return nullptr;
-
- auto p = api->ctor(m);
- if ( !p )
- return nullptr;
-
- p->set_api(api);
-
- return new InspectorWrapper(api, p);
-}
-
-#endif
-
//-------------------------------------------------------------------------
-#ifdef PIGLET
-struct InspectorWrapper
-{
- InspectorWrapper(const InspectApi* a, Inspector* p) :
- api { a }, instance { p } { }
-
- ~InspectorWrapper()
- {
- if ( api && instance && api->dtor )
- api->dtor(instance);
- }
-
- const InspectApi* api;
- Inspector* instance;
-};
-#endif
-
class InspectorManager
{
public:
static void empty_trash();
#ifdef PIGLET
- static InspectorWrapper* instantiate(const char*, Module*);
+ static Inspector* instantiate(const char*, Module*, SnortConfig*);
#endif
private:
#include <string>
#include <assert.h>
+#include "log/messages.h"
#include "lua/lua_iface.h"
#include "managers/inspector_manager.h"
#include "piglet/piglet_api.h"
class InspectorPiglet : public Piglet::BasePlugin
{
public:
- InspectorPiglet(Lua::State&, std::string, Module*);
+ InspectorPiglet(Lua::State&, std::string, Module*, SnortConfig*);
virtual ~InspectorPiglet() override;
virtual bool setup() override;
private:
- InspectorWrapper* wrapper;
+ Inspector* instance;
};
InspectorPiglet::InspectorPiglet(
- Lua::State& state, std::string target, Module* m) :
- BasePlugin(state, target, m)
+ Lua::State& state, std::string target, Module* m, SnortConfig* sc) :
+ BasePlugin(state, target, m, sc)
{
FlushBucket::set(0);
assert(module);
- wrapper = InspectorManager::instantiate(target.c_str(), module);
-}
+ assert(snort_conf);
-InspectorPiglet::~InspectorPiglet()
-{
- if ( wrapper )
- delete wrapper;
+ instance = InspectorManager::instantiate(target.c_str(), module, snort_conf);
}
+InspectorPiglet::~InspectorPiglet() { }
+
bool InspectorPiglet::setup()
{
- if ( !wrapper )
+ if ( !instance )
+ {
+ Piglet::error("couldn't instantiate Inspector '%s'", target.c_str());
return true;
+ }
install(L, DecodeDataIface);
install(L, RawBufferIface);
install(L, PacketIface);
install(L, StreamSplitterIface);
- install(L, InspectorIface, wrapper->instance);
+ install(L, InspectorIface, instance);
return false;
}
// API foo
// -----------------------------------------------------------------------------
static Piglet::BasePlugin* ctor(
- Lua::State& state, std::string target, Module* m, SnortConfig*)
-{ return new InspectorPiglet(state, target, m); }
+ Lua::State& state, std::string target, Module* m, SnortConfig* sc)
+{ return new InspectorPiglet(state, target, m, sc); }
static void dtor(Piglet::BasePlugin* p)
{ delete p; }