Bro plugins should support a patch version (x.y.z)

This commit is contained in:
Jon Zeolla 2018-09-29 23:08:10 -04:00
parent 35d0a4d38e
commit 615ff78282
31 changed files with 99 additions and 24 deletions

View file

@ -1,3 +1,6 @@
2.6-beta2-16 | 2018-09-29 21:30:31 -0500
* Add an optional plugin patch version (Jon Zeolla)
2.6-beta2-14 | 2018-09-25 16:38:29 -0500 2.6-beta2-14 | 2018-09-25 16:38:29 -0500

5
NEWS
View file

@ -544,6 +544,11 @@ Changed Functionality
indicated whether each Bro process was the "parent" or "child", but this indicated whether each Bro process was the "parent" or "child", but this
is no longer relevant because each Bro node now runs as a single process. is no longer relevant because each Bro node now runs as a single process.
- Bro's Plugin framework now allows a patch version. If a patch version is not
provided, it will default to 0. To specify this, modify the plugin
Configuration class in your ``src/Plugin.cc` and set
``config.version.patch``.
Removed Functionality Removed Functionality
--------------------- ---------------------

View file

@ -99,7 +99,7 @@ option::
# export BRO_PLUGIN_PATH=/path/to/rot13-plugin/build # export BRO_PLUGIN_PATH=/path/to/rot13-plugin/build
# bro -N # bro -N
[...] [...]
Demo::Rot13 - <Insert description> (dynamic, version 0.1) Demo::Rot13 - <Insert description> (dynamic, version 0.1.0)
[...] [...]
That looks quite good, except for the dummy description that we should That looks quite good, except for the dummy description that we should
@ -115,6 +115,7 @@ is about. We do this by editing the ``config.description`` line in
config.description = "Caesar cipher rotating a string's characters by 13 places."; config.description = "Caesar cipher rotating a string's characters by 13 places.";
config.version.major = 0; config.version.major = 0;
config.version.minor = 1; config.version.minor = 1;
config.version.patch = 0;
return config; return config;
} }
[...] [...]
@ -124,14 +125,14 @@ Now rebuild and verify that the description is visible::
# make # make
[...] [...]
# bro -N | grep Rot13 # bro -N | grep Rot13
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1) Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
Bro can also show us what exactly the plugin provides with the Bro can also show us what exactly the plugin provides with the
more verbose option ``-NN``:: more verbose option ``-NN``::
# bro -NN # bro -NN
[...] [...]
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1) Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
[Function] Demo::rot13 [Function] Demo::rot13
[...] [...]
@ -166,7 +167,7 @@ unpacking.
To distribute the plugin in binary form, the build process To distribute the plugin in binary form, the build process
conveniently creates a corresponding tarball in ``build/dist/``. In conveniently creates a corresponding tarball in ``build/dist/``. In
this case, it's called ``Demo_Rot13-0.1.tar.gz``, with the version this case, it's called ``Demo_Rot13-0.1.0.tar.gz``, with the version
number coming out of the ``VERSION`` file that ``init-plugin`` put number coming out of the ``VERSION`` file that ``init-plugin`` put
into place. The binary tarball has everything needed to run the into place. The binary tarball has everything needed to run the
plugin, but no further source files. Optionally, one can include plugin, but no further source files. Optionally, one can include
@ -395,7 +396,7 @@ let's get that in place::
% 'btest-diff output' failed unexpectedly (exit code 100) % 'btest-diff output' failed unexpectedly (exit code 100)
% cat .diag % cat .diag
== File =============================== == File ===============================
Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1) Demo::Rot13 - Caesar cipher rotating a string's characters by 13 places. (dynamic, version 0.1.0)
[Function] Demo::rot13 [Function] Demo::rot13
== Error =============================== == Error ===============================

View file

@ -445,6 +445,8 @@ void Plugin::Describe(ODesc* d) const
d->Add(config.version.major); d->Add(config.version.major);
d->Add("."); d->Add(".");
d->Add(config.version.minor); d->Add(config.version.minor);
d->Add(".");
d->Add(config.version.patch);
d->Add(")"); d->Add(")");
} }
else else

View file

@ -69,16 +69,26 @@ extern const char* hook_name(HookType h);
struct VersionNumber { struct VersionNumber {
int major; //< Major version number; int major; //< Major version number;
int minor; //< Minor version number; int minor; //< Minor version number;
int patch; //< Patch version number;
/** /**
* Constructor. * Constructor.
*/ */
VersionNumber() { major = minor = -1; } VersionNumber() {
/**
* Major and minor versions are required.
*/
major = minor = -1;
/**
* Patch version is optional, and set to 0 if not manually set.
*/
patch = 0;
}
/** /**
* Returns true if the version is set to a non-negative value. * Returns true if the version is set to a non-negative value.
*/ */
explicit operator bool() const { return major >= 0 && minor >= 0; } explicit operator bool() const { return major >= 0 && minor >= 0 && patch >= 0; }
}; };
/** /**

View file

@ -1,4 +1,4 @@
Demo::Foo - <Insert description> (dynamic, version 0.1) Demo::Foo - <Insert description> (dynamic, version 0.1.0)
[Function] hello_plugin_world [Function] hello_plugin_world
[Event] plugin_event [Event] plugin_event

View file

@ -1,4 +1,4 @@
Demo::Foo - <Insert description> (dynamic, version 0.1) Demo::Foo - <Insert description> (dynamic, version 0.1.0)
[Function] hello_plugin_world [Function] hello_plugin_world
[Event] plugin_event [Event] plugin_event

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test analyzer (dynamic, version 1.0) Demo::Foo - A Foo test analyzer (dynamic, version 1.0.0)
[File Analyzer] Foo (ANALYZER_FOO) [File Analyzer] Foo (ANALYZER_FOO)
[Event] foo_piece [Event] foo_piece

View file

@ -1,3 +1,3 @@
Demo::Foo - <Insert description> (dynamic, version 0.1) Demo::Foo - <Insert description> (dynamic, version 0.1.0)
=== ===

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo packet dumper (dynamic, version 1.0) Demo::Foo - A Foo packet dumper (dynamic, version 1.0.0)
[Packet Dumper] FooPktDumper (dumper prefix: "foo") [Packet Dumper] FooPktDumper (dumper prefix: "foo")
=== ===

View file

@ -0,0 +1 @@
Testing::NoPatchVersion - Testing a plugin without a specified patch version (dynamic, version 0.1.0)

View file

@ -0,0 +1 @@
Testing::WithPatchVersion - Testing a plugin with a specified patch version (dynamic, version 0.1.4)

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test analyzer (dynamic, version 1.0) Demo::Foo - A Foo test analyzer (dynamic, version 1.0.0)
[Analyzer] Foo (ANALYZER_FOO, enabled) [Analyzer] Foo (ANALYZER_FOO, enabled)
[Event] foo_message [Event] foo_message

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test input reader (dynamic, version 1.0) Demo::Foo - A Foo test input reader (dynamic, version 1.0.0)
[Reader] Foo (Input::READER_FOO) [Reader] Foo (Input::READER_FOO)
=== ===

View file

@ -1,4 +1,4 @@
Demo::Foo - A Foo test logging writer (dynamic, version 1.0) Demo::Foo - A Foo test logging writer (dynamic, version 1.0.0)
[Writer] Foo (Log::WRITER_FOO) [Writer] Foo (Log::WRITER_FOO)
=== ===

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test analyzer"; config.description = "A Foo test analyzer";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -29,6 +29,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercises all plugin hooks"; config.description = "Exercises all plugin hooks";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -21,6 +21,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercises Log hooks"; config.description = "Exercises Log hooks";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo packet dumper"; config.description = "A Foo packet dumper";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo packet source"; config.description = "A Foo packet source";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -0,0 +1,16 @@
#include "Plugin.h"
namespace plugin { namespace Testing_NoPatchVersion { Plugin plugin; } }
using namespace plugin::Testing_NoPatchVersion;
plugin::Configuration Plugin::Configure()
{
plugin::Configuration config;
config.name = "Testing::NoPatchVersion";
config.description = "Testing a plugin without a specified patch version";
config.version.major = 0;
config.version.minor = 1;
return config;
}

View file

@ -0,0 +1,5 @@
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Testing NoPatchVersion
# @TEST-EXEC: cp -r %DIR/plugin-nopatchversion-plugin/* .
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
# @TEST-EXEC: BRO_PLUGIN_PATH=$(pwd) bro -N Testing::NoPatchVersion >> output
# @TEST-EXEC: btest-diff output

View file

@ -0,0 +1,17 @@
#include "Plugin.h"
namespace plugin { namespace Testing_WithPatchVersion { Plugin plugin; } }
using namespace plugin::Testing_WithPatchVersion;
plugin::Configuration Plugin::Configure()
{
plugin::Configuration config;
config.name = "Testing::WithPatchVersion";
config.description = "Testing a plugin with a specified patch version";
config.version.major = 0;
config.version.minor = 1;
config.version.patch = 4;
return config;
}

View file

@ -0,0 +1,5 @@
# @TEST-EXEC: ${DIST}/aux/bro-aux/plugin-support/init-plugin -u . Testing WithPatchVersion
# @TEST-EXEC: cp -r %DIR/plugin-withpatchversion-plugin/* .
# @TEST-EXEC: ./configure --bro-dist=${DIST} && make
# @TEST-EXEC: BRO_PLUGIN_PATH=$(pwd) bro -N Testing::WithPatchVersion >> output
# @TEST-EXEC: btest-diff output

View file

@ -16,5 +16,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test analyzer"; config.description = "A Foo test analyzer";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -15,5 +15,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test input reader"; config.description = "A Foo test input reader";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -19,6 +19,7 @@ plugin::Configuration Plugin::Configure()
config.description = "Exercise Reporter Hook"; config.description = "Exercise Reporter Hook";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }

View file

@ -15,5 +15,6 @@ plugin::Configuration Plugin::Configure()
config.description = "A Foo test logging writer"; config.description = "A Foo test logging writer";
config.version.major = 1; config.version.major = 1;
config.version.minor = 0; config.version.minor = 0;
config.version.patch = 0;
return config; return config;
} }