mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 22:58:20 +00:00
Incremental
This commit is contained in:
parent
be5cb549a9
commit
6055b56f5c
3 changed files with 114 additions and 122 deletions
98
src/Func.cc
98
src/Func.cc
|
@ -249,38 +249,34 @@ TraversalCode Func::Traverse(TraversalCallback* cb) const
|
||||||
|
|
||||||
ValWrapper* Func::HandlePluginResult(ValWrapper* plugin_result, val_list* args, function_flavor flavor) const
|
ValWrapper* Func::HandlePluginResult(ValWrapper* plugin_result, val_list* args, function_flavor flavor) const
|
||||||
{
|
{
|
||||||
// We either have not received a plugin result, or the plugin result hasn't been processed (read: fall into ::Call method)
|
// We either have not received a plugin result, or the plugin result hasn't been processed (read: fall into ::Call method)
|
||||||
if(!plugin_result)
|
if(!plugin_result)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(!plugin_result->processed)
|
if(!plugin_result->processed)
|
||||||
{
|
{
|
||||||
if(plugin_result->value)
|
if(plugin_result->value)
|
||||||
{
|
{
|
||||||
Unref(plugin_result->value);
|
Unref(plugin_result->value);
|
||||||
plugin_result->value = NULL;
|
plugin_result->value = NULL;
|
||||||
}
|
}
|
||||||
delete plugin_result;
|
delete plugin_result;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( flavor ) {
|
switch ( flavor ) {
|
||||||
case FUNC_FLAVOR_EVENT:
|
case FUNC_FLAVOR_EVENT:
|
||||||
if(plugin_result->value)
|
if(plugin_result->value)
|
||||||
{
|
{
|
||||||
char sbuf[1024];
|
reporter->InternalError("plugin returned non-void result for event %s", this->Name());
|
||||||
snprintf(sbuf, 1024, "plugin returned non-void result for event %s", this->Name());
|
}
|
||||||
reporter->InternalError(sbuf);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FUNC_FLAVOR_HOOK:
|
case FUNC_FLAVOR_HOOK:
|
||||||
if ( plugin_result->value->Type()->Tag() != TYPE_BOOL )
|
if ( plugin_result->value->Type()->Tag() != TYPE_BOOL )
|
||||||
{
|
{
|
||||||
char sbuf[1024];
|
reporter->InternalError("plugin returned non-bool for hook %s", this->Name());
|
||||||
snprintf(sbuf, 1024, "plugin returned non-bool for hook %s", this->Name());
|
}
|
||||||
reporter->InternalError(sbuf);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FUNC_FLAVOR_FUNCTION:
|
case FUNC_FLAVOR_FUNCTION:
|
||||||
|
@ -289,19 +285,15 @@ ValWrapper* Func::HandlePluginResult(ValWrapper* plugin_result, val_list* args,
|
||||||
|
|
||||||
if ( (! yt) || yt->Tag() == TYPE_VOID )
|
if ( (! yt) || yt->Tag() == TYPE_VOID )
|
||||||
{
|
{
|
||||||
if(plugin_result && plugin_result->value)
|
if(plugin_result && plugin_result->value)
|
||||||
{
|
{
|
||||||
char sbuf[1024];
|
reporter->InternalError("plugin returned non-void result for void method %s", this->Name());
|
||||||
snprintf(sbuf, 1024, "plugin returned non-void result for void method %s", this->Name());
|
}
|
||||||
reporter->InternalError(sbuf);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ( plugin_result->value && plugin_result->value->Type()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY)
|
else if ( plugin_result->value && plugin_result->value->Type()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY)
|
||||||
{
|
{
|
||||||
char sbuf[1024];
|
reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", plugin_result->value->Type()->Tag(), yt->Tag(), this->Name());
|
||||||
snprintf(sbuf, 1024, "plugin returned wrong type (got %d, expecting %d) for %s", plugin_result->value->Type()->Tag(), yt->Tag(), this->Name());
|
}
|
||||||
reporter->InternalError(sbuf);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -358,13 +350,13 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
|
||||||
|
|
||||||
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
|
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
|
||||||
|
|
||||||
plugin_result = HandlePluginResult(plugin_result, args, Flavor());
|
plugin_result = HandlePluginResult(plugin_result, args, Flavor());
|
||||||
if(plugin_result)
|
if(plugin_result)
|
||||||
{
|
{
|
||||||
Val *result = plugin_result->value;
|
Val *result = plugin_result->value;
|
||||||
delete plugin_result;
|
delete plugin_result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( bodies.empty() )
|
if ( bodies.empty() )
|
||||||
{
|
{
|
||||||
|
@ -455,11 +447,11 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
|
||||||
// Warn if the function returns something, but we returned from
|
// Warn if the function returns something, but we returned from
|
||||||
// the function without an explicit return, or without a value.
|
// the function without an explicit return, or without a value.
|
||||||
else if ( FType()->YieldType() && FType()->YieldType()->Tag() != TYPE_VOID &&
|
else if ( FType()->YieldType() && FType()->YieldType()->Tag() != TYPE_VOID &&
|
||||||
(flow != FLOW_RETURN /* we fell off the end */ ||
|
(flow != FLOW_RETURN /* we fell off the end */ ||
|
||||||
! result /* explicit return with no result */) &&
|
! result /* explicit return with no result */) &&
|
||||||
! f->HasDelayed() )
|
! f->HasDelayed() )
|
||||||
reporter->Warning("non-void function returns without a value: %s",
|
reporter->Warning("non-void function returns without a value: %s",
|
||||||
Name());
|
Name());
|
||||||
|
|
||||||
if ( result && g_trace_state.DoTrace() )
|
if ( result && g_trace_state.DoTrace() )
|
||||||
{
|
{
|
||||||
|
@ -580,13 +572,13 @@ Val* BuiltinFunc::Call(val_list* args, Frame* parent) const
|
||||||
|
|
||||||
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
|
ValWrapper* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
|
||||||
|
|
||||||
plugin_result = HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION);
|
plugin_result = HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION);
|
||||||
if(plugin_result)
|
if(plugin_result)
|
||||||
{
|
{
|
||||||
Val *result = plugin_result->value;
|
Val *result = plugin_result->value;
|
||||||
delete plugin_result;
|
delete plugin_result;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( g_trace_state.DoTrace() )
|
if ( g_trace_state.DoTrace() )
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,12 +83,12 @@ void HookArgument::Describe(ODesc* d) const
|
||||||
d->Add("<null>");
|
d->Add("<null>");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FRAME:
|
case FRAME:
|
||||||
if ( arg.frame )
|
if ( arg.frame )
|
||||||
arg.frame->Describe(d);
|
arg.frame->Describe(d);
|
||||||
else
|
else
|
||||||
d->Add("<null>");
|
d->Add("<null>");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FUNC:
|
case FUNC:
|
||||||
if ( arg.func )
|
if ( arg.func )
|
||||||
|
@ -132,24 +132,24 @@ void HookArgument::Describe(ODesc* d) const
|
||||||
d->Add("<void ptr>");
|
d->Add("<void ptr>");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WRAPPED_VAL:
|
case WRAPPED_VAL:
|
||||||
if ( arg.wrapper )
|
if ( arg.wrapper )
|
||||||
{
|
{
|
||||||
d->Add("wrapped(");
|
d->Add("wrapped(");
|
||||||
if(arg.wrapper->value)
|
if(arg.wrapper->value)
|
||||||
{
|
{
|
||||||
arg.wrapper->value->Describe(d);
|
arg.wrapper->value->Describe(d);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
d->Add("<null>");
|
d->Add("<null>");
|
||||||
d->Add(")");
|
d->Add(")");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
d->Add("<null>");
|
d->Add("<null>");
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ void Plugin::InitPostScript()
|
||||||
|
|
||||||
Plugin::bif_item_list Plugin::BifItems() const
|
Plugin::bif_item_list Plugin::BifItems() const
|
||||||
{
|
{
|
||||||
return bif_items;
|
return bif_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Plugin::Done()
|
void Plugin::Done()
|
||||||
|
@ -399,7 +399,7 @@ void Plugin::Describe(ODesc* d) const
|
||||||
type = "<unknown>";
|
type = "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
d->Add(" ");
|
d->Add(" ");
|
||||||
d->Add("[");
|
d->Add("[");
|
||||||
d->Add(type);
|
d->Add(type);
|
||||||
d->Add("] ");
|
d->Add("] ");
|
||||||
|
@ -414,7 +414,7 @@ void Plugin::Describe(ODesc* d) const
|
||||||
HookType hook = (*i).first;
|
HookType hook = (*i).first;
|
||||||
int prio = (*i).second;
|
int prio = (*i).second;
|
||||||
|
|
||||||
d->Add(" Implements ");
|
d->Add(" Implements ");
|
||||||
d->Add(hook_name(hook));
|
d->Add(hook_name(hook));
|
||||||
d->Add(" (priority ");
|
d->Add(" (priority ");
|
||||||
d->Add(prio);
|
d->Add(prio);
|
||||||
|
|
|
@ -34,24 +34,24 @@ class Plugin;
|
||||||
* Plugins' function handlers return a result of this type.
|
* Plugins' function handlers return a result of this type.
|
||||||
*/
|
*/
|
||||||
struct ValWrapper {
|
struct ValWrapper {
|
||||||
Val* value; //< value being wrapped by this object
|
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)
|
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.
|
Wrapper for a specific value. If we're setting a value, we assume we've processed something.
|
||||||
|
|
||||||
@param value value to be wrapped
|
@param value value to be wrapped
|
||||||
*/
|
*/
|
||||||
ValWrapper(Val* value)
|
ValWrapper(Val* value)
|
||||||
: value(value), processed(true) { }
|
: 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.
|
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
|
@param processed whether or not an execution of a function was handled by the plugin
|
||||||
*/
|
*/
|
||||||
ValWrapper(bool processed)
|
ValWrapper(bool processed)
|
||||||
: value(NULL), processed(processed) { }
|
: value(NULL), processed(processed) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -237,15 +237,15 @@ public:
|
||||||
*/
|
*/
|
||||||
HookArgument(void* p) { type = VOIDP; arg.voidp = p; }
|
HookArgument(void* p) { type = VOIDP; arg.voidp = p; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with a ValWrapper argument.
|
* Constructor with a ValWrapper argument.
|
||||||
*/
|
*/
|
||||||
HookArgument(ValWrapper* a) { type = WRAPPED_VAL; arg.wrapper = a; }
|
HookArgument(ValWrapper* a) { type = WRAPPED_VAL; arg.wrapper = a; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with a Frame argument.
|
* Constructor with a Frame argument.
|
||||||
*/
|
*/
|
||||||
HookArgument(Frame* f) { type = FRAME; arg.frame = f; }
|
HookArgument(Frame* f) { type = FRAME; arg.frame = f; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for a boolen argument. The argument's type must
|
* Returns the value for a boolen argument. The argument's type must
|
||||||
|
@ -289,17 +289,17 @@ public:
|
||||||
*/
|
*/
|
||||||
const Val* AsVal() const { assert(type == VAL); return arg.val; }
|
const Val* AsVal() const { assert(type == VAL); return arg.val; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for a Bro wrapped value argument. The argument's type must
|
* Returns the value for a Bro wrapped value argument. The argument's type must
|
||||||
* match accordingly.
|
* match accordingly.
|
||||||
*/
|
*/
|
||||||
const ValWrapper* AsValWrapper() const { assert(type == VAL_WRAPPER); return arg.wrapper; }
|
const ValWrapper* AsValWrapper() const { assert(type == VAL_WRAPPER); return arg.wrapper; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for a Bro frame argument. The argument's type must
|
* Returns the value for a Bro frame argument. The argument's type must
|
||||||
* match accordingly.
|
* match accordingly.
|
||||||
*/
|
*/
|
||||||
const Frame* AsFrame() const { assert(type == FRAME); return arg.frame; }
|
const Frame* AsFrame() const { assert(type == FRAME); return arg.frame; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the value for a list of Bro values argument. The argument's type must
|
* Returns the value for a list of Bro values argument. The argument's type must
|
||||||
|
@ -332,10 +332,10 @@ private:
|
||||||
double double_;
|
double double_;
|
||||||
const Event* event;
|
const Event* event;
|
||||||
const Func* func;
|
const Func* func;
|
||||||
const Frame* frame;
|
const Frame* frame;
|
||||||
int int_;
|
int int_;
|
||||||
const Val* val;
|
const Val* val;
|
||||||
const ValWrapper* wrapper;
|
const ValWrapper* wrapper;
|
||||||
const val_list* vals;
|
const val_list* vals;
|
||||||
const void* voidp;
|
const void* voidp;
|
||||||
} arg;
|
} arg;
|
||||||
|
@ -564,7 +564,7 @@ protected:
|
||||||
* actually has code to execute for it. By calling this method, the
|
* actually has code to execute for it. By calling this method, the
|
||||||
* plugin tells Bro to raise the event even if there's no correspondong
|
* plugin tells Bro to raise the event even if there's no correspondong
|
||||||
* handler; it will then go into HookQueueEvent() just as any other.
|
* handler; it will then go into HookQueueEvent() just as any other.
|
||||||
*
|
*
|
||||||
* @param handler The event handler being interested in.
|
* @param handler The event handler being interested in.
|
||||||
*/
|
*/
|
||||||
void RequestEvent(EventHandlerPtr handler);
|
void RequestEvent(EventHandlerPtr handler);
|
||||||
|
@ -621,11 +621,11 @@ protected:
|
||||||
* counting.
|
* counting.
|
||||||
*
|
*
|
||||||
* @return If the plugin handled the call, a ValWrapper with the
|
* @return If the plugin handled the call, a ValWrapper with the
|
||||||
* processed flag set to true, and a value set on the object with
|
* 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
|
* 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
|
* interpreter. If the plugin did not handle the call, it may either
|
||||||
* return NULL *or* return a ValWrapper with the processed flag set to
|
* return NULL *or* return a ValWrapper with the processed flag set to
|
||||||
* 'false'.
|
* 'false'.
|
||||||
*/
|
*/
|
||||||
virtual ValWrapper* HookCallFunction(const Func* func, Frame *parent, val_list* args);
|
virtual ValWrapper* HookCallFunction(const Func* func, Frame *parent, val_list* args);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue