Further polishing and cleanup in preparation for merge.

This commit is contained in:
Robin Sommer 2014-07-12 18:12:09 -07:00
parent aeb8e71e8c
commit 9616cd8e61
15 changed files with 79 additions and 60 deletions

View file

@ -1,7 +1,6 @@
project(Bro C CXX)
# When changing the minimum version here, also adapt
# cmake/BroPluginDynamic and
# aux/bro-aux/plugin-support/skeleton/CMakeLists.txt
cmake_minimum_required(VERSION 2.6.3 FATAL_ERROR)

View file

@ -247,10 +247,11 @@ in its search path ``BRO_PLUGIN_PATH``. However, in bare mode (``bro
-b``), no dynamic plugins will be activated by default; instead the
user can selectively enable individual plugins in scriptland using the
``@load-plugin <qualified-plugin-name>`` directive (e.g.,
``@load-plugin Demo::Rot13``). Alternatively, one can also set the
environment variable ``BRO_PLUGIN_ACTIVATE`` to a list of
comma(!)-separated names of plugins to unconditionally activate, even
in bare mode.
``@load-plugin Demo::Rot13``). Alternatively, one can activate a
plugin from the command-line by specifying its full name
(``Demo::Rot13``), or set the environment variable
``BRO_PLUGIN_ACTIVATE`` to a list of comma(!)-separated names of
plugins to unconditionally activate, even in bare mode.
``bro -N`` shows activated plugins separately from found but not yet
activated plugins. Note that plugins compiled statically into Bro are
@ -323,6 +324,11 @@ Packet Dumpers
Not yet available as plugins.
Hooks
=====
TODO.
Testing Plugins
===============
@ -398,9 +404,20 @@ Run the test-suite::
Debugging Plugins
=================
..todo::
Plugins can use Bro's standard debug logger by using the
``PLUGIN_DBG_LOG(<plugin>, <args>)`` macro (defined in
``DebugLogger.h``), where ``<plugin>`` is the ``Plugin`` instance and
``<args>`` are printf-style arguments, just as with Bro's standard
debuggging macros.
At runtime, one then activates a plugin's debugging output with ``-B
plugin-<name>``, where ``<name>`` is the name of the plugin as
returned by its ``Configure()`` method, yet with the
namespace-separator ``::`` replaced with a simple dash. Example: If
the plugin is called ``Bro::Demo``, use ``-B plugin-Bro-Dome``. As
usual, the debugging output will be recorded to ``debug.log`` if Bro's
compiled in debug mode.
Document.
Documenting Plugins
===================

View file

@ -426,6 +426,6 @@ add_dependencies(bro bif_loader_plugins)
# Install *.bif.bro.
install(DIRECTORY ${CMAKE_BINARY_DIR}/scripts/base/bif DESTINATION ${BRO_SCRIPT_INSTALL_PATH}/base)
# Make clean removes the bif and plugin directories.
# Make clean removes the bif directory.
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/scripts/base/bif)

View file

@ -277,17 +277,11 @@ int BroFunc::IsPure() const
return 1;
}
Val* BroFunc::Call(val_list* args, Frame* parent) const
Val* BroFunc::HandlePluginResult(Val* plugin_resul, tval_list* args)
{
#ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", id->Name());
#endif
// Helper function factoring out this code from BroFunc:Call() for better
// readability.
Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0);
if ( plugin_result )
{
// TODO: We should factor this out into its own method.
switch ( Flavor() ) {
case FUNC_FLAVOR_EVENT:
Unref(plugin_result);
@ -326,6 +320,17 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
return plugin_result;
}
Val* BroFunc::Call(val_list* args, Frame* parent) const
{
#ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", id->Name());
#endif
Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0);
if ( plugin_result )
return HandlePluginResult(plugin_result, args);
if ( bodies.empty() )
{
// Can only happen for events and hooks.

View file

@ -100,6 +100,7 @@ public:
protected:
BroFunc() : Func(BRO_FUNC) {}
Stmt* AddInits(Stmt* body, id_list* inits);
Val* HandlePluginResult(Val* plugin_result, val_list* args);
DECLARE_SERIAL(BroFunc);

View file

@ -94,9 +94,7 @@ int BroObj::suppress_errors = 0;
BroObj::~BroObj()
{
if ( notify_plugins )
{
PLUGIN_HOOK_VOID(HOOK_BRO_OBJ_DTOR, HookBroObjDtor(this));
}
delete location;
}

View file

@ -23,7 +23,7 @@ namespace plugin {
* @param method_call The \a Manager method corresponding to the hook.
*/
#define PLUGIN_HOOK_VOID(hook, method_call) \
if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call;
{ if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call; }
/**
* Macro to trigger hooks that return a result.

View file

@ -1626,7 +1626,6 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
unsigned int ret_total;
#ifdef HAVE_MALLINFO
// For memory, getrusage() gives bogus results on Linux. Grmpf.
struct mallinfo mi = mallinfo();
if ( malloced )
@ -1637,7 +1636,7 @@ void get_memory_usage(unsigned int* total, unsigned int* malloced)
struct rusage r;
getrusage(RUSAGE_SELF, &r);
// At least on FreeBSD it's in KB.
// In KB.
ret_total = r.ru_maxrss * 1024;
if ( total )