[Bro-Dev] Opaque type in plugin

Robin Sommer robin at icir.org
Fri May 6 08:30:22 PDT 2016

On Mon, May 02, 2016 at 19:01 +0200, you wrote:

> Currently LogNormalizer.cc:11 declares the type using static. That seems
> to work (as it is local). If I remove "static" and use the "extern"
> declaration commented in LogNormalizer.h:78 (like its done in Bro),
> loading the plugin fails with:

Took me a bit to look at this, but I've tried it now. My guess is that
it was a namespace issue. Look at the attached patch, that version
works for me.

That said, your version using "static" is completely fine. Indeed,
it's even the better one for the plugin case: defining it globally
non-static is useful only if other object files need to access it.
Inside your plugin, that's not the case; and outside the plugin nobody
can (because nobody can rely on the plugin being present). So I think
your solution is just fine.

Good to see you got the type working from a plugin. Would be even
nicer if Bro actually showed the new type in the output of "-NN" but
we don't have the support in place yet for a plugin to register it


Robin Sommer * ICSI/LBNL * robin at icir.org * www.icir.org/robin
-------------- next part --------------
diff --git a/liblognorm/src/LogNormalizer.cc b/liblognorm/src/LogNormalizer.cc
index d713640..4e9029e 100644
--- a/liblognorm/src/LogNormalizer.cc
+++ b/liblognorm/src/LogNormalizer.cc
@@ -8,7 +8,7 @@ extern "C" {
 using namespace plugin::Bro_Lognorm;
-static OpaqueType* lognormalizer_type = new OpaqueType("lognormalizer");
+OpaqueType* plugin::Bro_Lognorm::lognormalizer_type = new OpaqueType("lognormalizer");
 LogNormalizer::LogNormalizer(EventHandlerPtr evt_unparsed) : evt_unparsed(evt_unparsed)
diff --git a/liblognorm/src/LogNormalizer.h b/liblognorm/src/LogNormalizer.h
index 0361f1f..a9b6fa4 100644
--- a/liblognorm/src/LogNormalizer.h
+++ b/liblognorm/src/LogNormalizer.h
@@ -13,6 +13,7 @@ extern "C" {
 namespace plugin {
 namespace Bro_Lognorm {
+extern OpaqueType* lognormalizer_type;
 typedef std::map<string, Val*> FieldList;

More information about the bro-dev mailing list