Coerce event handler record arguments to correct record type.

This lets events be sent to bro that contain record arguments that
don't have to fill in all &optional record fields.

This corresponds to broccoli-python tests that were updated in
commit 8b87d8f61ef89162019cd4acc01be93700b0c588
This commit is contained in:
Jon Siwek 2011-06-15 13:56:37 -05:00
parent 4f6690776c
commit 303dba6372
2 changed files with 29 additions and 0 deletions

View file

@ -69,7 +69,32 @@ void EventHandler::Call(val_list* vl, bool no_remote)
}
if ( local )
{
if ( FType() )
{
const type_list* arg_types = type->ArgTypes()->Types();
loop_over_list(*vl, i)
{
Val* v = (*vl)[i];
BroType* va_t = v->Type();
BroType* ar_t = (*arg_types)[i];
if ( va_t->Tag() == TYPE_RECORD && ar_t->Tag() == TYPE_RECORD )
{
if ( ! same_type(va_t, ar_t) )
{
Val* nv;
nv = v->AsRecordVal()->CoerceTo(ar_t->AsRecordType());
if ( nv )
{
vl->replace(i, nv);
Unref(v);
}
}
}
}
}
Unref(local->Call(vl));
}
else
{
loop_over_list(*vl, i)

View file

@ -13,3 +13,7 @@ Servus
==== record
[a=42, b=6.6.7.7]
42, 6.6.7.7
==== coerced record
[a=13, b=<uninitialized>, c=helloworld]
13
helloworld