Deprecate Val(double, TypeTag) ctor, add TimeVal/DoubleVal subclasses

This also updates all usages of the deprecated Val ctor to use
either IntervalVal, TimeVal, or DoubleVal ctors.  The reason for
doing away with the old constructor is that using it with TYPE_INTERVAL
isn't strictly correct since there exists a more specific subclass,
IntervalVal, with overriden ValDescribe() method that ought to be used
to print such values in a more descriptive way.
This commit is contained in:
Jon Siwek 2020-06-02 18:19:40 -07:00
parent a431f6b45d
commit 5b4313b593
76 changed files with 847 additions and 782 deletions

View file

@ -803,8 +803,10 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
if ( tag == TYPE_INTERVAL )
*pval = make_intrusive<IntervalVal>(*kp, 1.0);
else if ( tag == TYPE_TIME )
*pval = make_intrusive<TimeVal>(*kp);
else
*pval = make_intrusive<Val>(*kp, tag);
*pval = make_intrusive<DoubleVal>(*kp);
}
break;

View file

@ -401,8 +401,8 @@ const IntrusivePtr<RecordVal>& Connection::ConnVal()
if ( root_analyzer )
root_analyzer->UpdateConnVal(conn_val.get());
conn_val->Assign(3, make_intrusive<Val>(start_time, TYPE_TIME)); // ###
conn_val->Assign(4, make_intrusive<Val>(last_time - start_time, TYPE_INTERVAL));
conn_val->Assign(3, make_intrusive<TimeVal>(start_time)); // ###
conn_val->Assign(4, make_intrusive<IntervalVal>(last_time - start_time));
conn_val->Assign(6, make_intrusive<StringVal>(history.c_str()));
conn_val->Assign(11, val_mgr->Bool(is_successful));

View file

@ -718,7 +718,7 @@ IntrusivePtr<Val> DNS_Mgr::BuildMappingVal(DNS_Mapping* dm)
{
auto r = make_intrusive<RecordVal>(dm_rec);
r->Assign(0, make_intrusive<Val>(dm->CreationTime(), TYPE_TIME));
r->Assign(0, make_intrusive<TimeVal>(dm->CreationTime()));
r->Assign(1, make_intrusive<StringVal>(dm->ReqHost() ? dm->ReqHost() : ""));
r->Assign(2, make_intrusive<AddrVal>(dm->ReqAddr()));
r->Assign(3, val_mgr->Bool(dm->Valid()));

View file

@ -675,9 +675,11 @@ IntrusivePtr<Val> BinaryExpr::Fold(Val* v1, Val* v2) const
const auto& ret_type = IsVector(GetType()->Tag()) ? GetType()->Yield() : GetType();
if ( ret_type->Tag() == TYPE_INTERVAL )
return make_intrusive<IntervalVal>(d3, 1.0);
else if ( ret_type->InternalType() == TYPE_INTERNAL_DOUBLE )
return make_intrusive<Val>(d3, ret_type->Tag());
return make_intrusive<IntervalVal>(d3);
else if ( ret_type->Tag() == TYPE_TIME )
return make_intrusive<TimeVal>(d3);
else if ( ret_type->Tag() == TYPE_DOUBLE )
return make_intrusive<DoubleVal>(d3);
else if ( ret_type->InternalType() == TYPE_INTERNAL_UNSIGNED )
return val_mgr->Count(u3);
else if ( ret_type->Tag() == TYPE_BOOL )
@ -1097,9 +1099,9 @@ NegExpr::NegExpr(IntrusivePtr<Expr> arg_op)
IntrusivePtr<Val> NegExpr::Fold(Val* v) const
{
if ( v->GetType()->Tag() == TYPE_DOUBLE )
return make_intrusive<Val>(- v->InternalDouble(), v->GetType()->Tag());
return make_intrusive<DoubleVal>(- v->InternalDouble());
else if ( v->GetType()->Tag() == TYPE_INTERVAL )
return make_intrusive<IntervalVal>(- v->InternalDouble(), 1.0);
return make_intrusive<IntervalVal>(- v->InternalDouble());
else
return val_mgr->Int(- v->CoerceToInt());
}
@ -3461,7 +3463,7 @@ IntrusivePtr<Val> ArithCoerceExpr::FoldSingleVal(Val* v, InternalTypeTag t) cons
{
switch ( t ) {
case TYPE_INTERNAL_DOUBLE:
return make_intrusive<Val>(v->CoerceToDouble(), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(v->CoerceToDouble());
case TYPE_INTERNAL_INT:
return val_mgr->Int(v->CoerceToInt());

View file

@ -288,7 +288,7 @@ RecordVal* BroFile::Rotate()
return nullptr;
}
info->Assign(2, make_intrusive<Val>(open_time, TYPE_TIME));
info->Assign<TimeVal>(2, open_time);
Unlink();

View file

@ -493,7 +493,7 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out,
vl.reserve(vl_size);
if ( time )
vl.emplace_back(make_intrusive<Val>(network_time ? network_time : current_time(), TYPE_TIME));
vl.emplace_back(make_intrusive<TimeVal>(network_time ? network_time : current_time()));
vl.emplace_back(make_intrusive<StringVal>(buffer));

View file

@ -212,7 +212,7 @@ static void print_log(const std::vector<IntrusivePtr<Val>>& vals)
vec->Assign(vec->Size(), make_intrusive<StringVal>(d.Description()));
}
record->Assign(0, make_intrusive<Val>(current_time(), TYPE_TIME));
record->Assign(0, make_intrusive<TimeVal>(current_time()));
record->Assign(1, std::move(vec));
log_mgr->Write(plval.get(), record.get());
}

View file

@ -271,14 +271,14 @@ IntrusivePtr<Val> Val::SizeVal() const
return val_mgr->Count(val.uint_val);
case TYPE_INTERNAL_DOUBLE:
return make_intrusive<Val>(fabs(val.double_val), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(fabs(val.double_val));
case TYPE_INTERNAL_OTHER:
if ( type->Tag() == TYPE_FUNC )
return val_mgr->Count(val.func_val->GetType()->ParamList()->Types().size());
if ( type->Tag() == TYPE_FILE )
return make_intrusive<Val>(val.file_val->Size(), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(val.file_val->Size());
break;
default:
@ -666,11 +666,6 @@ IntrusivePtr<StringVal> Val::ToJSON(bool only_loggable, RE_Matcher* re)
return make_intrusive<StringVal>(buffer.GetString());
}
IntervalVal::IntervalVal(double quantity, double units) :
Val(quantity * units, TYPE_INTERVAL)
{
}
void IntervalVal::ValDescribe(ODesc* d) const
{
using unit_word = std::pair<double, const char*>;
@ -925,7 +920,7 @@ unsigned int SubNetVal::MemoryAllocation() const
IntrusivePtr<Val> SubNetVal::SizeVal() const
{
int retained = 128 - val.subnet_val->LengthIPv6();
return make_intrusive<Val>(pow(2.0, double(retained)), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(pow(2.0, double(retained)));
}
void SubNetVal::ValDescribe(ODesc* d) const
@ -3287,7 +3282,20 @@ IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, const BroType* t,
break;
case TYPE_INTERNAL_DOUBLE:
promoted_v = make_intrusive<Val>(v->CoerceToDouble(), t_tag);
switch ( t_tag ) {
case TYPE_DOUBLE:
promoted_v = make_intrusive<DoubleVal>(v->CoerceToDouble());
break;
case TYPE_INTERVAL:
promoted_v = make_intrusive<IntervalVal>(v->CoerceToDouble());
break;
case TYPE_TIME:
promoted_v = make_intrusive<TimeVal>(v->CoerceToDouble());
break;
default:
reporter->InternalError("bad internal type in check_and_promote()");
return nullptr;
}
break;
default:

View file

@ -120,6 +120,7 @@ class Val : public BroObj {
public:
static inline const IntrusivePtr<Val> nil;
[[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]]
Val(double d, TypeTag t)
: val(d), type(base_type(t))
{}
@ -489,14 +490,27 @@ extern ValManager* val_mgr;
class IntervalVal final : public Val {
public:
IntervalVal(double quantity, double units);
IntervalVal(double quantity, double units = Seconds)
: Val(quantity * units, base_type(TYPE_INTERVAL))
{}
protected:
IntervalVal() {}
void ValDescribe(ODesc* d) const override;
};
class TimeVal final : public Val {
public:
TimeVal(double t)
: Val(t, base_type(TYPE_TIME))
{}
};
class DoubleVal final : public Val {
public:
DoubleVal(double v)
: Val(v, base_type(TYPE_DOUBLE))
{}
};
class PortVal final : public Val {
public:

View file

@ -94,7 +94,7 @@ void ConnSize_Analyzer::CheckThresholds(bool is_orig)
{
EnqueueConnEvent(conn_duration_threshold_crossed,
ConnVal(),
make_intrusive<Val>(duration_thresh, TYPE_INTERVAL),
make_intrusive<IntervalVal>(duration_thresh),
val_mgr->Bool(is_orig)
);
duration_thresh = 0;

View file

@ -139,7 +139,7 @@ function get_current_conn_duration_threshold%(cid: conn_id%): interval
%{
analyzer::Analyzer* a = GetConnsizeAnalyzer(cid);
if ( ! a )
return make_intrusive<Val>(0.0, TYPE_INTERVAL);
return make_intrusive<IntervalVal>(0.0);
return make_intrusive<Val>(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetDurationThreshold(), TYPE_INTERVAL);
return make_intrusive<IntervalVal>(static_cast<analyzer::conn_size::ConnSize_Analyzer*>(a)->GetDurationThreshold());
%}

View file

@ -57,7 +57,7 @@ refine flow DHCP_Flow += {
dhcp_msg_val->Assign(0, val_mgr->Count(${msg.op}));
dhcp_msg_val->Assign(1, val_mgr->Count(${msg.type}));
dhcp_msg_val->Assign(2, val_mgr->Count(${msg.xid}));
dhcp_msg_val->Assign(3, make_intrusive<Val>(secs, TYPE_INTERVAL));
dhcp_msg_val->Assign(3, make_intrusive<IntervalVal>(secs));
dhcp_msg_val->Assign(4, val_mgr->Count(${msg.flags}));
dhcp_msg_val->Assign(5, make_intrusive<AddrVal>(htonl(${msg.ciaddr})));
dhcp_msg_val->Assign(6, make_intrusive<AddrVal>(htonl(${msg.yiaddr})));

View file

@ -414,7 +414,7 @@ refine flow DHCP_Flow += {
function process_lease_option(v: OptionValue): bool
%{
double lease = static_cast<double>(${v.lease});
${context.flow}->options->Assign(11, make_intrusive<Val>(lease, TYPE_INTERVAL));
${context.flow}->options->Assign(11, make_intrusive<IntervalVal>(lease));
return true;
%}
@ -546,7 +546,7 @@ refine flow DHCP_Flow += {
function process_renewal_time_option(v: OptionValue): bool
%{
double renewal_time = static_cast<double>(${v.renewal_time});
${context.flow}->options->Assign(16, make_intrusive<Val>(renewal_time, TYPE_INTERVAL));
${context.flow}->options->Assign(16, make_intrusive<IntervalVal>(renewal_time));
return true;
%}
@ -571,7 +571,7 @@ refine flow DHCP_Flow += {
function process_rebinding_time_option(v: OptionValue): bool
%{
double rebinding_time = static_cast<double>(${v.rebinding_time});
${context.flow}->options->Assign(17, make_intrusive<Val>(rebinding_time, TYPE_INTERVAL));
${context.flow}->options->Assign(17, make_intrusive<IntervalVal>(rebinding_time));
return true;
%}

View file

@ -1519,8 +1519,8 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig)
r->Assign(1, val_mgr->Count(int(answer_type)));
r->Assign(2, make_intrusive<StringVal>(tsig->alg_name));
r->Assign(3, make_intrusive<StringVal>(tsig->sig));
r->Assign(4, make_intrusive<Val>(rtime, TYPE_TIME));
r->Assign(5, make_intrusive<Val>(double(tsig->fudge), TYPE_TIME));
r->Assign(4, make_intrusive<TimeVal>(rtime));
r->Assign(5, make_intrusive<TimeVal>(double(tsig->fudge)));
r->Assign(6, val_mgr->Count(tsig->orig_id));
r->Assign(7, val_mgr->Count(tsig->rr_error));
r->Assign(8, val_mgr->Count(is_query));
@ -1539,8 +1539,8 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig)
r->Assign(3, val_mgr->Count(rrsig->algorithm));
r->Assign(4, val_mgr->Count(rrsig->labels));
r->Assign(5, make_intrusive<IntervalVal>(double(rrsig->orig_ttl), Seconds));
r->Assign(6, make_intrusive<Val>(double(rrsig->sig_exp), TYPE_TIME));
r->Assign(7, make_intrusive<Val>(double(rrsig->sig_incep), TYPE_TIME));
r->Assign(6, make_intrusive<TimeVal>(double(rrsig->sig_exp)));
r->Assign(7, make_intrusive<TimeVal>(double(rrsig->sig_incep)));
r->Assign(8, val_mgr->Count(rrsig->key_tag));
r->Assign(9, make_intrusive<StringVal>(rrsig->signer_name));
r->Assign(10, make_intrusive<StringVal>(rrsig->signature));

View file

@ -618,7 +618,7 @@ IntrusivePtr<RecordVal> HTTP_Message::BuildMessageStat(bool interrupted, const c
static auto http_message_stat = zeek::id::find_type<RecordType>("http_message_stat");
auto stat = make_intrusive<RecordVal>(http_message_stat);
int field = 0;
stat->Assign(field++, make_intrusive<Val>(start_time, TYPE_TIME));
stat->Assign(field++, make_intrusive<TimeVal>(start_time));
stat->Assign(field++, val_mgr->Bool(interrupted));
stat->Assign(field++, make_intrusive<StringVal>(msg));
stat->Assign(field++, val_mgr->Count(body_length));
@ -1156,8 +1156,8 @@ void HTTP_Analyzer::GenStats()
auto r = make_intrusive<RecordVal>(http_stats_rec);
r->Assign(0, val_mgr->Count(num_requests));
r->Assign(1, val_mgr->Count(num_replies));
r->Assign(2, make_intrusive<Val>(request_version.ToDouble(), TYPE_DOUBLE));
r->Assign(3, make_intrusive<Val>(reply_version.ToDouble(), TYPE_DOUBLE));
r->Assign(2, make_intrusive<DoubleVal>(request_version.ToDouble()));
r->Assign(3, make_intrusive<DoubleVal>(reply_version.ToDouble()));
// DEBUG_MSG("%.6f http_stats\n", network_time);
EnqueueConnEvent(http_stats, ConnVal(), std::move(r));

View file

@ -51,7 +51,7 @@ IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs)
if ( !lResult )
lResult = 0;
return make_intrusive<Val>(double(lResult + double(usecs/100000.0)), TYPE_TIME);
return make_intrusive<TimeVal>(double(lResult + double(usecs/100000.0)));
}
%}

View file

@ -12,7 +12,7 @@
// Bro can't support times back to the 1600's
// so we subtract a lot of seconds.
auto bro_ts = make_intrusive<Val>(secs - 11644473600.0, TYPE_TIME);
auto bro_ts = make_intrusive<TimeVal>(secs - 11644473600.0);
return bro_ts;
}

View file

@ -20,15 +20,15 @@
IntrusivePtr<Val> proc_ntp_short(const NTP_Short_Time* t)
{
if ( t->seconds() == 0 && t->fractions() == 0 )
return make_intrusive<Val>(0.0, TYPE_INTERVAL);
return make_intrusive<Val>(t->seconds() + t->fractions()*FRAC_16, TYPE_INTERVAL);
return make_intrusive<IntervalVal>(0.0);
return make_intrusive<IntervalVal>(t->seconds() + t->fractions()*FRAC_16);
}
IntrusivePtr<Val> proc_ntp_timestamp(const NTP_Time* t)
{
if ( t->seconds() == 0 && t->fractions() == 0)
return make_intrusive<Val>(0.0, TYPE_TIME);
return make_intrusive<Val>(EPOCH_OFFSET + t->seconds() + t->fractions()*FRAC_32, TYPE_TIME);
return make_intrusive<TimeVal>(0.0);
return make_intrusive<TimeVal>(EPOCH_OFFSET + t->seconds() + t->fractions()*FRAC_32);
}
// This builds the standard msg record
@ -37,8 +37,8 @@
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::NTP::StandardMessage);
rv->Assign(0, val_mgr->Count(${nsm.stratum}));
rv->Assign(1, make_intrusive<Val>(pow(2, ${nsm.poll}), TYPE_INTERVAL));
rv->Assign(2, make_intrusive<Val>(pow(2, ${nsm.precision}), TYPE_INTERVAL));
rv->Assign(1, make_intrusive<IntervalVal>(pow(2, ${nsm.poll})));
rv->Assign(2, make_intrusive<IntervalVal>(pow(2, ${nsm.precision})));
rv->Assign(3, proc_ntp_short(${nsm.root_delay}));
rv->Assign(4, proc_ntp_short(${nsm.root_dispersion}));

View file

@ -187,11 +187,11 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c,
auto info = make_intrusive<RecordVal>(zeek::BifType::Record::MOUNT3::info_t);
info->Assign(0, zeek::BifType::Enum::rpc_status->GetVal(rpc_status));
info->Assign(1, zeek::BifType::Enum::MOUNT3::status_t->GetVal(mount_status));
info->Assign(2, make_intrusive<Val>(c->StartTime(), TYPE_TIME));
info->Assign(3, make_intrusive<Val>(c->LastTime() - c->StartTime(), TYPE_INTERVAL));
info->Assign(2, make_intrusive<TimeVal>(c->StartTime()));
info->Assign(3, make_intrusive<IntervalVal>(c->LastTime() - c->StartTime()));
info->Assign(4, val_mgr->Count(c->RPCLen()));
info->Assign(5, make_intrusive<Val>(rep_start_time, TYPE_TIME));
info->Assign(6, make_intrusive<Val>(rep_last_time - rep_start_time, TYPE_INTERVAL));
info->Assign(5, make_intrusive<TimeVal>(rep_start_time));
info->Assign(6, make_intrusive<IntervalVal>(rep_last_time - rep_start_time));
info->Assign(7, val_mgr->Count(reply_len));
info->Assign(8, val_mgr->Count(c->Uid()));
info->Assign(9, val_mgr->Count(c->Gid()));

View file

@ -320,11 +320,11 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_
auto info = make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::info_t);
info->Assign(0, zeek::BifType::Enum::rpc_status->GetVal(rpc_status));
info->Assign(1, zeek::BifType::Enum::NFS3::status_t->GetVal(nfs_status));
info->Assign(2, make_intrusive<Val>(c->StartTime(), TYPE_TIME));
info->Assign(3, make_intrusive<Val>(c->LastTime()-c->StartTime(), TYPE_INTERVAL));
info->Assign(2, make_intrusive<TimeVal>(c->StartTime()));
info->Assign(3, make_intrusive<IntervalVal>(c->LastTime()-c->StartTime()));
info->Assign(4, val_mgr->Count(c->RPCLen()));
info->Assign(5, make_intrusive<Val>(rep_start_time, TYPE_TIME));
info->Assign(6, make_intrusive<Val>(rep_last_time-rep_start_time, TYPE_INTERVAL));
info->Assign(5, make_intrusive<TimeVal>(rep_start_time));
info->Assign(6, make_intrusive<IntervalVal>(rep_last_time-rep_start_time));
info->Assign(7, val_mgr->Count(reply_len));
info->Assign(8, val_mgr->Count(c->Uid()));
info->Assign(9, val_mgr->Count(c->Gid()));
@ -803,7 +803,7 @@ IntrusivePtr<Val> NFS_Interp::ExtractUint64(const u_char*& buf, int& n)
IntrusivePtr<Val> NFS_Interp::ExtractTime(const u_char*& buf, int& n)
{
return make_intrusive<Val>(extract_XDR_time(buf, n), TYPE_TIME);
return make_intrusive<TimeVal>(extract_XDR_time(buf, n));
}
IntrusivePtr<Val> NFS_Interp::ExtractInterval(const u_char*& buf, int& n)

View file

@ -342,7 +342,7 @@ void RPC_Interpreter::Event_RPC_Dialogue(RPC_CallInfo* c, BifEnum::rpc_status st
val_mgr->Count(c->Version()),
val_mgr->Count(c->Proc()),
zeek::BifType::Enum::rpc_status->GetVal(status),
make_intrusive<Val>(c->StartTime(), TYPE_TIME),
make_intrusive<TimeVal>(c->StartTime()),
val_mgr->Count(c->CallLen()),
val_mgr->Count(reply_len)
);

View file

@ -12,7 +12,7 @@ IntrusivePtr<Val> filetime2brotime(uint64_t ts)
// Bro can't support times back to the 1600's
// so we subtract a lot of seconds.
double secs = (ts / 10000000.0L) - 11644473600.0L;
return make_intrusive<Val>(secs, TYPE_TIME);
return make_intrusive<TimeVal>(secs);
}
IntrusivePtr<Val> time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz)
@ -26,7 +26,7 @@ IntrusivePtr<Val> time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz)
lTime.tm_year = 1980 + ${d.year};
lTime.tm_isdst = -1;
double lResult = mktime(&lTime);
return make_intrusive<Val>(lResult + tz, TYPE_TIME);
return make_intrusive<TimeVal>(lResult + tz);
}
IntrusivePtr<RecordVal> SMB_BuildMACTimes(uint64_t modify, uint64_t access,

View file

@ -108,7 +108,7 @@ struct val_converter {
result_type operator()(double a)
{
if ( type->Tag() == TYPE_DOUBLE )
return make_intrusive<Val>(a, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(a);
return nullptr;
}
@ -168,7 +168,7 @@ struct val_converter {
using namespace std::chrono;
auto s = duration_cast<broker::fractional_seconds>(a.time_since_epoch());
return make_intrusive<Val>(s.count(), TYPE_TIME);
return make_intrusive<TimeVal>(s.count());
}
result_type operator()(broker::timespan& a)
@ -178,7 +178,7 @@ struct val_converter {
using namespace std::chrono;
auto s = duration_cast<broker::fractional_seconds>(a);
return make_intrusive<Val>(s.count(), TYPE_INTERVAL);
return make_intrusive<IntervalVal>(s.count());
}
result_type operator()(broker::enum_value& a)

View file

@ -115,7 +115,7 @@ File::~File()
void File::UpdateLastActivityTime()
{
val->Assign(last_active_idx, make_intrusive<Val>(network_time, TYPE_TIME));
val->Assign(last_active_idx, make_intrusive<TimeVal>(network_time));
}
double File::GetLastActivityTime() const
@ -200,7 +200,7 @@ double File::GetTimeoutInterval() const
void File::SetTimeoutInterval(double interval)
{
val->Assign(timeout_interval_idx, make_intrusive<Val>(interval, TYPE_INTERVAL));
val->Assign(timeout_interval_idx, make_intrusive<IntervalVal>(interval));
}
bool File::SetExtractionLimit(RecordVal* args, uint64_t bytes)

View file

@ -64,11 +64,11 @@ void Entropy::Finalize()
static auto entropy_test_result = zeek::id::find_type<RecordType>("entropy_test_result");
auto ent_result = make_intrusive<RecordVal>(entropy_test_result);
ent_result->Assign(0, make_intrusive<Val>(ent, TYPE_DOUBLE));
ent_result->Assign(1, make_intrusive<Val>(chisq, TYPE_DOUBLE));
ent_result->Assign(2, make_intrusive<Val>(mean, TYPE_DOUBLE));
ent_result->Assign(3, make_intrusive<Val>(montepi, TYPE_DOUBLE));
ent_result->Assign(4, make_intrusive<Val>(scc, TYPE_DOUBLE));
ent_result->Assign<DoubleVal>(0, ent);
ent_result->Assign<DoubleVal>(1, chisq);
ent_result->Assign<DoubleVal>(2, mean);
ent_result->Assign<DoubleVal>(3, montepi);
ent_result->Assign<DoubleVal>(4, scc);
mgr.Enqueue(file_entropy,
GetFile()->ToVal(),

View file

@ -98,7 +98,7 @@ refine flow File += {
{
auto fh = make_intrusive<RecordVal>(zeek::BifType::Record::PE::FileHeader);
fh->Assign(0, val_mgr->Count(${h.Machine}));
fh->Assign(1, make_intrusive<Val>(static_cast<double>(${h.TimeDateStamp}), TYPE_TIME));
fh->Assign(1, make_intrusive<TimeVal>(static_cast<double>(${h.TimeDateStamp})));
fh->Assign(2, val_mgr->Count(${h.PointerToSymbolTable}));
fh->Assign(3, val_mgr->Count(${h.NumberOfSymbols}));
fh->Assign(4, val_mgr->Count(${h.SizeOfOptionalHeader}));

View file

@ -74,7 +74,7 @@ refine flow Flow += {
auto ids_event = make_intrusive<RecordVal>(zeek::BifType::Record::Unified2::IDSEvent);
ids_event->Assign(0, val_mgr->Count(${ev.sensor_id}));
ids_event->Assign(1, val_mgr->Count(${ev.event_id}));
ids_event->Assign(2, make_intrusive<Val>(ts_to_double(${ev.ts}), TYPE_TIME));
ids_event->Assign(2, make_intrusive<TimeVal>(ts_to_double(${ev.ts})));
ids_event->Assign(3, val_mgr->Count(${ev.signature_id}));
ids_event->Assign(4, val_mgr->Count(${ev.generator_id}));
ids_event->Assign(5, val_mgr->Count(${ev.signature_revision}));
@ -100,7 +100,7 @@ refine flow Flow += {
auto ids_event = make_intrusive<RecordVal>(zeek::BifType::Record::Unified2::IDSEvent);
ids_event->Assign(0, val_mgr->Count(${ev.sensor_id}));
ids_event->Assign(1, val_mgr->Count(${ev.event_id}));
ids_event->Assign(2, make_intrusive<Val>(ts_to_double(${ev.ts}), TYPE_TIME));
ids_event->Assign(2, make_intrusive<TimeVal>(ts_to_double(${ev.ts})));
ids_event->Assign(3, val_mgr->Count(${ev.signature_id}));
ids_event->Assign(4, val_mgr->Count(${ev.generator_id}));
ids_event->Assign(5, val_mgr->Count(${ev.signature_revision}));
@ -132,7 +132,7 @@ refine flow Flow += {
packet->Assign(0, val_mgr->Count(${pkt.sensor_id}));
packet->Assign(1, val_mgr->Count(${pkt.event_id}));
packet->Assign(2, val_mgr->Count(${pkt.event_second}));
packet->Assign(3, make_intrusive<Val>(ts_to_double(${pkt.packet_ts}), TYPE_TIME));
packet->Assign(3, make_intrusive<TimeVal>(ts_to_double(${pkt.packet_ts})));
packet->Assign(4, val_mgr->Count(${pkt.link_type}));
packet->Assign(5, to_stringval(${pkt.packet_data}));

View file

@ -518,7 +518,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp)
produced_at = OCSP_resp_get0_produced_at(basic_resp);
#endif
vl.emplace_back(make_intrusive<Val>(GetTimeFromAsn1(produced_at, GetFile(), reporter), TYPE_TIME));
vl.emplace_back(make_intrusive<TimeVal>(GetTimeFromAsn1(produced_at, GetFile(), reporter)));
// responses
@ -566,7 +566,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp)
// revocation time and reason if revoked
if ( status == V_OCSP_CERTSTATUS_REVOKED )
{
rvl.emplace_back(make_intrusive<Val>(GetTimeFromAsn1(revoke_time, GetFile(), reporter), TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(GetTimeFromAsn1(revoke_time, GetFile(), reporter)));
if ( reason != OCSP_REVOKED_STATUS_NOSTATUS )
{
@ -578,19 +578,19 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp)
}
else
{
rvl.emplace_back(make_intrusive<Val>(0.0, TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(0.0));
rvl.emplace_back(make_intrusive<StringVal>(0, ""));
}
if ( this_update )
rvl.emplace_back(make_intrusive<Val>(GetTimeFromAsn1(this_update, GetFile(), reporter), TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(GetTimeFromAsn1(this_update, GetFile(), reporter)));
else
rvl.emplace_back(make_intrusive<Val>(0.0, TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(0.0));
if ( next_update )
rvl.emplace_back(make_intrusive<Val>(GetTimeFromAsn1(next_update, GetFile(), reporter), TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(GetTimeFromAsn1(next_update, GetFile(), reporter)));
else
rvl.emplace_back(make_intrusive<Val>(0.0, TYPE_TIME));
rvl.emplace_back(make_intrusive<TimeVal>(0.0));
if ( ocsp_response_certificate )
mgr.Enqueue(ocsp_response_certificate, std::move(rvl));

View file

@ -158,8 +158,8 @@ IntrusivePtr<RecordVal> file_analysis::X509::ParseCertificate(X509Val* cert_val,
pX509Cert->Assign(3, make_intrusive<StringVal>(len, buf));
BIO_free(bio);
pX509Cert->Assign(5, make_intrusive<Val>(GetTimeFromAsn1(X509_get_notBefore(ssl_cert), f, reporter), TYPE_TIME));
pX509Cert->Assign(6, make_intrusive<Val>(GetTimeFromAsn1(X509_get_notAfter(ssl_cert), f, reporter), TYPE_TIME));
pX509Cert->Assign(5, make_intrusive<TimeVal>(GetTimeFromAsn1(X509_get_notBefore(ssl_cert), f, reporter)));
pX509Cert->Assign(6, make_intrusive<TimeVal>(GetTimeFromAsn1(X509_get_notAfter(ssl_cert), f, reporter)));
// we only read 255 bytes because byte 256 is always 0.
// if the string is longer than 255, that will be our null-termination,

View file

@ -2185,9 +2185,13 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ
return val_mgr->Count(val->val.int_val).release();
case TYPE_DOUBLE:
return new DoubleVal(val->val.double_val);
case TYPE_TIME:
return new TimeVal(val->val.double_val);
case TYPE_INTERVAL:
return new Val(val->val.double_val, val->type);
return new IntervalVal(val->val.double_val);
case TYPE_STRING:
{

View file

@ -1511,8 +1511,8 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con
info->Assign(0, {NewRef{}, winfo->type});
info->Assign(1, make_intrusive<StringVal>(new_name));
info->Assign(2, make_intrusive<StringVal>(winfo->writer->Info().path));
info->Assign(3, make_intrusive<Val>(open, TYPE_TIME));
info->Assign(4, make_intrusive<Val>(close, TYPE_TIME));
info->Assign(3, make_intrusive<TimeVal>(open));
info->Assign(4, make_intrusive<TimeVal>(close));
info->Assign(5, val_mgr->Bool(terminating));
Func* func = winfo->postprocessor;

View file

@ -113,7 +113,7 @@ function hll_cardinality_estimate%(handle: opaque of cardinality%): double
double estimate = h->Size();
return make_intrusive<Val>(estimate, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(estimate);
%}
## Copy a HLL cardinality counter.

View file

@ -232,7 +232,7 @@ function Reporter::set_weird_sampling_rate%(weird_sampling_rate: count%) : bool
## Returns: weird sampling duration.
function Reporter::get_weird_sampling_duration%(%) : interval
%{
return make_intrusive<Val>(reporter->GetWeirdSamplingDuration(), TYPE_INTERVAL);
return make_intrusive<IntervalVal>(reporter->GetWeirdSamplingDuration());
%}
## Sets the current weird sampling duration. Please note that

View file

@ -478,7 +478,7 @@ F RET_CONST(val_mgr->False()->Ref())
{D} {
RET_CONST(val_mgr->Count(static_cast<bro_uint_t>(strtoull(yytext, (char**) NULL, 10))).release())
}
{FLOAT} RET_CONST(new Val(atof(yytext), TYPE_DOUBLE))
{FLOAT} RET_CONST(new DoubleVal(atof(yytext)))
{D}"/tcp" {
uint32_t p = atoi(yytext);

View file

@ -152,7 +152,7 @@ function get_proc_stats%(%): ProcStats
r->Assign(n++, val_mgr->Count(0));
#endif
r->Assign(n++, make_intrusive<Val>(bro_start_time, TYPE_TIME));
r->Assign(n++, make_intrusive<TimeVal>(bro_start_time));
r->Assign(n++, make_intrusive<IntervalVal>(elapsed_time, Seconds));
r->Assign(n++, make_intrusive<IntervalVal>(user_time, Seconds));

View file

@ -456,9 +456,13 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e
return val_mgr->Count(val->val.int_val).release();
case TYPE_DOUBLE:
return new DoubleVal(val->val.double_val);
case TYPE_TIME:
return new TimeVal(val->val.double_val);
case TYPE_INTERVAL:
return new Val(val->val.double_val, val->type);
return new IntervalVal(val->val.double_val);
case TYPE_STRING:
{

View file

@ -1861,8 +1861,8 @@ FILE* rotate_file(const char* name, RecordVal* rotate_info)
{
rotate_info->Assign<StringVal>(0, name);
rotate_info->Assign<StringVal>(1, newname);
rotate_info->Assign<Val>(2, network_time, TYPE_TIME);
rotate_info->Assign<Val>(3, network_time, TYPE_TIME);
rotate_info->Assign<TimeVal>(2, network_time);
rotate_info->Assign<TimeVal>(3, network_time);
}
return newf;

View file

@ -220,7 +220,7 @@ void done_with_network()
mgr.Drain();
// Don't propagate this event to remote clients.
mgr.Dispatch(new Event(net_done,
{make_intrusive<Val>(timer_mgr->Time(), TYPE_TIME)}),
{make_intrusive<TimeVal>(timer_mgr->Time())}),
true);
}

View file

@ -319,7 +319,7 @@ static int next_fmt(const char*& fmt, const zeek::Args* args, ODesc* d, int& n)
## .. zeek:see:: network_time
function current_time%(%): time
%{
return make_intrusive<Val>(current_time(), TYPE_TIME);
return make_intrusive<TimeVal>(current_time());
%}
## Returns the timestamp of the last packet processed. This function returns
@ -331,7 +331,7 @@ function current_time%(%): time
## .. zeek:see:: current_time
function network_time%(%): time
%{
return make_intrusive<Val>(network_time, TYPE_TIME);
return make_intrusive<TimeVal>(network_time);
%}
## Returns a system environment variable.
@ -1053,11 +1053,11 @@ function find_entropy%(data: string%): entropy_test_result
static auto entropy_test_result = zeek::id::find_type<RecordType>("entropy_test_result");
auto ent_result = make_intrusive<RecordVal>(entropy_test_result);
ent_result->Assign(0, make_intrusive<Val>(ent, TYPE_DOUBLE));
ent_result->Assign(1, make_intrusive<Val>(chisq, TYPE_DOUBLE));
ent_result->Assign(2, make_intrusive<Val>(mean, TYPE_DOUBLE));
ent_result->Assign(3, make_intrusive<Val>(montepi, TYPE_DOUBLE));
ent_result->Assign(4, make_intrusive<Val>(scc, TYPE_DOUBLE));
ent_result->Assign(0, make_intrusive<DoubleVal>(ent));
ent_result->Assign(1, make_intrusive<DoubleVal>(chisq));
ent_result->Assign(2, make_intrusive<DoubleVal>(mean));
ent_result->Assign(3, make_intrusive<DoubleVal>(montepi));
ent_result->Assign(4, make_intrusive<DoubleVal>(scc));
return ent_result;
%}
@ -1105,11 +1105,11 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result
static auto entropy_test_result = zeek::id::find_type<RecordType>("entropy_test_result");
auto ent_result = make_intrusive<RecordVal>(entropy_test_result);
ent_result->Assign(0, make_intrusive<Val>(ent, TYPE_DOUBLE));
ent_result->Assign(1, make_intrusive<Val>(chisq, TYPE_DOUBLE));
ent_result->Assign(2, make_intrusive<Val>(mean, TYPE_DOUBLE));
ent_result->Assign(3, make_intrusive<Val>(montepi, TYPE_DOUBLE));
ent_result->Assign(4, make_intrusive<Val>(scc, TYPE_DOUBLE));
ent_result->Assign(0, make_intrusive<DoubleVal>(ent));
ent_result->Assign(1, make_intrusive<DoubleVal>(chisq));
ent_result->Assign(2, make_intrusive<DoubleVal>(mean));
ent_result->Assign(3, make_intrusive<DoubleVal>(montepi));
ent_result->Assign(4, make_intrusive<DoubleVal>(scc));
return ent_result;
%}
@ -1723,7 +1723,7 @@ function print_raw%(...%): bool
## .. zeek:see:: sqrt exp ln log10
function floor%(d: double%): double
%{
return make_intrusive<Val>(floor(d), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(floor(d));
%}
## Computes the square root of a :zeek:type:`double`.
@ -1738,10 +1738,10 @@ function sqrt%(x: double%): double
if ( x < 0 )
{
reporter->Error("negative sqrt argument");
return make_intrusive<Val>(-1.0, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(-1.0);
}
return make_intrusive<Val>(sqrt(x), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(sqrt(x));
%}
## Computes the exponential function.
@ -1753,7 +1753,7 @@ function sqrt%(x: double%): double
## .. zeek:see:: floor sqrt ln log10
function exp%(d: double%): double
%{
return make_intrusive<Val>(exp(d), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(exp(d));
%}
## Computes the natural logarithm of a number.
@ -1765,7 +1765,7 @@ function exp%(d: double%): double
## .. zeek:see:: exp floor sqrt log10
function ln%(d: double%): double
%{
return make_intrusive<Val>(log(d), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(log(d));
%}
## Computes the common logarithm of a number.
@ -1777,7 +1777,7 @@ function ln%(d: double%): double
## .. zeek:see:: exp floor sqrt ln
function log10%(d: double%): double
%{
return make_intrusive<Val>(log10(d), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(log10(d));
%}
# ===========================================================================
@ -2363,7 +2363,7 @@ function to_count%(str: string%): count
## .. zeek:see:: double_to_interval
function interval_to_double%(i: interval%): double
%{
return make_intrusive<Val>(i, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(i);
%}
## Converts a :zeek:type:`time` value to a :zeek:type:`double`.
@ -2375,7 +2375,7 @@ function interval_to_double%(i: interval%): double
## .. zeek:see:: double_to_time
function time_to_double%(t: time%): double
%{
return make_intrusive<Val>(t, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(t);
%}
## Converts a :zeek:type:`double` value to a :zeek:type:`time`.
@ -2387,7 +2387,7 @@ function time_to_double%(t: time%): double
## .. zeek:see:: time_to_double double_to_count
function double_to_time%(d: double%): time
%{
return make_intrusive<Val>(d, TYPE_TIME);
return make_intrusive<TimeVal>(d);
%}
## Converts a :zeek:type:`double` to an :zeek:type:`interval`.
@ -2399,7 +2399,7 @@ function double_to_time%(d: double%): time
## .. zeek:see:: interval_to_double
function double_to_interval%(d: double%): interval
%{
return make_intrusive<IntervalVal>(d, Seconds);
return make_intrusive<IntervalVal>(d);
%}
## Converts a :zeek:type:`port` to a :zeek:type:`count`.
@ -2548,7 +2548,7 @@ function to_double%(str: string%): double
d = 0;
}
return make_intrusive<Val>(d, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(d);
%}
## Converts a :zeek:type:`count` to an :zeek:type:`addr`.
@ -2637,13 +2637,13 @@ function bytestring_to_double%(s: string%): double
if ( s->Len() != sizeof(double) )
{
builtin_error("bad conversion to double");
return make_intrusive<Val>(0.0, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(0.0);
}
// See #908 for a discussion of portability.
double d;
memcpy(&d, s->Bytes(), sizeof(double));
return make_intrusive<Val>(ntohd(d), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(ntohd(d));
%}
## Converts a string of bytes to a :zeek:type:`count`.
@ -3116,11 +3116,11 @@ function strptime%(fmt: string, d: string%) : time
! strptime(d->CheckString(), fmt->CheckString(), &t) )
{
reporter->Warning("strptime conversion failed: fmt:%s d:%s", fmt->CheckString(), d->CheckString());
return make_intrusive<Val>(0.0, TYPE_TIME);
return make_intrusive<TimeVal>(0.0);
}
double ret = mktime(&t);
return make_intrusive<Val>(ret, TYPE_TIME);
return make_intrusive<TimeVal>(ret);
%}
@ -3320,8 +3320,8 @@ function lookup_connection%(cid: conn_id%): connection
c->Assign(1, std::move(orig_endp));
c->Assign(2, std::move(resp_endp));
c->Assign(3, make_intrusive<Val>(network_time, TYPE_TIME));
c->Assign(4, make_intrusive<Val>(0.0, TYPE_INTERVAL));
c->Assign(3, make_intrusive<TimeVal>(network_time));
c->Assign(4, make_intrusive<IntervalVal>(0.0));
c->Assign(5, make_intrusive<TableVal>(zeek::id::string_set)); // service
c->Assign(6, val_mgr->EmptyString()); // history
@ -3878,7 +3878,7 @@ static IntrusivePtr<Val> mmdb_getvalue(MMDB_entry_data_s* entry_data, int status
break;
case MMDB_DATA_TYPE_DOUBLE:
return make_intrusive<Val>(entry_data->double_value, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(entry_data->double_value);
break;
case MMDB_DATA_TYPE_UINT32:
@ -4155,7 +4155,7 @@ function haversine_distance%(lat1: double, long1: double, lat2: double, long2: d
double a = s1 * s1 + cos(lat1 * PI/180) * cos(lat2 * PI/180) * s2 * s2;
double distance = 2 * RADIUS * asin(sqrt(a));
return make_intrusive<Val>(distance, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(distance);
%}
## Converts UNIX file permissions given by a mode to an ASCII string.
@ -4368,12 +4368,12 @@ function set_inactivity_timeout%(cid: conn_id, t: interval%): interval
%{
Connection* c = sessions->FindConnection(cid);
if ( ! c )
return make_intrusive<Val>(0.0, TYPE_INTERVAL);
return make_intrusive<IntervalVal>(0.0);
double old_timeout = c->InactivityTimeout();
c->SetInactivityTimeout(t);
return make_intrusive<Val>(old_timeout, TYPE_INTERVAL);
return make_intrusive<IntervalVal>(old_timeout);
%}
# ===========================================================================
@ -4633,8 +4633,8 @@ function rotate_file%(f: file%): rotate_info
info = make_intrusive<RecordVal>(rotate_info);
info->Assign(0, val_mgr->EmptyString());
info->Assign(1, val_mgr->EmptyString());
info->Assign(2, make_intrusive<Val>(0.0, TYPE_TIME));
info->Assign(3, make_intrusive<Val>(0.0, TYPE_TIME));
info->Assign(2, make_intrusive<TimeVal>(0.0));
info->Assign(3, make_intrusive<TimeVal>(0.0));
return info;
%}
@ -4675,8 +4675,8 @@ function rotate_file_by_name%(f: string%): rotate_info
// Record indicating error.
info->Assign(0, val_mgr->EmptyString());
info->Assign(1, val_mgr->EmptyString());
info->Assign(2, make_intrusive<Val>(0.0, TYPE_TIME));
info->Assign(3, make_intrusive<Val>(0.0, TYPE_TIME));
info->Assign(2, make_intrusive<TimeVal>(0.0));
info->Assign(3, make_intrusive<TimeVal>(0.0));
return info;
}
@ -4684,12 +4684,12 @@ function rotate_file_by_name%(f: string%): rotate_info
if ( is_pkt_dumper )
{
info->Assign(2, make_intrusive<Val>(pkt_dumper->OpenTime(), TYPE_TIME));
info->Assign(2, make_intrusive<TimeVal>(pkt_dumper->OpenTime()));
pkt_dumper->Open();
}
if ( is_addl_pkt_dumper )
info->Assign(2, make_intrusive<Val>(addl_pkt_dumper->OpenTime(), TYPE_TIME));
info->Assign(2, make_intrusive<TimeVal>(addl_pkt_dumper->OpenTime()));
return info;
%}
@ -4708,7 +4708,7 @@ function calc_next_rotate%(i: interval%) : interval
static auto base_time = log_rotate_base_time->AsString()->CheckString();
double base = parse_rotate_base_time(base_time);
return make_intrusive<Val>(calc_next_rotate(network_time, i, base), TYPE_INTERVAL);
return make_intrusive<IntervalVal>(calc_next_rotate(network_time, i, base));
%}
## Returns the size of a given file.
@ -4721,9 +4721,9 @@ function file_size%(f: string%) : double
struct stat s;
if ( stat(f->CheckString(), &s) < 0 )
return make_intrusive<Val>(-1.0, TYPE_DOUBLE);
return make_intrusive<DoubleVal>(-1.0);
return make_intrusive<Val>(double(s.st_size), TYPE_DOUBLE);
return make_intrusive<DoubleVal>(double(s.st_size));
%}
## Prevents escaping of non-ASCII characters when writing to a file.