mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 12:38:20 +00:00
Merge remote-tracking branch 'origin/master' into topic/bernhard/topk
This commit is contained in:
commit
dbd53a09a6
9 changed files with 285 additions and 14 deletions
26
src/Expr.cc
26
src/Expr.cc
|
@ -4026,7 +4026,27 @@ Val* RecordCoerceExpr::Fold(Val* v) const
|
|||
Type()->AsRecordType()->FieldDecl(i)->FindAttr(ATTR_DEFAULT);
|
||||
|
||||
if ( def )
|
||||
val->Assign(i, def->AttrExpr()->Eval(0));
|
||||
{
|
||||
Val* def_val = def->AttrExpr()->Eval(0);
|
||||
BroType* def_type = def_val->Type();
|
||||
BroType* field_type = Type()->AsRecordType()->FieldType(i);
|
||||
|
||||
if ( def_type->Tag() == TYPE_RECORD &&
|
||||
field_type->Tag() == TYPE_RECORD &&
|
||||
! same_type(def_type, field_type) )
|
||||
{
|
||||
Val* tmp = def_val->AsRecordVal()->CoerceTo(
|
||||
field_type->AsRecordType());
|
||||
|
||||
if ( tmp )
|
||||
{
|
||||
Unref(def_val);
|
||||
def_val = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
val->Assign(i, def_val);
|
||||
}
|
||||
else
|
||||
val->Assign(i, 0);
|
||||
}
|
||||
|
@ -4297,6 +4317,10 @@ Val* ScheduleExpr::Eval(Frame* f) const
|
|||
if ( args )
|
||||
{
|
||||
TimerMgr* tmgr = mgr.CurrentTimerMgr();
|
||||
|
||||
if ( ! tmgr )
|
||||
tmgr = timer_mgr;
|
||||
|
||||
tmgr->Add(new ScheduleTimer(event->Handler(), args, dt, tmgr));
|
||||
}
|
||||
|
||||
|
|
14
src/Val.cc
14
src/Val.cc
|
@ -2560,10 +2560,22 @@ RecordVal::RecordVal(RecordType* t) : MutableVal(t)
|
|||
Attributes* a = record_type->FieldDecl(i)->attrs;
|
||||
Attr* def_attr = a ? a->FindAttr(ATTR_DEFAULT) : 0;
|
||||
Val* def = def_attr ? def_attr->AttrExpr()->Eval(0) : 0;
|
||||
BroType* type = record_type->FieldDecl(i)->type;
|
||||
|
||||
if ( def && type->Tag() == TYPE_RECORD &&
|
||||
def->Type()->Tag() == TYPE_RECORD &&
|
||||
! same_type(def->Type(), type) )
|
||||
{
|
||||
Val* tmp = def->AsRecordVal()->CoerceTo(type->AsRecordType());
|
||||
if ( tmp )
|
||||
{
|
||||
Unref(def);
|
||||
def = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! def && ! (a && a->FindAttr(ATTR_OPTIONAL)) )
|
||||
{
|
||||
BroType* type = record_type->FieldDecl(i)->type;
|
||||
TypeTag tag = type->Tag();
|
||||
|
||||
if ( tag == TYPE_RECORD )
|
||||
|
|
93
src/bro.bif
93
src/bro.bif
|
@ -622,7 +622,7 @@ function md5_hmac%(...%): string
|
|||
## ``md5_hash_update(c$http$md5_handle, some_more_data)`` in the
|
||||
## :bro:id:`http_entity_data` event handler. When all data has arrived, a call
|
||||
## to :bro:id:`md5_hash_finish` returns the final hash value.
|
||||
##
|
||||
##
|
||||
## Returns: The opaque handle associated with this hash computation.
|
||||
##
|
||||
## .. bro:see:: md5_hmac md5_hash md5_hash_update md5_hash_finish
|
||||
|
@ -2464,6 +2464,97 @@ function bytestring_to_double%(s: string%): double
|
|||
return new Val(ntohd(d), TYPE_DOUBLE);
|
||||
%}
|
||||
|
||||
## Converts a string of bytes to a :bro:type:`count`.
|
||||
##
|
||||
## s: A string of bytes containing the binary representation of the value.
|
||||
##
|
||||
## is_le: If true, *s* is assumed to be in little endian format, else it's big endian.
|
||||
##
|
||||
## Returns: The value contained in *s*, or 0 if the conversion failed.
|
||||
##
|
||||
function bytestring_to_count%(s: string, is_le: bool%): count
|
||||
%{
|
||||
#ifdef HOST_BIGENDIAN
|
||||
static const bool host_bigendian = true;
|
||||
#else
|
||||
static const bool host_bigendian = false;
|
||||
#endif
|
||||
const u_char *p = s->Bytes();
|
||||
unsigned int i;
|
||||
|
||||
switch ( s->Len() ) {
|
||||
case sizeof(uint8):
|
||||
{
|
||||
uint8 value = 0;
|
||||
memcpy(&value, p, sizeof(uint8));
|
||||
return new Val(value, TYPE_COUNT);
|
||||
}
|
||||
|
||||
case sizeof(uint16):
|
||||
{
|
||||
uint16 value = 0;
|
||||
|
||||
if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) )
|
||||
{
|
||||
char buf[sizeof(uint16)];
|
||||
char *d = &buf[sizeof(uint16)-1];
|
||||
|
||||
for ( i = 0; i < sizeof(uint16); i++ )
|
||||
*d-- = *p++;
|
||||
|
||||
memcpy(&value, buf, sizeof(uint16));
|
||||
}
|
||||
else
|
||||
memcpy(&value, p, sizeof(uint16));
|
||||
|
||||
return new Val(value, TYPE_COUNT);
|
||||
}
|
||||
|
||||
case sizeof(uint32):
|
||||
{
|
||||
uint32 value = 0;
|
||||
|
||||
if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) )
|
||||
{
|
||||
char buf[sizeof(uint32)];
|
||||
char *d = &buf[sizeof(uint32)-1];
|
||||
|
||||
for ( i = 0; i < sizeof(uint32); i++ )
|
||||
*d-- = *p++;
|
||||
|
||||
memcpy(&value, buf, sizeof(uint32));
|
||||
}
|
||||
else
|
||||
memcpy(&value, p, sizeof(uint32));
|
||||
|
||||
return new Val(value, TYPE_COUNT);
|
||||
}
|
||||
|
||||
case sizeof(uint64):
|
||||
{
|
||||
uint64 value = 0;
|
||||
|
||||
if ( (host_bigendian && is_le) || (! host_bigendian && ! is_le) )
|
||||
{
|
||||
char buf[sizeof(uint64)];
|
||||
char *d = &buf[sizeof(uint64)-1];
|
||||
|
||||
for ( i = 0; i < sizeof(uint64); i++ )
|
||||
*d-- = *p++;
|
||||
|
||||
memcpy(&value, buf, sizeof(uint64));
|
||||
}
|
||||
else
|
||||
memcpy(&value, p, sizeof(uint64));
|
||||
|
||||
return new Val(value, TYPE_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
builtin_error("unsupported byte length for bytestring_to_count");
|
||||
return new Val(0, TYPE_COUNT);
|
||||
%}
|
||||
|
||||
## Converts a reverse pointer name to an address. For example,
|
||||
## ``1.0.168.192.in-addr.arpa`` to ``192.168.0.1``.
|
||||
##
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue