mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 04:28:20 +00:00
Further polishing and cleanup in preparation for merge.
This commit is contained in:
parent
aeb8e71e8c
commit
9616cd8e61
15 changed files with 79 additions and 60 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
===================
|
||||
|
|
|
@ -154,7 +154,7 @@ export {
|
|||
args: AnalyzerArgs &default=AnalyzerArgs()): bool;
|
||||
|
||||
## Adds all analyzers associated with a give MIME type to the analysis of
|
||||
## a file. Note that analyzers added via MIME types cannot take further
|
||||
## a file. Note that analyzers added via MIME types cannot take further
|
||||
## arguments.
|
||||
##
|
||||
## f: the 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)
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
bool used; // this handler is indeed used somewhere
|
||||
bool enabled;
|
||||
bool error_handler; // this handler reports error messages.
|
||||
bool generate_always;
|
||||
bool generate_always;
|
||||
|
||||
declare(List, SourceID);
|
||||
typedef List(SourceID) receiver_list;
|
||||
|
|
|
@ -49,7 +49,7 @@ void FlowSrc::Process()
|
|||
|
||||
// This is normally done by calling net_packet_dispatch(),
|
||||
// but as we don't have a packet to dispatch ...
|
||||
net_update_time(next_timestamp);
|
||||
net_update_time(next_timestamp);
|
||||
expire_timers();
|
||||
|
||||
netflow_analyzer->downflow()->set_exporter_ip(exporter_ip);
|
||||
|
|
83
src/Func.cc
83
src/Func.cc
|
@ -277,6 +277,49 @@ int BroFunc::IsPure() const
|
|||
return 1;
|
||||
}
|
||||
|
||||
Val* BroFunc::HandlePluginResult(Val* plugin_resul, tval_list* args)
|
||||
{
|
||||
// Helper function factoring out this code from BroFunc:Call() for better
|
||||
// readability.
|
||||
|
||||
switch ( Flavor() ) {
|
||||
case FUNC_FLAVOR_EVENT:
|
||||
Unref(plugin_result);
|
||||
plugin_result = 0;
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_HOOK:
|
||||
if ( plugin_result->Type()->Tag() != TYPE_BOOL )
|
||||
reporter->InternalError("plugin returned non-bool for hook");
|
||||
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_FUNCTION:
|
||||
{
|
||||
BroType* yt = FType()->YieldType();
|
||||
|
||||
if ( (! yt) || yt->Tag() == TYPE_VOID )
|
||||
{
|
||||
Unref(plugin_result);
|
||||
plugin_result = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ( plugin_result->Type()->Tag() != yt->Tag() )
|
||||
reporter->InternalError("plugin returned wrong type for function call");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
loop_over_list(*args, i)
|
||||
Unref((*args)[i]);
|
||||
|
||||
return plugin_result;
|
||||
}
|
||||
|
||||
Val* BroFunc::Call(val_list* args, Frame* parent) const
|
||||
{
|
||||
#ifdef PROFILE_BRO_FUNCTIONS
|
||||
|
@ -286,45 +329,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
|
|||
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);
|
||||
plugin_result = 0;
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_HOOK:
|
||||
if ( plugin_result->Type()->Tag() != TYPE_BOOL )
|
||||
reporter->InternalError("plugin returned non-bool for hook");
|
||||
|
||||
break;
|
||||
|
||||
case FUNC_FLAVOR_FUNCTION:
|
||||
{
|
||||
BroType* yt = FType()->YieldType();
|
||||
|
||||
if ( (! yt) || yt->Tag() == TYPE_VOID )
|
||||
{
|
||||
Unref(plugin_result);
|
||||
plugin_result = 0;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if ( plugin_result->Type()->Tag() != yt->Tag() )
|
||||
reporter->InternalError("plugin returned wrong type for function call");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
loop_over_list(*args, i)
|
||||
Unref((*args)[i]);
|
||||
|
||||
return plugin_result;
|
||||
}
|
||||
return HandlePluginResult(plugin_result, args);
|
||||
|
||||
if ( bodies.empty() )
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -94,9 +94,7 @@ int BroObj::suppress_errors = 0;
|
|||
BroObj::~BroObj()
|
||||
{
|
||||
if ( notify_plugins )
|
||||
{
|
||||
PLUGIN_HOOK_VOID(HOOK_BRO_OBJ_DTOR, HookBroObjDtor(this));
|
||||
}
|
||||
PLUGIN_HOOK_VOID(HOOK_BRO_OBJ_DTOR, HookBroObjDtor(this));
|
||||
|
||||
delete location;
|
||||
}
|
||||
|
|
|
@ -547,7 +547,7 @@ class EnumType : public BroType {
|
|||
public:
|
||||
typedef std::list<std::pair<string, bro_int_t> > enum_name_list;
|
||||
|
||||
EnumType(EnumType* e);
|
||||
EnumType(EnumType* e);
|
||||
EnumType(const string& arg_name);
|
||||
~EnumType();
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ public:
|
|||
// is now fully closed, a connection_finished event will be
|
||||
// generated; otherwise not.
|
||||
virtual void ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint,
|
||||
analyzer::tcp::TCP_Endpoint* peer, int gen_event);
|
||||
analyzer::tcp::TCP_Endpoint* peer, int gen_event);
|
||||
virtual void ConnectionFinished(int half_finished);
|
||||
virtual void ConnectionReset();
|
||||
|
||||
|
|
|
@ -444,7 +444,7 @@ Analyzer* Manager::InstantiateAnalyzer(Tag tag, RecordVal* args, File* f) const
|
|||
if ( ! c->Factory() )
|
||||
{
|
||||
reporter->InternalWarning("file analyzer %s cannot be instantiated "
|
||||
"dynamically", c->CanonicalName().c_str());
|
||||
"dynamically", c->CanonicalName().c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// See the file in the main distribution directory for copyright.
|
||||
// See the file in the main distribution directory for copyright.
|
||||
|
||||
#include "plugin/Plugin.h"
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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 )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue