Merge branch 'master' into topic/gilbert/plugin-api-tweak

Conflicts:
	testing/btest/Baseline/plugins.api-version-mismatch/output
	testing/btest/Baseline/plugins.hooks/output
	testing/btest/plugins/api-version-mismatch.sh
This commit is contained in:
Gilbert Clark 2014-11-24 16:21:23 -05:00
commit 7eadcad674
139 changed files with 3194 additions and 1385 deletions

View file

@ -172,7 +172,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
// Load {bif,scripts}/__load__.bro automatically.
string init = dir + "lib/bif/__load__.bro";
string init = dir + "scripts/__load__.bro";
if ( is_file(init) )
{
@ -180,7 +180,7 @@ bool Manager::ActivateDynamicPluginInternal(const std::string& name, bool ok_if_
scripts_to_load.push_back(init);
}
init = dir + "scripts/__load__.bro";
init = dir + "lib/bif/__load__.bro";
if ( is_file(init) )
{
@ -559,7 +559,7 @@ int Manager::HookLoadFile(const string& file)
return rc;
}
ValWrapper* Manager::HookCallFunction(const Func* func, Frame* parent, val_list* vargs) const
std::pair<Val*, bool> Manager::HookCallFunction(const Func* func, Frame* parent, val_list* vargs) const
{
HookArgumentList args;
@ -573,7 +573,7 @@ ValWrapper* Manager::HookCallFunction(const Func* func, Frame* parent, val_list*
hook_list* l = hooks[HOOK_CALL_FUNCTION];
ValWrapper* v = 0;
std::pair<Val*, bool> v;
if ( l )
for ( hook_list::iterator i = l->begin(); i != l->end(); ++i )
@ -582,9 +582,11 @@ ValWrapper* Manager::HookCallFunction(const Func* func, Frame* parent, val_list*
v = p->HookCallFunction(func, parent, vargs);
if ( v && v-> processed)
if ( v.second )
{
break;
}
}
}
if ( HavePluginForHook(META_HOOK_POST) )
MetaHookPost(HOOK_CALL_FUNCTION, args, HookArgument(v));

View file

@ -3,6 +3,7 @@
#ifndef PLUGIN_MANAGER_H
#define PLUGIN_MANAGER_H
#include <utility>
#include <map>
#include "Plugin.h"
@ -244,7 +245,7 @@ public:
* functions and events, it may be any Val and must be ignored). If no
* plugin handled the call, the method returns null.
*/
ValWrapper* HookCallFunction(const Func* func, Frame *parent, val_list* args) const;
std::pair<Val*, bool> HookCallFunction(const Func* func, Frame *parent, val_list* args) const;
/**
* Hook that filters the queuing of an event.

View file

@ -133,21 +133,14 @@ void HookArgument::Describe(ODesc* d) const
break;
case WRAPPED_VAL:
if ( arg.wrapper )
d->Add("wrapped(");
if(wrapper.first)
{
d->Add("wrapped(");
if(arg.wrapper->value)
{
arg.wrapper->value->Describe(d);
}
else
d->Add("<null>");
d->Add(")");
wrapper.first->Describe(d);
}
else
{
d->Add("<null>");
}
d->Add(")");
break;
@ -298,9 +291,10 @@ int Plugin::HookLoadFile(const std::string& file, const std::string& ext)
return -1;
}
ValWrapper* Plugin::HookCallFunction(const Func* func, Frame *parent, val_list* args)
std::pair<Val*, bool> Plugin::HookCallFunction(const Func* func, Frame *parent, val_list* args)
{
return 0;
std::pair<Val*, bool> result(NULL, false);
return result;
}
bool Plugin::HookQueueEvent(Event* event)

View file

@ -5,6 +5,7 @@
#include <list>
#include <string>
#include <utility>
#include "config.h"
#include "analyzer/Component.h"
@ -26,34 +27,6 @@ class Manager;
class Component;
class Plugin;
/**
* In certain cases, functions may have well-defined return types but still return NULL values (e.g. delayed functions, opaque types).
* Thus, it's necessary to explicitly define whether or not a plugin has handled a function in addition to recording the value it has
* returned.
*
* Plugins' function handlers return a result of this type.
*/
struct ValWrapper {
Val* value; //< value being wrapped by this object
bool processed; //< true if execution should *STOP* (read: the plugin is replacing a method), and false if execution should *CONTINUE* (read: bro should execute a method)
/**
Wrapper for a specific value. If we're setting a value, we assume we've processed something.
@param value value to be wrapped
*/
ValWrapper(Val* value)
: value(value), processed(true) { }
/**
Wrapper for a specific value. If we're setting 'processed', we assume there's a reason we're not setting a Val and set that to NULL.
@param processed whether or not an execution of a function was handled by the plugin
*/
ValWrapper(bool processed)
: value(NULL), processed(processed) { }
};
/**
* Hook types that a plugin may define. Each label maps to the corresponding
* virtual method in \a Plugin.
@ -238,9 +211,9 @@ public:
HookArgument(void* p) { type = VOIDP; arg.voidp = p; }
/**
* Constructor with a ValWrapper argument.
* Constructor with a wrapped Val argument.
*/
HookArgument(ValWrapper* a) { type = WRAPPED_VAL; arg.wrapper = a; }
HookArgument(std::pair<Val*, bool> a) { type = WRAPPED_VAL; wrapper = a; }
/**
* Constructor with a Frame argument.
@ -293,7 +266,7 @@ public:
* Returns the value for a Bro wrapped value argument. The argument's type must
* match accordingly.
*/
const ValWrapper* AsValWrapper() const { assert(type == VAL_WRAPPER); return arg.wrapper; }
const std::pair<Val*, bool> AsValWrapper() const { assert(type == VAL_WRAPPER); return wrapper; }
/**
* Returns the value for a Bro frame argument. The argument's type must
@ -335,11 +308,11 @@ private:
const Frame* frame;
int int_;
const Val* val;
const ValWrapper* wrapper;
const val_list* vals;
const void* voidp;
} arg;
std::pair<Val*, bool> wrapper; // Outside union because it has dtor.
std::string arg_string; // Outside union because it has dtor.
};
@ -620,14 +593,13 @@ protected:
* in place as long as it ensures matching types and correct reference
* counting.
*
* @return If the plugin handled the call, a ValWrapper with the
* @return If the plugin handled the call, a std::pair<Val*, bool> with the
* processed flag set to true, and a value set on the object with
* a+1 reference count containing the result value to pass back to the
* interpreter. If the plugin did not handle the call, it may either
* return NULL *or* return a ValWrapper with the processed flag set to
* 'false'.
* interpreter. If the plugin did not handle the call, it must
* return a ValWrapper with the processed flag set to 'false'.
*/
virtual ValWrapper* HookCallFunction(const Func* func, Frame *parent, val_list* args);
virtual std::pair<Val*, bool> HookCallFunction(const Func* func, Frame *parent, val_list* args);
/**
* Hook into raising events. Whenever the script interpreter is about