diff --git a/aux/bifcl b/aux/bifcl index b1526de0d4..519a0ed580 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit b1526de0d4b8639b51b79b712e83ea62597df1c0 +Subproject commit 519a0ed580c7826509239002a1e240eccb016013 diff --git a/src/BroList.h b/src/BroList.h index 410dd950d9..0c971ad34a 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -16,8 +16,8 @@ using id_list = PList; FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); using stmt_list = PList; -class BroType; -using type_list = PList; +FORWARD_DECLARE_NAMESPACED(BroType, zeek); +using type_list = PList; FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail); using attr_list = PList; diff --git a/src/CompHash.cc b/src/CompHash.cc index aff8f65ac8..909494e91c 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -14,17 +14,17 @@ #include "Func.h" #include "IPAddr.h" -CompositeHash::CompositeHash(IntrusivePtr composite_type) +CompositeHash::CompositeHash(IntrusivePtr composite_type) : type(std::move(composite_type)) { - singleton_tag = TYPE_INTERNAL_ERROR; + singleton_tag = zeek::TYPE_INTERNAL_ERROR; // If the only element is a record, don't treat it as a // singleton, since it needs to be evaluated specially. if ( type->Types().size() == 1 ) { - if ( type->Types()[0]->Tag() == TYPE_RECORD ) + if ( type->Types()[0]->Tag() == zeek::TYPE_RECORD ) { is_complex_type = true; is_singleton = false; @@ -71,10 +71,10 @@ CompositeHash::~CompositeHash() // Computes the piece of the hash for Val*, returning the new kp. char* CompositeHash::SingleValHash(bool type_check, char* kp0, - BroType* bt, Val* v, bool optional) const + zeek::BroType* bt, Val* v, bool optional) const { char* kp1 = nullptr; - InternalTypeTag t = bt->InternalType(); + zeek::InternalTypeTag t = bt->InternalType(); if ( optional ) { @@ -89,13 +89,13 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, if ( type_check ) { - InternalTypeTag vt = v->GetType()->InternalType(); + zeek::InternalTypeTag vt = v->GetType()->InternalType(); if ( vt != t ) return nullptr; } switch ( t ) { - case TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_INT: { bro_int_t* kp = AlignAndPadType(kp0); *kp = v->ForceAsInt(); @@ -103,7 +103,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_UNSIGNED: { bro_uint_t* kp = AlignAndPadType(kp0); *kp = v->ForceAsUInt(); @@ -111,7 +111,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_ADDR: + case zeek::TYPE_INTERNAL_ADDR: { uint32_t* kp = AlignAndPadType(kp0); v->AsAddr().CopyIPv6(kp); @@ -119,7 +119,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: { uint32_t* kp = AlignAndPadType(kp0); v->AsSubNet().Prefix().CopyIPv6(kp); @@ -128,7 +128,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: { double* kp = AlignAndPadType(kp0); *kp = v->InternalDouble(); @@ -136,11 +136,11 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_VOID: - case TYPE_INTERNAL_OTHER: + case zeek::TYPE_INTERNAL_VOID: + case zeek::TYPE_INTERNAL_OTHER: { switch ( v->GetType()->Tag() ) { - case TYPE_FUNC: + case zeek::TYPE_FUNC: { uint32_t* kp = AlignAndPadType(kp0); *kp = v->AsFunc()->GetUniqueFuncID(); @@ -148,7 +148,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, break; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { const char* texts[2] = { v->AsPattern()->PatternText(), @@ -172,11 +172,11 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, break; } - case TYPE_RECORD: + case zeek::TYPE_RECORD: { char* kp = kp0; RecordVal* rv = v->AsRecordVal(); - RecordType* rt = bt->AsRecordType(); + zeek::RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); for ( int i = 0; i < num_fields; ++i ) @@ -199,7 +199,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { int* kp = AlignAndPadType(kp0); TableVal* tv = v->AsTableVal(); @@ -208,7 +208,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, auto tbl = tv->AsTable(); auto it = tbl->InitForIteration(); - auto lv = make_intrusive(TYPE_ANY); + auto lv = make_intrusive(zeek::TYPE_ANY); struct HashKeyComparer { bool operator()(const HashKey* a, const HashKey* b) const @@ -258,11 +258,11 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { unsigned int* kp = AlignAndPadType(kp0); VectorVal* vv = v->AsVectorVal(); - VectorType* vt = v->GetType()->AsVectorType(); + zeek::VectorType* vt = v->GetType()->AsVectorType(); *kp = vv->Size(); kp1 = reinterpret_cast(kp+1); for ( unsigned int i = 0; i < vv->Size(); ++i ) @@ -286,7 +286,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_LIST: + case zeek::TYPE_LIST: { int* kp = AlignAndPadType(kp0); ListVal* lv = v->AsListVal(); @@ -309,10 +309,10 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } } - break; // case TYPE_INTERNAL_VOID/OTHER + break; // case zeek::TYPE_INTERNAL_VOID/OTHER } - case TYPE_INTERNAL_STRING: + case zeek::TYPE_INTERNAL_STRING: { // Align to int for the length field. int* kp = AlignAndPadType(kp0); @@ -327,7 +327,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_ERROR: + case zeek::TYPE_INTERNAL_ERROR: return nullptr; } @@ -342,9 +342,9 @@ std::unique_ptr CompositeHash::MakeHashKey(const Val& argv, bool type_c if ( is_singleton ) return ComputeSingletonHash(v, type_check); - if ( is_complex_type && v->GetType()->Tag() != TYPE_LIST ) + if ( is_complex_type && v->GetType()->Tag() != zeek::TYPE_LIST ) { - ListVal lv(TYPE_ANY); + ListVal lv(zeek::TYPE_ANY); // Cast away const to use ListVal - but since we // re-introduce const on the recursive call, it should @@ -368,7 +368,7 @@ std::unique_ptr CompositeHash::MakeHashKey(const Val& argv, bool type_c const auto& tl = type->Types(); - if ( type_check && v->GetType()->Tag() != TYPE_LIST ) + if ( type_check && v->GetType()->Tag() != zeek::TYPE_LIST ) return nullptr; auto lv = v->AsListVal(); @@ -389,7 +389,7 @@ std::unique_ptr CompositeHash::MakeHashKey(const Val& argv, bool type_c std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const { - if ( v->GetType()->Tag() == TYPE_LIST ) + if ( v->GetType()->Tag() == zeek::TYPE_LIST ) { auto lv = v->AsListVal(); @@ -403,25 +403,25 @@ std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool return nullptr; switch ( singleton_tag ) { - case TYPE_INTERNAL_INT: - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_UNSIGNED: return std::make_unique(v->ForceAsInt()); - case TYPE_INTERNAL_ADDR: + case zeek::TYPE_INTERNAL_ADDR: return v->AsAddr().MakeHashKey(); - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: return v->AsSubNet().MakeHashKey(); - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: return std::make_unique(v->InternalDouble()); - case TYPE_INTERNAL_VOID: - case TYPE_INTERNAL_OTHER: - if ( v->GetType()->Tag() == TYPE_FUNC ) + case zeek::TYPE_INTERNAL_VOID: + case zeek::TYPE_INTERNAL_OTHER: + if ( v->GetType()->Tag() == zeek::TYPE_FUNC ) return std::make_unique(v->AsFunc()->GetUniqueFuncID()); - if ( v->GetType()->Tag() == TYPE_PATTERN ) + if ( v->GetType()->Tag() == zeek::TYPE_PATTERN ) { const char* texts[2] = { v->AsPattern()->PatternText(), @@ -437,10 +437,10 @@ std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool reporter->InternalError("bad index type in CompositeHash::ComputeSingletonHash"); return nullptr; - case TYPE_INTERNAL_STRING: + case zeek::TYPE_INTERNAL_STRING: return std::make_unique(v->AsString()); - case TYPE_INTERNAL_ERROR: + case zeek::TYPE_INTERNAL_ERROR: return nullptr; default: @@ -449,53 +449,53 @@ std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool } } -int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, +int CompositeHash::SingleTypeKeySize(zeek::BroType* bt, const Val* v, bool type_check, int sz, bool optional, bool calc_static_size) const { - InternalTypeTag t = bt->InternalType(); + zeek::InternalTypeTag t = bt->InternalType(); if ( optional ) sz = SizeAlign(sz, sizeof(char)); if ( type_check && v ) { - InternalTypeTag vt = v->GetType()->InternalType(); + zeek::InternalTypeTag vt = v->GetType()->InternalType(); if ( vt != t ) return 0; } switch ( t ) { - case TYPE_INTERNAL_INT: - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_UNSIGNED: sz = SizeAlign(sz, sizeof(bro_int_t)); break; - case TYPE_INTERNAL_ADDR: + case zeek::TYPE_INTERNAL_ADDR: sz = SizeAlign(sz, sizeof(uint32_t)); sz += sizeof(uint32_t) * 3; // to make a total of 4 words break; - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: sz = SizeAlign(sz, sizeof(uint32_t)); sz += sizeof(uint32_t) * 4; // to make a total of 5 words break; - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: sz = SizeAlign(sz, sizeof(double)); break; - case TYPE_INTERNAL_VOID: - case TYPE_INTERNAL_OTHER: + case zeek::TYPE_INTERNAL_VOID: + case zeek::TYPE_INTERNAL_OTHER: { switch ( bt->Tag() ) { - case TYPE_FUNC: + case zeek::TYPE_FUNC: { sz = SizeAlign(sz, sizeof(uint32_t)); break; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; @@ -506,10 +506,10 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, break; } - case TYPE_RECORD: + case zeek::TYPE_RECORD: { const RecordVal* rv = v ? v->AsRecordVal() : nullptr; - RecordType* rt = bt->AsRecordType(); + zeek::RecordType* rt = bt->AsRecordType(); int num_fields = rt->NumFields(); for ( int i = 0; i < num_fields; ++i ) @@ -528,7 +528,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; @@ -557,7 +557,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; @@ -579,7 +579,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, break; } - case TYPE_LIST: + case zeek::TYPE_LIST: { if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; @@ -603,10 +603,10 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, } } - break; // case TYPE_INTERNAL_VOID/OTHER + break; // case zeek::TYPE_INTERNAL_VOID/OTHER } - case TYPE_INTERNAL_STRING: + case zeek::TYPE_INTERNAL_STRING: if ( ! v ) return (optional && ! calc_static_size) ? sz : 0; @@ -615,7 +615,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, sz += v->AsString()->Len(); break; - case TYPE_INTERNAL_ERROR: + case zeek::TYPE_INTERNAL_ERROR: return 0; } @@ -628,7 +628,7 @@ int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_stati if ( v ) { - if ( type_check && v->GetType()->Tag() != TYPE_LIST ) + if ( type_check && v->GetType()->Tag() != zeek::TYPE_LIST ) return 0; auto lv = v->AsListVal(); @@ -710,7 +710,7 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const { - auto l = make_intrusive(TYPE_ANY); + auto l = make_intrusive(zeek::TYPE_ANY); const auto& tl = type->Types(); const char* kp = (const char*) k.Key(); const char* const k_end = kp + k.Size(); @@ -730,15 +730,15 @@ IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const } const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, - const char* const k_end, BroType* t, + const char* const k_end, zeek::BroType* t, IntrusivePtr* pval, bool optional) const { // k->Size() == 0 for a single empty string. if ( kp0 >= k_end && k.Size() > 0 ) reporter->InternalError("over-ran key in CompositeHash::RecoverVals"); - TypeTag tag = t->Tag(); - InternalTypeTag it = t->InternalType(); + zeek::TypeTag tag = t->Tag(); + zeek::InternalTypeTag it = t->InternalType(); const char* kp1 = nullptr; if ( optional ) @@ -754,16 +754,16 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } switch ( it ) { - case TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_INT: { const bro_int_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); - if ( tag == TYPE_ENUM ) + if ( tag == zeek::TYPE_ENUM ) *pval = t->AsEnumType()->GetVal(*kp); - else if ( tag == TYPE_BOOL ) + else if ( tag == zeek::TYPE_BOOL ) *pval = val_mgr->Bool(*kp); - else if ( tag == TYPE_INT ) + else if ( tag == zeek::TYPE_INT ) *pval = val_mgr->Int(*kp); else { @@ -773,18 +773,18 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_UNSIGNED: { const bro_uint_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); switch ( tag ) { - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: *pval = val_mgr->Count(*kp); break; - case TYPE_PORT: + case zeek::TYPE_PORT: *pval = val_mgr->Port(*kp); break; @@ -796,21 +796,21 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: { const double* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); - if ( tag == TYPE_INTERVAL ) + if ( tag == zeek::TYPE_INTERVAL ) *pval = make_intrusive(*kp, 1.0); - else if ( tag == TYPE_TIME ) + else if ( tag == zeek::TYPE_TIME ) *pval = make_intrusive(*kp); else *pval = make_intrusive(*kp); } break; - case TYPE_INTERNAL_ADDR: + case zeek::TYPE_INTERNAL_ADDR: { const uint32_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+4); @@ -818,7 +818,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, IPAddr addr(IPv6, kp, IPAddr::Network); switch ( tag ) { - case TYPE_ADDR: + case zeek::TYPE_ADDR: *pval = make_intrusive(addr); break; @@ -830,7 +830,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: { const uint32_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+5); @@ -838,11 +838,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_VOID: - case TYPE_INTERNAL_OTHER: + case zeek::TYPE_INTERNAL_VOID: + case zeek::TYPE_INTERNAL_OTHER: { switch ( t->Tag() ) { - case TYPE_FUNC: + case zeek::TYPE_FUNC: { const uint32_t* const kp = AlignType(kp0); kp1 = reinterpret_cast(kp+1); @@ -858,18 +858,18 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, if ( ! pvt ) reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()"); - else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) ) + else if ( t->Tag() != zeek::TYPE_FUNC && ! same_type(pvt, t) ) // ### Maybe fix later, but may be fundamentally // un-checkable --US reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); // ### A crude approximation for now. - else if ( t->Tag() == TYPE_FUNC && pvt->Tag() != TYPE_FUNC ) + else if ( t->Tag() == zeek::TYPE_FUNC && pvt->Tag() != zeek::TYPE_FUNC ) reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()"); } break; - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { RE_Matcher* re = nullptr; if ( is_singleton ) @@ -896,10 +896,10 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_RECORD: + case zeek::TYPE_RECORD: { const char* kp = kp0; - RecordType* rt = t->AsRecordType(); + zeek::RecordType* rt = t->AsRecordType(); int num_fields = rt->NumFields(); std::vector> values; @@ -939,13 +939,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_TABLE: + case zeek::TYPE_TABLE: { int n; const int* const kp = AlignType(kp0); n = *kp; kp1 = reinterpret_cast(kp+1); - TableType* tt = t->AsTableType(); + zeek::TableType* tt = t->AsTableType(); auto tv = make_intrusive(IntrusivePtr{NewRef{}, tt}); for ( int i = 0; i < n; ++i ) @@ -968,13 +968,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { unsigned int n; const unsigned int* kp = AlignType(kp0); n = *kp; kp1 = reinterpret_cast(kp+1); - VectorType* vt = t->AsVectorType(); + zeek::VectorType* vt = t->AsVectorType(); auto vv = make_intrusive(IntrusivePtr{NewRef{}, vt}); for ( unsigned int i = 0; i < n; ++i ) @@ -998,19 +998,19 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_LIST: + case zeek::TYPE_LIST: { int n; const int* const kp = AlignType(kp0); n = *kp; kp1 = reinterpret_cast(kp+1); - TypeList* tl = t->AsTypeList(); - auto lv = make_intrusive(TYPE_ANY); + zeek::TypeList* tl = t->AsTypeList(); + auto lv = make_intrusive(zeek::TYPE_ANY); for ( int i = 0; i < n; ++i ) { IntrusivePtr v; - BroType* it = tl->Types()[i].get(); + zeek::BroType* it = tl->Types()[i].get(); kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); lv->Append(std::move(v)); } @@ -1027,7 +1027,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_STRING: + case zeek::TYPE_INTERNAL_STRING: { // There is a minor issue here -- the pointer does not have to // be aligned by int in the singleton case. @@ -1050,7 +1050,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, } break; - case TYPE_INTERNAL_ERROR: + case zeek::TYPE_INTERNAL_ERROR: break; } diff --git a/src/CompHash.h b/src/CompHash.h index e3204fe630..38ccf735c8 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -12,7 +12,7 @@ class HashKey; class CompositeHash { public: - explicit CompositeHash(IntrusivePtr composite_type); + explicit CompositeHash(IntrusivePtr composite_type); ~CompositeHash(); // Compute the hash corresponding to the given index val, @@ -37,7 +37,7 @@ protected: // Computes the piece of the hash for Val*, returning the new kp. // Used as a helper for ComputeHash in the non-singleton case. - char* SingleValHash(bool type_check, char* kp, BroType* bt, Val* v, + char* SingleValHash(bool type_check, char* kp, zeek::BroType* bt, Val* v, bool optional) const; // Recovers just one Val of possibly many; called from RecoverVals. @@ -46,7 +46,7 @@ protected: // upon errors, so there is no return value for invalid input. const char* RecoverOneVal(const HashKey& k, const char* kp, const char* const k_end, - BroType* t, IntrusivePtr* pval, bool optional) const; + zeek::BroType* t, IntrusivePtr* pval, bool optional) const; // Rounds the given pointer up to the nearest multiple of the // given size, if not already a multiple. @@ -85,11 +85,11 @@ protected: int ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const; - int SingleTypeKeySize(BroType*, const Val*, + int SingleTypeKeySize(zeek::BroType*, const Val*, bool type_check, int sz, bool optional, bool calc_static_size) const; - IntrusivePtr type; + IntrusivePtr type; char* key; // space for composite key int size; bool is_singleton; // if just one type in index @@ -97,5 +97,5 @@ protected: // If one type, but not normal "singleton", e.g. record. bool is_complex_type; - InternalTypeTag singleton_tag; + zeek::InternalTypeTag singleton_tag; }; diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 50061babe2..50da2349e8 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -175,10 +175,10 @@ void DNS_Mgr_mapping_delete_func(void* v) static IntrusivePtr empty_addr_set() { - auto addr_t = base_type(TYPE_ADDR); - auto set_index = make_intrusive(addr_t); + auto addr_t = zeek::base_type(zeek::TYPE_ADDR); + auto set_index = make_intrusive(addr_t); set_index->Append(std::move(addr_t)); - auto s = make_intrusive(std::move(set_index), nullptr); + auto s = make_intrusive(std::move(set_index), nullptr); return make_intrusive(std::move(s)); } @@ -283,7 +283,7 @@ IntrusivePtr DNS_Mapping::Addrs() if ( ! addrs_val ) { - auto addrs_val = make_intrusive(TYPE_ADDR); + auto addrs_val = make_intrusive(zeek::TYPE_ADDR); for ( int i = 0; i < num_addrs; ++i ) addrs_val->Append(make_intrusive(addrs[i])); @@ -450,7 +450,7 @@ void DNS_Mgr::InitSource() void DNS_Mgr::InitPostScript() { - dm_rec = zeek::id::find_type("dns_mapping"); + dm_rec = zeek::id::find_type("dns_mapping"); // Registering will call Init() iosource_mgr->Register(this, true); @@ -465,7 +465,7 @@ static IntrusivePtr fake_name_lookup_result(const char* name) { hash128_t hash; KeyedHash::StaticHash128(name, strlen(name), &hash); - auto hv = make_intrusive(TYPE_ADDR); + auto hv = make_intrusive(zeek::TYPE_ADDR); hv->Append(make_intrusive(reinterpret_cast(&hash))); return hv->ToSetVal(); } @@ -872,7 +872,7 @@ void DNS_Mgr::CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm) IntrusivePtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) { - auto delta = make_intrusive(TYPE_ADDR); + auto delta = make_intrusive(zeek::TYPE_ADDR); for ( int i = 0; i < al1->Length(); ++i ) { diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 3ff0d3c307..a22ad078f3 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -11,6 +11,7 @@ #include "EventHandler.h" #include "iosource/IOSource.h" #include "IPAddr.h" +#include "util.h" template class IntrusivePtr; class Val; @@ -18,9 +19,10 @@ class ListVal; class TableVal; class Func; class EventHandler; -class RecordType; class DNS_Mgr_Request; +FORWARD_DECLARE_NAMESPACED(RecordType, zeek); + typedef PList DNS_mgr_request_list; struct nb_dns_info; @@ -149,7 +151,7 @@ protected: bool did_init; - IntrusivePtr dm_rec; + IntrusivePtr dm_rec; typedef std::list CallbackList; diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 990ff070a3..472924aba4 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -258,8 +258,8 @@ BreakCode DbgBreakpoint::HasHit() return bcHit; } - if ( ! IsIntegral(yes->GetType()->Tag()) && - ! IsBool(yes->GetType()->Tag()) ) + if ( ! zeek::IsIntegral(yes->GetType()->Tag()) && + ! zeek::IsBool(yes->GetType()->Tag()) ) { PrintHitMsg(); debug_msg("Breakpoint condition should return an integral type"); diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index 3cc5baa7f8..b7c411989a 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -65,7 +65,7 @@ static void lookup_global_symbols_regex(const string& orig_regex, vectorGetType()->Tag() == TYPE_FUNC ) + if ( ! func_only || nextid->GetType()->Tag() == zeek::TYPE_FUNC ) if ( ! regexec (&re, nextid->Name(), 0, 0, 0) ) matches.push_back(nextid); } diff --git a/src/Desc.cc b/src/Desc.cc index 978ddff24c..d2c67cb0dd 100644 --- a/src/Desc.cc +++ b/src/Desc.cc @@ -403,19 +403,19 @@ void ODesc::Clear() } } -bool ODesc::PushType(const BroType* type) +bool ODesc::PushType(const zeek::BroType* type) { auto res = encountered_types.insert(type); return std::get<1>(res); } -bool ODesc::PopType(const BroType* type) +bool ODesc::PopType(const zeek::BroType* type) { size_t res = encountered_types.erase(type); return (res == 1); } -bool ODesc::FindType(const BroType* type) +bool ODesc::FindType(const zeek::BroType* type) { auto res = encountered_types.find(type); diff --git a/src/Desc.h b/src/Desc.h index 658f0c477e..3124ebfa16 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -25,7 +25,7 @@ typedef enum { class BroFile; class IPAddr; class IPPrefix; -class BroType; +FORWARD_DECLARE_NAMESPACED(BroType, zeek); class ODesc { public: @@ -146,9 +146,9 @@ public: // Used to determine recursive types. Records push their types on here; // if the same type (by address) is re-encountered, processing aborts. - bool PushType(const BroType* type); - bool PopType(const BroType* type); - bool FindType(const BroType* type); + bool PushType(const zeek::BroType* type); + bool PopType(const zeek::BroType* type); + bool FindType(const zeek::BroType* type); protected: void Indent(); @@ -204,5 +204,5 @@ protected: bool do_flush; bool include_stats; - std::set encountered_types; + std::set encountered_types; }; diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 68673801d1..ad26499e3f 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -26,7 +26,7 @@ EventHandler::operator bool() const || ! auto_publish.empty()); } -const IntrusivePtr& EventHandler::GetType(bool check_export) +const IntrusivePtr& EventHandler::GetType(bool check_export) { if ( type ) return type; @@ -35,12 +35,12 @@ const IntrusivePtr& EventHandler::GetType(bool check_export) check_export); if ( ! id ) - return FuncType::nil; + return zeek::FuncType::nil; - if ( id->GetType()->Tag() != TYPE_FUNC ) - return FuncType::nil; + if ( id->GetType()->Tag() != zeek::TYPE_FUNC ) + return zeek::FuncType::nil; - type = id->GetType(); + type = id->GetType(); return type; } @@ -111,7 +111,7 @@ void EventHandler::NewEvent(zeek::Args* vl) return; const auto& args = GetType()->Params(); - static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); + static auto call_argument_vector = zeek::id::find_type("call_argument_vector"); auto vargs = make_intrusive(call_argument_vector); for ( int i = 0; i < args->NumFields(); i++ ) @@ -120,7 +120,7 @@ void EventHandler::NewEvent(zeek::Args* vl) const auto& ftype = args->GetFieldType(i); auto fdefault = args->FieldDefault(i); - static auto call_argument = zeek::id::find_type("call_argument"); + static auto call_argument = zeek::id::find_type("call_argument"); auto rec = make_intrusive(call_argument); rec->Assign(0, make_intrusive(fname)); @@ -144,4 +144,3 @@ void EventHandler::NewEvent(zeek::Args* vl) }); mgr.Dispatch(ev); } - diff --git a/src/EventHandler.h b/src/EventHandler.h index c2a053cac8..a995e4f234 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -22,10 +22,10 @@ public: [[deprecated("Remove in v4.1. Use GetFunc().")]] Func* LocalHandler() { return local.get(); } - const IntrusivePtr& GetType(bool check_export = true); + const IntrusivePtr& GetType(bool check_export = true); [[deprecated("Remove in v4.1. Use GetType().")]] - FuncType* FType(bool check_export = true) + zeek::FuncType* FType(bool check_export = true) { return GetType().get(); } void SetFunc(IntrusivePtr f) @@ -70,7 +70,7 @@ private: std::string name; IntrusivePtr local; - IntrusivePtr type; + IntrusivePtr type; bool used; // this handler is indeed used somewhere bool enabled; bool error_handler; // this handler reports error messages. diff --git a/src/Expr.cc b/src/Expr.cc index 4d7e89f8d1..ae57cddbca 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -132,7 +132,7 @@ IntrusivePtr Expr::InitVal(const BroType* t, IntrusivePtr aggr) const bool Expr::IsError() const { - return type && type->Tag() == TYPE_ERROR; + return type && type->Tag() == zeek::TYPE_ERROR; } void Expr::SetError() @@ -184,7 +184,7 @@ void Expr::Canonicize() void Expr::SetType(IntrusivePtr t) { - if ( ! type || type->Tag() != TYPE_ERROR ) + if ( ! type || type->Tag() != zeek::TYPE_ERROR ) type = std::move(t); } @@ -312,7 +312,7 @@ void NameExpr::ExprDescribe(ODesc* d) const ConstExpr::ConstExpr(IntrusivePtr arg_val) : Expr(EXPR_CONST), val(std::move(arg_val)) { - if ( val->GetType()->Tag() == TYPE_LIST && val->AsListVal()->Length() == 1 ) + if ( val->GetType()->Tag() == zeek::TYPE_LIST && val->AsListVal()->Length() == 1 ) val = val->AsListVal()->Idx(0); SetType(val->GetType()); @@ -357,12 +357,12 @@ IntrusivePtr UnaryExpr::Eval(Frame* f) const if ( is_vector(v) && Tag() != EXPR_IS && Tag() != EXPR_CAST ) { VectorVal* v_op = v->AsVectorVal(); - IntrusivePtr out_t; + IntrusivePtr out_t; - if ( GetType()->Tag() == TYPE_ANY ) - out_t = v->GetType(); + if ( GetType()->Tag() == zeek::TYPE_ANY ) + out_t = v->GetType(); else - out_t = GetType(); + out_t = GetType(); auto result = make_intrusive(std::move(out_t)); @@ -455,7 +455,7 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const return nullptr; } - auto v_result = make_intrusive(GetType()); + auto v_result = make_intrusive(GetType()); for ( unsigned int i = 0; i < v_op1->Size(); ++i ) { @@ -472,7 +472,7 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const if ( IsVector(GetType()->Tag()) && (is_vec1 || is_vec2) ) { // fold vector against scalar VectorVal* vv = (is_vec1 ? v1 : v2)->AsVectorVal(); - auto v_result = make_intrusive(GetType()); + auto v_result = make_intrusive(GetType()); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -527,19 +527,19 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const { InternalTypeTag it = v1->GetType()->InternalType(); - if ( it == TYPE_INTERNAL_STRING ) + if ( it == zeek::TYPE_INTERNAL_STRING ) return StringFold(v1, v2); - if ( v1->GetType()->Tag() == TYPE_PATTERN ) + if ( v1->GetType()->Tag() == zeek::TYPE_PATTERN ) return PatternFold(v1, v2); if ( v1->GetType()->IsSet() ) return SetFold(v1, v2); - if ( it == TYPE_INTERNAL_ADDR ) + if ( it == zeek::TYPE_INTERNAL_ADDR ) return AddrFold(v1, v2); - if ( it == TYPE_INTERNAL_SUBNET ) + if ( it == zeek::TYPE_INTERNAL_SUBNET ) return SubNetFold(v1, v2); bro_int_t i1 = 0, i2 = 0, i3 = 0; @@ -548,19 +548,19 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const bool is_integral = false; bool is_unsigned = false; - if ( it == TYPE_INTERNAL_INT ) + if ( it == zeek::TYPE_INTERNAL_INT ) { i1 = v1->InternalInt(); i2 = v2->InternalInt(); is_integral = true; } - else if ( it == TYPE_INTERNAL_UNSIGNED ) + else if ( it == zeek::TYPE_INTERNAL_UNSIGNED ) { u1 = v1->InternalUnsigned(); u2 = v2->InternalUnsigned(); is_unsigned = true; } - else if ( it == TYPE_INTERNAL_DOUBLE ) + else if ( it == zeek::TYPE_INTERNAL_DOUBLE ) { d1 = v1->InternalDouble(); d2 = v2->InternalDouble(); @@ -676,15 +676,15 @@ IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const const auto& ret_type = IsVector(GetType()->Tag()) ? GetType()->Yield() : GetType(); - if ( ret_type->Tag() == TYPE_INTERVAL ) + if ( ret_type->Tag() == zeek::TYPE_INTERVAL ) return make_intrusive(d3); - else if ( ret_type->Tag() == TYPE_TIME ) + else if ( ret_type->Tag() == zeek::TYPE_TIME ) return make_intrusive(d3); - else if ( ret_type->Tag() == TYPE_DOUBLE ) + else if ( ret_type->Tag() == zeek::TYPE_DOUBLE ) return make_intrusive(d3); - else if ( ret_type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( ret_type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return val_mgr->Count(u3); - else if ( ret_type->Tag() == TYPE_BOOL ) + else if ( ret_type->Tag() == zeek::TYPE_BOOL ) return val_mgr->Bool(i3); else return val_mgr->Int(i3); @@ -881,7 +881,7 @@ void BinaryExpr::PromoteType(TypeTag t, bool is_vector) PromoteOps(t); if ( is_vector) - SetType(make_intrusive(base_type(t))); + SetType(make_intrusive(base_type(t))); else SetType(base_type(t)); } @@ -949,13 +949,13 @@ IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const --k; if ( k < 0 && - v->GetType()->InternalType() == TYPE_INTERNAL_UNSIGNED ) + v->GetType()->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) RuntimeError("count underflow"); } const auto& ret_type = IsVector(GetType()->Tag()) ? GetType()->Yield() : GetType(); - if ( ret_type->Tag() == TYPE_INT ) + if ( ret_type->Tag() == zeek::TYPE_INT ) return val_mgr->Int(k); else return val_mgr->Count(k); @@ -1008,10 +1008,10 @@ ComplementExpr::ComplementExpr(IntrusivePtr arg_op) const auto& t = op->GetType(); TypeTag bt = t->Tag(); - if ( bt != TYPE_COUNT ) + if ( bt != zeek::TYPE_COUNT ) ExprError("requires \"count\" operand"); else - SetType(base_type(TYPE_COUNT)); + SetType(base_type(zeek::TYPE_COUNT)); } IntrusivePtr ComplementExpr::Fold(Val* v) const @@ -1027,10 +1027,10 @@ NotExpr::NotExpr(IntrusivePtr arg_op) TypeTag bt = op->GetType()->Tag(); - if ( ! IsIntegral(bt) && bt != TYPE_BOOL ) + if ( ! IsIntegral(bt) && bt != zeek::TYPE_BOOL ) ExprError("requires an integral or boolean operand"); else - SetType(base_type(TYPE_BOOL)); + SetType(base_type(zeek::TYPE_BOOL)); } IntrusivePtr NotExpr::Fold(Val* v) const @@ -1051,14 +1051,14 @@ PosExpr::PosExpr(IntrusivePtr arg_op) if ( IsIntegral(bt) ) // Promote count and counter to int. - base_result_type = base_type(TYPE_INT); - else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) + base_result_type = base_type(zeek::TYPE_INT); + else if ( bt == zeek::TYPE_INTERVAL || bt == zeek::TYPE_DOUBLE ) base_result_type = t; else ExprError("requires an integral or double operand"); if ( is_vector(op) ) - SetType(make_intrusive(std::move(base_result_type))); + SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); } @@ -1067,7 +1067,7 @@ IntrusivePtr PosExpr::Fold(Val* v) const { TypeTag t = v->GetType()->Tag(); - if ( t == TYPE_DOUBLE || t == TYPE_INTERVAL || t == TYPE_INT ) + if ( t == zeek::TYPE_DOUBLE || t == zeek::TYPE_INTERVAL || t == zeek::TYPE_INT ) return {NewRef{}, v}; else return val_mgr->Int(v->CoerceToInt()); @@ -1086,23 +1086,23 @@ NegExpr::NegExpr(IntrusivePtr arg_op) if ( IsIntegral(bt) ) // Promote count and counter to int. - base_result_type = base_type(TYPE_INT); - else if ( bt == TYPE_INTERVAL || bt == TYPE_DOUBLE ) + base_result_type = base_type(zeek::TYPE_INT); + else if ( bt == zeek::TYPE_INTERVAL || bt == zeek::TYPE_DOUBLE ) base_result_type = t; else ExprError("requires an integral or double operand"); if ( is_vector(op) ) - SetType(make_intrusive(std::move(base_result_type))); + SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); } IntrusivePtr NegExpr::Fold(Val* v) const { - if ( v->GetType()->Tag() == TYPE_DOUBLE ) + if ( v->GetType()->Tag() == zeek::TYPE_DOUBLE ) return make_intrusive(- v->InternalDouble()); - else if ( v->GetType()->Tag() == TYPE_INTERVAL ) + else if ( v->GetType()->Tag() == zeek::TYPE_INTERVAL ) return make_intrusive(- v->InternalDouble()); else return val_mgr->Int(- v->CoerceToInt()); @@ -1114,10 +1114,10 @@ SizeExpr::SizeExpr(IntrusivePtr arg_op) if ( IsError() ) return; - if ( op->GetType()->InternalType() == TYPE_INTERNAL_DOUBLE ) - SetType(base_type(TYPE_DOUBLE)); + if ( op->GetType()->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) + SetType(base_type(zeek::TYPE_DOUBLE)); else - SetType(base_type(TYPE_COUNT)); + SetType(base_type(zeek::TYPE_COUNT)); } IntrusivePtr SizeExpr::Eval(Frame* f) const @@ -1153,9 +1153,9 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) IntrusivePtr base_result_type; - if ( bt2 == TYPE_INTERVAL && ( bt1 == TYPE_TIME || bt1 == TYPE_INTERVAL ) ) + if ( bt2 == zeek::TYPE_INTERVAL && ( bt1 == zeek::TYPE_TIME || bt1 == zeek::TYPE_INTERVAL ) ) base_result_type = base_type(bt1); - else if ( bt2 == TYPE_TIME && bt1 == TYPE_INTERVAL ) + else if ( bt2 == zeek::TYPE_TIME && bt1 == zeek::TYPE_INTERVAL ) base_result_type = base_type(bt2); else if ( BothArithmetic(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); @@ -1167,7 +1167,7 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( base_result_type ) { if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(std::move(base_result_type))); + SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); } @@ -1176,8 +1176,8 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) void AddExpr::Canonicize() { if ( expr_greater(op2.get(), op1.get()) || - (op1->GetType()->Tag() == TYPE_INTERVAL && - op2->GetType()->Tag() == TYPE_TIME) || + (op1->GetType()->Tag() == zeek::TYPE_INTERVAL && + op2->GetType()->Tag() == zeek::TYPE_TIME) || (op2->IsConst() && ! is_vector(op2->ExprVal()) && ! op1->IsConst())) SwapOps(); } @@ -1216,7 +1216,7 @@ AddToExpr::AddToExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) ExprError("appending non-arithmetic to arithmetic vector"); } - else if ( bt1 != bt2 && bt1 != TYPE_ANY ) + else if ( bt1 != bt2 && bt1 != zeek::TYPE_ANY ) ExprError(fmt("incompatible vector append: %s and %s", type_name(bt1), type_name(bt2))); @@ -1278,11 +1278,11 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) IntrusivePtr base_result_type; - if ( bt2 == TYPE_INTERVAL && ( bt1 == TYPE_TIME || bt1 == TYPE_INTERVAL ) ) + if ( bt2 == zeek::TYPE_INTERVAL && ( bt1 == zeek::TYPE_TIME || bt1 == zeek::TYPE_INTERVAL ) ) base_result_type = base_type(bt1); - else if ( bt1 == TYPE_TIME && bt2 == TYPE_TIME ) - SetType(base_type(TYPE_INTERVAL)); + else if ( bt1 == zeek::TYPE_TIME && bt2 == zeek::TYPE_TIME ) + SetType(base_type(zeek::TYPE_INTERVAL)); else if ( t1->IsSet() && t2->IsSet() ) { @@ -1301,7 +1301,7 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( base_result_type ) { if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(std::move(base_result_type))); + SetType(make_intrusive(std::move(base_result_type))); else SetType(std::move(base_result_type)); } @@ -1364,10 +1364,10 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsVector(bt2) ) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); - if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) + if ( bt1 == zeek::TYPE_INTERVAL || bt2 == zeek::TYPE_INTERVAL ) { if ( IsArithmetic(bt1) || IsArithmetic(bt2) ) - PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2) ); + PromoteType(zeek::TYPE_INTERVAL, is_vector(op1) || is_vector(op2) ); else ExprError("multiplication with interval requires arithmetic operand"); } @@ -1379,7 +1379,7 @@ TimesExpr::TimesExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) void TimesExpr::Canonicize() { - if ( expr_greater(op2.get(), op1.get()) || op2->GetType()->Tag() == TYPE_INTERVAL || + if ( expr_greater(op2.get(), op1.get()) || op2->GetType()->Tag() == zeek::TYPE_INTERVAL || (op2->IsConst() && ! is_vector(op2->ExprVal()) && ! op1->IsConst()) ) SwapOps(); } @@ -1401,16 +1401,16 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, if ( IsVector(bt2) ) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); - if ( bt1 == TYPE_INTERVAL || bt2 == TYPE_INTERVAL ) + if ( bt1 == zeek::TYPE_INTERVAL || bt2 == zeek::TYPE_INTERVAL ) { if ( IsArithmetic(bt1) || IsArithmetic(bt2) ) - PromoteType(TYPE_INTERVAL, is_vector(op1) || is_vector(op2)); - else if ( bt1 == TYPE_INTERVAL && bt2 == TYPE_INTERVAL ) + PromoteType(zeek::TYPE_INTERVAL, is_vector(op1) || is_vector(op2)); + else if ( bt1 == zeek::TYPE_INTERVAL && bt2 == zeek::TYPE_INTERVAL ) { if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(base_type(TYPE_DOUBLE))); + SetType(make_intrusive(base_type(zeek::TYPE_DOUBLE))); else - SetType(base_type(TYPE_DOUBLE)); + SetType(base_type(zeek::TYPE_DOUBLE)); } else ExprError("division of interval requires arithmetic operand"); @@ -1419,9 +1419,9 @@ DivideExpr::DivideExpr(IntrusivePtr arg_op1, else if ( BothArithmetic(bt1, bt2) ) PromoteType(max_type(bt1, bt2), is_vector(op1) || is_vector(op2)); - else if ( bt1 == TYPE_ADDR && ! is_vector(op2) && - (bt2 == TYPE_COUNT || bt2 == TYPE_INT) ) - SetType(base_type(TYPE_SUBNET)); + else if ( bt1 == zeek::TYPE_ADDR && ! is_vector(op2) && + (bt2 == zeek::TYPE_COUNT || bt2 == zeek::TYPE_INT) ) + SetType(base_type(zeek::TYPE_SUBNET)); else ExprError("requires arithmetic operands"); @@ -1431,7 +1431,7 @@ IntrusivePtr DivideExpr::AddrFold(Val* v1, Val* v2) const { uint32_t mask; - if ( v2->GetType()->Tag() == TYPE_COUNT ) + if ( v2->GetType()->Tag() == zeek::TYPE_COUNT ) mask = static_cast(v2->InternalUnsigned()); else mask = static_cast(v2->InternalInt()); @@ -1497,10 +1497,10 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, { if ( ! (is_vector(op1) && is_vector(op2)) ) reporter->Warning("mixing vector and scalar operands is deprecated"); - SetType(make_intrusive(base_type(TYPE_BOOL))); + SetType(make_intrusive(base_type(zeek::TYPE_BOOL))); } else - SetType(base_type(TYPE_BOOL)); + SetType(base_type(zeek::TYPE_BOOL)); } else ExprError("requires boolean operands"); @@ -1574,7 +1574,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const if ( scalar_v->IsZero() == is_and ) { - result = make_intrusive(GetType()); + result = make_intrusive(GetType()); result->Resize(vector_v->Size()); result->AssignRepeat(0, result->Size(), std::move(scalar_v)); } @@ -1599,7 +1599,7 @@ IntrusivePtr BoolExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(GetType()); + auto result = make_intrusive(GetType()); result->Resize(vec_v1->Size()); for ( unsigned int i = 0; i < vec_v1->Size(); ++i ) @@ -1641,25 +1641,25 @@ BitExpr::BitExpr(BroExprTag arg_tag, if ( IsVector(bt2) ) bt2 = t2->AsVectorType()->Yield()->Tag(); - if ( (bt1 == TYPE_COUNT || bt1 == TYPE_COUNTER) && - (bt2 == TYPE_COUNT || bt2 == TYPE_COUNTER) ) + if ( (bt1 == zeek::TYPE_COUNT || bt1 == zeek::TYPE_COUNTER) && + (bt2 == zeek::TYPE_COUNT || bt2 == zeek::TYPE_COUNTER) ) { - if ( bt1 == TYPE_COUNTER && bt2 == TYPE_COUNTER ) + if ( bt1 == zeek::TYPE_COUNTER && bt2 == zeek::TYPE_COUNTER ) ExprError("cannot apply a bitwise operator to two \"counter\" operands"); else if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(base_type(TYPE_COUNT))); + SetType(make_intrusive(base_type(zeek::TYPE_COUNT))); else - SetType(base_type(TYPE_COUNT)); + SetType(base_type(zeek::TYPE_COUNT)); } - else if ( bt1 == TYPE_PATTERN ) + else if ( bt1 == zeek::TYPE_PATTERN ) { - if ( bt2 != TYPE_PATTERN ) + if ( bt2 != zeek::TYPE_PATTERN ) ExprError("cannot mix pattern and non-pattern operands"); else if ( tag == EXPR_XOR ) ExprError("'^' operator does not apply to patterns"); else - SetType(base_type(TYPE_PATTERN)); + SetType(base_type(zeek::TYPE_PATTERN)); } else if ( t1->IsSet() && t2->IsSet() ) @@ -1695,38 +1695,38 @@ EqExpr::EqExpr(BroExprTag arg_tag, bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(base_type(TYPE_BOOL))); + SetType(make_intrusive(base_type(zeek::TYPE_BOOL))); else - SetType(base_type(TYPE_BOOL)); + SetType(base_type(zeek::TYPE_BOOL)); if ( BothArithmetic(bt1, bt2) ) PromoteOps(max_type(bt1, bt2)); else if ( EitherArithmetic(bt1, bt2) && // Allow comparisons with zero. - ((bt1 == TYPE_TIME && op2->IsZero()) || - (bt2 == TYPE_TIME && op1->IsZero())) ) - PromoteOps(TYPE_TIME); + ((bt1 == zeek::TYPE_TIME && op2->IsZero()) || + (bt2 == zeek::TYPE_TIME && op1->IsZero())) ) + PromoteOps(zeek::TYPE_TIME); else if ( bt1 == bt2 ) { switch ( bt1 ) { - case TYPE_BOOL: - case TYPE_TIME: - case TYPE_INTERVAL: - case TYPE_STRING: - case TYPE_PORT: - case TYPE_ADDR: - case TYPE_SUBNET: - case TYPE_ERROR: + case zeek::TYPE_BOOL: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_STRING: + case zeek::TYPE_PORT: + case zeek::TYPE_ADDR: + case zeek::TYPE_SUBNET: + case zeek::TYPE_ERROR: break; - case TYPE_ENUM: + case zeek::TYPE_ENUM: if ( ! same_type(t1, t2) ) ExprError("illegal enum comparison"); break; - case TYPE_TABLE: + case zeek::TYPE_TABLE: if ( t1->IsSet() && t2->IsSet() ) { if ( ! same_type(t1, t2) ) @@ -1741,7 +1741,7 @@ EqExpr::EqExpr(BroExprTag arg_tag, } } - else if ( bt1 == TYPE_PATTERN && bt2 == TYPE_STRING ) + else if ( bt1 == zeek::TYPE_PATTERN && bt2 == zeek::TYPE_STRING ) ; else @@ -1750,10 +1750,10 @@ EqExpr::EqExpr(BroExprTag arg_tag, void EqExpr::Canonicize() { - if ( op2->GetType()->Tag() == TYPE_PATTERN ) + if ( op2->GetType()->Tag() == zeek::TYPE_PATTERN ) SwapOps(); - else if ( op1->GetType()->Tag() == TYPE_PATTERN ) + else if ( op1->GetType()->Tag() == zeek::TYPE_PATTERN ) ; else if ( expr_greater(op2.get(), op1.get()) ) @@ -1762,7 +1762,7 @@ void EqExpr::Canonicize() IntrusivePtr EqExpr::Fold(Val* v1, Val* v2) const { - if ( op1->GetType()->Tag() == TYPE_PATTERN ) + if ( op1->GetType()->Tag() == zeek::TYPE_PATTERN ) { RE_Matcher* re = v1->AsPattern(); const BroString* s = v2->AsString(); @@ -1797,9 +1797,9 @@ RelExpr::RelExpr(BroExprTag arg_tag, bt2 = t2->AsVectorType()->Yield()->Tag(); if ( is_vector(op1) || is_vector(op2) ) - SetType(make_intrusive(base_type(TYPE_BOOL))); + SetType(make_intrusive(base_type(zeek::TYPE_BOOL))); else - SetType(base_type(TYPE_BOOL)); + SetType(base_type(zeek::TYPE_BOOL)); if ( BothArithmetic(bt1, bt2) ) PromoteOps(max_type(bt1, bt2)); @@ -1813,9 +1813,9 @@ RelExpr::RelExpr(BroExprTag arg_tag, else if ( bt1 != bt2 ) ExprError("operands must be of the same type"); - else if ( bt1 != TYPE_TIME && bt1 != TYPE_INTERVAL && - bt1 != TYPE_PORT && bt1 != TYPE_ADDR && - bt1 != TYPE_STRING ) + else if ( bt1 != zeek::TYPE_TIME && bt1 != zeek::TYPE_INTERVAL && + bt1 != zeek::TYPE_PORT && bt1 != zeek::TYPE_ADDR && + bt1 != zeek::TYPE_STRING ) ExprError("illegal comparison"); } @@ -1847,7 +1847,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, if ( op1->IsError() || op2->IsError() || op3->IsError() ) SetError(); - else if ( bt1 != TYPE_BOOL ) + else if ( bt1 != zeek::TYPE_BOOL ) ExprError("requires boolean conditional"); else @@ -1877,7 +1877,7 @@ CondExpr::CondExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, op3 = make_intrusive(std::move(op3), t); if ( is_vector(op2) ) - SetType(make_intrusive(base_type(t))); + SetType(make_intrusive(base_type(t))); else SetType(base_type(t)); } @@ -1931,7 +1931,7 @@ IntrusivePtr CondExpr::Eval(Frame* f) const return nullptr; } - auto result = make_intrusive(GetType()); + auto result = make_intrusive(GetType()); result->Resize(cond->Size()); for ( unsigned int i = 0; i < cond->Size(); ++i ) @@ -1988,7 +1988,7 @@ RefExpr::RefExpr(IntrusivePtr arg_op) if ( IsError() ) return; - if ( ! ::is_assignable(op->GetType()->Tag()) ) + if ( ! zeek::is_assignable(op->GetType()->Tag()) ) ExprError("illegal assignment target"); else SetType(op->GetType()); @@ -2043,13 +2043,13 @@ bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) TypeTag bt1 = op1->GetType()->Tag(); TypeTag bt2 = op2->GetType()->Tag(); - if ( bt1 == TYPE_LIST && bt2 == TYPE_ANY ) + if ( bt1 == zeek::TYPE_LIST && bt2 == zeek::TYPE_ANY ) // This is ok because we cannot explicitly declare lists on // the script level. return true; // This should be one of them, but not both (i.e. XOR) - if ( ((bt1 == TYPE_ENUM) ^ (bt2 == TYPE_ENUM)) ) + if ( ((bt1 == zeek::TYPE_ENUM) ^ (bt2 == zeek::TYPE_ENUM)) ) { ExprError("can't convert to/from enumerated type"); return false; @@ -2058,20 +2058,20 @@ bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) if ( IsArithmetic(bt1) ) return TypeCheckArithmetics(bt1, bt2); - if ( bt1 == TYPE_TIME && IsArithmetic(bt2) && op2->IsZero() ) + if ( bt1 == zeek::TYPE_TIME && IsArithmetic(bt2) && op2->IsZero() ) { // Allow assignments to zero as a special case. op2 = make_intrusive(std::move(op2), bt1); return true; } - if ( bt1 == TYPE_TABLE && bt2 == bt1 && + if ( bt1 == zeek::TYPE_TABLE && bt2 == bt1 && op2->GetType()->AsTableType()->IsUnspecifiedTable() ) { op2 = make_intrusive(std::move(op2), op1->GetType()); return true; } - if ( bt1 == TYPE_TABLE && op2->Tag() == EXPR_LIST ) + if ( bt1 == zeek::TYPE_TABLE && op2->Tag() == EXPR_LIST ) { std::unique_ptr>> attr_copy; @@ -2100,11 +2100,11 @@ bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) return true; } - if ( bt1 == TYPE_VECTOR ) + if ( bt1 == zeek::TYPE_VECTOR ) { if ( bt2 == bt1 && op2->GetType()->AsVectorType()->IsUnspecifiedVector() ) { - op2 = make_intrusive(std::move(op2), op1->GetType()); + op2 = make_intrusive(std::move(op2), op1->GetType()); return true; } @@ -2117,8 +2117,8 @@ bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) } } - if ( op1->GetType()->Tag() == TYPE_RECORD && - op2->GetType()->Tag() == TYPE_RECORD ) + if ( op1->GetType()->Tag() == zeek::TYPE_RECORD && + op2->GetType()->Tag() == zeek::TYPE_RECORD ) { if ( same_type(op1->GetType(), op2->GetType()) ) { @@ -2144,7 +2144,7 @@ bool AssignExpr::TypeCheck(const IntrusivePtr& attrs) if ( ! same_type(op1->GetType(), op2->GetType()) ) { - if ( bt1 == TYPE_TABLE && bt2 == TYPE_TABLE ) + if ( bt1 == zeek::TYPE_TABLE && bt2 == zeek::TYPE_TABLE ) { if ( op2->Tag() == EXPR_SET_CONSTRUCTOR ) { @@ -2209,24 +2209,24 @@ bool AssignExpr::TypeCheckArithmetics(TypeTag bt1, TypeTag bt2) return false; } - if ( bt1 == TYPE_DOUBLE ) + if ( bt1 == zeek::TYPE_DOUBLE ) { - PromoteOps(TYPE_DOUBLE); + PromoteOps(zeek::TYPE_DOUBLE); return true; } - if ( bt2 == TYPE_DOUBLE ) + if ( bt2 == zeek::TYPE_DOUBLE ) { Warn("dangerous assignment of double to integral"); op2 = make_intrusive(std::move(op2), bt1); bt2 = op2->GetType()->Tag(); } - if ( bt1 == TYPE_INT ) - PromoteOps(TYPE_INT); + if ( bt1 == zeek::TYPE_INT ) + PromoteOps(zeek::TYPE_INT); else { - if ( bt2 == TYPE_INT ) + if ( bt2 == zeek::TYPE_INT ) { Warn("dangerous assignment of integer to count"); op2 = make_intrusive(std::move(op2), bt1); @@ -2271,7 +2271,7 @@ IntrusivePtr AssignExpr::InitType() const } const auto& tl = op1->GetType(); - if ( tl->Tag() != TYPE_LIST ) + if ( tl->Tag() != zeek::TYPE_LIST ) Internal("inconsistent list expr in AssignExpr::InitType"); return make_intrusive(IntrusivePtr{NewRef{}, tl->AsTypeList()}, @@ -2287,7 +2287,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const if ( IsRecordElement(&td) ) { - if ( t->Tag() != TYPE_RECORD ) + if ( t->Tag() != zeek::TYPE_RECORD ) { RuntimeError("not a record initializer"); return; @@ -2342,7 +2342,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) if ( IsRecordElement(&td) ) { - if ( t->Tag() != TYPE_RECORD ) + if ( t->Tag() != zeek::TYPE_RECORD ) { Error("not a record initializer", t); return nullptr; @@ -2357,7 +2357,7 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) return nullptr; } - if ( aggr->GetType()->Tag() != TYPE_RECORD ) + if ( aggr->GetType()->Tag() != zeek::TYPE_RECORD ) Internal("bad aggregate in AssignExpr::InitVal"); RecordVal* aggr_r = aggr->AsRecordVal(); @@ -2373,13 +2373,13 @@ IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) else if ( op1->Tag() == EXPR_LIST ) { - if ( t->Tag() != TYPE_TABLE ) + if ( t->Tag() != zeek::TYPE_TABLE ) { Error("not a table initialization", t); return nullptr; } - if ( aggr->GetType()->Tag() != TYPE_TABLE ) + if ( aggr->GetType()->Tag() != zeek::TYPE_TABLE ) Internal("bad aggregate in AssignExpr::InitVal"); auto tv = cast_intrusive(std::move(aggr)); @@ -2483,20 +2483,20 @@ IndexExpr::IndexExpr(IntrusivePtr arg_op1, else if ( ! op1->GetType()->Yield() ) { if ( IsString(op1->GetType()->Tag()) && match_type == MATCHES_INDEX_SCALAR ) - SetType(base_type(TYPE_STRING)); + SetType(base_type(zeek::TYPE_STRING)); else // It's a set - so indexing it yields void. We don't // directly generate an error message, though, since this // expression might be part of an add/delete statement, // rather than yielding a value. - SetType(base_type(TYPE_VOID)); + SetType(base_type(zeek::TYPE_VOID)); } else if ( match_type == MATCHES_INDEX_SCALAR ) SetType(op1->GetType()->Yield()); else if ( match_type == MATCHES_INDEX_VECTOR ) - SetType(make_intrusive(op1->GetType()->Yield())); + SetType(make_intrusive(op1->GetType()->Yield())); else ExprError("Unknown MatchesIndex() return value"); @@ -2516,7 +2516,7 @@ bool IndexExpr::CanDel() const if ( IsError() ) return true; // avoid cascading the error report - return op1->GetType()->Tag() == TYPE_TABLE; + return op1->GetType()->Tag() == zeek::TYPE_TABLE; } void IndexExpr::Add(Frame* f) @@ -2581,7 +2581,7 @@ IntrusivePtr IndexExpr::Eval(Frame* f) const { VectorVal* v_v1 = v1->AsVectorVal(); VectorVal* v_v2 = indv->AsVectorVal(); - auto v_result = make_intrusive(GetType()); + auto v_result = make_intrusive(GetType()); // Booleans select each element (or not). if ( IsBool(v_v2->GetType()->Yield()->Tag()) ) @@ -2632,7 +2632,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const IntrusivePtr v; switch ( v1->GetType()->Tag() ) { - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { VectorVal* vect = v1->AsVectorVal(); const ListVal* lv = v2->AsListVal(); @@ -2642,7 +2642,7 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const else { size_t len = vect->Size(); - auto result = make_intrusive(vect->GetType()); + auto result = make_intrusive(vect->GetType()); bro_int_t first = get_slice_index(lv->Idx(0)->CoerceToInt(), len); bro_int_t last = get_slice_index(lv->Idx(1)->CoerceToInt(), len); @@ -2661,11 +2661,11 @@ IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const } break; - case TYPE_TABLE: + case zeek::TYPE_TABLE: v = v1->AsTableVal()->FindOrDefault({NewRef{}, v2}); // Then, we jump into the TableVal here. break; - case TYPE_STRING: + case zeek::TYPE_STRING: { const ListVal* lv = v2->AsListVal(); const BroString* s = v1->AsString(); @@ -2730,7 +2730,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) auto v_extra = v; switch ( v1->GetType()->Tag() ) { - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { const ListVal* lv = v2->AsListVal(); VectorVal* v1_vect = v1->AsVectorVal(); @@ -2761,7 +2761,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) v->Describe(&d); const auto& vt = v->GetType(); auto vtt = vt->Tag(); - std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); + std::string tn = vtt == zeek::TYPE_RECORD ? vt->GetName() : type_name(vtt); RuntimeErrorWithCallStack(fmt( "vector index assignment failed for invalid type '%s', value: %s", tn.data(), d.Description())); @@ -2772,7 +2772,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: if ( ! v1->AsTableVal()->Assign(std::move(v2), std::move(v)) ) { v = std::move(v_extra); @@ -2783,7 +2783,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) v->Describe(&d); const auto& vt = v->GetType(); auto vtt = vt->Tag(); - std::string tn = vtt == TYPE_RECORD ? vt->GetName() : type_name(vtt); + std::string tn = vtt == zeek::TYPE_RECORD ? vt->GetName() : type_name(vtt); RuntimeErrorWithCallStack(fmt( "table index assignment failed for invalid type '%s', value: %s", tn.data(), d.Description())); @@ -2793,7 +2793,7 @@ void IndexExpr::Assign(Frame* f, IntrusivePtr v) } break; - case TYPE_STRING: + case zeek::TYPE_STRING: RuntimeErrorWithCallStack("assignment via string index accessor not allowed"); break; @@ -2940,7 +2940,7 @@ HasFieldExpr::HasFieldExpr(IntrusivePtr arg_op, else if ( rt->IsFieldDeprecated(field) ) reporter->Warning("%s", rt->GetFieldDeprecationWarning(field, true).c_str()); - SetType(base_type(TYPE_BOOL)); + SetType(base_type(zeek::TYPE_BOOL)); } } @@ -3069,7 +3069,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li else { if ( op->AsListExpr()->Exprs().empty() ) - SetType(make_intrusive(make_intrusive(base_type(TYPE_ANY)), nullptr)); + SetType(make_intrusive(make_intrusive(base_type(zeek::TYPE_ANY)), nullptr)); else { SetType(init_type(op.get())); @@ -3077,7 +3077,7 @@ TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_li if ( ! type ) SetError(); - else if ( type->Tag() != TYPE_TABLE || + else if ( type->Tag() != zeek::TYPE_TABLE || type->AsTableType()->IsSet() ) SetError("values in table(...) constructor do not specify a table"); } @@ -3190,7 +3190,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, else { if ( op->AsListExpr()->Exprs().empty() ) - SetType(make_intrusive<::SetType>(make_intrusive(base_type(TYPE_ANY)), nullptr)); + SetType(make_intrusive(make_intrusive(zeek::base_type(zeek::TYPE_ANY)), nullptr)); else SetType(init_type(op.get())); } @@ -3198,7 +3198,7 @@ SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, if ( ! type ) SetError(); - else if ( type->Tag() != TYPE_TABLE || ! type->AsTableType()->IsSet() ) + else if ( type->Tag() != zeek::TYPE_TABLE || ! type->AsTableType()->IsSet() ) SetError("values in set(...) constructor do not specify a set"); if ( arg_attrs ) @@ -3296,7 +3296,7 @@ VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr constructor_ if ( arg_type ) { - if ( arg_type->Tag() != TYPE_VECTOR ) + if ( arg_type->Tag() != zeek::TYPE_VECTOR ) { Error("bad vector constructor type", arg_type.get()); SetError(); @@ -3312,12 +3312,12 @@ VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr constructor_ // vector(). // By default, assign VOID type here. A vector with // void type set is seen as an unspecified vector. - SetType(make_intrusive<::VectorType>(base_type(TYPE_VOID))); + SetType(make_intrusive(zeek::base_type(zeek::TYPE_VOID))); return; } if ( auto t = merge_type_list(op->AsListExpr()) ) - SetType(make_intrusive(std::move(t))); + SetType(make_intrusive(std::move(t))); else { SetError(); @@ -3335,7 +3335,7 @@ IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const if ( IsError() ) return nullptr; - auto vec = make_intrusive(GetType()); + auto vec = make_intrusive(GetType()); const expr_list& exprs = op->AsListExpr()->Exprs(); loop_over_list(exprs, i) @@ -3357,7 +3357,7 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< if ( IsError() ) return nullptr; - auto vt = GetType(); + auto vt = GetType(); auto vec = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsVectorVal()} : make_intrusive(std::move(vt)); @@ -3443,17 +3443,17 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr arg_op, TypeTag t) if ( IsVector(bt) ) { - SetType(make_intrusive(base_type(t))); + SetType(make_intrusive(zeek::base_type(t))); vbt = op->GetType()->AsVectorType()->Yield()->Tag(); } else - SetType(base_type(t)); + SetType(zeek::base_type(t)); - if ( (bt == TYPE_ENUM) != (t == TYPE_ENUM) ) + if ( (bt == zeek::TYPE_ENUM) != (t == zeek::TYPE_ENUM) ) ExprError("can't convert to/from enumerated type"); else if ( ! IsArithmetic(t) && ! IsBool(t) && - t != TYPE_TIME && t != TYPE_INTERVAL ) + t != zeek::TYPE_TIME && t != zeek::TYPE_INTERVAL ) ExprError("bad coercion"); else if ( ! IsArithmetic(bt) && ! IsBool(bt) && @@ -3464,13 +3464,13 @@ ArithCoerceExpr::ArithCoerceExpr(IntrusivePtr arg_op, TypeTag t) IntrusivePtr ArithCoerceExpr::FoldSingleVal(Val* v, InternalTypeTag t) const { switch ( t ) { - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: return make_intrusive(v->CoerceToDouble()); - case TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_INT: return val_mgr->Int(v->CoerceToInt()); - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_UNSIGNED: return val_mgr->Count(v->CoerceToUnsigned()); default: @@ -3488,7 +3488,7 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const // Our result type might be vector, in which case this // invocation is being done per-element rather than on // the whole vector. Correct the type tag if necessary. - if ( type->Tag() == TYPE_VECTOR ) + if ( type->Tag() == zeek::TYPE_VECTOR ) t = GetType()->AsVectorType()->Yield()->InternalType(); return FoldSingleVal(v, t); @@ -3497,7 +3497,7 @@ IntrusivePtr ArithCoerceExpr::Fold(Val* v) const t = GetType()->AsVectorType()->Yield()->InternalType(); VectorVal* vv = v->AsVectorVal(); - auto result = make_intrusive(GetType()); + auto result = make_intrusive(GetType()); for ( unsigned int i = 0; i < vv->Size(); ++i ) { @@ -3520,10 +3520,10 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, SetType(std::move(r)); - if ( GetType()->Tag() != TYPE_RECORD ) + if ( GetType()->Tag() != zeek::TYPE_RECORD ) ExprError("coercion to non-record"); - else if ( op->GetType()->Tag() != TYPE_RECORD ) + else if ( op->GetType()->Tag() != zeek::TYPE_RECORD ) ExprError("coercion of non-record to record"); else @@ -3561,10 +3561,10 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, if ( ! BothArithmetic(sup_tag, sub_tag) ) return false; - if ( sub_tag == TYPE_DOUBLE && IsIntegral(sup_tag) ) + if ( sub_tag == zeek::TYPE_DOUBLE && IsIntegral(sup_tag) ) return false; - if ( sub_tag == TYPE_INT && sup_tag == TYPE_COUNT ) + if ( sub_tag == zeek::TYPE_INT && sup_tag == zeek::TYPE_COUNT ) return false; return true; @@ -3572,10 +3572,10 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, auto is_record_promotable = [](BroType* sup, BroType* sub) -> bool { - if ( sup->Tag() != TYPE_RECORD ) + if ( sup->Tag() != zeek::TYPE_RECORD ) return false; - if ( sub->Tag() != TYPE_RECORD ) + if ( sub->Tag() != zeek::TYPE_RECORD ) return false; return record_promotion_compatible(sup->AsRecordType(), @@ -3674,8 +3674,8 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const const auto& rhs_type = rhs->GetType(); const auto& field_type = val_type->GetFieldType(i); - if ( rhs_type->Tag() == TYPE_RECORD && - field_type->Tag() == TYPE_RECORD && + if ( rhs_type->Tag() == zeek::TYPE_RECORD && + field_type->Tag() == zeek::TYPE_RECORD && ! same_type(rhs_type, field_type) ) { if ( auto new_val = rhs->AsRecordVal()->CoerceTo(cast_intrusive(field_type)) ) @@ -3700,8 +3700,8 @@ IntrusivePtr RecordCoerceExpr::Fold(Val* v) const const auto& def_type = def_val->GetType(); const auto& field_type = GetType()->AsRecordType()->GetFieldType(i); - if ( def_type->Tag() == TYPE_RECORD && - field_type->Tag() == TYPE_RECORD && + if ( def_type->Tag() == zeek::TYPE_RECORD && + field_type->Tag() == zeek::TYPE_RECORD && ! same_type(def_type, field_type) ) { auto tmp = def_val->AsRecordVal()->CoerceTo( @@ -3730,10 +3730,10 @@ TableCoerceExpr::TableCoerceExpr(IntrusivePtr arg_op, SetType(std::move(r)); - if ( GetType()->Tag() != TYPE_TABLE ) + if ( GetType()->Tag() != zeek::TYPE_TABLE ) ExprError("coercion to non-table"); - else if ( op->GetType()->Tag() != TYPE_TABLE ) + else if ( op->GetType()->Tag() != zeek::TYPE_TABLE ) ExprError("coercion of non-table/set to table/set"); } @@ -3753,7 +3753,7 @@ IntrusivePtr TableCoerceExpr::Fold(Val* v) const } VectorCoerceExpr::VectorCoerceExpr(IntrusivePtr arg_op, - IntrusivePtr v) + IntrusivePtr v) : UnaryExpr(EXPR_VECTOR_COERCE, std::move(arg_op)) { if ( IsError() ) @@ -3761,10 +3761,10 @@ VectorCoerceExpr::VectorCoerceExpr(IntrusivePtr arg_op, SetType(std::move(v)); - if ( GetType()->Tag() != TYPE_VECTOR ) + if ( GetType()->Tag() != zeek::TYPE_VECTOR ) ExprError("coercion to non-vector"); - else if ( op->GetType()->Tag() != TYPE_VECTOR ) + else if ( op->GetType()->Tag() != zeek::TYPE_VECTOR ) ExprError("coercion of non-vector to vector"); } @@ -3780,7 +3780,7 @@ IntrusivePtr VectorCoerceExpr::Fold(Val* v) const if ( vv->Size() > 0 ) RuntimeErrorWithCallStack("coercion of non-empty vector"); - return make_intrusive(GetType()); + return make_intrusive(GetType()); } ScheduleTimer::ScheduleTimer(const EventHandlerPtr& arg_event, zeek::Args arg_args, @@ -3810,10 +3810,10 @@ ScheduleExpr::ScheduleExpr(IntrusivePtr arg_when, TypeTag bt = when->GetType()->Tag(); - if ( bt != TYPE_TIME && bt != TYPE_INTERVAL ) + if ( bt != zeek::TYPE_TIME && bt != zeek::TYPE_INTERVAL ) ExprError("schedule expression requires a time or time interval"); else - SetType(base_type(TYPE_TIMER)); + SetType(zeek::base_type(zeek::TYPE_TIMER)); } bool ScheduleExpr::IsPure() const @@ -3833,7 +3833,7 @@ IntrusivePtr ScheduleExpr::Eval(Frame* f) const double dt = when_val->InternalDouble(); - if ( when->GetType()->Tag() == TYPE_INTERVAL ) + if ( when->GetType()->Tag() == zeek::TYPE_INTERVAL ) dt += network_time; auto args = eval_list(f, event->Args()); @@ -3885,20 +3885,20 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsError() ) return; - if ( op1->GetType()->Tag() == TYPE_PATTERN ) + if ( op1->GetType()->Tag() == zeek::TYPE_PATTERN ) { - if ( op2->GetType()->Tag() != TYPE_STRING ) + if ( op2->GetType()->Tag() != zeek::TYPE_STRING ) { op2->GetType()->Error("pattern requires string index", op1.get()); SetError(); } else - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); } - else if ( op1->GetType()->Tag() == TYPE_RECORD ) + else if ( op1->GetType()->Tag() == zeek::TYPE_RECORD ) { - if ( op2->GetType()->Tag() != TYPE_TABLE ) + if ( op2->GetType()->Tag() != zeek::TYPE_TABLE ) { op2->GetType()->Error("table/set required"); SetError(); @@ -3915,31 +3915,31 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) SetError(); } else - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); } } - else if ( op1->GetType()->Tag() == TYPE_STRING && - op2->GetType()->Tag() == TYPE_STRING ) - SetType(base_type(TYPE_BOOL)); + else if ( op1->GetType()->Tag() == zeek::TYPE_STRING && + op2->GetType()->Tag() == zeek::TYPE_STRING ) + SetType(zeek::base_type(zeek::TYPE_BOOL)); else { // Check for: in // in set[subnet] // in table[subnet] of ... - if ( op1->GetType()->Tag() == TYPE_ADDR ) + if ( op1->GetType()->Tag() == zeek::TYPE_ADDR ) { - if ( op2->GetType()->Tag() == TYPE_SUBNET ) + if ( op2->GetType()->Tag() == zeek::TYPE_SUBNET ) { - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); return; } - if ( op2->GetType()->Tag() == TYPE_TABLE && + if ( op2->GetType()->Tag() == zeek::TYPE_TABLE && op2->GetType()->AsTableType()->IsSubNetIndex() ) { - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); return; } } @@ -3952,20 +3952,20 @@ InExpr::InExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( ! op2->GetType()->MatchesIndex(lop1) ) SetError("not an index type"); else - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); } } IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const { - if ( v1->GetType()->Tag() == TYPE_PATTERN ) + if ( v1->GetType()->Tag() == zeek::TYPE_PATTERN ) { RE_Matcher* re = v1->AsPattern(); const BroString* s = v2->AsString(); return val_mgr->Bool(re->MatchAnywhere(s) != 0); } - if ( v2->GetType()->Tag() == TYPE_STRING ) + if ( v2->GetType()->Tag() == zeek::TYPE_STRING ) { const BroString* s1 = v1->AsString(); const BroString* s2 = v2->AsString(); @@ -3976,8 +3976,8 @@ IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const return val_mgr->Bool(res); } - if ( v1->GetType()->Tag() == TYPE_ADDR && - v2->GetType()->Tag() == TYPE_SUBNET ) + if ( v1->GetType()->Tag() == zeek::TYPE_ADDR && + v2->GetType()->Tag() == zeek::TYPE_SUBNET ) return val_mgr->Bool(v2->AsSubNetVal()->Contains(v1->AsAddr())); bool res; @@ -4381,7 +4381,7 @@ bool ListExpr::IsPure() const IntrusivePtr ListExpr::Eval(Frame* f) const { - auto v = make_intrusive(TYPE_ANY); + auto v = make_intrusive(zeek::TYPE_ANY); for ( const auto& expr : exprs ) { @@ -4437,7 +4437,7 @@ IntrusivePtr ListExpr::InitType() const const auto& ti = e->GetType(); // Collapse any embedded sets or lists. - if ( ti->IsSet() || ti->Tag() == TYPE_LIST ) + if ( ti->IsSet() || ti->Tag() == zeek::TYPE_LIST ) { TypeList* til = ti->IsSet() ? ti->AsSetType()->GetIndices().get() : @@ -4470,7 +4470,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co // in which case we should expand as a ListVal. if ( ! aggr && type->AsTypeList()->AllMatch(t, true) ) { - auto v = make_intrusive(TYPE_ANY); + auto v = make_intrusive(zeek::TYPE_ANY); const auto& tl = type->AsTypeList()->Types(); if ( exprs.length() != static_cast(tl.size()) ) @@ -4491,7 +4491,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return v; } - if ( t->Tag() == TYPE_LIST ) + if ( t->Tag() == zeek::TYPE_LIST ) { if ( aggr ) { @@ -4507,7 +4507,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return nullptr; } - auto v = make_intrusive(TYPE_ANY); + auto v = make_intrusive(zeek::TYPE_ANY); loop_over_list(exprs, i) { @@ -4522,8 +4522,8 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return v; } - if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TABLE && - t->Tag() != TYPE_VECTOR ) + if ( t->Tag() != zeek::TYPE_RECORD && t->Tag() != zeek::TYPE_TABLE && + t->Tag() != zeek::TYPE_VECTOR ) { if ( exprs.length() == 1 ) // Allow "global x:int = { 5 }" @@ -4541,7 +4541,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co if ( t->IsSet() ) return AddSetInit(t, std::move(aggr)); - if ( t->Tag() == TYPE_VECTOR ) + if ( t->Tag() == zeek::TYPE_VECTOR ) { // v: vector = [10, 20, 30]; VectorVal* vec = aggr->AsVectorVal(); @@ -4579,7 +4579,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co } else { - if ( t->Tag() == TYPE_RECORD ) + if ( t->Tag() == zeek::TYPE_RECORD ) { e->Error("bad record initializer", t); return nullptr; @@ -4603,7 +4603,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) const { - if ( aggr->GetType()->Tag() != TYPE_TABLE ) + if ( aggr->GetType()->Tag() != zeek::TYPE_TABLE ) Internal("bad aggregate in ListExpr::InitVal"); TableVal* tv = aggr->AsTableVal(); @@ -4617,7 +4617,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) if ( expr->GetType()->IsSet() ) // A set to flatten. element = expr->Eval(nullptr); - else if ( expr->GetType()->Tag() == TYPE_LIST ) + else if ( expr->GetType()->Tag() == zeek::TYPE_LIST ) element = expr->InitVal(it, nullptr); else element = expr->InitVal(it->Types()[0].get(), nullptr); @@ -4639,7 +4639,7 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) continue; } - if ( expr->GetType()->Tag() == TYPE_LIST ) + if ( expr->GetType()->Tag() == zeek::TYPE_LIST ) element = check_and_promote(std::move(element), it, true); else element = check_and_promote(std::move(element), it->Types()[0].get(), true); @@ -4716,7 +4716,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, for ( const auto& init : inits ) { - if ( init->GetType()->Tag() == TYPE_RECORD ) + if ( init->GetType()->Tag() == zeek::TYPE_RECORD ) { RecordType* t = init->GetType()->AsRecordType(); @@ -4815,7 +4815,7 @@ void CastExpr::ExprDescribe(ODesc* d) const IsExpr::IsExpr(IntrusivePtr arg_op, IntrusivePtr arg_t) : UnaryExpr(EXPR_IS, std::move(arg_op)), t(std::move(arg_t)) { - SetType(base_type(TYPE_BOOL)); + SetType(zeek::base_type(zeek::TYPE_BOOL)); } IntrusivePtr IsExpr::Fold(Val* v) const @@ -4836,8 +4836,8 @@ void IsExpr::ExprDescribe(ODesc* d) const IntrusivePtr get_assign_expr(IntrusivePtr op1, IntrusivePtr op2, bool is_init) { - if ( op1->GetType()->Tag() == TYPE_RECORD && - op2->GetType()->Tag() == TYPE_LIST ) + if ( op1->GetType()->Tag() == zeek::TYPE_RECORD && + op2->GetType()->Tag() == zeek::TYPE_LIST ) return make_intrusive(std::move(op1), std::move(op2), is_init); @@ -4856,7 +4856,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) TypeTag e_tag = et->Tag(); TypeTag t_tag = t->Tag(); - if ( t->Tag() == TYPE_ANY ) + if ( t->Tag() == zeek::TYPE_ANY ) return {NewRef{}, e}; if ( EitherArithmetic(t_tag, e_tag) ) @@ -4880,7 +4880,7 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) return make_intrusive(IntrusivePtr{NewRef{}, e}, t_tag); } - if ( t->Tag() == TYPE_RECORD && et->Tag() == TYPE_RECORD ) + if ( t->Tag() == zeek::TYPE_RECORD && et->Tag() == zeek::TYPE_RECORD ) { RecordType* t_r = t->AsRecordType(); RecordType* et_r = et->AsRecordType(); @@ -4910,12 +4910,12 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) if ( ! same_type(t, et) ) { - if ( t->Tag() == TYPE_TABLE && et->Tag() == TYPE_TABLE && + if ( t->Tag() == zeek::TYPE_TABLE && et->Tag() == zeek::TYPE_TABLE && et->AsTableType()->IsUnspecifiedTable() ) return make_intrusive(IntrusivePtr{NewRef{}, e}, IntrusivePtr{NewRef{}, t->AsTableType()}); - if ( t->Tag() == TYPE_VECTOR && et->Tag() == TYPE_VECTOR && + if ( t->Tag() == zeek::TYPE_VECTOR && et->Tag() == zeek::TYPE_VECTOR && et->AsVectorType()->IsUnspecifiedVector() ) return make_intrusive(IntrusivePtr{NewRef{}, e}, IntrusivePtr{NewRef{}, t->AsVectorType()}); @@ -4932,7 +4932,7 @@ bool check_and_promote_exprs(ListExpr* const elements, TypeList* types) expr_list& el = elements->Exprs(); const auto& tl = types->Types(); - if ( tl.size() == 1 && tl[0]->Tag() == TYPE_ANY ) + if ( tl.size() == 1 && tl[0]->Tag() == zeek::TYPE_ANY ) return true; if ( el.length() != static_cast(tl.size()) ) @@ -4968,7 +4968,7 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) int ntypes = types->NumFields(); // give variadic BIFs automatic pass - if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == TYPE_ANY ) + if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == zeek::TYPE_ANY ) return true; if ( el.length() < ntypes ) @@ -5010,7 +5010,7 @@ bool check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) { expr_list& el = elements->Exprs(); - if ( type->Tag() == TYPE_ANY ) + if ( type->Tag() == zeek::TYPE_ANY ) return true; loop_over_list(el, i) diff --git a/src/Expr.h b/src/Expr.h index 34ddfbab28..122fe52844 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -704,7 +704,7 @@ protected: class ArithCoerceExpr final : public UnaryExpr { public: - ArithCoerceExpr(IntrusivePtr op, TypeTag t); + ArithCoerceExpr(IntrusivePtr op, zeek::TypeTag t); protected: IntrusivePtr FoldSingleVal(Val* v, InternalTypeTag t) const; diff --git a/src/File.cc b/src/File.cc index c27cd16773..f5c25b9b96 100644 --- a/src/File.cc +++ b/src/File.cc @@ -58,7 +58,7 @@ BroFile::BroFile(FILE* arg_f) Init(); f = arg_f; name = access = nullptr; - t = base_type(TYPE_STRING); + t = zeek::base_type(zeek::TYPE_STRING); is_open = (f != nullptr); } @@ -68,7 +68,7 @@ BroFile::BroFile(FILE* arg_f, const char* arg_name, const char* arg_access) f = arg_f; name = copy_string(arg_name); access = copy_string(arg_access); - t = base_type(TYPE_STRING); + t = zeek::base_type(zeek::TYPE_STRING); is_open = (f != nullptr); } @@ -78,7 +78,7 @@ BroFile::BroFile(const char* arg_name, const char* arg_access) f = nullptr; name = copy_string(arg_name); access = copy_string(arg_access); - t = base_type(TYPE_STRING); + t = zeek::base_type(zeek::TYPE_STRING); if ( streq(name, "/dev/stdin") ) f = stdin; @@ -278,7 +278,7 @@ RecordVal* BroFile::Rotate() if ( f == stdin || f == stdout || f == stderr ) return nullptr; - static auto rotate_info = zeek::id::find_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); RecordVal* info = new RecordVal(rotate_info); FILE* newf = rotate_file(name, info); diff --git a/src/File.h b/src/File.h index 09093b85c8..287b140972 100644 --- a/src/File.h +++ b/src/File.h @@ -16,9 +16,9 @@ #include "IntrusivePtr.h" #include "util.h" -class BroType; class RecordVal; +FORWARD_DECLARE_NAMESPACED(BroType, zeek); FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); @@ -41,9 +41,9 @@ public: void SetBuf(bool buffered); // false=line buffered, true=fully buffered [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* FType() const { return t.get(); } + zeek::BroType* FType() const { return t.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return t; } // Whether the file is open in a general sense; it might @@ -104,7 +104,7 @@ protected: void RaiseOpenEvent(); FILE* f; - IntrusivePtr t; + IntrusivePtr t; char* name; char* access; zeek::detail::Attributes* attrs; diff --git a/src/Frame.cc b/src/Frame.cc index 76ebbd05ff..7ab9aa2c16 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -175,7 +175,7 @@ Frame* Frame::Clone() const static bool val_is_func(const IntrusivePtr& v, BroFunc* func) { - if ( v->GetType()->Tag() != TYPE_FUNC ) + if ( v->GetType()->Tag() != zeek::TYPE_FUNC ) return false; return v->AsFunc() == func; @@ -333,7 +333,7 @@ broker::expected Frame::Serialize(const Frame* target, const id_li const auto& val = target->frame[location].val; - TypeTag tag = val->GetType()->Tag(); + zeek::TypeTag tag = val->GetType()->Tag(); auto expected = bro_broker::val_to_data(val.get()); if ( ! expected ) @@ -460,7 +460,7 @@ std::pair> Frame::Unserialize(const broker::vector& da return std::make_pair(false, nullptr); broker::integer g = *has_type; - BroType t( static_cast(g) ); + zeek::BroType t( static_cast(g) ); auto val = bro_broker::data_to_val(std::move(val_tuple[0]), &t); if ( ! val ) diff --git a/src/Func.cc b/src/Func.cc index d0d456ef38..afd008fbaa 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -216,7 +216,7 @@ void Func::CopyStateInto(Func* other) const } void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, - function_flavor flavor) const + zeek::FunctionFlavor flavor) const { // Helper function factoring out this code from BroFunc:Call() for // better readability. @@ -232,32 +232,32 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } switch ( flavor ) { - case FUNC_FLAVOR_EVENT: + case zeek::FUNC_FLAVOR_EVENT: if ( hook_result ) reporter->InternalError("plugin returned non-void result for event %s", this->Name()); break; - case FUNC_FLAVOR_HOOK: - if ( hook_result->GetType()->Tag() != TYPE_BOOL ) + case zeek::FUNC_FLAVOR_HOOK: + if ( hook_result->GetType()->Tag() != zeek::TYPE_BOOL ) reporter->InternalError("plugin returned non-bool for hook %s", this->Name()); break; - case FUNC_FLAVOR_FUNCTION: + case zeek::FUNC_FLAVOR_FUNCTION: { const auto& yt = GetType()->Yield(); - if ( (! yt) || yt->Tag() == TYPE_VOID ) + if ( (! yt) || yt->Tag() == zeek::TYPE_VOID ) { if ( hook_result ) reporter->InternalError("plugin returned non-void result for void method %s", this->Name()); } - else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY ) + else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && yt->Tag() != zeek::TYPE_ANY ) { reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s", hook_result->GetType()->Tag(), yt->Tag(), this->Name()); @@ -274,7 +274,7 @@ BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtrName(); - type = arg_id->GetType(); + type = arg_id->GetType(); frame_size = arg_frame_size; if ( arg_body ) @@ -326,8 +326,8 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const if ( bodies.empty() ) { // Can only happen for events and hooks. - assert(Flavor() == FUNC_FLAVOR_EVENT || Flavor() == FUNC_FLAVOR_HOOK); - return Flavor() == FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr; + assert(Flavor() == zeek::FUNC_FLAVOR_EVENT || Flavor() == zeek::FUNC_FLAVOR_HOOK); + return Flavor() == zeek::FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr; } auto f = make_intrusive(frame_size, this, args); @@ -384,7 +384,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const catch ( InterpreterException& e ) { // Already reported, but now determine whether to unwind further. - if ( Flavor() == FUNC_FLAVOR_FUNCTION ) + if ( Flavor() == zeek::FUNC_FLAVOR_FUNCTION ) { g_frame_stack.pop_back(); call_stack.pop_back(); @@ -404,7 +404,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const break; } - if ( Flavor() == FUNC_FLAVOR_HOOK ) + if ( Flavor() == zeek::FUNC_FLAVOR_HOOK ) { // Ignore any return values of hook bodies, final return value // depends on whether a body returns as a result of break statement. @@ -421,7 +421,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const call_stack.pop_back(); - if ( Flavor() == FUNC_FLAVOR_HOOK ) + if ( Flavor() == zeek::FUNC_FLAVOR_HOOK ) { if ( ! result ) result = val_mgr->True(); @@ -429,7 +429,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const // Warn if the function returns something, but we returned from // the function without an explicit return, or without a value. - else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID && + else if ( GetType()->Yield() && GetType()->Yield()->Tag() != zeek::TYPE_VOID && (flow != FLOW_RETURN /* we fell off the end */ || ! result /* explicit return with no result */) && ! f->HasDelayed() ) @@ -463,7 +463,7 @@ void BroFunc::AddBody(IntrusivePtr new_body, new_body = AddInits(std::move(new_body), new_inits); - if ( Flavor() == FUNC_FLAVOR_FUNCTION ) + if ( Flavor() == zeek::FUNC_FLAVOR_FUNCTION ) { // For functions, we replace the old body with the new one. assert(bodies.size() <= 1); @@ -601,7 +601,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, if ( id->HasVal() ) reporter->InternalError("built-in function %s multiply defined", Name()); - type = id->GetType(); + type = id->GetType(); id->SetVal(make_intrusive(IntrusivePtr{NewRef{}, this})); } @@ -628,7 +628,7 @@ IntrusivePtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const HookCallFunction(this, parent, args), empty_hook_result); - CheckPluginResult(handled, hook_result, FUNC_FLAVOR_FUNCTION); + CheckPluginResult(handled, hook_result, zeek::FUNC_FLAVOR_FUNCTION); if ( handled ) return hook_result; @@ -758,19 +758,19 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = zeek::id::find_type("ProcStats"); - NetStats = zeek::id::find_type("NetStats"); - MatcherStats = zeek::id::find_type("MatcherStats"); - ConnStats = zeek::id::find_type("ConnStats"); - ReassemblerStats = zeek::id::find_type("ReassemblerStats"); - DNSStats = zeek::id::find_type("DNSStats"); - GapStats = zeek::id::find_type("GapStats"); - EventStats = zeek::id::find_type("EventStats"); - TimerStats = zeek::id::find_type("TimerStats"); - FileAnalysisStats = zeek::id::find_type("FileAnalysisStats"); - ThreadStats = zeek::id::find_type("ThreadStats"); - BrokerStats = zeek::id::find_type("BrokerStats"); - ReporterStats = zeek::id::find_type("ReporterStats"); + ProcStats = zeek::id::find_type("ProcStats"); + NetStats = zeek::id::find_type("NetStats"); + MatcherStats = zeek::id::find_type("MatcherStats"); + ConnStats = zeek::id::find_type("ConnStats"); + ReassemblerStats = zeek::id::find_type("ReassemblerStats"); + DNSStats = zeek::id::find_type("DNSStats"); + GapStats = zeek::id::find_type("GapStats"); + EventStats = zeek::id::find_type("EventStats"); + TimerStats = zeek::id::find_type("TimerStats"); + FileAnalysisStats = zeek::id::find_type("FileAnalysisStats"); + ThreadStats = zeek::id::find_type("ThreadStats"); + BrokerStats = zeek::id::find_type("BrokerStats"); + ReporterStats = zeek::id::find_type("ReporterStats"); var_sizes = zeek::id::find_type("var_sizes")->AsTableType(); @@ -803,7 +803,7 @@ bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call) } const zeek::detail::Expr* fmt_str_arg = args[0]; - if ( fmt_str_arg->GetType()->Tag() != TYPE_STRING ) + if ( fmt_str_arg->GetType()->Tag() != zeek::TYPE_STRING ) { call->Error("first argument to fmt() needs to be a format string"); return false; @@ -867,7 +867,7 @@ static int get_func_priority(const std::vector> continue; } - if ( ! IsIntegral(v->GetType()->Tag()) ) + if ( ! zeek::IsIntegral(v->GetType()->Tag()) ) { a->Error("expression is not of integral type"); continue; diff --git a/src/Func.h b/src/Func.h index b1b653ddc4..454c595867 100644 --- a/src/Func.h +++ b/src/Func.h @@ -20,13 +20,13 @@ #include "ZeekArgs.h" class Val; -class FuncType; class Frame; class Scope; FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +FORWARD_DECLARE_NAMESPACED(FuncType, zeek); class Func : public BroObj { public: @@ -39,7 +39,7 @@ public: ~Func() override; virtual bool IsPure() const = 0; - function_flavor Flavor() const { return GetType()->Flavor(); } + zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); } struct Body { IntrusivePtr stmts; @@ -86,9 +86,9 @@ public: virtual Scope* GetScope() const { return scope.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] - virtual FuncType* FType() const { return type.get(); } + virtual zeek::FuncType* FType() const { return type.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } Kind GetKind() const { return kind; } @@ -115,13 +115,13 @@ protected: // Helper function for checking result of plugin hook. void CheckPluginResult(bool handled, const IntrusivePtr& hook_result, - function_flavor flavor) const; + zeek::FunctionFlavor flavor) const; std::vector bodies; IntrusivePtr scope; Kind kind; uint32_t unique_id; - IntrusivePtr type; + IntrusivePtr type; std::string name; static inline std::vector> unique_ids; }; diff --git a/src/ID.cc b/src/ID.cc index a35118a562..205a5fd749 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -19,24 +19,24 @@ #include "zeekygen/ScriptInfo.h" #include "module_util.h" -IntrusivePtr zeek::id::conn_id; -IntrusivePtr zeek::id::endpoint; -IntrusivePtr zeek::id::connection; -IntrusivePtr zeek::id::fa_file; -IntrusivePtr zeek::id::fa_metadata; -IntrusivePtr zeek::id::transport_proto; -IntrusivePtr zeek::id::string_set; -IntrusivePtr zeek::id::string_array; -IntrusivePtr zeek::id::count_set; -IntrusivePtr zeek::id::string_vec; -IntrusivePtr zeek::id::index_vec; +IntrusivePtr zeek::id::conn_id; +IntrusivePtr zeek::id::endpoint; +IntrusivePtr zeek::id::connection; +IntrusivePtr zeek::id::fa_file; +IntrusivePtr zeek::id::fa_metadata; +IntrusivePtr zeek::id::transport_proto; +IntrusivePtr zeek::id::string_set; +IntrusivePtr zeek::id::string_array; +IntrusivePtr zeek::id::count_set; +IntrusivePtr zeek::id::string_vec; +IntrusivePtr zeek::id::index_vec; const IntrusivePtr& zeek::id::find(std::string_view name) { return global_scope()->Find(name); } -const IntrusivePtr& zeek::id::find_type(std::string_view name) +const IntrusivePtr& zeek::id::find_type(std::string_view name) { auto id = global_scope()->Find(name); @@ -89,17 +89,17 @@ IntrusivePtr zeek::id::find_func(std::string_view name) void zeek::id::detail::init() { - conn_id = zeek::id::find_type("conn_id"); - endpoint = zeek::id::find_type("endpoint"); - connection = zeek::id::find_type("connection"); - fa_file = zeek::id::find_type("fa_file"); - fa_metadata = zeek::id::find_type("fa_metadata"); - transport_proto = zeek::id::find_type("transport_proto"); - string_set = zeek::id::find_type("string_set"); - string_array = zeek::id::find_type("string_array"); - count_set = zeek::id::find_type("count_set"); - string_vec = zeek::id::find_type("string_vec"); - index_vec = zeek::id::find_type("index_vec"); + conn_id = zeek::id::find_type("conn_id"); + endpoint = zeek::id::find_type("endpoint"); + connection = zeek::id::find_type("connection"); + fa_file = zeek::id::find_type("fa_file"); + fa_metadata = zeek::id::find_type("fa_metadata"); + transport_proto = zeek::id::find_type("transport_proto"); + string_set = zeek::id::find_type("string_set"); + string_array = zeek::id::find_type("string_array"); + count_set = zeek::id::find_type("count_set"); + string_vec = zeek::id::find_type("string_vec"); + index_vec = zeek::id::find_type("index_vec"); } namespace zeek::detail { @@ -133,7 +133,7 @@ std::string ID::ModuleName() const return extract_module_name(name); } -void ID::SetType(IntrusivePtr t) +void ID::SetType(IntrusivePtr t) { type = std::move(t); } @@ -267,7 +267,7 @@ void ID::UpdateValAttrs() if ( attr ) { // Apply &log to all record fields. - RecordType* rt = GetType()->AsRecordType(); + zeek::RecordType* rt = GetType()->AsRecordType(); for ( int i = 0; i < rt->NumFields(); ++i ) { TypeDecl* fd = rt->FieldDecl(i); diff --git a/src/ID.h b/src/ID.h index ff34218b54..ceeec0af2a 100644 --- a/src/ID.h +++ b/src/ID.h @@ -15,11 +15,12 @@ class Val; class Func; -class BroType; -class RecordType; -class TableType; -class VectorType; -class EnumType; + +FORWARD_DECLARE_NAMESPACED(BroType, zeek); +FORWARD_DECLARE_NAMESPACED(RecordType, zeek); +FORWARD_DECLARE_NAMESPACED(TableType, zeek); +FORWARD_DECLARE_NAMESPACED(VectorType, zeek); +FORWARD_DECLARE_NAMESPACED(EnumType, zeek); enum [[deprecated("Remove in v4.1. Use zeek::detail::init_class instead.")]] init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; enum [[deprecated("Remove in v4.1. Use zeek::detail::IDScope instead.")]] IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; @@ -201,7 +202,7 @@ const IntrusivePtr& find(std::string_view name); * @param name The identifier name to lookup * @return The type of the identifier. */ -const IntrusivePtr& find_type(std::string_view name); +const IntrusivePtr& find_type(std::string_view name); /** * Lookup an ID by its name and return its type (as cast to @c T). @@ -257,17 +258,17 @@ IntrusivePtr find_const(std::string_view name) */ IntrusivePtr find_func(std::string_view name); -extern IntrusivePtr conn_id; -extern IntrusivePtr endpoint; -extern IntrusivePtr connection; -extern IntrusivePtr fa_file; -extern IntrusivePtr fa_metadata; -extern IntrusivePtr transport_proto; -extern IntrusivePtr string_set; -extern IntrusivePtr string_array; -extern IntrusivePtr count_set; -extern IntrusivePtr string_vec; -extern IntrusivePtr index_vec; +extern IntrusivePtr conn_id; +extern IntrusivePtr endpoint; +extern IntrusivePtr connection; +extern IntrusivePtr fa_file; +extern IntrusivePtr fa_metadata; +extern IntrusivePtr transport_proto; +extern IntrusivePtr string_set; +extern IntrusivePtr string_array; +extern IntrusivePtr count_set; +extern IntrusivePtr string_vec; +extern IntrusivePtr index_vec; namespace detail { diff --git a/src/IP.cc b/src/IP.cc index 28109b185a..098ba3f468 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -15,11 +15,11 @@ static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(zeek::id::find_type("ip6_options")); + auto vv = make_intrusive(zeek::id::find_type("ip6_options")); while ( len > 0 ) { - static auto ip6_option_type = zeek::id::find_type("ip6_option"); + static auto ip6_option_type = zeek::id::find_type("ip6_option"); const struct ip6_opt* opt = (const struct ip6_opt*) data; auto rv = make_intrusive(ip6_option_type); rv->Assign(0, val_mgr->Count(opt->ip6o_type)); @@ -56,7 +56,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const switch ( type ) { case IPPROTO_IPV6: { - static auto ip6_hdr_type = zeek::id::find_type("ip6_hdr"); + static auto ip6_hdr_type = zeek::id::find_type("ip6_hdr"); rv = make_intrusive(ip6_hdr_type); const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20)); @@ -68,14 +68,14 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - zeek::id::find_type("ip6_ext_hdr_chain")); + zeek::id::find_type("ip6_ext_hdr_chain")); rv->Assign(7, std::move(chain)); } break; case IPPROTO_HOPOPTS: { - static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); + static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); rv = make_intrusive(ip6_hopopts_type); const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt)); @@ -88,7 +88,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_DSTOPTS: { - static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); + static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); rv = make_intrusive(ip6_dstopts_type); const struct ip6_dest* dst = (const struct ip6_dest*)data; rv->Assign(0, val_mgr->Count(dst->ip6d_nxt)); @@ -100,7 +100,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_ROUTING: { - static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); + static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); rv = make_intrusive(ip6_routing_type); const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; rv->Assign(0, val_mgr->Count(rt->ip6r_nxt)); @@ -114,7 +114,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_FRAGMENT: { - static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); + static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); rv = make_intrusive(ip6_fragment_type); const struct ip6_frag* frag = (const struct ip6_frag*)data; rv->Assign(0, val_mgr->Count(frag->ip6f_nxt)); @@ -128,7 +128,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_AH: { - static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); + static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); rv = make_intrusive(ip6_ah_type); rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt)); rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len)); @@ -148,7 +148,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const case IPPROTO_ESP: { - static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); + static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); rv = make_intrusive(ip6_esp_type); const uint32_t* esp = (const uint32_t*)data; rv->Assign(0, val_mgr->Count(ntohl(esp[0]))); @@ -159,7 +159,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const #ifdef ENABLE_MOBILE_IPV6 case IPPROTO_MOBILITY: { - static auto ip6_mob_type = zeek::id::find_type("ip6_mobility_hdr"); + static auto ip6_mob_type = zeek::id::find_type("ip6_mobility_hdr"); rv = make_intrusive(ip6_mob_type); const struct ip6_mobility* mob = (const struct ip6_mobility*) data; rv->Assign(0, val_mgr->Count(mob->ip6mob_payload)); @@ -168,21 +168,21 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(3, val_mgr->Count(mob->ip6mob_rsv)); rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum))); - static auto ip6_mob_msg_type = zeek::id::find_type("ip6_mobility_msg"); + static auto ip6_mob_msg_type = zeek::id::find_type("ip6_mobility_msg"); auto msg = make_intrusive(ip6_mob_msg_type); msg->Assign(0, val_mgr->Count(mob->ip6mob_type)); uint16_t off = sizeof(ip6_mobility); const u_char* msg_data = data + off; - static auto ip6_mob_brr_type = zeek::id::find_type("ip6_mobility_brr"); - static auto ip6_mob_hoti_type = zeek::id::find_type("ip6_mobility_hoti"); - static auto ip6_mob_coti_type = zeek::id::find_type("ip6_mobility_coti"); - static auto ip6_mob_hot_type = zeek::id::find_type("ip6_mobility_hot"); - static auto ip6_mob_cot_type = zeek::id::find_type("ip6_mobility_cot"); - static auto ip6_mob_bu_type = zeek::id::find_type("ip6_mobility_bu"); - static auto ip6_mob_back_type = zeek::id::find_type("ip6_mobility_back"); - static auto ip6_mob_be_type = zeek::id::find_type("ip6_mobility_be"); + static auto ip6_mob_brr_type = zeek::id::find_type("ip6_mobility_brr"); + static auto ip6_mob_hoti_type = zeek::id::find_type("ip6_mobility_hoti"); + static auto ip6_mob_coti_type = zeek::id::find_type("ip6_mobility_coti"); + static auto ip6_mob_hot_type = zeek::id::find_type("ip6_mobility_hot"); + static auto ip6_mob_cot_type = zeek::id::find_type("ip6_mobility_cot"); + static auto ip6_mob_bu_type = zeek::id::find_type("ip6_mobility_bu"); + static auto ip6_mob_back_type = zeek::id::find_type("ip6_mobility_back"); + static auto ip6_mob_be_type = zeek::id::find_type("ip6_mobility_be"); switch ( mob->ip6mob_type ) { case 0: @@ -332,7 +332,7 @@ IntrusivePtr IP_Hdr::ToIPHdrVal() const if ( ip4 ) { - static auto ip4_hdr_type = zeek::id::find_type("ip4_hdr"); + static auto ip4_hdr_type = zeek::id::find_type("ip4_hdr"); rval = make_intrusive(ip4_hdr_type); rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4)); rval->Assign(1, val_mgr->Count(ip4->ip_tos)); @@ -358,7 +358,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const IntrusivePtr IP_Hdr::ToPktHdrVal() const { - static auto pkt_hdr_type = zeek::id::find_type("pkt_hdr"); + static auto pkt_hdr_type = zeek::id::find_type("pkt_hdr"); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -369,9 +369,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int sindex) const { - static auto tcp_hdr_type = zeek::id::find_type("tcp_hdr"); - static auto udp_hdr_type = zeek::id::find_type("udp_hdr"); - static auto icmp_hdr_type = zeek::id::find_type("icmp_hdr"); + static auto tcp_hdr_type = zeek::id::find_type("tcp_hdr"); + static auto udp_hdr_type = zeek::id::find_type("udp_hdr"); + static auto icmp_hdr_type = zeek::id::find_type("icmp_hdr"); if ( ip4 ) pkt_hdr->Assign(sindex + 0, ToIPHdrVal()); @@ -678,14 +678,14 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) IntrusivePtr IPv6_Hdr_Chain::ToVal() const { - static auto ip6_ext_hdr_type = zeek::id::find_type("ip6_ext_hdr"); - static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); - static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); - static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); - static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); - static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); - static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); - static auto ip6_ext_hdr_chain_type = zeek::id::find_type("ip6_ext_hdr_chain"); + static auto ip6_ext_hdr_type = zeek::id::find_type("ip6_ext_hdr"); + static auto ip6_hopopts_type = zeek::id::find_type("ip6_hopopts"); + static auto ip6_dstopts_type = zeek::id::find_type("ip6_dstopts"); + static auto ip6_routing_type = zeek::id::find_type("ip6_routing"); + static auto ip6_fragment_type = zeek::id::find_type("ip6_fragment"); + static auto ip6_ah_type = zeek::id::find_type("ip6_ah"); + static auto ip6_esp_type = zeek::id::find_type("ip6_esp"); + static auto ip6_ext_hdr_chain_type = zeek::id::find_type("ip6_ext_hdr_chain"); auto rval = make_intrusive(ip6_ext_hdr_chain_type); for ( size_t i = 1; i < chain.size(); ++i ) diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 351d00fa19..868a2aaade 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -37,10 +37,10 @@ OpaqueMgr* OpaqueMgr::mgr() return &mgr; } -OpaqueVal::OpaqueVal(OpaqueType* t) : OpaqueVal({NewRef{}, t}) +OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({NewRef{}, t}) {} -OpaqueVal::OpaqueVal(IntrusivePtr t) : Val(std::move(t)) +OpaqueVal::OpaqueVal(IntrusivePtr t) : Val(std::move(t)) {} OpaqueVal::~OpaqueVal() @@ -96,12 +96,12 @@ IntrusivePtr OpaqueVal::Unserialize(const broker::data& data) return val; } -broker::expected OpaqueVal::SerializeType(const IntrusivePtr& t) +broker::expected OpaqueVal::SerializeType(const IntrusivePtr& t) { - if ( t->InternalType() == TYPE_INTERNAL_ERROR ) + if ( t->InternalType() == zeek::TYPE_INTERNAL_ERROR ) return broker::ec::invalid_data; - if ( t->InternalType() == TYPE_INTERNAL_OTHER ) + if ( t->InternalType() == zeek::TYPE_INTERNAL_OTHER ) { // Serialize by name. assert(t->GetName().size()); @@ -112,7 +112,7 @@ broker::expected OpaqueVal::SerializeType(const IntrusivePtr(t->Tag())}}; } -IntrusivePtr OpaqueVal::UnserializeType(const broker::data& data) +IntrusivePtr OpaqueVal::UnserializeType(const broker::data& data) { auto v = caf::get_if(&data); if ( ! (v && v->size() == 2) ) @@ -142,7 +142,7 @@ IntrusivePtr OpaqueVal::UnserializeType(const broker::data& data) if ( ! tag ) return nullptr; - return base_type(static_cast(*tag)); + return zeek::base_type(static_cast(*tag)); } IntrusivePtr OpaqueVal::DoClone(CloneState* state) @@ -206,12 +206,12 @@ IntrusivePtr HashVal::DoGet() return val_mgr->EmptyString(); } -HashVal::HashVal(IntrusivePtr t) : OpaqueVal(std::move(t)) +HashVal::HashVal(IntrusivePtr t) : OpaqueVal(std::move(t)) { valid = false; } -HashVal::HashVal(OpaqueType* t) : HashVal({NewRef{}, t}) +HashVal::HashVal(zeek::OpaqueType* t) : HashVal({NewRef{}, t}) {} MD5Val::MD5Val() : HashVal(md5_type) @@ -226,7 +226,7 @@ MD5Val::~MD5Val() void HashVal::digest_one(EVP_MD_CTX* h, const Val* v) { - if ( v->GetType()->Tag() == TYPE_STRING ) + if ( v->GetType()->Tag() == zeek::TYPE_STRING ) { const BroString* str = v->AsString(); hash_update(h, str->Bytes(), str->Len()); @@ -723,14 +723,14 @@ IntrusivePtr BloomFilterVal::DoClone(CloneState* state) return state->NewClone(this, make_intrusive()); } -bool BloomFilterVal::Typify(IntrusivePtr arg_type) +bool BloomFilterVal::Typify(IntrusivePtr arg_type) { if ( type ) return false; type = std::move(arg_type); - auto tl = make_intrusive(type); + auto tl = make_intrusive(type); tl->Append(type); hash = new CompositeHash(std::move(tl)); @@ -882,14 +882,14 @@ IntrusivePtr CardinalityVal::DoClone(CloneState* state) make_intrusive(new probabilistic::CardinalityCounter(*c))); } -bool CardinalityVal::Typify(IntrusivePtr arg_type) +bool CardinalityVal::Typify(IntrusivePtr arg_type) { if ( type ) return false; type = std::move(arg_type); - auto tl = make_intrusive(type); + auto tl = make_intrusive(type); tl->Append(type); hash = new CompositeHash(std::move(tl)); diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 50a4e74ce9..65db196d50 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -88,8 +88,8 @@ private: class OpaqueVal : public Val { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - explicit OpaqueVal(OpaqueType* t); - explicit OpaqueVal(IntrusivePtr t); + explicit OpaqueVal(zeek::OpaqueType* t); + explicit OpaqueVal(IntrusivePtr t); ~OpaqueVal() override; /** @@ -148,13 +148,13 @@ protected: * Helper function for derived class that need to record a type * during serialization. */ - static broker::expected SerializeType(const IntrusivePtr& t); + static broker::expected SerializeType(const IntrusivePtr& t); /** * Helper function for derived class that need to restore a type * during unserialization. Returns the type at reference count +1. */ - static IntrusivePtr UnserializeType(const broker::data& data); + static IntrusivePtr UnserializeType(const broker::data& data); }; namespace probabilistic { @@ -187,8 +187,8 @@ protected: HashVal() { valid = false; } [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - explicit HashVal(OpaqueType* t); - explicit HashVal(IntrusivePtr t); + explicit HashVal(zeek::OpaqueType* t); + explicit HashVal(IntrusivePtr t); virtual bool DoInit(); virtual bool DoFeed(const void* data, size_t size); @@ -304,10 +304,10 @@ public: IntrusivePtr DoClone(CloneState* state) override; - const IntrusivePtr& Type() const + const IntrusivePtr& Type() const { return type; } - bool Typify(IntrusivePtr type); + bool Typify(IntrusivePtr type); void Add(const Val* val); size_t Count(const Val* val) const; @@ -328,7 +328,7 @@ private: BloomFilterVal(const BloomFilterVal&); BloomFilterVal& operator=(const BloomFilterVal&); - IntrusivePtr type; + IntrusivePtr type; CompositeHash* hash; probabilistic::BloomFilter* bloom_filter; }; @@ -343,10 +343,10 @@ public: void Add(const Val* val); - const IntrusivePtr& Type() const + const IntrusivePtr& Type() const { return type; } - bool Typify(IntrusivePtr type); + bool Typify(IntrusivePtr type); probabilistic::CardinalityCounter* Get() { return c; }; @@ -355,7 +355,7 @@ protected: DECLARE_OPAQUE_VALUE(CardinalityVal) private: - IntrusivePtr type; + IntrusivePtr type; CompositeHash* hash; probabilistic::CardinalityCounter* c; }; diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index b0d50b0619..2ee59a2bf0 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -43,16 +43,16 @@ void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) void* PrefixTable::Insert(const Val* value, void* data) { // [elem] -> elem - if ( value->GetType()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == zeek::TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); switch ( value->GetType()->Tag() ) { - case TYPE_ADDR: + case zeek::TYPE_ADDR: return Insert(value->AsAddr(), 128, data); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: return Insert(value->AsSubNet().Prefix(), value->AsSubNet().LengthIPv6(), data); break; @@ -103,16 +103,16 @@ void* PrefixTable::Lookup(const IPAddr& addr, int width, bool exact) const void* PrefixTable::Lookup(const Val* value, bool exact) const { // [elem] -> elem - if ( value->GetType()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == zeek::TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); switch ( value->GetType()->Tag() ) { - case TYPE_ADDR: + case zeek::TYPE_ADDR: return Lookup(value->AsAddr(), 128, exact); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: return Lookup(value->AsSubNet().Prefix(), value->AsSubNet().LengthIPv6(), exact); break; @@ -142,16 +142,16 @@ void* PrefixTable::Remove(const IPAddr& addr, int width) void* PrefixTable::Remove(const Val* value) { // [elem] -> elem - if ( value->GetType()->Tag() == TYPE_LIST && + if ( value->GetType()->Tag() == zeek::TYPE_LIST && value->AsListVal()->Length() == 1 ) value = value->AsListVal()->Idx(0).get(); switch ( value->GetType()->Tag() ) { - case TYPE_ADDR: + case zeek::TYPE_ADDR: return Remove(value->AsAddr(), 128); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: return Remove(value->AsSubNet().Prefix(), value->AsSubNet().LengthIPv6()); break; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 732c74b4ac..8277e7952d 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -136,18 +136,18 @@ RuleConditionEval::RuleConditionEval(const char* func) return; } - if ( id->GetType()->Tag() == TYPE_FUNC ) + if ( id->GetType()->Tag() == zeek::TYPE_FUNC ) { // Validate argument quantity and type. - FuncType* f = id->GetType()->AsFuncType(); + zeek::FuncType* f = id->GetType()->AsFuncType(); - if ( f->Yield()->Tag() != TYPE_BOOL ) + if ( f->Yield()->Tag() != zeek::TYPE_BOOL ) rules_error("eval function type must yield a 'bool'", func); - static auto signature_state = zeek::id::find_type("signature_state"); - TypeList tl; + static auto signature_state = zeek::id::find_type("signature_state"); + zeek::TypeList tl; tl.Append(signature_state); - tl.Append(base_type(TYPE_STRING)); + tl.Append(zeek::base_type(zeek::TYPE_STRING)); if ( ! f->CheckArgs(tl.Types()) ) rules_error("eval function parameters must be a 'signature_state' " @@ -164,7 +164,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state, return false; } - if ( id->GetType()->Tag() != TYPE_FUNC ) + if ( id->GetType()->Tag() != zeek::TYPE_FUNC ) return id->GetVal()->AsBool(); // Call function with a signature_state value as argument. diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index 8b0b279e95..3a314fde1f 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -81,7 +81,7 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector arg_v) Val* RuleMatcher::BuildRuleStateValue(const Rule* rule, const RuleEndpointState* state) const { - static auto signature_state = zeek::id::find_type("signature_state"); + static auto signature_state = zeek::id::find_type("signature_state"); RecordVal* val = new RecordVal(signature_state); val->Assign(0, make_intrusive(rule->ID())); val->Assign(1, state->GetAnalyzer()->ConnVal()); @@ -1294,20 +1294,20 @@ static bool val_to_maskedval(Val* v, maskedvalue_list* append_to, MaskedValue* mval = new MaskedValue; switch ( v->GetType()->Tag() ) { - case TYPE_PORT: + case zeek::TYPE_PORT: mval->val = v->AsPortVal()->Port(); mval->mask = 0xffffffff; break; - case TYPE_BOOL: - case TYPE_COUNT: - case TYPE_ENUM: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_COUNT: + case zeek::TYPE_ENUM: + case zeek::TYPE_INT: mval->val = v->CoerceToUnsigned(); mval->mask = 0xffffffff; break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { if ( prefix_vector ) { @@ -1362,7 +1362,7 @@ void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, if ( ! v ) return; - if ( v->GetType()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == zeek::TYPE_TABLE ) { auto lv = v->AsTableVal()->ToPureListVal(); @@ -1384,7 +1384,7 @@ char* id_to_str(const char* id) if ( ! v ) goto error; - if ( v->GetType()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != zeek::TYPE_STRING ) { rules_error("Identifier must refer to string"); goto error; @@ -1407,10 +1407,10 @@ uint32_t id_to_uint(const char* id) if ( ! v ) return 0; - TypeTag t = v->GetType()->Tag(); + zeek::TypeTag t = v->GetType()->Tag(); - if ( t == TYPE_BOOL || t == TYPE_COUNT || t == TYPE_ENUM || - t == TYPE_INT || t == TYPE_PORT ) + if ( t == zeek::TYPE_BOOL || t == zeek::TYPE_COUNT || t == zeek::TYPE_ENUM || + t == zeek::TYPE_INT || t == zeek::TYPE_PORT ) return v->CoerceToUnsigned(); rules_error("Identifier must refer to integer"); diff --git a/src/Scope.cc b/src/Scope.cc index 6872039fc8..fe0695d014 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -25,12 +25,12 @@ Scope::Scope(IntrusivePtr id, { const auto& id_type = scope_id->GetType(); - if ( id_type->Tag() == TYPE_ERROR ) + if ( id_type->Tag() == zeek::TYPE_ERROR ) return; - else if ( id_type->Tag() != TYPE_FUNC ) + else if ( id_type->Tag() != zeek::TYPE_FUNC ) reporter->InternalError("bad scope id"); - FuncType* ft = id->GetType()->AsFuncType(); + zeek::FuncType* ft = id->GetType()->AsFuncType(); return_type = ft->Yield(); } } diff --git a/src/Scope.h b/src/Scope.h index 6596f5ea64..e73765cff7 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -13,9 +13,9 @@ #include "TraverseTypes.h" template class IntrusivePtr; -class BroType; class ListVal; +FORWARD_DECLARE_NAMESPACED(BroType, zeek); FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); class Scope : public BroObj { @@ -45,9 +45,9 @@ public: { return attrs; } [[deprecated("Remove in v4.1. Use GetReturnTrype().")]] - BroType* ReturnType() const { return return_type.get(); } + zeek::BroType* ReturnType() const { return return_type.get(); } - const IntrusivePtr& GetReturnType() const + const IntrusivePtr& GetReturnType() const { return return_type; } size_t Length() const { return local.size(); } @@ -70,7 +70,7 @@ public: protected: IntrusivePtr scope_id; std::unique_ptr>> attrs; - IntrusivePtr return_type; + IntrusivePtr return_type; std::map, std::less<>> local; std::vector> inits; }; diff --git a/src/Sessions.cc b/src/Sessions.cc index 101fc2100e..59da355f6e 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -906,10 +906,10 @@ FragReassembler* NetSessions::NextFragment(double t, const IP_Hdr* ip, Connection* NetSessions::FindConnection(Val* v) { const auto& vt = v->GetType(); - if ( ! IsRecord(vt->Tag()) ) + if ( ! zeek::IsRecord(vt->Tag()) ) return nullptr; - RecordType* vr = vt->AsRecordType(); + zeek::RecordType* vr = vt->AsRecordType(); auto vl = v->AsRecord(); int orig_h, orig_p; // indices into record's value list diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index bfbad2284b..f77f790055 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -58,10 +58,10 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { - static auto sw_substring_type = zeek::id::find_type("sw_substring"); - static auto sw_align_type = zeek::id::find_type("sw_align"); - static auto sw_align_vec_type = zeek::id::find_type("sw_align_vec"); - static auto sw_substring_vec_type = zeek::id::find_type("sw_substring_vec"); + static auto sw_substring_type = zeek::id::find_type("sw_substring"); + static auto sw_align_type = zeek::id::find_type("sw_align"); + static auto sw_align_vec_type = zeek::id::find_type("sw_align_vec"); + static auto sw_substring_vec_type = zeek::id::find_type("sw_substring_vec"); auto result = make_intrusive(sw_substring_vec_type); @@ -537,7 +537,7 @@ BroSubstring::Vec* smith_waterman(const BroString* s1, const BroString* s2, current->swn_prev ? current->swn_prev->id : 0, string1[i-1], string2[j-1]); #endif - //printf("%.5i ", current->swn_score); + //printf("%.5i ", current->swn_score); } #if 0 diff --git a/src/Stats.cc b/src/Stats.cc index e07853d74d..50f24dae5a 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -270,7 +270,7 @@ void ProfileLogger::Log() if ( size > 100 * 1024 ) print = true; - if ( v->GetType()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == zeek::TYPE_TABLE ) { entries = v->AsTable()->Length(); total_table_entries += entries; @@ -339,7 +339,7 @@ void ProfileLogger::SegmentProfile(const char* name, const Location* loc, SampleLogger::SampleLogger() { - static TableType* load_sample_info = nullptr; + static zeek::TableType* load_sample_info = nullptr; if ( ! load_sample_info ) load_sample_info = zeek::id::find_type("load_sample_info")->AsTableType(); diff --git a/src/Tag.cc b/src/Tag.cc index a964760fcb..cd2a93b7fb 100644 --- a/src/Tag.cc +++ b/src/Tag.cc @@ -4,7 +4,7 @@ #include "Val.h" #include "IntrusivePtr.h" -Tag::Tag(const IntrusivePtr& etype, type_t arg_type, subtype_t arg_subtype) +Tag::Tag(const IntrusivePtr& etype, type_t arg_type, subtype_t arg_subtype) { assert(arg_type > 0); @@ -14,7 +14,7 @@ Tag::Tag(const IntrusivePtr& etype, type_t arg_type, subtype_t arg_sub val = etype->GetVal(i); } -Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype) +Tag::Tag(zeek::EnumType* etype, type_t arg_type, subtype_t arg_subtype) : Tag({NewRef{}, etype}, arg_type, arg_subtype) { } @@ -73,7 +73,7 @@ Tag& Tag::operator=(const Tag&& other) noexcept return *this; } -const IntrusivePtr& Tag::AsVal(const IntrusivePtr& etype) const +const IntrusivePtr& Tag::AsVal(const IntrusivePtr& etype) const { if ( ! val ) { @@ -84,7 +84,7 @@ const IntrusivePtr& Tag::AsVal(const IntrusivePtr& etype) con return val; } -EnumVal* Tag::AsEnumVal(EnumType* etype) const +EnumVal* Tag::AsEnumVal(zeek::EnumType* etype) const { return AsVal({NewRef{}, etype}).get(); } diff --git a/src/Tag.h b/src/Tag.h index 68e7f34b80..9d35590e6e 100644 --- a/src/Tag.h +++ b/src/Tag.h @@ -3,14 +3,15 @@ #pragma once #include "zeek-config.h" -#include "IntrusivePtr.h" - -#include #include +#include + +#include "IntrusivePtr.h" +#include "util.h" class EnumVal; -class EnumType; +FORWARD_DECLARE_NAMESPACED(EnumType, zeek); /** * Class to identify an analyzer type. @@ -115,10 +116,10 @@ protected: * * @param etype the script-layer enum type associated with the tag. */ - const IntrusivePtr& AsVal(const IntrusivePtr& etype) const; + const IntrusivePtr& AsVal(const IntrusivePtr& etype) const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] - EnumVal* AsEnumVal(EnumType* etype) const; + EnumVal* AsEnumVal(zeek::EnumType* etype) const; /** * Constructor. @@ -131,10 +132,10 @@ protected: * @param subtype The sub type, which is left to an analyzer for * interpretation. By default it's set to zero. */ - Tag(const IntrusivePtr& etype, type_t type, subtype_t subtype = 0); + Tag(const IntrusivePtr& etype, type_t type, subtype_t subtype = 0); [[deprecated("Remove in v4.1. Construct from IntrusivePtr& instead.")]] - Tag(EnumType* etype, type_t type, subtype_t subtype = 0); + Tag(zeek::EnumType* etype, type_t type, subtype_t subtype = 0); /** * Constructor. diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 3b2a06db49..048fcdddfd 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -3,14 +3,15 @@ #pragma once #include "zeek-config.h" + +#include + #include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" #include "ID.h" #include "UID.h" -#include - class Connection; /** @@ -198,7 +199,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - zeek::id::find_type("EncapsulatingConnVector")); + zeek::id::find_type("EncapsulatingConnVector")); if ( conns ) { diff --git a/src/Type.cc b/src/Type.cc index 8c114c1df0..fa6519a2be 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -22,10 +22,12 @@ using namespace std; +namespace zeek { + BroType::TypeAliasMap BroType::type_aliases; // Note: This function must be thread-safe. -const char* type_name(TypeTag t) +const char* type_name(zeek::TypeTag t) { static constexpr const char* type_names[int(NUM_TYPES)] = { "void", // 0 @@ -62,9 +64,9 @@ const char* type_name(TypeTag t) return type_names[int(t)]; } -BroType::BroType(TypeTag t, bool arg_base_type) +BroType::BroType(zeek::TypeTag t, bool arg_base_type) : tag(t), internal_tag(to_internal_type_tag(tag)), - is_network_order(::is_network_order(t)), + is_network_order(zeek::is_network_order(t)), base_type(arg_base_type) { } @@ -102,7 +104,7 @@ int BroType::MatchesIndex(zeek::detail::ListExpr* const index) const if ( index->Exprs().length() != 1 && index->Exprs().length() != 2 ) return DOES_NOT_MATCH_INDEX; - if ( check_and_promote_exprs_to_type(index, ::base_type(TYPE_INT).get()) ) + if ( check_and_promote_exprs_to_type(index, zeek::base_type(zeek::TYPE_INT).get()) ) return MATCHES_INDEX_SCALAR; } @@ -409,7 +411,7 @@ IntrusivePtr SetType::ShallowClone() SetType::~SetType() = default; FuncType::FuncType(IntrusivePtr arg_args, - IntrusivePtr arg_yield, function_flavor arg_flavor) + IntrusivePtr arg_yield, FunctionFlavor arg_flavor) : BroType(TYPE_FUNC), args(std::move(arg_args)), arg_types(make_intrusive()), yield(std::move(arg_yield)) { @@ -1320,7 +1322,7 @@ const IntrusivePtr& VectorType::Yield() const // return any as that's what other code historically expects for type // comparisions. if ( IsUnspecifiedVector() ) - return ::base_type(TYPE_ANY); + return zeek::base_type(zeek::TYPE_ANY); return yield_type; } @@ -1369,22 +1371,6 @@ void VectorType::DescribeReST(ODesc* d, bool roles_only) const d->Add(fmt(":zeek:type:`%s`", yield_type->GetName().c_str())); } -const IntrusivePtr& base_type(TypeTag tag) - { - static IntrusivePtr base_types[NUM_TYPES]; - - // We could check here that "tag" actually corresponds to a basic type. - if ( ! base_types[tag] ) - { - base_types[tag] = make_intrusive(tag, true); - // Give the base types a pseudo-location for easier identification. - Location l(type_name(tag), 0, 0, 0, 0); - base_types[tag]->SetLocationInfo(&l); - } - - return base_types[tag]; - } - // Returns true if t1 is initialization-compatible with t2 (i.e., if an // initializer with type t1 can be used to initialize a value with type t2), // false otherwise. Assumes that t1's tag is different from t2's. Note @@ -2081,3 +2067,22 @@ bool is_atomic_type(const BroType& t) return false; } } + +const IntrusivePtr& base_type(zeek::TypeTag tag) + { + static IntrusivePtr base_types[NUM_TYPES]; + + // We could check here that "tag" actually corresponds to a basic type. + if ( ! base_types[tag] ) + { + base_types[tag] = make_intrusive(tag, true); + // Give the base types a pseudo-location for easier identification. + Location l(type_name(tag), 0, 0, 0, 0); + base_types[tag]->SetLocationInfo(&l); + } + + return base_types[tag]; + } + + +} // namespace zeek diff --git a/src/Type.h b/src/Type.h index cbc4a7878b..bc35e752b6 100644 --- a/src/Type.h +++ b/src/Type.h @@ -14,8 +14,60 @@ #include #include -// BRO types. +class EnumVal; +class TableVal; +FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail); +FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); + +// BRO types. +enum [[deprecated("Remove in v4.1. Use zeek::TypeTag instead.")]] TypeTag { + TYPE_VOID, // 0 + TYPE_BOOL, // 1 + TYPE_INT, // 2 + TYPE_COUNT, // 3 + TYPE_COUNTER, // 4 + TYPE_DOUBLE, // 5 + TYPE_TIME, // 6 + TYPE_INTERVAL, // 7 + TYPE_STRING, // 8 + TYPE_PATTERN, // 9 + TYPE_ENUM, // 10 + TYPE_TIMER, // 11 + TYPE_PORT, // 12 + TYPE_ADDR, // 13 + TYPE_SUBNET, // 14 + TYPE_ANY, // 15 + TYPE_TABLE, // 16 + TYPE_UNION, // 17 + TYPE_RECORD, // 18 + TYPE_LIST, // 19 + TYPE_FUNC, // 20 + TYPE_FILE, // 21 + TYPE_VECTOR, // 22 + TYPE_OPAQUE, // 23 + TYPE_TYPE, // 24 + TYPE_ERROR // 25 +#define NUM_TYPES (int(TYPE_ERROR) + 1) +}; + +enum [[deprecated("Remove in v4.1. Use zeek::FunctionFlavor instead.")]] function_flavor { + FUNC_FLAVOR_FUNCTION, + FUNC_FLAVOR_EVENT, + FUNC_FLAVOR_HOOK +}; + +enum [[deprecated("Remove in v4.1. Use zeek::InternalTypeTag instead.")]] InternalTypeTag : uint16_t { + TYPE_INTERNAL_VOID, + TYPE_INTERNAL_INT, TYPE_INTERNAL_UNSIGNED, TYPE_INTERNAL_DOUBLE, + TYPE_INTERNAL_STRING, TYPE_INTERNAL_ADDR, TYPE_INTERNAL_SUBNET, + TYPE_INTERNAL_OTHER, TYPE_INTERNAL_ERROR +}; + +namespace zeek { + +// BRO types. enum TypeTag { TYPE_VOID, // 0 TYPE_BOOL, // 1 @@ -46,12 +98,15 @@ enum TypeTag { #define NUM_TYPES (int(TYPE_ERROR) + 1) }; +// Returns the name of the type. +extern const char* type_name(TypeTag t); + constexpr bool is_network_order(TypeTag tag) noexcept { return tag == TYPE_PORT; } -enum function_flavor { +enum FunctionFlavor { FUNC_FLAVOR_FUNCTION, FUNC_FLAVOR_EVENT, FUNC_FLAVOR_HOOK @@ -116,9 +171,6 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept return TYPE_INTERNAL_VOID; } -// Returns the name of the type. -extern const char* type_name(TypeTag t); - class TypeList; class TableType; class SetType; @@ -129,22 +181,20 @@ class EnumType; class VectorType; class TypeType; class OpaqueType; -class EnumVal; -class TableVal; -FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); -FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail); -FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); - -const int DOES_NOT_MATCH_INDEX = 0; -const int MATCHES_INDEX_SCALAR = 1; -const int MATCHES_INDEX_VECTOR = 2; +constexpr int DOES_NOT_MATCH_INDEX = 0; +constexpr int MATCHES_INDEX_SCALAR = 1; +constexpr int MATCHES_INDEX_VECTOR = 2; class BroType : public BroObj { public: static inline const IntrusivePtr nil; - explicit BroType(TypeTag tag, bool base_type = false); + explicit BroType(zeek::TypeTag tag, bool base_type = false); + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + explicit BroType(::TypeTag tag, bool base_type = false) + : BroType(static_cast(tag), base_type) + {} // Performs a shallow clone operation of the Bro type. // This especially means that especially for tables the types @@ -477,7 +527,13 @@ public: }; FuncType(IntrusivePtr args, IntrusivePtr yield, - function_flavor f); + FunctionFlavor f); + + [[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]] + FuncType(IntrusivePtr args, IntrusivePtr yield, ::function_flavor f) + : FuncType(args, yield, static_cast(f)) + {} + IntrusivePtr ShallowClone() override; ~FuncType() override; @@ -492,13 +548,17 @@ public: { return yield; } void SetYieldType(IntrusivePtr arg_yield) { yield = std::move(arg_yield); } - function_flavor Flavor() const { return flavor; } + FunctionFlavor Flavor() const { return flavor; } std::string FlavorString() const; // Used to convert a function type to an event or hook type. - void ClearYieldType(function_flavor arg_flav) + void ClearYieldType(FunctionFlavor arg_flav) { yield = nullptr; flavor = arg_flav; } + [[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]] + void ClearYieldType(::function_flavor arg_flav) + { yield = nullptr; flavor = static_cast(arg_flav); } + int MatchesIndex(zeek::detail::ListExpr* index) const override; bool CheckArgs(const type_list* args, bool is_init = false) const; bool CheckArgs(const std::vector>& args, @@ -536,7 +596,7 @@ protected: IntrusivePtr args; IntrusivePtr arg_types; IntrusivePtr yield; - function_flavor flavor; + FunctionFlavor flavor; std::vector prototypes; }; @@ -583,7 +643,7 @@ public: const char* id = nullptr; }; -typedef PList type_decl_list; +using type_decl_list = PList; class RecordType final : public BroType { public: @@ -806,29 +866,6 @@ protected: IntrusivePtr yield_type; }; -extern IntrusivePtr md5_type; -extern IntrusivePtr sha1_type; -extern IntrusivePtr sha256_type; -extern IntrusivePtr entropy_type; -extern IntrusivePtr cardinality_type; -extern IntrusivePtr topk_type; -extern IntrusivePtr bloomfilter_type; -extern IntrusivePtr x509_opaque_type; -extern IntrusivePtr ocsp_resp_opaque_type; -extern IntrusivePtr paraglob_type; - -// Returns the basic (non-parameterized) type with the given type. -const IntrusivePtr& base_type(TypeTag tag); - -// Returns the basic (non-parameterized) type with the given type. -// The reference count of the type is not increased. -[[deprecated("Remove in v4.1. Use ::base_type() instead")]] -inline BroType* base_type_no_ref(TypeTag tag) - { return base_type(tag).get(); } - -// Returns the basic error type. -inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); } - // True if the two types are equivalent. If is_init is true then the test is // done in the context of an initialization. If match_record_field_names is // true then for record types the field names have to match, too. @@ -887,7 +924,7 @@ inline bool is_atomic_type(const IntrusivePtr& t) // True if the given type tag corresponds to type that can be assigned to. extern bool is_assignable(TypeTag t); inline bool is_assignable(BroType* t) - { return ::is_assignable(t->Tag()); } + { return zeek::is_assignable(t->Tag()); } // True if the given type tag corresponds to an integral type. inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); } @@ -936,3 +973,65 @@ inline bool BothString(TypeTag t1, TypeTag t2) { return (IsString(t1) && IsStrin // True if either tag is the error type. inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); } + +// Returns the basic (non-parameterized) type with the given type. +const IntrusivePtr& base_type(zeek::TypeTag tag); + +// Returns the basic (non-parameterized) type with the given type. +// The reference count of the type is not increased. +[[deprecated("Remove in v4.1. Use ::base_type() instead")]] +inline zeek::BroType* base_type_no_ref(TypeTag tag) + { return base_type(tag).get(); } + +// Returns the basic error type. +inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); } + +} // namespace zeek + +extern IntrusivePtr md5_type; +extern IntrusivePtr sha1_type; +extern IntrusivePtr sha256_type; +extern IntrusivePtr entropy_type; +extern IntrusivePtr cardinality_type; +extern IntrusivePtr topk_type; +extern IntrusivePtr bloomfilter_type; +extern IntrusivePtr x509_opaque_type; +extern IntrusivePtr ocsp_resp_opaque_type; +extern IntrusivePtr paraglob_type; + +using BroType [[deprecated("Remove in v4.1. Use zeek::BroType instead.")]] = zeek::BroType; +using TypeList [[deprecated("Remove in v4.1. Use zeek::TypeList instead.")]] = zeek::TypeList; +using IndexType [[deprecated("Remove in v4.1. Use zeek::IndexType instead.")]] = zeek::IndexType; +using TableType [[deprecated("Remove in v4.1. Use zeek::TableType instead.")]] = zeek::TableType; +using SetType [[deprecated("Remove in v4.1. Use zeek::SetType instead.")]] = zeek::SetType; +using FuncType [[deprecated("Remove in v4.1. Use zeek::FuncType instead.")]] = zeek::FuncType; +using TypeType [[deprecated("Remove in v4.1. Use zeek::TypeType instead.")]] = zeek::TypeType; +using TypeDecl [[deprecated("Remove in v4.1. Use zeek::TypeDecl instead.")]] = zeek::TypeDecl; +using RecordType [[deprecated("Remove in v4.1. Use zeek::RecordType instead.")]] = zeek::RecordType; +using SubNetType [[deprecated("Remove in v4.1. Use zeek::SubNetType instead.")]] = zeek::SubNetType; +using FileType [[deprecated("Remove in v4.1. Use zeek::FileType instead.")]] = zeek::FileType; +using OpaqueType [[deprecated("Remove in v4.1. Use zeek::OpaqueType instead.")]] = zeek::OpaqueType; +using EnumType [[deprecated("Remove in v4.1. Use zeek::EnumType instead.")]] = zeek::EnumType; +using VectorType [[deprecated("Remove in v4.1. Use zeek::VectorType instead.")]] = zeek::VectorType; +using type_decl_list [[deprecated("Remove in v4.1. Use zeek::type_decl_list instead.")]] = zeek::type_decl_list; + +constexpr auto IsIntegral [[deprecated("Remove in v4.1. Use zeek::IsIntegral instead.")]] = zeek::IsIntegral; +constexpr auto IsArithmetic [[deprecated("Remove in v4.1. Use zeek::IsArithmetic instead.")]] = zeek::IsArithmetic; +constexpr auto IsBool [[deprecated("Remove in v4.1. Use zeek::IsBool instead.")]] = zeek::IsBool; +constexpr auto IsInterval [[deprecated("Remove in v4.1. Use zeek::IsInterval instead.")]] = zeek::IsInterval; +constexpr auto IsRecord [[deprecated("Remove in v4.1. Use zeek::IsRecord instead.")]] = zeek::IsRecord; +constexpr auto IsFunc [[deprecated("Remove in v4.1. Use zeek::IsFunc instead.")]] = zeek::IsFunc; +constexpr auto IsVector [[deprecated("Remove in v4.1. Use zeek::IsVector instead.")]] = zeek::IsVector; +constexpr auto IsString [[deprecated("Remove in v4.1. Use zeek::IsString instead.")]] = zeek::IsString; +constexpr auto IsErrorType [[deprecated("Remove in v4.1. Use zeek::IsErrorType instead.")]] = zeek::IsErrorType; +constexpr auto BothIntegral [[deprecated("Remove in v4.1. Use zeek::BothIntegral instead.")]] = zeek::BothIntegral; +constexpr auto BothArithmetic [[deprecated("Remove in v4.1. Use zeek::BothArithmetic instead.")]] = zeek::BothArithmetic; +constexpr auto EitherArithmetic [[deprecated("Remove in v4.1. Use zeek::EitherArithmetic instead.")]] = zeek::EitherArithmetic; +constexpr auto BothBool [[deprecated("Remove in v4.1. Use zeek::BothBool instead.")]] = zeek::BothBool; +constexpr auto BothInterval [[deprecated("Remove in v4.1. Use zeek::BothInterval instead.")]] = zeek::BothInterval; +constexpr auto BothString [[deprecated("Remove in v4.1. Use zeek::BothString instead.")]] = zeek::BothString; +constexpr auto EitherError [[deprecated("Remove in v4.1. Use zeek::EitherError instead.")]] = zeek::EitherError; +constexpr auto base_type [[deprecated("Remove in v4.1. Use zeek::base_type instead.")]] = zeek::base_type; +constexpr auto error_type [[deprecated("Remove in v4.1. Use zeek::error_type instead.")]] = zeek::error_type; +constexpr auto type_name [[deprecated("Remove in v4.1. Use zeek::type_name instead.")]] = zeek::type_name; +constexpr auto is_network_order [[deprecated("Remove in v4.1. Use zeek::is_network_order instead.")]] = zeek::is_network_order; diff --git a/src/Val.cc b/src/Val.cc index 4ed394420d..e0b64945d8 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -49,10 +49,10 @@ Val::Val(IntrusivePtr f) : val(f.release()), type(val.func_val->GetType()) {} -static const IntrusivePtr& GetStringFileType() noexcept +static const IntrusivePtr& GetStringFileType() noexcept { - static IntrusivePtr string_file_type - = make_intrusive(base_type(TYPE_STRING)); + static IntrusivePtr string_file_type + = make_intrusive(zeek::base_type(zeek::TYPE_STRING)); return string_file_type; } @@ -63,18 +63,18 @@ Val::Val(BroFile* f) : Val({AdoptRef{}, f}) Val::Val(IntrusivePtr f) : val(f.release()), type(GetStringFileType()) { - assert(val.file_val->GetType()->Tag() == TYPE_STRING); + assert(val.file_val->GetType()->Tag() == zeek::TYPE_STRING); } Val::~Val() { - if ( type->InternalType() == TYPE_INTERNAL_STRING ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_STRING ) delete val.string_val; - else if ( type->Tag() == TYPE_FUNC ) + else if ( type->Tag() == zeek::TYPE_FUNC ) Unref(val.func_val); - else if ( type->Tag() == TYPE_FILE ) + else if ( type->Tag() == zeek::TYPE_FILE ) Unref(val.file_val); #ifdef DEBUG @@ -112,19 +112,19 @@ IntrusivePtr Val::Clone(CloneState* state) IntrusivePtr Val::DoClone(CloneState* state) { switch ( type->InternalType() ) { - case TYPE_INTERNAL_INT: - case TYPE_INTERNAL_UNSIGNED: - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_DOUBLE: // Immutable. return {NewRef{}, this}; - case TYPE_INTERNAL_OTHER: + case zeek::TYPE_INTERNAL_OTHER: // Derived classes are responsible for this. Exception: // Functions and files. There aren't any derived classes. - if ( type->Tag() == TYPE_FUNC ) + if ( type->Tag() == zeek::TYPE_FUNC ) return make_intrusive(AsFunc()->DoClone()); - if ( type->Tag() == TYPE_FILE ) + if ( type->Tag() == zeek::TYPE_FILE ) { // I think we can just ref the file here - it is unclear what else // to do. In the case of cached files, I think this is equivalent @@ -139,7 +139,7 @@ IntrusivePtr Val::DoClone(CloneState* state) return {NewRef{}, this}; } - if ( type->Tag() == TYPE_TYPE ) + if ( type->Tag() == zeek::TYPE_TYPE ) // These are immutable, essentially. return {NewRef{}, this}; @@ -155,16 +155,16 @@ IntrusivePtr Val::DoClone(CloneState* state) IntrusivePtr Val::AsFuncPtr() const { - CHECK_TAG(type->Tag(), TYPE_FUNC, "Val::Func", type_name) + CHECK_TAG(type->Tag(), zeek::TYPE_FUNC, "Val::Func", zeek::type_name) return {NewRef{}, val.func_val}; } bool Val::IsZero() const { switch ( type->InternalType() ) { - case TYPE_INTERNAL_INT: return val.int_val == 0; - case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 0; - case TYPE_INTERNAL_DOUBLE: return val.double_val == 0.0; + case zeek::TYPE_INTERNAL_INT: return val.int_val == 0; + case zeek::TYPE_INTERNAL_UNSIGNED: return val.uint_val == 0; + case zeek::TYPE_INTERNAL_DOUBLE: return val.double_val == 0.0; default: return false; } @@ -173,9 +173,9 @@ bool Val::IsZero() const bool Val::IsOne() const { switch ( type->InternalType() ) { - case TYPE_INTERNAL_INT: return val.int_val == 1; - case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 1; - case TYPE_INTERNAL_DOUBLE: return val.double_val == 1.0; + case zeek::TYPE_INTERNAL_INT: return val.int_val == 1; + case zeek::TYPE_INTERNAL_UNSIGNED: return val.uint_val == 1; + case zeek::TYPE_INTERNAL_DOUBLE: return val.double_val == 1.0; default: return false; } @@ -183,9 +183,9 @@ bool Val::IsOne() const bro_int_t Val::InternalInt() const { - if ( type->InternalType() == TYPE_INTERNAL_INT ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_INT ) return val.int_val; - else if ( type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) // ### should check here for overflow return static_cast(val.uint_val); else @@ -196,7 +196,7 @@ bro_int_t Val::InternalInt() const bro_uint_t Val::InternalUnsigned() const { - if ( type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return val.uint_val; else InternalWarning("bad request for InternalUnsigned"); @@ -206,7 +206,7 @@ bro_uint_t Val::InternalUnsigned() const double Val::InternalDouble() const { - if ( type->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return val.double_val; else InternalWarning("bad request for InternalDouble"); @@ -216,11 +216,11 @@ double Val::InternalDouble() const bro_int_t Val::CoerceToInt() const { - if ( type->InternalType() == TYPE_INTERNAL_INT ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_INT ) return val.int_val; - else if ( type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return static_cast(val.uint_val); - else if ( type->InternalType() == TYPE_INTERNAL_DOUBLE ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return static_cast(val.double_val); else InternalWarning("bad request for CoerceToInt"); @@ -230,11 +230,11 @@ bro_int_t Val::CoerceToInt() const bro_uint_t Val::CoerceToUnsigned() const { - if ( type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return val.uint_val; - else if ( type->InternalType() == TYPE_INTERNAL_INT ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_INT ) return static_cast(val.int_val); - else if ( type->InternalType() == TYPE_INTERNAL_DOUBLE ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return static_cast(val.double_val); else InternalWarning("bad request for CoerceToUnsigned"); @@ -244,11 +244,11 @@ bro_uint_t Val::CoerceToUnsigned() const double Val::CoerceToDouble() const { - if ( type->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return val.double_val; - else if ( type->InternalType() == TYPE_INTERNAL_INT ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_INT ) return static_cast(val.int_val); - else if ( type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return static_cast(val.uint_val); else InternalWarning("bad request for CoerceToDouble"); @@ -259,7 +259,7 @@ double Val::CoerceToDouble() const IntrusivePtr Val::SizeVal() const { switch ( type->InternalType() ) { - case TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_INT: // Return abs value. However abs() only works on ints and llabs // doesn't work on Mac OS X 10.5. So we do it by hand if ( val.int_val < 0 ) @@ -267,17 +267,17 @@ IntrusivePtr Val::SizeVal() const else return val_mgr->Count(val.int_val); - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_UNSIGNED: return val_mgr->Count(val.uint_val); - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: return make_intrusive(fabs(val.double_val)); - case TYPE_INTERNAL_OTHER: - if ( type->Tag() == TYPE_FUNC ) + case zeek::TYPE_INTERNAL_OTHER: + if ( type->Tag() == zeek::TYPE_FUNC ) return val_mgr->Count(val.func_val->GetType()->ParamList()->Types().size()); - if ( type->Tag() == TYPE_FILE ) + if ( type->Tag() == zeek::TYPE_FILE ) return make_intrusive(val.file_val->Size()); break; @@ -323,36 +323,36 @@ void Val::DescribeReST(ODesc* d) const void Val::ValDescribe(ODesc* d) const { - if ( d->IsReadable() && type->Tag() == TYPE_BOOL ) + if ( d->IsReadable() && type->Tag() == zeek::TYPE_BOOL ) { d->Add(CoerceToInt() ? "T" : "F"); return; } switch ( type->InternalType() ) { - case TYPE_INTERNAL_INT: d->Add(val.int_val); break; - case TYPE_INTERNAL_UNSIGNED: d->Add(val.uint_val); break; - case TYPE_INTERNAL_DOUBLE: d->Add(val.double_val); break; - case TYPE_INTERNAL_STRING: d->AddBytes(val.string_val); break; - case TYPE_INTERNAL_ADDR: d->Add(val.addr_val->AsString().c_str()); break; + case zeek::TYPE_INTERNAL_INT: d->Add(val.int_val); break; + case zeek::TYPE_INTERNAL_UNSIGNED: d->Add(val.uint_val); break; + case zeek::TYPE_INTERNAL_DOUBLE: d->Add(val.double_val); break; + case zeek::TYPE_INTERNAL_STRING: d->AddBytes(val.string_val); break; + case zeek::TYPE_INTERNAL_ADDR: d->Add(val.addr_val->AsString().c_str()); break; - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: d->Add(val.subnet_val->AsString().c_str()); break; - case TYPE_INTERNAL_ERROR: d->AddCS("error"); break; - case TYPE_INTERNAL_OTHER: - if ( type->Tag() == TYPE_FUNC ) + case zeek::TYPE_INTERNAL_ERROR: d->AddCS("error"); break; + case zeek::TYPE_INTERNAL_OTHER: + if ( type->Tag() == zeek::TYPE_FUNC ) AsFunc()->Describe(d); - else if ( type->Tag() == TYPE_FILE ) + else if ( type->Tag() == zeek::TYPE_FILE ) AsFile()->Describe(d); - else if ( type->Tag() == TYPE_TYPE ) + else if ( type->Tag() == zeek::TYPE_TYPE ) d->Add(type->AsTypeType()->GetType()->GetName()); else d->Add(""); break; - case TYPE_INTERNAL_VOID: + case zeek::TYPE_INTERNAL_VOID: d->Add(""); break; @@ -366,7 +366,7 @@ void Val::ValDescribe(ODesc* d) const void Val::ValDescribeReST(ODesc* d) const { switch ( type->InternalType() ) { - case TYPE_INTERNAL_OTHER: + case zeek::TYPE_INTERNAL_OTHER: Describe(d); break; @@ -391,28 +391,28 @@ void Val::SetID(zeek::detail::ID* id) } #endif -bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val) +bool Val::WouldOverflow(const zeek::BroType* from_type, const zeek::BroType* to_type, const Val* val) { if ( !to_type || !from_type ) return true; else if ( same_type(to_type, from_type) ) return false; - if ( to_type->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( to_type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return false; - else if ( to_type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( to_type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) { - if ( from_type->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( from_type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return (val->InternalDouble() < 0.0 || val->InternalDouble() > static_cast(UINT64_MAX)); - else if ( from_type->InternalType() == TYPE_INTERNAL_INT ) + else if ( from_type->InternalType() == zeek::TYPE_INTERNAL_INT ) return (val->InternalInt() < 0); } - else if ( to_type->InternalType() == TYPE_INTERNAL_INT ) + else if ( to_type->InternalType() == zeek::TYPE_INTERNAL_INT ) { - if ( from_type->InternalType() == TYPE_INTERNAL_DOUBLE ) + if ( from_type->InternalType() == zeek::TYPE_INTERNAL_DOUBLE ) return (val->InternalDouble() < static_cast(INT64_MIN) || val->InternalDouble() > static_cast(INT64_MAX)); - else if ( from_type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + else if ( from_type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) return (val->InternalUnsigned() > INT64_MAX); } @@ -421,19 +421,19 @@ bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const IntrusivePtr Val::GetRecordFields() { - static auto record_field_table = zeek::id::find_type("record_field_table"); + static auto record_field_table = zeek::id::find_type("record_field_table"); auto t = GetType().get(); - if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) + if ( t->Tag() != zeek::TYPE_RECORD && t->Tag() != zeek::TYPE_TYPE ) { reporter->Error("non-record value/type passed to record_fields"); return make_intrusive(record_field_table); } - RecordType* rt = nullptr; + zeek::RecordType* rt = nullptr; RecordVal* rv = nullptr; - if ( t->Tag() == TYPE_RECORD ) + if ( t->Tag() == zeek::TYPE_RECORD ) { rt = t->AsRecordType(); rv = AsRecordVal(); @@ -442,7 +442,7 @@ IntrusivePtr Val::GetRecordFields() { t = t->AsTypeType()->GetType().get(); - if ( t->Tag() != TYPE_RECORD ) + if ( t->Tag() != zeek::TYPE_RECORD ) { reporter->Error("non-record value/type passed to record_fields"); return make_intrusive(record_field_table); @@ -471,31 +471,31 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* switch ( val->GetType()->Tag() ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: writer.Bool(val->AsBool()); break; - case TYPE_INT: + case zeek::TYPE_INT: writer.Int64(val->AsInt()); break; - case TYPE_COUNT: + case zeek::TYPE_COUNT: writer.Uint64(val->AsCount()); break; - case TYPE_COUNTER: + case zeek::TYPE_COUNTER: writer.Uint64(val->AsCounter()); break; - case TYPE_TIME: + case zeek::TYPE_TIME: writer.Double(val->AsTime()); break; - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: writer.Double(val->AsDouble()); break; - case TYPE_PORT: + case zeek::TYPE_PORT: { auto* pval = val->AsPortVal(); writer.StartObject(); @@ -507,10 +507,10 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_PATTERN: - case TYPE_INTERVAL: - case TYPE_ADDR: - case TYPE_SUBNET: + case zeek::TYPE_PATTERN: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_ADDR: + case zeek::TYPE_SUBNET: { ODesc d; d.SetStyle(RAW_STYLE); @@ -519,10 +519,10 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_FILE: - case TYPE_FUNC: - case TYPE_ENUM: - case TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: { ODesc d; d.SetStyle(RAW_STYLE); @@ -531,7 +531,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { auto* table = val->AsTable(); auto* tval = val->AsTableVal(); @@ -577,7 +577,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_RECORD: + case zeek::TYPE_RECORD: { writer.StartObject(); @@ -612,7 +612,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_LIST: + case zeek::TYPE_LIST: { writer.StartArray(); @@ -625,7 +625,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { writer.StartArray(); @@ -638,7 +638,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* break; } - case TYPE_OPAQUE: + case zeek::TYPE_OPAQUE: { writer.StartObject(); @@ -775,7 +775,7 @@ uint32_t PortVal::Mask(uint32_t port_num, TransportProto port_type) return port_num; } -PortVal::PortVal(uint32_t p) : Val(bro_uint_t(p), TYPE_PORT) +PortVal::PortVal(uint32_t p) : Val(bro_uint_t(p), zeek::TYPE_PORT) { } @@ -826,7 +826,7 @@ IntrusivePtr PortVal::DoClone(CloneState* state) return {NewRef{}, this}; } -AddrVal::AddrVal(const char* text) : Val(new IPAddr(text), TYPE_ADDR) +AddrVal::AddrVal(const char* text) : Val(new IPAddr(text), zeek::TYPE_ADDR) { } @@ -834,16 +834,16 @@ AddrVal::AddrVal(const std::string& text) : AddrVal(text.c_str()) { } -AddrVal::AddrVal(uint32_t addr) : Val(new IPAddr(IPv4, &addr, IPAddr::Network), TYPE_ADDR) +AddrVal::AddrVal(uint32_t addr) : Val(new IPAddr(IPv4, &addr, IPAddr::Network), zeek::TYPE_ADDR) { // ### perhaps do gethostbyaddr here? } -AddrVal::AddrVal(const uint32_t addr[4]) : Val(new IPAddr(IPv6, addr, IPAddr::Network), TYPE_ADDR) +AddrVal::AddrVal(const uint32_t addr[4]) : Val(new IPAddr(IPv6, addr, IPAddr::Network), zeek::TYPE_ADDR) { } -AddrVal::AddrVal(const IPAddr& addr) : Val(new IPAddr(addr), TYPE_ADDR) +AddrVal::AddrVal(const IPAddr& addr) : Val(new IPAddr(addr), zeek::TYPE_ADDR) { } @@ -871,13 +871,13 @@ IntrusivePtr AddrVal::DoClone(CloneState* state) return {NewRef{}, this}; } -SubNetVal::SubNetVal(const char* text) : Val(new IPPrefix(), TYPE_SUBNET) +SubNetVal::SubNetVal(const char* text) : Val(new IPPrefix(), zeek::TYPE_SUBNET) { if ( ! IPPrefix::ConvertString(text, val.subnet_val) ) reporter->Error("Bad string in SubNetVal ctor: %s", text); } -SubNetVal::SubNetVal(const char* text, int width) : Val(new IPPrefix(text, width), TYPE_SUBNET) +SubNetVal::SubNetVal(const char* text, int width) : Val(new IPPrefix(text, width), zeek::TYPE_SUBNET) { } @@ -889,11 +889,11 @@ SubNetVal::SubNetVal(const uint32_t* addr, int width) : SubNetVal(IPAddr{IPv6, a { } -SubNetVal::SubNetVal(const IPAddr& addr, int width) : Val(new IPPrefix(addr, width), TYPE_SUBNET) +SubNetVal::SubNetVal(const IPAddr& addr, int width) : Val(new IPPrefix(addr, width), zeek::TYPE_SUBNET) { } -SubNetVal::SubNetVal(const IPPrefix& prefix) : Val(new IPPrefix(prefix), TYPE_SUBNET) +SubNetVal::SubNetVal(const IPPrefix& prefix) : Val(new IPPrefix(prefix), zeek::TYPE_SUBNET) { } @@ -968,7 +968,7 @@ IntrusivePtr SubNetVal::DoClone(CloneState* state) return {NewRef{}, this}; } -StringVal::StringVal(BroString* s) : Val(s, TYPE_STRING) +StringVal::StringVal(BroString* s) : Val(s, zeek::TYPE_STRING) { } @@ -1129,7 +1129,7 @@ IntrusivePtr StringVal::DoClone(CloneState* state) } PatternVal::PatternVal(RE_Matcher* re) - : Val(base_type(TYPE_PATTERN)) + : Val(zeek::base_type(zeek::TYPE_PATTERN)) { val.re_val = re; } @@ -1141,7 +1141,7 @@ PatternVal::~PatternVal() bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const { - if ( v->GetType()->Tag() != TYPE_PATTERN ) + if ( v->GetType()->Tag() != zeek::TYPE_PATTERN ) { v->Error("not a pattern"); return false; @@ -1187,8 +1187,8 @@ IntrusivePtr PatternVal::DoClone(CloneState* state) return state->NewClone(this, make_intrusive(re)); } -ListVal::ListVal(TypeTag t) - : Val(make_intrusive(t == TYPE_ANY ? nullptr : base_type(t))) +ListVal::ListVal(zeek::TypeTag t) + : Val(make_intrusive(t == zeek::TYPE_ANY ? nullptr : zeek::base_type(t))) { tag = t; } @@ -1204,7 +1204,7 @@ IntrusivePtr ListVal::SizeVal() const RE_Matcher* ListVal::BuildRE() const { - if ( tag != TYPE_STRING ) + if ( tag != zeek::TYPE_STRING ) Internal("non-string list in ListVal::IncludedInString"); RE_Matcher* re = new RE_Matcher(); @@ -1237,13 +1237,13 @@ void ListVal::Append(Val* v) IntrusivePtr ListVal::ToSetVal() const { - if ( tag == TYPE_ANY ) + if ( tag == zeek::TYPE_ANY ) Internal("conversion of heterogeneous list to set"); const auto& pt = type->AsTypeList()->GetPureType(); - auto set_index = make_intrusive(pt); - set_index->Append(base_type(tag)); - auto s = make_intrusive(std::move(set_index), nullptr); + auto set_index = make_intrusive(pt); + set_index->Append(zeek::base_type(tag)); + auto s = make_intrusive(std::move(set_index), nullptr); auto t = make_intrusive(std::move(s)); for ( const auto& val : vals ) @@ -1337,13 +1337,13 @@ static void table_entry_val_delete_func(void* val) delete tv; } -static void find_nested_record_types(const IntrusivePtr& t, std::set* found) +static void find_nested_record_types(const IntrusivePtr& t, std::set* found) { if ( ! t ) return; switch ( t->Tag() ) { - case TYPE_RECORD: + case zeek::TYPE_RECORD: { auto rt = t->AsRecordType(); found->emplace(rt); @@ -1352,24 +1352,24 @@ static void find_nested_record_types(const IntrusivePtr& t, std::setFieldDecl(i)->type, found); } return; - case TYPE_TABLE: + case zeek::TYPE_TABLE: find_nested_record_types(t->AsTableType()->GetIndices(), found); find_nested_record_types(t->AsTableType()->Yield(), found); return; - case TYPE_LIST: + case zeek::TYPE_LIST: { for ( const auto& type : t->AsTypeList()->Types() ) find_nested_record_types(type, found); } return; - case TYPE_FUNC: + case zeek::TYPE_FUNC: find_nested_record_types(t->AsFuncType()->Params(), found); find_nested_record_types(t->AsFuncType()->Yield(), found); return; - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: find_nested_record_types(t->AsVectorType()->Yield(), found); return; - case TYPE_TYPE: + case zeek::TYPE_TYPE: find_nested_record_types(t->AsTypeType()->GetType(), found); return; default: @@ -1377,7 +1377,7 @@ static void find_nested_record_types(const IntrusivePtr& t, std::set t, IntrusivePtr a) : Val(t) +TableVal::TableVal(IntrusivePtr t, IntrusivePtr a) : Val(t) { Init(std::move(t)); SetAttrs(std::move(a)); @@ -1387,7 +1387,7 @@ TableVal::TableVal(IntrusivePtr t, IntrusivePtrIndexTypes() ) { - std::set found; + std::set found; // TODO: this likely doesn't have to be repeated for each new TableVal, // can remember the resulting dependencies per TableType find_nested_record_types(t, &found); @@ -1397,7 +1397,7 @@ TableVal::TableVal(IntrusivePtr t, IntrusivePtr t) +void TableVal::Init(IntrusivePtr t) { table_type = std::move(t); expire_func = nullptr; @@ -1444,7 +1444,7 @@ int TableVal::RecursiveSize() const int n = AsTable()->Length(); if ( GetType()->IsSet() || - GetType()->AsTableType()->Yield()->Tag() != TYPE_TABLE ) + GetType()->AsTableType()->Yield()->Tag() != zeek::TYPE_TABLE ) return n; PDict* v = val.table_val; @@ -1490,7 +1490,7 @@ void TableVal::CheckExpireAttr(zeek::detail::attr_tag at) { expire_time = a->GetExpr(); - if ( expire_time->GetType()->Tag() != TYPE_INTERVAL ) + if ( expire_time->GetType()->Tag() != zeek::TYPE_INTERVAL ) { if ( ! expire_time->IsError() ) expire_time->SetError("expiration interval has wrong type"); @@ -1589,7 +1589,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init) const bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const { - if ( val->GetType()->Tag() != TYPE_TABLE ) + if ( val->GetType()->Tag() != zeek::TYPE_TABLE ) { val->Error("not a table"); return false; @@ -1637,7 +1637,7 @@ bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const bool TableVal::RemoveFrom(Val* val) const { - if ( val->GetType()->Tag() != TYPE_TABLE ) + if ( val->GetType()->Tag() != zeek::TYPE_TABLE ) { val->Error("not a table"); return false; @@ -1764,12 +1764,12 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) return ExpandAndInit(std::move(index), std::move(new_val)); } - if ( index_type->Tag() != TYPE_LIST ) + if ( index_type->Tag() != zeek::TYPE_LIST ) // Nothing to expand. return CheckAndAssign(std::move(index), std::move(new_val)); ListVal* iv = index->AsListVal(); - if ( iv->BaseTag() != TYPE_ANY ) + if ( iv->BaseTag() != zeek::TYPE_ANY ) { if ( table_type->GetIndices()->Types().size() != 1 ) reporter->InternalError("bad singleton list index"); @@ -1793,7 +1793,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) // then we could optimize here. const auto& t = v->GetType(); - if ( t->IsSet() || t->Tag() == TYPE_LIST ) + if ( t->IsSet() || t->Tag() == zeek::TYPE_LIST ) break; } @@ -1818,12 +1818,12 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const auto& ytype = GetType()->Yield(); const auto& dtype = def_attr->GetExpr()->GetType(); - if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && + if ( dtype->Tag() == zeek::TYPE_RECORD && ytype->Tag() == zeek::TYPE_RECORD && ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) { - auto rt = cast_intrusive(ytype); + auto rt = cast_intrusive(ytype); auto coerce = make_intrusive( def_attr->GetExpr(), std::move(rt)); @@ -1840,7 +1840,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) return nullptr; } - if ( def_val->GetType()->Tag() != TYPE_FUNC || + if ( def_val->GetType()->Tag() != zeek::TYPE_FUNC || same_type(def_val->GetType(), GetType()->Yield()) ) { if ( def_attr->GetExpr()->IsConst() ) @@ -1860,7 +1860,7 @@ IntrusivePtr TableVal::Default(const IntrusivePtr& index) const Func* f = def_val->AsFunc(); zeek::Args vl; - if ( index->GetType()->Tag() == TYPE_LIST ) + if ( index->GetType()->Tag() == zeek::TYPE_LIST ) { auto lv = index->AsListVal(); vl.reserve(lv->Length()); @@ -1964,7 +1964,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(zeek::id::find_type("subnet_vec")); + auto result = make_intrusive(zeek::id::find_type("subnet_vec")); auto matches = subnets->FindAll(search); for ( auto element : matches ) @@ -1978,7 +1978,7 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnetValues called on wrong table type"); - auto nt = make_intrusive(this->GetType()); + auto nt = make_intrusive(this->GetType()); auto matches = subnets->FindAll(search); for ( auto element : matches ) @@ -2049,7 +2049,7 @@ void TableVal::CallChangeFunc(const Val* index, return; } - if ( thefunc->GetType()->Tag() != TYPE_FUNC ) + if ( thefunc->GetType()->Tag() != zeek::TYPE_FUNC ) { thefunc->Error("not a function"); return; @@ -2144,7 +2144,7 @@ IntrusivePtr TableVal::Remove(const HashKey& k) return va; } -IntrusivePtr TableVal::ToListVal(TypeTag t) const +IntrusivePtr TableVal::ToListVal(zeek::TypeTag t) const { auto l = make_intrusive(t); @@ -2156,7 +2156,7 @@ IntrusivePtr TableVal::ToListVal(TypeTag t) const { auto index = table_hash->RecoverVals(*k); - if ( t == TYPE_ANY ) + if ( t == zeek::TYPE_ANY ) l->Append(std::move(index)); else { @@ -2173,7 +2173,7 @@ IntrusivePtr TableVal::ToListVal(TypeTag t) const return l; } -ListVal* TableVal::ConvertToList(TypeTag t) const +ListVal* TableVal::ConvertToList(zeek::TypeTag t) const { return ToListVal().release(); } @@ -2296,7 +2296,7 @@ bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_v for ( int i = 0; i < ind_k->Length(); ++i ) { const auto& ind_k_i = ind_k->Idx(i); - auto expd = make_intrusive(TYPE_ANY); + auto expd = make_intrusive(zeek::TYPE_ANY); for ( auto j = 0; j < lv->Length(); ++j ) { @@ -2344,7 +2344,7 @@ void TableVal::InitDefaultFunc(Frame* f) const auto& ytype = GetType()->Yield(); const auto& dtype = def_attr->GetExpr()->GetType(); - if ( dtype->Tag() == TYPE_RECORD && ytype->Tag() == TYPE_RECORD && + if ( dtype->Tag() == zeek::TYPE_RECORD && ytype->Tag() == zeek::TYPE_RECORD && ! same_type(dtype, ytype) && record_promotion_compatible(dtype->AsRecordType(), ytype->AsRecordType()) ) @@ -2507,7 +2507,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) // Will have been reported already. return 0; - if ( vf->GetType()->Tag() != TYPE_FUNC ) + if ( vf->GetType()->Tag() != zeek::TYPE_FUNC ) { vf->Error("not a function"); return 0; @@ -2518,7 +2518,7 @@ double TableVal::CallExpireFunc(IntrusivePtr idx) const auto& func_args = f->GetType()->ParamList()->Types(); // backwards compatibility with idx: any idiom - bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == TYPE_ANY; + bool any_idiom = func_args.size() == 2 && func_args.back()->Tag() == zeek::TYPE_ANY; if ( ! any_idiom ) { @@ -2627,7 +2627,7 @@ std::unique_ptr TableVal::MakeHashKey(const Val& index) const return table_hash->MakeHashKey(index, true); } -void TableVal::SaveParseTimeTableState(RecordType* rt) +void TableVal::SaveParseTimeTableState(zeek::RecordType* rt) { auto it = parse_time_table_record_dependencies.find(rt); @@ -2688,11 +2688,11 @@ TableVal::TableRecordDependencies TableVal::parse_time_table_record_dependencies RecordVal::RecordTypeValMap RecordVal::parse_time_records; -RecordVal::RecordVal(RecordType* t, bool init_fields) +RecordVal::RecordVal(zeek::RecordType* t, bool init_fields) : RecordVal({NewRef{}, t}, init_fields) {} -RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::move(t)) +RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::move(t)) { origin = nullptr; auto rt = GetType()->AsRecordType(); @@ -2715,11 +2715,11 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo auto def = def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; const auto& type = rt->FieldDecl(i)->type; - if ( def && type->Tag() == TYPE_RECORD && - def->GetType()->Tag() == TYPE_RECORD && + if ( def && type->Tag() == zeek::TYPE_RECORD && + def->GetType()->Tag() == zeek::TYPE_RECORD && ! same_type(def->GetType(), type) ) { - auto tmp = def->AsRecordVal()->CoerceTo(cast_intrusive(type)); + auto tmp = def->AsRecordVal()->CoerceTo(cast_intrusive(type)); if ( tmp ) def = std::move(tmp); @@ -2727,17 +2727,17 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo if ( ! def && ! (a && a->Find(zeek::detail::ATTR_OPTIONAL)) ) { - TypeTag tag = type->Tag(); + zeek::TypeTag tag = type->Tag(); - if ( tag == TYPE_RECORD ) - def = make_intrusive(cast_intrusive(type)); + if ( tag == zeek::TYPE_RECORD ) + def = make_intrusive(cast_intrusive(type)); - else if ( tag == TYPE_TABLE ) + else if ( tag == zeek::TYPE_TABLE ) def = make_intrusive(IntrusivePtr{NewRef{}, type->AsTableType()}, IntrusivePtr{NewRef{}, a}); - else if ( tag == TYPE_VECTOR ) - def = make_intrusive(cast_intrusive(type)); + else if ( tag == zeek::TYPE_VECTOR ) + def = make_intrusive(cast_intrusive(type)); } vl->emplace_back(std::move(def)); @@ -2775,7 +2775,7 @@ IntrusivePtr RecordVal::GetFieldOrDefault(int field) const return GetType()->AsRecordType()->FieldDefault(field); } -void RecordVal::ResizeParseTimeRecords(RecordType* rt) +void RecordVal::ResizeParseTimeRecords(zeek::RecordType* rt) { auto it = parse_time_records.find(rt); @@ -2825,7 +2825,7 @@ IntrusivePtr RecordVal::GetFieldOrDefault(const char* field) const return GetFieldOrDefault(idx); } -IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, +IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, IntrusivePtr aggr, bool allow_orphaning) const { @@ -2835,8 +2835,8 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, if ( ! aggr ) aggr = make_intrusive(std::move(t)); - RecordType* ar_t = aggr->GetType()->AsRecordType(); - const RecordType* rv_t = GetType()->AsRecordType(); + zeek::RecordType* ar_t = aggr->GetType()->AsRecordType(); + const zeek::RecordType* rv_t = GetType()->AsRecordType(); int i; for ( i = 0; i < rv_t->NumFields(); ++i ) @@ -2864,11 +2864,11 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, const auto& ft = ar_t->GetFieldType(t_i); - if ( ft->Tag() == TYPE_RECORD && ! same_type(ft, v->GetType()) ) + if ( ft->Tag() == zeek::TYPE_RECORD && ! same_type(ft, v->GetType()) ) { auto rhs = make_intrusive(v); auto e = make_intrusive(std::move(rhs), - cast_intrusive(ft)); + cast_intrusive(ft)); aggr->Assign(t_i, e->Eval(nullptr)); continue; } @@ -2889,7 +2889,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, return aggr; } -IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, +IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, bool allow_orphaning) { if ( same_type(GetType(), t) ) @@ -2977,7 +2977,7 @@ IntrusivePtr RecordVal::DoClone(CloneState* state) // record. As we cannot guarantee that it will ber zeroed out at the // approproate time (as it seems to be guaranteed for the original record) // we don't touch it. - auto rv = make_intrusive(GetType(), false); + auto rv = make_intrusive(GetType(), false); rv->origin = nullptr; state->NewClone(this, rv); @@ -3027,10 +3027,10 @@ IntrusivePtr EnumVal::DoClone(CloneState* state) return {NewRef{}, this}; } -VectorVal::VectorVal(VectorType* t) : VectorVal({NewRef{}, t}) +VectorVal::VectorVal(zeek::VectorType* t) : VectorVal({NewRef{}, t}) { } -VectorVal::VectorVal(IntrusivePtr t) : Val(std::move(t)) +VectorVal::VectorVal(IntrusivePtr t) : Val(std::move(t)) { val.vector_val = new vector>(); } @@ -3107,7 +3107,7 @@ bool VectorVal::Remove(unsigned int index) bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const { - if ( val->GetType()->Tag() != TYPE_VECTOR ) + if ( val->GetType()->Tag() != zeek::TYPE_VECTOR ) { val->Error("not a vector"); return false; @@ -3156,7 +3156,7 @@ unsigned int VectorVal::ResizeAtLeast(unsigned int new_num_elements) IntrusivePtr VectorVal::DoClone(CloneState* state) { - auto vv = make_intrusive(GetType()); + auto vv = make_intrusive(GetType()); vv->val.vector_val->reserve(val.vector_val->size()); state->NewClone(this, vv); @@ -3188,26 +3188,26 @@ void VectorVal::ValDescribe(ODesc* d) const d->Add("]"); } -IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, +IntrusivePtr check_and_promote(IntrusivePtr v, const zeek::BroType* t, bool is_init, const Location* expr_location) { if ( ! v ) return nullptr; - BroType* vt = flatten_type(v->GetType().get()); + zeek::BroType* vt = flatten_type(v->GetType().get()); t = flatten_type(t); - TypeTag t_tag = t->Tag(); - TypeTag v_tag = vt->Tag(); + zeek::TypeTag t_tag = t->Tag(); + zeek::TypeTag v_tag = vt->Tag(); // More thought definitely needs to go into this. - if ( t_tag == TYPE_ANY || v_tag == TYPE_ANY ) + if ( t_tag == zeek::TYPE_ANY || v_tag == zeek::TYPE_ANY ) return v; - if ( ! EitherArithmetic(t_tag, v_tag) || + if ( ! zeek::EitherArithmetic(t_tag, v_tag) || /* allow sets as initializers */ - (is_init && v_tag == TYPE_TABLE) ) + (is_init && v_tag == zeek::TYPE_TABLE) ) { if ( same_type(t, vt, is_init) ) return v; @@ -3216,10 +3216,10 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, return nullptr; } - if ( ! BothArithmetic(t_tag, v_tag) && - (! IsArithmetic(v_tag) || t_tag != TYPE_TIME || ! v->IsZero()) ) + if ( ! zeek::BothArithmetic(t_tag, v_tag) && + (! zeek::IsArithmetic(v_tag) || t_tag != zeek::TYPE_TIME || ! v->IsZero()) ) { - if ( t_tag == TYPE_LIST || v_tag == TYPE_LIST ) + if ( t_tag == zeek::TYPE_LIST || v_tag == zeek::TYPE_LIST ) t->Error("list mixed with scalar", v.get(), false, expr_location); else t->Error("arithmetic mixed with non-arithmetic", v.get(), false, expr_location); @@ -3229,9 +3229,9 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, if ( v_tag == t_tag ) return v; - if ( t_tag != TYPE_TIME && ! BothArithmetic(t_tag, v_tag) ) + if ( t_tag != zeek::TYPE_TIME && ! zeek::BothArithmetic(t_tag, v_tag) ) { - TypeTag mt = max_type(t_tag, v_tag); + zeek::TypeTag mt = zeek::max_type(t_tag, v_tag); if ( mt != t_tag ) { t->Error("over-promotion of arithmetic value", v.get(), false, expr_location); @@ -3240,8 +3240,8 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, } // Need to promote v to type t. - InternalTypeTag it = t->InternalType(); - InternalTypeTag vit = vt->InternalType(); + zeek::InternalTypeTag it = t->InternalType(); + zeek::InternalTypeTag vit = vt->InternalType(); if ( it == vit ) // Already has the right internal type. @@ -3250,13 +3250,13 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, IntrusivePtr promoted_v; switch ( it ) { - case TYPE_INTERNAL_INT: - if ( ( vit == TYPE_INTERNAL_UNSIGNED || vit == TYPE_INTERNAL_DOUBLE ) && Val::WouldOverflow(vt, t, v.get()) ) + case zeek::TYPE_INTERNAL_INT: + if ( ( vit == zeek::TYPE_INTERNAL_UNSIGNED || vit == zeek::TYPE_INTERNAL_DOUBLE ) && Val::WouldOverflow(vt, t, v.get()) ) { t->Error("overflow promoting from unsigned/double to signed arithmetic value", v.get(), false, expr_location); return nullptr; } - else if ( t_tag == TYPE_INT ) + else if ( t_tag == zeek::TYPE_INT ) promoted_v = val_mgr->Int(v->CoerceToInt()); else // enum { @@ -3266,13 +3266,13 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, break; - case TYPE_INTERNAL_UNSIGNED: - if ( ( vit == TYPE_INTERNAL_DOUBLE || vit == TYPE_INTERNAL_INT) && Val::WouldOverflow(vt, t, v.get()) ) + case zeek::TYPE_INTERNAL_UNSIGNED: + if ( ( vit == zeek::TYPE_INTERNAL_DOUBLE || vit == zeek::TYPE_INTERNAL_INT) && Val::WouldOverflow(vt, t, v.get()) ) { t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), false, expr_location); return nullptr; } - else if ( t_tag == TYPE_COUNT || t_tag == TYPE_COUNTER ) + else if ( t_tag == zeek::TYPE_COUNT || t_tag == zeek::TYPE_COUNTER ) promoted_v = val_mgr->Count(v->CoerceToUnsigned()); else // port { @@ -3282,15 +3282,15 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, break; - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: switch ( t_tag ) { - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: promoted_v = make_intrusive(v->CoerceToDouble()); break; - case TYPE_INTERVAL: + case zeek::TYPE_INTERVAL: promoted_v = make_intrusive(v->CoerceToDouble()); break; - case TYPE_TIME: + case zeek::TYPE_TIME: promoted_v = make_intrusive(v->CoerceToDouble()); break; default: @@ -3326,17 +3326,17 @@ bool same_atomic_val(const Val* v1, const Val* v2) return false; switch ( v1->GetType()->InternalType() ) { - case TYPE_INTERNAL_INT: + case zeek::TYPE_INTERNAL_INT: return v1->InternalInt() == v2->InternalInt(); - case TYPE_INTERNAL_UNSIGNED: + case zeek::TYPE_INTERNAL_UNSIGNED: return v1->InternalUnsigned() == v2->InternalUnsigned(); - case TYPE_INTERNAL_DOUBLE: + case zeek::TYPE_INTERNAL_DOUBLE: return v1->InternalDouble() == v2->InternalDouble(); - case TYPE_INTERNAL_STRING: + case zeek::TYPE_INTERNAL_STRING: return Bstr_eq(v1->AsString(), v2->AsString()); - case TYPE_INTERNAL_ADDR: + case zeek::TYPE_INTERNAL_ADDR: return v1->AsAddr() == v2->AsAddr(); - case TYPE_INTERNAL_SUBNET: + case zeek::TYPE_INTERNAL_SUBNET: return v1->AsSubNet() == v2->AsSubNet(); default: @@ -3392,7 +3392,7 @@ void delete_vals(val_list* vals) } } -IntrusivePtr cast_value_to_type(Val* v, BroType* t) +IntrusivePtr cast_value_to_type(Val* v, zeek::BroType* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3418,7 +3418,7 @@ IntrusivePtr cast_value_to_type(Val* v, BroType* t) return nullptr; } -bool can_cast_value_to_type(const Val* v, BroType* t) +bool can_cast_value_to_type(const Val* v, zeek::BroType* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3444,7 +3444,7 @@ bool can_cast_value_to_type(const Val* v, BroType* t) return false; } -bool can_cast_value_to_type(const BroType* s, BroType* t) +bool can_cast_value_to_type(const zeek::BroType* s, zeek::BroType* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3465,17 +3465,17 @@ bool can_cast_value_to_type(const BroType* s, BroType* t) IntrusivePtr Val::MakeBool(bool b) { - return IntrusivePtr{AdoptRef{}, new Val(bro_int_t(b), TYPE_BOOL)}; + return IntrusivePtr{AdoptRef{}, new Val(bro_int_t(b), zeek::TYPE_BOOL)}; } IntrusivePtr Val::MakeInt(bro_int_t i) { - return IntrusivePtr{AdoptRef{}, new Val(i, TYPE_INT)}; + return IntrusivePtr{AdoptRef{}, new Val(i, zeek::TYPE_INT)}; } IntrusivePtr Val::MakeCount(bro_uint_t u) { - return IntrusivePtr{AdoptRef{}, new Val(u, TYPE_COUNT)}; + return IntrusivePtr{AdoptRef{}, new Val(u, zeek::TYPE_COUNT)}; } ValManager::ValManager() diff --git a/src/Val.h b/src/Val.h index 30a0d213b9..f7ea2e0cbb 100644 --- a/src/Val.h +++ b/src/Val.h @@ -121,8 +121,12 @@ public: static inline const IntrusivePtr nil; [[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]] - Val(double d, TypeTag t) - : val(d), type(base_type(t)) + Val(double d, zeek::TypeTag t) + : val(d), type(zeek::base_type(t)) + {} + + [[deprecated("Remove in v4.1. Use version that takes zeek::TypeTag instead.")]] + Val(double d, ::TypeTag t) : Val(d, static_cast(t)) {} [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] @@ -136,16 +140,16 @@ public: explicit Val(IntrusivePtr f); // Extra arg to differentiate from protected version. - Val(IntrusivePtr t, bool type_type) - : type(make_intrusive(std::move(t))) + Val(IntrusivePtr t, bool type_type) + : type(make_intrusive(std::move(t))) {} [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - Val(BroType* t, bool type_type) : Val({NewRef{}, t}, type_type) + Val(zeek::BroType* t, bool type_type) : Val({NewRef{}, t}, type_type) {} Val() - : val(bro_int_t(0)), type(base_type(TYPE_ERROR)) + : val(bro_int_t(0)), type(zeek::base_type(zeek::TYPE_ERROR)) {} ~Val() override; @@ -181,11 +185,11 @@ public: virtual bool RemoveFrom(Val* v) const; [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* Type() { return type.get(); } + zeek::BroType* Type() { return type.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] - const BroType* Type() const { return type.get(); } + const zeek::BroType* Type() const { return type.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } template @@ -195,7 +199,7 @@ public: #define CONST_ACCESSOR(tag, ctype, accessor, name) \ const ctype name() const \ { \ - CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", type_name) \ + CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", zeek::type_name) \ return val.accessor; \ } @@ -203,72 +207,72 @@ public: #define CONST_ACCESSOR2(tag, ctype, accessor, name) \ ctype name() const \ { \ - CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", type_name) \ + CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", zeek::type_name) \ return val.accessor; \ } - CONST_ACCESSOR2(TYPE_BOOL, bool, int_val, AsBool) - CONST_ACCESSOR2(TYPE_INT, bro_int_t, int_val, AsInt) - CONST_ACCESSOR2(TYPE_COUNT, bro_uint_t, uint_val, AsCount) - CONST_ACCESSOR2(TYPE_COUNTER, bro_uint_t, uint_val, AsCounter) - CONST_ACCESSOR2(TYPE_DOUBLE, double, double_val, AsDouble) - CONST_ACCESSOR2(TYPE_TIME, double, double_val, AsTime) - CONST_ACCESSOR2(TYPE_INTERVAL, double, double_val, AsInterval) - CONST_ACCESSOR2(TYPE_ENUM, int, int_val, AsEnum) - CONST_ACCESSOR(TYPE_STRING, BroString*, string_val, AsString) - CONST_ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc) - CONST_ACCESSOR(TYPE_TABLE, PDict*, table_val, AsTable) - CONST_ACCESSOR(TYPE_RECORD, std::vector>*, record_val, AsRecord) - CONST_ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile) - CONST_ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) - CONST_ACCESSOR(TYPE_VECTOR, std::vector>*, vector_val, AsVector) + CONST_ACCESSOR2(zeek::TYPE_BOOL, bool, int_val, AsBool) + CONST_ACCESSOR2(zeek::TYPE_INT, bro_int_t, int_val, AsInt) + CONST_ACCESSOR2(zeek::TYPE_COUNT, bro_uint_t, uint_val, AsCount) + CONST_ACCESSOR2(zeek::TYPE_COUNTER, bro_uint_t, uint_val, AsCounter) + CONST_ACCESSOR2(zeek::TYPE_DOUBLE, double, double_val, AsDouble) + CONST_ACCESSOR2(zeek::TYPE_TIME, double, double_val, AsTime) + CONST_ACCESSOR2(zeek::TYPE_INTERVAL, double, double_val, AsInterval) + CONST_ACCESSOR2(zeek::TYPE_ENUM, int, int_val, AsEnum) + CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) + CONST_ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc) + CONST_ACCESSOR(zeek::TYPE_TABLE, PDict*, table_val, AsTable) + CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector>*, record_val, AsRecord) + CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) + CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) + CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector>*, vector_val, AsVector) const IPPrefix& AsSubNet() const { - CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name) + CHECK_TAG(type->Tag(), zeek::TYPE_SUBNET, "Val::SubNet", zeek::type_name) return *val.subnet_val; } - BroType* AsType() const + zeek::BroType* AsType() const { - CHECK_TAG(type->Tag(), TYPE_TYPE, "Val::Type", type_name) + CHECK_TAG(type->Tag(), zeek::TYPE_TYPE, "Val::Type", zeek::type_name) return type.get(); } const IPAddr& AsAddr() const { - if ( type->Tag() != TYPE_ADDR ) - BadTag("Val::AsAddr", type_name(type->Tag())); + if ( type->Tag() != zeek::TYPE_ADDR ) + BadTag("Val::AsAddr", zeek::type_name(type->Tag())); return *val.addr_val; } #define ACCESSOR(tag, ctype, accessor, name) \ ctype name() \ { \ - CHECK_TAG(type->Tag(), tag, "Val::ACCESSOR", type_name) \ + CHECK_TAG(type->Tag(), tag, "Val::ACCESSOR", zeek::type_name) \ return val.accessor; \ } // Accessors for mutable values are called AsNonConst* and // are protected to avoid external state changes. - // ACCESSOR(TYPE_STRING, BroString*, string_val, AsString) - ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc) - ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile) - ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) - ACCESSOR(TYPE_VECTOR, std::vector>*, vector_val, AsVector) + // ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) + ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc) + ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) + ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) + ACCESSOR(zeek::TYPE_VECTOR, std::vector>*, vector_val, AsVector) IntrusivePtr AsFuncPtr() const; const IPPrefix& AsSubNet() { - CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name) + CHECK_TAG(type->Tag(), zeek::TYPE_SUBNET, "Val::SubNet", zeek::type_name) return *val.subnet_val; } const IPAddr& AsAddr() { - if ( type->Tag() != TYPE_ADDR ) - BadTag("Val::AsAddr", type_name(type->Tag())); + if ( type->Tag() != zeek::TYPE_ADDR ) + BadTag("Val::AsAddr", zeek::type_name(type->Tag())); return *val.addr_val; } @@ -280,39 +284,39 @@ public: #define CONVERTER(tag, ctype, name) \ ctype name() \ { \ - CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", type_name) \ + CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", zeek::type_name) \ return (ctype)(this); \ } - CONVERTER(TYPE_PATTERN, PatternVal*, AsPatternVal) - CONVERTER(TYPE_PORT, PortVal*, AsPortVal) - CONVERTER(TYPE_SUBNET, SubNetVal*, AsSubNetVal) - CONVERTER(TYPE_ADDR, AddrVal*, AsAddrVal) - CONVERTER(TYPE_TABLE, TableVal*, AsTableVal) - CONVERTER(TYPE_RECORD, RecordVal*, AsRecordVal) - CONVERTER(TYPE_LIST, ListVal*, AsListVal) - CONVERTER(TYPE_STRING, StringVal*, AsStringVal) - CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal) - CONVERTER(TYPE_ENUM, EnumVal*, AsEnumVal) - CONVERTER(TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal) + CONVERTER(zeek::TYPE_PATTERN, PatternVal*, AsPatternVal) + CONVERTER(zeek::TYPE_PORT, PortVal*, AsPortVal) + CONVERTER(zeek::TYPE_SUBNET, SubNetVal*, AsSubNetVal) + CONVERTER(zeek::TYPE_ADDR, AddrVal*, AsAddrVal) + CONVERTER(zeek::TYPE_TABLE, TableVal*, AsTableVal) + CONVERTER(zeek::TYPE_RECORD, RecordVal*, AsRecordVal) + CONVERTER(zeek::TYPE_LIST, ListVal*, AsListVal) + CONVERTER(zeek::TYPE_STRING, StringVal*, AsStringVal) + CONVERTER(zeek::TYPE_VECTOR, VectorVal*, AsVectorVal) + CONVERTER(zeek::TYPE_ENUM, EnumVal*, AsEnumVal) + CONVERTER(zeek::TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal) #define CONST_CONVERTER(tag, ctype, name) \ const ctype name() const \ { \ - CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", type_name) \ + CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", zeek::type_name) \ return (const ctype)(this); \ } - CONST_CONVERTER(TYPE_PATTERN, PatternVal*, AsPatternVal) - CONST_CONVERTER(TYPE_PORT, PortVal*, AsPortVal) - CONST_CONVERTER(TYPE_SUBNET, SubNetVal*, AsSubNetVal) - CONST_CONVERTER(TYPE_ADDR, AddrVal*, AsAddrVal) - CONST_CONVERTER(TYPE_TABLE, TableVal*, AsTableVal) - CONST_CONVERTER(TYPE_RECORD, RecordVal*, AsRecordVal) - CONST_CONVERTER(TYPE_LIST, ListVal*, AsListVal) - CONST_CONVERTER(TYPE_STRING, StringVal*, AsStringVal) - CONST_CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal) - CONST_CONVERTER(TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal) + CONST_CONVERTER(zeek::TYPE_PATTERN, PatternVal*, AsPatternVal) + CONST_CONVERTER(zeek::TYPE_PORT, PortVal*, AsPortVal) + CONST_CONVERTER(zeek::TYPE_SUBNET, SubNetVal*, AsSubNetVal) + CONST_CONVERTER(zeek::TYPE_ADDR, AddrVal*, AsAddrVal) + CONST_CONVERTER(zeek::TYPE_TABLE, TableVal*, AsTableVal) + CONST_CONVERTER(zeek::TYPE_RECORD, RecordVal*, AsRecordVal) + CONST_CONVERTER(zeek::TYPE_LIST, ListVal*, AsListVal) + CONST_CONVERTER(zeek::TYPE_STRING, StringVal*, AsStringVal) + CONST_CONVERTER(zeek::TYPE_VECTOR, VectorVal*, AsVectorVal) + CONST_CONVERTER(zeek::TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal) void Describe(ODesc* d) const override; virtual void DescribeReST(ODesc* d) const; @@ -329,7 +333,7 @@ public: void SetID(zeek::detail::ID* id); #endif - static bool WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val); + static bool WouldOverflow(const zeek::BroType* from_type, const zeek::BroType* to_type, const Val* val); IntrusivePtr GetRecordFields(); @@ -337,7 +341,7 @@ public: protected: - friend class EnumType; + friend class zeek::EnumType; friend class ListVal; friend class RecordVal; friend class VectorVal; @@ -352,21 +356,21 @@ protected: static IntrusivePtr MakeCount(bro_uint_t u); template - Val(V&& v, TypeTag t) noexcept - : val(std::forward(v)), type(base_type(t)) + Val(V&& v, zeek::TypeTag t) noexcept + : val(std::forward(v)), type(zeek::base_type(t)) {} template - Val(V&& v, IntrusivePtr t) noexcept + Val(V&& v, IntrusivePtr t) noexcept : val(std::forward(v)), type(std::move(t)) {} - explicit Val(IntrusivePtr t) noexcept + explicit Val(IntrusivePtr t) noexcept : type(std::move(t)) {} - ACCESSOR(TYPE_TABLE, PDict*, table_val, AsNonConstTable) - ACCESSOR(TYPE_RECORD, std::vector>*, record_val, AsNonConstRecord) + ACCESSOR(zeek::TYPE_TABLE, PDict*, table_val, AsNonConstTable) + ACCESSOR(zeek::TYPE_RECORD, std::vector>*, record_val, AsNonConstRecord) // For internal use by the Val::Clone() methods. struct CloneState { @@ -382,7 +386,7 @@ protected: virtual IntrusivePtr DoClone(CloneState* state); BroValUnion val; - IntrusivePtr type; + IntrusivePtr type; #ifdef DEBUG // For debugging, we keep the name of the ID to which a Val is bound. @@ -491,7 +495,7 @@ extern ValManager* val_mgr; class IntervalVal final : public Val { public: IntervalVal(double quantity, double units = Seconds) - : Val(quantity * units, base_type(TYPE_INTERVAL)) + : Val(quantity * units, zeek::base_type(zeek::TYPE_INTERVAL)) {} protected: @@ -501,14 +505,14 @@ protected: class TimeVal final : public Val { public: TimeVal(double t) - : Val(t, base_type(TYPE_TIME)) + : Val(t, zeek::base_type(zeek::TYPE_TIME)) {} }; class DoubleVal final : public Val { public: DoubleVal(double v) - : Val(v, base_type(TYPE_DOUBLE)) + : Val(v, zeek::base_type(zeek::TYPE_DOUBLE)) {} }; @@ -647,10 +651,12 @@ protected: // element in their index. class ListVal final : public Val { public: - explicit ListVal(TypeTag t); + explicit ListVal(zeek::TypeTag t); + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag")]] + explicit ListVal(::TypeTag t) : ListVal(static_cast(t)) {} ~ListVal() override; - TypeTag BaseTag() const { return tag; } + zeek::TypeTag BaseTag() const { return tag; } IntrusivePtr SizeVal() const override; @@ -698,7 +704,7 @@ protected: IntrusivePtr DoClone(CloneState* state) override; std::vector> vals; - TypeTag tag; + zeek::TypeTag tag; }; extern double bro_start_network_time; @@ -758,10 +764,10 @@ class Frame; class TableVal final : public Val, public notifier::Modifiable { public: - explicit TableVal(IntrusivePtr t, IntrusivePtr attrs = nullptr); + explicit TableVal(IntrusivePtr t, IntrusivePtr attrs = nullptr); [[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]] - explicit TableVal(TableType* t, Attributes* attrs = nullptr) + explicit TableVal(zeek::TableType* t, Attributes* attrs = nullptr) : TableVal({NewRef{}, t}, {NewRef{}, attrs}) {} @@ -933,14 +939,14 @@ public: { return Remove(*k).release(); } // Returns a ListVal representation of the table (which must be a set). - IntrusivePtr ToListVal(TypeTag t = TYPE_ANY) const; + IntrusivePtr ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const; // Returns a ListVal representation of the table (which must be a set // with non-composite index type). IntrusivePtr ToPureListVal() const; [[deprecated("Remove in v4.1. Use ToListVal() instead.")]] - ListVal* ConvertToList(TypeTag t=TYPE_ANY) const; + ListVal* ConvertToList(zeek::TypeTag t=zeek::TYPE_ANY) const; [[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]] ListVal* ConvertToPureList() const; // must be single index type @@ -998,8 +1004,8 @@ public: notifier::Modifiable* Modifiable() override { return this; } // Retrieves and saves all table state (key-value pairs) for - // tables whose index type depends on the given RecordType. - static void SaveParseTimeTableState(RecordType* rt); + // tables whose index type depends on the given zeek::detail::RecordType. + static void SaveParseTimeTableState(zeek::RecordType* rt); // Rebuilds all TableVals whose state was previously saved by // SaveParseTimeTableState(). This is used to re-recreate the tables @@ -1007,13 +1013,13 @@ public: static void RebuildParseTimeTables(); // Clears all state that was used to track TableVals that depending - // on RecordTypes. + // on zeek::detail::RecordTypes. static void DoneParsing(); protected: - void Init(IntrusivePtr t); + void Init(IntrusivePtr t); - using TableRecordDependencies = std::unordered_map>>; + using TableRecordDependencies = std::unordered_map>>; using ParseTimeTableState = std::vector, IntrusivePtr>>; using ParseTimeTableStates = std::unordered_map; @@ -1050,7 +1056,7 @@ protected: IntrusivePtr DoClone(CloneState* state) override; - IntrusivePtr table_type; + IntrusivePtr table_type; CompositeHash* table_hash; IntrusivePtr attrs; IntrusivePtr expire_time; @@ -1070,8 +1076,8 @@ protected: class RecordVal final : public Val, public notifier::Modifiable { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - explicit RecordVal(RecordType* t, bool init_fields = true); - explicit RecordVal(IntrusivePtr t, bool init_fields = true); + explicit RecordVal(zeek::RecordType* t, bool init_fields = true); + explicit RecordVal(IntrusivePtr t, bool init_fields = true); ~RecordVal() override; @@ -1211,10 +1217,10 @@ public: // // The *allow_orphaning* parameter allows for a record to be demoted // down to a record type that contains less fields. - IntrusivePtr CoerceTo(IntrusivePtr other, + IntrusivePtr CoerceTo(IntrusivePtr other, IntrusivePtr aggr, bool allow_orphaning = false) const; - IntrusivePtr CoerceTo(IntrusivePtr other, + IntrusivePtr CoerceTo(IntrusivePtr other, bool allow_orphaning = false); unsigned int MemoryAllocation() const override; @@ -1225,7 +1231,7 @@ public: // Extend the underlying arrays of record instances created during // parsing to match the number of fields in the record type (they may // mismatch as a result of parse-time record type redefinitions. - static void ResizeParseTimeRecords(RecordType* rt); + static void ResizeParseTimeRecords(zeek::RecordType* rt); static void DoneParsing(); @@ -1234,7 +1240,7 @@ protected: BroObj* origin; - using RecordTypeValMap = std::unordered_map>>; + using RecordTypeValMap = std::unordered_map>>; static RecordTypeValMap parse_time_records; }; @@ -1244,12 +1250,12 @@ public: protected: friend class Val; - friend class EnumType; + friend class zeek::EnumType; template friend IntrusivePtr make_intrusive(Ts&&... args); - EnumVal(IntrusivePtr t, int i) : Val(bro_int_t(i), std::move(t)) + EnumVal(IntrusivePtr t, int i) : Val(bro_int_t(i), std::move(t)) {} void ValDescribe(ODesc* d) const override; @@ -1260,8 +1266,8 @@ protected: class VectorVal final : public Val, public notifier::Modifiable { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] - explicit VectorVal(VectorType* t); - explicit VectorVal(IntrusivePtr t); + explicit VectorVal(zeek::VectorType* t); + explicit VectorVal(IntrusivePtr t); ~VectorVal() override; IntrusivePtr SizeVal() const override; @@ -1366,7 +1372,7 @@ protected: // If not a match, generates an error message and return nil. If is_init is // true, then the checking is done in the context of an initialization. extern IntrusivePtr check_and_promote(IntrusivePtr v, - const BroType* t, bool is_init, + const zeek::BroType* t, bool is_init, const Location* expr_location = nullptr); extern bool same_val(const Val* v1, const Val* v2); @@ -1378,22 +1384,22 @@ extern void describe_vals(const std::vector>& vals, extern void delete_vals(val_list* vals); // True if the given Val* has a vector type. -inline bool is_vector(Val* v) { return v->GetType()->Tag() == TYPE_VECTOR; } +inline bool is_vector(Val* v) { return v->GetType()->Tag() == zeek::TYPE_VECTOR; } inline bool is_vector(const IntrusivePtr& v) { return is_vector(v.get()); } // Returns v casted to type T if the type supports that. Returns null if not. // // Note: This implements the script-level cast operator. -extern IntrusivePtr cast_value_to_type(Val* v, BroType* t); +extern IntrusivePtr cast_value_to_type(Val* v, zeek::BroType* t); // Returns true if v can be casted to type T. If so, check_and_cast() will // succeed as well. // // Note: This implements the script-level type comparision operator. -extern bool can_cast_value_to_type(const Val* v, BroType* t); +extern bool can_cast_value_to_type(const Val* v, zeek::BroType* t); // Returns true if values of type s may support casting to type t. This is // purely static check to weed out cases early on that will never succeed. // However, even this function returns true, casting may still fail for a // specific instance later. -extern bool can_cast_value_to_type(const BroType* s, BroType* t); +extern bool can_cast_value_to_type(const zeek::BroType* s, zeek::BroType* t); diff --git a/src/Var.cc b/src/Var.cc index 3b75239350..85dc5bcd83 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -19,7 +19,7 @@ using namespace zeek::detail; -static IntrusivePtr init_val(zeek::detail::Expr* init, const BroType* t, +static IntrusivePtr init_val(zeek::detail::Expr* init, const zeek::BroType* t, IntrusivePtr aggr) { try @@ -32,14 +32,14 @@ static IntrusivePtr init_val(zeek::detail::Expr* init, const BroType* t, } } -static bool add_prototype(const IntrusivePtr& id, BroType* t, +static bool add_prototype(const IntrusivePtr& id, zeek::BroType* t, std::vector>* attrs, const IntrusivePtr& init) { - if ( ! IsFunc(id->GetType()->Tag()) ) + if ( ! zeek::IsFunc(id->GetType()->Tag()) ) return false; - if ( ! IsFunc(t->Tag()) ) + if ( ! zeek::IsFunc(t->Tag()) ) { t->Error("type incompatible with previous definition", id.get()); return false; @@ -54,7 +54,7 @@ static bool add_prototype(const IntrusivePtr& id, BroType* t, return false; } - if ( canon_ft->Flavor() == FUNC_FLAVOR_FUNCTION ) + if ( canon_ft->Flavor() == zeek::FUNC_FLAVOR_FUNCTION ) { alt_ft->Error("redeclaration of function", canon_ft); return false; @@ -105,12 +105,12 @@ static bool add_prototype(const IntrusivePtr& id, BroType* t, if ( a->Tag() == zeek::detail::ATTR_DEPRECATED ) deprecated = true; - FuncType::Prototype p{deprecated, alt_args, std::move(offsets)}; + zeek::FuncType::Prototype p{deprecated, alt_args, std::move(offsets)}; canon_ft->AddPrototype(std::move(p)); return true; } -static void make_var(const IntrusivePtr& id, IntrusivePtr t, +static void make_var(const IntrusivePtr& id, IntrusivePtr t, zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, @@ -119,7 +119,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrGetType() ) { - if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) ) + if ( id->IsRedefinable() || (! init && attr && ! zeek::IsFunc(id->GetType()->Tag())) ) { BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); if ( dt != VAR_REDEF ) @@ -128,7 +128,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrGetType()->Tag()) ) + if ( zeek::IsFunc(id->GetType()->Tag()) ) add_prototype(id, t.get(), attr.get(), init); else id->Error("already defined", init.get()); @@ -149,10 +149,10 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrGetType(); } - if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR ) + if ( id->GetType() && id->GetType()->Tag() != zeek::TYPE_ERROR ) { if ( dt != VAR_REDEF && - (! init || ! do_init || (! t && ! (t = init_type(init.get())))) ) + (! init || ! do_init || (! t && ! (t = zeek::init_type(init.get())))) ) { id->Error("already defined", init.get()); return; @@ -168,7 +168,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrIsSet() ) { // Check for set with explicit elements. - SetType* st = t->AsTableType()->AsSetType(); + zeek::SetType* st = t->AsTableType()->AsSetType(); const auto& elements = st->Elements(); if ( elements ) @@ -191,10 +191,10 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrSetType(error_type()); + id->SetType(zeek::error_type()); return; } } @@ -245,9 +245,9 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr aggr; - if ( t->Tag() == TYPE_RECORD ) + if ( t->Tag() == zeek::TYPE_RECORD ) { - aggr = make_intrusive(cast_intrusive(t)); + aggr = make_intrusive(cast_intrusive(t)); if ( init && t ) // Have an initialization and type is not deduced. @@ -255,12 +255,12 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrAsRecordType()}); } - else if ( t->Tag() == TYPE_TABLE ) - aggr = make_intrusive(cast_intrusive(t), + else if ( t->Tag() == zeek::TYPE_TABLE ) + aggr = make_intrusive(cast_intrusive(t), id->GetAttrs()); - else if ( t->Tag() == TYPE_VECTOR ) - aggr = make_intrusive(cast_intrusive(t)); + else if ( t->Tag() == zeek::TYPE_VECTOR ) + aggr = make_intrusive(cast_intrusive(t)); IntrusivePtr v; @@ -297,9 +297,9 @@ static void make_var(const IntrusivePtr& id, IntrusivePtrUpdateValAttrs(); - if ( t && t->Tag() == TYPE_FUNC && - (t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT || - t->AsFuncType()->Flavor() == FUNC_FLAVOR_HOOK) ) + if ( t && t->Tag() == zeek::TYPE_FUNC && + (t->AsFuncType()->Flavor() == zeek::FUNC_FLAVOR_EVENT || + t->AsFuncType()->Flavor() == zeek::FUNC_FLAVOR_HOOK) ) { // For events, add a function value (without any body) here so that // we can later access the ID even if no implementations have been @@ -310,7 +310,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr& id, IntrusivePtr t, +void add_global(const IntrusivePtr& id, IntrusivePtr t, zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) @@ -318,7 +318,7 @@ void add_global(const IntrusivePtr& id, IntrusivePtr make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } -IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, +IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt) @@ -360,14 +360,14 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr t, +void add_type(zeek::detail::ID* id, IntrusivePtr t, std::unique_ptr>> attr) { std::string new_type_name = id->Name(); std::string old_type_name = t->GetName(); - IntrusivePtr tnew; + IntrusivePtr tnew; - if ( (t->Tag() == TYPE_RECORD || t->Tag() == TYPE_ENUM) && + if ( (t->Tag() == zeek::TYPE_RECORD || t->Tag() == zeek::TYPE_ENUM) && old_type_name.empty() ) // An extensible type (record/enum) being declared for first time. tnew = std::move(t); @@ -375,10 +375,10 @@ void add_type(zeek::detail::ID* id, IntrusivePtr t, // Clone the type to preserve type name aliasing. tnew = t->ShallowClone(); - BroType::AddAlias(new_type_name, tnew.get()); + zeek::BroType::AddAlias(new_type_name, tnew.get()); if ( new_type_name != old_type_name && ! old_type_name.empty() ) - BroType::AddAlias(old_type_name, tnew.get()); + zeek::BroType::AddAlias(old_type_name, tnew.get()); tnew->SetName(id->Name()); @@ -389,12 +389,12 @@ void add_type(zeek::detail::ID* id, IntrusivePtr t, id->SetAttrs(make_intrusive(std::move(*attr), tnew, false, false)); } -static void transfer_arg_defaults(RecordType* args, RecordType* recv) +static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv) { for ( int i = 0; i < args->NumFields(); ++i ) { - TypeDecl* args_i = args->FieldDecl(i); - TypeDecl* recv_i = recv->FieldDecl(i); + zeek::TypeDecl* args_i = args->FieldDecl(i); + zeek::TypeDecl* recv_i = recv->FieldDecl(i); const auto& def = args_i->attrs ? args_i->attrs->Find(zeek::detail::ATTR_DEFAULT) : nullptr; @@ -427,7 +427,7 @@ static zeek::detail::Attr* find_attr(const std::vector func_type_check(const FuncType* decl, const FuncType* impl) +static std::optional func_type_check(const zeek::FuncType* decl, const zeek::FuncType* impl) { if ( decl->Flavor() != impl->Flavor() ) { @@ -435,7 +435,7 @@ static std::optional func_type_check(const FuncType* decl, return {}; } - if ( impl->Flavor() == FUNC_FLAVOR_FUNCTION ) + if ( impl->Flavor() == zeek::FUNC_FLAVOR_FUNCTION ) { if ( same_type(decl, impl) ) return decl->Prototypes()[0]; @@ -447,7 +447,7 @@ static std::optional func_type_check(const FuncType* decl, return decl->FindPrototype(*impl->Params()); } -static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl) +static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::FuncType* impl) { const auto& canon_args = decl->Params(); const auto& impl_args = impl->Params(); @@ -463,21 +463,21 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl } void begin_func(IntrusivePtr id, const char* module_name, - function_flavor flavor, bool is_redef, - IntrusivePtr t, + zeek::FunctionFlavor flavor, bool is_redef, + IntrusivePtr t, std::unique_ptr>> attrs) { - if ( flavor == FUNC_FLAVOR_EVENT ) + if ( flavor == zeek::FUNC_FLAVOR_EVENT ) { const auto& yt = t->Yield(); - if ( yt && yt->Tag() != TYPE_VOID ) + if ( yt && yt->Tag() != zeek::TYPE_VOID ) id->Error("event cannot yield a value", t.get()); t->ClearYieldType(flavor); } - std::optional prototype; + std::optional prototype; if ( id->GetType() ) { @@ -486,7 +486,7 @@ void begin_func(IntrusivePtr id, const char* module_name, if ( prototype ) { - if ( decl->Flavor() == FUNC_FLAVOR_FUNCTION ) + if ( decl->Flavor() == zeek::FUNC_FLAVOR_FUNCTION ) { // If a previous declaration of the function had &default // params, automatically transfer any that are missing @@ -535,21 +535,21 @@ void begin_func(IntrusivePtr id, const char* module_name, if ( id->HasVal() ) { - function_flavor id_flavor = id->GetVal()->AsFunc()->Flavor(); + zeek::FunctionFlavor id_flavor = id->GetVal()->AsFunc()->Flavor(); if ( id_flavor != flavor ) id->Error("inconsistent function flavor", t.get()); switch ( id_flavor ) { - case FUNC_FLAVOR_EVENT: - case FUNC_FLAVOR_HOOK: + case zeek::FUNC_FLAVOR_EVENT: + case zeek::FUNC_FLAVOR_HOOK: if ( is_redef ) // Clear out value so it will be replaced. id->SetVal(nullptr); break; - case FUNC_FLAVOR_FUNCTION: + case zeek::FUNC_FLAVOR_FUNCTION: if ( ! id->IsRedefinable() ) id->Error("already defined"); break; @@ -569,7 +569,7 @@ void begin_func(IntrusivePtr id, const char* module_name, for ( int i = 0; i < num_args; ++i ) { - TypeDecl* arg_i = args->FieldDecl(i); + zeek::TypeDecl* arg_i = args->FieldDecl(i); auto arg_id = lookup_ID(arg_i->id, module_name); if ( arg_id && ! arg_id->IsGlobal() ) @@ -752,7 +752,7 @@ ListVal* internal_list_val(const char* name) if ( v ) { - if ( v->GetType()->Tag() == TYPE_LIST ) + if ( v->GetType()->Tag() == zeek::TYPE_LIST ) return (ListVal*) v; else if ( v->GetType()->IsSet() ) @@ -769,7 +769,7 @@ ListVal* internal_list_val(const char* name) return nullptr; } -BroType* internal_type(const char* name) +zeek::BroType* internal_type(const char* name) { return zeek::id::find_type(name).get(); } diff --git a/src/Var.h b/src/Var.h index f219277352..83809f2cbe 100644 --- a/src/Var.h +++ b/src/Var.h @@ -6,27 +6,27 @@ #include "ID.h" #include "Type.h" -class FuncType; class Scope; class EventHandlerPtr; class StringVal; class TableVal; class ListVal; +FORWARD_DECLARE_NAMESPACED(FuncType, zeek); FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; extern void add_global(const IntrusivePtr& id, - IntrusivePtr t, + IntrusivePtr t, zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, decl_type dt); extern IntrusivePtr add_local(IntrusivePtr id, - IntrusivePtr t, + IntrusivePtr t, zeek::detail::init_class c, IntrusivePtr init, std::unique_ptr>> attr, @@ -36,12 +36,12 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr init, IntrusivePtr val = nullptr); -extern void add_type(zeek::detail::ID* id, IntrusivePtr t, +extern void add_type(zeek::detail::ID* id, IntrusivePtr t, std::unique_ptr>> attr); extern void begin_func(IntrusivePtr id, const char* module_name, - function_flavor flavor, bool is_redef, - IntrusivePtr t, + zeek::FunctionFlavor flavor, bool is_redef, + IntrusivePtr t, std::unique_ptr>> attrs = nullptr); extern void end_func(IntrusivePtr body); @@ -77,7 +77,7 @@ extern TableVal* opt_internal_table(const char* name); // nil if not defined extern ListVal* internal_list_val(const char* name); [[deprecated("Remove in v4.1. Use zeek::id::find_type().")]] -extern BroType* internal_type(const char* name); +extern zeek::BroType* internal_type(const char* name); [[deprecated("Remove in v4.1. Use zeek::id::find_func().")]] extern Func* internal_func(const char* name); diff --git a/src/analyzer/protocol/asn1/asn1.pac b/src/analyzer/protocol/asn1/asn1.pac index 61ef62630d..4e87e11c1a 100644 --- a/src/analyzer/protocol/asn1/asn1.pac +++ b/src/analyzer/protocol/asn1/asn1.pac @@ -3,8 +3,8 @@ %} %header{ - IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, TypeTag t); - IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, TypeTag t); + IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t); + IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t); IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid); IntrusivePtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid); IntrusivePtr asn1_octet_string_to_val(const ASN1Encoding* s); @@ -102,25 +102,25 @@ function binary_to_int64(bs: bytestring): int64 %code{ -IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, TypeTag t) +IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t) { return asn1_integer_to_val(i->encoding(), t); } -IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, TypeTag t) +IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t) { auto v = binary_to_int64(i->content()); switch ( t ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: return val_mgr->Bool(v); - case TYPE_INT: + case zeek::TYPE_INT: return val_mgr->Int(v); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return val_mgr->Count(v); default: - reporter->Error("bad asn1_integer_to_val tag: %s", type_name(t)); + reporter->Error("bad asn1_integer_to_val tag: %s", zeek::type_name(t)); return val_mgr->Count(v); } } diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 4172929eab..c73644991a 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -15,11 +15,11 @@ using namespace analyzer::bittorrent; -static IntrusivePtr bt_tracker_headers; -static IntrusivePtr bittorrent_peer; -static IntrusivePtr bittorrent_peer_set; -static IntrusivePtr bittorrent_benc_value; -static IntrusivePtr bittorrent_benc_dir; +static IntrusivePtr bt_tracker_headers; +static IntrusivePtr bittorrent_peer; +static IntrusivePtr bittorrent_peer_set; +static IntrusivePtr bittorrent_benc_value; +static IntrusivePtr bittorrent_benc_dir; BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) : tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c) @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - zeek::id::find_type("bt_tracker_headers"); + zeek::id::find_type("bt_tracker_headers"); bittorrent_peer = - zeek::id::find_type("bittorrent_peer"); + zeek::id::find_type("bittorrent_peer"); bittorrent_peer_set = - zeek::id::find_type("bittorrent_peer_set"); + zeek::id::find_type("bittorrent_peer_set"); bittorrent_benc_value = - zeek::id::find_type("bittorrent_benc_value"); + zeek::id::find_type("bittorrent_benc_value"); bittorrent_benc_dir = - zeek::id::find_type("bittorrent_benc_dir"); + zeek::id::find_type("bittorrent_benc_dir"); } keep_alive = false; diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index 07f92fcd3f..1228322d39 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -119,4 +119,3 @@ refine typeattr DHCP_Message += &let { refine typeattr Option += &let { proc_create_options = $context.flow.create_options(code); }; - diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 61fe7a1ae6..e505c61b81 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -594,7 +594,7 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { - static auto dns_soa = zeek::id::find_type("dns_soa"); + static auto dns_soa = zeek::id::find_type("dns_soa"); auto r = make_intrusive(dns_soa); r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); @@ -1438,7 +1438,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) IntrusivePtr DNS_MsgInfo::BuildHdrVal() { - static auto dns_msg = zeek::id::find_type("dns_msg"); + static auto dns_msg = zeek::id::find_type("dns_msg"); auto r = make_intrusive(dns_msg); r->Assign(0, val_mgr->Count(id)); @@ -1460,7 +1460,7 @@ IntrusivePtr DNS_MsgInfo::BuildHdrVal() IntrusivePtr DNS_MsgInfo::BuildAnswerVal() { - static auto dns_answer = zeek::id::find_type("dns_answer"); + static auto dns_answer = zeek::id::find_type("dns_answer"); auto r = make_intrusive(dns_answer); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1476,7 +1476,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. - static auto dns_edns_additional = zeek::id::find_type("dns_edns_additional"); + static auto dns_edns_additional = zeek::id::find_type("dns_edns_additional"); auto r = make_intrusive(dns_edns_additional); r->Assign(0, val_mgr->Count(int(answer_type))); @@ -1510,7 +1510,7 @@ IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { - static auto dns_tsig_additional = zeek::id::find_type("dns_tsig_additional"); + static auto dns_tsig_additional = zeek::id::find_type("dns_tsig_additional"); auto r = make_intrusive(dns_tsig_additional); double rtime = tsig->time_s + tsig->time_ms / 1000.0; @@ -1530,7 +1530,7 @@ IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { - static auto dns_rrsig_rr = zeek::id::find_type("dns_rrsig_rr"); + static auto dns_rrsig_rr = zeek::id::find_type("dns_rrsig_rr"); auto r = make_intrusive(dns_rrsig_rr); r->Assign(0, query_name); @@ -1551,7 +1551,7 @@ IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { - static auto dns_dnskey_rr = zeek::id::find_type("dns_dnskey_rr"); + static auto dns_dnskey_rr = zeek::id::find_type("dns_dnskey_rr"); auto r = make_intrusive(dns_dnskey_rr); r->Assign(0, query_name); @@ -1567,7 +1567,7 @@ IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { - static auto dns_nsec3_rr = zeek::id::find_type("dns_nsec3_rr"); + static auto dns_nsec3_rr = zeek::id::find_type("dns_nsec3_rr"); auto r = make_intrusive(dns_nsec3_rr); r->Assign(0, query_name); @@ -1587,7 +1587,7 @@ IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { - static auto dns_ds_rr = zeek::id::find_type("dns_ds_rr"); + static auto dns_ds_rr = zeek::id::find_type("dns_ds_rr"); auto r = make_intrusive(dns_ds_rr); r->Assign(0, query_name); diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index b5b4bfdef3..a4e4d2befe 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -615,7 +615,7 @@ HTTP_Message::~HTTP_Message() IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { - static auto http_message_stat = zeek::id::find_type("http_message_stat"); + static auto http_message_stat = zeek::id::find_type("http_message_stat"); auto stat = make_intrusive(http_message_stat); int field = 0; stat->Assign(field++, make_intrusive(start_time)); @@ -1152,7 +1152,7 @@ void HTTP_Analyzer::GenStats() { if ( http_stats ) { - static auto http_stats_rec = zeek::id::find_type("http_stats_rec"); + static auto http_stats_rec = zeek::id::find_type("http_stats_rec"); auto r = make_intrusive(http_stats_rec); r->Assign(0, val_mgr->Count(num_requests)); r->Assign(1, val_mgr->Count(num_replies)); diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 664a5a8cdd..c1677c315b 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -225,7 +225,7 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, { if ( ! icmp_conn_val ) { - static auto icmp_conn = zeek::id::find_type("icmp_conn"); + static auto icmp_conn = zeek::id::find_type("icmp_conn"); icmp_conn_val = make_intrusive(icmp_conn); icmp_conn_val->Assign(0, make_intrusive(Conn()->OrigAddr())); @@ -351,7 +351,7 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char } } - static auto icmp_context = zeek::id::find_type("icmp_context"); + static auto icmp_context = zeek::id::find_type("icmp_context"); auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::id::conn_id); @@ -411,7 +411,7 @@ IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char } } - static auto icmp_context = zeek::id::find_type("icmp_context"); + static auto icmp_context = zeek::id::find_type("icmp_context"); auto iprec = make_intrusive(icmp_context); auto id_val = make_intrusive(zeek::id::conn_id); @@ -724,11 +724,11 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp, IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) { - static auto icmp6_nd_option_type = zeek::id::find_type("icmp6_nd_option"); - static auto icmp6_nd_prefix_info_type = zeek::id::find_type("icmp6_nd_prefix_info"); + static auto icmp6_nd_option_type = zeek::id::find_type("icmp6_nd_option"); + static auto icmp6_nd_prefix_info_type = zeek::id::find_type("icmp6_nd_prefix_info"); auto vv = make_intrusive( - zeek::id::find_type("icmp6_nd_options")); + zeek::id::find_type("icmp6_nd_options")); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/irc/IRC.cc b/src/analyzer/protocol/irc/IRC.cc index 583206bbf7..4c1e817a99 100644 --- a/src/analyzer/protocol/irc/IRC.cc +++ b/src/analyzer/protocol/irc/IRC.cc @@ -44,8 +44,8 @@ inline void IRC_Analyzer::SkipLeadingWhitespace(string& str) void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) { - static auto irc_join_list = zeek::id::find_type("irc_join_list"); - static auto irc_join_info = zeek::id::find_type("irc_join_info"); + static auto irc_join_list = zeek::id::find_type("irc_join_list"); + static auto irc_join_info = zeek::id::find_type("irc_join_info"); tcp::TCP_ApplicationAnalyzer::DeliverStream(length, line, orig); if ( starttls ) diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index 928cdf4fd5..3d19ef2777 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -31,8 +31,8 @@ IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAn { auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Request); - rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), zeek::TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), zeek::TYPE_COUNT)); if ( msg->padata()->has_padata() ) rv->Assign(2, proc_padata(msg->padata()->padata()->padata(), bro_analyzer, false)); @@ -64,7 +64,7 @@ IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAn rv->Assign(9, GetTimeFromAsn1(element->data()->rtime(), 0)); break; case 7: - rv->Assign(10, asn1_integer_to_val(element->data()->nonce(), TYPE_COUNT)); + rv->Assign(10, asn1_integer_to_val(element->data()->nonce(), zeek::TYPE_COUNT)); break; case 8: if ( element->data()->etype()->data()->size() ) @@ -132,10 +132,10 @@ bool proc_error_arguments(RecordVal* rv, const std::vector* args switch ( (*args)[i]->seq_meta()->index() ) { case 0: - rv->Assign(0, asn1_integer_to_val((*args)[i]->args()->pvno(), TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val((*args)[i]->args()->pvno(), zeek::TYPE_COUNT)); break; case 1: - rv->Assign(1, asn1_integer_to_val((*args)[i]->args()->msg_type(), TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val((*args)[i]->args()->msg_type(), zeek::TYPE_COUNT)); break; // ctime/stime handled above case 7: @@ -205,8 +205,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::KDC_Response); - rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT)); if ( ${msg.padata.has_padata} ) rv->Assign(2, proc_padata(${msg.padata.padata.padata}, bro_analyzer(), false)); @@ -246,7 +246,7 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::Error_Msg); proc_error_arguments(rv.get(), ${msg.args1}, 0); - rv->Assign(4, asn1_integer_to_val(${msg.error_code}, TYPE_COUNT)); + rv->Assign(4, asn1_integer_to_val(${msg.error_code}, zeek::TYPE_COUNT)); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); zeek::BifEvent::enqueue_krb_error(bro_analyzer(), bro_analyzer()->Conn(), std::move(rv)); } @@ -291,8 +291,8 @@ refine connection KRB_Conn += { { auto rv = make_intrusive(zeek::BifType::Record::KRB::SAFE_Msg); - rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, TYPE_COUNT)); - rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT)); + rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT)); uint timestamp_i = 0; int64 timestamp_usecs = 0; @@ -325,7 +325,7 @@ refine connection KRB_Conn += { rv->Assign(3, to_stringval(${msg.safe_body.args[i].args.user_data.encoding.content})); break; case 3: - rv->Assign(5, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, TYPE_COUNT)); + rv->Assign(5, asn1_integer_to_val(${msg.safe_body.args[i].args.seq_number}, zeek::TYPE_COUNT)); break; case 4: rv->Assign(6, proc_host_address(bro_analyzer(), ${msg.safe_body.args[i].args.sender_addr})); diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 957df4e789..003fb43e7b 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,7 +13,7 @@ IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroA %code{ IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - auto vv = make_intrusive(zeek::id::find_type("KRB::Type_Value_Vector")); + auto vv = make_intrusive(zeek::id::find_type("KRB::Type_Value_Vector")); if ( ! data->data()->has_padata() ) return vv; @@ -192,7 +192,7 @@ type KRB_PA_Data_Element(is_orig: bool, type: int64, length: uint64) = case type }; type KRB_PA_AP_REQ_wrapper(is_orig: bool) = record { - # Not sure what these two field are, but they need to be + # Not sure what these two field are, but they need to be # here for pre-auth ap-req messages. some_meta1 : ASN1EncodingMeta; some_meta2 : ASN1EncodingMeta; diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 20ef1ea3bb..f9c3e24d84 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -29,13 +29,13 @@ IntrusivePtr proc_cipher_list(const Array* list) { auto ciphers = make_intrusive(zeek::id::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) - ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); + ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], zeek::TYPE_COUNT)); return ciphers; } IntrusivePtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - auto addrs = make_intrusive(zeek::id::find_type("KRB::Host_Address_Vector")); + auto addrs = make_intrusive(zeek::id::find_type("KRB::Host_Address_Vector")); for ( uint i = 0; i < list->addresses()->size(); ++i ) { @@ -86,7 +86,7 @@ IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Ad } auto unk = make_intrusive(zeek::BifType::Record::KRB::Type_Value); - unk->Assign(0, asn1_integer_to_val(addr->addr_type(), TYPE_COUNT)); + unk->Assign(0, asn1_integer_to_val(addr->addr_type(), zeek::TYPE_COUNT)); unk->Assign(1, to_stringval(addr_bytes)); rv->Assign(2, std::move(unk)); return rv; @@ -94,7 +94,7 @@ IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Ad IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(zeek::id::find_type("KRB::Ticket_Vector")); + auto tickets = make_intrusive(zeek::id::find_type("KRB::Ticket_Vector")); for ( uint i = 0; i < list->tickets()->size(); ++i ) { @@ -109,10 +109,10 @@ IntrusivePtr proc_ticket(const KRB_Ticket* ticket) { auto rv = make_intrusive(zeek::BifType::Record::KRB::Ticket); - rv->Assign(0, asn1_integer_to_val(ticket->tkt_vno()->data(), TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val(ticket->tkt_vno()->data(), zeek::TYPE_COUNT)); rv->Assign(1, to_stringval(ticket->realm()->data()->content())); rv->Assign(2, GetStringFromPrincipalName(ticket->sname())); - rv->Assign(3, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), TYPE_COUNT)); + rv->Assign(3, asn1_integer_to_val(ticket->enc_part()->data()->etype()->data(), zeek::TYPE_COUNT)); rv->Assign(4, to_stringval(ticket->enc_part()->data()->ciphertext()->encoding()->content())); return rv; @@ -189,4 +189,3 @@ type KRB_Checksum = record { checksum_type: SequenceElement(true); checksum : SequenceElement(true); }; - diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index dbe81f41a9..a69d0e039f 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1301,7 +1301,7 @@ RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h) IntrusivePtr MIME_Message::ToHeaderVal(MIME_Header* h) { - static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); auto header_record = make_intrusive(mime_header_rec); header_record->Assign(0, to_string_val(h->get_name())); auto upper_hn = to_string_val(h->get_name()); @@ -1316,7 +1316,7 @@ TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) IntrusivePtr MIME_Message::ToHeaderTable(MIME_HeaderList& hlist) { - static auto mime_header_list = zeek::id::find_type("mime_header_list"); + static auto mime_header_list = zeek::id::find_type("mime_header_list"); auto t = make_intrusive(mime_header_list); for ( unsigned int i = 0; i < hlist.size(); ++i ) diff --git a/src/analyzer/protocol/modbus/modbus-analyzer.pac b/src/analyzer/protocol/modbus/modbus-analyzer.pac index 9d5de6a705..06271c82e6 100644 --- a/src/analyzer/protocol/modbus/modbus-analyzer.pac +++ b/src/analyzer/protocol/modbus/modbus-analyzer.pac @@ -39,7 +39,7 @@ IntrusivePtr create_vector_of_count() { - auto vt = make_intrusive(base_type(TYPE_COUNT)); + auto vt = make_intrusive(zeek::base_type(zeek::TYPE_COUNT)); auto vv = make_intrusive(std::move(vt)); return vv; } diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index 43d878971a..7b4f38e288 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -201,4 +201,3 @@ refine typeattr NTLM_Challenge += &let { refine typeattr NTLM_Authenticate += &let { proc : bool = $context.connection.proc_ntlm_authenticate(this); }; - diff --git a/src/analyzer/protocol/ntp/ntp-analyzer.pac b/src/analyzer/protocol/ntp/ntp-analyzer.pac index 13731762c6..1e08505da4 100644 --- a/src/analyzer/protocol/ntp/ntp-analyzer.pac +++ b/src/analyzer/protocol/ntp/ntp-analyzer.pac @@ -160,4 +160,3 @@ refine flow NTP_Flow += { refine typeattr NTP_PDU += &let { proc: bool = $context.flow.proc_ntp_message(this); }; - diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index 775765e1b4..2e9d2d46bd 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -258,7 +258,7 @@ IntrusivePtr MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& auth_flavors_count = max_auth_flavors; } - auto enum_vector = make_intrusive(base_type(TYPE_ENUM)); + auto enum_vector = make_intrusive(zeek::base_type(zeek::TYPE_ENUM)); auto auth_flavors = make_intrusive(std::move(enum_vector)); for ( auto i = 0u; i < auth_flavors_count; ++i ) diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 5fb2fb878e..e69bb9d487 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -138,7 +138,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu event = success ? pm_request_dump : pm_attempt_dump; if ( success ) { - static auto pm_mappings = zeek::id::find_type("pm_mappings"); + static auto pm_mappings = zeek::id::find_type("pm_mappings"); auto mappings = make_intrusive(pm_mappings); uint32_t nmap = 0; @@ -191,7 +191,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu IntrusivePtr PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { - static auto pm_mapping = zeek::id::find_type("pm_mapping"); + static auto pm_mapping = zeek::id::find_type("pm_mapping"); auto mapping = make_intrusive(pm_mapping); mapping->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -209,7 +209,7 @@ IntrusivePtr PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) IntrusivePtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { - static auto pm_port_request = zeek::id::find_type("pm_port_request"); + static auto pm_port_request = zeek::id::find_type("pm_port_request"); auto pr = make_intrusive(pm_port_request); pr->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); @@ -227,7 +227,7 @@ IntrusivePtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& IntrusivePtr PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { - static auto pm_callit_request = zeek::id::find_type("pm_callit_request"); + static auto pm_callit_request = zeek::id::find_type("pm_callit_request"); auto c = make_intrusive(pm_callit_request); c->Assign(0, val_mgr->Count(extract_XDR_uint32(buf, len))); diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index aad9df3a14..4a754dcd65 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -67,7 +67,7 @@ refine flow SIP_Flow += { function build_sip_headers_val(): BroVal %{ - static auto mime_header_list = zeek::id::find_type("mime_header_list"); + static auto mime_header_list = zeek::id::find_type("mime_header_list"); TableVal* t = new TableVal(mime_header_list); for ( unsigned int i = 0; i < headers.size(); ++i ) @@ -102,7 +102,7 @@ refine flow SIP_Flow += { function build_sip_header_val(name: const_bytestring, value: const_bytestring): BroVal %{ - static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); + static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); RecordVal* header_record = new RecordVal(mime_header_rec); IntrusivePtr name_val; diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index 4793405697..3b4af47cf5 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -61,14 +61,14 @@ IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) break; case ASN1_INTEGER_TAG: - rval->Assign(2, asn1_integer_to_val(obj, TYPE_INT)); + rval->Assign(2, asn1_integer_to_val(obj, zeek::TYPE_INT)); break; case APP_COUNTER32_TAG: case APP_UNSIGNED32_TAG: case APP_TIMETICKS_TAG: case APP_COUNTER64_TAG: - rval->Assign(3, asn1_integer_to_val(obj, TYPE_COUNT)); + rval->Assign(3, asn1_integer_to_val(obj, zeek::TYPE_COUNT)); break; case APP_IPADDRESS_TAG: @@ -87,7 +87,7 @@ IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) IntrusivePtr time_ticks_to_val(const TimeTicks* tt) { - return asn1_integer_to_val(tt->asn1_integer(), TYPE_COUNT); + return asn1_integer_to_val(tt->asn1_integer(), zeek::TYPE_COUNT); } IntrusivePtr build_hdr(const Header* header) @@ -130,13 +130,13 @@ IntrusivePtr build_hdrV3(const Header* header) bytestring const& flags = global_data->flags()->encoding()->content(); uint8 flags_byte = flags.length() > 0 ? flags[0] : 0; - v3->Assign(0, asn1_integer_to_val(global_data->id(), TYPE_COUNT)); - v3->Assign(1, asn1_integer_to_val(global_data->max_size(), TYPE_COUNT)); + v3->Assign(0, asn1_integer_to_val(global_data->id(), zeek::TYPE_COUNT)); + v3->Assign(1, asn1_integer_to_val(global_data->max_size(), zeek::TYPE_COUNT)); v3->Assign(2, val_mgr->Count(flags_byte)); v3->Assign(3, val_mgr->Bool(flags_byte & 0x01)); v3->Assign(4, val_mgr->Bool(flags_byte & 0x02)); v3->Assign(5, val_mgr->Bool(flags_byte & 0x04)); - v3->Assign(6, asn1_integer_to_val(global_data->security_model(), TYPE_COUNT)); + v3->Assign(6, asn1_integer_to_val(global_data->security_model(), zeek::TYPE_COUNT)); v3->Assign(7, asn1_octet_string_to_val(v3hdr->security_parameters())); if ( v3hdr->next()->tag() == ASN1_SEQUENCE_TAG ) @@ -170,9 +170,9 @@ IntrusivePtr build_bindings(const VarBindList* vbl) IntrusivePtr build_pdu(const CommonPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::PDU); - rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); - rv->Assign(1, asn1_integer_to_val(pdu->error_status(), TYPE_INT)); - rv->Assign(2, asn1_integer_to_val(pdu->error_index(), TYPE_INT)); + rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); + rv->Assign(1, asn1_integer_to_val(pdu->error_status(), zeek::TYPE_INT)); + rv->Assign(2, asn1_integer_to_val(pdu->error_index(), zeek::TYPE_INT)); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } @@ -182,8 +182,8 @@ IntrusivePtr build_trap_pdu(const TrapPDU* pdu) auto rv = make_intrusive(zeek::BifType::Record::SNMP::TrapPDU); rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); rv->Assign(1, network_address_to_val(pdu->agent_addr())); - rv->Assign(2, asn1_integer_to_val(pdu->generic_trap(), TYPE_INT)); - rv->Assign(3, asn1_integer_to_val(pdu->specific_trap(), TYPE_INT)); + rv->Assign(2, asn1_integer_to_val(pdu->generic_trap(), zeek::TYPE_INT)); + rv->Assign(3, asn1_integer_to_val(pdu->specific_trap(), zeek::TYPE_INT)); rv->Assign(4, time_ticks_to_val(pdu->time_stamp())); rv->Assign(5, build_bindings(pdu->var_bindings())); return rv; @@ -192,9 +192,9 @@ IntrusivePtr build_trap_pdu(const TrapPDU* pdu) IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu) { auto rv = make_intrusive(zeek::BifType::Record::SNMP::BulkPDU); - rv->Assign(0, asn1_integer_to_val(pdu->request_id(), TYPE_INT)); - rv->Assign(1, asn1_integer_to_val(pdu->non_repeaters(), TYPE_COUNT)); - rv->Assign(2, asn1_integer_to_val(pdu->max_repititions(), TYPE_COUNT)); + rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); + rv->Assign(1, asn1_integer_to_val(pdu->non_repeaters(), zeek::TYPE_COUNT)); + rv->Assign(2, asn1_integer_to_val(pdu->max_repititions(), zeek::TYPE_COUNT)); rv->Assign(3, build_bindings(pdu->var_bindings())); return rv; } @@ -373,7 +373,7 @@ refine connection SNMP_Conn += { %{ if ( ! ${rec.is_orig} ) bro_analyzer()->ProtocolConfirmation(); - + if ( rec->unknown() ) return false; diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index fe45150215..7c7932fb02 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -24,7 +24,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_request ) { - static auto socks_address = zeek::id::find_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${request.addr}))); @@ -49,7 +49,7 @@ refine connection SOCKS_Conn += { %{ if ( socks_reply ) { - static auto socks_address = zeek::id::find_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); sa->Assign(0, make_intrusive(htonl(${reply.addr}))); @@ -82,7 +82,7 @@ refine connection SOCKS_Conn += { return false; } - static auto socks_address = zeek::id::find_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... @@ -122,7 +122,7 @@ refine connection SOCKS_Conn += { function socks5_reply(reply: SOCKS5_Reply): bool %{ - static auto socks_address = zeek::id::find_type("SOCKS::Address"); + static auto socks_address = zeek::id::find_type("SOCKS::Address"); auto sa = make_intrusive(socks_address); // This is dumb and there must be a better way (checking for presence of a field)... diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 7db8d7584f..e0ae9bdb5a 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(zeek::id::find_type("signature_and_hashalgorithm_vec")); + auto slist = make_intrusive(zeek::id::find_type("signature_and_hashalgorithm_vec")); if ( supported_signature_algorithms ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(zeek::id::find_type("psk_identity_vec")); + auto slist = make_intrusive(zeek::id::find_type("psk_identity_vec")); if ( identities && identities->identities() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index d61c246c8f..4415566c01 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -107,7 +107,7 @@ static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, options += opt_len; } - static auto SYN_packet = zeek::id::find_type("SYN_packet"); + static auto SYN_packet = zeek::id::find_type("SYN_packet"); RecordVal* v = new RecordVal(SYN_packet); v->Assign(0, val_mgr->Bool(is_orig)); @@ -2078,7 +2078,7 @@ bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int capl RecordVal* TCPStats_Endpoint::BuildStats() { - static auto endpoint_stats = zeek::id::find_type("endpoint_stats"); + static auto endpoint_stats = zeek::id::find_type("endpoint_stats"); RecordVal* stats = new RecordVal(endpoint_stats); stats->Assign(0, val_mgr->Count(num_pkts)); diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index e37ef7d18f..263aa4d334 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -98,9 +98,9 @@ bool TeredoEncapsulation::DoParse(const u_char* data, int& len, IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const { - static auto teredo_hdr_type = zeek::id::find_type("teredo_hdr"); - static auto teredo_auth_type = zeek::id::find_type("teredo_auth"); - static auto teredo_origin_type = zeek::id::find_type("teredo_origin"); + static auto teredo_hdr_type = zeek::id::find_type("teredo_hdr"); + static auto teredo_auth_type = zeek::id::find_type("teredo_auth"); + static auto teredo_origin_type = zeek::id::find_type("teredo_origin"); auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 09758077df..b101f09ed8 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -14,13 +14,13 @@ using namespace std; -IntrusivePtr bro_broker::opaque_of_data_type; -IntrusivePtr bro_broker::opaque_of_set_iterator; -IntrusivePtr bro_broker::opaque_of_table_iterator; -IntrusivePtr bro_broker::opaque_of_vector_iterator; -IntrusivePtr bro_broker::opaque_of_record_iterator; +IntrusivePtr bro_broker::opaque_of_data_type; +IntrusivePtr bro_broker::opaque_of_set_iterator; +IntrusivePtr bro_broker::opaque_of_table_iterator; +IntrusivePtr bro_broker::opaque_of_vector_iterator; +IntrusivePtr bro_broker::opaque_of_record_iterator; -static bool data_type_check(const broker::data& d, BroType* t); +static bool data_type_check(const broker::data& d, zeek::BroType* t); static broker::port::protocol to_broker_port_proto(TransportProto tp) { @@ -75,7 +75,7 @@ TEST_CASE("converting Broker to Zeek protocol constants") struct val_converter { using result_type = IntrusivePtr; - BroType* type; + zeek::BroType* type; result_type operator()(broker::none) { @@ -84,30 +84,30 @@ struct val_converter { result_type operator()(bool a) { - if ( type->Tag() == TYPE_BOOL ) + if ( type->Tag() == zeek::TYPE_BOOL ) return val_mgr->Bool(a); return nullptr; } result_type operator()(uint64_t a) { - if ( type->Tag() == TYPE_COUNT ) + if ( type->Tag() == zeek::TYPE_COUNT ) return val_mgr->Count(a); - if ( type->Tag() == TYPE_COUNTER ) + if ( type->Tag() == zeek::TYPE_COUNTER ) return val_mgr->Count(a); return nullptr; } result_type operator()(int64_t a) { - if ( type->Tag() == TYPE_INT ) + if ( type->Tag() == zeek::TYPE_INT ) return val_mgr->Int(a); return nullptr; } result_type operator()(double a) { - if ( type->Tag() == TYPE_DOUBLE ) + if ( type->Tag() == zeek::TYPE_DOUBLE ) return make_intrusive(a); return nullptr; } @@ -115,9 +115,9 @@ struct val_converter { result_type operator()(std::string& a) { switch ( type->Tag() ) { - case TYPE_STRING: + case zeek::TYPE_STRING: return make_intrusive(a.size(), a.data()); - case TYPE_FILE: + case zeek::TYPE_FILE: { auto file = BroFile::Get(a.data()); @@ -133,7 +133,7 @@ struct val_converter { result_type operator()(broker::address& a) { - if ( type->Tag() == TYPE_ADDR ) + if ( type->Tag() == zeek::TYPE_ADDR ) { auto bits = reinterpret_cast(&a.bytes()); return make_intrusive(IPAddr(*bits)); @@ -144,7 +144,7 @@ struct val_converter { result_type operator()(broker::subnet& a) { - if ( type->Tag() == TYPE_SUBNET ) + if ( type->Tag() == zeek::TYPE_SUBNET ) { auto bits = reinterpret_cast(&a.network().bytes()); return make_intrusive(IPPrefix(IPAddr(*bits), a.length())); @@ -155,7 +155,7 @@ struct val_converter { result_type operator()(broker::port& a) { - if ( type->Tag() == TYPE_PORT ) + if ( type->Tag() == zeek::TYPE_PORT ) return val_mgr->Port(a.number(), bro_broker::to_bro_port_proto(a.type())); return nullptr; @@ -163,7 +163,7 @@ struct val_converter { result_type operator()(broker::timestamp& a) { - if ( type->Tag() != TYPE_TIME ) + if ( type->Tag() != zeek::TYPE_TIME ) return nullptr; using namespace std::chrono; @@ -173,7 +173,7 @@ struct val_converter { result_type operator()(broker::timespan& a) { - if ( type->Tag() != TYPE_INTERVAL ) + if ( type->Tag() != zeek::TYPE_INTERVAL ) return nullptr; using namespace std::chrono; @@ -183,7 +183,7 @@ struct val_converter { result_type operator()(broker::enum_value& a) { - if ( type->Tag() == TYPE_ENUM ) + if ( type->Tag() == zeek::TYPE_ENUM ) { auto etype = type->AsEnumType(); auto i = etype->Lookup(GLOBAL_MODULE_NAME, a.name.data()); @@ -217,8 +217,8 @@ struct val_converter { if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - expected_index_types[0]->Tag() == TYPE_RECORD || - expected_index_types[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == zeek::TYPE_RECORD || + expected_index_types[0]->Tag() == zeek::TYPE_VECTOR; if ( index_is_vector_or_record ) { @@ -237,7 +237,7 @@ struct val_converter { if ( expected_index_types.size() != indices->size() ) return nullptr; - auto list_val = make_intrusive(TYPE_ANY); + auto list_val = make_intrusive(zeek::TYPE_ANY); for ( auto i = 0u; i < indices->size(); ++i ) { @@ -276,8 +276,8 @@ struct val_converter { if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - expected_index_types[0]->Tag() == TYPE_RECORD || - expected_index_types[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == zeek::TYPE_RECORD || + expected_index_types[0]->Tag() == zeek::TYPE_VECTOR; if ( index_is_vector_or_record ) { @@ -296,7 +296,7 @@ struct val_converter { if ( expected_index_types.size() != indices->size() ) return nullptr; - auto list_val = make_intrusive(TYPE_ANY); + auto list_val = make_intrusive(zeek::TYPE_ANY); for ( auto i = 0u; i < indices->size(); ++i ) { @@ -323,7 +323,7 @@ struct val_converter { result_type operator()(broker::vector& a) { - if ( type->Tag() == TYPE_VECTOR ) + if ( type->Tag() == zeek::TYPE_VECTOR ) { auto vt = type->AsVectorType(); auto rval = make_intrusive(IntrusivePtr{NewRef{}, vt}); @@ -340,7 +340,7 @@ struct val_converter { return rval; } - else if ( type->Tag() == TYPE_FUNC ) + else if ( type->Tag() == zeek::TYPE_FUNC ) { if ( a.size() < 1 || a.size() > 2 ) return nullptr; @@ -361,7 +361,7 @@ struct val_converter { if ( ! t ) return nullptr; - if ( t->Tag() != TYPE_FUNC ) + if ( t->Tag() != zeek::TYPE_FUNC ) return nullptr; if ( a.size() == 2 ) // We have a closure. @@ -380,7 +380,7 @@ struct val_converter { return rval; } - else if ( type->Tag() == TYPE_RECORD ) + else if ( type->Tag() == zeek::TYPE_RECORD ) { auto rt = type->AsRecordType(); auto rval = make_intrusive(IntrusivePtr{NewRef{}, rt}); @@ -410,7 +410,7 @@ struct val_converter { return rval; } - else if ( type->Tag() == TYPE_PATTERN ) + else if ( type->Tag() == zeek::TYPE_PATTERN ) { if ( a.size() != 2 ) return nullptr; @@ -435,7 +435,7 @@ struct val_converter { auto rval = make_intrusive(re); return rval; } - else if ( type->Tag() == TYPE_OPAQUE ) + else if ( type->Tag() == zeek::TYPE_OPAQUE ) return OpaqueVal::Unserialize(a); return nullptr; @@ -445,7 +445,7 @@ struct val_converter { struct type_checker { using result_type = bool; - BroType* type; + zeek::BroType* type; result_type operator()(broker::none) { @@ -454,30 +454,30 @@ struct type_checker { result_type operator()(bool a) { - if ( type->Tag() == TYPE_BOOL ) + if ( type->Tag() == zeek::TYPE_BOOL ) return true; return false; } result_type operator()(uint64_t a) { - if ( type->Tag() == TYPE_COUNT ) + if ( type->Tag() == zeek::TYPE_COUNT ) return true; - if ( type->Tag() == TYPE_COUNTER ) + if ( type->Tag() == zeek::TYPE_COUNTER ) return true; return false; } result_type operator()(int64_t a) { - if ( type->Tag() == TYPE_INT ) + if ( type->Tag() == zeek::TYPE_INT ) return true; return false; } result_type operator()(double a) { - if ( type->Tag() == TYPE_DOUBLE ) + if ( type->Tag() == zeek::TYPE_DOUBLE ) return true; return false; } @@ -485,9 +485,9 @@ struct type_checker { result_type operator()(const std::string& a) { switch ( type->Tag() ) { - case TYPE_STRING: + case zeek::TYPE_STRING: return true; - case TYPE_FILE: + case zeek::TYPE_FILE: return true; default: return false; @@ -496,7 +496,7 @@ struct type_checker { result_type operator()(const broker::address& a) { - if ( type->Tag() == TYPE_ADDR ) + if ( type->Tag() == zeek::TYPE_ADDR ) return true; return false; @@ -504,7 +504,7 @@ struct type_checker { result_type operator()(const broker::subnet& a) { - if ( type->Tag() == TYPE_SUBNET ) + if ( type->Tag() == zeek::TYPE_SUBNET ) return true; return false; @@ -512,7 +512,7 @@ struct type_checker { result_type operator()(const broker::port& a) { - if ( type->Tag() == TYPE_PORT ) + if ( type->Tag() == zeek::TYPE_PORT ) return true; return false; @@ -520,7 +520,7 @@ struct type_checker { result_type operator()(const broker::timestamp& a) { - if ( type->Tag() == TYPE_TIME ) + if ( type->Tag() == zeek::TYPE_TIME ) return true; return false; @@ -528,7 +528,7 @@ struct type_checker { result_type operator()(const broker::timespan& a) { - if ( type->Tag() == TYPE_INTERVAL ) + if ( type->Tag() == zeek::TYPE_INTERVAL ) return true; return false; @@ -536,7 +536,7 @@ struct type_checker { result_type operator()(const broker::enum_value& a) { - if ( type->Tag() == TYPE_ENUM ) + if ( type->Tag() == zeek::TYPE_ENUM ) { auto etype = type->AsEnumType(); auto i = etype->Lookup(GLOBAL_MODULE_NAME, a.name.data()); @@ -564,8 +564,8 @@ struct type_checker { if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - expected_index_types[0]->Tag() == TYPE_RECORD || - expected_index_types[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == zeek::TYPE_RECORD || + expected_index_types[0]->Tag() == zeek::TYPE_VECTOR; if ( index_is_vector_or_record ) // Disambiguate from composite key w/ multiple vals. @@ -623,8 +623,8 @@ struct type_checker { if ( expected_index_types.size() == 1 ) { auto index_is_vector_or_record = - expected_index_types[0]->Tag() == TYPE_RECORD || - expected_index_types[0]->Tag() == TYPE_VECTOR; + expected_index_types[0]->Tag() == zeek::TYPE_RECORD || + expected_index_types[0]->Tag() == zeek::TYPE_VECTOR; if ( index_is_vector_or_record ) // Disambiguate from composite key w/ multiple vals. @@ -672,7 +672,7 @@ struct type_checker { result_type operator()(const broker::vector& a) { - if ( type->Tag() == TYPE_VECTOR ) + if ( type->Tag() == zeek::TYPE_VECTOR ) { auto vt = type->AsVectorType(); @@ -684,7 +684,7 @@ struct type_checker { return true; } - else if ( type->Tag() == TYPE_FUNC ) + else if ( type->Tag() == zeek::TYPE_FUNC ) { if ( a.size() < 1 || a.size() > 2 ) return false; @@ -705,12 +705,12 @@ struct type_checker { if ( ! t ) return false; - if ( t->Tag() != TYPE_FUNC ) + if ( t->Tag() != zeek::TYPE_FUNC ) return false; return true; } - else if ( type->Tag() == TYPE_RECORD ) + else if ( type->Tag() == zeek::TYPE_RECORD ) { auto rt = type->AsRecordType(); auto idx = 0u; @@ -734,7 +734,7 @@ struct type_checker { return true; } - else if ( type->Tag() == TYPE_PATTERN ) + else if ( type->Tag() == zeek::TYPE_PATTERN ) { if ( a.size() != 2 ) return false; @@ -759,7 +759,7 @@ struct type_checker { return true; } - else if ( type->Tag() == TYPE_OPAQUE ) + else if ( type->Tag() == zeek::TYPE_OPAQUE ) { // TODO: Could avoid doing the full unserialization here // and just check if the type is a correct match. @@ -771,17 +771,17 @@ struct type_checker { } }; -static bool data_type_check(const broker::data& d, BroType* t) +static bool data_type_check(const broker::data& d, zeek::BroType* t) { - if ( t->Tag() == TYPE_ANY ) + if ( t->Tag() == zeek::TYPE_ANY ) return true; return caf::visit(type_checker{t}, d); } -IntrusivePtr bro_broker::data_to_val(broker::data d, BroType* type) +IntrusivePtr bro_broker::data_to_val(broker::data d, zeek::BroType* type) { - if ( type->Tag() == TYPE_ANY ) + if ( type->Tag() == zeek::TYPE_ANY ) return bro_broker::make_data_val(move(d)); return caf::visit(val_converter{type}, std::move(d)); @@ -790,20 +790,20 @@ IntrusivePtr bro_broker::data_to_val(broker::data d, BroType* type) broker::expected bro_broker::val_to_data(const Val* v) { switch ( v->GetType()->Tag() ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: return {v->AsBool()}; - case TYPE_INT: + case zeek::TYPE_INT: return {v->AsInt()}; - case TYPE_COUNT: + case zeek::TYPE_COUNT: return {v->AsCount()}; - case TYPE_COUNTER: + case zeek::TYPE_COUNTER: return {v->AsCounter()}; - case TYPE_PORT: + case zeek::TYPE_PORT: { auto p = v->AsPortVal(); return {broker::port(p->Port(), to_broker_port_proto(p->PortType()))}; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { auto a = v->AsAddr(); in6_addr tmp; @@ -813,7 +813,7 @@ broker::expected bro_broker::val_to_data(const Val* v) broker::address::byte_order::network)}; } break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { auto s = v->AsSubNet(); in6_addr tmp; @@ -824,33 +824,33 @@ broker::expected bro_broker::val_to_data(const Val* v) return {broker::subnet(std::move(a), s.Length())}; } break; - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: return {v->AsDouble()}; - case TYPE_TIME: + case zeek::TYPE_TIME: { auto secs = broker::fractional_seconds{v->AsTime()}; auto since_epoch = std::chrono::duration_cast(secs); return {broker::timestamp{since_epoch}}; } - case TYPE_INTERVAL: + case zeek::TYPE_INTERVAL: { auto secs = broker::fractional_seconds{v->AsInterval()}; return {std::chrono::duration_cast(secs)}; } - case TYPE_ENUM: + case zeek::TYPE_ENUM: { auto enum_type = v->GetType()->AsEnumType(); auto enum_name = enum_type->Lookup(v->AsEnum()); return {broker::enum_value(enum_name ? enum_name : "")}; } - case TYPE_STRING: + case zeek::TYPE_STRING: { auto s = v->AsString(); return {string(reinterpret_cast(s->Bytes()), s->Len())}; } - case TYPE_FILE: + case zeek::TYPE_FILE: return {string(v->AsFile()->Name())}; - case TYPE_FUNC: + case zeek::TYPE_FUNC: { const Func* f = v->AsFunc(); std::string name(f->Name()); @@ -878,7 +878,7 @@ broker::expected bro_broker::val_to_data(const Val* v) return {std::move(rval)}; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { auto is_set = v->GetType()->IsSet(); auto table = v->AsTable(); @@ -934,7 +934,7 @@ broker::expected bro_broker::val_to_data(const Val* v) return {std::move(rval)}; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { auto vec = v->AsVectorVal(); broker::vector rval; @@ -957,7 +957,7 @@ broker::expected bro_broker::val_to_data(const Val* v) return {std::move(rval)}; } - case TYPE_RECORD: + case zeek::TYPE_RECORD: { auto rec = v->AsRecordVal(); broker::vector rval; @@ -984,13 +984,13 @@ broker::expected bro_broker::val_to_data(const Val* v) return {std::move(rval)}; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { const RE_Matcher* p = v->AsPattern(); broker::vector rval = {p->PatternText(), p->AnywherePatternText()}; return {std::move(rval)}; } - case TYPE_OPAQUE: + case zeek::TYPE_OPAQUE: { auto c = v->AsOpaqueVal()->Serialize(); if ( ! c ) @@ -1003,7 +1003,7 @@ broker::expected bro_broker::val_to_data(const Val* v) } default: reporter->Error("unsupported Broker::Data type: %s", - type_name(v->GetType()->Tag())); + zeek::type_name(v->GetType()->Tag())); break; } @@ -1137,17 +1137,17 @@ void bro_broker::DataVal::ValDescribe(ODesc* d) const d->Add("}"); } -bool bro_broker::DataVal::canCastTo(BroType* t) const +bool bro_broker::DataVal::canCastTo(zeek::BroType* t) const { return data_type_check(data, t); } -IntrusivePtr bro_broker::DataVal::castTo(BroType* t) +IntrusivePtr bro_broker::DataVal::castTo(zeek::BroType* t) { return data_to_val(data, t); } -const IntrusivePtr& bro_broker::DataVal::ScriptDataType() +const IntrusivePtr& bro_broker::DataVal::ScriptDataType() { static auto script_data_type = zeek::id::find_type("Broker::Data"); return script_data_type; @@ -1305,7 +1305,7 @@ threading::Field* bro_broker::data_to_threading_field(broker::data d) return new threading::Field(name->c_str(), secondary != broker::nil ? caf::get(secondary).c_str() : nullptr, - static_cast(*type), - static_cast(*subtype), + static_cast(*type), + static_cast(*subtype), *optional); } diff --git a/src/broker/Data.h b/src/broker/Data.h index 906e5376ed..284d6ec46f 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -17,11 +17,11 @@ struct Field; namespace bro_broker { -extern IntrusivePtr opaque_of_data_type; -extern IntrusivePtr opaque_of_set_iterator; -extern IntrusivePtr opaque_of_table_iterator; -extern IntrusivePtr opaque_of_vector_iterator; -extern IntrusivePtr opaque_of_record_iterator; +extern IntrusivePtr opaque_of_data_type; +extern IntrusivePtr opaque_of_set_iterator; +extern IntrusivePtr opaque_of_table_iterator; +extern IntrusivePtr opaque_of_vector_iterator; +extern IntrusivePtr opaque_of_record_iterator; /** * Convert a broker port protocol to a bro port protocol. @@ -65,7 +65,7 @@ broker::expected val_to_data(const Val* v); * @return a pointer to a new Bro value or a nullptr if the conversion was not * possible. */ -IntrusivePtr data_to_val(broker::data d, BroType* type); +IntrusivePtr data_to_val(broker::data d, zeek::BroType* type); /** * Convert a Bro threading::Value to a Broker data value. @@ -109,13 +109,13 @@ public: void ValDescribe(ODesc* d) const override; - IntrusivePtr castTo(BroType* t); - bool canCastTo(BroType* t) const; + IntrusivePtr castTo(zeek::BroType* t); + bool canCastTo(zeek::BroType* t) const; // Returns the Bro type that scripts use to represent a Broker data // instance. This may be wrapping the opaque value inside another // type. - static const IntrusivePtr& ScriptDataType(); + static const IntrusivePtr& ScriptDataType(); broker::data data; @@ -177,11 +177,11 @@ struct type_name_getter { result_type operator()(const broker::vector&) { - assert(tag == TYPE_VECTOR || tag == TYPE_RECORD); - return tag == TYPE_VECTOR ? "vector" : "record"; + assert(tag == zeek::TYPE_VECTOR || tag == zeek::TYPE_RECORD); + return tag == zeek::TYPE_VECTOR ? "vector" : "record"; } - TypeTag tag; + zeek::TypeTag tag; }; /** @@ -204,14 +204,14 @@ broker::data& opaque_field_to_data(RecordVal* v, Frame* f); * is not currently stored in the Broker data. */ template -T& require_data_type(broker::data& d, TypeTag tag, Frame* f) +T& require_data_type(broker::data& d, zeek::TypeTag tag, Frame* f) { auto ptr = caf::get_if(&d); if ( ! ptr ) reporter->RuntimeError(f->GetCall()->GetLocationInfo(), "data is of type '%s' not of type '%s'", caf::visit(type_name_getter{tag}, d), - type_name(tag)); + zeek::type_name(tag)); return *ptr; } @@ -220,7 +220,7 @@ T& require_data_type(broker::data& d, TypeTag tag, Frame* f) * @see require_data_type() and opaque_field_to_data(). */ template -inline T& require_data_type(RecordVal* v, TypeTag tag, Frame* f) +inline T& require_data_type(RecordVal* v, zeek::TypeTag tag, Frame* f) { return require_data_type(opaque_field_to_data(v, f), tag, f); } @@ -230,12 +230,17 @@ inline T& require_data_type(RecordVal* v, TypeTag tag, Frame* f) class SetIterator : public OpaqueVal { public: - SetIterator(RecordVal* v, TypeTag tag, Frame* f) + SetIterator(RecordVal* v, zeek::TypeTag tag, Frame* f) : OpaqueVal(bro_broker::opaque_of_set_iterator), - dat(require_data_type(v, TYPE_TABLE, f)), + dat(require_data_type(v, zeek::TYPE_TABLE, f)), it(dat.begin()) {} + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + SetIterator(RecordVal* v, ::TypeTag tag, Frame* f) + : SetIterator(v, static_cast(tag), f) + {} + broker::set dat; broker::set::iterator it; @@ -250,12 +255,17 @@ protected: class TableIterator : public OpaqueVal { public: - TableIterator(RecordVal* v, TypeTag tag, Frame* f) + TableIterator(RecordVal* v, zeek::TypeTag tag, Frame* f) : OpaqueVal(bro_broker::opaque_of_table_iterator), - dat(require_data_type(v, TYPE_TABLE, f)), + dat(require_data_type(v, zeek::TYPE_TABLE, f)), it(dat.begin()) {} + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + TableIterator(RecordVal* v, ::TypeTag tag, Frame* f) + : TableIterator(v, static_cast(tag), f) + {} + broker::table dat; broker::table::iterator it; @@ -270,12 +280,17 @@ protected: class VectorIterator : public OpaqueVal { public: - VectorIterator(RecordVal* v, TypeTag tag, Frame* f) + VectorIterator(RecordVal* v, zeek::TypeTag tag, Frame* f) : OpaqueVal(bro_broker::opaque_of_vector_iterator), - dat(require_data_type(v, TYPE_VECTOR, f)), + dat(require_data_type(v, zeek::TYPE_VECTOR, f)), it(dat.begin()) {} + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + VectorIterator(RecordVal* v, ::TypeTag tag, Frame* f) + : VectorIterator(v, static_cast(tag), f) + {} + broker::vector dat; broker::vector::iterator it; @@ -290,12 +305,17 @@ protected: class RecordIterator : public OpaqueVal { public: - RecordIterator(RecordVal* v, TypeTag tag, Frame* f) + RecordIterator(RecordVal* v, zeek::TypeTag tag, Frame* f) : OpaqueVal(bro_broker::opaque_of_record_iterator), - dat(require_data_type(v, TYPE_RECORD, f)), + dat(require_data_type(v, zeek::TYPE_RECORD, f)), it(dat.begin()) {} + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + RecordIterator(RecordVal* v, ::TypeTag tag, Frame* f) + : RecordIterator(v, static_cast(tag), f) + {} + broker::vector dat; broker::vector::iterator it; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 3c6bce5f00..0b93592d42 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -152,13 +152,13 @@ void Manager::InitPostScript() log_id_type = zeek::id::find_type("Log::ID")->AsEnumType(); writer_id_type = zeek::id::find_type("Log::Writer")->AsEnumType(); - opaque_of_data_type = make_intrusive("Broker::Data"); - opaque_of_set_iterator = make_intrusive("Broker::SetIterator"); - opaque_of_table_iterator = make_intrusive("Broker::TableIterator"); - opaque_of_vector_iterator = make_intrusive("Broker::VectorIterator"); - opaque_of_record_iterator = make_intrusive("Broker::RecordIterator"); - opaque_of_store_handle = make_intrusive("Broker::Store"); - vector_of_data_type = make_intrusive(zeek::id::find_type("Broker::Data")); + opaque_of_data_type = make_intrusive("Broker::Data"); + opaque_of_set_iterator = make_intrusive("Broker::SetIterator"); + opaque_of_table_iterator = make_intrusive("Broker::TableIterator"); + opaque_of_vector_iterator = make_intrusive("Broker::VectorIterator"); + opaque_of_record_iterator = make_intrusive("Broker::RecordIterator"); + opaque_of_store_handle = make_intrusive("Broker::Store"); + vector_of_data_type = make_intrusive(zeek::id::find_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -430,7 +430,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id) if ( ! data ) { Error("Failed to publish ID with unsupported type: %s (%s)", - id.c_str(), type_name(val->GetType()->Tag())); + id.c_str(), zeek::type_name(val->GetType()->Tag())); return false; } @@ -639,14 +639,14 @@ void Manager::Error(const char* format, ...) bool Manager::AutoPublishEvent(string topic, Val* event) { - if ( event->GetType()->Tag() != TYPE_FUNC ) + if ( event->GetType()->Tag() != zeek::TYPE_FUNC ) { Error("Broker::auto_publish must operate on an event"); return false; } auto event_val = event->AsFunc(); - if ( event_val->Flavor() != FUNC_FLAVOR_EVENT ) + if ( event_val->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { Error("Broker::auto_publish must operate on an event"); return false; @@ -668,7 +668,7 @@ bool Manager::AutoPublishEvent(string topic, Val* event) bool Manager::AutoUnpublishEvent(const string& topic, Val* event) { - if ( event->GetType()->Tag() != TYPE_FUNC ) + if ( event->GetType()->Tag() != zeek::TYPE_FUNC ) { Error("Broker::auto_event_stop must operate on an event"); return false; @@ -676,7 +676,7 @@ bool Manager::AutoUnpublishEvent(const string& topic, Val* event) auto event_val = event->AsFunc(); - if ( event_val->Flavor() != FUNC_FLAVOR_EVENT ) + if ( event_val->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { Error("Broker::auto_event_stop must operate on an event"); return false; @@ -714,7 +714,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { // Event val must come first. - if ( arg_val->GetType()->Tag() != TYPE_FUNC ) + if ( arg_val->GetType()->Tag() != zeek::TYPE_FUNC ) { Error("attempt to convert non-event into an event type"); return rval; @@ -722,7 +722,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) func = arg_val->AsFunc(); - if ( func->Flavor() != FUNC_FLAVOR_EVENT ) + if ( func->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { Error("attempt to convert non-event into an event type"); return rval; @@ -748,8 +748,8 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { rval->Assign(0, nullptr); Error("event parameter #%d type mismatch, got %s, expect %s", i, - type_name(got_type->Tag()), - type_name(expected_type->Tag())); + zeek::type_name(got_type->Tag()), + zeek::type_name(expected_type->Tag())); return rval; } @@ -764,7 +764,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) { rval->Assign(0, nullptr); Error("failed to convert param #%d of type %s to broker data", - i, type_name(got_type->Tag())); + i, zeek::type_name(got_type->Tag())); return rval; } @@ -1001,7 +1001,7 @@ void Manager::ProcessEvent(const broker::topic& topic, broker::zeek::Event ev) vl.emplace_back(std::move(val)); else { - auto expected_name = type_name(expected_type->Tag()); + auto expected_name = zeek::type_name(expected_type->Tag()); reporter->Warning("failed to convert remote event '%s' arg #%d," " got %s, expected %s", @@ -1201,7 +1201,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu) if ( ! val ) { reporter->Error("Failed to receive ID with unsupported type: %s (%s)", - id_name.c_str(), type_name(id->GetType()->Tag())); + id_name.c_str(), zeek::type_name(id->GetType()->Tag())); return false; } @@ -1246,13 +1246,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - static auto ei = zeek::id::find_type("Broker::EndpointInfo"); + static auto ei = zeek::id::find_type("Broker::EndpointInfo"); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - static auto ni = zeek::id::find_type("Broker::NetworkInfo"); + static auto ni = zeek::id::find_type("Broker::NetworkInfo"); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/Manager.h b/src/broker/Manager.h index 255b62bfa7..9044d6cf31 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -23,7 +23,8 @@ class Frame; class Func; -class VectorType; + +FORWARD_DECLARE_NAMESPACED(VectorType, zeek); namespace bro_broker { @@ -396,9 +397,9 @@ private: size_t log_batch_size; Func* log_topic_func; - IntrusivePtr vector_of_data_type; - EnumType* log_id_type; - EnumType* writer_id_type; + IntrusivePtr vector_of_data_type; + zeek::EnumType* log_id_type; + zeek::EnumType* writer_id_type; static int script_scope; }; diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 7eb22c5948..63a63953ef 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -5,11 +5,11 @@ namespace bro_broker { -IntrusivePtr opaque_of_store_handle; +IntrusivePtr opaque_of_store_handle; IntrusivePtr query_status(bool success) { - static EnumType* store_query_status = nullptr; + static zeek::EnumType* store_query_status = nullptr; static int success_val; static int failure_val; diff --git a/src/broker/Store.h b/src/broker/Store.h index e4fea0fdbe..4c0bcda211 100644 --- a/src/broker/Store.h +++ b/src/broker/Store.h @@ -11,7 +11,7 @@ namespace bro_broker { -extern IntrusivePtr opaque_of_store_handle; +extern IntrusivePtr opaque_of_store_handle; /** * Create a Broker::QueryStatus value. diff --git a/src/broker/data.bif b/src/broker/data.bif index 0cdceff2e9..2091a1cb99 100644 --- a/src/broker/data.bif +++ b/src/broker/data.bif @@ -51,7 +51,7 @@ function Broker::__opaque_clone_through_serialization%(d: any%): any builtin_error("cannot serialize object to clone"); return val_mgr->False(); } - + return OpaqueVal::Unserialize(std::move(*x)); %} @@ -63,7 +63,7 @@ function Broker::__set_create%(%): Broker::Data function Broker::__set_clear%(s: Broker::Data%): bool %{ auto& v = bro_broker::require_data_type(s->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); v.clear(); return val_mgr->True(); %} @@ -71,14 +71,14 @@ function Broker::__set_clear%(s: Broker::Data%): bool function Broker::__set_size%(s: Broker::Data%): count %{ auto& v = bro_broker::require_data_type(s->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); return val_mgr->Count(static_cast(v.size())); %} function Broker::__set_contains%(s: Broker::Data, key: any%): bool %{ auto& v = bro_broker::require_data_type(s->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); if ( ! k ) @@ -93,7 +93,7 @@ function Broker::__set_contains%(s: Broker::Data, key: any%): bool function Broker::__set_insert%(s: Broker::Data, key: any%): bool %{ auto& v = bro_broker::require_data_type(s->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); @@ -109,7 +109,7 @@ function Broker::__set_insert%(s: Broker::Data, key: any%): bool function Broker::__set_remove%(s: Broker::Data, key: any%): bool %{ auto& v = bro_broker::require_data_type(s->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); if ( ! k ) @@ -123,7 +123,7 @@ function Broker::__set_remove%(s: Broker::Data, key: any%): bool function Broker::__set_iterator%(s: Broker::Data%): opaque of Broker::SetIterator %{ - return make_intrusive(s->AsRecordVal(), TYPE_TABLE, frame); + return make_intrusive(s->AsRecordVal(), zeek::TYPE_TABLE, frame); %} function Broker::__set_iterator_last%(it: opaque of Broker::SetIterator%): bool @@ -166,7 +166,7 @@ function Broker::__table_create%(%): Broker::Data function Broker::__table_clear%(t: Broker::Data%): bool %{ auto& v = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); v.clear(); return val_mgr->True(); %} @@ -174,14 +174,14 @@ function Broker::__table_clear%(t: Broker::Data%): bool function Broker::__table_size%(t: Broker::Data%): count %{ auto& v = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); return val_mgr->Count(static_cast(v.size())); %} function Broker::__table_contains%(t: Broker::Data, key: any%): bool %{ auto& v = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); @@ -197,7 +197,7 @@ function Broker::__table_contains%(t: Broker::Data, key: any%): bool function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker::Data %{ auto& table = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); @@ -232,7 +232,7 @@ function Broker::__table_insert%(t: Broker::Data, key: any, val: any%): Broker:: function Broker::__table_remove%(t: Broker::Data, key: any%): Broker::Data %{ auto& table = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); @@ -257,7 +257,7 @@ function Broker::__table_remove%(t: Broker::Data, key: any%): Broker::Data function Broker::__table_lookup%(t: Broker::Data, key: any%): Broker::Data %{ auto& table = bro_broker::require_data_type(t->AsRecordVal(), - TYPE_TABLE, frame); + zeek::TYPE_TABLE, frame); auto k = bro_broker::val_to_data(key); @@ -277,7 +277,7 @@ function Broker::__table_lookup%(t: Broker::Data, key: any%): Broker::Data function Broker::__table_iterator%(t: Broker::Data%): opaque of Broker::TableIterator %{ - return make_intrusive(t->AsRecordVal(), TYPE_TABLE, frame); + return make_intrusive(t->AsRecordVal(), zeek::TYPE_TABLE, frame); %} function Broker::__table_iterator_last%(it: opaque of Broker::TableIterator%): bool @@ -325,7 +325,7 @@ function Broker::__vector_create%(%): Broker::Data function Broker::__vector_clear%(v: Broker::Data%): bool %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); vec.clear(); return val_mgr->True(); %} @@ -333,14 +333,14 @@ function Broker::__vector_clear%(v: Broker::Data%): bool function Broker::__vector_size%(v: Broker::Data%): count %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); return val_mgr->Count(static_cast(vec.size())); %} function Broker::__vector_insert%(v: Broker::Data, idx:count, d: any%): bool %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); auto item = bro_broker::val_to_data(d); if ( ! item ) @@ -357,7 +357,7 @@ function Broker::__vector_insert%(v: Broker::Data, idx:count, d: any%): bool function Broker::__vector_replace%(v: Broker::Data, idx: count, d: any%): Broker::Data %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); auto item = bro_broker::val_to_data(d); if ( ! item ) @@ -377,7 +377,7 @@ function Broker::__vector_replace%(v: Broker::Data, idx: count, d: any%): Broker function Broker::__vector_remove%(v: Broker::Data, idx: count%): Broker::Data %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); if ( idx >= vec.size() ) return make_intrusive(zeek::BifType::Record::Broker::Data); @@ -390,7 +390,7 @@ function Broker::__vector_remove%(v: Broker::Data, idx: count%): Broker::Data function Broker::__vector_lookup%(v: Broker::Data, idx: count%): Broker::Data %{ auto& vec = bro_broker::require_data_type(v->AsRecordVal(), - TYPE_VECTOR, frame); + zeek::TYPE_VECTOR, frame); if ( idx >= vec.size() ) return make_intrusive(zeek::BifType::Record::Broker::Data); @@ -400,7 +400,7 @@ function Broker::__vector_lookup%(v: Broker::Data, idx: count%): Broker::Data function Broker::__vector_iterator%(v: Broker::Data%): opaque of Broker::VectorIterator %{ - return make_intrusive(v->AsRecordVal(), TYPE_VECTOR, frame); + return make_intrusive(v->AsRecordVal(), zeek::TYPE_VECTOR, frame); %} function Broker::__vector_iterator_last%(it: opaque of Broker::VectorIterator%): bool @@ -443,14 +443,14 @@ function Broker::__record_create%(sz: count%): Broker::Data function Broker::__record_size%(r: Broker::Data%): count %{ auto& v = bro_broker::require_data_type(r->AsRecordVal(), - TYPE_RECORD, frame); + zeek::TYPE_RECORD, frame); return val_mgr->Count(static_cast(v.size())); %} function Broker::__record_assign%(r: Broker::Data, idx: count, d: any%): bool %{ auto& v = bro_broker::require_data_type(r->AsRecordVal(), - TYPE_RECORD, frame); + zeek::TYPE_RECORD, frame); if ( idx >= v.size() ) return val_mgr->False(); @@ -469,7 +469,7 @@ function Broker::__record_assign%(r: Broker::Data, idx: count, d: any%): bool function Broker::__record_lookup%(r: Broker::Data, idx: count%): Broker::Data %{ auto& v = bro_broker::require_data_type(r->AsRecordVal(), - TYPE_RECORD, frame); + zeek::TYPE_RECORD, frame); if ( idx >= v.size() || caf::get_if(&v[idx]) ) return make_intrusive(zeek::BifType::Record::Broker::Data); @@ -479,7 +479,7 @@ function Broker::__record_lookup%(r: Broker::Data, idx: count%): Broker::Data function Broker::__record_iterator%(r: Broker::Data%): opaque of Broker::RecordIterator %{ - return make_intrusive(r->AsRecordVal(), TYPE_RECORD, frame); + return make_intrusive(r->AsRecordVal(), zeek::TYPE_RECORD, frame); %} function Broker::__record_iterator_last%(it: opaque of Broker::RecordIterator%): bool diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index b88320bcd2..481d172423 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -7,7 +7,7 @@ #include #include -static bool is_string_set(const BroType* type) +static bool is_string_set(const zeek::BroType* type) { if ( ! type->IsSet() ) return false; @@ -17,14 +17,14 @@ static bool is_string_set(const BroType* type) if ( index_types.size() != 1 ) return false; - return index_types[0]->Tag() == TYPE_STRING; + return index_types[0]->Tag() == zeek::TYPE_STRING; } std::set val_to_topic_set(Val* val) { std::set rval; - if ( val->GetType()->Tag() == TYPE_STRING ) + if ( val->GetType()->Tag() == zeek::TYPE_STRING ) rval.emplace(val->AsString()->CheckString()); else { @@ -53,7 +53,7 @@ static bool publish_event_args(val_list& args, const BroString* topic, bro_broker::Manager::ScriptScopeGuard ssg; auto rval = false; - if ( args[0]->GetType()->Tag() == TYPE_RECORD ) + if ( args[0]->GetType()->Tag() == zeek::TYPE_RECORD ) rval = broker_mgr->PublishEvent(topic->CheckString(), args[0]->AsRecordVal()); else diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 8d1397e6d6..2f7d5ae6a0 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -20,7 +20,7 @@ static void analyzer_del_func(void* v) AnalyzerSet::AnalyzerSet(File* arg_file) : file(arg_file) { - auto t = make_intrusive(); + auto t = make_intrusive(); t->Append(file_mgr->GetTagType()); t->Append(zeek::BifType::Record::Files::AnalyzerArgs); analyzer_hash = new CompositeHash(std::move(t)); @@ -156,7 +156,7 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) std::unique_ptr AnalyzerSet::GetKey(const file_analysis::Tag& t, IntrusivePtr args) const { - auto lv = make_intrusive(TYPE_ANY); + auto lv = make_intrusive(zeek::TYPE_ANY); lv->Append(t.AsVal()); lv->Append(std::move(args)); auto key = analyzer_hash->MakeHashKey(*lv, true); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index e9bc68d120..2b97a746c6 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -23,10 +23,10 @@ using namespace file_analysis; static IntrusivePtr empty_connection_table() { - auto tbl_index = make_intrusive(zeek::id::conn_id); + auto tbl_index = make_intrusive(zeek::id::conn_id); tbl_index->Append(zeek::id::conn_id); - auto tbl_type = make_intrusive(std::move(tbl_index), - zeek::id::connection); + auto tbl_type = make_intrusive(std::move(tbl_index), + zeek::id::connection); return make_intrusive(std::move(tbl_type)); } @@ -170,7 +170,7 @@ double File::LookupFieldDefaultInterval(int idx) const return v->AsInterval(); } -int File::Idx(const std::string& field, const RecordType* type) +int File::Idx(const std::string& field, const zeek::RecordType* type) { int rval = type->FieldOffset(field.c_str()); diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index f7afe45b77..2b7ccc37d3 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -14,10 +14,11 @@ #include "WeirdState.h" class Connection; -class RecordType; class RecordVal; class EventHandlerPtr; +FORWARD_DECLARE_NAMESPACED(RecordType, zeek); + namespace file_analysis { class FileReassembler; @@ -336,8 +337,8 @@ protected: * @param type the record type for which the field will be looked up. * @return the field offset in #val record corresponding to \a field_name. */ - static int Idx(const std::string& field_name, const RecordType* type); - static int Idx(const std::string& field_name, const IntrusivePtr& type) + static int Idx(const std::string& field_name, const zeek::RecordType* type); + static int Idx(const std::string& field_name, const IntrusivePtr& type) { return Idx(field_name, type.get()); } /** diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 1c2465c415..c2c734e7c6 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -519,8 +519,8 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) { - static auto mime_matches = zeek::id::find_type("mime_matches"); - static auto mime_match = zeek::id::find_type("mime_match"); + static auto mime_matches = zeek::id::find_type("mime_matches"); + static auto mime_match = zeek::id::find_type("mime_match"); auto rval = make_intrusive(mime_matches); for ( RuleMatcher::MIME_Matches::const_iterator it = m.begin(); diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index 4f8874a0a1..6a233192e9 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -428,7 +428,7 @@ private: MIMEMap mime_types;/**< Mapping of MIME types to analyzers. */ inline static TableVal* disabled = nullptr; /**< Table of disabled analyzers. */ - inline static TableType* tag_set_type = nullptr; /**< Type for set[tag]. */ + inline static zeek::TableType* tag_set_type = nullptr; /**< Type for set[tag]. */ size_t cumulative_files; size_t max_files; diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index 1456eb1fad..93d92eefee 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -62,7 +62,7 @@ void Entropy::Finalize() montepi = scc = ent = mean = chisq = 0.0; entropy->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, ent); ent_result->Assign(1, chisq); diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index a77eac036d..972742b5c3 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -620,7 +620,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(zeek::id::find_type("x509_opaque_vector")); + certs_vector = new VectorVal(zeek::id::find_type("x509_opaque_vector")); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) @@ -675,4 +675,3 @@ void file_analysis::OCSP::ParseExtensionsSpecific(X509_EXTENSION* ex, bool globa #endif ParseSignedCertificateTimestamps(ex); } - diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index 9da3adc349..cd59a5a259 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -393,7 +393,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = make_intrusive(zeek::id::find_type("addr_vec")); + ips = make_intrusive(zeek::id::find_type("addr_vec")); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 31ce39b1a4..20159e48ad 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -96,8 +96,8 @@ public: bool want_record; TableVal* tab; - RecordType* rtype; - RecordType* itype; + zeek::RecordType* rtype; + zeek::RecordType* itype; PDict* currDict; PDict* lastDict; @@ -114,7 +114,7 @@ class Manager::EventStream final : public Manager::Stream { public: EventHandlerPtr event; - RecordType* fields; + zeek::RecordType* fields; unsigned int num_fields; bool want_record; @@ -217,7 +217,7 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) // Create a new input reader object to be used at whomevers leisure later on. bool Manager::CreateStream(Stream* info, RecordVal* description) { - RecordType* rtype = description->GetType()->AsRecordType(); + zeek::RecordType* rtype = description->GetType()->AsRecordType(); if ( ! ( same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) || same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) || same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) ) @@ -305,7 +305,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { - RecordType* rtype = fval->GetType()->AsRecordType(); + zeek::RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, zeek::BifType::Record::Input::EventDescription, false) ) { reporter->Error("EventDescription argument not of right type"); @@ -315,7 +315,7 @@ bool Manager::CreateEventStream(RecordVal* fval) string stream_name = fval->GetFieldOrDefault("name")->AsString()->CheckString(); auto fields_val = fval->GetFieldOrDefault("fields"); - RecordType* fields = fields_val->AsType()->AsTypeType()->GetType()->AsRecordType(); + zeek::RecordType* fields = fields_val->AsType()->AsTypeType()->GetType()->AsRecordType(); auto want_record = fval->GetFieldOrDefault("want_record"); @@ -326,7 +326,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool allow_file_func = false; - if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) + if ( etype->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { reporter->Error("Input stream %s: Stream event is a function, not an event", stream_name.c_str()); return false; @@ -371,8 +371,8 @@ bool Manager::CreateEventStream(RecordVal* fval) reporter->Error("Input stream %s: Incompatible type for event in field %d. Need type '%s':%s, got '%s':%s", stream_name.c_str(), i + 3, - type_name(fields->GetFieldType(i)->Tag()), desc2.Description(), - type_name(args[i + 2]->Tag()), desc1.Description()); + zeek::type_name(fields->GetFieldType(i)->Tag()), desc2.Description(), + zeek::type_name(args[i + 2]->Tag()), desc1.Description()); return false; } @@ -396,8 +396,8 @@ bool Manager::CreateEventStream(RecordVal* fval) fields->Describe(&desc2); reporter->Error("Input stream %s: Incompatible type '%s':%s for event, which needs type '%s':%s\n", stream_name.c_str(), - type_name(args[2]->Tag()), desc1.Description(), - type_name(fields->Tag()), desc2.Description()); + zeek::type_name(args[2]->Tag()), desc1.Description(), + zeek::type_name(fields->Tag()), desc2.Description()); return false; } @@ -459,7 +459,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { - RecordType* rtype = fval->GetType()->AsRecordType(); + zeek::RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, zeek::BifType::Record::Input::TableDescription, false) ) { reporter->Error("TableDescription argument not of right type"); @@ -470,13 +470,13 @@ bool Manager::CreateTableStream(RecordVal* fval) auto pred = fval->GetFieldOrDefault("pred"); auto idx_val = fval->GetFieldOrDefault("idx"); - RecordType* idx = idx_val->AsType()->AsTypeType()->GetType()->AsRecordType(); + zeek::RecordType* idx = idx_val->AsType()->AsTypeType()->GetType()->AsRecordType(); - IntrusivePtr val; + IntrusivePtr val; auto val_val = fval->GetFieldOrDefault("val"); if ( val_val ) - val = val_val->AsType()->AsTypeType()->GetType(); + val = val_val->AsType()->AsTypeType()->GetType(); auto dst = fval->GetFieldOrDefault("destination"); @@ -501,8 +501,8 @@ bool Manager::CreateTableStream(RecordVal* fval) tl[j]->Describe(&desc2); reporter->Error("Input stream %s: Table type does not match index type. Need type '%s':%s, got '%s':%s", stream_name.c_str(), - type_name(idx->GetFieldType(j)->Tag()), desc1.Description(), - type_name(tl[j]->Tag()), desc2.Description()); + zeek::type_name(idx->GetFieldType(j)->Tag()), desc1.Description(), + zeek::type_name(tl[j]->Tag()), desc2.Description()); return false; } @@ -551,7 +551,7 @@ bool Manager::CreateTableStream(RecordVal* fval) { const auto& etype = event->GetType(); - if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) + if ( etype->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { reporter->Error("Input stream %s: Stream event is a function, not an event", stream_name.c_str()); return false; @@ -698,7 +698,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e const auto& etype = ev->GetType(); - if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) + if ( etype->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { reporter->Error("Input stream %s: Error event is a function, not an event", stream_name.c_str()); return false; @@ -724,7 +724,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( args[1]->Tag() != TYPE_STRING ) + if ( args[1]->Tag() != zeek::TYPE_STRING ) { reporter->Error("Input stream %s: Error event's second attribute must be of type string", stream_name.c_str()); return false; @@ -741,7 +741,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e bool Manager::CreateAnalysisStream(RecordVal* fval) { - RecordType* rtype = fval->GetType()->AsRecordType(); + zeek::RecordType* rtype = fval->GetType()->AsRecordType(); if ( ! same_type(rtype, zeek::BifType::Record::Input::AnalysisDescription, false) ) { @@ -763,7 +763,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) // reader takes in a byte stream as the only field Field** fields = new Field*[1]; - fields[0] = new Field("bytestream", nullptr, TYPE_STRING, TYPE_VOID, false); + fields[0] = new Field("bytestream", nullptr, zeek::TYPE_STRING, zeek::TYPE_VOID, false); stream->reader->Init(1, fields); readers[stream->reader] = stream; @@ -774,31 +774,31 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) return true; } -bool Manager::IsCompatibleType(BroType* t, bool atomic_only) +bool Manager::IsCompatibleType(zeek::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_ADDR: - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_PATTERN: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: + case zeek::TYPE_PORT: + case zeek::TYPE_SUBNET: + case zeek::TYPE_ADDR: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_PATTERN: return true; - case TYPE_RECORD: + case zeek::TYPE_RECORD: return ! atomic_only; - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( atomic_only ) return false; @@ -809,7 +809,7 @@ bool Manager::IsCompatibleType(BroType* t, bool atomic_only) return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( atomic_only ) return false; @@ -879,7 +879,7 @@ bool Manager::RemoveStreamContinuation(ReaderFrontend* reader) return true; } -bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, +bool Manager::UnrollRecordType(vector *fields, const zeek::RecordType *rec, const string& nameprepend, bool allow_file_func) const { for ( int i = 0; i < rec->NumFields(); i++ ) @@ -893,21 +893,22 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, // stuff that we actually cannot read :) if ( allow_file_func ) { - if ( ( rec->GetFieldType(i)->Tag() == TYPE_FILE || - rec->GetFieldType(i)->Tag() == TYPE_FUNC || - rec->GetFieldType(i)->Tag() == TYPE_OPAQUE ) && + if ( ( rec->GetFieldType(i)->Tag() == zeek::TYPE_FILE || + rec->GetFieldType(i)->Tag() == zeek::TYPE_FUNC || + rec->GetFieldType(i)->Tag() == zeek::TYPE_OPAQUE ) && rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) ) { - reporter->Info("Encountered incompatible type \"%s\" in type definition for field \"%s\" in ReaderFrontend. Ignoring optional field.", type_name(rec->GetFieldType(i)->Tag()), name.c_str()); + reporter->Info("Encountered incompatible type \"%s\" in type definition for field \"%s\" in ReaderFrontend. Ignoring optional field.", zeek::type_name(rec->GetFieldType(i)->Tag()), name.c_str()); continue; } } - reporter->Error("Incompatible type \"%s\" in type definition for for field \"%s\" in ReaderFrontend", type_name(rec->GetFieldType(i)->Tag()), name.c_str()); + reporter->Error("Incompatible type \"%s\" in type definition for for field \"%s\" in ReaderFrontend", + zeek::type_name(rec->GetFieldType(i)->Tag()), name.c_str()); return false; } - if ( rec->GetFieldType(i)->Tag() == TYPE_RECORD ) + if ( rec->GetFieldType(i)->Tag() == zeek::TYPE_RECORD ) { string prep = nameprepend + rec->FieldName(i) + "."; @@ -929,17 +930,17 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, string name = nameprepend + rec->FieldName(i); const char* secondary = nullptr; IntrusivePtr c; - TypeTag ty = rec->GetFieldType(i)->Tag(); - TypeTag st = TYPE_VOID; + zeek::TypeTag ty = rec->GetFieldType(i)->Tag(); + zeek::TypeTag st = zeek::TYPE_VOID; bool optional = false; - if ( ty == TYPE_TABLE ) + if ( ty == zeek::TYPE_TABLE ) st = rec->GetFieldType(i)->AsSetType()->GetIndices()->GetPureType()->Tag(); - else if ( ty == TYPE_VECTOR ) + else if ( ty == zeek::TYPE_VECTOR ) st = rec->GetFieldType(i)->AsVectorType()->Yield()->Tag(); - else if ( ty == TYPE_PORT && + else if ( ty == zeek::TYPE_PORT && rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_TYPE_COLUMN) ) { // we have an annotation for the second column @@ -947,7 +948,7 @@ bool Manager::UnrollRecordType(vector *fields, const RecordType *rec, c = rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr); assert(c); - assert(c->GetType()->Tag() == TYPE_STRING); + assert(c->GetType()->Tag() == zeek::TYPE_STRING); secondary = c->AsStringVal()->AsString()->CheckString(); } @@ -992,16 +993,16 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const { IntrusivePtr idxval; - RecordType *type = r->GetType()->AsRecordType(); + zeek::RecordType *type = r->GetType()->AsRecordType(); int num_fields = type->NumFields(); - if ( num_fields == 1 && type->FieldDecl(0)->type->Tag() != TYPE_RECORD ) + if ( num_fields == 1 && type->FieldDecl(0)->type->Tag() != zeek::TYPE_RECORD ) idxval = r->GetFieldOrDefault(0); else { - auto l = make_intrusive(TYPE_ANY); + auto l = make_intrusive(zeek::TYPE_ANY); for ( int j = 0 ; j < num_fields; j++ ) l->Append(r->GetFieldOrDefault(j)); @@ -1013,23 +1014,23 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const } -Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const RecordType *type, const Value* const *vals, bool& have_error) const +Val* Manager::ValueToIndexVal(const Stream* i, int num_fields, const zeek::RecordType *type, const Value* const *vals, bool& have_error) const { Val* idxval; int position = 0; - if ( num_fields == 1 && type->GetFieldType(0)->Tag() != TYPE_RECORD ) + if ( num_fields == 1 && type->GetFieldType(0)->Tag() != zeek::TYPE_RECORD ) { idxval = ValueToVal(i, vals[0], type->GetFieldType(0).get(), have_error); position = 1; } else { - ListVal *l = new ListVal(TYPE_ANY); + ListVal *l = new ListVal(zeek::TYPE_ANY); for ( int j = 0 ; j < type->NumFields(); j++ ) { - if ( type->GetFieldType(j)->Tag() == TYPE_RECORD ) + if ( type->GetFieldType(j)->Tag() == zeek::TYPE_RECORD ) l->Append({AdoptRef{}, ValueToRecordVal(i, vals, type->GetFieldType(j)->AsRecordType(), &position, have_error)}); else @@ -1071,7 +1072,7 @@ void Manager::SendEntry(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == ANALYSIS_STREAM ) { readFields = 1; - assert(vals[0]->type == TYPE_STRING); + assert(vals[0]->type == zeek::TYPE_STRING); file_mgr->DataIn(reinterpret_cast(vals[0]->val.string_val.data), vals[0]->val.string_val.length, static_cast(i)->file_id, i->name); @@ -1438,7 +1439,7 @@ void Manager::Put(ReaderFrontend* reader, Value* *vals) else if ( i->stream_type == ANALYSIS_STREAM ) { readFields = 1; - assert(vals[0]->type == TYPE_STRING); + assert(vals[0]->type == zeek::TYPE_STRING); file_mgr->DataIn(reinterpret_cast(vals[0]->val.string_val.data), vals[0]->val.string_val.length, static_cast(i)->file_id, i->name); @@ -1479,7 +1480,7 @@ int Manager::SendEventStreamEvent(Stream* i, EnumVal* type, const Value* const * { Val* val = nullptr; - if ( stream->fields->GetFieldType(j)->Tag() == TYPE_RECORD ) + if ( stream->fields->GetFieldType(j)->Tag() == zeek::TYPE_RECORD ) val = ValueToRecordVal(i, vals, stream->fields->GetFieldType(j)->AsRecordType(), &position, convert_error); @@ -1816,7 +1817,7 @@ void Manager::SendEvent(EventHandlerPtr ev, list events) const // Convert a bro list value to a bro record value. // I / we could think about moving this functionality to val.cc -RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, int* position) const +RecordVal* Manager::ListValToRecordVal(ListVal* list, zeek::RecordType *request_type, int* position) const { assert(position != nullptr); // we need the pointer to point to data; @@ -1830,7 +1831,7 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, assert ( (*position) <= maxpos ); Val* fieldVal = nullptr; - if ( request_type->GetFieldType(i)->Tag() == TYPE_RECORD ) + if ( request_type->GetFieldType(i)->Tag() == zeek::TYPE_RECORD ) fieldVal = ListValToRecordVal(list, request_type->GetFieldType(i)->AsRecordType(), position); else { @@ -1846,7 +1847,7 @@ RecordVal* Manager::ListValToRecordVal(ListVal* list, RecordType *request_type, // Convert a threading value to a record value RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *vals, - RecordType *request_type, int* position, bool& have_error) const + zeek::RecordType *request_type, int* position, bool& have_error) const { assert(position != nullptr); // we need the pointer to point to data. @@ -1854,10 +1855,10 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v for ( int i = 0; i < request_type->NumFields(); i++ ) { Val* fieldVal = nullptr; - if ( request_type->GetFieldType(i)->Tag() == TYPE_RECORD ) + if ( request_type->GetFieldType(i)->Tag() == zeek::TYPE_RECORD ) fieldVal = ValueToRecordVal(stream, vals, request_type->GetFieldType(i)->AsRecordType(), position, have_error); - else if ( request_type->GetFieldType(i)->Tag() == TYPE_FILE || - request_type->GetFieldType(i)->Tag() == TYPE_FUNC ) + else if ( request_type->GetFieldType(i)->Tag() == zeek::TYPE_FILE || + request_type->GetFieldType(i)->Tag() == zeek::TYPE_FUNC ) { // If those two unsupported types are encountered here, they have // been let through by the type checking. @@ -1889,35 +1890,35 @@ int Manager::GetValueLength(const Value* val) const int length = 0; switch (val->type) { - case TYPE_BOOL: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: length += sizeof(val->val.int_val); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: length += sizeof(val->val.uint_val); break; - case TYPE_PORT: + case zeek::TYPE_PORT: length += sizeof(val->val.port_val.port); length += sizeof(val->val.port_val.proto); break; - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: length += sizeof(val->val.double_val); break; - case TYPE_STRING: - case TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_ENUM: { length += val->val.string_val.length + 1; break; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { switch ( val->val.addr_val.family ) { case IPv4: @@ -1932,7 +1933,7 @@ int Manager::GetValueLength(const Value* val) const } break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { switch ( val->val.subnet_val.prefix.family ) { case IPv4: @@ -1949,20 +1950,20 @@ int Manager::GetValueLength(const Value* val) const } break; - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { length += strlen(val->val.pattern_text_val) + 1; break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { for ( int i = 0; i < val->val.set_val.size; i++ ) length += GetValueLength(val->val.set_val.vals[i]); break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { int j = val->val.vector_val.size; for ( int i = 0; i < j; i++ ) @@ -1985,17 +1986,17 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const assert( val->present ); // presence has to be checked elsewhere switch ( val->type ) { - case TYPE_BOOL: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: memcpy(data+startpos, (const void*) &(val->val.int_val), sizeof(val->val.int_val)); return sizeof(val->val.int_val); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: memcpy(data+startpos, (const void*) &(val->val.uint_val), sizeof(val->val.uint_val)); return sizeof(val->val.uint_val); - case TYPE_PORT: + case zeek::TYPE_PORT: { int length = 0; memcpy(data+startpos, (const void*) &(val->val.port_val.port), @@ -2008,15 +2009,15 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const } - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: memcpy(data+startpos, (const void*) &(val->val.double_val), sizeof(val->val.double_val)); return sizeof(val->val.double_val); - case TYPE_STRING: - case TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_ENUM: { memcpy(data+startpos, val->val.string_val.data, val->val.string_val.length); // Add a \0 to the end. To be able to hash zero-length @@ -2025,7 +2026,7 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const return val->val.string_val.length + 1; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { int length = 0; switch ( val->val.addr_val.family ) { @@ -2046,7 +2047,7 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const return length; } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { int length = 0; switch ( val->val.subnet_val.prefix.family ) { @@ -2074,7 +2075,7 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const return length; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { // include null-terminator int length = strlen(val->val.pattern_text_val) + 1; @@ -2082,7 +2083,7 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const return length; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { int length = 0; int j = val->val.set_val.size; @@ -2092,7 +2093,7 @@ int Manager::CopyValue(char *data, const int startpos, const Value* val) const return length; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { int length = 0; int j = val->val.vector_val.size; @@ -2158,12 +2159,12 @@ HashKey* Manager::HashValues(const int num_elements, const Value* const *vals) c // have_error is a reference to a boolean which is set to true as soon as an error occurs. // When have_error is set to true at the beginning of the function, it is assumed that // an error already occurred in the past and processing is aborted. -Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_type, bool& have_error) const +Val* Manager::ValueToVal(const Stream* i, const Value* val, zeek::BroType* request_type, bool& have_error) const { if ( have_error ) return nullptr; - if ( request_type->Tag() != TYPE_ANY && request_type->Tag() != val->type ) + if ( request_type->Tag() != zeek::TYPE_ANY && request_type->Tag() != val->type ) { reporter->InternalError("Typetags don't match: %d vs %d in stream %s", request_type->Tag(), val->type, i->name.c_str()); return nullptr; @@ -2173,35 +2174,35 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return nullptr; // unset field switch ( val->type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: return val_mgr->Bool(val->val.int_val)->Ref(); - case TYPE_INT: + case zeek::TYPE_INT: return val_mgr->Int(val->val.int_val).release(); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return val_mgr->Count(val->val.int_val).release(); - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: return new DoubleVal(val->val.double_val); - case TYPE_TIME: + case zeek::TYPE_TIME: return new TimeVal(val->val.double_val); - case TYPE_INTERVAL: + case zeek::TYPE_INTERVAL: return new IntervalVal(val->val.double_val); - case TYPE_STRING: + case zeek::TYPE_STRING: { BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, true); return new StringVal(s); } - case TYPE_PORT: + case zeek::TYPE_PORT: return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref(); - case TYPE_ADDR: + case zeek::TYPE_ADDR: { IPAddr* addr = nullptr; switch ( val->val.addr_val.family ) { @@ -2222,7 +2223,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return addrval; } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { IPAddr* addr = nullptr; switch ( val->val.subnet_val.prefix.family ) { @@ -2243,20 +2244,20 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return subnetval; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { RE_Matcher* re = new RE_Matcher(val->val.pattern_text_val); re->Compile(); return new PatternVal(re); } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { // all entries have to have the same type... const auto& type = request_type->AsTableType()->GetIndices()->GetPureType(); - auto set_index = make_intrusive(type); + auto set_index = make_intrusive(type); set_index->Append(type); - auto s = make_intrusive(std::move(set_index), nullptr); + auto s = make_intrusive(std::move(set_index), nullptr); TableVal* t = new TableVal(std::move(s)); for ( int j = 0; j < val->val.set_val.size; j++ ) { @@ -2268,11 +2269,11 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return t; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { // all entries have to have the same type... const auto& type = request_type->AsVectorType()->Yield(); - auto vt = make_intrusive(type); + auto vt = make_intrusive(type); auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) @@ -2284,7 +2285,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ return v.release(); } - case TYPE_ENUM: { + case zeek::TYPE_ENUM: { // Convert to string first to not have to deal with missing // \0's... string enum_string(val->val.string_val.data, val->val.string_val.length); diff --git a/src/input/Manager.h b/src/input/Manager.h index c24b930d64..d458055472 100644 --- a/src/input/Manager.h +++ b/src/input/Manager.h @@ -111,7 +111,7 @@ public: * * @return True if the type is compatible with the input framework. */ - static bool IsCompatibleType(BroType* t, bool atomic_only=false); + static bool IsCompatibleType(zeek::BroType* t, bool atomic_only=false); protected: friend class ReaderFrontend; @@ -199,7 +199,7 @@ private: // Check if a record is made up of compatible types and return a list // of all fields that are in the record in order. Recursively unrolls // records - bool UnrollRecordType(std::vector *fields, const RecordType *rec, const std::string& nameprepend, bool allow_file_func) const; + bool UnrollRecordType(std::vector *fields, const zeek::RecordType *rec, const std::string& nameprepend, bool allow_file_func) const; // Send events void SendEvent(EventHandlerPtr ev, const int numvals, ...) const; @@ -222,19 +222,19 @@ private: int CopyValue(char *data, const int startpos, const threading::Value* val) const; // Convert Threading::Value to an internal Bro Type (works with Records). - Val* ValueToVal(const Stream* i, const threading::Value* val, BroType* request_type, bool& have_error) const; + Val* ValueToVal(const Stream* i, const threading::Value* val, zeek::BroType* request_type, bool& have_error) const; // Convert Threading::Value to an internal Bro list type. - Val* ValueToIndexVal(const Stream* i, int num_fields, const RecordType* type, const threading::Value* const *vals, bool& have_error) const; + Val* ValueToIndexVal(const Stream* i, int num_fields, const zeek::RecordType* type, const threading::Value* const *vals, bool& have_error) const; // Converts a threading::value to a record type. Mostly used by // ValueToVal. - RecordVal* ValueToRecordVal(const Stream* i, const threading::Value* const *vals, RecordType *request_type, int* position, bool& have_error) const; + RecordVal* ValueToRecordVal(const Stream* i, const threading::Value* const *vals, zeek::RecordType *request_type, int* position, bool& have_error) const; Val* RecordValToIndexVal(RecordVal *r) const; // Converts a Bro ListVal to a RecordVal given the record type. - RecordVal* ListValToRecordVal(ListVal* list, RecordType *request_type, int* position) const; + RecordVal* ListValToRecordVal(ListVal* list, zeek::RecordType *request_type, int* position) const; // Internally signal errors, warnings, etc. // These are sent on to input scriptland and reporter.log diff --git a/src/input/readers/ascii/Ascii.cc b/src/input/readers/ascii/Ascii.cc index c3950cdc59..a9b4eb7fc2 100644 --- a/src/input/readers/ascii/Ascii.cc +++ b/src/input/readers/ascii/Ascii.cc @@ -18,16 +18,16 @@ using namespace std; using threading::Value; using threading::Field; -FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position) - : name(arg_name), type(arg_type), subtype(TYPE_ERROR) +FieldMapping::FieldMapping(const string& arg_name, const zeek::TypeTag& arg_type, int arg_position) + : name(arg_name), type(arg_type), subtype(zeek::TYPE_ERROR) { position = arg_position; secondary_position = -1; present = true; } -FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, - const TypeTag& arg_subtype, int arg_position) +FieldMapping::FieldMapping(const string& arg_name, const zeek::TypeTag& arg_type, + const zeek::TypeTag& arg_subtype, int arg_position) : name(arg_name), type(arg_type), subtype(arg_subtype) { position = arg_position; @@ -407,7 +407,7 @@ bool Ascii::DoUpdate() if ( (*fit).secondary_position != -1 ) { // we have a port definition :) - assert(val->type == TYPE_PORT ); + assert(val->type == zeek::TYPE_PORT ); // Error(Fmt("Got type %d != PORT with secondary position!", val->type)); val->val.port_val.proto = formatter->ParseProto(stringfields[(*fit).secondary_position]); @@ -434,7 +434,7 @@ bool Ascii::DoUpdate() //printf("fpos: %d, second.num_fields: %d\n", fpos, (*it).second.num_fields); assert ( fpos == NumFields() ); - if ( Info().mode == MODE_STREAM ) + if ( Info().mode == MODE_STREAM ) Put(fields); else SendEntry(fields); diff --git a/src/input/readers/ascii/Ascii.h b/src/input/readers/ascii/Ascii.h index 858e6f94cd..2c958bf2f1 100644 --- a/src/input/readers/ascii/Ascii.h +++ b/src/input/readers/ascii/Ascii.h @@ -16,14 +16,25 @@ namespace input { namespace reader { // Description for input field mapping. struct FieldMapping { std::string name; - TypeTag type; - TypeTag subtype; // internal type for sets and vectors + zeek::TypeTag type; + zeek::TypeTag subtype; // internal type for sets and vectors int position; int secondary_position; // for ports: pos of the second field bool present; - FieldMapping(const std::string& arg_name, const TypeTag& arg_type, int arg_position); - FieldMapping(const std::string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position); + FieldMapping(const std::string& arg_name, const zeek::TypeTag& arg_type, int arg_position); + FieldMapping(const std::string& arg_name, const zeek::TypeTag& arg_type, const zeek::TypeTag& arg_subtype, int arg_position); + + [[deprecated("Remove in v4.1. Use the version that takes zeek:TypeTag.")]] + FieldMapping(const std::string& arg_name, const ::TypeTag& arg_type, int arg_position) + : FieldMapping(arg_name, static_cast(arg_type), arg_position) + {} + + [[deprecated("Remove in v4.1. Use the version that takes zeek:TypeTag.")]] + FieldMapping(const std::string& arg_name, const ::TypeTag& arg_type, const ::TypeTag& arg_subtype, int arg_position) + : FieldMapping(arg_name, static_cast(arg_type), static_cast(arg_subtype), arg_position) + {} + FieldMapping(const FieldMapping& arg); FieldMapping() { position = -1; secondary_position = -1; } diff --git a/src/input/readers/benchmark/Benchmark.cc b/src/input/readers/benchmark/Benchmark.cc index 26975ad411..13aad78233 100644 --- a/src/input/readers/benchmark/Benchmark.cc +++ b/src/input/readers/benchmark/Benchmark.cc @@ -123,17 +123,17 @@ bool Benchmark::DoUpdate() return true; } -threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) +threading::Value* Benchmark::EntryToVal(zeek::TypeTag type, zeek::TypeTag subtype) { Value* val = new Value(type, subtype, true); // basically construct something random from the fields that we want. switch ( type ) { - case TYPE_ENUM: + case zeek::TYPE_ENUM: assert(false); // no enums, please. - case TYPE_STRING: + case zeek::TYPE_STRING: { std::string rnd = RandomString(10); val->val.string_val.data = copy_string(rnd.c_str()); @@ -141,46 +141,46 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) break; } - case TYPE_BOOL: + case zeek::TYPE_BOOL: val->val.int_val = 1; // we never lie. break; - case TYPE_INT: + case zeek::TYPE_INT: val->val.int_val = random(); break; - case TYPE_TIME: + case zeek::TYPE_TIME: val->val.double_val = CurrTime(); break; - case TYPE_DOUBLE: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_INTERVAL: val->val.double_val = random(); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: val->val.uint_val = random(); break; - case TYPE_PORT: + case zeek::TYPE_PORT: val->val.port_val.port = random() / (RAND_MAX / 60000); val->val.port_val.proto = TRANSPORT_UNKNOWN; break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1"); val->val.subnet_val.length = 16; } break; - case TYPE_ADDR: + case zeek::TYPE_ADDR: val->val.addr_val = ascii->ParseAddr("192.168.17.1"); break; - case TYPE_TABLE: - case TYPE_VECTOR: + case zeek::TYPE_TABLE: + case zeek::TYPE_VECTOR: // First - common initialization // Then - initialization for table. // Then - initialization for vector. @@ -191,12 +191,12 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) Value** lvals = new Value* [length]; - if ( type == TYPE_TABLE ) + if ( type == zeek::TYPE_TABLE ) { val->val.set_val.vals = lvals; val->val.set_val.size = length; } - else if ( type == TYPE_VECTOR ) + else if ( type == zeek::TYPE_VECTOR ) { val->val.vector_val.vals = lvals; val->val.vector_val.size = length; @@ -209,7 +209,7 @@ threading::Value* Benchmark::EntryToVal(TypeTag type, TypeTag subtype) for ( unsigned int pos = 0; pos < length; pos++ ) { - Value* newval = EntryToVal(subtype, TYPE_ENUM); + Value* newval = EntryToVal(subtype, zeek::TYPE_ENUM); if ( newval == nullptr ) { Error("Error while reading set"); @@ -251,9 +251,9 @@ bool Benchmark::DoHeartbeat(double network_time, double current_time) { // we have to document at what time we changed the factor to what value. Value** v = new Value*[2]; - v[0] = new Value(TYPE_COUNT, true); + v[0] = new Value(zeek::TYPE_COUNT, true); v[0]->val.uint_val = num_lines; - v[1] = new Value(TYPE_TIME, true); + v[1] = new Value(zeek::TYPE_TIME, true); v[1]->val.double_val = CurrTime(); SendEvent("lines_changed", 2, v); diff --git a/src/input/readers/benchmark/Benchmark.h b/src/input/readers/benchmark/Benchmark.h index 173d4eccda..e969ee77ea 100644 --- a/src/input/readers/benchmark/Benchmark.h +++ b/src/input/readers/benchmark/Benchmark.h @@ -26,7 +26,7 @@ protected: private: double CurrTime(); std::string RandomString(const int len); - threading::Value* EntryToVal(TypeTag Type, TypeTag subtype); + threading::Value* EntryToVal(zeek::TypeTag Type, zeek::TypeTag subtype); int num_lines; double multiplication_factor; diff --git a/src/input/readers/binary/Binary.cc b/src/input/readers/binary/Binary.cc index 77db68a80e..d181315a74 100644 --- a/src/input/readers/binary/Binary.cc +++ b/src/input/readers/binary/Binary.cc @@ -99,7 +99,7 @@ bool Binary::DoInit(const ReaderInfo& info, int num_fields, return false; } - if ( fields[0]->type != TYPE_STRING ) + if ( fields[0]->type != zeek::TYPE_STRING ) { Error("Filter for binary reader contains a non-string field."); return false; @@ -241,7 +241,7 @@ bool Binary::DoUpdate() Value** fields = new Value*[1]; // filter has exactly one text field. convert to it. - Value* val = new Value(TYPE_STRING, true); + Value* val = new Value(zeek::TYPE_STRING, true); val->val.string_val.data = chunk; val->val.string_val.length = size; fields[0] = val; diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index a5f11f3fc5..e3199c78ba 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -35,18 +35,18 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) if ( ! id->IsOption() ) continue; - if ( id->GetType()->Tag() == TYPE_RECORD || + if ( id->GetType()->Tag() == zeek::TYPE_RECORD || ! input::Manager::IsCompatibleType(id->GetType().get()) ) { - option_types[id->Name()] = std::make_tuple(TYPE_ERROR, id->GetType()->Tag()); + option_types[id->Name()] = std::make_tuple(zeek::TYPE_ERROR, id->GetType()->Tag()); continue; } - TypeTag primary = id->GetType()->Tag(); - TypeTag secondary = TYPE_VOID; - if ( primary == TYPE_TABLE ) + zeek::TypeTag primary = id->GetType()->Tag(); + zeek::TypeTag secondary = zeek::TYPE_VOID; + if ( primary == zeek::TYPE_TABLE ) secondary = id->GetType()->AsSetType()->GetIndices()->GetPureType()->Tag(); - else if ( primary == TYPE_VECTOR ) + else if ( primary == zeek::TYPE_VECTOR ) secondary = id->GetType()->AsVectorType()->Yield()->Tag(); option_types[id->Name()] = std::make_tuple(primary, secondary); @@ -209,9 +209,10 @@ bool Config::DoUpdate() continue; } - if ( std::get<0>((*typeit).second) == TYPE_ERROR ) + if ( std::get<0>((*typeit).second) == zeek::TYPE_ERROR ) { - Warning(Fmt("Option '%s' has type '%s', which is not supported for file input. Ignoring line.", key.c_str(), type_name(std::get<1>((*typeit).second)))); + Warning(Fmt("Option '%s' has type '%s', which is not supported for file input. Ignoring line.", + key.c_str(), zeek::type_name(std::get<1>((*typeit).second)))); continue; } @@ -244,11 +245,11 @@ bool Config::DoUpdate() { Value** fields = new Value*[2]; - Value* keyval = new threading::Value(TYPE_STRING, true); + Value* keyval = new threading::Value(zeek::TYPE_STRING, true); keyval->val.string_val.length = key.size(); keyval->val.string_val.data = copy_string(key.c_str()); fields[0] = keyval; - Value* val = new threading::Value(TYPE_STRING, true); + Value* val = new threading::Value(zeek::TYPE_STRING, true); val->val.string_val.length = value.size(); val->val.string_val.data = copy_string(value.c_str()); fields[1] = val; @@ -261,13 +262,13 @@ bool Config::DoUpdate() { Value** vals = new Value*[4]; - vals[0] = new Value(TYPE_STRING, true); + vals[0] = new Value(zeek::TYPE_STRING, true); vals[0]->val.string_val.data = copy_string(Info().name); vals[0]->val.string_val.length = strlen(Info().name); - vals[1] = new Value(TYPE_STRING, true); + vals[1] = new Value(zeek::TYPE_STRING, true); vals[1]->val.string_val.data = copy_string(Info().source); vals[1]->val.string_val.length = strlen(Info().source); - vals[2] = new Value(TYPE_STRING, true); + vals[2] = new Value(zeek::TYPE_STRING, true); vals[2]->val.string_val.data = copy_string(key.c_str()); vals[2]->val.string_val.length = key.size(); vals[3] = eventval; diff --git a/src/input/readers/config/Config.h b/src/input/readers/config/Config.h index e56576d375..005da75b7c 100644 --- a/src/input/readers/config/Config.h +++ b/src/input/readers/config/Config.h @@ -50,7 +50,7 @@ private: std::string empty_field; std::unique_ptr formatter; - std::unordered_map> option_types; + std::unordered_map> option_types; std::unordered_map option_values; }; diff --git a/src/input/readers/raw/Raw.cc b/src/input/readers/raw/Raw.cc index d1dd8c9aac..fb2a009bc1 100644 --- a/src/input/readers/raw/Raw.cc +++ b/src/input/readers/raw/Raw.cc @@ -396,12 +396,12 @@ bool Raw::DoInit(const ReaderInfo& info, int num_fields, const Field* const* fie return false; } - if ( fields[0]->type != TYPE_STRING ) + if ( fields[0]->type != zeek::TYPE_STRING ) { Error("First field for raw reader always has to be of type string."); return false; } - if ( use_stderr && fields[1]->type != TYPE_BOOL ) + if ( use_stderr && fields[1]->type != zeek::TYPE_BOOL ) { Error("Second field for raw reader always has to be of type bool."); return false; @@ -605,14 +605,14 @@ bool Raw::DoUpdate() Value** fields = new Value*[2]; // just always reserve 2. This means that our [] is too long by a count of 1 if not using stderr. But who cares... // filter has exactly one text field. convert to it. - Value* val = new Value(TYPE_STRING, true); + Value* val = new Value(zeek::TYPE_STRING, true); val->val.string_val.data = outbuf.release(); val->val.string_val.length = length; fields[0] = val; if ( use_stderr ) { - Value* bval = new Value(TYPE_BOOL, true); + Value* bval = new Value(zeek::TYPE_BOOL, true); bval->val.int_val = 0; fields[1] = bval; } @@ -633,11 +633,11 @@ bool Raw::DoUpdate() break; Value** fields = new Value*[2]; - Value* val = new Value(TYPE_STRING, true); + Value* val = new Value(zeek::TYPE_STRING, true); val->val.string_val.data = outbuf.release(); val->val.string_val.length = length; fields[0] = val; - Value* bval = new Value(TYPE_BOOL, true); + Value* bval = new Value(zeek::TYPE_BOOL, true); bval->val.int_val = 1; // yes, we are stderr fields[1] = bval; @@ -675,15 +675,15 @@ bool Raw::DoUpdate() assert(false); Value** vals = new Value*[4]; - vals[0] = new Value(TYPE_STRING, true); + vals[0] = new Value(zeek::TYPE_STRING, true); vals[0]->val.string_val.data = copy_string(Info().name); vals[0]->val.string_val.length = strlen(Info().name); - vals[1] = new Value(TYPE_STRING, true); + vals[1] = new Value(zeek::TYPE_STRING, true); vals[1]->val.string_val.data = copy_string(Info().source); vals[1]->val.string_val.length = strlen(Info().source); - vals[2] = new Value(TYPE_COUNT, true); + vals[2] = new Value(zeek::TYPE_COUNT, true); vals[2]->val.int_val = code; - vals[3] = new Value(TYPE_BOOL, true); + vals[3] = new Value(zeek::TYPE_BOOL, true); vals[3]->val.int_val = signal; // and in this case we can signal end_of_data even for the streaming reader diff --git a/src/input/readers/sqlite/SQLite.cc b/src/input/readers/sqlite/SQLite.cc index fccb9a5b0b..733cb4cd7b 100644 --- a/src/input/readers/sqlite/SQLite.cc +++ b/src/input/readers/sqlite/SQLite.cc @@ -136,8 +136,8 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p Value* val = new Value(field->type, true); switch ( field->type ) { - case TYPE_ENUM: - case TYPE_STRING: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: { const char *text = (const char*) sqlite3_column_text(st, pos); int length = sqlite3_column_bytes(st, pos); @@ -150,7 +150,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p break; } - case TYPE_BOOL: + case zeek::TYPE_BOOL: { if ( sqlite3_column_type(st, pos) != SQLITE_INTEGER ) { @@ -172,22 +172,22 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p break; } - case TYPE_INT: + case zeek::TYPE_INT: val->val.int_val = sqlite3_column_int64(st, pos); break; - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: val->val.double_val = sqlite3_column_double(st, pos); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: val->val.uint_val = sqlite3_column_int64(st, pos); break; - case TYPE_PORT: + case zeek::TYPE_PORT: { val->val.port_val.port = sqlite3_column_int(st, pos); val->val.port_val.proto = TRANSPORT_UNKNOWN; @@ -206,7 +206,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p break; } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { const char *text = (const char*) sqlite3_column_text(st, pos); std::string s(text, sqlite3_column_bytes(st, pos)); @@ -219,7 +219,7 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p break; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { const char *text = (const char*) sqlite3_column_text(st, pos); std::string s(text, sqlite3_column_bytes(st, pos)); @@ -227,8 +227,8 @@ Value* SQLite::EntryToVal(sqlite3_stmt *st, const threading::Field *field, int p break; } - case TYPE_TABLE: - case TYPE_VECTOR: + case zeek::TYPE_TABLE: + case zeek::TYPE_VECTOR: { const char *text = (const char*) sqlite3_column_text(st, pos); std::string s(text, sqlite3_column_bytes(st, pos)); @@ -281,7 +281,7 @@ bool SQLite::DoUpdate() if ( fields[j]->secondary_name != nullptr && strcmp(fields[j]->secondary_name, name) == 0 ) { - assert(fields[j]->type == TYPE_PORT); + assert(fields[j]->type == zeek::TYPE_PORT); if ( submapping[j] != -1 ) { Error(Fmt("SQLite statement returns several columns with name %s! Cannot decide which to choose, aborting", name)); diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 75554662cf..1843868f10 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -594,8 +594,8 @@ void Packet::ProcessLayer2() IntrusivePtr Packet::ToRawPktHdrVal() const { - static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); - static auto l2_hdr_type = zeek::id::find_type("l2_hdr"); + static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); + static auto l2_hdr_type = zeek::id::find_type("l2_hdr"); auto pkt_hdr = make_intrusive(raw_pkt_hdr_type); auto l2_hdr = make_intrusive(l2_hdr_type); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 25fa2b2f83..0457f9f506 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -78,7 +78,7 @@ struct Manager::Stream { EnumVal* id; bool enabled; string name; - RecordType* columns; + zeek::RecordType* columns; EventHandlerPtr event; list filters; @@ -236,7 +236,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) return false; } - RecordType* columns = sval->GetField("columns") + zeek::RecordType* columns = sval->GetField("columns") ->AsType()->AsTypeType()->GetType()->AsRecordType(); bool log_attr_present = false; @@ -271,7 +271,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) // Make sure the event is prototyped as expected. const auto& etype = event->GetType(); - if ( etype->Flavor() != FUNC_FLAVOR_EVENT ) + if ( etype->Flavor() != zeek::FUNC_FLAVOR_EVENT ) { reporter->Error("stream event is a function, not an event"); return false; @@ -386,7 +386,7 @@ bool Manager::DisableStream(EnumVal* id) } // Helper for recursive record field unrolling. -bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, +bool Manager::TraverseRecord(Stream* stream, Filter* filter, zeek::RecordType* rt, TableVal* include, TableVal* exclude, const string& path, const list& indices) { // Only include extensions for the outer record. @@ -395,7 +395,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, int i = 0; for ( int j = 0; j < num_ext_fields + rt->NumFields(); ++j ) { - RecordType* rtype; + zeek::RecordType* rtype; // If this is an ext field, set the rtype appropriately if ( j < num_ext_fields ) { @@ -429,9 +429,9 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, if ( j < num_ext_fields ) new_path = filter->ext_prefix + new_path; - if ( t->InternalType() == TYPE_INTERNAL_OTHER ) + if ( t->InternalType() == zeek::TYPE_INTERNAL_OTHER ) { - if ( t->Tag() == TYPE_RECORD ) + if ( t->Tag() == zeek::TYPE_RECORD ) { // Recurse. if ( ! TraverseRecord(stream, filter, @@ -445,23 +445,23 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, continue; } - else if ( t->Tag() == TYPE_TABLE && + else if ( t->Tag() == zeek::TYPE_TABLE && t->AsTableType()->IsSet() ) { // That's ok, we handle it below. } - else if ( t->Tag() == TYPE_VECTOR ) + else if ( t->Tag() == zeek::TYPE_VECTOR ) { // That's ok, we handle it below. } - else if ( t->Tag() == TYPE_FILE ) + else if ( t->Tag() == zeek::TYPE_FILE ) { // That's ok, we handle it below. } - else if ( t->Tag() == TYPE_FUNC ) + else if ( t->Tag() == zeek::TYPE_FUNC ) { // That's ok, we handle it below. } @@ -509,12 +509,12 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, ++filter->num_fields; filter->fields = (threading::Field**) tmp; - TypeTag st = TYPE_VOID; + zeek::TypeTag st = zeek::TYPE_VOID; - if ( t->Tag() == TYPE_TABLE ) + if ( t->Tag() == zeek::TYPE_TABLE ) st = t->AsSetType()->GetIndices()->GetPureType()->Tag(); - else if ( t->Tag() == TYPE_VECTOR ) + else if ( t->Tag() == zeek::TYPE_VECTOR ) st = t->AsVectorType()->Yield()->Tag(); bool optional = (bool)rtype->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL); @@ -580,18 +580,19 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) filter->num_ext_fields = 0; if ( filter->ext_func ) { - if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_RECORD ) + if ( filter->ext_func->GetType()->Yield()->Tag() == zeek::TYPE_RECORD ) { filter->num_ext_fields = filter->ext_func->GetType()->Yield()->AsRecordType()->NumFields(); } - else if ( filter->ext_func->GetType()->Yield()->Tag() == TYPE_VOID ) + else if ( filter->ext_func->GetType()->Yield()->Tag() == zeek::TYPE_VOID ) { // This is a special marker for the default no-implementation // of the ext_func and we'll allow it to slide. } else { - reporter->Error("Return value of log_ext is not a record (got %s)", type_name(filter->ext_func->GetType()->Yield()->Tag())); + reporter->Error("Return value of log_ext is not a record (got %s)", + zeek::type_name(filter->ext_func->GetType()->Yield()->Tag())); delete filter; return false; } @@ -646,7 +647,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { threading::Field* field = filter->fields[i]; DBG_LOG(DBG_LOGGING, " field %10s: %s", - field->name, type_name(field->type)); + field->name, zeek::type_name(field->type)); } #endif @@ -739,8 +740,8 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) IntrusivePtr rec_arg; const auto& rt = filter->path_func->GetType()->Params()->GetFieldType("rec"); - if ( rt->Tag() == TYPE_RECORD ) - rec_arg = columns->CoerceTo(cast_intrusive(rt), true); + if ( rt->Tag() == zeek::TYPE_RECORD ) + rec_arg = columns->CoerceTo(cast_intrusive(rt), true); else // Can be TYPE_ANY here. rec_arg = columns; @@ -752,7 +753,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( ! v ) return false; - if ( v->GetType()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != zeek::TYPE_STRING ) { reporter->Error("path_func did not return string"); return false; @@ -912,7 +913,7 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) return true; } -threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) +threading::Value* Manager::ValToLogVal(Val* val, zeek::BroType* ty) { if ( ! ty ) ty = val->GetType().get(); @@ -923,12 +924,12 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) threading::Value* lval = new threading::Value(ty->Tag()); switch ( lval->type ) { - case TYPE_BOOL: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: lval->val.int_val = val->InternalInt(); break; - case TYPE_ENUM: + case zeek::TYPE_ENUM: { const char* s = val->GetType()->AsEnumType()->Lookup(val->InternalInt()); @@ -948,31 +949,31 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) break; } - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: lval->val.uint_val = val->InternalUnsigned(); break; - case TYPE_PORT: + case zeek::TYPE_PORT: lval->val.port_val.port = val->AsPortVal()->Port(); lval->val.port_val.proto = val->AsPortVal()->PortType(); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: val->AsSubNet().ConvertToThreadingValue(&lval->val.subnet_val); break; - case TYPE_ADDR: + case zeek::TYPE_ADDR: val->AsAddr().ConvertToThreadingValue(&lval->val.addr_val); break; - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: lval->val.double_val = val->InternalDouble(); break; - case TYPE_STRING: + case zeek::TYPE_STRING: { const BroString* s = val->AsString(); char* buf = new char[s->Len()]; @@ -983,7 +984,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) break; } - case TYPE_FILE: + case zeek::TYPE_FILE: { const BroFile* f = val->AsFile(); string s = f->Name(); @@ -992,7 +993,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) break; } - case TYPE_FUNC: + case zeek::TYPE_FUNC: { ODesc d; const Func* f = val->AsFunc(); @@ -1003,13 +1004,13 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { auto set = val->AsTableVal()->ToPureListVal(); if ( ! set ) // ToPureListVal has reported an internal warning // already. Just keep going by making something up. - set = make_intrusive(TYPE_INT); + set = make_intrusive(zeek::TYPE_INT); lval->val.set_val.size = set->Length(); lval->val.set_val.vals = new threading::Value* [lval->val.set_val.size]; @@ -1020,7 +1021,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { VectorVal* vec = val->AsVectorVal(); lval->val.vector_val.size = vec->Size(); @@ -1038,7 +1039,7 @@ threading::Value* Manager::ValToLogVal(Val* val, BroType* ty) } default: - reporter->InternalError("unsupported type %s for log_write", type_name(lval->type)); + reporter->InternalError("unsupported type %s for log_write", zeek::type_name(lval->type)); } return lval; @@ -1372,7 +1373,7 @@ bool Manager::RemoteLogsAreEnabled(EnumVal* stream_id) return stream->enable_remote; } -RecordType* Manager::StreamColumns(EnumVal* stream_id) +zeek::RecordType* Manager::StreamColumns(EnumVal* stream_id) { auto stream = FindStream(stream_id); diff --git a/src/logging/Manager.h b/src/logging/Manager.h index 8db9904e86..eec4fcd988 100644 --- a/src/logging/Manager.h +++ b/src/logging/Manager.h @@ -224,7 +224,7 @@ public: * @return the type which corresponds to the columns in a log entry for * a given log stream. */ - RecordType* StreamColumns(EnumVal* stream_id); + zeek::RecordType* StreamColumns(EnumVal* stream_id); protected: friend class WriterFrontend; @@ -255,13 +255,13 @@ private: struct Stream; struct WriterInfo; - bool TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, + bool TraverseRecord(Stream* stream, Filter* filter, zeek::RecordType* rt, TableVal* include, TableVal* exclude, const std::string& path, const std::list& indices); threading::Value** RecordToFilterVals(Stream* stream, Filter* filter, RecordVal* columns); - threading::Value* ValToLogVal(Val* val, BroType* ty = nullptr); + threading::Value* ValToLogVal(Val* val, zeek::BroType* ty = nullptr); Stream* FindStream(EnumVal* id); void RemoveDisabledWriters(Stream* stream); void InstallRotationTimer(WriterInfo* winfo); diff --git a/src/logging/writers/none/None.cc b/src/logging/writers/none/None.cc index 3ab4f049aa..b8a4d8aa71 100644 --- a/src/logging/writers/none/None.cc +++ b/src/logging/writers/none/None.cc @@ -35,7 +35,7 @@ bool None::DoInit(const WriterInfo& info, int num_fields, { const threading::Field* field = fields[i]; std::cout << " field " << field->name << ": " - << type_name(field->type) << std::endl; + << zeek::type_name(field->type) << std::endl; } std::cout << std::endl; @@ -54,5 +54,3 @@ bool None::DoRotate(const char* rotated_path, double open, double close, bool te return true; } - - diff --git a/src/logging/writers/sqlite/SQLite.cc b/src/logging/writers/sqlite/SQLite.cc index b0ac37afa3..0ea7b686f2 100644 --- a/src/logging/writers/sqlite/SQLite.cc +++ b/src/logging/writers/sqlite/SQLite.cc @@ -58,37 +58,37 @@ string SQLite::GetTableType(int arg_type, int arg_subtype) { string type; switch ( arg_type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: type = "boolean"; break; - case TYPE_INT: - case TYPE_COUNT: - case TYPE_COUNTER: - case TYPE_PORT: // note that we do not save the protocol at the moment. Just like in the case of the ascii-writer + case zeek::TYPE_INT: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: + case zeek::TYPE_PORT: // note that we do not save the protocol at the moment. Just like in the case of the ascii-writer type = "integer"; break; - case TYPE_SUBNET: - case TYPE_ADDR: + case zeek::TYPE_SUBNET: + case zeek::TYPE_ADDR: type = "text"; // sqlite3 does not have a type for internet addresses break; - case TYPE_TIME: - case TYPE_INTERVAL: - case TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: type = "double precision"; break; - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: type = "text"; break; - case TYPE_TABLE: - case TYPE_VECTOR: + case zeek::TYPE_TABLE: + case zeek::TYPE_VECTOR: type = "text"; // dirty - but sqlite does not directly support arrays. so - we just roll it into a ","-separated string. break; @@ -243,40 +243,40 @@ int SQLite::AddParams(Value* val, int pos) return sqlite3_bind_null(st, pos); switch ( val->type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: return sqlite3_bind_int(st, pos, val->val.int_val != 0 ? 1 : 0 ); - case TYPE_INT: + case zeek::TYPE_INT: return sqlite3_bind_int(st, pos, val->val.int_val); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return sqlite3_bind_int(st, pos, val->val.uint_val); - case TYPE_PORT: + case zeek::TYPE_PORT: return sqlite3_bind_int(st, pos, val->val.port_val.port); - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { string out = io->Render(val->val.subnet_val); return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { string out = io->Render(val->val.addr_val); return sqlite3_bind_text(st, pos, out.data(), out.size(), SQLITE_TRANSIENT); } - case TYPE_TIME: - case TYPE_INTERVAL: - case TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: return sqlite3_bind_double(st, pos, val->val.double_val); - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: { if ( ! val->val.string_val.length || val->val.string_val.length == 0 ) return sqlite3_bind_null(st, pos); @@ -284,7 +284,7 @@ int SQLite::AddParams(Value* val, int pos) return sqlite3_bind_text(st, pos, val->val.string_val.data, val->val.string_val.length, SQLITE_TRANSIENT); } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { ODesc desc; desc.Clear(); @@ -306,7 +306,7 @@ int SQLite::AddParams(Value* val, int pos) return sqlite3_bind_text(st, pos, (const char*) desc.Bytes(), desc.Len(), SQLITE_TRANSIENT); } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { ODesc desc; desc.Clear(); @@ -367,4 +367,3 @@ bool SQLite::DoRotate(const char* rotated_path, double open, double close, bool return true; } - diff --git a/src/option.bif b/src/option.bif index 771095567a..d55f3600c0 100644 --- a/src/option.bif +++ b/src/option.bif @@ -164,7 +164,7 @@ function Option::set_change_handler%(ID: string, on_change: any, priority: int & return val_mgr->False(); } - if ( on_change->GetType()->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + if ( on_change->GetType()->AsFuncType()->Flavor() != zeek::FUNC_FLAVOR_FUNCTION ) { builtin_error("Option::on_change needs function argument; not hook or event"); return val_mgr->False(); diff --git a/src/parse.y b/src/parse.y index 5f80acfb5f..9d9ba8606a 100644 --- a/src/parse.y +++ b/src/parse.y @@ -135,16 +135,16 @@ bool defining_global_ID = false; std::vector saved_in_init; static Location func_hdr_location; -EnumType *cur_enum_type = 0; -static zeek::detail::ID* cur_decl_type_id = 0; +zeek::EnumType* cur_enum_type = nullptr; +static zeek::detail::ID* cur_decl_type_id = nullptr; static void parser_new_enum (void) { /* Starting a new enum definition. */ - assert(cur_enum_type == NULL); + assert(cur_enum_type == nullptr); if ( cur_decl_type_id ) - cur_enum_type = new EnumType(cur_decl_type_id->Name()); + cur_enum_type = new zeek::EnumType(cur_decl_type_id->Name()); else reporter->FatalError("incorrect syntax for enum type declaration"); } @@ -153,23 +153,23 @@ static void parser_redef_enum (zeek::detail::ID *id) { /* Redef an enum. id points to the enum to be redefined. Let cur_enum_type point to it. */ - assert(cur_enum_type == NULL); + assert(cur_enum_type == nullptr); // abort on errors; enums need to be accessible to continue parsing if ( ! id->GetType() ) reporter->FatalError("unknown enum identifier \"%s\"", id->Name()); else { - if ( ! id->GetType() || id->GetType()->Tag() != TYPE_ENUM ) + if ( ! id->GetType() || id->GetType()->Tag() != zeek::TYPE_ENUM ) reporter->FatalError("identifier \"%s\" is not an enum", id->Name()); cur_enum_type = id->GetType()->AsEnumType(); } } -static void extend_record(zeek::detail::ID* id, std::unique_ptr fields, +static void extend_record(zeek::detail::ID* id, std::unique_ptr fields, std::unique_ptr>> attrs) { - std::set types = BroType::GetAliases(id->Name()); + std::set types = zeek::BroType::GetAliases(id->Name()); if ( types.empty() ) { @@ -201,7 +201,7 @@ static void extend_record(zeek::detail::ID* id, std::unique_ptr static IntrusivePtr make_attributes(std::vector>* attrs, - IntrusivePtr t, bool in_record, bool is_global) + IntrusivePtr t, bool in_record, bool is_global) { if ( ! attrs ) return nullptr; @@ -222,7 +222,7 @@ static bool expr_is_table_type_name(const zeek::detail::Expr* expr) if ( type->IsTable() ) return true; - if ( type->Tag() == TYPE_TYPE ) + if ( type->Tag() == zeek::TYPE_TYPE ) return type->AsTypeType()->GetType()->IsTable(); return false; @@ -241,12 +241,12 @@ static bool expr_is_table_type_name(const zeek::detail::Expr* expr) zeek::detail::EventExpr* event_expr; zeek::detail::Stmt* stmt; zeek::detail::ListExpr* list; - BroType* type; - RecordType* record; - FuncType* func_type; - TypeList* type_l; - TypeDecl* type_decl; - type_decl_list* type_decl_l; + zeek::BroType* type; + zeek::RecordType* record; + zeek::FuncType* func_type; + zeek::TypeList* type_l; + zeek::TypeDecl* type_decl; + zeek::type_decl_list* type_decl_l; zeek::detail::Case* c_case; zeek::detail::case_list* case_l; zeek::detail::Attr* attr; @@ -498,7 +498,7 @@ expr: auto func_id = current_scope()->GenerateTemporary("anonymous-function"); func_id->SetInferReturnType(true); begin_func(std::move(func_id), current_module.c_str(), - FUNC_FLAVOR_FUNCTION, false, + zeek::FUNC_FLAVOR_FUNCTION, false, {AdoptRef{}, $3}); } lambda_body @@ -600,16 +600,16 @@ expr: const auto& ctor_type = $1->AsNameExpr()->Id()->GetType(); switch ( ctor_type->Tag() ) { - case TYPE_RECORD: + case zeek::TYPE_RECORD: { auto rce = make_intrusive( IntrusivePtr{AdoptRef{}, $4}); - auto rt = cast_intrusive(ctor_type); + auto rt = cast_intrusive(ctor_type); $$ = new zeek::detail::RecordCoerceExpr(std::move(rce), std::move(rt)); } break; - case TYPE_TABLE: + case zeek::TYPE_TABLE: if ( ctor_type->IsTable() ) $$ = new zeek::detail::TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); else @@ -617,7 +617,7 @@ expr: break; - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: $$ = new zeek::detail::VectorConstructorExpr({AdoptRef{}, $4}, ctor_type); break; @@ -686,13 +686,13 @@ expr: if ( ! id->GetType() ) { id->Error("undeclared variable"); - id->SetType(error_type()); + id->SetType(zeek::error_type()); $$ = new zeek::detail::NameExpr(std::move(id)); } else if ( id->IsEnumConst() ) { - EnumType* t = id->GetType()->AsEnumType(); + zeek::EnumType* t = id->GetType()->AsEnumType(); int intval = t->Lookup(id->ModuleName(), id->Name()); if ( intval < 0 ) @@ -731,8 +731,8 @@ expr: set_location(@1, @3); IntrusivePtr e{AdoptRef{}, $2}; - if ( IsIntegral(e->GetType()->Tag()) ) - e = make_intrusive(std::move(e), TYPE_INT); + if ( zeek::IsIntegral(e->GetType()->Tag()) ) + e = make_intrusive(std::move(e), zeek::TYPE_INT); $$ = new zeek::detail::SizeExpr(std::move(e)); } @@ -774,13 +774,13 @@ enum_body: enum_body_list { $$ = cur_enum_type; - cur_enum_type = NULL; + cur_enum_type = nullptr; } | enum_body_list ',' { $$ = cur_enum_type; - cur_enum_type = NULL; + cur_enum_type = nullptr; } ; @@ -801,7 +801,7 @@ enum_body_elem: set_location(@1, @3); assert(cur_enum_type); - if ( $3->GetType()->Tag() != TYPE_COUNT ) + if ( $3->GetType()->Tag() != zeek::TYPE_COUNT ) reporter->Error("enumerator is not a count constant"); else cur_enum_type->AddName(current_module, $1, @@ -828,84 +828,84 @@ enum_body_elem: type: TOK_BOOL { set_location(@1); - $$ = base_type(TYPE_BOOL)->Ref(); + $$ = zeek::base_type(zeek::TYPE_BOOL)->Ref(); } | TOK_INT { set_location(@1); - $$ = base_type(TYPE_INT)->Ref(); + $$ = zeek::base_type(zeek::TYPE_INT)->Ref(); } | TOK_COUNT { set_location(@1); - $$ = base_type(TYPE_COUNT)->Ref(); + $$ = zeek::base_type(zeek::TYPE_COUNT)->Ref(); } | TOK_COUNTER { set_location(@1); - $$ = base_type(TYPE_COUNTER)->Ref(); + $$ = zeek::base_type(zeek::TYPE_COUNTER)->Ref(); } | TOK_DOUBLE { set_location(@1); - $$ = base_type(TYPE_DOUBLE)->Ref(); + $$ = zeek::base_type(zeek::TYPE_DOUBLE)->Ref(); } | TOK_TIME { set_location(@1); - $$ = base_type(TYPE_TIME)->Ref(); + $$ = zeek::base_type(zeek::TYPE_TIME)->Ref(); } | TOK_INTERVAL { set_location(@1); - $$ = base_type(TYPE_INTERVAL)->Ref(); + $$ = zeek::base_type(zeek::TYPE_INTERVAL)->Ref(); } | TOK_STRING { set_location(@1); - $$ = base_type(TYPE_STRING)->Ref(); + $$ = zeek::base_type(zeek::TYPE_STRING)->Ref(); } | TOK_PATTERN { set_location(@1); - $$ = base_type(TYPE_PATTERN)->Ref(); + $$ = zeek::base_type(zeek::TYPE_PATTERN)->Ref(); } | TOK_TIMER { set_location(@1); - $$ = base_type(TYPE_TIMER)->Ref(); + $$ = zeek::base_type(zeek::TYPE_TIMER)->Ref(); } | TOK_PORT { set_location(@1); - $$ = base_type(TYPE_PORT)->Ref(); + $$ = zeek::base_type(zeek::TYPE_PORT)->Ref(); } | TOK_ADDR { set_location(@1); - $$ = base_type(TYPE_ADDR)->Ref(); + $$ = zeek::base_type(zeek::TYPE_ADDR)->Ref(); } | TOK_SUBNET { set_location(@1); - $$ = base_type(TYPE_SUBNET)->Ref(); + $$ = zeek::base_type(zeek::TYPE_SUBNET)->Ref(); } | TOK_ANY { set_location(@1); - $$ = base_type(TYPE_ANY)->Ref(); + $$ = zeek::base_type(zeek::TYPE_ANY)->Ref(); } | TOK_TABLE '[' type_list ']' TOK_OF type { set_location(@1, @6); - $$ = new TableType({AdoptRef{}, $3}, {AdoptRef{}, $6}); + $$ = new zeek::TableType({AdoptRef{}, $3}, {AdoptRef{}, $6}); } | TOK_SET '[' type_list ']' { set_location(@1, @4); - $$ = new SetType({AdoptRef{}, $3}, nullptr); + $$ = new zeek::SetType({AdoptRef{}, $3}, nullptr); } | TOK_RECORD '{' @@ -915,7 +915,7 @@ type: '}' { set_location(@1, @5); - $$ = new RecordType($4); + $$ = new zeek::RecordType($4); } | TOK_UNION '{' type_list '}' @@ -951,7 +951,7 @@ type: | TOK_VECTOR TOK_OF type { set_location(@1, @3); - $$ = new VectorType({AdoptRef{}, $3}); + $$ = new zeek::VectorType({AdoptRef{}, $3}); } | TOK_FUNCTION func_params @@ -963,31 +963,31 @@ type: | TOK_EVENT '(' formal_args ')' { set_location(@1, @3); - $$ = new FuncType({AdoptRef{}, $3}, nullptr, FUNC_FLAVOR_EVENT); + $$ = new zeek::FuncType({AdoptRef{}, $3}, nullptr, zeek::FUNC_FLAVOR_EVENT); } | TOK_HOOK '(' formal_args ')' { set_location(@1, @3); - $$ = new FuncType({AdoptRef{}, $3}, base_type(TYPE_BOOL), FUNC_FLAVOR_HOOK); + $$ = new zeek::FuncType({AdoptRef{}, $3}, zeek::base_type(zeek::TYPE_BOOL), zeek::FUNC_FLAVOR_HOOK); } | TOK_FILE TOK_OF type { set_location(@1, @3); - $$ = new FileType({AdoptRef{}, $3}); + $$ = new zeek::FileType({AdoptRef{}, $3}); } | TOK_FILE { set_location(@1); - $$ = new FileType(base_type(TYPE_STRING)); + $$ = new zeek::FileType(zeek::base_type(zeek::TYPE_STRING)); } | TOK_OPAQUE TOK_OF TOK_ID { set_location(@1, @3); - $$ = new OpaqueType($3); + $$ = new zeek::OpaqueType($3); } | resolve_id @@ -997,7 +997,7 @@ type: zeek::detail::NullStmt here; if ( $1 ) $1->Error("not a Zeek type", &here); - $$ = error_type()->Ref(); + $$ = zeek::error_type()->Ref(); } else { @@ -1014,7 +1014,7 @@ type_list: { $1->AppendEvenIfNotPure({AdoptRef{}, $3}); } | type { - $$ = new TypeList({NewRef{}, $1}); + $$ = new zeek::TypeList({NewRef{}, $1}); $$->Append({AdoptRef{}, $1}); } ; @@ -1026,7 +1026,7 @@ type_decl_list: } | { - $$ = new type_decl_list(); + $$ = new zeek::type_decl_list(); } ; @@ -1035,7 +1035,7 @@ type_decl: { set_location(@1, @4); auto attrs = make_attributes($4, {NewRef{}, $3}, in_record > 0, false); - $$ = new TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); + $$ = new zeek::TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); if ( in_record > 0 && cur_decl_type_id ) zeekygen_mgr->RecordField(cur_decl_type_id, $$, ::filename); @@ -1044,11 +1044,11 @@ type_decl: formal_args: formal_args_decl_list - { $$ = new RecordType($1); } + { $$ = new zeek::RecordType($1); } | formal_args_decl_list ';' - { $$ = new RecordType($1); } + { $$ = new zeek::RecordType($1); } | - { $$ = new RecordType(new type_decl_list()); } + { $$ = new zeek::RecordType(new zeek::type_decl_list()); } ; formal_args_decl_list: @@ -1057,7 +1057,7 @@ formal_args_decl_list: | formal_args_decl_list ',' formal_args_decl { $1->push_back($3); } | formal_args_decl - { $$ = new type_decl_list(); $$->push_back($1); } + { $$ = new zeek::type_decl_list(); $$->push_back($1); } ; formal_args_decl: @@ -1065,7 +1065,7 @@ formal_args_decl: { set_location(@1, @4); auto attrs = make_attributes($4, {NewRef{}, $3}, true, false); - $$ = new TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); + $$ = new zeek::TypeDecl($1, {AdoptRef{}, $3}, std::move(attrs)); } ; @@ -1136,7 +1136,7 @@ decl: if ( ! $3->GetType() ) $3->Error("unknown identifier"); else - extend_record($3, std::unique_ptr($8), + extend_record($3, std::unique_ptr($8), std::unique_ptr>>($11)); } @@ -1180,7 +1180,7 @@ func_hdr: { IntrusivePtr id{AdoptRef{}, $2}; begin_func(id, current_module.c_str(), - FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, + zeek::FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; zeekygen_mgr->Identifier(std::move(id)); @@ -1195,23 +1195,23 @@ func_hdr: } begin_func({NewRef{}, $2}, current_module.c_str(), - FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, + zeek::FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; } | TOK_HOOK def_global_id func_params opt_attr { - $3->ClearYieldType(FUNC_FLAVOR_HOOK); - $3->SetYieldType(base_type(TYPE_BOOL)); + $3->ClearYieldType(zeek::FUNC_FLAVOR_HOOK); + $3->SetYieldType(zeek::base_type(zeek::TYPE_BOOL)); begin_func({NewRef{}, $2}, current_module.c_str(), - FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, + zeek::FUNC_FLAVOR_HOOK, 0, {NewRef{}, $3}, std::unique_ptr>>{$4}); $$ = $3; } | TOK_REDEF TOK_EVENT event_id func_params opt_attr { begin_func({NewRef{}, $3}, current_module.c_str(), - FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, + zeek::FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, std::unique_ptr>>{$5}); $$ = $4; } @@ -1275,16 +1275,16 @@ begin_func: func_params { auto id = current_scope()->GenerateTemporary("anonymous-function"); - begin_func(id, current_module.c_str(), FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1}); + begin_func(id, current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, 0, {AdoptRef{}, $1}); $$ = id.release(); } ; func_params: '(' formal_args ')' ':' type - { $$ = new FuncType({AdoptRef{}, $2}, {AdoptRef{}, $5}, FUNC_FLAVOR_FUNCTION); } + { $$ = new zeek::FuncType({AdoptRef{}, $2}, {AdoptRef{}, $5}, zeek::FUNC_FLAVOR_FUNCTION); } | '(' formal_args ')' - { $$ = new FuncType({AdoptRef{}, $2}, base_type(TYPE_VOID), FUNC_FLAVOR_FUNCTION); } + { $$ = new zeek::FuncType({AdoptRef{}, $2}, zeek::base_type(zeek::TYPE_VOID), zeek::FUNC_FLAVOR_FUNCTION); } ; opt_type: @@ -1328,7 +1328,7 @@ index_slice: make_intrusive( IntrusivePtr{NewRef{}, $1}); - if ( ! IsIntegral(low->GetType()->Tag()) || ! IsIntegral(high->GetType()->Tag()) ) + if ( ! zeek::IsIntegral(low->GetType()->Tag()) || ! zeek::IsIntegral(high->GetType()->Tag()) ) reporter->Error("slice notation must have integral values as indexes"); auto le = make_intrusive(std::move(low)); @@ -1387,7 +1387,7 @@ attr: { $$ = new zeek::detail::Attr(zeek::detail::ATTR_DEPRECATED); } | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->GetType()->Tag()) ) + if ( zeek::IsString($3->GetType()->Tag()) ) $$ = new zeek::detail::Attr( zeek::detail::ATTR_DEPRECATED, make_intrusive(IntrusivePtr{AdoptRef{}, $3})); @@ -1667,7 +1667,7 @@ case_type: | TOK_TYPE type TOK_AS TOK_ID { const char* name = $4; - IntrusivePtr type{AdoptRef{}, $2}; + IntrusivePtr type{AdoptRef{}, $2}; auto case_var = lookup_ID(name, current_module.c_str()); if ( case_var && case_var->IsGlobal() ) @@ -1831,8 +1831,8 @@ global_or_event_id: { const auto& t = $$->GetType(); - if ( t->Tag() != TYPE_FUNC || - t->AsFuncType()->Flavor() != FUNC_FLAVOR_FUNCTION ) + if ( t->Tag() != zeek::TYPE_FUNC || + t->AsFuncType()->Flavor() != zeek::FUNC_FLAVOR_FUNCTION ) reporter->Warning("%s", $$->GetDeprecationWarning().c_str()); } @@ -1884,7 +1884,7 @@ opt_deprecated: | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->GetType()->Tag()) ) + if ( zeek::IsString($3->GetType()->Tag()) ) $$ = new zeek::detail::ConstExpr({AdoptRef{}, $3}); else { diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 3abb08c8a7..f503066a51 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -52,10 +52,10 @@ public: /** * @return The enum type associated with the script-layer "Tag". */ - const IntrusivePtr& GetTagType() const; + const IntrusivePtr& GetTagType() const; [[deprecated("Remove in v4.1. Use GetTagType() instead.")]] - EnumType* GetTagEnumType() const; + zeek::EnumType* GetTagEnumType() const; /** * Get a component name from its tag. @@ -128,7 +128,7 @@ public: private: std::string module; /**< Script layer module in which component tags live. */ - IntrusivePtr tag_enum_type; /**< Enum type of component tags. */ + IntrusivePtr tag_enum_type; /**< Enum type of component tags. */ std::map components_by_name; std::map components_by_tag; std::map components_by_val; @@ -137,7 +137,7 @@ private: template ComponentManager::ComponentManager(const std::string& arg_module, const std::string& local_id) : module(arg_module), - tag_enum_type(make_intrusive(module + "::" + local_id)) + tag_enum_type(make_intrusive(module + "::" + local_id)) { auto id = install_ID(local_id.c_str(), module.c_str(), true, true); add_type(id.get(), tag_enum_type, nullptr); @@ -163,13 +163,13 @@ std::list ComponentManager::GetComponents() const } template -const IntrusivePtr& ComponentManager::GetTagType() const +const IntrusivePtr& ComponentManager::GetTagType() const { return tag_enum_type; } template -EnumType* ComponentManager::GetTagEnumType() const +zeek::EnumType* ComponentManager::GetTagEnumType() const { return tag_enum_type.get(); } diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 0de42bef47..98411fbd59 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -18,11 +18,11 @@ static void topk_element_hash_delete_func(void* val) delete e; } -void TopkVal::Typify(IntrusivePtr t) +void TopkVal::Typify(IntrusivePtr t) { assert(!hash && !type); type = std::move(t); - auto tl = make_intrusive(type); + auto tl = make_intrusive(type); tl->Append(type); hash = new CompositeHash(std::move(tl)); } @@ -191,7 +191,7 @@ IntrusivePtr TopkVal::GetTopK(int k) const // returns vector return nullptr; } - auto v = make_intrusive(type); + auto v = make_intrusive(type); auto t = make_intrusive(std::move(v)); // this does no estimation if the results is correct! diff --git a/src/probabilistic/Topk.h b/src/probabilistic/Topk.h index c71dbfe769..fcfcb2c61f 100644 --- a/src/probabilistic/Topk.h +++ b/src/probabilistic/Topk.h @@ -161,9 +161,9 @@ private: * * @param t type that is tracked */ - void Typify(IntrusivePtr t); + void Typify(IntrusivePtr t); - IntrusivePtr type; + IntrusivePtr type; CompositeHash* hash; std::list buckets; PDict* elementDict; diff --git a/src/scan.l b/src/scan.l index 0e4e769d56..b359a5f593 100644 --- a/src/scan.l +++ b/src/scan.l @@ -47,7 +47,7 @@ struct ZeekINode { } extern YYLTYPE yylloc; // holds start line and column of token -extern EnumType* cur_enum_type; +extern zeek::EnumType* cur_enum_type; // Track the @if... depth. ptr_compat_int current_depth = 0; @@ -1005,7 +1005,7 @@ int yywrap() const auto& param_id = lookup_ID(param, GLOBAL_MODULE_NAME); Val* v = param_id ? param_id->GetVal().get() : nullptr; - if ( v && v->GetType() && v->GetType()->Tag() == TYPE_STRING ) + if ( v && v->GetType() && v->GetType()->Tag() == zeek::TYPE_STRING ) opt_quote = "\""; // use quotes policy += std::string("redef ") + param + "=" diff --git a/src/stats.bif b/src/stats.bif index c9e7e6de80..901f62a223 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -4,19 +4,19 @@ #include "threading/Manager.h" #include "broker/Manager.h" -IntrusivePtr ProcStats; -IntrusivePtr NetStats; -IntrusivePtr MatcherStats; -IntrusivePtr ReassemblerStats; -IntrusivePtr DNSStats; -IntrusivePtr ConnStats; -IntrusivePtr GapStats; -IntrusivePtr EventStats; -IntrusivePtr ThreadStats; -IntrusivePtr TimerStats; -IntrusivePtr FileAnalysisStats; -IntrusivePtr BrokerStats; -IntrusivePtr ReporterStats; +IntrusivePtr ProcStats; +IntrusivePtr NetStats; +IntrusivePtr MatcherStats; +IntrusivePtr ReassemblerStats; +IntrusivePtr DNSStats; +IntrusivePtr ConnStats; +IntrusivePtr GapStats; +IntrusivePtr EventStats; +IntrusivePtr ThreadStats; +IntrusivePtr TimerStats; +IntrusivePtr FileAnalysisStats; +IntrusivePtr BrokerStats; +IntrusivePtr ReporterStats; %%} ## Returns packet capture statistics. Statistics include the number of diff --git a/src/strings.bif b/src/strings.bif index 00160454d1..909280b564 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(zeek::id::find_type("string_vec")); + auto rval = make_intrusive(zeek::id::find_type("string_vec")); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 16f0483fa0..bcf9a1c9f6 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1172,7 +1172,7 @@ IntrusivePtr Supervisor::Node::ToRecord() const static IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { - static auto node_type = zeek::id::find_type("Cluster::NodeType"); + static auto node_type = zeek::id::find_type("Cluster::NodeType"); switch ( role ) { case BifEnum::Supervisor::LOGGER: @@ -1193,7 +1193,7 @@ bool Supervisor::SupervisedNode::InitCluster() const if ( config.cluster.empty() ) return false; - const auto& cluster_node_type = zeek::id::find_type("Cluster::Node"); + const auto& cluster_node_type = zeek::id::find_type("Cluster::Node"); const auto& cluster_nodes_id = zeek::id::find("Cluster::nodes"); const auto& cluster_manager_is_logger_id = zeek::id::find("Cluster::manager_is_logger"); auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal(); diff --git a/src/threading/Formatter.h b/src/threading/Formatter.h index 83a3667145..e31cf56f4b 100644 --- a/src/threading/Formatter.h +++ b/src/threading/Formatter.h @@ -81,7 +81,7 @@ public: * @return The new value, or null on error. Errors must also be * flagged via the thread. */ - virtual threading::Value* ParseValue(const std::string& s, const std::string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const = 0; + virtual threading::Value* ParseValue(const std::string& s, const std::string& name, zeek::TypeTag type, zeek::TypeTag subtype = zeek::TYPE_ERROR) const = 0; /** * Convert an IP address into a string. diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index e3f82b9b55..45dae236a3 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -47,8 +47,8 @@ bool Field::Read(SerializationFormat* fmt) name = copy_string(tmp_name.c_str()); - type = (TypeTag) t; - subtype = (TypeTag) st; + type = static_cast(t); + subtype = static_cast(st); return true; } @@ -79,15 +79,15 @@ std::string Field::TypeName() const // We do not support tables, if the internal Bro type is table it // always is a set. - if ( type == TYPE_TABLE ) + if ( type == zeek::TYPE_TABLE ) n = "set"; else - n = type_name(type); + n = zeek::type_name(type); - if ( (type == TYPE_TABLE) || (type == TYPE_VECTOR) ) + if ( (type == zeek::TYPE_TABLE) || (type == zeek::TYPE_VECTOR) ) { n += "["; - n += type_name(subtype); + n += zeek::type_name(subtype); n += "]"; } @@ -99,13 +99,13 @@ Value::~Value() if ( ! present ) return; - if ( type == TYPE_ENUM || type == TYPE_STRING || type == TYPE_FILE || type == TYPE_FUNC ) + if ( type == zeek::TYPE_ENUM || type == zeek::TYPE_STRING || type == zeek::TYPE_FILE || type == zeek::TYPE_FUNC ) delete [] val.string_val.data; - else if ( type == TYPE_PATTERN ) + else if ( type == zeek::TYPE_PATTERN ) delete [] val.pattern_text_val; - else if ( type == TYPE_TABLE ) + else if ( type == zeek::TYPE_TABLE ) { for ( int i = 0; i < val.set_val.size; i++ ) delete val.set_val.vals[i]; @@ -113,7 +113,7 @@ Value::~Value() delete [] val.set_val.vals; } - else if ( type == TYPE_VECTOR ) + else if ( type == zeek::TYPE_VECTOR ) { for ( int i = 0; i < val.vector_val.size; i++ ) delete val.vector_val.vals[i]; @@ -122,32 +122,32 @@ Value::~Value() } } -bool Value::IsCompatibleType(BroType* t, bool atomic_only) +bool Value::IsCompatibleType(zeek::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_ADDR: - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: + case zeek::TYPE_PORT: + case zeek::TYPE_SUBNET: + case zeek::TYPE_ADDR: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: return true; - case TYPE_RECORD: + case zeek::TYPE_RECORD: return ! atomic_only; - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( atomic_only ) return false; @@ -158,7 +158,7 @@ bool Value::IsCompatibleType(BroType* t, bool atomic_only) return IsCompatibleType(t->AsSetType()->GetIndices()->GetPureType().get(), true); } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( atomic_only ) return false; @@ -180,22 +180,22 @@ bool Value::Read(SerializationFormat* fmt) if ( ! (fmt->Read(&ty, "type") && fmt->Read(&sty, "subtype") && fmt->Read(&present, "present")) ) return false; - type = (TypeTag)(ty); - subtype = (TypeTag)(sty); + type = static_cast(ty); + subtype = static_cast(sty); if ( ! present ) return true; switch ( type ) { - case TYPE_BOOL: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: return fmt->Read(&val.int_val, "int"); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return fmt->Read(&val.uint_val, "uint"); - case TYPE_PORT: { + case zeek::TYPE_PORT: { int proto; if ( ! (fmt->Read(&val.port_val.port, "port") && fmt->Read(&proto, "proto") ) ) { return false; @@ -221,7 +221,7 @@ bool Value::Read(SerializationFormat* fmt) return true; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { char family; @@ -243,7 +243,7 @@ bool Value::Read(SerializationFormat* fmt) abort(); } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { char length; char family; @@ -268,18 +268,18 @@ bool Value::Read(SerializationFormat* fmt) abort(); } - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: return fmt->Read(&val.double_val, "double"); - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: return fmt->Read(&val.string_val.data, &val.string_val.length, "string"); - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( ! fmt->Read(&val.set_val.size, "set_size") ) return false; @@ -297,7 +297,7 @@ bool Value::Read(SerializationFormat* fmt) return true; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( ! fmt->Read(&val.vector_val.size, "vector_size") ) return false; @@ -317,7 +317,7 @@ bool Value::Read(SerializationFormat* fmt) default: reporter->InternalError("unsupported type %s in Value::Read", - type_name(type)); + zeek::type_name(type)); } return false; @@ -334,18 +334,18 @@ bool Value::Write(SerializationFormat* fmt) const return true; switch ( type ) { - case TYPE_BOOL: - case TYPE_INT: + case zeek::TYPE_BOOL: + case zeek::TYPE_INT: return fmt->Write(val.int_val, "int"); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return fmt->Write(val.uint_val, "uint"); - case TYPE_PORT: + case zeek::TYPE_PORT: return fmt->Write(val.port_val.port, "port") && fmt->Write(val.port_val.proto, "proto"); - case TYPE_ADDR: + case zeek::TYPE_ADDR: { switch ( val.addr_val.family ) { case IPv4: @@ -361,7 +361,7 @@ bool Value::Write(SerializationFormat* fmt) const abort(); } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { if ( ! fmt->Write((char)val.subnet_val.length, "subnet-length") ) return false; @@ -380,18 +380,18 @@ bool Value::Write(SerializationFormat* fmt) const abort(); } - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: return fmt->Write(val.double_val, "double"); - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: return fmt->Write(val.string_val.data, val.string_val.length, "string"); - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( ! fmt->Write(val.set_val.size, "set_size") ) return false; @@ -405,7 +405,7 @@ bool Value::Write(SerializationFormat* fmt) const return true; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( ! fmt->Write(val.vector_val.size, "vector_size") ) return false; @@ -421,7 +421,7 @@ bool Value::Write(SerializationFormat* fmt) const default: reporter->InternalError("unsupported type %s in Value::Write", - type_name(type)); + zeek::type_name(type)); } // unreachable @@ -445,35 +445,35 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return nullptr; // unset field switch ( val->type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: return val_mgr->Bool(val->val.int_val)->Ref(); - case TYPE_INT: + case zeek::TYPE_INT: return val_mgr->Int(val->val.int_val).release(); - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: return val_mgr->Count(val->val.int_val).release(); - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: return new DoubleVal(val->val.double_val); - case TYPE_TIME: + case zeek::TYPE_TIME: return new TimeVal(val->val.double_val); - case TYPE_INTERVAL: + case zeek::TYPE_INTERVAL: return new IntervalVal(val->val.double_val); - case TYPE_STRING: + case zeek::TYPE_STRING: { BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, true); return new StringVal(s); } - case TYPE_PORT: + case zeek::TYPE_PORT: return val_mgr->Port(val->val.port_val.port, val->val.port_val.proto)->Ref(); - case TYPE_ADDR: + case zeek::TYPE_ADDR: { IPAddr* addr = nullptr; switch ( val->val.addr_val.family ) { @@ -494,7 +494,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return addrval; } - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { IPAddr* addr = nullptr; switch ( val->val.subnet_val.prefix.family ) { @@ -515,29 +515,29 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return subnetval; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { RE_Matcher* re = new RE_Matcher(val->val.pattern_text_val); re->Compile(); return new PatternVal(re); } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { - IntrusivePtr set_index; - if ( val->val.set_val.size == 0 && val->subtype == TYPE_VOID ) + IntrusivePtr set_index; + if ( val->val.set_val.size == 0 && val->subtype == zeek::TYPE_VOID ) // don't know type - unspecified table. - set_index = make_intrusive(); + set_index = make_intrusive(); else { // all entries have to have the same type... - TypeTag stag = val->subtype; - if ( stag == TYPE_VOID ) - TypeTag stag = val->val.set_val.vals[0]->type; + zeek::TypeTag stag = val->subtype; + if ( stag == zeek::TYPE_VOID ) + stag = val->val.set_val.vals[0]->type; - IntrusivePtr index_type; + IntrusivePtr index_type; - if ( stag == TYPE_ENUM ) + if ( stag == zeek::TYPE_ENUM ) { // Enums are not a base-type, so need to look it up. const auto& sv = val->val.set_val.vals[0]->val.string_val; @@ -556,13 +556,13 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e index_type = enum_id->GetType(); } else - index_type = base_type(stag); + index_type = zeek::base_type(stag); - set_index = make_intrusive(index_type); + set_index = make_intrusive(index_type); set_index->Append(std::move(index_type)); } - auto s = make_intrusive(std::move(set_index), nullptr); + auto s = make_intrusive(std::move(set_index), nullptr); TableVal* t = new TableVal(std::move(s)); for ( int j = 0; j < val->val.set_val.size; j++ ) { @@ -573,23 +573,23 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return t; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { - IntrusivePtr type; + IntrusivePtr type; - if ( val->val.vector_val.size == 0 && val->subtype == TYPE_VOID ) + if ( val->val.vector_val.size == 0 && val->subtype == zeek::TYPE_VOID ) // don't know type - unspecified table. - type = base_type(TYPE_ANY); + type = zeek::base_type(zeek::TYPE_ANY); else { // all entries have to have the same type... - if ( val->subtype == TYPE_VOID ) - type = base_type(val->val.vector_val.vals[0]->type); + if ( val->subtype == zeek::TYPE_VOID ) + type = zeek::base_type(val->val.vector_val.vals[0]->type); else - type = base_type(val->subtype); + type = zeek::base_type(val->subtype); } - auto vt = make_intrusive(std::move(type)); + auto vt = make_intrusive(std::move(type)); auto v = make_intrusive(std::move(vt)); for ( int j = 0; j < val->val.vector_val.size; j++ ) @@ -601,7 +601,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return v.release(); } - case TYPE_ENUM: { + case zeek::TYPE_ENUM: { // Convert to string first to not have to deal with missing // \0's... std::string enum_string(val->val.string_val.data, val->val.string_val.length); @@ -618,7 +618,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e return nullptr; } - EnumType* t = id->GetType()->AsEnumType(); + zeek::EnumType* t = id->GetType()->AsEnumType(); int intval = t->Lookup(id->ModuleName(), id->Name()); if ( intval < 0 ) { diff --git a/src/threading/SerialTypes.h b/src/threading/SerialTypes.h index 0969e5b6db..355fcc0837 100644 --- a/src/threading/SerialTypes.h +++ b/src/threading/SerialTypes.h @@ -21,18 +21,23 @@ struct Field { //! Needed by input framework. Port fields have two names (one for the //! port, one for the type), and this specifies the secondary name. const char* secondary_name; - TypeTag type; //! Type of the field. - TypeTag subtype; //! Inner type for sets and vectors. + zeek::TypeTag type; //! Type of the field. + zeek::TypeTag subtype; //! Inner type for sets and vectors. bool optional; //! True if field is optional. /** * Constructor. */ - Field(const char* name, const char* secondary_name, TypeTag type, TypeTag subtype, bool optional) + Field(const char* name, const char* secondary_name, zeek::TypeTag type, zeek::TypeTag subtype, bool optional) : name(name ? copy_string(name) : nullptr), secondary_name(secondary_name ? copy_string(secondary_name) : nullptr), type(type), subtype(subtype), optional(optional) { } + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead")]] + Field(const char* name, const char* secondary_name, ::TypeTag type, ::TypeTag subtype, bool optional) : + Field(name, secondary_name, static_cast(type), static_cast(subtype), optional) + {} + /** * Copy constructor. */ @@ -85,8 +90,8 @@ private: * those Vals supported). */ struct Value { - TypeTag type; //! The type of the value. - TypeTag subtype; //! Inner type for sets and vectors. + zeek::TypeTag type; //! The type of the value. + zeek::TypeTag subtype; //! Inner type for sets and vectors. bool present; //! False for optional record fields that are not set. struct set_t { bro_int_t size; Value** vals; }; @@ -140,9 +145,15 @@ struct Value { * * arg_present: False if the value represents an optional record field * that is not set. - */ - Value(TypeTag arg_type = TYPE_ERROR, bool arg_present = true) - : type(arg_type), subtype(TYPE_VOID), present(arg_present) {} + */ + Value(zeek::TypeTag arg_type = zeek::TYPE_ERROR, bool arg_present = true) + : type(arg_type), subtype(zeek::TYPE_VOID), present(arg_present) + {} + + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag.")]] + Value(::TypeTag arg_type, bool arg_present = true) + : Value(static_cast(arg_type), arg_present) + {} /** * Constructor. @@ -154,8 +165,14 @@ struct Value { * arg_present: False if the value represents an optional record field * that is not set. */ - Value(TypeTag arg_type, TypeTag arg_subtype, bool arg_present = true) - : type(arg_type), subtype(arg_subtype), present(arg_present) {} + Value(zeek::TypeTag arg_type, zeek::TypeTag arg_subtype, bool arg_present = true) + : type(arg_type), subtype(arg_subtype), present(arg_present) + {} + + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag.")]] + Value(::TypeTag arg_type, ::TypeTag arg_subtype, bool arg_present = true) + : Value(static_cast(arg_type), static_cast(arg_subtype), arg_present) + {} /** * Destructor. @@ -185,7 +202,7 @@ struct Value { * Returns true if the type can be represented by a Value. If * `atomic_only` is true, will not permit composite types. This * method is thread-safe. */ - static bool IsCompatibleType(BroType* t, bool atomic_only=false); + static bool IsCompatibleType(zeek::BroType* t, bool atomic_only=false); /** * Convenience function to delete an array of value pointers. @@ -209,7 +226,7 @@ struct Value { private: friend class ::IPAddr; - Value(const Value& other) { } // Disabled. + Value(const Value& other) = delete; }; } diff --git a/src/threading/formatters/Ascii.cc b/src/threading/formatters/Ascii.cc index dd2aa3983a..9b9a7a7166 100644 --- a/src/threading/formatters/Ascii.cc +++ b/src/threading/formatters/Ascii.cc @@ -81,50 +81,50 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con switch ( val->type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: desc->Add(val->val.int_val ? "T" : "F"); break; - case TYPE_INT: + case zeek::TYPE_INT: desc->Add(val->val.int_val); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: desc->Add(val->val.uint_val); break; - case TYPE_PORT: + case zeek::TYPE_PORT: desc->Add(val->val.port_val.port); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: desc->Add(Render(val->val.subnet_val)); break; - case TYPE_ADDR: + case zeek::TYPE_ADDR: desc->Add(Render(val->val.addr_val)); break; - case TYPE_DOUBLE: + case zeek::TYPE_DOUBLE: // Rendering via Add() truncates trailing 0s after the // decimal point. The difference with TIME/INTERVAL is mainly // to keep the log format consistent. desc->Add(val->val.double_val, true); break; - case TYPE_INTERVAL: - case TYPE_TIME: + case zeek::TYPE_INTERVAL: + case zeek::TYPE_TIME: // Rendering via Render() keeps trailing 0s after the decimal // point. The difference with DOUBLE is mainly to keep the // log format consistent. desc->Add(Render(val->val.double_val)); break; - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: { int size = val->val.string_val.length; const char* data = val->val.string_val.data; @@ -145,7 +145,7 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { if ( ! val->val.set_val.size ) { @@ -172,7 +172,7 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { if ( ! val->val.vector_val.size ) { @@ -208,7 +208,7 @@ bool Ascii::Describe(ODesc* desc, threading::Value* val, const string& name) con } -threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype) const +threading::Value* Ascii::ParseValue(const string& s, const string& name, zeek::TypeTag type, zeek::TypeTag subtype) const { if ( ! separators.unset_field.empty() && s.compare(separators.unset_field) == 0 ) // field is not set... return new threading::Value(type, false); @@ -220,8 +220,8 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag size_t pos; switch ( type ) { - case TYPE_ENUM: - case TYPE_STRING: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: { string unescaped = get_unescaped_string(s); val->val.string_val.length = unescaped.size(); @@ -229,7 +229,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag break; } - case TYPE_BOOL: + case zeek::TYPE_BOOL: { auto stripped = strstrip(s); if ( stripped == "T" || stripped == "1" ) @@ -245,28 +245,28 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag break; } - case TYPE_INT: + case zeek::TYPE_INT: val->val.int_val = strtoll(start, &end, 10); if ( CheckNumberError(start, end) ) goto parse_error; break; - case TYPE_DOUBLE: - case TYPE_TIME: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_TIME: + case zeek::TYPE_INTERVAL: val->val.double_val = strtod(start, &end); if ( CheckNumberError(start, end) ) goto parse_error; break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: val->val.uint_val = strtoull(start, &end, 10); if ( CheckNumberError(start, end) ) goto parse_error; break; - case TYPE_PORT: + case zeek::TYPE_PORT: { auto stripped = strstrip(s); val->val.port_val.proto = TRANSPORT_UNKNOWN; @@ -298,7 +298,7 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag } break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { string unescaped = strstrip(get_unescaped_string(s)); size_t pos = unescaped.find('/'); @@ -321,14 +321,14 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag break; } - case TYPE_ADDR: + case zeek::TYPE_ADDR: { string unescaped = strstrip(get_unescaped_string(s)); val->val.addr_val = ParseAddr(unescaped); break; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { string candidate = get_unescaped_string(s); // A string is a candidate pattern iff it begins and ends with @@ -351,8 +351,8 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag goto parse_error; } - case TYPE_TABLE: - case TYPE_VECTOR: + case zeek::TYPE_TABLE: + case zeek::TYPE_VECTOR: // First - common initialization // Then - initialization for table. // Then - initialization for vector. @@ -377,13 +377,13 @@ threading::Value* Ascii::ParseValue(const string& s, const string& name, TypeTag threading::Value** lvals = new threading::Value* [length]; - if ( type == TYPE_TABLE ) + if ( type == zeek::TYPE_TABLE ) { val->val.set_val.vals = lvals; val->val.set_val.size = length; } - else if ( type == TYPE_VECTOR ) + else if ( type == zeek::TYPE_VECTOR ) { val->val.vector_val.vals = lvals; val->val.vector_val.size = length; diff --git a/src/threading/formatters/Ascii.h b/src/threading/formatters/Ascii.h index e6fd757aab..aeaaef279f 100644 --- a/src/threading/formatters/Ascii.h +++ b/src/threading/formatters/Ascii.h @@ -51,7 +51,7 @@ public: virtual bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields, threading::Value** vals) const; virtual threading::Value* ParseValue(const std::string& s, const std::string& name, - TypeTag type, TypeTag subtype = TYPE_ERROR) const; + zeek::TypeTag type, zeek::TypeTag subtype = zeek::TYPE_ERROR) const; private: bool CheckNumberError(const char* start, const char* end) const; diff --git a/src/threading/formatters/JSON.cc b/src/threading/formatters/JSON.cc index e6d702bafe..b832fb01ac 100644 --- a/src/threading/formatters/JSON.cc +++ b/src/threading/formatters/JSON.cc @@ -78,7 +78,7 @@ bool JSON::Describe(ODesc* desc, Value* val, const std::string& name) const return true; } -threading::Value* JSON::ParseValue(const std::string& s, const std::string& name, TypeTag type, TypeTag subtype) const +threading::Value* JSON::ParseValue(const std::string& s, const std::string& name, zeek::TypeTag type, zeek::TypeTag subtype) const { GetThread()->Error("JSON formatter does not support parsing yet."); return nullptr; @@ -97,37 +97,37 @@ void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& na switch ( val->type ) { - case TYPE_BOOL: + case zeek::TYPE_BOOL: writer.Bool(val->val.int_val != 0); break; - case TYPE_INT: + case zeek::TYPE_INT: writer.Int64(val->val.int_val); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: writer.Uint64(val->val.uint_val); break; - case TYPE_PORT: + case zeek::TYPE_PORT: writer.Uint64(val->val.port_val.port); break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: writer.String(Formatter::Render(val->val.subnet_val)); break; - case TYPE_ADDR: + case zeek::TYPE_ADDR: writer.String(Formatter::Render(val->val.addr_val)); break; - case TYPE_DOUBLE: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_INTERVAL: writer.Double(val->val.double_val); break; - case TYPE_TIME: + case zeek::TYPE_TIME: { if ( timestamps == TS_ISO8601 ) { @@ -169,16 +169,16 @@ void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& na break; } - case TYPE_ENUM: - case TYPE_STRING: - case TYPE_FILE: - case TYPE_FUNC: + case zeek::TYPE_ENUM: + case zeek::TYPE_STRING: + case zeek::TYPE_FILE: + case zeek::TYPE_FUNC: { writer.String(json_escape_utf8(std::string(val->val.string_val.data, val->val.string_val.length))); break; } - case TYPE_TABLE: + case zeek::TYPE_TABLE: { writer.StartArray(); @@ -189,7 +189,7 @@ void JSON::BuildJSON(NullDoubleWriter& writer, Value* val, const std::string& na break; } - case TYPE_VECTOR: + case zeek::TYPE_VECTOR: { writer.StartArray(); diff --git a/src/threading/formatters/JSON.h b/src/threading/formatters/JSON.h index f336ca659b..66ab88c39e 100644 --- a/src/threading/formatters/JSON.h +++ b/src/threading/formatters/JSON.h @@ -28,7 +28,7 @@ public: bool Describe(ODesc* desc, threading::Value* val, const std::string& name = "") const override; bool Describe(ODesc* desc, int num_fields, const threading::Field* const * fields, threading::Value** vals) const override; - threading::Value* ParseValue(const std::string& s, const std::string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const override; + threading::Value* ParseValue(const std::string& s, const std::string& name, zeek::TypeTag type, zeek::TypeTag subtype = zeek::TYPE_ERROR) const override; class NullDoubleWriter : public rapidjson::Writer { public: diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index fa61815997..c7972ec126 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -114,16 +114,16 @@ vector params; set requested_plugins; const char* proc_status_file = nullptr; -IntrusivePtr md5_type; -IntrusivePtr sha1_type; -IntrusivePtr sha256_type; -IntrusivePtr entropy_type; -IntrusivePtr cardinality_type; -IntrusivePtr topk_type; -IntrusivePtr bloomfilter_type; -IntrusivePtr x509_opaque_type; -IntrusivePtr ocsp_resp_opaque_type; -IntrusivePtr paraglob_type; +IntrusivePtr md5_type; +IntrusivePtr sha1_type; +IntrusivePtr sha256_type; +IntrusivePtr entropy_type; +IntrusivePtr cardinality_type; +IntrusivePtr topk_type; +IntrusivePtr bloomfilter_type; +IntrusivePtr x509_opaque_type; +IntrusivePtr ocsp_resp_opaque_type; +IntrusivePtr paraglob_type; // Keep copy of command line int bro_argc; @@ -593,16 +593,16 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, init_event_handlers(); - md5_type = make_intrusive("md5"); - sha1_type = make_intrusive("sha1"); - sha256_type = make_intrusive("sha256"); - entropy_type = make_intrusive("entropy"); - cardinality_type = make_intrusive("cardinality"); - topk_type = make_intrusive("topk"); - bloomfilter_type = make_intrusive("bloomfilter"); - x509_opaque_type = make_intrusive("x509"); - ocsp_resp_opaque_type = make_intrusive("ocsp_resp"); - paraglob_type = make_intrusive("paraglob"); + md5_type = make_intrusive("md5"); + sha1_type = make_intrusive("sha1"); + sha256_type = make_intrusive("sha256"); + entropy_type = make_intrusive("entropy"); + cardinality_type = make_intrusive("cardinality"); + topk_type = make_intrusive("topk"); + bloomfilter_type = make_intrusive("bloomfilter"); + x509_opaque_type = make_intrusive("x509"); + ocsp_resp_opaque_type = make_intrusive("ocsp_resp"); + paraglob_type = make_intrusive("paraglob"); // The leak-checker tends to produce some false // positives (memory which had already been diff --git a/src/zeek.bif b/src/zeek.bif index 5e67bc3638..006df997e2 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -31,7 +31,7 @@ using namespace std; -TableType* var_sizes; +zeek::TableType* var_sizes; static iosource::PktDumper* addl_pkt_dumper = 0; @@ -47,19 +47,19 @@ bro_int_t parse_int(const char*& fmt) return k; } -static TypeTag ok_d_fmt[] = { - TYPE_BOOL, TYPE_ENUM, TYPE_INT, TYPE_COUNT, TYPE_COUNTER, TYPE_PORT, - TYPE_SUBNET, - TYPE_ERROR +static zeek::TypeTag ok_d_fmt[] = { + zeek::TYPE_BOOL, zeek::TYPE_ENUM, zeek::TYPE_INT, zeek::TYPE_COUNT, zeek::TYPE_COUNTER, zeek::TYPE_PORT, + zeek::TYPE_SUBNET, + zeek::TYPE_ERROR }; -static TypeTag ok_f_fmt[] = { - TYPE_DOUBLE, TYPE_TIME, TYPE_INTERVAL, - TYPE_ERROR +static zeek::TypeTag ok_f_fmt[] = { + zeek::TYPE_DOUBLE, zeek::TYPE_TIME, zeek::TYPE_INTERVAL, + zeek::TYPE_ERROR }; -static int check_fmt_type(TypeTag t, TypeTag ok[]) +static int check_fmt_type(zeek::TypeTag t, zeek::TypeTag ok[]) { - for ( int i = 0; ok[i] != TYPE_ERROR; ++i ) + for ( int i = 0; ok[i] != zeek::TYPE_ERROR; ++i ) if ( ok[i] == t ) return 1; @@ -68,8 +68,8 @@ static int check_fmt_type(TypeTag t, TypeTag ok[]) static void do_fmt(const char*& fmt, Val* v, ODesc* d) { - TypeTag t = v->GetType()->Tag(); - InternalTypeTag it = v->GetType()->InternalType(); + zeek::TypeTag t = v->GetType()->Tag(); + zeek::InternalTypeTag it = v->GetType()->InternalType(); bool zero_pad = false; bool left_just = false; @@ -136,7 +136,7 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d) case 'D': case 'T': // ISO Timestamp with microsecond precision. { - if ( t != TYPE_TIME ) + if ( t != zeek::TYPE_TIME ) { builtin_error("bad type for Date/Time format", v); break; @@ -178,7 +178,7 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d) case 'd': case 'x': { - if ( *fmt == 'x' && it == TYPE_INTERNAL_ADDR ) + if ( *fmt == 'x' && it == zeek::TYPE_INTERNAL_ADDR ) { // Deficiency: we don't support num_fmt in this case. // This makes only a very slight difference, so not @@ -194,13 +194,13 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d) break; } - else if ( it == TYPE_INTERNAL_UNSIGNED ) + else if ( it == zeek::TYPE_INTERNAL_UNSIGNED ) { bro_uint_t u = v->CoerceToUnsigned(); if ( v->GetType()->IsNetworkOrder() ) { - if ( v->GetType()->Tag() == TYPE_PORT ) + if ( v->GetType()->Tag() == zeek::TYPE_PORT ) u = v->AsPortVal()->Port(); else u = ntohl(uint32_t(u)); @@ -408,8 +408,8 @@ static bool prepare_environment(TableVal* tbl, bool set) const auto& key = idxs->Idx(i); const auto& val = tbl->Find(key); - if ( key->GetType()->Tag() != TYPE_STRING || - val->GetType()->Tag() != TYPE_STRING ) + if ( key->GetType()->Tag() != zeek::TYPE_STRING || + val->GetType()->Tag() != zeek::TYPE_STRING ) { builtin_error("system_env() needs a table[string] of string"); return false; @@ -487,7 +487,7 @@ function system%(str: string%): int ## .. zeek:see:: system safe_shell_quote piped_exec function system_env%(str: string, env: table_string_of_string%): int %{ - if ( env->GetType()->Tag() != TYPE_TABLE ) + if ( env->GetType()->Tag() != zeek::TYPE_TABLE ) { builtin_error("system_env() requires a table argument"); return val_mgr->Int(-1); @@ -803,8 +803,8 @@ function sha256_hash_finish%(handle: opaque of sha256%): string ## .. zeek:see::paraglob_match paraglob_equals paraglob_add function paraglob_init%(v: any%) : opaque of paraglob %{ - if ( v->GetType()->Tag() != TYPE_VECTOR || - v->GetType()->Yield()->Tag() != TYPE_STRING ) + if ( v->GetType()->Tag() != zeek::TYPE_VECTOR || + v->GetType()->Yield()->Tag() != zeek::TYPE_STRING ) { // reporter->Error will throw an exception. reporter->Error("paraglob requires a vector of strings for initialization."); @@ -1051,7 +1051,7 @@ function find_entropy%(data: string%): entropy_test_result e.Feed(data->Bytes(), data->Len()); e.Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent)); ent_result->Assign(1, make_intrusive(chisq)); @@ -1103,7 +1103,7 @@ function entropy_test_finish%(handle: opaque of entropy%): entropy_test_result montepi = scc = ent = mean = chisq = 0.0; static_cast(handle)->Get(&ent, &chisq, &mean, &montepi, &scc); - static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); + static auto entropy_test_result = zeek::id::find_type("entropy_test_result"); auto ent_result = make_intrusive(entropy_test_result); ent_result->Assign(0, make_intrusive(ent)); ent_result->Assign(1, make_intrusive(chisq)); @@ -1156,7 +1156,7 @@ function unique_id_from%(pool: int, prefix: string%) : string ## v: The set or table function clear_table%(v: any%): any %{ - if ( v->GetType()->Tag() == TYPE_TABLE ) + if ( v->GetType()->Tag() == zeek::TYPE_TABLE ) v->AsTableVal()->RemoveAll(); else builtin_error("clear_table() requires a table/set argument"); @@ -1173,7 +1173,7 @@ function clear_table%(v: any%): any ## Returns: All the keys of the set or table that cover the subnet searched for. function matching_subnets%(search: subnet, t: any%): subnet_vec %{ - if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != zeek::TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("matching_subnets needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1192,7 +1192,7 @@ function matching_subnets%(search: subnet, t: any%): subnet_vec ## Returns: A new table that contains all the entries that cover the subnet searched for. function filter_subnet_table%(search: subnet, t: any%): any %{ - if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != zeek::TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("filter_subnet_table needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1212,7 +1212,7 @@ function filter_subnet_table%(search: subnet, t: any%): any ## Returns: True if the exact subnet is a member, false otherwise. function check_subnet%(search: subnet, t: any%): bool %{ - if ( t->GetType()->Tag() != TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) + if ( t->GetType()->Tag() != zeek::TYPE_TABLE || ! t->GetType()->AsTableType()->IsSubNetIndex() ) { reporter->Error("check_subnet needs to be called on a set[subnet]/table[subnet]."); return nullptr; @@ -1263,7 +1263,7 @@ function val_size%(v: any%): count ## Returns: The old size of *aggr*, or 0 if *aggr* is not a :zeek:type:`vector`. function resize%(aggr: any, newsize: count%) : count %{ - if ( aggr->GetType()->Tag() != TYPE_VECTOR ) + if ( aggr->GetType()->Tag() != zeek::TYPE_VECTOR ) { builtin_error("resize() operates on vectors"); return nullptr; @@ -1282,8 +1282,8 @@ function resize%(aggr: any, newsize: count%) : count ## .. zeek:see:: all_set function any_set%(v: any%) : bool %{ - if ( v->GetType()->Tag() != TYPE_VECTOR || - v->GetType()->Yield()->Tag() != TYPE_BOOL ) + if ( v->GetType()->Tag() != zeek::TYPE_VECTOR || + v->GetType()->Yield()->Tag() != zeek::TYPE_BOOL ) { builtin_error("any_set() requires vector of bool"); return val_mgr->False(); @@ -1311,8 +1311,8 @@ function any_set%(v: any%) : bool ## Missing elements count as false. function all_set%(v: any%) : bool %{ - if ( v->GetType()->Tag() != TYPE_VECTOR || - v->GetType()->Yield()->Tag() != TYPE_BOOL ) + if ( v->GetType()->Tag() != zeek::TYPE_VECTOR || + v->GetType()->Yield()->Tag() != zeek::TYPE_BOOL ) { builtin_error("all_set() requires vector of bool"); return val_mgr->False(); @@ -1403,7 +1403,7 @@ function sort%(v: any, ...%) : any %{ IntrusivePtr rval{NewRef{}, v}; - if ( v->GetType()->Tag() != TYPE_VECTOR ) + if ( v->GetType()->Tag() != zeek::TYPE_VECTOR ) { builtin_error("sort() requires vector"); return rval; @@ -1436,7 +1436,7 @@ function sort%(v: any, ...%) : any { const auto& comp_type = comp->GetType(); - if ( comp_type->Yield()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != zeek::TYPE_INT || ! comp_type->ParamList()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to sort()"); @@ -1449,7 +1449,7 @@ function sort%(v: any, ...%) : any } else { - if ( elt_type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + if ( elt_type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) sort(vv.begin(), vv.end(), unsigned_sort_function); else sort(vv.begin(), vv.end(), signed_sort_function); @@ -1473,7 +1473,7 @@ function order%(v: any, ...%) : index_vec %{ auto result_v = make_intrusive(zeek::id::index_vec); - if ( v->GetType()->Tag() != TYPE_VECTOR ) + if ( v->GetType()->Tag() != zeek::TYPE_VECTOR ) { builtin_error("order() requires vector"); return result_v; @@ -1517,7 +1517,7 @@ function order%(v: any, ...%) : index_vec if ( comp ) { const auto& comp_type = comp->GetType(); - if ( comp_type->Yield()->Tag() != TYPE_INT || + if ( comp_type->Yield()->Tag() != zeek::TYPE_INT || ! comp_type->ParamList()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to order()"); @@ -1530,7 +1530,7 @@ function order%(v: any, ...%) : index_vec } else { - if ( elt_type->InternalType() == TYPE_INTERNAL_UNSIGNED ) + if ( elt_type->InternalType() == zeek::TYPE_INTERNAL_UNSIGNED ) sort(ind_vv.begin(), ind_vv.end(), indirect_unsigned_sort_function); else sort(ind_vv.begin(), ind_vv.end(), indirect_signed_sort_function); @@ -1603,7 +1603,7 @@ function cat_sep%(sep: string, def: string, ...%): string d.Add(sep->CheckString(), 0); Val* v = @ARG@[i].get(); - if ( v->GetType()->Tag() == TYPE_STRING && ! v->AsString()->Len() ) + if ( v->GetType()->Tag() == zeek::TYPE_STRING && ! v->AsString()->Len() ) v = def; v->Describe(&d); @@ -1825,7 +1825,7 @@ function record_type_to_vector%(rt: string%): string_vec %{ auto result = make_intrusive(zeek::id::string_vec); - RecordType* type = zeek::id::find_type(rt->CheckString())->AsRecordType(); + zeek::RecordType* type = zeek::id::find_type(rt->CheckString())->AsRecordType(); for ( int i = 0; i < type->NumFields(); ++i ) result->Assign(i+1, make_intrusive(type->FieldName(i))); @@ -1890,7 +1890,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - static auto ps_type = zeek::id::find_type("PacketSource"); + static auto ps_type = zeek::id::find_type("PacketSource"); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -1940,14 +1940,14 @@ function global_sizes%(%): var_sizes ## .. zeek:see:: global_sizes function global_ids%(%): id_table %{ - static auto id_table = zeek::id::find_type("id_table"); + static auto id_table = zeek::id::find_type("id_table"); auto ids = make_intrusive(id_table); const auto& globals = global_scope()->Vars(); for ( const auto& global : globals ) { zeek::detail::ID* id = global.second.get(); - static auto script_id = zeek::id::find_type("script_id"); + static auto script_id = zeek::id::find_type("script_id"); auto rec = make_intrusive(script_id); rec->Assign(0, make_intrusive(type_name(id->GetType()->Tag()))); rec->Assign(1, val_mgr->Bool(id->IsExport())); @@ -1993,13 +1993,13 @@ function lookup_ID%(id: string%) : any ## Returns: A table that describes the fields of a record. function record_fields%(rec: any%): record_field_table %{ - static auto record_field_table = zeek::id::find_type("record_field_table"); + static auto record_field_table = zeek::id::find_type("record_field_table"); - if ( rec->GetType()->Tag() == TYPE_STRING ) + if ( rec->GetType()->Tag() == zeek::TYPE_STRING ) { const auto& id = global_scope()->Find(rec->AsStringVal()->ToStdString()); - if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) + if ( ! id || ! id->IsType() || id->GetType()->Tag() != zeek::TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); return make_intrusive(record_field_table); @@ -2188,7 +2188,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(zeek::id::find_type("addr_vec")); + auto rval = make_intrusive(zeek::id::find_type("addr_vec")); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2266,7 +2266,7 @@ function counts_to_addr%(v: index_vec%): addr ## Returns: The :zeek:type:`int` value that corresponds to the :zeek:type:`enum`. function enum_to_int%(e: any%): int %{ - if ( e->GetType()->Tag() != TYPE_ENUM ) + if ( e->GetType()->Tag() != zeek::TYPE_ENUM ) { builtin_error("enum_to_int() requires enum value"); return val_mgr->Int(-1); @@ -3384,7 +3384,7 @@ function dump_current_packet%(file_name: string%) : bool ## .. zeek:see:: dump_current_packet dump_packet function get_current_packet%(%) : pcap_packet %{ - static auto pcap_packet = zeek::id::find_type("pcap_packet"); + static auto pcap_packet = zeek::id::find_type("pcap_packet"); const Packet* p; auto pkt = make_intrusive(pcap_packet); @@ -3426,7 +3426,7 @@ function get_current_packet_header%(%) : raw_pkt_hdr return p->ToRawPktHdrVal(); } - static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); + static auto raw_pkt_hdr_type = zeek::id::find_type("raw_pkt_hdr"); auto hdr = make_intrusive(raw_pkt_hdr_type); return hdr; %} @@ -3520,7 +3520,7 @@ public: else { - ListVal* lv = new ListVal(TYPE_ADDR); + ListVal* lv = new ListVal(zeek::TYPE_ADDR); lv->Append(make_intrusive("0.0.0.0")); auto result = lv->ToSetVal(); trigger->Cache(call, result.get()); @@ -3997,7 +3997,7 @@ function mmdb_open_asn_db%(f: string%) : bool ## .. zeek:see:: lookup_asn function lookup_location%(a: addr%) : geo_location %{ - static auto geo_location = zeek::id::find_type("geo_location"); + static auto geo_location = zeek::id::find_type("geo_location"); auto location = make_intrusive(geo_location); #ifdef USE_GEOIP @@ -4629,7 +4629,7 @@ function rotate_file%(f: file%): rotate_info return info; // Record indicating error. - static auto rotate_info = zeek::id::find_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); info = make_intrusive(rotate_info); info->Assign(0, val_mgr->EmptyString()); info->Assign(1, val_mgr->EmptyString()); @@ -4649,7 +4649,7 @@ function rotate_file%(f: file%): rotate_info ## .. zeek:see:: rotate_file calc_next_rotate function rotate_file_by_name%(f: string%): rotate_info %{ - static auto rotate_info = zeek::id::find_type("rotate_info"); + static auto rotate_info = zeek::id::find_type("rotate_info"); auto info = make_intrusive(rotate_info); bool is_pkt_dumper = false; diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index ba8edbdd9f..0175a42380 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -38,12 +38,12 @@ void IdentifierInfo::AddRedef(const string& script, zeek::detail::init_class ic, redefs.push_back(redef); } -void IdentifierInfo::AddRecordField(const TypeDecl* field, +void IdentifierInfo::AddRecordField(const zeek::TypeDecl* field, const string& script, vector& comments) { RecordField* rf = new RecordField(); - rf->field = new TypeDecl(*field); + rf->field = new zeek::TypeDecl(*field); rf->from_script = script; rf->comments = comments; @@ -116,7 +116,7 @@ string IdentifierInfo::DoReStructuredText(bool roles_only) const if ( i > 0 ) d.NL(); - if ( IsFunc(id->GetType()->Tag()) ) + if ( zeek::IsFunc(id->GetType()->Tag()) ) { string s = comments[i]; diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index 5bb284d23d..6a8166179c 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -2,18 +2,18 @@ #pragma once -#include "Info.h" -#include "IntrusivePtr.h" -#include "ID.h" - +#include // for time_t #include #include #include #include -#include // for time_t +#include "Info.h" +#include "IntrusivePtr.h" +#include "ID.h" +#include "util.h" -class TypeDecl; +FORWARD_DECLARE_NAMESPACED(TypeDecl, zeek); namespace zeekygen { @@ -82,7 +82,7 @@ public: * differ from the script in which a record type is declared due to redefs. * @param comments Comments associated with the record field. */ - void AddRecordField(const TypeDecl* field, const std::string& script, + void AddRecordField(const zeek::TypeDecl* field, const std::string& script, std::vector& comments); /** @@ -165,7 +165,7 @@ private: struct RecordField { ~RecordField(); - TypeDecl* field; + zeek::TypeDecl* field; std::string from_script; std::vector comments; }; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index eab18fa6e1..071940eb25 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -275,7 +275,7 @@ void Manager::StartType(IntrusivePtr id) static bool IsEnumType(zeek::detail::ID* id) { - return id->IsType() ? id->GetType()->Tag() == TYPE_ENUM : false; + return id->IsType() ? id->GetType()->Tag() == zeek::TYPE_ENUM : false; } void Manager::Identifier(IntrusivePtr id) @@ -301,7 +301,7 @@ void Manager::Identifier(IntrusivePtr id) if ( id_info ) { - if ( IsFunc(id_info->GetID()->GetType()->Tag()) ) + if ( zeek::IsFunc(id_info->GetID()->GetType()->Tag()) ) { // Function may already been seen (declaration versus body). id_info->AddComments(comment_buffer); @@ -337,7 +337,7 @@ void Manager::Identifier(IntrusivePtr id) CreateIdentifierInfo(std::move(id), script_info); } -void Manager::RecordField(const zeek::detail::ID* id, const TypeDecl* field, +void Manager::RecordField(const zeek::detail::ID* id, const zeek::TypeDecl* field, const string& path) { if ( disabled ) diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index fcac96204a..b652982f84 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -2,20 +2,21 @@ #pragma once +#include +#include +#include +#include +#include +#include + #include "Configuration.h" #include "Reporter.h" #include "ID.h" - -#include -#include -#include -#include -#include -#include +#include "util.h" template class IntrusivePtr; -class TypeDecl; +FORWARD_DECLARE_NAMESPACED(TypeDecl, zeek); namespace zeekygen { @@ -128,7 +129,7 @@ public: * declared. This can be different from the place where the record type * is declared due to redefs. */ - void RecordField(const zeek::detail::ID* id, const TypeDecl* field, + void RecordField(const zeek::detail::ID* id, const zeek::TypeDecl* field, const std::string& path); /** diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index 9104d42e2d..0bbd64ad66 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -192,20 +192,20 @@ void ScriptInfo::DoInitPostScript() continue; } - if ( IsFunc(id->GetType()->Tag()) ) + if ( zeek::IsFunc(id->GetType()->Tag()) ) { switch ( id->GetType()->AsFuncType()->Flavor() ) { - case FUNC_FLAVOR_HOOK: + case zeek::FUNC_FLAVOR_HOOK: DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a hook", id->Name(), name.c_str()); hooks.push_back(info); break; - case FUNC_FLAVOR_EVENT: + case zeek::FUNC_FLAVOR_EVENT: DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a event", id->Name(), name.c_str()); events.push_back(info); break; - case FUNC_FLAVOR_FUNCTION: + case zeek::FUNC_FLAVOR_FUNCTION: DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a function", id->Name(), name.c_str()); functions.push_back(info); @@ -244,7 +244,7 @@ void ScriptInfo::DoInitPostScript() continue; } - if ( id->GetType()->Tag() == TYPE_ENUM ) + if ( id->GetType()->Tag() == zeek::TYPE_ENUM ) // Enums are always referenced/documented from the type's // documentation. continue; diff --git a/testing/btest/plugins/reader-plugin/src/Foo.cc b/testing/btest/plugins/reader-plugin/src/Foo.cc index c008babff9..4a05420bc3 100644 --- a/testing/btest/plugins/reader-plugin/src/Foo.cc +++ b/testing/btest/plugins/reader-plugin/src/Foo.cc @@ -71,17 +71,17 @@ bool Foo::DoUpdate() return true; } -threading::Value* Foo::EntryToVal(TypeTag type, TypeTag subtype) +threading::Value* Foo::EntryToVal(zeek::TypeTag type, zeek::TypeTag subtype) { Value* val = new Value(type, true); // basically construct something random from the fields that we want. switch ( type ) { - case TYPE_ENUM: + case zeek::TYPE_ENUM: assert(false); // no enums, please. - case TYPE_STRING: + case zeek::TYPE_STRING: { std::string rnd = RandomString(10); val->val.string_val.data = copy_string(rnd.c_str()); @@ -89,46 +89,46 @@ threading::Value* Foo::EntryToVal(TypeTag type, TypeTag subtype) break; } - case TYPE_BOOL: + case zeek::TYPE_BOOL: val->val.int_val = 1; // we never lie. break; - case TYPE_INT: + case zeek::TYPE_INT: val->val.int_val = random(); break; - case TYPE_TIME: + case zeek::TYPE_TIME: val->val.double_val = 0; break; - case TYPE_DOUBLE: - case TYPE_INTERVAL: + case zeek::TYPE_DOUBLE: + case zeek::TYPE_INTERVAL: val->val.double_val = random(); break; - case TYPE_COUNT: - case TYPE_COUNTER: + case zeek::TYPE_COUNT: + case zeek::TYPE_COUNTER: val->val.uint_val = random(); break; - case TYPE_PORT: + case zeek::TYPE_PORT: val->val.port_val.port = random() / (RAND_MAX / 60000); val->val.port_val.proto = TRANSPORT_UNKNOWN; break; - case TYPE_SUBNET: + case zeek::TYPE_SUBNET: { val->val.subnet_val.prefix = ascii->ParseAddr("192.168.17.1"); val->val.subnet_val.length = 16; } break; - case TYPE_ADDR: + case zeek::TYPE_ADDR: val->val.addr_val = ascii->ParseAddr("192.168.17.1"); break; - case TYPE_TABLE: - case TYPE_VECTOR: + case zeek::TYPE_TABLE: + case zeek::TYPE_VECTOR: // First - common initialization // Then - initialization for table. // Then - initialization for vector. @@ -139,12 +139,12 @@ threading::Value* Foo::EntryToVal(TypeTag type, TypeTag subtype) Value** lvals = new Value* [length]; - if ( type == TYPE_TABLE ) + if ( type == zeek::TYPE_TABLE ) { val->val.set_val.vals = lvals; val->val.set_val.size = length; } - else if ( type == TYPE_VECTOR ) + else if ( type == zeek::TYPE_VECTOR ) { val->val.vector_val.vals = lvals; val->val.vector_val.size = length; @@ -157,7 +157,7 @@ threading::Value* Foo::EntryToVal(TypeTag type, TypeTag subtype) for ( unsigned int pos = 0; pos < length; pos++ ) { - Value* newval = EntryToVal(subtype, TYPE_ENUM); + Value* newval = EntryToVal(subtype, zeek::TYPE_ENUM); if ( newval == 0 ) { Error("Error while reading set"); diff --git a/testing/btest/plugins/reader-plugin/src/Foo.h b/testing/btest/plugins/reader-plugin/src/Foo.h index 38bddcda94..5a88ff757b 100644 --- a/testing/btest/plugins/reader-plugin/src/Foo.h +++ b/testing/btest/plugins/reader-plugin/src/Foo.h @@ -24,7 +24,7 @@ protected: private: std::string RandomString(const int len); - threading::Value* EntryToVal(TypeTag Type, TypeTag subtype); + threading::Value* EntryToVal(zeek::TypeTag Type, zeek::TypeTag subtype); threading::formatter::Ascii* ascii; };