When creating a new stream, we check now that all log field have

supported types.

Also not reporting a run-time error anymore when logging to a stream
that hasn't been created; just fail silently as this may happen due to
other earlier errors.
This commit is contained in:
Robin Sommer 2011-03-09 19:20:06 -08:00
parent 5beee9e45e
commit de227b8d88
2 changed files with 53 additions and 1 deletions

View file

@ -77,7 +77,48 @@ LogVal::~LogVal()
} }
} }
bool LogVal::IsCompatibleType(BroType* t, bool atomic_only)
{
if ( ! t )
return false;
switch ( t->Tag() ) {
case TYPE_BOOL:
case TYPE_INT:
case TYPE_COUNT:
case TYPE_COUNTER:
case TYPE_PORT:
case TYPE_SUBNET:
case TYPE_NET:
case TYPE_ADDR:
case TYPE_DOUBLE:
case TYPE_TIME:
case TYPE_INTERVAL:
case TYPE_ENUM:
case TYPE_STRING:
return true;
case TYPE_RECORD:
return ! atomic_only;
case TYPE_TABLE:
{
if ( atomic_only )
return false;
if ( ! t->IsSet() )
return false;
return IsCompatibleType(t->AsSetType()->Indices()->PureType());
}
default:
return false;
}
return false;
}
bool LogVal::Read(SerializationFormat* fmt) bool LogVal::Read(SerializationFormat* fmt)
{ {
int ty; int ty;
@ -302,7 +343,7 @@ LogMgr::Stream* LogMgr::FindStream(EnumVal* id)
if ( idx >= streams.size() || ! streams[idx] ) if ( idx >= streams.size() || ! streams[idx] )
{ {
run_time(fmt("unknown log stream (%d)", id->AsEnum())); // run_time(fmt("unknown log stream (%d)", id->AsEnum()));
return 0; return 0;
} }
@ -338,6 +379,15 @@ bool LogMgr::CreateStream(EnumVal* id, RecordVal* sval)
RecordType* columns = sval->Lookup(rtype->FieldOffset("columns"))->AsType()->AsTypeType()->Type()->AsRecordType(); RecordType* columns = sval->Lookup(rtype->FieldOffset("columns"))->AsType()->AsTypeType()->Type()->AsRecordType();
for ( int i = 0; i < columns->NumFields(); i++ )
{
if ( ! LogVal::IsCompatibleType(columns->FieldType(i)) )
{
run_time("type of field '%s' is not support for logging output", columns->FieldName(i));
return false;
}
}
Val* event_val = sval->Lookup(rtype->FieldOffset("ev")); Val* event_val = sval->Lookup(rtype->FieldOffset("ev"));
Func* event = event_val ? event_val->AsFunc() : 0; Func* event = event_val ? event_val->AsFunc() : 0;

View file

@ -54,6 +54,8 @@ struct LogVal {
bool Read(SerializationFormat* fmt); bool Read(SerializationFormat* fmt);
bool Write(SerializationFormat* fmt) const; bool Write(SerializationFormat* fmt) const;
static bool IsCompatibleType(BroType* t, bool atomic_only=false);
private: private:
LogVal(const LogVal& other) { } LogVal(const LogVal& other) { }
}; };