diff --git a/CHANGES b/CHANGES index cdff7874ce..47041d4269 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,32 @@ +3.2.0-dev.779 | 2020-06-11 23:17:46 -0700 + + * Rename BroType to zeek::Type (Tim Wojtulewicz, Corelight) + + * Move Type types to zeek namespace (Tim Wojtulewicz, Corelight) + + * Move Flare/Pipe from the bro namespace to zeek::detail (Tim Wojtulewicz, Corelight) + + * Move Attr to the zeek::detail namespace (Tim Wojtulewicz, Corelight) + + * Move Trigger into the zeek::detail namespace (Tim Wojtulewicz, Corelight) + + * Move ID to the zeek::detail namespace (Tim Wojtulewicz, Corelight) + + * Move Anon.h into zeek::detail namespace (Tim Wojtulewicz, Corelight) + + * Mark all of the aliased classes in plugin/Plugin.h deprecated (Tim Wojtulewicz, Corelight) + + And fix all of the plugins that were using them + + * Move all of the base plugin classes into the zeek::plugin namespace (Tim Wojtulewicz, Corelight) + + * Expr: move all classes into zeek::detail (Tim Wojtulewicz, Corelight) + + * Stmt: move Stmt classes into zeek::detail namespace (Tim Wojtulewicz, Corelight) + + * Add utility macro for creating namespaced aliases for classes (Tim Wojtulewicz, Corelight) + 3.2.0-dev.763 | 2020-06-10 16:34:31 -0700 * Optimize Connection::RemovalEvent() for bare-mode usage (Jon Siwek, Corelight) diff --git a/NEWS b/NEWS index 848e695fce..87c423b4c2 100644 --- a/NEWS +++ b/NEWS @@ -83,7 +83,7 @@ Changed Functionality - "using namespace std" was removed from the Zeek header files; Zeek now always explicitly specifies std when using STL functionality in headers. This may - necessitate small changes in external plugins, if they relied on the using + necessitate small changes in external plugins, if they relied on the using statement in Zeek headers. - The ``connection_external`` event was removed. This functionality that could @@ -107,6 +107,14 @@ Changed Functionality - ``Attributes::Attrs()`` now returns ``const std::vector>&`` instead of ``attr_list*`` +- Moved a large number of classes from the global namespace into either the + ``zeek`` or ``zeek::detail`` namespace. See https://github.com/zeek/zeek/issues/266 + for the rationale behind these changes. Most types that were moved and functions + that used them have been marked as deprecated and will generate compiler + warnings if used (a few exceptions will not generate compiler warnings, + but the Deprecated Functionality section below will mention those + ones specifically). + Removed Functionality --------------------- @@ -124,6 +132,12 @@ Deprecated Functionality method to now use is called ``HookFunctionCall`` and uses ``IntrusivePtr`` arguments and return value. +- The ``plugin::Plugin::MetaHookPre()`` and ``MetaHookPost()`` methods are + deprecated. Note that compilers will not emit a deprecation warning, but + the replacement methods are named the same except use + ``zeek::plugin::HookType`` arguments (the type is now from the "zeek" + namespace). + - The ``Func::Call(val_list*, ...)`` method is now deprecated. Use ``Invoke()`` instead which takes a ``zeek::Args`` (``std::vector>``). There's also a variadic template for ``Invoke()`` that forwards all arguments diff --git a/VERSION b/VERSION index d30372865c..8563353333 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.2.0-dev.763 +3.2.0-dev.779 diff --git a/auxil/bifcl b/auxil/bifcl index 7d474ff6ac..9c10bb74bb 160000 --- a/auxil/bifcl +++ b/auxil/bifcl @@ -1 +1 @@ -Subproject commit 7d474ff6ac0ff1870eef6159bef93a1bfed953df +Subproject commit 9c10bb74bb62aa7fb10efc079f1b2e5926e9798c diff --git a/src/Anon.cc b/src/Anon.cc index ee1d296732..bb878061ae 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -14,7 +14,9 @@ #include "ID.h" #include "IPAddr.h" -AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr}; +using namespace zeek::detail; + +AnonymizeIPAddr* zeek::detail::ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr}; static uint32_t rand32() { @@ -22,7 +24,7 @@ static uint32_t rand32() } // From tcpdpriv. -int bi_ffs(uint32_t value) +static int bi_ffs(uint32_t value) { int add = 0; static uint8_t bvals[] = { @@ -360,7 +362,7 @@ static IntrusivePtr anon_preserve_orig_addr; static IntrusivePtr anon_preserve_resp_addr; static IntrusivePtr anon_preserve_other_addr; -void init_ip_addr_anonymizers() +void zeek::detail::init_ip_addr_anonymizers() { ip_anonymizer[KEEP_ORIG_ADDR] = nullptr; ip_anonymizer[SEQUENTIALLY_NUMBERED] = new AnonymizeIPAddr_Seq(); @@ -384,7 +386,7 @@ void init_ip_addr_anonymizers() anon_preserve_other_addr = cast_intrusive(id->GetVal()); } -ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) +ipaddr32_t zeek::detail::anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) { TableVal* preserve_addr = nullptr; auto addr = make_intrusive(ip); @@ -439,7 +441,7 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) #include "NetVar.h" #include "Event.h" -void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output) +void zeek::detail::log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output) { if ( anonymization_mapping ) mgr.Enqueue(anonymization_mapping, diff --git a/src/Anon.h b/src/Anon.h index ecda53f023..c9b1db8553 100644 --- a/src/Anon.h +++ b/src/Anon.h @@ -14,6 +14,8 @@ #include #include +namespace zeek::detail { + // TODO: Anon.h may not be the right place to put these functions ... enum ip_addr_anonymization_class_t { @@ -126,3 +128,5 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl); #define LOG_ANONYMIZATION_MAPPING void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output); + +} diff --git a/src/Attr.cc b/src/Attr.cc index c57f288313..859ddaa720 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -9,6 +9,8 @@ #include "IntrusivePtr.h" #include "threading/SerialTypes.h" +namespace zeek::detail { + const char* attr_name(attr_tag t) { static const char* attr_names[int(NUM_ATTRS)] = { @@ -35,9 +37,20 @@ Attr::Attr(attr_tag t) { } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +Attr::Attr(::attr_tag t, IntrusivePtr e) : Attr(static_cast(t), e) + { + } + +Attr::Attr(::attr_tag t) : Attr(static_cast(t)) + { + } +#pragma GCC diagnostic pop + Attr::~Attr() = default; -void Attr::SetAttrExpr(IntrusivePtr e) +void Attr::SetAttrExpr(IntrusivePtr e) { expr = std::move(e); } void Attr::Describe(ODesc* d) const @@ -136,7 +149,7 @@ void Attr::AddTag(ODesc* d) const d->Add(attr_name(Tag())); } -Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record, bool is_global) +Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record, bool is_global) { attrs.reserve(a->length()); in_record = arg_in_record; @@ -154,14 +167,14 @@ Attributes::Attributes(attr_list* a, IntrusivePtr t, bool arg_in_record delete a; } -Attributes::Attributes(IntrusivePtr t, +Attributes::Attributes(IntrusivePtr t, bool arg_in_record, bool is_global) : Attributes(std::vector>{}, std::move(t), arg_in_record, is_global) {} Attributes::Attributes(std::vector> a, - IntrusivePtr t, + IntrusivePtr t, bool arg_in_record, bool is_global) : type(std::move(t)) { @@ -244,6 +257,19 @@ void Attributes::RemoveAttr(attr_tag t) } } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +Attr* Attributes::FindAttr(::attr_tag t) const + { + return FindAttr(static_cast(t)); + } + +void Attributes::RemoveAttr(::attr_tag t) + { + RemoveAttr(static_cast(t)); + } +#pragma GCC diagnostic pop + void Attributes::Describe(ODesc* d) const { if ( attrs.empty() ) @@ -663,3 +689,5 @@ bool Attributes::operator==(const Attributes& other) const return true; } + +} diff --git a/src/Attr.h b/src/Attr.h index fbf60f68a4..39c333447a 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -8,13 +8,13 @@ #include "BroList.h" #include "IntrusivePtr.h" -class Expr; +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); // Note that there are two kinds of attributes: the kind (here) which // modify expressions or supply metadata on types, and the kind that // are extra metadata on every variable instance. -typedef enum { +enum [[deprecated("Remove in v4.1. Use zeek::detail::attr_tag instead.")]] attr_tag { ATTR_OPTIONAL, ATTR_DEFAULT, ATTR_REDEF, @@ -33,26 +33,60 @@ typedef enum { ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry ATTR_ON_CHANGE, // for table change tracking ATTR_DEPRECATED, -#define NUM_ATTRS (int(ATTR_DEPRECATED) + 1) -} attr_tag; + NUM_ATTRS // this item should always be last +}; + +namespace zeek::detail { + +enum attr_tag { + ATTR_OPTIONAL, + ATTR_DEFAULT, + ATTR_REDEF, + ATTR_ADD_FUNC, + ATTR_DEL_FUNC, + ATTR_EXPIRE_FUNC, + ATTR_EXPIRE_READ, + ATTR_EXPIRE_WRITE, + ATTR_EXPIRE_CREATE, + ATTR_RAW_OUTPUT, + ATTR_PRIORITY, + ATTR_GROUP, + ATTR_LOG, + ATTR_ERROR_HANDLER, + ATTR_TYPE_COLUMN, // for input framework + ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry + ATTR_ON_CHANGE, // for table change tracking + ATTR_DEPRECATED, + NUM_ATTRS // this item should always be last +}; class Attr final : public BroObj { public: - static inline const IntrusivePtr nil; + static inline const IntrusivePtr nil; - Attr(attr_tag t, IntrusivePtr e); + Attr(attr_tag t, IntrusivePtr e); explicit Attr(attr_tag t); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + Attr(::attr_tag t, IntrusivePtr e); + + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + explicit Attr(::attr_tag t); +#pragma GCC diagnostic pop + ~Attr() override; attr_tag Tag() const { return tag; } [[deprecated("Remove in v4.1. Use GetExpr().")]] - Expr* AttrExpr() const { return expr.get(); } + zeek::detail::Expr* AttrExpr() const { return expr.get(); } - const IntrusivePtr& GetExpr() const + const IntrusivePtr& GetExpr() const { return expr; } - void SetAttrExpr(IntrusivePtr e); + void SetAttrExpr(IntrusivePtr e); void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool shorten = false) const; @@ -82,11 +116,11 @@ protected: class Attributes final : public BroObj { public: [[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]] - Attributes(attr_list* a, IntrusivePtr t, bool in_record, bool is_global); + Attributes(attr_list* a, IntrusivePtr t, bool in_record, bool is_global); - Attributes(std::vector> a, IntrusivePtr t, + Attributes(std::vector> a, IntrusivePtr t, bool in_record, bool is_global); - Attributes(IntrusivePtr t, bool in_record, bool is_global); + Attributes(IntrusivePtr t, bool in_record, bool is_global); void AddAttr(IntrusivePtr a); @@ -102,6 +136,14 @@ public: void RemoveAttr(attr_tag t); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + Attr* FindAttr(::attr_tag t) const; + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + void RemoveAttr(::attr_tag t); +#pragma GCC diagnostic pop + void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool shorten = false) const; @@ -113,8 +155,13 @@ public: protected: void CheckAttr(Attr* attr); - IntrusivePtr type; + IntrusivePtr type; std::vector> attrs; bool in_record; bool global_var; }; + +} + +using Attr [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attr; +using Attributes [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attributes; diff --git a/src/BroList.h b/src/BroList.h index a37f40d84a..a1463603eb 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -4,23 +4,24 @@ #include "List.h" -class Expr; -typedef PList expr_list; - -class ID; -typedef PList id_list; - class Val; -typedef PList val_list; +using val_list = PList; -class Stmt; -typedef PList stmt_list; +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +using expr_list = PList; -class BroType; -typedef PList type_list; +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +using id_list = PList; -class Attr; -typedef PList attr_list; +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +using stmt_list = PList; + +namespace zeek { class Type; } +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; +using type_list = PList; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail); +using attr_list = PList; class Timer; -typedef PList timer_list; +using timer_list = PList; diff --git a/src/Brofiler.cc b/src/Brofiler.cc index ba7ff1b358..4eeb456380 100644 --- a/src/Brofiler.cc +++ b/src/Brofiler.cc @@ -26,7 +26,7 @@ Brofiler::~Brofiler() Unref(s); } -void Brofiler::AddStmt(Stmt* s) +void Brofiler::AddStmt(zeek::detail::Stmt* s) { if ( ignoring != 0 ) return; @@ -127,7 +127,7 @@ bool Brofiler::WriteStats() return false; } - for ( list::const_iterator it = stmts.begin(); + for ( list::const_iterator it = stmts.begin(); it != stmts.end(); ++it ) { ODesc location_info; @@ -154,4 +154,3 @@ bool Brofiler::WriteStats() fclose(f); return true; } - diff --git a/src/Brofiler.h b/src/Brofiler.h index 4d6bb2eaf5..c6fad1ae51 100644 --- a/src/Brofiler.h +++ b/src/Brofiler.h @@ -5,7 +5,8 @@ #include #include -class Stmt; +#include "util.h" +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); /** * A simple class for managing stats of Bro script coverage across Bro runs. @@ -39,13 +40,13 @@ public: void IncIgnoreDepth() { ignoring++; } void DecIgnoreDepth() { ignoring--; } - void AddStmt(Stmt* s); + void AddStmt(zeek::detail::Stmt* s); private: /** * The current, global Brofiler instance creates this list at parse-time. */ - std::list stmts; + std::list stmts; /** * Indicates whether new statments will not be considered as part of diff --git a/src/CompHash.cc b/src/CompHash.cc index 5243e4241e..4e3f56b19e 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -15,17 +15,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; @@ -72,10 +72,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::Type* bt, Val* v, bool optional) const { char* kp1 = nullptr; - InternalTypeTag t = bt->InternalType(); + zeek::InternalTypeTag t = bt->InternalType(); if ( optional ) { @@ -90,13 +90,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(); @@ -104,7 +104,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(); @@ -112,7 +112,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); @@ -120,7 +120,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); @@ -129,7 +129,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(); @@ -137,11 +137,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(); @@ -149,7 +149,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, break; } - case TYPE_PATTERN: + case zeek::TYPE_PATTERN: { const char* texts[2] = { v->AsPattern()->PatternText(), @@ -173,19 +173,19 @@ 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 ) { auto rv_i = rv->GetField(i).get(); - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->Find(ATTR_OPTIONAL)); + zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL)); if ( ! (rv_i || optional) ) return nullptr; @@ -200,7 +200,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(); @@ -209,7 +209,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 @@ -259,11 +259,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 ) @@ -287,7 +287,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(); @@ -310,10 +310,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); @@ -328,7 +328,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0, } break; - case TYPE_INTERNAL_ERROR: + case zeek::TYPE_INTERNAL_ERROR: return nullptr; } @@ -343,9 +343,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 @@ -369,7 +369,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(); @@ -390,7 +390,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(); @@ -404,25 +404,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(), @@ -438,10 +438,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: @@ -450,53 +450,53 @@ std::unique_ptr CompositeHash::ComputeSingletonHash(const Val* v, bool } } -int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, +int CompositeHash::SingleTypeKeySize(zeek::Type* 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; @@ -507,16 +507,16 @@ 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 ) { - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->Find(ATTR_OPTIONAL)); + zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL)); sz = SingleTypeKeySize(rt->GetFieldType(i).get(), rv ? rv->GetField(i).get() : nullptr, @@ -529,7 +529,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; @@ -558,7 +558,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; @@ -580,7 +580,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; @@ -604,10 +604,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; @@ -616,7 +616,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; } @@ -629,7 +629,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(); @@ -711,7 +711,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(); @@ -731,15 +731,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::Type* 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 ) @@ -755,16 +755,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 { @@ -774,18 +774,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; @@ -797,21 +797,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); @@ -819,7 +819,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; @@ -831,7 +831,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); @@ -839,11 +839,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); @@ -859,18 +859,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 ) @@ -897,10 +897,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; @@ -909,8 +909,8 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, { IntrusivePtr v; - Attributes* a = rt->FieldDecl(i)->attrs.get(); - bool optional = (a && a->Find(ATTR_OPTIONAL)); + zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); + bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL)); kp = RecoverOneVal(k, kp, k_end, rt->GetFieldType(i).get(), &v, optional); @@ -940,13 +940,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 ) @@ -969,13 +969,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 ) @@ -999,19 +999,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::Type* it = tl->Types()[i].get(); kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); lv->Append(std::move(v)); } @@ -1028,7 +1028,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. @@ -1051,7 +1051,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..367fd445a0 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::Type* 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::Type* 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::Type*, 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..4e5079c585 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; +ZEEK_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 2ad5d3ef94..472924aba4 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -166,7 +166,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str) return true; } -bool DbgBreakpoint::SetLocation(Stmt* stmt) +bool DbgBreakpoint::SetLocation(zeek::detail::Stmt* stmt) { if ( ! stmt ) return false; @@ -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"); @@ -290,7 +290,7 @@ BreakCode DbgBreakpoint::HasHit() return bcHit; } -BreakCode DbgBreakpoint::ShouldBreak(Stmt* s) +BreakCode DbgBreakpoint::ShouldBreak(zeek::detail::Stmt* s) { if ( ! IsEnabled() ) return bcNoHit; diff --git a/src/DbgBreakpoint.h b/src/DbgBreakpoint.h index 2e8e59a16c..e2f643c51e 100644 --- a/src/DbgBreakpoint.h +++ b/src/DbgBreakpoint.h @@ -3,9 +3,11 @@ #pragma once #include +#include "util.h" struct ParseLocationRec; -class Stmt; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); enum BreakCode { bcNoHit, bcHit, bcHitAndDelete }; class DbgBreakpoint { @@ -20,7 +22,7 @@ public: // True if breakpoint could be set; false otherwise bool SetLocation(ParseLocationRec plr, std::string_view loc_str); - bool SetLocation(Stmt* stmt); + bool SetLocation(zeek::detail::Stmt* stmt); bool SetLocation(double time); bool Reset(); // cancel and re-apply bpt when restarting execution @@ -35,7 +37,7 @@ public: // // NOTE: If it returns a hit, the DbgBreakpoint object will take // appropriate action (e.g., resetting counters). - BreakCode ShouldBreak(Stmt* s); + BreakCode ShouldBreak(zeek::detail::Stmt* s); BreakCode ShouldBreak(double t); const std::string& GetCondition() const { return condition; } @@ -70,7 +72,7 @@ protected: bool enabled; // ### comment this and next bool temporary; - Stmt* at_stmt; + zeek::detail::Stmt* at_stmt; double at_time; // break when the virtual time is this // Support for conditional and N'th time breakpoints. diff --git a/src/DbgWatch.cc b/src/DbgWatch.cc index 8ea7d96fa1..5d286afc1c 100644 --- a/src/DbgWatch.cc +++ b/src/DbgWatch.cc @@ -12,7 +12,7 @@ DbgWatch::DbgWatch(BroObj* var_to_watch) reporter->InternalError("DbgWatch unimplemented"); } -DbgWatch::DbgWatch(Expr* expr_to_watch) +DbgWatch::DbgWatch(zeek::detail::Expr* expr_to_watch) { reporter->InternalError("DbgWatch unimplemented"); } diff --git a/src/DbgWatch.h b/src/DbgWatch.h index 2dfb8ea605..72a0bbe7fd 100644 --- a/src/DbgWatch.h +++ b/src/DbgWatch.h @@ -2,16 +2,19 @@ #pragma once +#include "util.h" + class BroObj; -class Expr; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); class DbgWatch { public: explicit DbgWatch(BroObj* var_to_watch); - explicit DbgWatch(Expr* expr_to_watch); + explicit DbgWatch(zeek::detail::Expr* expr_to_watch); ~DbgWatch(); protected: BroObj* var; - Expr* expr; + zeek::detail::Expr* expr; }; diff --git a/src/Debug.cc b/src/Debug.cc index 3637516850..f1e94e96c9 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -135,7 +135,7 @@ int TraceState::LogTrace(const char* fmt, ...) // Prefix includes timestamp and file/line info. fprintf(trace_file, "%.6f ", network_time); - const Stmt* stmt; + const zeek::detail::Stmt* stmt; Location loc; loc.filename = nullptr; @@ -174,7 +174,7 @@ int TraceState::LogTrace(const char* fmt, ...) // Helper functions. -void get_first_statement(Stmt* list, Stmt*& first, Location& loc) +void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, Location& loc) { if ( ! list ) { @@ -231,7 +231,7 @@ static void parse_function_name(vector& result, return; } - Stmt* body = nullptr; // the particular body we care about; 0 = all + zeek::detail::Stmt* body = nullptr; // the particular body we care about; 0 = all if ( bodies.size() == 1 ) body = bodies[0].stmts.get(); @@ -243,7 +243,7 @@ static void parse_function_name(vector& result, "Please choose one of the following options:\n"); for ( unsigned int i = 0; i < bodies.size(); ++i ) { - Stmt* first; + zeek::detail::Stmt* first; Location stmt_loc; get_first_statement(bodies[i].stmts.get(), first, stmt_loc); debug_msg("[%d] %s:%d\n", i+1, stmt_loc.filename, stmt_loc.first_line); @@ -286,7 +286,7 @@ static void parse_function_name(vector& result, plr.type = plrFunction; // Find first atomic (non-STMT_LIST) statement - Stmt* first; + zeek::detail::Stmt* first; Location stmt_loc; if ( body ) @@ -728,7 +728,7 @@ static char* get_prompt(bool reset_counter = false) return prompt; } -string get_context_description(const Stmt* stmt, const Frame* frame) +string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame) { ODesc d; const BroFunc* func = frame ? frame->GetFunction() : nullptr; @@ -776,7 +776,7 @@ int dbg_handle_debug_input() else current_module = GLOBAL_MODULE_NAME; - const Stmt* stmt = curr_frame->GetNextStmt(); + const zeek::detail::Stmt* stmt = curr_frame->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: stmt != 0"); @@ -840,7 +840,7 @@ int dbg_handle_debug_input() // Return true to continue execution, false to abort. -bool pre_execute_stmt(Stmt* stmt, Frame* f) +bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f) { if ( ! g_policy_debug || stmt->Tag() == STMT_LIST || stmt->Tag() == STMT_NULL ) @@ -905,7 +905,7 @@ bool pre_execute_stmt(Stmt* stmt, Frame* f) return true; } -bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) +bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) { // Handle the case where someone issues a "next" debugger command, // but we're at a return statement, so the next statement is in @@ -935,7 +935,7 @@ bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow) // Evaluates the given expression in the context of the currently selected // frame. Returns the resulting value, or nil if none (or there was an error). -Expr* g_curr_debug_expr = nullptr; +zeek::detail::Expr* g_curr_debug_expr = nullptr; const char* g_curr_debug_error = nullptr; bool in_debug = false; diff --git a/src/Debug.h b/src/Debug.h index 5208e61780..e467c00a0e 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -5,6 +5,7 @@ #include "Obj.h" #include "Queue.h" #include "StmtEnums.h" +#include "util.h" #include #include @@ -12,14 +13,15 @@ template class IntrusivePtr; class Val; -class Stmt; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); // This needs to be defined before we do the includes that come after it. enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction }; struct ParseLocationRec { ParseLocationRecType type; int32_t line; - Stmt* stmt; + zeek::detail::Stmt* stmt; const char* filename; }; @@ -33,7 +35,7 @@ class DbgDisplay; class StmtHashFn; typedef std::map BPIDMapType; -typedef std::multimap BPMapType; +typedef std::multimap BPMapType; extern std::string current_module; @@ -104,15 +106,15 @@ private: class StmtLocMapping { public: StmtLocMapping() { } - StmtLocMapping(const Location* l, Stmt* s) { loc = *l; stmt = s; } + StmtLocMapping(const Location* l, zeek::detail::Stmt* s) { loc = *l; stmt = s; } bool StartsAfter(const StmtLocMapping* m2); const Location& Loc() const { return loc; } - Stmt* Statement() const { return stmt; } + zeek::detail::Stmt* Statement() const { return stmt; } protected: Location loc; - Stmt* stmt; + zeek::detail::Stmt* stmt; }; @@ -143,8 +145,8 @@ std::vector parse_location_string(const std::string& s); // Debugging hooks. // Return true to continue execution, false to abort. -bool pre_execute_stmt(Stmt* stmt, Frame* f); -bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow); +bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f); +bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow); // Returns 1 if successful, 0 otherwise. // If cmdfile is non-nil, it contains the location of a file of commands @@ -168,7 +170,7 @@ IntrusivePtr dbg_eval_expr(const char* expr); int dbg_read_internal_state(); // Get line that looks like "In FnFoo(arg = val) at File:Line". -std::string get_context_description(const Stmt* stmt, const Frame* frame); +std::string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame); extern Frame* g_dbg_locals; // variables created within debugger context diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index e36836e50a..b7c411989a 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -30,13 +30,13 @@ using namespace std; // // Helper routines // -bool string_is_regex(const string& s) +static bool string_is_regex(const string& s) { return strpbrk(s.data(), "?*\\+"); } -void lookup_global_symbols_regex(const string& orig_regex, vector& matches, - bool func_only = false) +static void lookup_global_symbols_regex(const string& orig_regex, vector& matches, + bool func_only = false) { if ( streq(orig_regex.c_str(), "") ) return; @@ -61,18 +61,18 @@ void lookup_global_symbols_regex(const string& orig_regex, vector& matches, Scope* global = global_scope(); const auto& syms = global->Vars(); - ID* nextid; + zeek::detail::ID* nextid; for ( const auto& sym : syms ) { - ID* nextid = sym.second.get(); - if ( ! func_only || nextid->GetType()->Tag() == TYPE_FUNC ) + zeek::detail::ID* nextid = sym.second.get(); + if ( ! func_only || nextid->GetType()->Tag() == zeek::TYPE_FUNC ) if ( ! regexec (&re, nextid->Name(), 0, 0, 0) ) matches.push_back(nextid); } } -void choose_global_symbols_regex(const string& regex, vector& choices, - bool func_only = false) +static void choose_global_symbols_regex(const string& regex, vector& choices, + bool func_only = false) { lookup_global_symbols_regex(regex, choices, func_only); @@ -111,7 +111,7 @@ void choose_global_symbols_regex(const string& regex, vector& choices, int option = atoi(input.c_str()); if ( option > 0 && option <= (int) choices.size() ) { - ID* choice = choices[option - 1]; + zeek::detail::ID* choice = choices[option - 1]; choices.clear(); choices.push_back(choice); return; @@ -216,7 +216,7 @@ static int dbg_backtrace_internal(int start, int end) for ( int i = start; i >= end; --i ) { const Frame* f = g_frame_stack[i]; - const Stmt* stmt = f ? f->GetNextStmt() : nullptr; + const zeek::detail::Stmt* stmt = f ? f->GetNextStmt() : nullptr; string context = get_context_description(stmt, f); debug_msg("#%d %s\n", @@ -333,7 +333,7 @@ int dbg_cmd_frame(DebugCmd cmd, const vector& args) // Set the current location to the new frame being looked at // for 'list', 'break', etc. - const Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); + const zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: %s", "stmt != 0"); @@ -373,7 +373,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector& args) g_frame_stack.size() - 1 - g_debugger_state.curr_frame_idx; - Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); + zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt(); if ( ! stmt ) reporter->InternalError("Assertion failed: %s", "stmt != 0"); @@ -398,7 +398,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector& args) vector locstrings; if ( string_is_regex(args[0]) ) { - vector choices; + vector choices; choose_global_symbols_regex(args[0], choices, true); for ( unsigned int i = 0; i < choices.size(); ++i ) locstrings.push_back(choices[i]->Name()); diff --git a/src/DebugLogger.cc b/src/DebugLogger.cc index 8234e14b08..8f8be1fc97 100644 --- a/src/DebugLogger.cc +++ b/src/DebugLogger.cc @@ -163,7 +163,7 @@ void DebugLogger::Log(DebugStream stream, const char* fmt, ...) fflush(file); } -void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...) +void DebugLogger::Log(const zeek::plugin::Plugin& plugin, const char* fmt, ...) { std::string tok = std::string("plugin-") + plugin.Name(); tok = strreplace(tok, "::", "-"); diff --git a/src/DebugLogger.h b/src/DebugLogger.h index e0eb57f47b..c0caa02088 100644 --- a/src/DebugLogger.h +++ b/src/DebugLogger.h @@ -45,7 +45,7 @@ enum DebugStream { #define PLUGIN_DBG_LOG(plugin, args...) debug_logger.Log(plugin, args) -namespace plugin { class Plugin; } +namespace zeek::plugin { class Plugin; } class DebugLogger { public: @@ -56,7 +56,7 @@ public: void OpenDebugLog(const char* filename = 0); void Log(DebugStream stream, const char* fmt, ...) __attribute__((format(printf, 3, 4))); - void Log(const plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4))); + void Log(const zeek::plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4))); void PushIndent(DebugStream stream) { ++streams[int(stream)].indent; } diff --git a/src/Desc.cc b/src/Desc.cc index 978ddff24c..624aeaaa6b 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::Type* type) { auto res = encountered_types.insert(type); return std::get<1>(res); } -bool ODesc::PopType(const BroType* type) +bool ODesc::PopType(const zeek::Type* type) { size_t res = encountered_types.erase(type); return (res == 1); } -bool ODesc::FindType(const BroType* type) +bool ODesc::FindType(const zeek::Type* type) { auto res = encountered_types.find(type); diff --git a/src/Desc.h b/src/Desc.h index 658f0c477e..7a009caa57 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -25,7 +25,9 @@ typedef enum { class BroFile; class IPAddr; class IPPrefix; -class BroType; + +namespace zeek { class Type; } +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; class ODesc { public: @@ -146,9 +148,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::Type* type); + bool PopType(const zeek::Type* type); + bool FindType(const zeek::Type* type); protected: void Indent(); @@ -204,5 +206,5 @@ protected: bool do_flush; bool include_stats; - std::set encountered_types; + std::set encountered_types; }; diff --git a/src/Event.h b/src/Event.h index fe5dc9baf2..69e9fe37f9 100644 --- a/src/Event.h +++ b/src/Event.h @@ -145,7 +145,7 @@ protected: analyzer::ID current_aid; RecordVal* src_val; bool draining; - bro::Flare queue_flare; + zeek::detail::Flare queue_flare; }; extern EventMgr mgr; diff --git a/src/EventHandler.cc b/src/EventHandler.cc index 890bda3a4d..60ae89536f 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; } @@ -117,7 +117,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++ ) @@ -126,7 +126,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)); @@ -150,4 +150,3 @@ void EventHandler::NewEvent(zeek::Args* vl) }); mgr.Dispatch(ev); } - diff --git a/src/EventHandler.h b/src/EventHandler.h index 056165271b..4016328655 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -23,10 +23,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); @@ -69,7 +69,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 817a8f49b0..8f32196452 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -22,6 +22,8 @@ #include "broker/Data.h" +namespace zeek::detail { + const char* expr_name(BroExprTag t) { static const char* expr_names[int(NUM_EXPRS)] = { @@ -88,7 +90,7 @@ IntrusivePtr Expr::MakeLvalue() return {NewRef{}, this}; } -void Expr::EvalIntoAggregate(const BroType* /* t */, Val* /* aggr */, +void Expr::EvalIntoAggregate(const zeek::Type* /* t */, Val* /* aggr */, Frame* /* f */) const { Internal("Expr::EvalIntoAggregate called"); @@ -99,7 +101,7 @@ void Expr::Assign(Frame* /* f */, IntrusivePtr /* v */) Internal("Expr::Assign called"); } -IntrusivePtr Expr::InitType() const +IntrusivePtr Expr::InitType() const { return type; } @@ -114,7 +116,7 @@ bool Expr::IsPure() const return true; } -IntrusivePtr Expr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr Expr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( aggr ) { @@ -130,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() @@ -180,9 +182,9 @@ void Expr::Canonicize() { } -void Expr::SetType(IntrusivePtr t) +void Expr::SetType(IntrusivePtr t) { - if ( ! type || type->Tag() != TYPE_ERROR ) + if ( ! type || type->Tag() != zeek::TYPE_ERROR ) type = std::move(t); } @@ -310,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()); @@ -355,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)); @@ -453,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 ) { @@ -470,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 ) { @@ -525,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; @@ -546,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(); @@ -674,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); @@ -879,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)); } @@ -947,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); @@ -1006,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 @@ -1025,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 @@ -1045,18 +1047,18 @@ PosExpr::PosExpr(IntrusivePtr arg_op) const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); - IntrusivePtr base_result_type; + IntrusivePtr base_result_type; 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)); } @@ -1065,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()); @@ -1080,27 +1082,27 @@ NegExpr::NegExpr(IntrusivePtr arg_op) const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); - IntrusivePtr base_result_type; + IntrusivePtr base_result_type; 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()); @@ -1112,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 @@ -1149,11 +1151,11 @@ AddExpr::AddExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsVector(bt2) ) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); - IntrusivePtr base_result_type; + 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)); @@ -1165,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)); } @@ -1174,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(); } @@ -1214,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))); @@ -1274,13 +1276,13 @@ SubExpr::SubExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2) if ( IsVector(bt2) ) bt2 = t2->AsVectorType()->Yield()->Tag(); - IntrusivePtr base_result_type; + 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() ) { @@ -1299,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)); } @@ -1362,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"); } @@ -1377,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(); } @@ -1399,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"); @@ -1417,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"); @@ -1429,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()); @@ -1495,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"); @@ -1572,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)); } @@ -1597,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 ) @@ -1639,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() ) @@ -1693,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) ) @@ -1739,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 @@ -1748,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()) ) @@ -1760,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(); @@ -1795,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)); @@ -1811,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"); } @@ -1845,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 @@ -1875,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)); } @@ -1929,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 ) @@ -1986,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()); @@ -2041,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; @@ -2056,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; @@ -2098,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; } @@ -2115,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()) ) { @@ -2142,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 ) { @@ -2207,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); @@ -2260,7 +2262,7 @@ IntrusivePtr AssignExpr::Eval(Frame* f) const return nullptr; } -IntrusivePtr AssignExpr::InitType() const +IntrusivePtr AssignExpr::InitType() const { if ( op1->Tag() != EXPR_LIST ) { @@ -2269,14 +2271,14 @@ 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()}, op2->GetType()); } -void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const +void AssignExpr::EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const { if ( IsError() ) return; @@ -2285,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; @@ -2325,7 +2327,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const RuntimeError("type clash in table assignment"); } -IntrusivePtr AssignExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr AssignExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( ! aggr ) { @@ -2340,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; @@ -2355,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(); @@ -2371,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)); @@ -2481,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"); @@ -2514,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) @@ -2579,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()) ) @@ -2630,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(); @@ -2640,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); @@ -2659,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(); @@ -2728,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(); @@ -2759,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())); @@ -2770,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); @@ -2781,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())); @@ -2791,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; @@ -2938,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)); } } @@ -3002,14 +3004,14 @@ RecordConstructorExpr::~RecordConstructorExpr() { } -IntrusivePtr RecordConstructorExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr RecordConstructorExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { auto v = Eval(nullptr); if ( v ) { RecordVal* rv = v->AsRecordVal(); - auto bt = const_cast(t); + auto bt = const_cast(t); IntrusivePtr rt{NewRef{}, bt->AsRecordType()}; auto aggr_rec = cast_intrusive(std::move(aggr)); auto ar = rv->CoerceTo(std::move(rt), std::move(aggr_rec)); @@ -3047,7 +3049,7 @@ void RecordConstructorExpr::ExprDescribe(ODesc* d) const TableConstructorExpr::TableConstructorExpr(IntrusivePtr constructor_list, std::unique_ptr>> arg_attrs, - IntrusivePtr arg_type) + IntrusivePtr arg_type) : UnaryExpr(EXPR_TABLE_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3067,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())); @@ -3075,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"); } @@ -3141,7 +3143,7 @@ IntrusivePtr TableConstructorExpr::Eval(Frame* f) const return aggr; } -IntrusivePtr TableConstructorExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr TableConstructorExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( IsError() ) return nullptr; @@ -3168,7 +3170,7 @@ void TableConstructorExpr::ExprDescribe(ODesc* d) const SetConstructorExpr::SetConstructorExpr(IntrusivePtr constructor_list, std::unique_ptr>> arg_attrs, - IntrusivePtr arg_type) + IntrusivePtr arg_type) : UnaryExpr(EXPR_SET_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3188,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())); } @@ -3196,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 ) @@ -3252,7 +3254,7 @@ IntrusivePtr SetConstructorExpr::Eval(Frame* f) const return aggr; } -IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr SetConstructorExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( IsError() ) return nullptr; @@ -3286,7 +3288,7 @@ void SetConstructorExpr::ExprDescribe(ODesc* d) const } VectorConstructorExpr::VectorConstructorExpr(IntrusivePtr constructor_list, - IntrusivePtr arg_type) + IntrusivePtr arg_type) : UnaryExpr(EXPR_VECTOR_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3294,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(); @@ -3310,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(); @@ -3333,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) @@ -3350,12 +3352,12 @@ IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const return vec; } -IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr VectorConstructorExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( IsError() ) return nullptr; - auto vt = GetType(); + auto vt = GetType(); auto vec = aggr ? IntrusivePtr{AdoptRef{}, aggr.release()->AsVectorVal()} : make_intrusive(std::move(vt)); @@ -3390,7 +3392,7 @@ FieldAssignExpr::FieldAssignExpr(const char* arg_field_name, SetType(op->GetType()); } -void FieldAssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) +void FieldAssignExpr::EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const { if ( IsError() ) @@ -3441,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) && @@ -3462,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: @@ -3486,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); @@ -3495,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 ) { @@ -3518,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 @@ -3551,7 +3553,7 @@ RecordCoerceExpr::RecordCoerceExpr(IntrusivePtr arg_op, if ( ! same_type(sup_t_i, sub_t_i) ) { - auto is_arithmetic_promotable = [](BroType* sup, BroType* sub) -> bool + auto is_arithmetic_promotable = [](zeek::Type* sup, zeek::Type* sub) -> bool { auto sup_tag = sup->Tag(); auto sub_tag = sub->Tag(); @@ -3559,21 +3561,21 @@ 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; }; - auto is_record_promotable = [](BroType* sup, BroType* sub) -> bool + auto is_record_promotable = [](zeek::Type* sup, zeek::Type* 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(), @@ -3621,12 +3623,12 @@ RecordCoerceExpr::~RecordCoerceExpr() delete [] map; } -IntrusivePtr RecordCoerceExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr RecordCoerceExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { if ( auto v = Eval(nullptr) ) { RecordVal* rv = v->AsRecordVal(); - auto bt = const_cast(t); + auto bt = const_cast(t); IntrusivePtr rt{NewRef{}, bt->AsRecordType()}; auto aggr_rec = cast_intrusive(std::move(aggr)); @@ -3672,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)) ) @@ -3698,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( @@ -3728,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"); } @@ -3751,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() ) @@ -3759,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"); } @@ -3778,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, @@ -3808,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 @@ -3831,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()); @@ -3883,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(); @@ -3913,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; } } @@ -3950,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(); @@ -3974,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; @@ -4379,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 ) { @@ -4397,7 +4399,7 @@ IntrusivePtr ListExpr::Eval(Frame* f) const return v; } -IntrusivePtr ListExpr::InitType() const +IntrusivePtr ListExpr::InitType() const { if ( exprs.empty() ) { @@ -4435,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() : @@ -4455,7 +4457,7 @@ IntrusivePtr ListExpr::InitType() const } } -IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr ListExpr::InitVal(const zeek::Type* t, IntrusivePtr aggr) const { // While fairly similar to the EvalIntoAggregate() code, // we keep this separate since it also deals with initialization @@ -4468,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()) ) @@ -4489,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 ) { @@ -4505,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) { @@ -4520,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 }" @@ -4539,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(); @@ -4577,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; @@ -4599,9 +4601,9 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return aggr; } -IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) const +IntrusivePtr ListExpr::AddSetInit(const zeek::Type* 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(); @@ -4615,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); @@ -4637,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); @@ -4714,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(); @@ -4762,7 +4764,7 @@ RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, } } -CastExpr::CastExpr(IntrusivePtr arg_op, IntrusivePtr t) +CastExpr::CastExpr(IntrusivePtr arg_op, IntrusivePtr t) : UnaryExpr(EXPR_CAST, std::move(arg_op)) { auto stype = Op()->GetType(); @@ -4810,10 +4812,10 @@ void CastExpr::ExprDescribe(ODesc* d) const GetType()->Describe(d); } -IsExpr::IsExpr(IntrusivePtr arg_op, IntrusivePtr arg_t) +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 @@ -4834,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); @@ -4848,13 +4850,13 @@ IntrusivePtr get_assign_expr(IntrusivePtr op1, is_init); } -IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) +IntrusivePtr check_and_promote_expr(Expr* const e, zeek::Type* t) { const auto& et = e->GetType(); 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) ) @@ -4878,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(); @@ -4908,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()}); @@ -4930,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()) ) @@ -4966,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 ) @@ -5004,11 +5006,11 @@ bool check_and_promote_args(ListExpr* const args, RecordType* types) return rval; } -bool check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) +bool check_and_promote_exprs_to_type(ListExpr* const elements, zeek::Type* type) { expr_list& el = elements->Exprs(); - if ( type->Tag() == TYPE_ANY ) + if ( type->Tag() == zeek::TYPE_ANY ) return true; loop_over_list(el, i) @@ -5055,3 +5057,5 @@ bool expr_greater(const Expr* e1, const Expr* e2) { return e1->Tag() > e2->Tag(); } + +} diff --git a/src/Expr.h b/src/Expr.h index cd09920522..67fad1a9d5 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -17,6 +17,13 @@ #include "Val.h" #include "ZeekArgs.h" +template class IntrusivePtr; +class Frame; +class Scope; +struct function_ingredients; + +namespace zeek::detail { + enum BroExprTag : int { EXPR_ANY = -1, EXPR_NAME, EXPR_CONST, @@ -58,26 +65,20 @@ enum BroExprTag : int { extern const char* expr_name(BroExprTag t); -template class IntrusivePtr; -class Stmt; -class Frame; -class Scope; class ListExpr; class NameExpr; class IndexExpr; class AssignExpr; class CallExpr; class EventExpr; - -struct function_ingredients; - +class Stmt; class Expr : public BroObj { public: [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* Type() const { return type.get(); } + zeek::Type* Type() const { return type.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } template @@ -96,7 +97,7 @@ public: // into the given aggregate of the given type. Note that // return type is void since it's updating an existing // value, rather than creating a new one. - virtual void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) + virtual void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const; // Assign to the given value, if appropriate. @@ -104,7 +105,7 @@ public: // Returns the type corresponding to this expression interpreted // as an initialization. Returns nil if the initialization is illegal. - virtual IntrusivePtr InitType() const; + virtual IntrusivePtr InitType() const; // Returns true if this expression, interpreted as an initialization, // constitutes a record element, false otherwise. If the TypeDecl* @@ -117,7 +118,7 @@ public: // with the given type. If "aggr" is non-nil, then this expression // is an element of the given aggregate, and it is added to it // accordingly. - virtual IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const; + virtual IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const; // True if the expression has no side effects, false otherwise. virtual bool IsPure() const; @@ -222,7 +223,7 @@ protected: // Puts the expression in canonical form. virtual void Canonicize(); - void SetType(IntrusivePtr t); + void SetType(IntrusivePtr t); // Reports the given error and sets the expression's type to // TYPE_ERROR. @@ -234,7 +235,7 @@ protected: [[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const; BroExprTag tag; - IntrusivePtr type; + IntrusivePtr type; bool paren; }; @@ -523,10 +524,10 @@ public: const IntrusivePtr& attrs = nullptr); IntrusivePtr Eval(Frame* f) const override; - void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override; - IntrusivePtr InitType() const override; + void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override; + IntrusivePtr InitType() const override; bool IsRecordElement(TypeDecl* td) const override; - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; bool IsPure() const override; protected: @@ -623,7 +624,7 @@ public: ~RecordConstructorExpr() override; protected: - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; IntrusivePtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; @@ -633,7 +634,7 @@ class TableConstructorExpr final : public UnaryExpr { public: TableConstructorExpr(IntrusivePtr constructor_list, std::unique_ptr>> attrs, - IntrusivePtr arg_type = nullptr); + IntrusivePtr arg_type = nullptr); [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } @@ -644,7 +645,7 @@ public: IntrusivePtr Eval(Frame* f) const override; protected: - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; void ExprDescribe(ODesc* d) const override; @@ -655,7 +656,7 @@ class SetConstructorExpr final : public UnaryExpr { public: SetConstructorExpr(IntrusivePtr constructor_list, std::unique_ptr>> attrs, - IntrusivePtr arg_type = nullptr); + IntrusivePtr arg_type = nullptr); [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } @@ -666,7 +667,7 @@ public: IntrusivePtr Eval(Frame* f) const override; protected: - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; void ExprDescribe(ODesc* d) const override; @@ -676,12 +677,12 @@ protected: class VectorConstructorExpr final : public UnaryExpr { public: explicit VectorConstructorExpr(IntrusivePtr constructor_list, - IntrusivePtr arg_type = nullptr); + IntrusivePtr arg_type = nullptr); IntrusivePtr Eval(Frame* f) const override; protected: - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; void ExprDescribe(ODesc* d) const override; }; @@ -692,7 +693,7 @@ public: const char* FieldName() const { return field_name.c_str(); } - void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override; + void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override; bool IsRecordElement(TypeDecl* td) const override; protected: @@ -703,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; @@ -716,7 +717,7 @@ public: ~RecordCoerceExpr() override; protected: - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; IntrusivePtr Fold(Val* v) const override; // For each super-record slot, gives subrecord slot with which to @@ -867,15 +868,15 @@ public: IntrusivePtr Eval(Frame* f) const override; - IntrusivePtr InitType() const override; - IntrusivePtr InitVal(const BroType* t, IntrusivePtr aggr) const override; + IntrusivePtr InitType() const override; + IntrusivePtr InitVal(const zeek::Type* t, IntrusivePtr aggr) const override; IntrusivePtr MakeLvalue() override; void Assign(Frame* f, IntrusivePtr v) override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: - IntrusivePtr AddSetInit(const BroType* t, IntrusivePtr aggr) const; + IntrusivePtr AddSetInit(const zeek::Type* t, IntrusivePtr aggr) const; void ExprDescribe(ODesc* d) const override; @@ -890,7 +891,7 @@ public: class CastExpr final : public UnaryExpr { public: - CastExpr(IntrusivePtr op, IntrusivePtr t); + CastExpr(IntrusivePtr op, IntrusivePtr t); protected: IntrusivePtr Eval(Frame* f) const override; @@ -899,14 +900,14 @@ protected: class IsExpr final : public UnaryExpr { public: - IsExpr(IntrusivePtr op, IntrusivePtr t); + IsExpr(IntrusivePtr op, IntrusivePtr t); protected: IntrusivePtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; private: - IntrusivePtr t; + IntrusivePtr t; }; inline Val* Expr::ExprVal() const @@ -935,11 +936,11 @@ IntrusivePtr get_assign_expr(IntrusivePtr op1, * Returns nullptr if the expression cannot match or a promoted * expression. */ -extern IntrusivePtr check_and_promote_expr(Expr* e, BroType* t); +extern IntrusivePtr check_and_promote_expr(Expr* e, Type* t); extern bool check_and_promote_exprs(ListExpr* elements, TypeList* types); extern bool check_and_promote_args(ListExpr* args, RecordType* types); -extern bool check_and_promote_exprs_to_type(ListExpr* elements, BroType* type); +extern bool check_and_promote_exprs_to_type(ListExpr* elements, Type* type); // Returns a ListExpr simplified down to a list a values, or nil // if they couldn't all be reduced. @@ -953,3 +954,55 @@ extern bool expr_greater(const Expr* e1, const Expr* e2); // True if the given Expr* has a vector type inline bool is_vector(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; } inline bool is_vector(const IntrusivePtr& e) { return is_vector(e.get()); } + +} + +using Expr [[deprecated("Remove in v4.1. Use zeek::detail::Expr instead.")]] = zeek::detail::Expr; +using NameExpr [[deprecated("Remove in v4.1. Use zeek::detail::NameExpr instead.")]] = zeek::detail::NameExpr; +using ConstExpr [[deprecated("Remove in v4.1. Use zeek::detail::ConstExpr instead.")]] = zeek::detail::ConstExpr; +using UnaryExpr [[deprecated("Remove in v4.1. Use zeek::detail::UnaryExpr instead.")]] = zeek::detail::UnaryExpr; +using BinaryExpr [[deprecated("Remove in v4.1. Use zeek::detail::BinaryExpr instead.")]] = zeek::detail::BinaryExpr; +using CloneExpr [[deprecated("Remove in v4.1. Use zeek::detail::CloneExpr instead.")]] = zeek::detail::CloneExpr; +using IncrExpr [[deprecated("Remove in v4.1. Use zeek::detail::IncrExpr instead.")]] = zeek::detail::IncrExpr; +using ComplementExpr [[deprecated("Remove in v4.1. Use zeek::detail::ComplementExpr instead.")]] = zeek::detail::ComplementExpr; +using NotExpr [[deprecated("Remove in v4.1. Use zeek::detail::NotExpr instead.")]] = zeek::detail::NotExpr; +using PosExpr [[deprecated("Remove in v4.1. Use zeek::detail::PosExpr instead.")]] = zeek::detail::PosExpr; +using NegExpr [[deprecated("Remove in v4.1. Use zeek::detail::NegExpr instead.")]] = zeek::detail::NegExpr; +using SizeExpr [[deprecated("Remove in v4.1. Use zeek::detail::SizeExpr instead.")]] = zeek::detail::SizeExpr; +using AddExpr [[deprecated("Remove in v4.1. Use zeek::detail::AddExpr instead.")]] = zeek::detail::AddExpr; +using AddToExpr [[deprecated("Remove in v4.1. Use zeek::detail::AddToExpr instead.")]] = zeek::detail::AddToExpr; +using RemoveFromExpr [[deprecated("Remove in v4.1. Use zeek::detail::RemoveFromExpr instead.")]] = zeek::detail::RemoveFromExpr; +using SubExpr [[deprecated("Remove in v4.1. Use zeek::detail::SubExpr instead.")]] = zeek::detail::SubExpr; +using TimesExpr [[deprecated("Remove in v4.1. Use zeek::detail::TimesExpr instead.")]] = zeek::detail::TimesExpr; +using DivideExpr [[deprecated("Remove in v4.1. Use zeek::detail::DivideExpr instead.")]] = zeek::detail::DivideExpr; +using ModExpr [[deprecated("Remove in v4.1. Use zeek::detail::ModExpr instead.")]] = zeek::detail::ModExpr; +using BoolExpr [[deprecated("Remove in v4.1. Use zeek::detail::BoolExpr instead.")]] = zeek::detail::BoolExpr; +using BitExpr [[deprecated("Remove in v4.1. Use zeek::detail::BitExpr instead.")]] = zeek::detail::BitExpr; +using EqExpr [[deprecated("Remove in v4.1. Use zeek::detail::EqExpr instead.")]] = zeek::detail::EqExpr; +using RelExpr [[deprecated("Remove in v4.1. Use zeek::detail::RelExpr instead.")]] = zeek::detail::RelExpr; +using CondExpr [[deprecated("Remove in v4.1. Use zeek::detail::CondExpr instead.")]] = zeek::detail::CondExpr; +using RefExpr [[deprecated("Remove in v4.1. Use zeek::detail::RefExpr instead.")]] = zeek::detail::RefExpr; +using AssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::AssignExpr instead.")]] = zeek::detail::AssignExpr; +using IndexSliceAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::IndexSliceAssignExpr instead.")]] = zeek::detail::IndexSliceAssignExpr; +using IndexExpr [[deprecated("Remove in v4.1. Use zeek::detail::IndexExpr instead.")]] = zeek::detail::IndexExpr; +using FieldExpr [[deprecated("Remove in v4.1. Use zeek::detail::FieldExpr instead.")]] = zeek::detail::FieldExpr; +using HasFieldExpr [[deprecated("Remove in v4.1. Use zeek::detail::HasFieldExpr instead.")]] = zeek::detail::HasFieldExpr; +using RecordConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordConstructorExpr instead.")]] = zeek::detail::RecordConstructorExpr; +using TableConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::TableConstructorExpr instead.")]] = zeek::detail::TableConstructorExpr; +using SetConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::SetConstructorExpr instead.")]] = zeek::detail::SetConstructorExpr; +using VectorConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::VectorConstructorExpr instead.")]] = zeek::detail::VectorConstructorExpr; +using FieldAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::FieldAssignExpr instead.")]] = zeek::detail::FieldAssignExpr; +using ArithCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::ArithCoerceExpr instead.")]] = zeek::detail::ArithCoerceExpr; +using RecordCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordCoerceExpr instead.")]] = zeek::detail::RecordCoerceExpr; +using TableCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::TableCoerceExpr instead.")]] = zeek::detail::TableCoerceExpr; +using VectorCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::VectorCoerceExpr instead.")]] = zeek::detail::VectorCoerceExpr; +using ScheduleTimer [[deprecated("Remove in v4.1. Use zeek::detail::ScheduleTimer instead.")]] = zeek::detail::ScheduleTimer; +using ScheduleExpr [[deprecated("Remove in v4.1. Use zeek::detail::ScheduleExpr instead.")]] = zeek::detail::ScheduleExpr; +using InExpr [[deprecated("Remove in v4.1. Use zeek::detail::InExpr instead.")]] = zeek::detail::InExpr; +using CallExpr [[deprecated("Remove in v4.1. Use zeek::detail::CallExpr instead.")]] = zeek::detail::CallExpr; +using LambdaExpr [[deprecated("Remove in v4.1. Use zeek::detail::LambdaExpr instead.")]] = zeek::detail::LambdaExpr; +using EventExpr [[deprecated("Remove in v4.1. Use zeek::detail::EventExpr instead.")]] = zeek::detail::EventExpr; +using ListExpr [[deprecated("Remove in v4.1. Use zeek::detail::ListExpr instead.")]] = zeek::detail::ListExpr; +using RecordAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordAssignExpr instead.")]] = zeek::detail::RecordAssignExpr; +using CastExpr [[deprecated("Remove in v4.1. Use zeek::detail::CastExpr instead.")]] = zeek::detail::CastExpr; +using IsExpr [[deprecated("Remove in v4.1. Use zeek::detail::IsExpr instead.")]] = zeek::detail::IsExpr; diff --git a/src/File.cc b/src/File.cc index a360fbf8a7..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; @@ -257,7 +257,7 @@ void BroFile::Describe(ODesc* d) const d->Add("(no type)"); } -void BroFile::SetAttrs(Attributes* arg_attrs) +void BroFile::SetAttrs(zeek::detail::Attributes* arg_attrs) { if ( ! arg_attrs ) return; @@ -265,7 +265,7 @@ void BroFile::SetAttrs(Attributes* arg_attrs) attrs = arg_attrs; Ref(attrs); - if ( attrs->Find(ATTR_RAW_OUTPUT) ) + if ( attrs->Find(zeek::detail::ATTR_RAW_OUTPUT) ) EnableRawOutput(); } @@ -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 edf0b7d0f4..8e57572a63 100644 --- a/src/File.h +++ b/src/File.h @@ -2,23 +2,28 @@ #pragma once -#include "Obj.h" -#include "IntrusivePtr.h" - #include #include #include #include -# ifdef NEED_KRB5_H -# include -# endif // NEED_KRB5_H +#ifdef NEED_KRB5_H +#include +#endif // NEED_KRB5_H + +#include "Obj.h" +#include "IntrusivePtr.h" +#include "util.h" -class Attributes; -class BroType; class RecordVal; +namespace zeek { class Type; } +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; + +ZEEK_FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); + class BroFile final : public BroObj { public: explicit BroFile(FILE* arg_f); @@ -38,9 +43,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::Type* 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 @@ -58,7 +63,7 @@ public: RecordVal* Rotate(); // Set &raw_output attribute. - void SetAttrs(Attributes* attrs); + void SetAttrs(zeek::detail::Attributes* attrs); // Returns the current size of the file, after fresh stat'ing. double Size(); @@ -77,7 +82,7 @@ public: protected: - friend class PrintStmt; + friend class zeek::detail::PrintStmt; BroFile() { Init(); } void Init(); @@ -101,10 +106,10 @@ protected: void RaiseOpenEvent(); FILE* f; - IntrusivePtr t; + IntrusivePtr t; char* name; char* access; - Attributes* attrs; + zeek::detail::Attributes* attrs; double open_time; bool is_open; // whether the file is open in a general sense bool buffered; diff --git a/src/Flare.cc b/src/Flare.cc index ec3ef2073f..89e24303ab 100644 --- a/src/Flare.cc +++ b/src/Flare.cc @@ -6,7 +6,7 @@ #include #include -using namespace bro; +using namespace zeek::detail; Flare::Flare() : pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK) diff --git a/src/Flare.h b/src/Flare.h index ea484b2858..3fa92a6cae 100644 --- a/src/Flare.h +++ b/src/Flare.h @@ -4,7 +4,7 @@ #include "Pipe.h" -namespace bro { +namespace zeek::detail { class Flare { public: @@ -21,8 +21,7 @@ public: * @return a file descriptor that will become ready if the flare has been * Fire()'d and not yet Extinguished()'d. */ - int FD() const - { return pipe.ReadFD(); } + int FD() const { return pipe.ReadFD(); } /** * Put the object in the "ready" state. @@ -44,4 +43,4 @@ private: Pipe pipe; }; -} // namespace bro +} // namespace zeek::detail diff --git a/src/Frame.cc b/src/Frame.cc index 7c1470d2dc..6962b1aa0e 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -77,7 +77,7 @@ void Frame::SetElementWeak(int n, Val* v) frame[n] = {{AdoptRef{}, v}, true}; } -void Frame::SetElement(const ID* id, IntrusivePtr v) +void Frame::SetElement(const zeek::detail::ID* id, IntrusivePtr v) { if ( closure ) { @@ -106,7 +106,7 @@ void Frame::SetElement(const ID* id, IntrusivePtr v) SetElement(id->Offset(), std::move(v)); } -const IntrusivePtr& Frame::GetElementByID(const ID* id) const +const IntrusivePtr& Frame::GetElementByID(const zeek::detail::ID* id) const { if ( closure ) { @@ -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::Type t( static_cast(g) ); auto val = bro_broker::data_to_val(std::move(val_tuple[0]), &t); if ( ! val ) @@ -478,7 +478,7 @@ void Frame::AddKnownOffsets(const id_list& ids) offset_map = std::make_unique(); std::transform(ids.begin(), ids.end(), std::inserter(*offset_map, offset_map->end()), - [] (const ID* id) -> std::pair + [] (const zeek::detail::ID* id) -> std::pair { return std::make_pair(std::string(id->Name()), id->Offset()); }); @@ -505,7 +505,7 @@ void Frame::CaptureClosure(Frame* c, id_list arg_outer_ids) // if (c) closure = c->SelectiveClone(outer_ids); } -void Frame::SetTrigger(IntrusivePtr arg_trigger) +void Frame::SetTrigger(IntrusivePtr arg_trigger) { trigger = std::move(arg_trigger); } @@ -523,10 +523,10 @@ void Frame::ClearElement(int n) frame[n] = {nullptr, false}; } -bool Frame::IsOuterID(const ID* in) const +bool Frame::IsOuterID(const zeek::detail::ID* in) const { return std::any_of(outer_ids.begin(), outer_ids.end(), - [&in](ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; }); + [&in](zeek::detail::ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; }); } broker::expected Frame::SerializeIDList(const id_list& in) @@ -588,7 +588,7 @@ Frame::UnserializeIDList(const broker::vector& data) return std::make_pair(false, std::move(rval)); } - ID* id = new ID(has_name->c_str(), SCOPE_FUNCTION, false); + auto* id = new zeek::detail::ID(has_name->c_str(), zeek::detail::SCOPE_FUNCTION, false); id->SetOffset(*has_offset); rval.push_back(id); std::advance(where, 1); diff --git a/src/Frame.h b/src/Frame.h index a85254469c..248e8e8f04 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -16,10 +16,11 @@ #include #include -namespace trigger { class Trigger; } -class CallExpr; class BroFunc; +ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger); + class Frame : public BroObj { public: /** @@ -65,8 +66,8 @@ public: * @param id the ID to associate * @param v the value to associate it with */ - void SetElement(const ID* id, IntrusivePtr v); - void SetElement(const IntrusivePtr& id, IntrusivePtr v) + void SetElement(const zeek::detail::ID* id, IntrusivePtr v); + void SetElement(const IntrusivePtr& id, IntrusivePtr v) { SetElement(id.get(), std::move(v)); } /** @@ -76,11 +77,11 @@ public: * @param id the id who's value to retreive * @return the value associated with *id* */ - const IntrusivePtr& GetElementByID(const IntrusivePtr& id) const + const IntrusivePtr& GetElementByID(const IntrusivePtr& id) const { return GetElementByID(id.get()); } [[deprecated("Remove in v4.1. Use GetElementByID().")]] - Val* GetElement(const ID* id) const + Val* GetElement(const zeek::detail::ID* id) const { return GetElementByID(id).get(); } /** @@ -118,12 +119,12 @@ public: * * @param stmt the statement to set it to. */ - void SetNextStmt(Stmt* stmt) { next_stmt = stmt; } + void SetNextStmt(zeek::detail::Stmt* stmt) { next_stmt = stmt; } /** * @return the next statement to be executed in the context of the frame. */ - Stmt* GetNextStmt() const { return next_stmt; } + zeek::detail::Stmt* GetNextStmt() const { return next_stmt; } /** Used to implement "next" command in debugger. */ void BreakBeforeNextStmt(bool should_break) @@ -215,13 +216,13 @@ public: // If the frame is run in the context of a trigger condition evaluation, // the trigger needs to be registered. - void SetTrigger(IntrusivePtr arg_trigger); + void SetTrigger(IntrusivePtr arg_trigger); void ClearTrigger(); - trigger::Trigger* GetTrigger() const { return trigger.get(); } + zeek::detail::trigger::Trigger* GetTrigger() const { return trigger.get(); } - void SetCall(const CallExpr* arg_call) { call = arg_call; } + void SetCall(const zeek::detail::CallExpr* arg_call) { call = arg_call; } void ClearCall() { call = nullptr; } - const CallExpr* GetCall() const { return call; } + const zeek::detail::CallExpr* GetCall() const { return call; } void SetDelayed() { delayed = true; } bool HasDelayed() const { return delayed; } @@ -246,7 +247,7 @@ private: bool weak_ref; }; - const IntrusivePtr& GetElementByID(const ID* id) const; + const IntrusivePtr& GetElementByID(const zeek::detail::ID* id) const; /** * Sets the element at index *n* of the underlying array to *v*, but does @@ -272,7 +273,7 @@ private: void ClearElement(int n); /** Have we captured this id? */ - bool IsOuterID(const ID* in) const; + bool IsOuterID(const zeek::detail::ID* in) const; /** Serializes an offset_map */ static broker::expected @@ -319,10 +320,10 @@ private: const zeek::Args* func_args; /** The next statement to be evaluted in the context of this frame. */ - Stmt* next_stmt; + zeek::detail::Stmt* next_stmt; - IntrusivePtr trigger; - const CallExpr* call; + IntrusivePtr trigger; + const zeek::detail::CallExpr* call; std::unique_ptr> functions_with_closure_frame_reference; }; diff --git a/src/Func.cc b/src/Func.cc index 38ec25b137..8bdcf2d2c5 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -121,8 +121,8 @@ Func::Func(Kind arg_kind) : kind(arg_kind) Func::~Func() = default; -void Func::AddBody(IntrusivePtr /* new_body */, - const std::vector>& /* new_inits */, +void Func::AddBody(IntrusivePtr /* new_body */, + const std::vector>& /* new_inits */, size_t /* new_frame_size */, int /* priority */) { Internal("Func::AddBody called"); @@ -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()); @@ -268,13 +268,13 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr& hook_result, } } -BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, - const std::vector>& aggr_inits, +BroFunc::BroFunc(const IntrusivePtr& arg_id, IntrusivePtr arg_body, + const std::vector>& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) { name = arg_id->Name(); - 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); @@ -343,7 +343,7 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const } g_frame_stack.push_back(f.get()); // used for backtracing - const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; + const zeek::detail::CallExpr* call_expr = parent ? parent->GetCall() : nullptr; call_stack.emplace_back(CallInfo{call_expr, this, *args}); if ( g_trace_state.DoTrace() ) @@ -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() ) @@ -449,8 +449,8 @@ IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const return result; } -void BroFunc::AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, +void BroFunc::AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, size_t new_frame_size, int priority) { if ( new_frame_size > frame_size ) @@ -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); @@ -574,14 +574,14 @@ void BroFunc::Describe(ODesc* d) const } } -IntrusivePtr BroFunc::AddInits(IntrusivePtr body, - const std::vector>& inits) +IntrusivePtr BroFunc::AddInits(IntrusivePtr body, + const std::vector>& inits) { if ( inits.empty() ) return body; - auto stmt_series = make_intrusive(); - stmt_series->Stmts().push_back(new InitStmt(inits)); + auto stmt_series = make_intrusive(); + stmt_series->Stmts().push_back(new zeek::detail::InitStmt(inits)); stmt_series->Stmts().push_back(body.release()); return stmt_series; @@ -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; @@ -641,7 +641,7 @@ IntrusivePtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const g_trace_state.LogTrace("\tBuiltin Function called: %s\n", d.Description()); } - const CallExpr* call_expr = parent ? parent->GetCall() : nullptr; + const zeek::detail::CallExpr* call_expr = parent ? parent->GetCall() : nullptr; call_stack.emplace_back(CallInfo{call_expr, this, *args}); auto result = std::move(func(parent, args).rval); call_stack.pop_back(); @@ -675,7 +675,7 @@ void builtin_error(const char* msg, IntrusivePtr arg) void builtin_error(const char* msg, BroObj* arg) { - auto emit = [=](const CallExpr* ce) + auto emit = [=](const zeek::detail::CallExpr* ce) { if ( ce ) ce->Error(msg, arg); @@ -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(); @@ -789,7 +789,7 @@ void init_builtin_funcs_subdirs() #include "__all__.bif.init.cc" // Autogenerated for compiling in the bif_target() code. } -bool check_built_in_call(BuiltinFunc* f, CallExpr* call) +bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call) { if ( f->TheFunc() != zeek::BifFunc::fmt_bif) return true; @@ -802,8 +802,8 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call) return true; } - const Expr* fmt_str_arg = args[0]; - if ( fmt_str_arg->GetType()->Tag() != TYPE_STRING ) + const zeek::detail::Expr* fmt_str_arg = args[0]; + if ( fmt_str_arg->GetType()->Tag() != zeek::TYPE_STRING ) { call->Error("first argument to fmt() needs to be a format string"); return false; @@ -844,16 +844,16 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call) // Gets a function's priority from its Scope's attributes. Errors if it sees any // problems. -static int get_func_priority(const std::vector>& attrs) +static int get_func_priority(const std::vector>& attrs) { int priority = 0; for ( const auto& a : attrs ) { - if ( a->Tag() == ATTR_DEPRECATED ) + if ( a->Tag() == zeek::detail::ATTR_DEPRECATED ) continue; - if ( a->Tag() != ATTR_PRIORITY ) + if ( a->Tag() != zeek::detail::ATTR_PRIORITY ) { a->Error("illegal attribute for function body"); continue; @@ -867,7 +867,7 @@ static int get_func_priority(const std::vector>& attrs) continue; } - if ( ! IsIntegral(v->GetType()->Tag()) ) + if ( ! zeek::IsIntegral(v->GetType()->Tag()) ) { a->Error("expression is not of integral type"); continue; @@ -879,7 +879,7 @@ static int get_func_priority(const std::vector>& attrs) return priority; } -function_ingredients::function_ingredients(IntrusivePtr scope, IntrusivePtr body) +function_ingredients::function_ingredients(IntrusivePtr scope, IntrusivePtr body) { frame_size = scope->Length(); inits = scope->GetInits(); diff --git a/src/Func.h b/src/Func.h index c8a284e3bd..b1a2eae796 100644 --- a/src/Func.h +++ b/src/Func.h @@ -18,14 +18,14 @@ #include "BifReturnVal.h" class Val; -class ListExpr; -class FuncType; -class Stmt; class Frame; -class ID; -class CallExpr; class Scope; +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); + namespace caf { template class expected; } @@ -47,10 +47,10 @@ 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; + IntrusivePtr stmts; int priority; bool operator<(const Body& other) const { return priority > other.priority; } // reverse sort @@ -86,17 +86,17 @@ public: } // Add a new event handler to an existing function (event). - virtual void AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, + virtual void AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, size_t new_frame_size, int priority = 0); virtual void SetScope(IntrusivePtr newscope); 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; } @@ -123,13 +123,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; }; @@ -137,8 +137,8 @@ protected: class BroFunc final : public Func { public: - BroFunc(const IntrusivePtr& id, IntrusivePtr body, - const std::vector>& inits, + BroFunc(const IntrusivePtr& id, IntrusivePtr body, + const std::vector>& inits, size_t frame_size, int priority); ~BroFunc() override; @@ -175,8 +175,8 @@ public: */ broker::expected SerializeClosure() const; - void AddBody(IntrusivePtr new_body, - const std::vector>& new_inits, + void AddBody(IntrusivePtr new_body, + const std::vector>& new_inits, size_t new_frame_size, int priority) override; /** Sets this function's outer_id list. */ @@ -187,8 +187,9 @@ public: protected: BroFunc() : Func(BRO_FUNC) {} - IntrusivePtr AddInits(IntrusivePtr body, - const std::vector>& inits); + IntrusivePtr AddInits( + IntrusivePtr body, + const std::vector>& inits); /** * Clones this function along with its closures. @@ -240,10 +241,10 @@ extern void builtin_error(const char* msg, BroObj* arg); extern void init_builtin_funcs(); extern void init_builtin_funcs_subdirs(); -extern bool check_built_in_call(BuiltinFunc* f, CallExpr* call); +extern bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call); struct CallInfo { - const CallExpr* call; + const zeek::detail::CallExpr* call; const Func* func; const zeek::Args& args; }; @@ -254,11 +255,11 @@ struct function_ingredients { // Gathers all of the information from a scope and a function body needed // to build a function. - function_ingredients(IntrusivePtr scope, IntrusivePtr body); + function_ingredients(IntrusivePtr scope, IntrusivePtr body); - IntrusivePtr id; - IntrusivePtr body; - std::vector> inits; + IntrusivePtr id; + IntrusivePtr body; + std::vector> inits; int frame_size; int priority; IntrusivePtr scope; diff --git a/src/ID.cc b/src/ID.cc index 20172a5e54..3d6bcab64c 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) +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,19 +89,21 @@ 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 { + ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) { name = copy_string(arg_name); @@ -118,6 +120,12 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export) SetLocationInfo(&start_location, &end_location); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +ID::ID(const char* arg_name, ::IDScope arg_scope, bool arg_is_export) : + ID(arg_name, static_cast(arg_scope), arg_is_export) {} +#pragma GCC diagnostic pop + ID::~ID() { delete [] name; @@ -128,7 +136,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); } @@ -215,6 +223,19 @@ void ID::SetVal(IntrusivePtr ev, init_class c) EvalFunc(a->GetExpr(), std::move(ev)); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void ID::SetVal(IntrusivePtr v, ::init_class c) + { + SetVal(v, static_cast(c)); + } + +void ID::SetVal(IntrusivePtr ev, ::init_class c) + { + SetVal(ev, static_cast(c)); + } +#pragma GCC diagnostic pop + bool ID::IsRedefinable() const { return GetAttr(ATTR_REDEF) != nullptr; @@ -252,7 +273,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); @@ -292,7 +313,7 @@ std::string ID::GetDeprecationWarning() const if ( depr_attr ) { - auto expr = static_cast(depr_attr->GetExpr().get()); + auto expr = static_cast(depr_attr->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); @@ -322,6 +343,14 @@ void ID::RemoveAttr(attr_tag a) attrs->RemoveAttr(a); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void ID::RemoveAttr(::attr_tag a) + { + RemoveAttr(static_cast(a)); + } +#pragma GCC diagnostic pop + void ID::SetOption() { if ( is_option ) @@ -339,8 +368,8 @@ void ID::SetOption() void ID::EvalFunc(IntrusivePtr ef, IntrusivePtr ev) { - auto arg1 = make_intrusive(val); - auto args = make_intrusive(); + auto arg1 = make_intrusive(val); + auto args = make_intrusive(); args->Append(std::move(arg1)); args->Append(std::move(ev)); auto ce = make_intrusive(std::move(ef), std::move(args)); @@ -655,3 +684,5 @@ std::vector ID::GetOptionHandlers() const v.push_back(element.second.get()); return v; } + +} diff --git a/src/ID.h b/src/ID.h index 5c0c5e84b7..1726f8c727 100644 --- a/src/ID.h +++ b/src/ID.h @@ -14,23 +14,39 @@ #include class Val; -class Expr; class Func; -class BroType; -class RecordType; -class TableType; -class VectorType; -class EnumType; -class Attributes; -typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class; -typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope; +namespace zeek { class Type; } +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; + +ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(TableType, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek); +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 }; + +namespace zeek::detail { + +class Attributes; +class Expr; + +enum init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; +enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; class ID final : public BroObj, public notifier::Modifiable { public: static inline const IntrusivePtr nil; ID(const char* name, IDScope arg_scope, bool arg_is_export); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::IDScope")]] + ID(const char* name, ::IDScope arg_scope, bool arg_is_export); +#pragma GCC diagnostic pop + ~ID() override; const char* Name() const { return name; } @@ -43,14 +59,14 @@ public: std::string ModuleName() const; - void SetType(IntrusivePtr t); + void SetType(IntrusivePtr t); [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* Type() { return type.get(); } + zeek::Type* Type() { return type.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] - const BroType* Type() const { return type.get(); } + const zeek::Type* Type() const { return type.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } template @@ -58,9 +74,9 @@ public: { return cast_intrusive(type); } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] - BroType* AsType() { return is_type ? GetType().get() : nullptr; } + zeek::Type* AsType() { return is_type ? GetType().get() : nullptr; } [[deprecated("Remove in v4.1. Use IsType() and GetType().")]] - const BroType* AsType() const { return is_type ? GetType().get() : nullptr; } + const zeek::Type* AsType() const { return is_type ? GetType().get() : nullptr; } bool IsType() const { return is_type; } @@ -72,6 +88,14 @@ public: void SetVal(IntrusivePtr v, init_class c); void SetVal(IntrusivePtr ev, init_class c); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]] + void SetVal(IntrusivePtr v, ::init_class c); + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]] + void SetVal(IntrusivePtr ev, ::init_class c); +#pragma GCC diagnostic pop + bool HasVal() const { return val != nullptr; } [[deprecated("Remove in v4.1. Use GetVal().")]] @@ -101,6 +125,11 @@ public: void SetAttrs(IntrusivePtr attr); void AddAttrs(IntrusivePtr attr); void RemoveAttr(attr_tag a); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag")]] + void RemoveAttr(::attr_tag a); +#pragma GCC diagnostic pop void UpdateValAttrs(); const IntrusivePtr& GetAttrs() const @@ -109,11 +138,14 @@ public: [[deprecated("Remove in 4.1. Use GetAttrs().")]] Attributes* Attrs() const { return attrs.get(); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" [[deprecated("Remove in 4.1. Use GetAttr().")]] - Attr* FindAttr(attr_tag t) const - { return GetAttr(t).get(); } + Attr* FindAttr(::attr_tag t) const + { return GetAttr(static_cast(t)).get(); } +#pragma GCC diagnostic pop - const IntrusivePtr& GetAttr(attr_tag t) const; + const IntrusivePtr& GetAttr(zeek::detail::attr_tag t) const; bool IsDeprecated() const; @@ -154,7 +186,7 @@ protected: IDScope scope; bool is_export; bool infer_return_type; - IntrusivePtr type; + IntrusivePtr type; bool is_const, is_enum_const, is_type, is_option; int offset; IntrusivePtr val; @@ -164,6 +196,10 @@ protected: }; +} + +using ID [[deprecated("Remove in v4.1. Use zeek::detail::ID instead.")]] = zeek::detail::ID; + namespace zeek::id { /** @@ -172,7 +208,7 @@ namespace zeek::id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const IntrusivePtr& find(std::string_view name); +const IntrusivePtr& find(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID @@ -180,7 +216,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). @@ -236,17 +272,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/Net.cc b/src/Net.cc index d7d6f59a14..1574202266 100644 --- a/src/Net.cc +++ b/src/Net.cc @@ -199,7 +199,7 @@ void net_init(const std::optional& interface, reporter->Error("trace_output_file not defined in bro.init"); } - init_ip_addr_anonymizers(); + zeek::detail::init_ip_addr_anonymizers(); sessions = new NetSessions(); @@ -409,8 +409,8 @@ void net_delete() delete sessions; - for ( int i = 0; i < NUM_ADDR_ANONYMIZATION_METHODS; ++i ) - delete ip_anonymizer[i]; + for ( int i = 0; i < zeek::detail::NUM_ADDR_ANONYMIZATION_METHODS; ++i ) + delete zeek::detail::ip_anonymizer[i]; } int _processing_suspended = 0; diff --git a/src/NetVar.cc b/src/NetVar.cc index 535350b4eb..27a8f98340 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -8,27 +8,27 @@ #include "Val.h" #include "ID.h" -RecordType* conn_id; -RecordType* endpoint; -RecordType* endpoint_stats; -RecordType* connection_type; -RecordType* fa_file_type; -RecordType* fa_metadata_type; -RecordType* icmp_conn; -RecordType* icmp_context; -RecordType* SYN_packet; -RecordType* pcap_packet; -RecordType* raw_pkt_hdr_type; -RecordType* l2_hdr_type; -RecordType* signature_state; -EnumType* transport_proto; -TableType* string_set; -TableType* string_array; -TableType* count_set; -VectorType* string_vec; -VectorType* index_vec; -VectorType* mime_matches; -RecordType* mime_match; +zeek::RecordType* conn_id; +zeek::RecordType* endpoint; +zeek::RecordType* endpoint_stats; +zeek::RecordType* connection_type; +zeek::RecordType* fa_file_type; +zeek::RecordType* fa_metadata_type; +zeek::RecordType* icmp_conn; +zeek::RecordType* icmp_context; +zeek::RecordType* SYN_packet; +zeek::RecordType* pcap_packet; +zeek::RecordType* raw_pkt_hdr_type; +zeek::RecordType* l2_hdr_type; +zeek::RecordType* signature_state; +zeek::EnumType* transport_proto; +zeek::TableType* string_set; +zeek::TableType* string_array; +zeek::TableType* count_set; +zeek::VectorType* string_vec; +zeek::VectorType* index_vec; +zeek::VectorType* mime_matches; +zeek::RecordType* mime_match; int watchdog_interval; @@ -56,7 +56,7 @@ int tcp_max_above_hole_without_any_acks; int tcp_excessive_data_without_further_acks; int tcp_max_old_segments; -RecordType* socks_address; +zeek::RecordType* socks_address; double non_analyzed_lifetime; double tcp_inactivity_timeout; @@ -86,32 +86,32 @@ double rpc_timeout; int mime_segment_length; int mime_segment_overlap_length; -RecordType* mime_header_rec; -TableType* mime_header_list; +zeek::RecordType* mime_header_rec; +zeek::TableType* mime_header_list; int http_entity_data_delivery_size; -RecordType* http_stats_rec; -RecordType* http_message_stat; +zeek::RecordType* http_stats_rec; +zeek::RecordType* http_message_stat; int truncate_http_URI; -RecordType* pm_mapping; -TableType* pm_mappings; -RecordType* pm_port_request; -RecordType* pm_callit_request; +zeek::RecordType* pm_mapping; +zeek::TableType* pm_mappings; +zeek::RecordType* pm_port_request; +zeek::RecordType* pm_callit_request; -RecordType* geo_location; +zeek::RecordType* geo_location; -RecordType* entropy_test_result; +zeek::RecordType* entropy_test_result; -RecordType* dns_msg; -RecordType* dns_answer; -RecordType* dns_soa; -RecordType* dns_edns_additional; -RecordType* dns_tsig_additional; -RecordType* dns_rrsig_rr; -RecordType* dns_dnskey_rr; -RecordType* dns_nsec3_rr; -RecordType* dns_ds_rr; +zeek::RecordType* dns_msg; +zeek::RecordType* dns_answer; +zeek::RecordType* dns_soa; +zeek::RecordType* dns_edns_additional; +zeek::RecordType* dns_tsig_additional; +zeek::RecordType* dns_rrsig_rr; +zeek::RecordType* dns_dnskey_rr; +zeek::RecordType* dns_nsec3_rr; +zeek::RecordType* dns_ds_rr; TableVal* dns_skip_auth; TableVal* dns_skip_addl; int dns_skip_all_auth; @@ -134,7 +134,7 @@ TableVal* preserve_orig_addr; TableVal* preserve_resp_addr; TableVal* preserve_other_addr; -RecordType* rotate_info; +zeek::RecordType* rotate_info; StringVal* log_rotate_base_time; StringVal* peer_description; @@ -153,8 +153,8 @@ int packet_filter_default; int sig_max_group_size; -TableType* irc_join_list; -RecordType* irc_join_info; +zeek::TableType* irc_join_list; +zeek::RecordType* irc_join_info; int dpd_reassemble_first_packets; int dpd_buffer_size; @@ -172,12 +172,12 @@ StringVal* trace_output_file; int record_all_packets; -RecordType* script_id; -TableType* id_table; -RecordType* record_field; -TableType* record_field_table; -RecordType* call_argument; -VectorType* call_argument_vector; +zeek::RecordType* script_id; +zeek::TableType* id_table; +zeek::RecordType* record_field; +zeek::TableType* record_field_table; +zeek::RecordType* call_argument; +zeek::VectorType* call_argument_vector; StringVal* cmd_line_bpf_filter; diff --git a/src/NetVar.h b/src/NetVar.h index ac616d03a9..86116228af 100644 --- a/src/NetVar.h +++ b/src/NetVar.h @@ -7,47 +7,47 @@ #include "Stats.h" [[deprecated("Remove in v4.1. Use zeek::id::conn_id.")]] -extern RecordType* conn_id; +extern zeek::RecordType* conn_id; [[deprecated("Remove in v4.1. Use zeek::id::endpoint.")]] -extern RecordType* endpoint; +extern zeek::RecordType* endpoint; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* endpoint_stats; +extern zeek::RecordType* endpoint_stats; [[deprecated("Remove in v4.1. Use zeek::id::connection.")]] -extern RecordType* connection_type; +extern zeek::RecordType* connection_type; [[deprecated("Remove in v4.1. Use zeek::id::fa_file.")]] -extern RecordType* fa_file_type; +extern zeek::RecordType* fa_file_type; [[deprecated("Remove in v4.1. Use zeek::id::fa_metadata.")]] -extern RecordType* fa_metadata_type; +extern zeek::RecordType* fa_metadata_type; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* icmp_conn; +extern zeek::RecordType* icmp_conn; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* icmp_context; +extern zeek::RecordType* icmp_context; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* signature_state; +extern zeek::RecordType* signature_state; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* SYN_packet; +extern zeek::RecordType* SYN_packet; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* pcap_packet; +extern zeek::RecordType* pcap_packet; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* raw_pkt_hdr_type; +extern zeek::RecordType* raw_pkt_hdr_type; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* l2_hdr_type; +extern zeek::RecordType* l2_hdr_type; [[deprecated("Remove in v4.1. Use zeek::id::transport_proto.")]] -extern EnumType* transport_proto; +extern zeek::EnumType* transport_proto; [[deprecated("Remove in v4.1. Use zeek::id::string_set.")]] -extern TableType* string_set; +extern zeek::TableType* string_set; [[deprecated("Remove in v4.1. Use zeek::id::string_array.")]] -extern TableType* string_array; +extern zeek::TableType* string_array; [[deprecated("Remove in v4.1. Use zeek::id::count_set.")]] -extern TableType* count_set; +extern zeek::TableType* count_set; [[deprecated("Remove in v4.1. Use zeek::id::string_vec.")]] -extern VectorType* string_vec; +extern zeek::VectorType* string_vec; [[deprecated("Remove in v4.1. Use zeek::id::index_vec.")]] -extern VectorType* index_vec; +extern zeek::VectorType* index_vec; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern VectorType* mime_matches; +extern zeek::VectorType* mime_matches; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* mime_match; +extern zeek::RecordType* mime_match; extern int watchdog_interval; @@ -76,7 +76,7 @@ extern int tcp_excessive_data_without_further_acks; extern int tcp_max_old_segments; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* socks_address; +extern zeek::RecordType* socks_address; extern double non_analyzed_lifetime; extern double tcp_inactivity_timeout; @@ -114,50 +114,50 @@ extern double rpc_timeout; extern int mime_segment_length; extern int mime_segment_overlap_length; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* mime_header_rec; +extern zeek::RecordType* mime_header_rec; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern TableType* mime_header_list; +extern zeek::TableType* mime_header_list; extern int http_entity_data_delivery_size; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* http_stats_rec; +extern zeek::RecordType* http_stats_rec; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* http_message_stat; +extern zeek::RecordType* http_message_stat; extern int truncate_http_URI; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* pm_mapping; +extern zeek::RecordType* pm_mapping; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern TableType* pm_mappings; +extern zeek::TableType* pm_mappings; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* pm_port_request; +extern zeek::RecordType* pm_port_request; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* pm_callit_request; +extern zeek::RecordType* pm_callit_request; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* geo_location; +extern zeek::RecordType* geo_location; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* entropy_test_result; +extern zeek::RecordType* entropy_test_result; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_msg; +extern zeek::RecordType* dns_msg; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_answer; +extern zeek::RecordType* dns_answer; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_soa; +extern zeek::RecordType* dns_soa; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_edns_additional; +extern zeek::RecordType* dns_edns_additional; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_tsig_additional; +extern zeek::RecordType* dns_tsig_additional; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_rrsig_rr; +extern zeek::RecordType* dns_rrsig_rr; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_dnskey_rr; +extern zeek::RecordType* dns_dnskey_rr; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_nsec3_rr; +extern zeek::RecordType* dns_nsec3_rr; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* dns_ds_rr; +extern zeek::RecordType* dns_ds_rr; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern TableVal* dns_skip_auth; [[deprecated("Remove in v4.1. Perform your own lookup.")]] @@ -187,7 +187,7 @@ extern TableVal* preserve_other_addr; extern double connection_status_update_interval; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* rotate_info; +extern zeek::RecordType* rotate_info; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* log_rotate_base_time; @@ -212,9 +212,9 @@ extern int packet_filter_default; extern int sig_max_group_size; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern TableType* irc_join_list; +extern zeek::TableType* irc_join_list; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* irc_join_info; +extern zeek::RecordType* irc_join_info; extern int dpd_reassemble_first_packets; extern int dpd_buffer_size; @@ -235,17 +235,17 @@ extern StringVal* trace_output_file; extern int record_all_packets; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* script_id; +extern zeek::RecordType* script_id; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern TableType* id_table; +extern zeek::TableType* id_table; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* record_field; +extern zeek::RecordType* record_field; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern TableType* record_field_table; +extern zeek::TableType* record_field_table; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern RecordType* call_argument; +extern zeek::RecordType* call_argument; [[deprecated("Remove in v4.1. Perform your own lookup.")]] -extern VectorType* call_argument_vector; +extern zeek::VectorType* call_argument_vector; [[deprecated("Remove in v4.1. Perform your own lookup.")]] extern StringVal* cmd_line_bpf_filter; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 351d00fa19..f1d5c50fca 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..848e6bed76 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/Pipe.cc b/src/Pipe.cc index 5a0916a3dd..93ceac50ea 100644 --- a/src/Pipe.cc +++ b/src/Pipe.cc @@ -7,7 +7,7 @@ #include #include -using namespace bro; +using namespace zeek::detail; static void pipe_fail(int eno) { diff --git a/src/Pipe.h b/src/Pipe.h index e310c83edc..16d2bfcec2 100644 --- a/src/Pipe.h +++ b/src/Pipe.h @@ -2,7 +2,7 @@ #pragma once -namespace bro { +namespace zeek::detail { class Pipe { public: @@ -136,4 +136,4 @@ private: bool swapped = false; }; -} // namespace bro +} // namespace zeek::detail 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/Reporter.cc b/src/Reporter.cc index a692c957ce..e881706834 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -143,7 +143,7 @@ void Reporter::FatalErrorWithCore(const char* fmt, ...) abort(); } -void Reporter::ExprRuntimeError(const Expr* expr, const char* fmt, ...) +void Reporter::ExprRuntimeError(const zeek::detail::Expr* expr, const char* fmt, ...) { ++errors; diff --git a/src/Reporter.h b/src/Reporter.h index 337b3664ea..4c35009c82 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -36,7 +36,8 @@ protected: }; class IPAddr; -class Expr; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); #define FMT_ATTR __attribute__((format(printf, 2, 3))) // sic! 1st is "this" I guess. @@ -77,7 +78,7 @@ public: // Report a runtime error in evaluating a Bro script expression. This // function will not return but raise an InterpreterException. - [[noreturn]] void ExprRuntimeError(const Expr* expr, const char* fmt, ...) __attribute__((format(printf, 3, 4))); + [[noreturn]] void ExprRuntimeError(const zeek::detail::Expr* expr, const char* fmt, ...) __attribute__((format(printf, 3, 4))); // Report a runtime error in evaluating a Bro script expression. This // function will not return but raise an InterpreterException. 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/RuleCondition.h b/src/RuleCondition.h index d8f0b684b2..6919738d18 100644 --- a/src/RuleCondition.h +++ b/src/RuleCondition.h @@ -2,11 +2,13 @@ #include // for u_char #include // for u_char +#include "util.h" -class ID; class Rule; class RuleEndpointState; +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); + // Base class for all rule conditions except patterns and "header". class RuleCondition { public: @@ -111,7 +113,5 @@ public: void PrintDebug() override; private: - ID* id; + zeek::detail::ID* id; }; - - 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 657a27170e..fe0695d014 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -15,8 +15,8 @@ typedef PList scope_list; static scope_list scopes; static Scope* top_scope; -Scope::Scope(IntrusivePtr id, - std::unique_ptr>> al) +Scope::Scope(IntrusivePtr id, + std::unique_ptr>> al) : scope_id(std::move(id)), attrs(std::move(al)) { return_type = nullptr; @@ -25,27 +25,27 @@ 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(); } } -const IntrusivePtr& Scope::Find(std::string_view name) const +const IntrusivePtr& Scope::Find(std::string_view name) const { auto entry = local.find(name); if ( entry != local.end() ) return entry->second; - return ID::nil; + return zeek::detail::ID::nil; } -IntrusivePtr Scope::Remove(std::string_view name) +IntrusivePtr Scope::Remove(std::string_view name) { auto entry = local.find(name); @@ -59,12 +59,12 @@ IntrusivePtr Scope::Remove(std::string_view name) return nullptr; } -IntrusivePtr Scope::GenerateTemporary(const char* name) +IntrusivePtr Scope::GenerateTemporary(const char* name) { - return make_intrusive(name, SCOPE_FUNCTION, false); + return make_intrusive(name, zeek::detail::SCOPE_FUNCTION, false); } -std::vector> Scope::GetInits() +std::vector> Scope::GetInits() { auto rval = std::move(inits); inits = {}; @@ -100,7 +100,7 @@ void Scope::Describe(ODesc* d) const for ( const auto& entry : local ) { - ID* id = entry.second.get(); + zeek::detail::ID* id = entry.second.get(); id->Describe(d); d->NL(); } @@ -110,7 +110,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const { for ( const auto& entry : local ) { - ID* id = entry.second.get(); + zeek::detail::ID* id = entry.second.get(); TraversalCode tc = id->Traverse(cb); HANDLE_TC_STMT_PRE(tc); } @@ -119,9 +119,9 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const } -const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, - bool no_global, bool same_module_only, - bool check_export) +const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, + bool no_global, bool same_module_only, + bool check_export) { std::string fullname = make_full_var_name(curr_module, name); @@ -150,30 +150,30 @@ const IntrusivePtr& lookup_ID(const char* name, const char* curr_module, return global_scope()->Find(globalname); } - return ID::nil; + return zeek::detail::ID::nil; } -IntrusivePtr install_ID(const char* name, const char* module_name, +IntrusivePtr install_ID(const char* name, const char* module_name, bool is_global, bool is_export) { if ( scopes.empty() && ! is_global ) reporter->InternalError("local identifier in global scope"); - IDScope scope; + zeek::detail::IDScope scope; if ( is_export || ! module_name || (is_global && normalized_module_name(module_name) == GLOBAL_MODULE_NAME) ) - scope = SCOPE_GLOBAL; + scope = zeek::detail::SCOPE_GLOBAL; else if ( is_global ) - scope = SCOPE_MODULE; + scope = zeek::detail::SCOPE_MODULE; else - scope = SCOPE_FUNCTION; + scope = zeek::detail::SCOPE_FUNCTION; std::string full_name = make_full_var_name(module_name, name); - auto id = make_intrusive(full_name.data(), scope, is_export); + auto id = make_intrusive(full_name.data(), scope, is_export); - if ( SCOPE_FUNCTION != scope ) + if ( zeek::detail::SCOPE_FUNCTION != scope ) global_scope()->Insert(std::move(full_name), id); else { @@ -189,8 +189,8 @@ void push_existing_scope(Scope* scope) scopes.push_back(scope); } -void push_scope(IntrusivePtr id, - std::unique_ptr>> attrs) +void push_scope(IntrusivePtr id, + std::unique_ptr>> attrs) { top_scope = new Scope(std::move(id), std::move(attrs)); scopes.push_back(top_scope); diff --git a/src/Scope.h b/src/Scope.h index 146c5c051e..0d09b9033c 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -13,53 +13,55 @@ #include "TraverseTypes.h" template class IntrusivePtr; -class ID; -class BroType; class ListVal; +namespace zeek { class Type; } +using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); + class Scope : public BroObj { public: - explicit Scope(IntrusivePtr id, - std::unique_ptr>> al); + explicit Scope(IntrusivePtr id, + std::unique_ptr>> al); - const IntrusivePtr& Find(std::string_view name) const; + const IntrusivePtr& Find(std::string_view name) const; template [[deprecated("Remove in v4.1. Use Find().")]] - ID* Lookup(N&& name) const + zeek::detail::ID* Lookup(N&& name) const { return Find(name).get(); } template void Insert(N&& name, I&& id) { local[std::forward(name)] = std::forward(id); } - IntrusivePtr Remove(std::string_view name); + IntrusivePtr Remove(std::string_view name); [[deprecated("Remove in v4.1. Use GetID().")]] - ID* ScopeID() const { return scope_id.get(); } + zeek::detail::ID* ScopeID() const { return scope_id.get(); } - const IntrusivePtr& GetID() const + const IntrusivePtr& GetID() const { return scope_id; } - const std::unique_ptr>>& Attrs() const + const std::unique_ptr>>& Attrs() const { return attrs; } [[deprecated("Remove in v4.1. Use GetReturnTrype().")]] - BroType* ReturnType() const { return return_type.get(); } + zeek::Type* ReturnType() const { return return_type.get(); } - const IntrusivePtr& GetReturnType() const + const IntrusivePtr& GetReturnType() const { return return_type; } size_t Length() const { return local.size(); } const auto& Vars() { return local; } - IntrusivePtr GenerateTemporary(const char* name); + IntrusivePtr GenerateTemporary(const char* name); // Returns the list of variables needing initialization, and // removes it from this Scope. - std::vector> GetInits(); + std::vector> GetInits(); // Adds a variable to the list. - void AddInit(IntrusivePtr id) + void AddInit(IntrusivePtr id) { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; @@ -67,27 +69,27 @@ public: TraversalCode Traverse(TraversalCallback* cb) const; protected: - IntrusivePtr scope_id; - std::unique_ptr>> attrs; - IntrusivePtr return_type; - std::map, std::less<>> local; - std::vector> inits; + IntrusivePtr scope_id; + std::unique_ptr>> attrs; + IntrusivePtr return_type; + std::map, std::less<>> local; + std::vector> inits; }; extern bool in_debug; // If no_global is true, don't search in the default "global" namespace. -extern const IntrusivePtr& lookup_ID(const char* name, const char* module, - bool no_global = false, - bool same_module_only = false, - bool check_export = true); +extern const IntrusivePtr& lookup_ID(const char* name, const char* module, + bool no_global = false, + bool same_module_only = false, + bool check_export = true); -extern IntrusivePtr install_ID(const char* name, const char* module_name, - bool is_global, bool is_export); +extern IntrusivePtr install_ID(const char* name, const char* module_name, + bool is_global, bool is_export); -extern void push_scope(IntrusivePtr id, - std::unique_ptr>> attrs); +extern void push_scope(IntrusivePtr id, + std::unique_ptr>> attrs); extern void push_existing_scope(Scope* scope); // Returns the one popped off. diff --git a/src/Sessions.cc b/src/Sessions.cc index 715d5e97ab..c1981b3628 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -923,10 +923,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 39f645bf13..759f95972b 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -191,7 +191,7 @@ void ProfileLogger::Log() dstats.requests, dstats.successful, dstats.failed, dstats.pending, dstats.cached_hosts, dstats.cached_addresses)); - trigger::Manager::Stats tstats; + zeek::detail::trigger::Manager::Stats tstats; trigger_mgr->GetStats(&tstats); file->Write(fmt("%.06f Triggers: total=%lu pending=%lu\n", network_time, tstats.total, tstats.pending)); @@ -252,7 +252,7 @@ void ProfileLogger::Log() for ( const auto& global : globals ) { - ID* id = global.second.get(); + auto& id = global.second; // We don't show/count internal globals as they are always // contained in some other global user-visible container. @@ -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/Stmt.cc b/src/Stmt.cc index e30233ccf3..b0ef9c4ab7 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -2,6 +2,8 @@ #include "zeek-config.h" +#include "Stmt.h" + #include "CompHash.h" #include "Expr.h" #include "Event.h" @@ -9,7 +11,6 @@ #include "File.h" #include "Reporter.h" #include "NetVar.h" -#include "Stmt.h" #include "Scope.h" #include "Var.h" #include "Desc.h" @@ -34,6 +35,8 @@ const char* stmt_name(BroStmtTag t) return stmt_names[int(t)]; } +namespace zeek::detail { + Stmt::Stmt(BroStmtTag arg_tag) { tag = arg_tag; @@ -1833,3 +1836,5 @@ TraversalCode WhenStmt::Traverse(TraversalCallback* cb) const tc = cb->PostStmt(this); HANDLE_TC_STMT_POST(tc); } + +} diff --git a/src/Stmt.h b/src/Stmt.h index 0cc4e8ae43..b39872aee8 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -13,12 +13,15 @@ #include "TraverseTypes.h" -class StmtList; class CompositeHash; +class Frame; + +namespace zeek::detail { + +class StmtList; +class ForStmt; class EventExpr; class ListExpr; -class ForStmt; -class Frame; class Stmt : public BroObj { public: @@ -447,3 +450,27 @@ protected: IntrusivePtr timeout; bool is_return; }; + +} + +using Stmt [[deprecated("Remove in v4.1. Use zeek::detail::Stmt instead.")]] = zeek::detail::Stmt; +using ExprListStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprListStmt instead.")]] = zeek::detail::ExprListStmt; +using PrintStmt [[deprecated("Remove in v4.1. Use zeek::detail::PrintStmt instead.")]] = zeek::detail::PrintStmt; +using ExprStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprStmt instead.")]] = zeek::detail::ExprStmt; +using IfStmt [[deprecated("Remove in v4.1. Use zeek::detail::IfStmt instead.")]] = zeek::detail::IfStmt; +using Case [[deprecated("Remove in v4.1. Use zeek::detail::Case instead.")]] = zeek::detail::Case; +using SwitchStmt [[deprecated("Remove in v4.1. Use zeek::detail::SwitchStmt instead.")]] = zeek::detail::SwitchStmt; +using AddStmt [[deprecated("Remove in v4.1. Use zeek::detail::AddStmt instead.")]] = zeek::detail::AddStmt; +using DelStmt [[deprecated("Remove in v4.1. Use zeek::detail::DelStmt instead.")]] = zeek::detail::DelStmt; +using EventStmt [[deprecated("Remove in v4.1. Use zeek::detail::EventStmt instead.")]] = zeek::detail::EventStmt; +using WhileStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhileStmt instead.")]] = zeek::detail::WhileStmt; +using ForStmt [[deprecated("Remove in v4.1. Use zeek::detail::ForStmt instead.")]] = zeek::detail::ForStmt; +using NextStmt [[deprecated("Remove in v4.1. Use zeek::detail::NextStmt instead.")]] = zeek::detail::NextStmt; +using BreakStmt [[deprecated("Remove in v4.1. Use zeek::detail::BreakStmt instead.")]] = zeek::detail::BreakStmt; +using FallthroughStmt [[deprecated("Remove in v4.1. Use zeek::detail::FallthroughStmt instead.")]] = zeek::detail::FallthroughStmt; +using ReturnStmt [[deprecated("Remove in v4.1. Use zeek::detail::ReturnStmt instead.")]] = zeek::detail::ReturnStmt; +using StmtList [[deprecated("Remove in v4.1. Use zeek::detail::StmtList instead.")]] = zeek::detail::StmtList; +using EventBodyList [[deprecated("Remove in v4.1. Use zeek::detail::EventBodyList instead.")]] = zeek::detail::EventBodyList; +using InitStmt [[deprecated("Remove in v4.1. Use zeek::detail::InitStmt instead.")]] = zeek::detail::InitStmt; +using NullStmt [[deprecated("Remove in v4.1. Use zeek::detail::NullStmt instead.")]] = zeek::detail::NullStmt; +using WhenStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhenStmt instead.")]] = zeek::detail::WhenStmt; 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..763d14ef7a 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; +ZEEK_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/Traverse.h b/src/Traverse.h index 2e528905e0..2d3e13bfee 100644 --- a/src/Traverse.h +++ b/src/Traverse.h @@ -6,9 +6,10 @@ class Func; class Scope; -class Stmt; -class Expr; -class ID; + +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); class TraversalCallback { public: @@ -18,20 +19,20 @@ public: virtual TraversalCode PreFunction(const Func*) { return TC_CONTINUE; } virtual TraversalCode PostFunction(const Func*) { return TC_CONTINUE; } - virtual TraversalCode PreStmt(const Stmt*) { return TC_CONTINUE; } - virtual TraversalCode PostStmt(const Stmt*) { return TC_CONTINUE; } + virtual TraversalCode PreStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } + virtual TraversalCode PostStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; } - virtual TraversalCode PreExpr(const Expr*) { return TC_CONTINUE; } - virtual TraversalCode PostExpr(const Expr*) { return TC_CONTINUE; } + virtual TraversalCode PreExpr(const zeek::detail::Expr*) { return TC_CONTINUE; } + virtual TraversalCode PostExpr(const zeek::detail::Expr*) { return TC_CONTINUE; } - virtual TraversalCode PreID(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostID(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreID(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostID(const zeek::detail::ID*) { return TC_CONTINUE; } - virtual TraversalCode PreTypedef(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostTypedef(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreTypedef(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostTypedef(const zeek::detail::ID*) { return TC_CONTINUE; } - virtual TraversalCode PreDecl(const ID*) { return TC_CONTINUE; } - virtual TraversalCode PostDecl(const ID*) { return TC_CONTINUE; } + virtual TraversalCode PreDecl(const zeek::detail::ID*) { return TC_CONTINUE; } + virtual TraversalCode PostDecl(const zeek::detail::ID*) { return TC_CONTINUE; } Scope* current_scope; }; diff --git a/src/Trigger.cc b/src/Trigger.cc index 18fd850b64..084404de85 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -15,12 +15,13 @@ #include "DebugLogger.h" #include "iosource/Manager.h" -using namespace trigger; +using namespace zeek::detail; +using namespace zeek::detail::trigger; // Callback class to traverse an expression, registering all relevant IDs and // Vals for change notifications. -namespace trigger { +namespace zeek::detail::trigger { class TriggerTraversalCallback : public TraversalCallback { public: @@ -30,15 +31,13 @@ public: ~TriggerTraversalCallback() { Unref(trigger); } - virtual TraversalCode PreExpr(const Expr*); + virtual TraversalCode PreExpr(const zeek::detail::Expr*) override; private: Trigger* trigger; }; -} - -TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) +TraversalCode zeek::detail::trigger::TriggerTraversalCallback::PreExpr(const zeek::detail::Expr* expr) { // We catch all expressions here which in some way reference global // state. @@ -46,7 +45,7 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) switch ( expr->Tag() ) { case EXPR_NAME: { - const NameExpr* e = static_cast(expr); + const auto* e = static_cast(expr); if ( e->Id()->IsGlobal() ) trigger->Register(e->Id()); @@ -59,7 +58,7 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) case EXPR_INDEX: { - const IndexExpr* e = static_cast(expr); + const auto* e = static_cast(expr); BroObj::SuppressErrors no_errors; try @@ -83,8 +82,6 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr) return TC_CONTINUE; } -namespace trigger { - class TriggerTimer final : public Timer { public: TriggerTimer(double arg_timeout, Trigger* arg_trigger) @@ -120,10 +117,9 @@ protected: double time; }; -} - -Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts, - Expr* arg_timeout, Frame* arg_frame, +Trigger::Trigger(zeek::detail::Expr* arg_cond, zeek::detail::Stmt* arg_body, + zeek::detail::Stmt* arg_timeout_stmts, + zeek::detail::Expr* arg_timeout, Frame* arg_frame, bool arg_is_return, const Location* arg_location) { cond = arg_cond; @@ -389,7 +385,7 @@ void Trigger::Timeout() Unref(this); } -void Trigger::Register(ID* id) +void Trigger::Register(zeek::detail::ID* id) { assert(! disabled); notifier::registry.Register(id, this); @@ -440,7 +436,7 @@ void Trigger::Attach(Trigger *trigger) Hold(); } -bool Trigger::Cache(const CallExpr* expr, Val* v) +bool Trigger::Cache(const zeek::detail::CallExpr* expr, Val* v) { if ( disabled || ! v ) return false; @@ -463,7 +459,7 @@ bool Trigger::Cache(const CallExpr* expr, Val* v) } -Val* Trigger::Lookup(const CallExpr* expr) +Val* Trigger::Lookup(const zeek::detail::CallExpr* expr) { assert(! disabled); @@ -553,3 +549,5 @@ void Manager::GetStats(Stats* stats) stats->total = total_triggers; stats->pending = pending->size(); } + +} diff --git a/src/Trigger.h b/src/Trigger.h index c26e6e7b05..368238208c 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -1,22 +1,25 @@ #pragma once -#include "Obj.h" -#include "Notifier.h" -#include "iosource/IOSource.h" - #include #include #include -class CallExpr; -class Expr; -class Stmt; +#include "Obj.h" +#include "Notifier.h" +#include "iosource/IOSource.h" +#include "util.h" + class Frame; class Val; -class ID; class ODesc; -namespace trigger { +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); + +namespace zeek::detail::trigger { + // Triggers are the heart of "when" statements: expressions that when // they become true execute a body of statements. @@ -29,7 +32,7 @@ public: // instantiation. Note that if the condition is already true, the // statements are executed immediately and the object is deleted // right away. - Trigger(Expr* cond, Stmt* body, Stmt* timeout_stmts, Expr* timeout, + Trigger(zeek::detail::Expr* cond, zeek::detail::Stmt* body, zeek::detail::Stmt* timeout_stmts, zeek::detail::Expr* timeout, Frame* f, bool is_return, const Location* loc); ~Trigger() override; @@ -60,8 +63,8 @@ public: // Cache for return values of delayed function calls. Returns whether // the trigger is queued for later evaluation -- it may not be queued // if the Val is null or it's disabled. - bool Cache(const CallExpr* expr, Val* val); - Val* Lookup(const CallExpr*); + bool Cache(const zeek::detail::CallExpr* expr, Val* val); + Val* Lookup(const zeek::detail::CallExpr*); // Disable this trigger completely. Needed because Unref'ing the trigger // may not immediately delete it as other references may still exist. @@ -87,14 +90,14 @@ private: friend class TriggerTimer; void Init(); - void Register(ID* id); + void Register(zeek::detail::ID* id); void Register(Val* val); void UnregisterAll(); - Expr* cond; - Stmt* body; - Stmt* timeout_stmts; - Expr* timeout; + zeek::detail::Expr* cond; + zeek::detail::Stmt* body; + zeek::detail::Stmt* timeout_stmts; + zeek::detail::Expr* timeout; double timeout_value; Frame* frame; bool is_return; @@ -108,7 +111,7 @@ private: std::vector> objs; - using ValCache = std::map; + using ValCache = std::map; ValCache cache; }; @@ -140,4 +143,9 @@ private: } -extern trigger::Manager* trigger_mgr; +namespace trigger { + using Trigger [[deprecated("Remove in v4.1. Use zeek::detail::trigger::Trigger instead")]] = zeek::detail::trigger::Trigger; + using Manager [[deprecated("Remove in v4.1. Use zeek::detail::trigger::Manager instead")]] = zeek::detail::trigger::Manager; +} + +extern zeek::detail::trigger::Manager* trigger_mgr; 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 382da6cb8c..4c5e1ad45c 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -22,10 +22,12 @@ using namespace std; -BroType::TypeAliasMap BroType::type_aliases; +namespace zeek { + +Type::TypeAliasMap Type::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,14 +64,14 @@ const char* type_name(TypeTag t) return type_names[int(t)]; } -BroType::BroType(TypeTag t, bool arg_base_type) +Type::Type(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) { } -IntrusivePtr BroType::ShallowClone() +IntrusivePtr Type::ShallowClone() { switch ( tag ) { case TYPE_VOID: @@ -87,44 +89,44 @@ IntrusivePtr BroType::ShallowClone() case TYPE_ADDR: case TYPE_SUBNET: case TYPE_ANY: - return make_intrusive(tag, base_type); + return make_intrusive(tag, base_type); default: - reporter->InternalError("cloning illegal base BroType"); + reporter->InternalError("cloning illegal base Type"); } return nullptr; } -int BroType::MatchesIndex(ListExpr* const index) const +int Type::MatchesIndex(zeek::detail::ListExpr* const index) const { if ( Tag() == TYPE_STRING ) { 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; } return DOES_NOT_MATCH_INDEX; } -const IntrusivePtr& BroType::Yield() const +const IntrusivePtr& Type::Yield() const { - return BroType::nil; + return Type::nil; } -bool BroType::HasField(const char* /* field */) const +bool Type::HasField(const char* /* field */) const { return false; } -BroType* BroType::FieldType(const char* /* field */) const +Type* Type::FieldType(const char* /* field */) const { return nullptr; } -void BroType::Describe(ODesc* d) const +void Type::Describe(ODesc* d) const { if ( d->IsBinary() ) d->Add(int(Tag())); @@ -138,22 +140,22 @@ void BroType::Describe(ODesc* d) const } } -void BroType::DescribeReST(ODesc* d, bool roles_only) const +void Type::DescribeReST(ODesc* d, bool roles_only) const { d->Add(fmt(":zeek:type:`%s`", type_name(Tag()))); } -void BroType::SetError() +void Type::SetError() { tag = TYPE_ERROR; } -unsigned int BroType::MemoryAllocation() const +unsigned int Type::MemoryAllocation() const { return padded_sizeof(*this); } -bool TypeList::AllMatch(const BroType* t, bool is_init) const +bool TypeList::AllMatch(const Type* t, bool is_init) const { for ( const auto& type : types ) if ( ! same_type(type, t, is_init) ) @@ -161,7 +163,7 @@ bool TypeList::AllMatch(const BroType* t, bool is_init) const return true; } -void TypeList::Append(IntrusivePtr t) +void TypeList::Append(IntrusivePtr t) { if ( pure_type && ! same_type(t, pure_type) ) reporter->InternalError("pure type-list violation"); @@ -169,7 +171,7 @@ void TypeList::Append(IntrusivePtr t) types.emplace_back(std::move(t)); } -void TypeList::AppendEvenIfNotPure(IntrusivePtr t) +void TypeList::AppendEvenIfNotPure(IntrusivePtr t) { if ( pure_type && ! same_type(t, pure_type) ) pure_type = nullptr; @@ -213,14 +215,14 @@ unsigned int TypeList::MemoryAllocation() const size += pad_size(types.capacity() * sizeof(decltype(types)::value_type)); - return BroType::MemoryAllocation() - + padded_sizeof(*this) - padded_sizeof(BroType) + return Type::MemoryAllocation() + + padded_sizeof(*this) - padded_sizeof(Type) + size; } IndexType::~IndexType() = default; -int IndexType::MatchesIndex(ListExpr* const index) const +int IndexType::MatchesIndex(zeek::detail::ListExpr* const index) const { // If we have a type indexed by subnets, addresses are ok. const auto& types = indices->Types(); @@ -236,7 +238,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const void IndexType::Describe(ODesc* d) const { - BroType::Describe(d); + Type::Describe(d); if ( ! d->IsBinary() ) d->Add("["); @@ -315,7 +317,7 @@ bool IndexType::IsSubNetIndex() const return false; } -TableType::TableType(IntrusivePtr ind, IntrusivePtr yield) +TableType::TableType(IntrusivePtr ind, IntrusivePtr yield) : IndexType(TYPE_TABLE, std::move(ind), std::move(yield)) { if ( ! indices ) @@ -342,7 +344,7 @@ TableType::TableType(IntrusivePtr ind, IntrusivePtr yield) } } -IntrusivePtr TableType::ShallowClone() +IntrusivePtr TableType::ShallowClone() { return make_intrusive(indices, yield_type); } @@ -353,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const return indices->Types().empty(); } -SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements) +SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements) : TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) { if ( elements ) @@ -376,7 +378,7 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements else if ( tl.size() == 1 ) { - IntrusivePtr ft{NewRef{}, flatten_type(tl[0].get())}; + IntrusivePtr ft{NewRef{}, flatten_type(tl[0].get())}; indices = make_intrusive(ft); indices->Append(std::move(ft)); } @@ -401,7 +403,7 @@ SetType::SetType(IntrusivePtr ind, IntrusivePtr arg_elements } } -IntrusivePtr SetType::ShallowClone() +IntrusivePtr SetType::ShallowClone() { return make_intrusive(indices, elements); } @@ -409,8 +411,8 @@ IntrusivePtr SetType::ShallowClone() SetType::~SetType() = default; FuncType::FuncType(IntrusivePtr arg_args, - IntrusivePtr arg_yield, function_flavor arg_flavor) - : BroType(TYPE_FUNC), args(std::move(arg_args)), + IntrusivePtr arg_yield, FunctionFlavor arg_flavor) + : Type(TYPE_FUNC), args(std::move(arg_args)), arg_types(make_intrusive()), yield(std::move(arg_yield)) { flavor = arg_flavor; @@ -422,7 +424,7 @@ FuncType::FuncType(IntrusivePtr arg_args, { const TypeDecl* td = args->FieldDecl(i); - if ( td->attrs && td->attrs->Find(ATTR_DEFAULT) ) + if ( td->attrs && td->attrs->Find(zeek::detail::ATTR_DEFAULT) ) has_default_arg = true; else if ( has_default_arg ) @@ -439,7 +441,7 @@ FuncType::FuncType(IntrusivePtr arg_args, prototypes.emplace_back(Prototype{false, args, std::move(offsets)}); } -IntrusivePtr FuncType::ShallowClone() +IntrusivePtr FuncType::ShallowClone() { auto f = make_intrusive(); f->args = args; @@ -471,7 +473,7 @@ string FuncType::FlavorString() const FuncType::~FuncType() = default; -int FuncType::MatchesIndex(ListExpr* const index) const +int FuncType::MatchesIndex(zeek::detail::ListExpr* const index) const { return check_and_promote_args(index, args.get()) ? MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; @@ -479,7 +481,7 @@ int FuncType::MatchesIndex(ListExpr* const index) const bool FuncType::CheckArgs(const type_list* args, bool is_init) const { - std::vector> as; + std::vector> as; as.reserve(args->length()); for ( auto a : *args ) @@ -488,7 +490,7 @@ bool FuncType::CheckArgs(const type_list* args, bool is_init) const return CheckArgs(as, is_init); } -bool FuncType::CheckArgs(const std::vector>& args, +bool FuncType::CheckArgs(const std::vector>& args, bool is_init) const { const auto& my_args = arg_types->Types(); @@ -607,8 +609,8 @@ std::optional FuncType::FindPrototype(const RecordType& arg return {}; } -TypeDecl::TypeDecl(const char* i, IntrusivePtr t, - IntrusivePtr arg_attrs) +TypeDecl::TypeDecl(const char* i, IntrusivePtr t, + IntrusivePtr arg_attrs) : type(std::move(t)), attrs(std::move(arg_attrs)), id(i) @@ -648,7 +650,7 @@ void TypeDecl::DescribeReST(ODesc* d, bool roles_only) const } } -RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD) +RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD) { types = arg_types; num_fields = types ? types->length() : 0; @@ -656,7 +658,7 @@ RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD) // in this case the clone is actually not so shallow, since // it gets modified by everyone. -IntrusivePtr RecordType::ShallowClone() +IntrusivePtr RecordType::ShallowClone() { auto pass = new type_decl_list(); for ( const auto& type : *types ) @@ -687,7 +689,7 @@ IntrusivePtr RecordType::FieldDefault(int field) const if ( ! td->attrs ) return nullptr; - const auto& def_attr = td->attrs->Find(ATTR_DEFAULT); + const auto& def_attr = td->attrs->Find(zeek::detail::ATTR_DEFAULT); return def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr; } @@ -758,7 +760,7 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const d->PopType(this); } -static string container_type_name(const BroType* ft) +static string container_type_name(const Type* ft) { string s; if ( ft->Tag() == TYPE_RECORD ) @@ -807,7 +809,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const if ( rv ) fv = rv->GetField(i); - bool logged = (fd->attrs && fd->GetAttr(ATTR_LOG) != nullptr); + bool logged = (fd->attrs && fd->GetAttr(zeek::detail::ATTR_LOG) != nullptr); auto nr = make_intrusive(record_field); @@ -832,7 +834,7 @@ const char* RecordType::AddFields(const type_decl_list& others, for ( const auto& td : others ) { - if ( ! td->GetAttr(ATTR_DEFAULT) && ! td->GetAttr(ATTR_OPTIONAL) ) + if ( ! td->GetAttr(zeek::detail::ATTR_DEFAULT) && ! td->GetAttr(zeek::detail::ATTR_OPTIONAL) ) return "extension field must be &optional or have &default"; } @@ -843,9 +845,9 @@ const char* RecordType::AddFields(const type_decl_list& others, if ( add_log_attr ) { if ( ! td->attrs ) - td->attrs = make_intrusive(td->type, true, false); + td->attrs = make_intrusive(td->type, true, false); - td->attrs->AddAttr(make_intrusive(ATTR_LOG)); + td->attrs->AddAttr(make_intrusive(zeek::detail::ATTR_LOG)); } types->push_back(td); @@ -993,9 +995,9 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const if ( decl) { string result; - if ( const auto& deprecation = decl->GetAttr(ATTR_DEPRECATED) ) + if ( const auto& deprecation = decl->GetAttr(zeek::detail::ATTR_DEPRECATED) ) { - auto expr = static_cast(deprecation->GetExpr().get()); + auto expr = static_cast(deprecation->GetExpr().get()); if ( expr ) { StringVal* text = expr->Value()->AsStringVal(); @@ -1014,7 +1016,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const return ""; } -SubNetType::SubNetType() : BroType(TYPE_SUBNET) +SubNetType::SubNetType() : Type(TYPE_SUBNET) { } @@ -1026,8 +1028,8 @@ void SubNetType::Describe(ODesc* d) const d->Add(int(Tag())); } -FileType::FileType(IntrusivePtr yield_type) - : BroType(TYPE_FILE), yield(std::move(yield_type)) +FileType::FileType(IntrusivePtr yield_type) + : Type(TYPE_FILE), yield(std::move(yield_type)) { } @@ -1047,7 +1049,7 @@ void FileType::Describe(ODesc* d) const } } -OpaqueType::OpaqueType(const string& arg_name) : BroType(TYPE_OPAQUE) +OpaqueType::OpaqueType(const string& arg_name) : Type(TYPE_OPAQUE) { name = arg_name; } @@ -1068,20 +1070,20 @@ void OpaqueType::DescribeReST(ODesc* d, bool roles_only) const } EnumType::EnumType(const string& name) - : BroType(TYPE_ENUM) + : Type(TYPE_ENUM) { counter = 0; SetName(name); } EnumType::EnumType(const EnumType* e) - : BroType(TYPE_ENUM), names(e->names), vals(e->vals) + : Type(TYPE_ENUM), names(e->names), vals(e->vals) { counter = e->counter; SetName(e->GetName()); } -IntrusivePtr EnumType::ShallowClone() +IntrusivePtr EnumType::ShallowClone() { if ( counter == 0 ) return make_intrusive(GetName()); @@ -1094,7 +1096,7 @@ EnumType::~EnumType() = default; // Note, we use reporter->Error() here (not Error()) to include the current script // location in the error message, rather than the one where the type was // originally defined. -void EnumType::AddName(const string& module_name, const char* name, bool is_export, Expr* deprecation) +void EnumType::AddName(const string& module_name, const char* name, bool is_export, zeek::detail::Expr* deprecation) { /* implicit, auto-increment */ if ( counter < 0) @@ -1107,7 +1109,7 @@ void EnumType::AddName(const string& module_name, const char* name, bool is_expo counter++; } -void EnumType::AddName(const string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation) +void EnumType::AddName(const string& module_name, const char* name, bro_int_t val, bool is_export, zeek::detail::Expr* deprecation) { /* explicit value specified */ if ( counter > 0 ) @@ -1121,7 +1123,7 @@ void EnumType::AddName(const string& module_name, const char* name, bro_int_t va } void EnumType::CheckAndAddName(const string& module_name, const char* name, - bro_int_t val, bool is_export, Expr* deprecation) + bro_int_t val, bool is_export, zeek::detail::Expr* deprecation) { if ( Lookup(val) ) { @@ -1164,8 +1166,8 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name, if ( vals.find(val) == vals.end() ) vals[val] = make_intrusive(IntrusivePtr{NewRef{}, this}, val); - set types = BroType::GetAliases(GetName()); - set::const_iterator it; + set types = Type::GetAliases(GetName()); + set::const_iterator it; for ( it = types.begin(); it != types.end(); ++it ) if ( *it != this ) @@ -1301,31 +1303,31 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const } } -VectorType::VectorType(IntrusivePtr element_type) - : BroType(TYPE_VECTOR), yield_type(std::move(element_type)) +VectorType::VectorType(IntrusivePtr element_type) + : Type(TYPE_VECTOR), yield_type(std::move(element_type)) { } -IntrusivePtr VectorType::ShallowClone() +IntrusivePtr VectorType::ShallowClone() { return make_intrusive(yield_type); } VectorType::~VectorType() = default; -const IntrusivePtr& VectorType::Yield() const +const IntrusivePtr& VectorType::Yield() const { // Work around the fact that we use void internally to mark a vector // as being unspecified. When looking at its yield type, we need to // 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; } -int VectorType::MatchesIndex(ListExpr* const index) const +int VectorType::MatchesIndex(zeek::detail::ListExpr* const index) const { expr_list& el = index->Exprs(); @@ -1369,28 +1371,12 @@ 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 // that the test is in only one direction - we don't check whether t2 is // initialization-compatible with t1. -static bool is_init_compat(const BroType& t1, const BroType& t2) +static bool is_init_compat(const Type& t1, const Type& t2) { if ( t1.Tag() == TYPE_LIST ) { @@ -1406,7 +1392,7 @@ static bool is_init_compat(const BroType& t1, const BroType& t2) return false; } -bool same_type(const BroType& arg_t1, const BroType& arg_t2, +bool same_type(const Type& arg_t1, const Type& arg_t2, bool is_init, bool match_record_field_names) { if ( &arg_t1 == &arg_t2 || @@ -1559,7 +1545,7 @@ bool same_type(const BroType& arg_t1, const BroType& arg_t2, return false; } -bool same_attrs(const Attributes* a1, const Attributes* a2) +bool same_attrs(const zeek::detail::Attributes* a1, const zeek::detail::Attributes* a2) { if ( ! a1 ) return (a2 == nullptr); @@ -1601,7 +1587,7 @@ bool record_promotion_compatible(const RecordType* super_rec, return true; } -const BroType* flatten_type(const BroType* t) +const Type* flatten_type(const Type* t) { if ( t->Tag() != TYPE_LIST ) return t; @@ -1624,9 +1610,9 @@ const BroType* flatten_type(const BroType* t) return t; } -BroType* flatten_type(BroType* t) +Type* flatten_type(Type* t) { - return (BroType*) flatten_type((const BroType*) t); + return (Type*) flatten_type((const Type*) t); } bool is_assignable(TypeTag t) @@ -1698,8 +1684,8 @@ TypeTag max_type(TypeTag t1, TypeTag t2) } } -IntrusivePtr merge_types(const IntrusivePtr& arg_t1, - const IntrusivePtr& arg_t2) +IntrusivePtr merge_types(const IntrusivePtr& arg_t1, + const IntrusivePtr& arg_t2) { auto t1 = arg_t1.get(); auto t2 = arg_t2.get(); @@ -1793,7 +1779,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, const auto& y1 = t1->Yield(); const auto& y2 = t2->Yield(); - IntrusivePtr y3; + IntrusivePtr y3; if ( y1 || y2 ) { @@ -1938,7 +1924,7 @@ IntrusivePtr merge_types(const IntrusivePtr& arg_t1, } } -IntrusivePtr merge_type_list(ListExpr* elements) +IntrusivePtr merge_type_list(zeek::detail::ListExpr* elements) { TypeList* tl_type = elements->GetType()->AsTypeList(); const auto& tl = tl_type->Types(); @@ -1964,7 +1950,7 @@ IntrusivePtr merge_type_list(ListExpr* elements) } // Reduces an aggregate type. -static BroType* reduce_type(BroType* t) +static Type* reduce_type(Type* t) { if ( t->Tag() == TYPE_LIST ) return flatten_type(t); @@ -1983,9 +1969,9 @@ static BroType* reduce_type(BroType* t) return t; } -IntrusivePtr init_type(Expr* init) +IntrusivePtr init_type(zeek::detail::Expr* init) { - if ( init->Tag() != EXPR_LIST ) + if ( init->Tag() != zeek::detail::EXPR_LIST ) { auto t = init->InitType(); @@ -2002,7 +1988,7 @@ IntrusivePtr init_type(Expr* init) return t; } - ListExpr* init_list = init->AsListExpr(); + zeek::detail::ListExpr* init_list = init->AsListExpr(); const expr_list& el = init_list->Exprs(); if ( el.length() == 0 ) @@ -2012,7 +1998,7 @@ IntrusivePtr init_type(Expr* init) } // Could be a record, a set, or a list of table elements. - Expr* e0 = el[0]; + zeek::detail::Expr* e0 = el[0]; if ( e0->IsRecordElement(nullptr) ) // ListExpr's know how to build a record from their @@ -2030,7 +2016,7 @@ IntrusivePtr init_type(Expr* init) for ( int i = 1; t && i < el.length(); ++i ) { auto el_t = el[i]->InitType(); - IntrusivePtr ti; + IntrusivePtr ti; if ( el_t ) ti = {NewRef{}, reduce_type(el_t.get())}; @@ -2067,7 +2053,7 @@ IntrusivePtr init_type(Expr* init) nullptr); } -bool is_atomic_type(const BroType& t) +bool is_atomic_type(const Type& t) { switch ( t.InternalType() ) { case TYPE_INTERNAL_INT: @@ -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 80cd024ce5..c123eb397c 100644 --- a/src/Type.h +++ b/src/Type.h @@ -14,8 +14,59 @@ #include #include -// BRO types. +class EnumVal; +class TableVal; +ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); + +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 +97,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,34 +170,34 @@ 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 Expr; -class Attributes; class TypeList; class TableType; class SetType; class RecordType; class SubNetType; class FuncType; -class ListExpr; class EnumType; class VectorType; class TypeType; class OpaqueType; -class EnumVal; -class TableVal; -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 { +class Type : public BroObj { public: - static inline const IntrusivePtr nil; + static inline const IntrusivePtr nil; - explicit BroType(TypeTag tag, bool base_type = false); + explicit Type(zeek::TypeTag tag, bool base_type = false); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]] + explicit Type(::TypeTag tag, bool base_type = false) + : Type(static_cast(tag), base_type) + {} +#pragma GCC diagnostic pop // Performs a shallow clone operation of the Bro type. // This especially means that especially for tables the types @@ -153,7 +207,7 @@ public: // Clone operations will mostly be implemented in the derived classes; // in addition cloning will be limited to classes that can be reached by // the script-level. - virtual IntrusivePtr ShallowClone(); + virtual IntrusivePtr ShallowClone(); TypeTag Tag() const { return tag; } InternalTypeTag InternalType() const { return internal_tag; } @@ -168,18 +222,18 @@ public: // if it matches and produces a vector result; and // DOES_NOT_MATCH_INDEX = 0 if it can't match (or the type // is not an indexable type). - virtual int MatchesIndex(ListExpr* index) const; + virtual int MatchesIndex(zeek::detail::ListExpr* index) const; // Returns the type yielded by this type. For example, if // this type is a table[string] of port, then returns the "port" // type. Returns nil if this is not an index type. - virtual const IntrusivePtr& Yield() const; + virtual const IntrusivePtr& Yield() const; [[deprecated("Remove in v4.1. Use Yield() instead.")]] - virtual BroType* YieldType() + virtual Type* YieldType() { return Yield().get(); } [[deprecated("Remove in v4.1. Use Yield() instead.")]] - virtual const BroType* YieldType() const + virtual const Type* YieldType() const { return Yield().get(); } // Returns true if this type is a record and contains the @@ -189,126 +243,126 @@ public: // Returns the type of the given field, or nil if no such field. [[deprecated("Remove in v4.1. Use RecordType::GetFieldType() directly.")]] - virtual BroType* FieldType(const char* field) const; + virtual Type* FieldType(const char* field) const; #define CHECK_TYPE_TAG(tag_type, func_name) \ CHECK_TAG(tag, tag_type, func_name, type_name) const TypeList* AsTypeList() const { - CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList"); + CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList"); return (const TypeList*) this; } TypeList* AsTypeList() { - CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList"); + CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList"); return (TypeList*) this; } const TableType* AsTableType() const { - CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType"); + CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType"); return (const TableType*) this; } TableType* AsTableType() { - CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType"); + CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType"); return (TableType*) this; } SetType* AsSetType() { if ( ! IsSet() ) - BadTag("BroType::AsSetType", type_name(tag)); + BadTag("Type::AsSetType", type_name(tag)); return (SetType*) this; } const SetType* AsSetType() const { if ( ! IsSet() ) - BadTag("BroType::AsSetType", type_name(tag)); + BadTag("Type::AsSetType", type_name(tag)); return (const SetType*) this; } const RecordType* AsRecordType() const { - CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType"); + CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType"); return (const RecordType*) this; } RecordType* AsRecordType() { - CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType"); + CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType"); return (RecordType*) this; } const SubNetType* AsSubNetType() const { - CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType"); + CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType"); return (const SubNetType*) this; } SubNetType* AsSubNetType() { - CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType"); + CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType"); return (SubNetType*) this; } const FuncType* AsFuncType() const { - CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType"); + CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType"); return (const FuncType*) this; } FuncType* AsFuncType() { - CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType"); + CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType"); return (FuncType*) this; } const EnumType* AsEnumType() const { - CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType"); + CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType"); return (EnumType*) this; } EnumType* AsEnumType() { - CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType"); + CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType"); return (EnumType*) this; } const VectorType* AsVectorType() const { - CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType"); + CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType"); return (VectorType*) this; } OpaqueType* AsOpaqueType() { - CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType"); + CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType"); return (OpaqueType*) this; } const OpaqueType* AsOpaqueType() const { - CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType"); + CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType"); return (OpaqueType*) this; } VectorType* AsVectorType() { - CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType"); + CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType"); return (VectorType*) this; } const TypeType* AsTypeType() const { - CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType"); + CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType"); return (TypeType*) this; } TypeType* AsTypeType() { - CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType"); + CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType"); return (TypeType*) this; } @@ -322,7 +376,7 @@ public: return tag == TYPE_TABLE && Yield(); } - BroType* Ref() { ::Ref(this); return this; } + Type* Ref() { ::Ref(this); return this; } void Describe(ODesc* d) const override; virtual void DescribeReST(ODesc* d, bool roles_only = false) const; @@ -332,16 +386,16 @@ public: void SetName(const std::string& arg_name) { name = arg_name; } const std::string& GetName() const { return name; } - typedef std::map > TypeAliasMap; + typedef std::map > TypeAliasMap; - static std::set GetAliases(const std::string& type_name) - { return BroType::type_aliases[type_name]; } + static std::set GetAliases(const std::string& type_name) + { return Type::type_aliases[type_name]; } - static void AddAlias(const std::string &type_name, BroType* type) - { BroType::type_aliases[type_name].insert(type); } + static void AddAlias(const std::string &type_name, Type* type) + { Type::type_aliases[type_name].insert(type); } protected: - BroType() { } + Type() = default; void SetError(); @@ -355,50 +409,50 @@ private: static TypeAliasMap type_aliases; }; -class TypeList final : public BroType { +class TypeList final : public Type { public: - explicit TypeList(IntrusivePtr arg_pure_type = nullptr) - : BroType(TYPE_LIST), pure_type(std::move(arg_pure_type)) + explicit TypeList(IntrusivePtr arg_pure_type = nullptr) + : Type(TYPE_LIST), pure_type(std::move(arg_pure_type)) { } - const std::vector>& Types() const + const std::vector>& Types() const { return types; } bool IsPure() const { return pure_type != nullptr; } // Returns the underlying pure type, or nil if the list // is not pure or is empty. - const IntrusivePtr& GetPureType() const + const IntrusivePtr& GetPureType() const { return pure_type; } [[deprecated("Remove in v4.1. Use GetPureType() instead.")]] - BroType* PureType() { return pure_type.get(); } + Type* PureType() { return pure_type.get(); } [[deprecated("Remove in v4.1. Use GetPureType() instead.")]] - const BroType* PureType() const { return pure_type.get(); } + const Type* PureType() const { return pure_type.get(); } // True if all of the types match t, false otherwise. If // is_init is true, then the matching is done in the context // of an initialization. - bool AllMatch(const BroType* t, bool is_init) const; - bool AllMatch(const IntrusivePtr& t, bool is_init) const + bool AllMatch(const Type* t, bool is_init) const; + bool AllMatch(const IntrusivePtr& t, bool is_init) const { return AllMatch(t.get(), is_init); } - void Append(IntrusivePtr t); - void AppendEvenIfNotPure(IntrusivePtr t); + void Append(IntrusivePtr t); + void AppendEvenIfNotPure(IntrusivePtr t); void Describe(ODesc* d) const override; unsigned int MemoryAllocation() const override; protected: - IntrusivePtr pure_type; - std::vector> types; + IntrusivePtr pure_type; + std::vector> types; }; -class IndexType : public BroType { +class IndexType : public Type { public: - int MatchesIndex(ListExpr* index) const override; + int MatchesIndex(zeek::detail::ListExpr* index) const override; const IntrusivePtr& GetIndices() const { return indices; } @@ -406,10 +460,10 @@ public: [[deprecated("Remove in v4.1. Use GetIndices().")]] TypeList* Indices() const { return indices.get(); } - const std::vector>& IndexTypes() const + const std::vector>& IndexTypes() const { return indices->Types(); } - const IntrusivePtr& Yield() const override + const IntrusivePtr& Yield() const override { return yield_type; } void Describe(ODesc* d) const override; @@ -420,8 +474,8 @@ public: protected: IndexType(TypeTag t, IntrusivePtr arg_indices, - IntrusivePtr arg_yield_type) - : BroType(t), indices(std::move(arg_indices)), + IntrusivePtr arg_yield_type) + : Type(t), indices(std::move(arg_indices)), yield_type(std::move(arg_yield_type)) { } @@ -429,14 +483,14 @@ protected: ~IndexType() override; IntrusivePtr indices; - IntrusivePtr yield_type; + IntrusivePtr yield_type; }; class TableType : public IndexType { public: - TableType(IntrusivePtr ind, IntrusivePtr yield); + TableType(IntrusivePtr ind, IntrusivePtr yield); - IntrusivePtr ShallowClone() override; + IntrusivePtr ShallowClone() override; // Returns true if this table type is "unspecified", which is // what one gets using an empty "set()" or "table()" constructor. @@ -445,22 +499,22 @@ public: class SetType final : public TableType { public: - SetType(IntrusivePtr ind, IntrusivePtr arg_elements); + SetType(IntrusivePtr ind, IntrusivePtr arg_elements); ~SetType() override; - IntrusivePtr ShallowClone() override; + IntrusivePtr ShallowClone() override; [[deprecated("Remove in v4.1. Use Elements() isntead.")]] - ListExpr* SetElements() const { return elements.get(); } + zeek::detail::ListExpr* SetElements() const { return elements.get(); } - const IntrusivePtr& Elements() const + const IntrusivePtr& Elements() const { return elements; } protected: - IntrusivePtr elements; + IntrusivePtr elements; }; -class FuncType final : public BroType { +class FuncType final : public Type { public: static inline const IntrusivePtr nil; @@ -475,9 +529,18 @@ public: std::map offsets; }; - FuncType(IntrusivePtr args, IntrusivePtr yield, - function_flavor f); - IntrusivePtr ShallowClone() override; + FuncType(IntrusivePtr args, IntrusivePtr yield, + FunctionFlavor f); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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)) + {} +#pragma GCC diagnostic pop + + IntrusivePtr ShallowClone() override; ~FuncType() override; @@ -487,20 +550,27 @@ public: const IntrusivePtr& Params() const { return args; } - const IntrusivePtr& Yield() const override + const IntrusivePtr& Yield() const override { return yield; } - void SetYieldType(IntrusivePtr arg_yield) { yield = std::move(arg_yield); } - function_flavor Flavor() const { return flavor; } + void SetYieldType(IntrusivePtr arg_yield) { yield = std::move(arg_yield); } + 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; } - int MatchesIndex(ListExpr* index) const override; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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); } +#pragma GCC diagnostic pop + + 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, + bool CheckArgs(const std::vector>& args, bool is_init = false) const; [[deprecated("Remove in v4.1. Use ParamList().")]] @@ -531,20 +601,20 @@ public: protected: friend IntrusivePtr make_intrusive(); - FuncType() : BroType(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } + FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } IntrusivePtr args; IntrusivePtr arg_types; - IntrusivePtr yield; - function_flavor flavor; + IntrusivePtr yield; + FunctionFlavor flavor; std::vector prototypes; }; -class TypeType final : public BroType { +class TypeType final : public Type { public: - explicit TypeType(IntrusivePtr t) : BroType(TYPE_TYPE), type(std::move(t)) {} - IntrusivePtr ShallowClone() override { return make_intrusive(type); } + explicit TypeType(IntrusivePtr t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {} + IntrusivePtr ShallowClone() override { return make_intrusive(type); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } template @@ -552,62 +622,66 @@ public: { return cast_intrusive(type); } [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* Type() { return type.get(); } + zeek::Type* Type() { return type.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] - const BroType* Type() const { return type.get(); } + const zeek::Type* Type() const { return type.get(); } protected: - IntrusivePtr type; + IntrusivePtr type; }; class TypeDecl final { public: TypeDecl() = default; - TypeDecl(const char* i, IntrusivePtr t, IntrusivePtr attrs = nullptr); + TypeDecl(const char* i, IntrusivePtr t, + IntrusivePtr attrs = nullptr); TypeDecl(const TypeDecl& other); ~TypeDecl(); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" [[deprecated("Remove in v4.1. Use GetAttr().")]] - const Attr* FindAttr(attr_tag a) const - { return attrs ? attrs->Find(a).get() : nullptr; } + const zeek::detail::Attr* FindAttr(::attr_tag a) const + { return attrs ? attrs->Find(static_cast(a)).get() : nullptr; } +#pragma GCC diagnostic pop - const IntrusivePtr& GetAttr(attr_tag a) const - { return attrs ? attrs->Find(a) : Attr::nil; } + const IntrusivePtr& GetAttr(zeek::detail::attr_tag a) const + { return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; } void DescribeReST(ODesc* d, bool roles_only = false) const; - IntrusivePtr type; - IntrusivePtr attrs; + IntrusivePtr type; + IntrusivePtr attrs; const char* id = nullptr; }; -typedef PList type_decl_list; +using type_decl_list = PList; -class RecordType final : public BroType { +class RecordType final : public Type { public: explicit RecordType(type_decl_list* types); - IntrusivePtr ShallowClone() override; + IntrusivePtr ShallowClone() override; ~RecordType() override; bool HasField(const char* field) const override; [[deprecated("Remove in v4.1. Use GetFieldType() instead (note it doesn't check for invalid names).")]] - BroType* FieldType(const char* field) const override + Type* FieldType(const char* field) const override { auto offset = FieldOffset(field); return offset >= 0 ? GetFieldType(offset).get() : nullptr; } [[deprecated("Remove in v4.1. Use GetFieldType() instead.")]] - BroType* FieldType(int field) const + Type* FieldType(int field) const { return GetFieldType(field).get(); } /** * Looks up a field by name and returns its type. No check for invalid * field name is performed. */ - const IntrusivePtr& GetFieldType(const char* field_name) const + const IntrusivePtr& GetFieldType(const char* field_name) const { return GetFieldType(FieldOffset(field_name)); } /** @@ -622,7 +696,7 @@ public: * Looks up a field by its index and returns its type. No check for * invalid field offset is performed. */ - const IntrusivePtr& GetFieldType(int field_index) const + const IntrusivePtr& GetFieldType(int field_index) const { return (*types)[field_index]->type; } /** @@ -669,15 +743,24 @@ public: bool IsFieldDeprecated(int field) const { const TypeDecl* decl = FieldDecl(field); - return decl && decl->GetAttr(ATTR_DEPRECATED) != nullptr; + return decl && decl->GetAttr(zeek::detail::ATTR_DEPRECATED) != nullptr; } - bool FieldHasAttr(int field, attr_tag at) const + bool FieldHasAttr(int field, zeek::detail::attr_tag at) const { const TypeDecl* decl = FieldDecl(field); return decl && decl->GetAttr(at) != nullptr; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + bool FieldHasAttr(int field, ::attr_tag at) const + { + return FieldHasAttr(field, static_cast(at)); + } +#pragma GCC diagnostic pop + std::string GetFieldDeprecationWarning(int field, bool has_check) const; protected: @@ -687,31 +770,31 @@ protected: type_decl_list* types; }; -class SubNetType final : public BroType { +class SubNetType final : public Type { public: SubNetType(); void Describe(ODesc* d) const override; }; -class FileType final : public BroType { +class FileType final : public Type { public: - explicit FileType(IntrusivePtr yield_type); - IntrusivePtr ShallowClone() override { return make_intrusive(yield); } + explicit FileType(IntrusivePtr yield_type); + IntrusivePtr ShallowClone() override { return make_intrusive(yield); } ~FileType() override; - const IntrusivePtr& Yield() const override + const IntrusivePtr& Yield() const override { return yield; } void Describe(ODesc* d) const override; protected: - IntrusivePtr yield; + IntrusivePtr yield; }; -class OpaqueType final : public BroType { +class OpaqueType final : public Type { public: explicit OpaqueType(const std::string& name); - IntrusivePtr ShallowClone() override { return make_intrusive(name); } + IntrusivePtr ShallowClone() override { return make_intrusive(name); } ~OpaqueType() override { }; const std::string& Name() const { return name; } @@ -725,23 +808,23 @@ protected: std::string name; }; -class EnumType final : public BroType { +class EnumType final : public Type { public: typedef std::list > enum_name_list; explicit EnumType(const EnumType* e); explicit EnumType(const std::string& arg_name); - IntrusivePtr ShallowClone() override; + IntrusivePtr ShallowClone() override; ~EnumType() override; // The value of this name is next internal counter value, starting // with zero. The internal counter is incremented. - void AddName(const std::string& module_name, const char* name, bool is_export, Expr* deprecation = nullptr); + void AddName(const std::string& module_name, const char* name, bool is_export, zeek::detail::Expr* deprecation = nullptr); // The value of this name is set to val. Once a value has been // explicitly assigned using this method, no further names can be // added that aren't likewise explicitly initalized. - void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr); + void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, zeek::detail::Expr* deprecation = nullptr); // -1 indicates not found. bro_int_t Lookup(const std::string& module_name, const char* name) const; @@ -761,7 +844,7 @@ protected: void CheckAndAddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, - Expr* deprecation = nullptr); + zeek::detail::Expr* deprecation = nullptr); typedef std::map NameMap; NameMap names; @@ -778,15 +861,15 @@ protected: bro_int_t counter; }; -class VectorType final : public BroType { +class VectorType final : public Type { public: - explicit VectorType(IntrusivePtr t); - IntrusivePtr ShallowClone() override; + explicit VectorType(IntrusivePtr t); + IntrusivePtr ShallowClone() override; ~VectorType() override; - const IntrusivePtr& Yield() const override; + const IntrusivePtr& Yield() const override; - int MatchesIndex(ListExpr* index) const override; + int MatchesIndex(zeek::detail::ListExpr* index) const override; // Returns true if this table type is "unspecified", which is what one // gets using an empty "vector()" constructor. @@ -796,62 +879,39 @@ public: void DescribeReST(ODesc* d, bool roles_only = false) const override; protected: - IntrusivePtr yield_type; + 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. -extern bool same_type(const BroType& t1, const BroType& t2, +extern bool same_type(const Type& t1, const Type& t2, bool is_init=false, bool match_record_field_names=true); -inline bool same_type(const IntrusivePtr& t1, const IntrusivePtr& t2, +inline bool same_type(const IntrusivePtr& t1, const IntrusivePtr& t2, bool is_init=false, bool match_record_field_names=true) { return same_type(*t1, *t2, is_init, match_record_field_names); } -inline bool same_type(const BroType* t1, const BroType* t2, +inline bool same_type(const Type* t1, const Type* t2, bool is_init=false, bool match_record_field_names=true) { return same_type(*t1, *t2, is_init, match_record_field_names); } -inline bool same_type(const IntrusivePtr& t1, const BroType* t2, +inline bool same_type(const IntrusivePtr& t1, const Type* t2, bool is_init=false, bool match_record_field_names=true) { return same_type(*t1, *t2, is_init, match_record_field_names); } -inline bool same_type(const BroType* t1, const IntrusivePtr& t2, +inline bool same_type(const Type* t1, const IntrusivePtr& t2, bool is_init=false, bool match_record_field_names=true) { return same_type(*t1, *t2, is_init, match_record_field_names); } // True if the two attribute lists are equivalent. -extern bool same_attrs(const Attributes* a1, const Attributes* a2); +extern bool same_attrs(const zeek::detail::Attributes* a1, const zeek::detail::Attributes* a2); // Returns true if the record sub_rec can be promoted to the record // super_rec. extern bool record_promotion_compatible(const RecordType* super_rec, const RecordType* sub_rec); -// If the given BroType is a TypeList with just one element, returns +// If the given Type is a TypeList with just one element, returns // that element, otherwise returns the type. -extern const BroType* flatten_type(const BroType* t); -extern BroType* flatten_type(BroType* t); +extern const Type* flatten_type(const Type* t); +extern Type* flatten_type(Type* t); // Returns the "maximum" of two type tags, in a type-promotion sense. extern TypeTag max_type(TypeTag t1, TypeTag t2); @@ -859,28 +919,28 @@ extern TypeTag max_type(TypeTag t1, TypeTag t2); // Given two types, returns the "merge", in which promotable types // are promoted to the maximum of the two. Returns nil (and generates // an error message) if the types are incompatible. -IntrusivePtr merge_types(const IntrusivePtr& t1, - const IntrusivePtr& t2); +IntrusivePtr merge_types(const IntrusivePtr& t1, + const IntrusivePtr& t2); // Given a list of expressions, returns a (ref'd) type reflecting // a merged type consistent across all of them, or nil if this // cannot be done. -IntrusivePtr merge_type_list(ListExpr* elements); +IntrusivePtr merge_type_list(zeek::detail::ListExpr* elements); // Given an expression, infer its type when used for an initialization. -IntrusivePtr init_type(Expr* init); +IntrusivePtr init_type(zeek::detail::Expr* init); // Returns true if argument is an atomic type. -bool is_atomic_type(const BroType& t); -inline bool is_atomic_type(const BroType* t) +bool is_atomic_type(const Type& t); +inline bool is_atomic_type(const Type* t) { return is_atomic_type(*t); } -inline bool is_atomic_type(const IntrusivePtr& t) +inline bool is_atomic_type(const IntrusivePtr& t) { return is_atomic_type(*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()); } +inline bool is_assignable(Type* t) + { 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); } @@ -929,3 +989,68 @@ 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 error type. +inline const IntrusivePtr& error_type() { return base_type(TYPE_ERROR); } + +} // namespace zeek + +// Returns the basic (non-parameterized) type with the given type. +// The reference count of the type is not increased. +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +[[deprecated("Remove in v4.1. Use zeek::base_type() instead")]] +inline zeek::Type* base_type_no_ref(::TypeTag tag) + { return zeek::base_type(static_cast(tag)).get(); } +#pragma GCC diagnostic pop + +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::Type instead.")]] = zeek::Type; +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 66a01f1677..0823c56a70 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; @@ -379,40 +379,40 @@ void Val::ValDescribeReST(ODesc* d) const #ifdef DEBUG -ID* Val::GetID() const +zeek::detail::ID* Val::GetID() const { return bound_id ? global_scope()->Find(bound_id).get() : nullptr; } -void Val::SetID(ID* id) +void Val::SetID(zeek::detail::ID* id) { delete [] bound_id; bound_id = id ? copy_string(id->Name()) : nullptr; } #endif -bool Val::WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val) +bool Val::WouldOverflow(const zeek::Type* from_type, const zeek::Type* 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(); @@ -588,7 +588,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* { auto value = rval->GetFieldOrDefault(i); - if ( value && ( ! only_loggable || rt->FieldHasAttr(i, ATTR_LOG) ) ) + if ( value && ( ! only_loggable || rt->FieldHasAttr(i, zeek::detail::ATTR_LOG) ) ) { string key_str; auto field_name = rt->FieldName(i); @@ -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, IntrusivePtr a) : Val( for ( const auto& t : table_type->IndexTypes() ) { - 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 a) : Val( } } -void TableVal::Init(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; @@ -1460,29 +1460,29 @@ int TableVal::RecursiveSize() const return n; } -void TableVal::SetAttrs(IntrusivePtr a) +void TableVal::SetAttrs(IntrusivePtr a) { attrs = std::move(a); if ( ! attrs ) return; - CheckExpireAttr(ATTR_EXPIRE_READ); - CheckExpireAttr(ATTR_EXPIRE_WRITE); - CheckExpireAttr(ATTR_EXPIRE_CREATE); + CheckExpireAttr(zeek::detail::ATTR_EXPIRE_READ); + CheckExpireAttr(zeek::detail::ATTR_EXPIRE_WRITE); + CheckExpireAttr(zeek::detail::ATTR_EXPIRE_CREATE); - const auto& ef = attrs->Find(ATTR_EXPIRE_FUNC); + const auto& ef = attrs->Find(zeek::detail::ATTR_EXPIRE_FUNC); if ( ef ) expire_func = ef->GetExpr(); - const auto& cf = attrs->Find(ATTR_ON_CHANGE); + const auto& cf = attrs->Find(zeek::detail::ATTR_ON_CHANGE); if ( cf ) change_func = cf->GetExpr(); } -void TableVal::CheckExpireAttr(attr_tag at) +void TableVal::CheckExpireAttr(zeek::detail::attr_tag at) { const auto& a = attrs->Find(at); @@ -1490,7 +1490,7 @@ void TableVal::CheckExpireAttr(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"); @@ -1555,7 +1555,7 @@ bool TableVal::Assign(IntrusivePtr index, std::unique_ptr k, } // Keep old expiration time if necessary. - if ( old_entry_val && attrs && attrs->Find(ATTR_EXPIRE_CREATE) ) + if ( old_entry_val && attrs && attrs->Find(zeek::detail::ATTR_EXPIRE_CREATE) ) new_entry_val->SetExpireAccess(old_entry_val->ExpireAccessTime()); Modified(); @@ -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; } @@ -1808,7 +1808,7 @@ bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) IntrusivePtr TableVal::Default(const IntrusivePtr& index) { - const auto& def_attr = GetAttr(ATTR_DEFAULT); + const auto& def_attr = GetAttr(zeek::detail::ATTR_DEFAULT); if ( ! def_attr ) return nullptr; @@ -1818,14 +1818,15 @@ 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 coerce = make_intrusive(def_attr->GetExpr(), - std::move(rt)); + auto rt = cast_intrusive(ytype); + auto coerce = make_intrusive( + def_attr->GetExpr(), std::move(rt)); + def_val = coerce->Eval(nullptr); } @@ -1839,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() ) @@ -1859,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()); @@ -1896,7 +1897,7 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) TableEntryVal* v = (TableEntryVal*) subnets->Lookup(index.get()); if ( v ) { - if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(zeek::detail::ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); if ( v->GetVal() ) @@ -1920,7 +1921,7 @@ const IntrusivePtr& TableVal::Find(const IntrusivePtr& index) if ( v ) { - if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(zeek::detail::ATTR_EXPIRE_READ) ) v->SetExpireAccess(network_time); if ( v->GetVal() ) @@ -1963,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 ) @@ -1977,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 ) @@ -1992,7 +1993,7 @@ IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) if ( entry ) { - if ( attrs && attrs->Find(ATTR_EXPIRE_READ) ) + if ( attrs && attrs->Find(zeek::detail::ATTR_EXPIRE_READ) ) entry->SetExpireAccess(network_time); } } @@ -2048,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; @@ -2143,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); @@ -2155,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 { @@ -2172,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(); } @@ -2194,9 +2195,9 @@ ListVal* TableVal::ConvertToPureList() const return ToPureListVal().release(); } -const IntrusivePtr& TableVal::GetAttr(attr_tag t) const +const IntrusivePtr& TableVal::GetAttr(zeek::detail::attr_tag t) const { - return attrs ? attrs->Find(t) : Attr::nil; + return attrs ? attrs->Find(t) : zeek::detail::Attr::nil; } void TableVal::Describe(ODesc* d) const @@ -2295,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 ) { @@ -2335,7 +2336,7 @@ void TableVal::InitDefaultFunc(Frame* f) if ( def_val ) return; - const auto& def_attr = GetAttr(ATTR_DEFAULT); + const auto& def_attr = GetAttr(zeek::detail::ATTR_DEFAULT); if ( ! def_attr ) return; @@ -2343,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()) ) @@ -2506,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; @@ -2517,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 ) { @@ -2626,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); @@ -2687,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(); @@ -2709,34 +2710,34 @@ RecordVal::RecordVal(IntrusivePtr t, bool init_fields) : Val(std::mo // by default). for ( int i = 0; i < n; ++i ) { - Attributes* a = rt->FieldDecl(i)->attrs.get(); - Attr* def_attr = a ? a->Find(ATTR_DEFAULT).get() : nullptr; + zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); + zeek::detail::Attr* def_attr = a ? a->Find(zeek::detail::ATTR_DEFAULT).get() : nullptr; 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); } - if ( ! def && ! (a && a->Find(ATTR_OPTIONAL)) ) + 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)); @@ -2774,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); @@ -2824,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 { @@ -2834,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 ) @@ -2863,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)); + auto rhs = make_intrusive(v); + auto e = make_intrusive(std::move(rhs), + cast_intrusive(ft)); aggr->Assign(t_i, e->Eval(nullptr)); continue; } @@ -2877,7 +2878,7 @@ IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, for ( i = 0; i < ar_t->NumFields(); ++i ) if ( ! aggr->GetField(i) && - ! ar_t->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) + ! ar_t->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) ) { char buf[512]; snprintf(buf, sizeof(buf), @@ -2888,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) ) @@ -2976,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); @@ -3026,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>(); } @@ -3106,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; @@ -3155,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); @@ -3187,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::Type* t, bool is_init, const Location* expr_location) { if ( ! v ) return nullptr; - BroType* vt = flatten_type(v->GetType().get()); + zeek::Type* 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; @@ -3215,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); @@ -3228,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); @@ -3239,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. @@ -3249,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 { @@ -3265,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 { @@ -3281,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: @@ -3325,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: @@ -3391,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::Type* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3417,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::Type* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3443,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::Type* s, zeek::Type* t) { // Note: when changing this function, adapt all three of // cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). @@ -3464,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 6a7587da37..84afb01e51 100644 --- a/src/Val.h +++ b/src/Val.h @@ -121,10 +121,17 @@ 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)) {} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]] + Val(double d, ::TypeTag t) : Val(d, static_cast(t)) + {} +#pragma GCC diagnostic pop + [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(Func* f); explicit Val(IntrusivePtr f); @@ -136,16 +143,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::Type* 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 +188,11 @@ public: virtual bool RemoveFrom(Val* v) const; [[deprecated("Remove in v4.1. Use GetType().")]] - BroType* Type() { return type.get(); } + zeek::Type* Type() { return type.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] - const BroType* Type() const { return type.get(); } + const zeek::Type* Type() const { return type.get(); } - const IntrusivePtr& GetType() const + const IntrusivePtr& GetType() const { return type; } template @@ -195,7 +202,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 +210,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::Type* 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 +287,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; @@ -324,12 +331,12 @@ public: #ifdef DEBUG // For debugging, we keep a reference to the global ID to which a // value has been bound *last*. - ID* GetID() const; + zeek::detail::ID* GetID() const; - void SetID(ID* id); + 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::Type* from_type, const zeek::Type* to_type, const Val* val); IntrusivePtr GetRecordFields(); @@ -337,7 +344,7 @@ public: protected: - friend class EnumType; + friend class zeek::EnumType; friend class ListVal; friend class RecordVal; friend class VectorVal; @@ -352,21 +359,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 +389,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 +498,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 +508,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 +654,17 @@ protected: // element in their index. class ListVal final : public Val { public: - explicit ListVal(TypeTag t); + explicit ListVal(zeek::TypeTag t); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag")]] + explicit ListVal(::TypeTag t) : ListVal(static_cast(t)) {} +#pragma GCC diagnostic pop + ~ListVal() override; - TypeTag BaseTag() const { return tag; } + zeek::TypeTag BaseTag() const { return tag; } IntrusivePtr SizeVal() const override; @@ -698,7 +712,7 @@ protected: IntrusivePtr DoClone(CloneState* state) override; std::vector> vals; - TypeTag tag; + zeek::TypeTag tag; }; extern double bro_start_network_time; @@ -758,9 +772,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, zeek::detail::Attributes* attrs = nullptr) : TableVal({NewRef{}, t}, {NewRef{}, attrs}) {} @@ -932,29 +947,32 @@ 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 - void SetAttrs(IntrusivePtr attrs); + void SetAttrs(IntrusivePtr attrs); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" [[deprecated("Remove in v4.1. Use GetAttr().")]] - Attr* FindAttr(attr_tag t) const - { return GetAttr(t).get(); } + Attr* FindAttr(::attr_tag t) const + { return GetAttr(static_cast(t)).get(); } +#pragma GCC diagnostic pop - const IntrusivePtr& GetAttr(attr_tag t) const; + const IntrusivePtr& GetAttr(zeek::detail::attr_tag t) const; [[deprecated("Remove in v4.1. Use GetAttrs().")]] - Attributes* Attrs() { return attrs.get(); } + zeek::detail::Attributes* Attrs() { return attrs.get(); } - const IntrusivePtr& GetAttrs() const + const IntrusivePtr& GetAttrs() const { return attrs; } // Returns the size of the table. @@ -997,8 +1015,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::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 @@ -1006,13 +1024,13 @@ public: static void RebuildParseTimeTables(); // Clears all state that was used to track TableVals that depending - // on RecordTypes. + // on zeek::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; @@ -1020,7 +1038,12 @@ protected: ParseTimeTableState DumpTableState(); void RebuildTable(ParseTimeTableState ptts); - void CheckExpireAttr(attr_tag at); + void CheckExpireAttr(zeek::detail::attr_tag at); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]] + void CheckExpireAttr(::attr_tag at); +#pragma GCC diagnostic pop bool ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr new_val); bool CheckAndAssign(IntrusivePtr index, IntrusivePtr new_val); @@ -1047,16 +1070,16 @@ protected: IntrusivePtr DoClone(CloneState* state) override; - IntrusivePtr table_type; + IntrusivePtr table_type; CompositeHash* table_hash; - IntrusivePtr attrs; - IntrusivePtr expire_time; - IntrusivePtr expire_func; + IntrusivePtr attrs; + IntrusivePtr expire_time; + IntrusivePtr expire_func; TableValTimer* timer; IterCookie* expire_cookie; PrefixTable* subnets; IntrusivePtr def_val; - IntrusivePtr change_func; + IntrusivePtr change_func; // prevent recursion of change functions bool in_change_func = false; @@ -1067,8 +1090,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; @@ -1208,10 +1231,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; @@ -1222,7 +1245,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(); @@ -1231,7 +1254,7 @@ protected: BroObj* origin; - using RecordTypeValMap = std::unordered_map>>; + using RecordTypeValMap = std::unordered_map>>; static RecordTypeValMap parse_time_records; }; @@ -1241,12 +1264,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; @@ -1257,8 +1280,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; @@ -1363,7 +1386,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::Type* t, bool is_init, const Location* expr_location = nullptr); extern bool same_val(const Val* v1, const Val* v2); @@ -1375,22 +1398,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::Type* 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::Type* 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::Type* s, zeek::Type* t); diff --git a/src/Var.cc b/src/Var.cc index af1665d92a..b3305cf2fa 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -17,7 +17,9 @@ #include "module_util.h" #include "ID.h" -static IntrusivePtr init_val(Expr* init, const BroType* t, +using namespace zeek::detail; + +static IntrusivePtr init_val(zeek::detail::Expr* init, const zeek::Type* t, IntrusivePtr aggr) { try @@ -30,14 +32,14 @@ static IntrusivePtr init_val(Expr* init, const BroType* t, } } -static bool add_prototype(const IntrusivePtr& id, BroType* t, - std::vector>* attrs, - const IntrusivePtr& init) +static bool add_prototype(const IntrusivePtr& id, zeek::Type* 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; @@ -52,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; @@ -100,23 +102,24 @@ static bool add_prototype(const IntrusivePtr& id, BroType* t, if ( attrs ) for ( const auto& a : *attrs ) - if ( a->Tag() == ATTR_DEPRECATED ) + 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, init_class c, - IntrusivePtr init, - std::unique_ptr>> attr, +static void make_var(const IntrusivePtr& id, IntrusivePtr t, + zeek::detail::init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, decl_type dt, bool do_init) { if ( id->GetType() ) { - 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 ) @@ -125,7 +128,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c else if ( dt != VAR_REDEF || init || ! attr ) { - if ( IsFunc(id->GetType()->Tag()) ) + if ( zeek::IsFunc(id->GetType()->Tag()) ) add_prototype(id, t.get(), attr.get(), init); else id->Error("already defined", init.get()); @@ -146,10 +149,10 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c t = id->GetType(); } - 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; @@ -165,7 +168,7 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c if ( t && t->IsSet() ) { // Check for set with explicit elements. - SetType* st = t->AsTableType()->AsSetType(); + zeek::SetType* st = t->AsTableType()->AsSetType(); const auto& elements = st->Elements(); if ( elements ) @@ -188,10 +191,10 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c return; } - t = init_type(init.get()); + t = zeek::init_type(init.get()); if ( ! t ) { - id->SetType(error_type()); + id->SetType(zeek::error_type()); return; } } @@ -199,22 +202,22 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c id->SetType(t); if ( attr ) - id->AddAttrs(make_intrusive(std::move(*attr), t, false, id->IsGlobal())); + id->AddAttrs(make_intrusive(std::move(*attr), t, false, id->IsGlobal())); if ( init ) { switch ( init->Tag() ) { - case EXPR_TABLE_CONSTRUCTOR: + case zeek::detail::EXPR_TABLE_CONSTRUCTOR: { - TableConstructorExpr* ctor = (TableConstructorExpr*) init.get(); + auto* ctor = static_cast(init.get()); if ( ctor->GetAttrs() ) id->AddAttrs(ctor->GetAttrs()); } break; - case EXPR_SET_CONSTRUCTOR: + case zeek::detail::EXPR_SET_CONSTRUCTOR: { - SetConstructorExpr* ctor = (SetConstructorExpr*) init.get(); + auto* ctor = static_cast(init.get()); if ( ctor->GetAttrs() ) id->AddAttrs(ctor->GetAttrs()); } @@ -227,14 +230,14 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c if ( do_init ) { - if ( c == INIT_NONE && dt == VAR_REDEF && t->IsTable() && - init && init->Tag() == EXPR_ASSIGN ) + if ( c == zeek::detail::INIT_NONE && dt == VAR_REDEF && t->IsTable() && + init && init->Tag() == zeek::detail::EXPR_ASSIGN ) // e.g. 'redef foo["x"] = 1' is missing an init class, but the // intention clearly isn't to overwrite entire existing table val. - c = INIT_EXTRA; + c = zeek::detail::INIT_EXTRA; - if ( init && ((c == INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) || - (c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) )) + if ( init && ((c == zeek::detail::INIT_EXTRA && id->GetAttr(zeek::detail::ATTR_ADD_FUNC)) || + (c == zeek::detail::INIT_REMOVE && id->GetAttr(zeek::detail::ATTR_DEL_FUNC)) )) // Just apply the function. id->SetVal(init, c); @@ -242,22 +245,22 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c { 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. - init = make_intrusive(std::move(init), + init = make_intrusive(std::move(init), IntrusivePtr{NewRef{}, t->AsRecordType()}); } - 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; @@ -294,49 +297,48 @@ static void make_var(const IntrusivePtr& id, IntrusivePtr t, init_c id->UpdateValAttrs(); - 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 // defined. - std::vector> inits; + std::vector> inits; auto f = make_intrusive(id, nullptr, inits, 0, 0); id->SetVal(make_intrusive(std::move(f))); } } - -void add_global(const IntrusivePtr& id, IntrusivePtr t, - init_class c, IntrusivePtr init, - std::unique_ptr>> attr, +void add_global(const IntrusivePtr& id, IntrusivePtr t, + zeek::detail::init_class c, IntrusivePtr init, + std::unique_ptr>> attr, decl_type dt) { make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } -IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, - init_class c, IntrusivePtr init, - std::unique_ptr>> attr, +IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, + zeek::detail::init_class c, IntrusivePtr init, + std::unique_ptr>> attr, decl_type dt) { make_var(id, std::move(t), c, init, std::move(attr), dt, false); if ( init ) { - if ( c != INIT_FULL ) + if ( c != zeek::detail::INIT_FULL ) id->Error("can't use += / -= for initializations of local variables"); // copy Location to the stack, because AssignExpr may free "init" const Location location = init->GetLocationInfo() ? *init->GetLocationInfo() : no_location; - auto name_expr = make_intrusive(id, dt == VAR_CONST); - auto assign_expr = make_intrusive(std::move(name_expr), - std::move(init), 0, - nullptr, id->GetAttrs()); - auto stmt = make_intrusive(std::move(assign_expr)); + auto name_expr = make_intrusive(id, dt == VAR_CONST); + auto assign_expr = make_intrusive(std::move(name_expr), + std::move(init), 0, + nullptr, id->GetAttrs()); + auto stmt = make_intrusive(std::move(assign_expr)); stmt->SetLocationInfo(&location); return stmt; } @@ -344,28 +346,28 @@ IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, else { current_scope()->AddInit(std::move(id)); - return make_intrusive(); + return make_intrusive(); } } -extern IntrusivePtr add_and_assign_local(IntrusivePtr id, - IntrusivePtr init, +extern IntrusivePtr add_and_assign_local(IntrusivePtr id, + IntrusivePtr init, IntrusivePtr val) { - make_var(id, nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false); - auto name_expr = make_intrusive(std::move(id)); - return make_intrusive(std::move(name_expr), std::move(init), - false, std::move(val)); + make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false); + auto name_expr = make_intrusive(std::move(id)); + return make_intrusive(std::move(name_expr), std::move(init), + false, std::move(val)); } -void add_type(ID* id, IntrusivePtr t, - std::unique_ptr>> attr) +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); @@ -373,10 +375,10 @@ void add_type(ID* id, IntrusivePtr t, // Clone the type to preserve type name aliasing. tnew = t->ShallowClone(); - BroType::AddAlias(new_type_name, tnew.get()); + zeek::Type::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::Type::AddAlias(old_type_name, tnew.get()); tnew->SetName(id->Name()); @@ -384,35 +386,36 @@ void add_type(ID* id, IntrusivePtr t, id->MakeType(); if ( attr ) - id->SetAttrs(make_intrusive(std::move(*attr), tnew, false, false)); + 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(ATTR_DEFAULT) : nullptr; + const auto& def = args_i->attrs ? args_i->attrs->Find(zeek::detail::ATTR_DEFAULT) : nullptr; if ( ! def ) continue; if ( ! recv_i->attrs ) { - std::vector> a{def}; - recv_i->attrs = make_intrusive(std::move(a), - recv_i->type, - true, false); + std::vector> a{def}; + recv_i->attrs = make_intrusive(std::move(a), + recv_i->type, + true, false); } - else if ( ! recv_i->attrs->Find(ATTR_DEFAULT) ) + else if ( ! recv_i->attrs->Find(zeek::detail::ATTR_DEFAULT) ) recv_i->attrs->AddAttr(def); } } -static Attr* find_attr(const std::vector>* al, attr_tag tag) +static zeek::detail::Attr* find_attr(const std::vector>* al, + zeek::detail::attr_tag tag) { if ( ! al ) return nullptr; @@ -424,7 +427,7 @@ static Attr* find_attr(const std::vector>* al, attr_tag tag) return nullptr; } -static std::optional 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() ) { @@ -432,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]; @@ -444,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(); @@ -459,22 +462,22 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl return true; } -void begin_func(IntrusivePtr id, const char* module_name, - function_flavor flavor, bool is_redef, - IntrusivePtr t, - std::unique_ptr>> attrs) +void begin_func(IntrusivePtr id, const char* module_name, + 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() ) { @@ -483,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 @@ -502,7 +505,7 @@ void begin_func(IntrusivePtr id, const char* module_name, { auto f = args->FieldDecl(i); - if ( f->attrs && f->attrs->Find(ATTR_DEFAULT) ) + if ( f->attrs && f->attrs->Find(zeek::detail::ATTR_DEFAULT) ) { reporter->PushLocation(args->GetLocationInfo()); reporter->Warning( @@ -532,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; @@ -566,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() ) @@ -579,8 +582,8 @@ void begin_func(IntrusivePtr id, const char* module_name, arg_id->SetOffset(prototype->offsets[i]); } - if ( Attr* depr_attr = find_attr(current_scope()->Attrs().get(), - ATTR_DEPRECATED) ) + if ( zeek::detail::Attr* depr_attr = find_attr(current_scope()->Attrs().get(), + zeek::detail::ATTR_DEPRECATED) ) current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr()); } @@ -591,26 +594,26 @@ public: scopes.emplace_back(s); } - TraversalCode PreExpr(const Expr*) override; - TraversalCode PostExpr(const Expr*) override; + TraversalCode PreExpr(const zeek::detail::Expr*) override; + TraversalCode PostExpr(const zeek::detail::Expr*) override; std::vector scopes; - std::vector outer_id_references; + std::vector outer_id_references; }; -TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) +TraversalCode OuterIDBindingFinder::PreExpr(const zeek::detail::Expr* expr) { - if ( expr->Tag() == EXPR_LAMBDA ) + if ( expr->Tag() == zeek::detail::EXPR_LAMBDA ) { - auto le = static_cast(expr); + auto le = static_cast(expr); scopes.emplace_back(le->GetScope()); return TC_CONTINUE; } - if ( expr->Tag() != EXPR_NAME ) + if ( expr->Tag() != zeek::detail::EXPR_NAME ) return TC_CONTINUE; - const NameExpr* e = static_cast(expr); + auto* e = static_cast(expr); if ( e->Id()->IsGlobal() ) return TC_CONTINUE; @@ -625,15 +628,15 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) return TC_CONTINUE; } -TraversalCode OuterIDBindingFinder::PostExpr(const Expr* expr) +TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr) { - if ( expr->Tag() == EXPR_LAMBDA ) + if ( expr->Tag() == zeek::detail::EXPR_LAMBDA ) scopes.pop_back(); return TC_CONTINUE; } -void end_func(IntrusivePtr body) +void end_func(IntrusivePtr body) { auto ingredients = std::make_unique(pop_scope(), std::move(body)); @@ -668,7 +671,7 @@ Val* internal_val(const char* name) return zeek::id::find_val(name).get(); } -id_list gather_outer_ids(Scope* scope, Stmt* body) +id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body) { OuterIDBindingFinder cb(scope); body->Traverse(&cb); @@ -749,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() ) @@ -766,7 +769,7 @@ ListVal* internal_list_val(const char* name) return nullptr; } -BroType* internal_type(const char* name) +zeek::Type* internal_type(const char* name) { return zeek::id::find_type(name).get(); } diff --git a/src/Var.h b/src/Var.h index 935e276f86..3b2161e1bc 100644 --- a/src/Var.h +++ b/src/Var.h @@ -6,47 +6,48 @@ #include "ID.h" #include "Type.h" -class Expr; -class FuncType; -class Stmt; class Scope; class EventHandlerPtr; class StringVal; class TableVal; class ListVal; +ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +ZEEK_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, - init_class c, - IntrusivePtr init, - std::unique_ptr>> attr, +extern void add_global(const IntrusivePtr& id, + IntrusivePtr t, + zeek::detail::init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, decl_type dt); -extern IntrusivePtr add_local(IntrusivePtr id, - IntrusivePtr t, - init_class c, - IntrusivePtr init, - std::unique_ptr>> attr, - decl_type dt); +extern IntrusivePtr add_local(IntrusivePtr id, + IntrusivePtr t, + zeek::detail::init_class c, + IntrusivePtr init, + std::unique_ptr>> attr, + decl_type dt); -extern IntrusivePtr add_and_assign_local(IntrusivePtr id, - IntrusivePtr init, +extern IntrusivePtr add_and_assign_local(IntrusivePtr id, + IntrusivePtr init, IntrusivePtr val = nullptr); -extern void add_type(ID* id, IntrusivePtr t, - std::unique_ptr>> attr); +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, - std::unique_ptr>> attrs = nullptr); +extern void begin_func(IntrusivePtr id, const char* module_name, + zeek::FunctionFlavor flavor, bool is_redef, + IntrusivePtr t, + std::unique_ptr>> attrs = nullptr); -extern void end_func(IntrusivePtr body); +extern void end_func(IntrusivePtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. -extern id_list gather_outer_ids(Scope* scope, Stmt* body); +extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body); [[deprecated("Remove in v4.1. Use zeek::id::find_val().")]] extern Val* internal_val(const char* name); @@ -76,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::Type* 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/Component.cc b/src/analyzer/Component.cc index 2630db84df..99f149ff88 100644 --- a/src/analyzer/Component.cc +++ b/src/analyzer/Component.cc @@ -9,7 +9,7 @@ using namespace analyzer; Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial) - : plugin::Component(plugin::component::ANALYZER, name), + : zeek::plugin::Component(zeek::plugin::component::ANALYZER, name), plugin::TaggedComponent(arg_subtype) { factory = arg_factory; diff --git a/src/analyzer/Component.h b/src/analyzer/Component.h index 1c0f0a2002..bfdb688df3 100644 --- a/src/analyzer/Component.h +++ b/src/analyzer/Component.h @@ -21,7 +21,7 @@ class Analyzer; * A plugin can provide a specific protocol analyzer by registering this * analyzer component, describing the analyzer. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(Connection* conn); diff --git a/src/analyzer/Tag.h b/src/analyzer/Tag.h index 39cdc3ed45..18eaf2fdf6 100644 --- a/src/analyzer/Tag.h +++ b/src/analyzer/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace analyzer { @@ -92,8 +98,8 @@ public: protected: friend class analyzer::Manager; - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/analyzer/protocol/arp/Plugin.cc b/src/analyzer/protocol/arp/Plugin.cc index aceca7dd58..18bba8067c 100644 --- a/src/analyzer/protocol/arp/Plugin.cc +++ b/src/analyzer/protocol/arp/Plugin.cc @@ -6,11 +6,11 @@ namespace plugin { namespace Zeek_ARP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::ARP"; config.description = "ARP Parsing"; return config; 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/ayiya/Plugin.cc b/src/analyzer/protocol/ayiya/Plugin.cc index df053c57a0..b16de5bf37 100644 --- a/src/analyzer/protocol/ayiya/Plugin.cc +++ b/src/analyzer/protocol/ayiya/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_AYIYA { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("AYIYA", ::analyzer::ayiya::AYIYA_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::AYIYA"; config.description = "AYIYA Analyzer"; return config; 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/bittorrent/Plugin.cc b/src/analyzer/protocol/bittorrent/Plugin.cc index bf8636a103..ea47b945ff 100644 --- a/src/analyzer/protocol/bittorrent/Plugin.cc +++ b/src/analyzer/protocol/bittorrent/Plugin.cc @@ -8,14 +8,14 @@ namespace plugin { namespace Zeek_BitTorrent { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("BitTorrent", ::analyzer::bittorrent::BitTorrent_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("BitTorrentTracker", ::analyzer::bittorrent::BitTorrentTracker_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::BitTorrent"; config.description = "BitTorrent Analyzer"; return config; diff --git a/src/analyzer/protocol/conn-size/Plugin.cc b/src/analyzer/protocol/conn-size/Plugin.cc index 3f73558051..7068a27baf 100644 --- a/src/analyzer/protocol/conn-size/Plugin.cc +++ b/src/analyzer/protocol/conn-size/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_ConnSize { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("ConnSize", ::analyzer::conn_size::ConnSize_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::ConnSize"; config.description = "Connection size analyzer"; return config; diff --git a/src/analyzer/protocol/dce-rpc/Plugin.cc b/src/analyzer/protocol/dce-rpc/Plugin.cc index 4974b1c427..eb002174dc 100644 --- a/src/analyzer/protocol/dce-rpc/Plugin.cc +++ b/src/analyzer/protocol/dce-rpc/Plugin.cc @@ -8,13 +8,13 @@ namespace plugin { namespace Zeek_DCE_RPC { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("DCE_RPC", ::analyzer::dce_rpc::DCE_RPC_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::DCE_RPC"; config.description = "DCE-RPC analyzer"; return config; diff --git a/src/analyzer/protocol/dhcp/Plugin.cc b/src/analyzer/protocol/dhcp/Plugin.cc index 1b42b8b4fd..5d2b3f8939 100644 --- a/src/analyzer/protocol/dhcp/Plugin.cc +++ b/src/analyzer/protocol/dhcp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_DHCP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("DHCP", ::analyzer::dhcp::DHCP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::DHCP"; config.description = "DHCP analyzer"; return config; 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/dnp3/Plugin.cc b/src/analyzer/protocol/dnp3/Plugin.cc index 70a9e6fcc2..ad8639969e 100644 --- a/src/analyzer/protocol/dnp3/Plugin.cc +++ b/src/analyzer/protocol/dnp3/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_DNP3 { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("DNP3_TCP", ::analyzer::dnp3::DNP3_TCP_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("DNP3_UDP", ::analyzer::dnp3::DNP3_UDP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::DNP3"; config.description = "DNP3 UDP/TCP analyzers"; return config; 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/dns/Plugin.cc b/src/analyzer/protocol/dns/Plugin.cc index 4aceaf0ff4..7f6eba2376 100644 --- a/src/analyzer/protocol/dns/Plugin.cc +++ b/src/analyzer/protocol/dns/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_DNS { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("DNS", ::analyzer::dns::DNS_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("Contents_DNS", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::DNS"; config.description = "DNS analyzer"; return config; diff --git a/src/analyzer/protocol/file/Plugin.cc b/src/analyzer/protocol/file/Plugin.cc index 4c9d6ff31a..6f775cad33 100644 --- a/src/analyzer/protocol/file/Plugin.cc +++ b/src/analyzer/protocol/file/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_File { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("FTP_Data", ::analyzer::file::FTP_Data::Instantiate)); AddComponent(new ::analyzer::Component("IRC_Data", ::analyzer::file::IRC_Data::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::File"; config.description = "Generic file analyzer"; return config; diff --git a/src/analyzer/protocol/finger/Plugin.cc b/src/analyzer/protocol/finger/Plugin.cc index 65edceb642..36a8b6f218 100644 --- a/src/analyzer/protocol/finger/Plugin.cc +++ b/src/analyzer/protocol/finger/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Finger { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Finger", ::analyzer::finger::Finger_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Finger"; config.description = "Finger analyzer"; return config; diff --git a/src/analyzer/protocol/ftp/Plugin.cc b/src/analyzer/protocol/ftp/Plugin.cc index b7743355a7..86dff3a911 100644 --- a/src/analyzer/protocol/ftp/Plugin.cc +++ b/src/analyzer/protocol/ftp/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_FTP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("FTP", ::analyzer::ftp::FTP_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("FTP_ADAT", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::FTP"; config.description = "FTP analyzer"; return config; diff --git a/src/analyzer/protocol/gnutella/Plugin.cc b/src/analyzer/protocol/gnutella/Plugin.cc index 6452961b19..380d43559e 100644 --- a/src/analyzer/protocol/gnutella/Plugin.cc +++ b/src/analyzer/protocol/gnutella/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Gnutella { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Gnutella", ::analyzer::gnutella::Gnutella_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Gnutella"; config.description = "Gnutella analyzer"; return config; diff --git a/src/analyzer/protocol/gssapi/Plugin.cc b/src/analyzer/protocol/gssapi/Plugin.cc index 7f934cd3ac..fc478e29c9 100644 --- a/src/analyzer/protocol/gssapi/Plugin.cc +++ b/src/analyzer/protocol/gssapi/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_GSSAPI { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("GSSAPI", ::analyzer::gssapi::GSSAPI_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::GSSAPI"; config.description = "GSSAPI analyzer"; return config; diff --git a/src/analyzer/protocol/gtpv1/Plugin.cc b/src/analyzer/protocol/gtpv1/Plugin.cc index 9196c05a3b..94482bff96 100644 --- a/src/analyzer/protocol/gtpv1/Plugin.cc +++ b/src/analyzer/protocol/gtpv1/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_GTPv1 { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("GTPv1", ::analyzer::gtpv1::GTPv1_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::GTPv1"; config.description = "GTPv1 analyzer"; return config; 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/http/Plugin.cc b/src/analyzer/protocol/http/Plugin.cc index 52d8369d9e..d75e5eaaae 100644 --- a/src/analyzer/protocol/http/Plugin.cc +++ b/src/analyzer/protocol/http/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_HTTP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("HTTP", ::analyzer::http::HTTP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::HTTP"; config.description = "HTTP analyzer"; return config; 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/icmp/Plugin.cc b/src/analyzer/protocol/icmp/Plugin.cc index 1a104e63c1..ffa23f28ba 100644 --- a/src/analyzer/protocol/icmp/Plugin.cc +++ b/src/analyzer/protocol/icmp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_ICMP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("ICMP", ::analyzer::icmp::ICMP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::ICMP"; config.description = "ICMP analyzer"; return config; diff --git a/src/analyzer/protocol/ident/Plugin.cc b/src/analyzer/protocol/ident/Plugin.cc index 68042555b2..a338a00543 100644 --- a/src/analyzer/protocol/ident/Plugin.cc +++ b/src/analyzer/protocol/ident/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Ident { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Ident", ::analyzer::ident::Ident_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Ident"; config.description = "Ident analyzer"; return config; diff --git a/src/analyzer/protocol/imap/Plugin.cc b/src/analyzer/protocol/imap/Plugin.cc index 5c5ec7c4bf..8851f821eb 100644 --- a/src/analyzer/protocol/imap/Plugin.cc +++ b/src/analyzer/protocol/imap/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_IMAP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("IMAP", ::analyzer::imap::IMAP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::IMAP"; config.description = "IMAP analyzer (StartTLS only)"; return config; 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/irc/Plugin.cc b/src/analyzer/protocol/irc/Plugin.cc index c22498c38d..d54ef4d9c6 100644 --- a/src/analyzer/protocol/irc/Plugin.cc +++ b/src/analyzer/protocol/irc/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_IRC { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("IRC", ::analyzer::irc::IRC_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::IRC"; config.description = "IRC analyzer"; return config; diff --git a/src/analyzer/protocol/krb/Plugin.cc b/src/analyzer/protocol/krb/Plugin.cc index 8b6d51a9e5..cce65b797a 100644 --- a/src/analyzer/protocol/krb/Plugin.cc +++ b/src/analyzer/protocol/krb/Plugin.cc @@ -6,18 +6,20 @@ #include "analyzer/Component.h" namespace plugin { - namespace Zeek_KRB { - class Plugin : public plugin::Plugin { - public: - plugin::Configuration Configure() override - { - AddComponent(new ::analyzer::Component("KRB", ::analyzer::krb::KRB_Analyzer::Instantiate)); - AddComponent(new ::analyzer::Component("KRB_TCP", ::analyzer::krb_tcp::KRB_Analyzer::Instantiate)); - plugin::Configuration config; - config.name = "Zeek::KRB"; - config.description = "Kerberos analyzer"; - return config; - } - } plugin; - } +namespace Zeek_KRB { + +class Plugin : public zeek::plugin::Plugin { +public: + zeek::plugin::Configuration Configure() override + { + AddComponent(new ::analyzer::Component("KRB", ::analyzer::krb::KRB_Analyzer::Instantiate)); + AddComponent(new ::analyzer::Component("KRB_TCP", ::analyzer::krb_tcp::KRB_Analyzer::Instantiate)); + zeek::plugin::Configuration config; + config.name = "Zeek::KRB"; + config.description = "Kerberos analyzer"; + return config; + } +} plugin; + +} } 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/login/Plugin.cc b/src/analyzer/protocol/login/Plugin.cc index 27457b04d7..bc3a440537 100644 --- a/src/analyzer/protocol/login/Plugin.cc +++ b/src/analyzer/protocol/login/Plugin.cc @@ -10,9 +10,9 @@ namespace plugin { namespace Zeek_Login { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Telnet", ::analyzer::login::Telnet_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("Rsh", ::analyzer::login::Rsh_Analyzer::Instantiate)); @@ -22,7 +22,7 @@ public: AddComponent(new ::analyzer::Component("Contents_Rsh", nullptr)); AddComponent(new ::analyzer::Component("Contents_Rlogin", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Login"; config.description = "Telnet/Rsh/Rlogin analyzers"; return config; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 2305e47fa2..377d272bfa 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -1303,7 +1303,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()); @@ -1318,7 +1318,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/mime/Plugin.cc b/src/analyzer/protocol/mime/Plugin.cc index 222b5a2f79..fefe969098 100644 --- a/src/analyzer/protocol/mime/Plugin.cc +++ b/src/analyzer/protocol/mime/Plugin.cc @@ -6,11 +6,11 @@ namespace plugin { namespace Zeek_MIME { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::MIME"; config.description = "MIME parsing"; return config; diff --git a/src/analyzer/protocol/modbus/Plugin.cc b/src/analyzer/protocol/modbus/Plugin.cc index 9b1aef6ea5..e31bd4f89d 100644 --- a/src/analyzer/protocol/modbus/Plugin.cc +++ b/src/analyzer/protocol/modbus/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Modbus { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("MODBUS", ::analyzer::modbus::ModbusTCP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Modbus"; config.description = "Modbus analyzer"; return config; 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/mqtt/Plugin.cc b/src/analyzer/protocol/mqtt/Plugin.cc index fcafb4a7f2..ab820ecb44 100644 --- a/src/analyzer/protocol/mqtt/Plugin.cc +++ b/src/analyzer/protocol/mqtt/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_MQTT { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("MQTT", ::analyzer::MQTT::MQTT_Analyzer::InstantiateAnalyzer)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::MQTT"; config.description = "Message Queuing Telemetry Transport v3.1.1 Protocol analyzer"; return config; diff --git a/src/analyzer/protocol/mysql/Plugin.cc b/src/analyzer/protocol/mysql/Plugin.cc index 965bda6993..6a3d7d3ccc 100644 --- a/src/analyzer/protocol/mysql/Plugin.cc +++ b/src/analyzer/protocol/mysql/Plugin.cc @@ -5,17 +5,19 @@ #include "analyzer/Component.h" namespace plugin { - namespace Zeek_MySQL { - class Plugin : public plugin::Plugin { - public: - plugin::Configuration Configure() override - { - AddComponent(new ::analyzer::Component("MySQL", ::analyzer::MySQL::MySQL_Analyzer::Instantiate)); - plugin::Configuration config; - config.name = "Zeek::MySQL"; - config.description = "MySQL analyzer"; - return config; - } - } plugin; - } +namespace Zeek_MySQL { + +class Plugin : public zeek::plugin::Plugin { +public: + zeek::plugin::Configuration Configure() override + { + AddComponent(new ::analyzer::Component("MySQL", ::analyzer::MySQL::MySQL_Analyzer::Instantiate)); + zeek::plugin::Configuration config; + config.name = "Zeek::MySQL"; + config.description = "MySQL analyzer"; + return config; + } +} plugin; + +} } diff --git a/src/analyzer/protocol/ncp/Plugin.cc b/src/analyzer/protocol/ncp/Plugin.cc index b76fcbf748..24030935fc 100644 --- a/src/analyzer/protocol/ncp/Plugin.cc +++ b/src/analyzer/protocol/ncp/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_NCP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("NCP", ::analyzer::ncp::NCP_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("Contents_NCP", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::NCP"; config.description = "NCP analyzer"; return config; diff --git a/src/analyzer/protocol/netbios/Plugin.cc b/src/analyzer/protocol/netbios/Plugin.cc index 47db030464..d5d8671d4b 100644 --- a/src/analyzer/protocol/netbios/Plugin.cc +++ b/src/analyzer/protocol/netbios/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_NetBIOS { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("NetbiosSSN", ::analyzer::netbios_ssn::NetbiosSSN_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("Contents_NetbiosSSN", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::NetBIOS"; config.description = "NetBIOS analyzer support"; return config; diff --git a/src/analyzer/protocol/ntlm/Plugin.cc b/src/analyzer/protocol/ntlm/Plugin.cc index 92a3a3df77..572d9b97c6 100644 --- a/src/analyzer/protocol/ntlm/Plugin.cc +++ b/src/analyzer/protocol/ntlm/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_NTLM { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("NTLM", ::analyzer::ntlm::NTLM_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::NTLM"; config.description = "NTLM analyzer"; return config; 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/Plugin.cc b/src/analyzer/protocol/ntp/Plugin.cc index 437051f032..0b03791e1a 100644 --- a/src/analyzer/protocol/ntp/Plugin.cc +++ b/src/analyzer/protocol/ntp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_NTP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("NTP", ::analyzer::NTP::NTP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::NTP"; config.description = "NTP analyzer"; return config; 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/pia/Plugin.cc b/src/analyzer/protocol/pia/Plugin.cc index 1dbdfa45b4..b3482f2913 100644 --- a/src/analyzer/protocol/pia/Plugin.cc +++ b/src/analyzer/protocol/pia/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_PIA { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("PIA_TCP", ::analyzer::pia::PIA_TCP::Instantiate)); AddComponent(new ::analyzer::Component("PIA_UDP", ::analyzer::pia::PIA_UDP::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::PIA"; config.description = "Analyzers implementing Dynamic Protocol"; return config; diff --git a/src/analyzer/protocol/pop3/Plugin.cc b/src/analyzer/protocol/pop3/Plugin.cc index 1f1f95da2e..1f287798f7 100644 --- a/src/analyzer/protocol/pop3/Plugin.cc +++ b/src/analyzer/protocol/pop3/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_POP3 { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("POP3", ::analyzer::pop3::POP3_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::POP3"; config.description = "POP3 analyzer"; return config; diff --git a/src/analyzer/protocol/radius/Plugin.cc b/src/analyzer/protocol/radius/Plugin.cc index c99d945a57..5b765d2596 100644 --- a/src/analyzer/protocol/radius/Plugin.cc +++ b/src/analyzer/protocol/radius/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_RADIUS { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("RADIUS", ::analyzer::RADIUS::RADIUS_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::RADIUS"; config.description = "RADIUS analyzer"; return config; diff --git a/src/analyzer/protocol/rdp/Plugin.cc b/src/analyzer/protocol/rdp/Plugin.cc index 7d07d4c564..70145b109e 100644 --- a/src/analyzer/protocol/rdp/Plugin.cc +++ b/src/analyzer/protocol/rdp/Plugin.cc @@ -6,18 +6,18 @@ namespace plugin { namespace Zeek_RDP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override - { - AddComponent(new ::analyzer::Component("RDP", ::analyzer::rdp::RDP_Analyzer::InstantiateAnalyzer)); - AddComponent(new ::analyzer::Component("RDPEUDP", ::analyzer::rdpeudp::RDP_Analyzer::InstantiateAnalyzer)); + zeek::plugin::Configuration Configure() override + { + AddComponent(new ::analyzer::Component("RDP", ::analyzer::rdp::RDP_Analyzer::InstantiateAnalyzer)); + AddComponent(new ::analyzer::Component("RDPEUDP", ::analyzer::rdpeudp::RDP_Analyzer::InstantiateAnalyzer)); - plugin::Configuration config; - config.name = "Zeek::RDP"; - config.description = "RDP analyzer"; - return config; - } + zeek::plugin::Configuration config; + config.name = "Zeek::RDP"; + config.description = "RDP analyzer"; + return config; + } } plugin; } diff --git a/src/analyzer/protocol/rfb/Plugin.cc b/src/analyzer/protocol/rfb/Plugin.cc index 7d9d7e31bd..1bc665e25d 100644 --- a/src/analyzer/protocol/rfb/Plugin.cc +++ b/src/analyzer/protocol/rfb/Plugin.cc @@ -5,14 +5,14 @@ namespace plugin { namespace Zeek_RFB { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("RFB", ::analyzer::rfb::RFB_Analyzer::InstantiateAnalyzer)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::RFB"; config.description = "Parser for rfb (VNC) analyzer"; return config; 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/Plugin.cc b/src/analyzer/protocol/rpc/Plugin.cc index 6e284c9dbf..21f44a247f 100644 --- a/src/analyzer/protocol/rpc/Plugin.cc +++ b/src/analyzer/protocol/rpc/Plugin.cc @@ -10,9 +10,9 @@ namespace plugin { namespace Zeek_RPC { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("NFS", ::analyzer::rpc::NFS_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("MOUNT", ::analyzer::rpc::MOUNT_Analyzer::Instantiate)); @@ -20,7 +20,7 @@ public: AddComponent(new ::analyzer::Component("Contents_RPC", nullptr)); AddComponent(new ::analyzer::Component("Contents_NFS", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::RPC"; config.description = "Analyzers for RPC-based protocols"; return config; 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/Plugin.cc b/src/analyzer/protocol/sip/Plugin.cc index d05930fa00..4a6d253cbd 100644 --- a/src/analyzer/protocol/sip/Plugin.cc +++ b/src/analyzer/protocol/sip/Plugin.cc @@ -8,16 +8,16 @@ namespace plugin { namespace Zeek_SIP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SIP", ::analyzer::SIP::SIP_Analyzer::Instantiate)); // We don't fully support SIP-over-TCP yet, so we don't activate this component. // AddComponent(new ::analyzer::Component("SIP_TCP", ::analyzer::sip_tcp::SIP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SIP"; config.description = "SIP analyzer UDP-only"; return config; 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/smb/Plugin.cc b/src/analyzer/protocol/smb/Plugin.cc index 2c10066eed..a4935fe204 100644 --- a/src/analyzer/protocol/smb/Plugin.cc +++ b/src/analyzer/protocol/smb/Plugin.cc @@ -7,14 +7,14 @@ namespace plugin { namespace Zeek_SMB { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SMB", ::analyzer::smb::SMB_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("Contents_SMB", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SMB"; config.description = "SMB analyzer"; return config; diff --git a/src/analyzer/protocol/smtp/Plugin.cc b/src/analyzer/protocol/smtp/Plugin.cc index 2db99893af..d1a28ddc02 100644 --- a/src/analyzer/protocol/smtp/Plugin.cc +++ b/src/analyzer/protocol/smtp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_SMTP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SMTP", ::analyzer::smtp::SMTP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SMTP"; config.description = "SMTP analyzer"; return config; diff --git a/src/analyzer/protocol/snmp/Plugin.cc b/src/analyzer/protocol/snmp/Plugin.cc index 11785903b6..887b9a73ac 100644 --- a/src/analyzer/protocol/snmp/Plugin.cc +++ b/src/analyzer/protocol/snmp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_SNMP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SNMP", ::analyzer::snmp::SNMP_Analyzer::InstantiateAnalyzer)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SNMP"; config.description = "SNMP analyzer"; return config; 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/Plugin.cc b/src/analyzer/protocol/socks/Plugin.cc index 6bd33509ad..da2375991c 100644 --- a/src/analyzer/protocol/socks/Plugin.cc +++ b/src/analyzer/protocol/socks/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_SOCKS { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SOCKS", ::analyzer::socks::SOCKS_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SOCKS"; config.description = "SOCKS analyzer"; return config; 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/ssh/Plugin.cc b/src/analyzer/protocol/ssh/Plugin.cc index b9b147c86d..395192bb60 100644 --- a/src/analyzer/protocol/ssh/Plugin.cc +++ b/src/analyzer/protocol/ssh/Plugin.cc @@ -5,20 +5,20 @@ #include "analyzer/Component.h" namespace plugin { - namespace Zeek_SSH { +namespace Zeek_SSH { - class Plugin : public plugin::Plugin { - public: - plugin::Configuration Configure() override - { - AddComponent(new ::analyzer::Component("SSH", ::analyzer::SSH::SSH_Analyzer::Instantiate)); - - plugin::Configuration config; - config.name = "Zeek::SSH"; - config.description = "Secure Shell analyzer"; - return config; - } - } plugin; +class Plugin : public zeek::plugin::Plugin { +public: + zeek::plugin::Configuration Configure() override + { + AddComponent(new ::analyzer::Component("SSH", ::analyzer::SSH::SSH_Analyzer::Instantiate)); + zeek::plugin::Configuration config; + config.name = "Zeek::SSH"; + config.description = "Secure Shell analyzer"; + return config; } - } + } plugin; + +} +} diff --git a/src/analyzer/protocol/ssl/Plugin.cc b/src/analyzer/protocol/ssl/Plugin.cc index ea36628e09..72ea74dc7a 100644 --- a/src/analyzer/protocol/ssl/Plugin.cc +++ b/src/analyzer/protocol/ssl/Plugin.cc @@ -8,14 +8,14 @@ namespace plugin { namespace Zeek_SSL { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SSL", ::analyzer::ssl::SSL_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("DTLS", ::analyzer::dtls::DTLS_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SSL"; config.description = "SSL/TLS and DTLS analyzers"; return config; 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/stepping-stone/Plugin.cc b/src/analyzer/protocol/stepping-stone/Plugin.cc index 3d840a1b27..61e408bfce 100644 --- a/src/analyzer/protocol/stepping-stone/Plugin.cc +++ b/src/analyzer/protocol/stepping-stone/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_SteppingStone { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("SteppingStone", ::analyzer::stepping_stone::SteppingStone_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SteppingStone"; config.description = "Stepping stone analyzer"; return config; diff --git a/src/analyzer/protocol/syslog/Plugin.cc b/src/analyzer/protocol/syslog/Plugin.cc index f407275270..80cbf2e974 100644 --- a/src/analyzer/protocol/syslog/Plugin.cc +++ b/src/analyzer/protocol/syslog/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Syslog { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Syslog", ::analyzer::syslog::Syslog_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Syslog"; config.description = "Syslog analyzer UDP-only"; return config; diff --git a/src/analyzer/protocol/tcp/Plugin.cc b/src/analyzer/protocol/tcp/Plugin.cc index 9f06936baa..a6dd74e460 100644 --- a/src/analyzer/protocol/tcp/Plugin.cc +++ b/src/analyzer/protocol/tcp/Plugin.cc @@ -7,16 +7,16 @@ namespace plugin { namespace Zeek_TCP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("TCP", ::analyzer::tcp::TCP_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("TCPStats", ::analyzer::tcp::TCPStats_Analyzer::Instantiate)); AddComponent(new ::analyzer::Component("CONTENTLINE", nullptr)); AddComponent(new ::analyzer::Component("Contents", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::TCP"; config.description = "TCP analyzer"; return config; 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/Plugin.cc b/src/analyzer/protocol/teredo/Plugin.cc index 05bf47ea45..12d4fc66a3 100644 --- a/src/analyzer/protocol/teredo/Plugin.cc +++ b/src/analyzer/protocol/teredo/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_Teredo { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("Teredo", ::analyzer::teredo::Teredo_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Teredo"; config.description = "Teredo analyzer"; return config; 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/analyzer/protocol/udp/Plugin.cc b/src/analyzer/protocol/udp/Plugin.cc index aeac50f044..5eb42a867f 100644 --- a/src/analyzer/protocol/udp/Plugin.cc +++ b/src/analyzer/protocol/udp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_UDP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("UDP", ::analyzer::udp::UDP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::UDP"; config.description = "UDP Analyzer"; return config; diff --git a/src/analyzer/protocol/vxlan/Plugin.cc b/src/analyzer/protocol/vxlan/Plugin.cc index f00bf8a418..d199f4fe9d 100644 --- a/src/analyzer/protocol/vxlan/Plugin.cc +++ b/src/analyzer/protocol/vxlan/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_VXLAN { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("VXLAN", ::analyzer::vxlan::VXLAN_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::VXLAN"; config.description = "VXLAN analyzer"; return config; diff --git a/src/analyzer/protocol/xmpp/Plugin.cc b/src/analyzer/protocol/xmpp/Plugin.cc index 94befed562..f7f89852d9 100644 --- a/src/analyzer/protocol/xmpp/Plugin.cc +++ b/src/analyzer/protocol/xmpp/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_XMPP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("XMPP", ::analyzer::xmpp::XMPP_Analyzer::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::XMPP"; config.description = "XMPP analyzer (StartTLS only)"; return config; diff --git a/src/analyzer/protocol/zip/Plugin.cc b/src/analyzer/protocol/zip/Plugin.cc index d59cde2ca0..751797a55a 100644 --- a/src/analyzer/protocol/zip/Plugin.cc +++ b/src/analyzer/protocol/zip/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_ZIP { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::analyzer::Component("ZIP", nullptr)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::ZIP"; config.description = "Generic ZIP support analyzer"; return config; diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 09758077df..33413c74f0 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::Type* 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::Type* 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::Type* 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::Type* 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::Type* 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::Type* t) const { return data_type_check(data, t); } -IntrusivePtr bro_broker::DataVal::castTo(BroType* t) +IntrusivePtr bro_broker::DataVal::castTo(zeek::Type* 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..8045c86b28 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::Type* 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::Type* t); + bool canCastTo(zeek::Type* 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,20 @@ 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()) {} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + broker::set dat; broker::set::iterator it; @@ -250,12 +258,20 @@ 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()) {} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + broker::table dat; broker::table::iterator it; @@ -270,12 +286,20 @@ 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()) {} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + broker::vector dat; broker::vector::iterator it; @@ -290,12 +314,20 @@ 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()) {} +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + 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..30f917546a 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -23,7 +23,8 @@ class Frame; class Func; -class VectorType; + +ZEEK_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 186bb519ba..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. @@ -50,7 +50,7 @@ inline IntrusivePtr query_result(IntrusivePtr data) */ class StoreQueryCallback { public: - StoreQueryCallback(trigger::Trigger* arg_trigger, const CallExpr* arg_call, + StoreQueryCallback(zeek::detail::trigger::Trigger* arg_trigger, const zeek::detail::CallExpr* arg_call, broker::store store) : trigger(arg_trigger), call(arg_call), store(std::move(store)) { @@ -83,8 +83,8 @@ public: private: - trigger::Trigger* trigger; - const CallExpr* call; + zeek::detail::trigger::Trigger* trigger; + const zeek::detail::CallExpr* call; broker::store store; }; 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..f135388d88 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::Type* 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/Component.cc b/src/file_analysis/Component.cc index b2a55ce53d..1372a8eedf 100644 --- a/src/file_analysis/Component.cc +++ b/src/file_analysis/Component.cc @@ -9,7 +9,7 @@ using namespace file_analysis; Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t subtype) - : plugin::Component(plugin::component::FILE_ANALYZER, name), + : zeek::plugin::Component(zeek::plugin::component::FILE_ANALYZER, name), plugin::TaggedComponent(subtype) { factory = arg_factory; @@ -17,7 +17,7 @@ Component::Component(const std::string& name, factory_callback arg_factory, Tag: } Component::Component(const std::string& name, factory_function arg_factory, Tag::subtype_t subtype) - : plugin::Component(plugin::component::FILE_ANALYZER, name), + : zeek::plugin::Component(zeek::plugin::component::FILE_ANALYZER, name), plugin::TaggedComponent(subtype) { factory = nullptr; diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 1bf5efe7ff..98ac262127 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -22,7 +22,7 @@ class Manager; * A plugin can provide a specific file analyzer by registering this * analyzer component, describing the analyzer. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(RecordVal* args, File* file); 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..0eacf90a6b 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; +ZEEK_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/Tag.h b/src/file_analysis/Tag.h index 8c434e20e6..e2a1e1a1d8 100644 --- a/src/file_analysis/Tag.h +++ b/src/file_analysis/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace file_analysis { @@ -90,8 +96,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/file_analysis/analyzer/data_event/Plugin.cc b/src/file_analysis/analyzer/data_event/Plugin.cc index 31330e1aca..e90e628c4e 100644 --- a/src/file_analysis/analyzer/data_event/Plugin.cc +++ b/src/file_analysis/analyzer/data_event/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_FileDataEvent { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("DATA_EVENT", ::file_analysis::DataEvent::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::FileDataEvent"; config.description = "Delivers file content"; return config; 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/entropy/Plugin.cc b/src/file_analysis/analyzer/entropy/Plugin.cc index 1cf3b011fa..1592ce7a95 100644 --- a/src/file_analysis/analyzer/entropy/Plugin.cc +++ b/src/file_analysis/analyzer/entropy/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_FileEntropy { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("ENTROPY", ::file_analysis::Entropy::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::FileEntropy"; config.description = "Entropy test file content"; return config; diff --git a/src/file_analysis/analyzer/extract/Plugin.cc b/src/file_analysis/analyzer/extract/Plugin.cc index d8f90bfd9d..8b9d442c40 100644 --- a/src/file_analysis/analyzer/extract/Plugin.cc +++ b/src/file_analysis/analyzer/extract/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_FileExtract { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("EXTRACT", ::file_analysis::Extract::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::FileExtract"; config.description = "Extract file content"; return config; diff --git a/src/file_analysis/analyzer/hash/Plugin.cc b/src/file_analysis/analyzer/hash/Plugin.cc index b557a03e04..e7c09c5417 100644 --- a/src/file_analysis/analyzer/hash/Plugin.cc +++ b/src/file_analysis/analyzer/hash/Plugin.cc @@ -7,15 +7,15 @@ namespace plugin { namespace Zeek_FileHash { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("MD5", ::file_analysis::MD5::Instantiate)); AddComponent(new ::file_analysis::Component("SHA1", ::file_analysis::SHA1::Instantiate)); AddComponent(new ::file_analysis::Component("SHA256", ::file_analysis::SHA256::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::FileHash"; config.description = "Hash file content"; return config; diff --git a/src/file_analysis/analyzer/pe/Plugin.cc b/src/file_analysis/analyzer/pe/Plugin.cc index 567d00e920..5e7800c9c7 100644 --- a/src/file_analysis/analyzer/pe/Plugin.cc +++ b/src/file_analysis/analyzer/pe/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_PE { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("PE", ::file_analysis::PE::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::PE"; config.description = "Portable Executable analyzer"; return config; diff --git a/src/file_analysis/analyzer/unified2/Plugin.cc b/src/file_analysis/analyzer/unified2/Plugin.cc index 5cc60f7799..2e33ed0881 100644 --- a/src/file_analysis/analyzer/unified2/Plugin.cc +++ b/src/file_analysis/analyzer/unified2/Plugin.cc @@ -9,13 +9,13 @@ namespace plugin { namespace Zeek_Unified2 { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("UNIFIED2", ::file_analysis::Unified2::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Unified2"; config.description = "Analyze Unified2 alert files."; return config; 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/Plugin.cc b/src/file_analysis/analyzer/x509/Plugin.cc index 221816fca5..e52be3f8d5 100644 --- a/src/file_analysis/analyzer/x509/Plugin.cc +++ b/src/file_analysis/analyzer/x509/Plugin.cc @@ -8,15 +8,15 @@ namespace plugin { namespace Zeek_X509 { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::file_analysis::Component("X509", ::file_analysis::X509::Instantiate)); AddComponent(new ::file_analysis::Component("OCSP_REQUEST", ::file_analysis::OCSP::InstantiateRequest)); AddComponent(new ::file_analysis::Component("OCSP_REPLY", ::file_analysis::OCSP::InstantiateReply)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::X509"; config.description = "X509 and OCSP analyzer"; return config; @@ -24,7 +24,7 @@ public: void Done() override { - plugin::Plugin::Done(); + zeek::plugin::Plugin::Done(); ::file_analysis::X509::FreeRootStore(); } } plugin; diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index dc48b0a6d3..a5cd0a1ce2 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -395,7 +395,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.h b/src/input.h index 70aa75ae28..2aacbea9a8 100644 --- a/src/input.h +++ b/src/input.h @@ -22,7 +22,7 @@ extern void add_to_name_list(char* s, char delim, name_list& nl); extern void begin_RE(); -extern void do_atif(Expr* expr); +extern void do_atif(zeek::detail::Expr* expr); extern void do_atifdef(const char* id); extern void do_atifndef(const char* id); extern void do_atelse(); @@ -41,5 +41,5 @@ extern std::vector zeek_script_prefixes; // -p flag extern const char* command_line_policy; // -e flag extern std::vector params; -class Stmt; -extern Stmt* stmts; // global statements +ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); +extern zeek::detail::Stmt* stmts; // global statements diff --git a/src/input/Component.cc b/src/input/Component.cc index dbca5a2cf3..db6a127b2f 100644 --- a/src/input/Component.cc +++ b/src/input/Component.cc @@ -9,7 +9,7 @@ using namespace input; Component::Component(const std::string& name, factory_callback arg_factory) - : plugin::Component(plugin::component::READER, name) + : zeek::plugin::Component(zeek::plugin::component::READER, name) { factory = arg_factory; } @@ -29,4 +29,3 @@ void Component::DoDescribe(ODesc* d) const d->Add("Input::READER_"); d->Add(CanonicalName()); } - diff --git a/src/input/Component.h b/src/input/Component.h index 2e6b55bb96..b9aaa8ec76 100644 --- a/src/input/Component.h +++ b/src/input/Component.h @@ -14,7 +14,7 @@ class ReaderBackend; /** * Component description for plugins providing log readers. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef ReaderBackend* (*factory_callback)(ReaderFrontend* frontend); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 73474353c8..1664b54f09 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::Type* 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,12 +879,11 @@ 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++ ) { - if ( ! IsCompatibleType(rec->GetFieldType(i).get()) ) { string name = nameprepend + rec->FieldName(i); @@ -894,25 +893,26 @@ 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 ) && - rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) + 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) + "."; - if ( rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL) ) + if ( rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL) ) { reporter->Info("The input framework does not support optional record fields: \"%s\"", rec->FieldName(i)); return false; @@ -930,30 +930,30 @@ 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 && - rec->FieldDecl(i)->GetAttr(ATTR_TYPE_COLUMN) ) + else if ( ty == zeek::TYPE_PORT && + rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_TYPE_COLUMN) ) { // we have an annotation for the second column - c = rec->FieldDecl(i)->GetAttr(ATTR_TYPE_COLUMN)->GetExpr()->Eval(nullptr); + 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(); } - if ( rec->FieldDecl(i)->GetAttr(ATTR_OPTIONAL ) ) + if ( rec->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL ) ) optional = true; Field* field = new Field(name.c_str(), secondary, ty, st, optional); @@ -993,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)); @@ -1014,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 @@ -1072,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); @@ -1439,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); @@ -1480,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); @@ -1817,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; @@ -1831,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 { @@ -1847,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. @@ -1855,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. @@ -1867,7 +1867,7 @@ RecordVal* Manager::ValueToRecordVal(const Stream* stream, const Value* const *v // Hence -> assign null to the field, done. // Better check that it really is optional. Uou never know. - assert(request_type->FieldDecl(i)->GetAttr(ATTR_OPTIONAL)); + assert(request_type->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL)); } else { @@ -1890,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: @@ -1933,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: @@ -1950,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++ ) @@ -1986,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), @@ -2009,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 @@ -2026,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 ) { @@ -2047,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 ) { @@ -2075,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; @@ -2083,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; @@ -2093,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; @@ -2159,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::Type* 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; @@ -2174,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 ) { @@ -2223,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 ) { @@ -2244,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++ ) { @@ -2269,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++ ) @@ -2285,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..8f5d7df3f6 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::Type* 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::Type* 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/Tag.h b/src/input/Tag.h index 20a163da23..b4aa4b11f7 100644 --- a/src/input/Tag.h +++ b/src/input/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace input { @@ -91,8 +97,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. 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..3f7b04808b 100644 --- a/src/input/readers/ascii/Ascii.h +++ b/src/input/readers/ascii/Ascii.h @@ -16,14 +16,28 @@ 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); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + FieldMapping(const FieldMapping& arg); FieldMapping() { position = -1; secondary_position = -1; } diff --git a/src/input/readers/ascii/Plugin.cc b/src/input/readers/ascii/Plugin.cc index 365d7370e7..296d6bdd2e 100644 --- a/src/input/readers/ascii/Plugin.cc +++ b/src/input/readers/ascii/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_AsciiReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::input::Component("Ascii", ::input::reader::Ascii::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::AsciiReader"; config.description = "ASCII input reader"; return config; 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/benchmark/Plugin.cc b/src/input/readers/benchmark/Plugin.cc index 8a75149c60..ce81218f54 100644 --- a/src/input/readers/benchmark/Plugin.cc +++ b/src/input/readers/benchmark/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_BenchmarkReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::input::Component("Benchmark", ::input::reader::Benchmark::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::BenchmarkReader"; config.description = "Benchmark input reader"; return config; 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/binary/Plugin.cc b/src/input/readers/binary/Plugin.cc index f39d85ca9a..c258d20549 100644 --- a/src/input/readers/binary/Plugin.cc +++ b/src/input/readers/binary/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_BinaryReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::input::Component("Binary", ::input::reader::Binary::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::BinaryReader"; config.description = "Binary input reader"; return config; diff --git a/src/input/readers/config/Config.cc b/src/input/readers/config/Config.cc index 2416ff7af0..56d93fcfb0 100644 --- a/src/input/readers/config/Config.cc +++ b/src/input/readers/config/Config.cc @@ -31,22 +31,22 @@ Config::Config(ReaderFrontend *frontend) : ReaderBackend(frontend) for ( const auto& entry : globals ) { - ID* id = entry.second.get(); + auto& id = entry.second; 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/config/Plugin.cc b/src/input/readers/config/Plugin.cc index 72ccc7f8af..8ea2c115ed 100644 --- a/src/input/readers/config/Plugin.cc +++ b/src/input/readers/config/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_ConfigReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::input::Component("Config", ::input::reader::Config::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::ConfigReader"; config.description = "Configuration file input reader"; return config; diff --git a/src/input/readers/raw/Plugin.cc b/src/input/readers/raw/Plugin.cc index d5b17cd62f..ae25c62850 100644 --- a/src/input/readers/raw/Plugin.cc +++ b/src/input/readers/raw/Plugin.cc @@ -10,11 +10,11 @@ Plugin::Plugin() { } -plugin::Configuration Plugin::Configure() +zeek::plugin::Configuration Plugin::Configure() { AddComponent(new ::input::Component("Raw", ::input::reader::Raw::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::RawReader"; config.description = "Raw input reader"; return config; diff --git a/src/input/readers/raw/Plugin.h b/src/input/readers/raw/Plugin.h index 16f76ad3d6..86fded2575 100644 --- a/src/input/readers/raw/Plugin.h +++ b/src/input/readers/raw/Plugin.h @@ -11,11 +11,11 @@ namespace plugin { namespace Zeek_RawReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: Plugin(); - plugin::Configuration Configure() override; + zeek::plugin::Configuration Configure() override; void InitPreScript() override; void Done() override; 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/Plugin.cc b/src/input/readers/sqlite/Plugin.cc index 4ab173394d..5b5a296263 100644 --- a/src/input/readers/sqlite/Plugin.cc +++ b/src/input/readers/sqlite/Plugin.cc @@ -7,13 +7,13 @@ namespace plugin { namespace Zeek_SQLiteReader { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::input::Component("SQLite", ::input::reader::SQLite::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SQLiteReader"; config.description = "SQLite input reader"; return config; 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/Component.cc b/src/iosource/Component.cc index 1d8a431df5..b4cd06ce2f 100644 --- a/src/iosource/Component.cc +++ b/src/iosource/Component.cc @@ -8,21 +8,29 @@ using namespace iosource; Component::Component(const std::string& name) - : plugin::Component(plugin::component::IOSOURCE, name) + : zeek::plugin::Component(zeek::plugin::component::IOSOURCE, name) { } -Component::Component(plugin::component::Type type, const std::string& name) +Component::Component(zeek::plugin::component::Type type, const std::string& name) : plugin::Component(type, name) { } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +Component::Component(plugin::component::Type type, const std::string& name) + : plugin::Component(static_cast(type), name) + { + } +#pragma GCC diagnostic pop + Component::~Component() { } PktSrcComponent::PktSrcComponent(const std::string& arg_name, const std::string& arg_prefix, InputType arg_type, factory_callback arg_factory) - : iosource::Component(plugin::component::PKTSRC, arg_name) + : iosource::Component(zeek::plugin::component::PKTSRC, arg_name) { tokenize_string(arg_prefix, ":", &prefixes); type = arg_type; @@ -108,7 +116,7 @@ void PktSrcComponent::DoDescribe(ODesc* d) const } PktDumperComponent::PktDumperComponent(const std::string& name, const std::string& arg_prefix, factory_callback arg_factory) - : plugin::Component(plugin::component::PKTDUMPER, name) + : zeek::plugin::Component(zeek::plugin::component::PKTDUMPER, name) { tokenize_string(arg_prefix, ":", &prefixes); factory = arg_factory; @@ -142,7 +150,7 @@ bool PktDumperComponent::HandlesPrefix(const std::string& prefix) const void PktDumperComponent::DoDescribe(ODesc* d) const { - plugin::Component::DoDescribe(d); + zeek::plugin::Component::DoDescribe(d); std::string prefs; diff --git a/src/iosource/Component.h b/src/iosource/Component.h index 9d8367ac0a..878d202ac9 100644 --- a/src/iosource/Component.h +++ b/src/iosource/Component.h @@ -16,7 +16,7 @@ class PktDumper; /** * Component description for plugins providing IOSources. */ -class Component : public plugin::Component { +class Component : public zeek::plugin::Component { public: typedef IOSource* (*factory_callback)(); @@ -34,6 +34,7 @@ public: ~Component() override; protected: + /** * Constructor to use by derived classes. * @@ -42,7 +43,21 @@ protected: * @param name A descriptive name for the component. This name must * be unique across all components of this type. */ + Component(zeek::plugin::component::Type type, const std::string& name); + + /** + * Constructor to use by derived classes. + * + * @param type The type of the componnent. + * + * @param name A descriptive name for the component. This name must + * be unique across all components of this type. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::component::Type instead")]] Component(plugin::component::Type type, const std::string& name); +#pragma GCC diagnostic pop }; /** @@ -126,7 +141,7 @@ private: * PktDumpers aren't IOSurces but we locate them here to keep them along with * the PktSrc. */ -class PktDumperComponent : public plugin::Component { +class PktDumperComponent : public zeek::plugin::Component { public: typedef PktDumper* (*factory_callback)(const std::string& path, bool append); diff --git a/src/iosource/Manager.h b/src/iosource/Manager.h index af6f62ce77..bd875f5fae 100644 --- a/src/iosource/Manager.h +++ b/src/iosource/Manager.h @@ -178,7 +178,7 @@ private: double GetNextTimeout() override { return -1; } private: - bro::Flare flare; + zeek::detail::Flare flare; }; struct Source { 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/iosource/pcap/Plugin.cc b/src/iosource/pcap/Plugin.cc index 66249ef132..388645a598 100644 --- a/src/iosource/pcap/Plugin.cc +++ b/src/iosource/pcap/Plugin.cc @@ -8,14 +8,14 @@ namespace plugin { namespace Zeek_Pcap { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::iosource::PktSrcComponent("PcapReader", "pcap", ::iosource::PktSrcComponent::BOTH, ::iosource::pcap::PcapSource::Instantiate)); AddComponent(new ::iosource::PktDumperComponent("PcapWriter", "pcap", ::iosource::pcap::PcapDumper::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::Pcap"; config.description = "Packet acquisition via libpcap"; return config; diff --git a/src/logging/Component.cc b/src/logging/Component.cc index 570cccb8d7..b100ce2583 100644 --- a/src/logging/Component.cc +++ b/src/logging/Component.cc @@ -8,7 +8,7 @@ using namespace logging; Component::Component(const std::string& name, factory_callback arg_factory) - : plugin::Component(plugin::component::WRITER, name) + : zeek::plugin::Component(zeek::plugin::component::WRITER, name) { factory = arg_factory; } diff --git a/src/logging/Component.h b/src/logging/Component.h index b80ae5f0b2..600f6a8438 100644 --- a/src/logging/Component.h +++ b/src/logging/Component.h @@ -14,7 +14,7 @@ class WriterBackend; /** * Component description for plugins providing log writers. */ -class Component : public plugin::Component, +class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef WriterBackend* (*factory_callback)(WriterFrontend* frontend); diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 434c25304f..1547c5bd55 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,14 +236,14 @@ 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; for ( int i = 0; i < columns->NumFields(); i++ ) { - if ( ! (columns->FieldDecl(i)->GetAttr(ATTR_LOG)) ) + if ( ! (columns->FieldDecl(i)->GetAttr(zeek::detail::ATTR_LOG)) ) continue; if ( ! threading::Value::IsCompatibleType(columns->GetFieldType(i).get()) ) @@ -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 ) { @@ -411,7 +411,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, const auto& t = rtype->GetFieldType(i); // Ignore if &log not specified. - if ( ! rtype->FieldDecl(i)->GetAttr(ATTR_LOG) ) + if ( ! rtype->FieldDecl(i)->GetAttr(zeek::detail::ATTR_LOG) ) continue; list new_indices = indices; @@ -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,15 +509,15 @@ 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(ATTR_OPTIONAL); + bool optional = (bool)rtype->FieldDecl(i)->GetAttr(zeek::detail::ATTR_OPTIONAL); filter->fields[filter->num_fields - 1] = new threading::Field(new_path.c_str(), nullptr, t->Tag(), st, 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::Type* 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..23a61f9d69 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::Type* ty = nullptr); Stream* FindStream(EnumVal* id); void RemoveDisabledWriters(Stream* stream); void InstallRotationTimer(WriterInfo* winfo); diff --git a/src/logging/Tag.h b/src/logging/Tag.h index 78aee1a3d0..01cfb4b04e 100644 --- a/src/logging/Tag.h +++ b/src/logging/Tag.h @@ -7,11 +7,17 @@ class EnumVal; +namespace zeek::plugin { + template class TaggedComponent; + template class ComponentManager; +} namespace plugin { -template -class TaggedComponent; -template -class ComponentManager; + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; } namespace logging { @@ -96,8 +102,8 @@ public: static const Tag Error; protected: - friend class plugin::ComponentManager; - friend class plugin::TaggedComponent; + friend class zeek::plugin::ComponentManager; + friend class zeek::plugin::TaggedComponent; /** * Constructor. diff --git a/src/logging/writers/ascii/Plugin.cc b/src/logging/writers/ascii/Plugin.cc index bc9aa80d99..ad41deeaf7 100644 --- a/src/logging/writers/ascii/Plugin.cc +++ b/src/logging/writers/ascii/Plugin.cc @@ -8,13 +8,13 @@ namespace plugin { namespace Zeek_AsciiWriter { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::logging::Component("Ascii", ::logging::writer::Ascii::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::AsciiWriter"; config.description = "ASCII log writer"; return config; 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/none/Plugin.cc b/src/logging/writers/none/Plugin.cc index 92dbcabded..e767fc28d3 100644 --- a/src/logging/writers/none/Plugin.cc +++ b/src/logging/writers/none/Plugin.cc @@ -8,13 +8,13 @@ namespace plugin { namespace Zeek_NoneWriter { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::logging::Component("None", ::logging::writer::None::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::NoneWriter"; config.description = "None log writer (primarily for debugging)"; return config; diff --git a/src/logging/writers/sqlite/Plugin.cc b/src/logging/writers/sqlite/Plugin.cc index a7ddc95472..906407b673 100644 --- a/src/logging/writers/sqlite/Plugin.cc +++ b/src/logging/writers/sqlite/Plugin.cc @@ -8,13 +8,13 @@ namespace plugin { namespace Zeek_SQLiteWriter { -class Plugin : public plugin::Plugin { +class Plugin : public zeek::plugin::Plugin { public: - plugin::Configuration Configure() override + zeek::plugin::Configuration Configure() override { AddComponent(new ::logging::Component("SQLite", ::logging::writer::SQLite::Instantiate)); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Zeek::SQLiteWriter"; config.description = "SQLite log writer"; return config; 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 f2024062c4..d55f3600c0 100644 --- a/src/option.bif +++ b/src/option.bif @@ -7,7 +7,7 @@ module Option; #include "NetVar.h" #include "broker/Data.h" -static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr& i, +static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr& i, IntrusivePtr val, StringVal* location) { @@ -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 59b229bdca..d4781a7ef4 100644 --- a/src/parse.y +++ b/src/parse.y @@ -121,7 +121,7 @@ bool is_export = false; // true if in an export {} block * When parsing an expression for the debugger, where to put the result * (obviously not reentrant). */ -extern Expr* g_curr_debug_expr; +extern zeek::detail::Expr* g_curr_debug_expr; extern bool in_debug; extern const char* g_curr_debug_error; @@ -135,41 +135,41 @@ bool defining_global_ID = false; std::vector saved_in_init; static Location func_hdr_location; -EnumType *cur_enum_type = 0; -static 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"); } -static void parser_redef_enum (ID *id) +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(ID* id, std::unique_ptr fields, - std::unique_ptr>> attrs) +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::Type::GetAliases(id->Name()); if ( types.empty() ) { @@ -181,7 +181,7 @@ static void extend_record(ID* id, std::unique_ptr fields, if ( attrs ) for ( const auto& at : *attrs ) - if ( at->Tag() == ATTR_LOG ) + if ( at->Tag() == zeek::detail::ATTR_LOG ) { add_log_attr = true; break; @@ -199,22 +199,22 @@ static void extend_record(ID* id, std::unique_ptr fields, } } -static IntrusivePtr -make_attributes(std::vector>* attrs, - IntrusivePtr t, bool in_record, bool is_global) +static IntrusivePtr +make_attributes(std::vector>* attrs, + IntrusivePtr t, bool in_record, bool is_global) { if ( ! attrs ) return nullptr; - auto rval = make_intrusive(std::move(*attrs), std::move(t), + auto rval = make_intrusive(std::move(*attrs), std::move(t), in_record, is_global); delete attrs; return rval; } -static bool expr_is_table_type_name(const Expr* expr) +static bool expr_is_table_type_name(const zeek::detail::Expr* expr) { - if ( expr->Tag() != EXPR_NAME ) + if ( expr->Tag() != zeek::detail::EXPR_NAME ) return false; const auto& type = expr->GetType(); @@ -222,7 +222,7 @@ static bool expr_is_table_type_name(const 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; @@ -232,26 +232,26 @@ static bool expr_is_table_type_name(const Expr* expr) %union { bool b; char* str; - ID* id; + zeek::detail::ID* id; id_list* id_l; - init_class ic; + zeek::detail::init_class ic; Val* val; RE_Matcher* re; - Expr* expr; - EventExpr* event_expr; - Stmt* stmt; - ListExpr* list; - BroType* type; - RecordType* record; - FuncType* func_type; - TypeList* type_l; - TypeDecl* type_decl; - type_decl_list* type_decl_l; - Case* c_case; - case_list* case_l; - Attr* attr; - std::vector>* attr_l; - attr_tag attrtag; + zeek::detail::Expr* expr; + zeek::detail::EventExpr* event_expr; + zeek::detail::Stmt* stmt; + zeek::detail::ListExpr* list; + zeek::Type* 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; + std::vector>* attr_l; + zeek::detail::attr_tag attrtag; } %% @@ -300,169 +300,169 @@ expr: | TOK_COPY '(' expr ')' { set_location(@1, @4); - $$ = new CloneExpr({AdoptRef{}, $3}); + $$ = new zeek::detail::CloneExpr({AdoptRef{}, $3}); } | TOK_INCR expr { set_location(@1, @2); - $$ = new IncrExpr(EXPR_INCR, {AdoptRef{}, $2}); + $$ = new zeek::detail::IncrExpr(zeek::detail::EXPR_INCR, {AdoptRef{}, $2}); } | TOK_DECR expr { set_location(@1, @2); - $$ = new IncrExpr(EXPR_DECR, {AdoptRef{}, $2}); + $$ = new zeek::detail::IncrExpr(zeek::detail::EXPR_DECR, {AdoptRef{}, $2}); } | '!' expr { set_location(@1, @2); - $$ = new NotExpr({AdoptRef{}, $2}); + $$ = new zeek::detail::NotExpr({AdoptRef{}, $2}); } | '~' expr { set_location(@1, @2); - $$ = new ComplementExpr({AdoptRef{}, $2}); + $$ = new zeek::detail::ComplementExpr({AdoptRef{}, $2}); } | '-' expr %prec '!' { set_location(@1, @2); - $$ = new NegExpr({AdoptRef{}, $2}); + $$ = new zeek::detail::NegExpr({AdoptRef{}, $2}); } | '+' expr %prec '!' { set_location(@1, @2); - $$ = new PosExpr({AdoptRef{}, $2}); + $$ = new zeek::detail::PosExpr({AdoptRef{}, $2}); } | expr '+' expr { set_location(@1, @3); - $$ = new AddExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::AddExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_ADD_TO expr { set_location(@1, @3); - $$ = new AddToExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::AddToExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '-' expr { set_location(@1, @3); - $$ = new SubExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::SubExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_REMOVE_FROM expr { set_location(@1, @3); - $$ = new RemoveFromExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::RemoveFromExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '*' expr { set_location(@1, @3); - $$ = new TimesExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::TimesExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '/' expr { set_location(@1, @3); - $$ = new DivideExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::DivideExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '%' expr { set_location(@1, @3); - $$ = new ModExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::ModExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '&' expr { set_location(@1, @3); - $$ = new BitExpr(EXPR_AND, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::BitExpr(zeek::detail::EXPR_AND, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '|' expr { set_location(@1, @3); - $$ = new BitExpr(EXPR_OR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::BitExpr(zeek::detail::EXPR_OR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '^' expr { set_location(@1, @3); - $$ = new BitExpr(EXPR_XOR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::BitExpr(zeek::detail::EXPR_XOR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_AND_AND expr { set_location(@1, @3); - $$ = new BoolExpr(EXPR_AND_AND, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::BoolExpr(zeek::detail::EXPR_AND_AND, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_OR_OR expr { set_location(@1, @3); - $$ = new BoolExpr(EXPR_OR_OR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::BoolExpr(zeek::detail::EXPR_OR_OR, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_EQ expr { set_location(@1, @3); - $$ = new EqExpr(EXPR_EQ, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::EqExpr(zeek::detail::EXPR_EQ, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_NE expr { set_location(@1, @3); - $$ = new EqExpr(EXPR_NE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::EqExpr(zeek::detail::EXPR_NE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '<' expr { set_location(@1, @3); - $$ = new RelExpr(EXPR_LT, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::RelExpr(zeek::detail::EXPR_LT, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_LE expr { set_location(@1, @3); - $$ = new RelExpr(EXPR_LE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::RelExpr(zeek::detail::EXPR_LE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '>' expr { set_location(@1, @3); - $$ = new RelExpr(EXPR_GT, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::RelExpr(zeek::detail::EXPR_GT, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_GE expr { set_location(@1, @3); - $$ = new RelExpr(EXPR_GE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::RelExpr(zeek::detail::EXPR_GE, {AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr '?' expr ':' expr { set_location(@1, @5); - $$ = new CondExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}, {AdoptRef{}, $5}); + $$ = new zeek::detail::CondExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}, {AdoptRef{}, $5}); } | expr '=' expr { set_location(@1, @3); - if ( $1->Tag() == EXPR_INDEX && $1->AsIndexExpr()->IsSlice() ) + if ( $1->Tag() == zeek::detail::EXPR_INDEX && $1->AsIndexExpr()->IsSlice() ) reporter->Error("index slice assignment may not be used" " in arbitrary expression contexts, only" " as a statement"); - $$ = get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init).release(); + $$ = zeek::detail::get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init).release(); } | TOK_LOCAL local_id '=' expr @@ -475,7 +475,7 @@ expr: | expr '[' expr_list ']' { set_location(@1, @4); - $$ = new IndexExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::IndexExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | index_slice @@ -483,13 +483,13 @@ expr: | expr '$' TOK_ID { set_location(@1, @3); - $$ = new FieldExpr({AdoptRef{}, $1}, $3); + $$ = new zeek::detail::FieldExpr({AdoptRef{}, $1}, $3); } | '$' TOK_ID '=' expr { set_location(@1, @4); - $$ = new FieldAssignExpr($2, {AdoptRef{}, $4}); + $$ = new zeek::detail::FieldAssignExpr($2, {AdoptRef{}, $4}); } | '$' TOK_ID func_params '=' @@ -498,26 +498,26 @@ 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 { - $$ = new FieldAssignExpr($2, IntrusivePtr{AdoptRef{}, $6}); + $$ = new zeek::detail::FieldAssignExpr($2, IntrusivePtr{AdoptRef{}, $6}); } | expr TOK_IN expr { set_location(@1, @3); - $$ = new InExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::InExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_NOT_IN expr { set_location(@1, @3); - $$ = new NotExpr(make_intrusive( - IntrusivePtr{AdoptRef{}, $1}, - IntrusivePtr{AdoptRef{}, $3})); + $$ = new zeek::detail::NotExpr(make_intrusive( + IntrusivePtr{AdoptRef{}, $1}, + IntrusivePtr{AdoptRef{}, $3})); } | '[' expr_list ']' @@ -532,7 +532,7 @@ expr: for ( int i = 0; i < $2->Exprs().length(); ++i ) { - if ( $2->Exprs()[i]->Tag() != EXPR_FIELD_ASSIGN ) + if ( $2->Exprs()[i]->Tag() != zeek::detail::EXPR_FIELD_ASSIGN ) { is_record_ctor = false; break; @@ -540,7 +540,7 @@ expr: } if ( is_record_ctor ) - $$ = new RecordConstructorExpr({AdoptRef{}, $2}); + $$ = new zeek::detail::RecordConstructorExpr({AdoptRef{}, $2}); else $$ = $2; } @@ -548,35 +548,35 @@ expr: | '[' ']' { // We interpret this as an empty record constructor. - $$ = new RecordConstructorExpr(make_intrusive()); + $$ = new zeek::detail::RecordConstructorExpr(make_intrusive()); } | TOK_RECORD '(' expr_list ')' { set_location(@1, @4); - $$ = new RecordConstructorExpr({AdoptRef{}, $3}); + $$ = new zeek::detail::RecordConstructorExpr({AdoptRef{}, $3}); } | TOK_TABLE '(' { ++in_init; } opt_expr_list ')' { --in_init; } opt_attr { // the ++in_init fixes up the parsing of "[x] = y" set_location(@1, @5); - std::unique_ptr>> attrs{$7}; - $$ = new TableConstructorExpr({AdoptRef{}, $4}, std::move(attrs)); + std::unique_ptr>> attrs{$7}; + $$ = new zeek::detail::TableConstructorExpr({AdoptRef{}, $4}, std::move(attrs)); } | TOK_SET '(' opt_expr_list ')' opt_attr { set_location(@1, @4); - std::unique_ptr>> attrs{$5}; - $$ = new SetConstructorExpr({AdoptRef{}, $3}, std::move(attrs)); + std::unique_ptr>> attrs{$5}; + $$ = new zeek::detail::SetConstructorExpr({AdoptRef{}, $3}, std::move(attrs)); } | TOK_VECTOR '(' opt_expr_list ')' { set_location(@1, @4); - $$ = new VectorConstructorExpr({AdoptRef{}, $3}); + $$ = new zeek::detail::VectorConstructorExpr({AdoptRef{}, $3}); } | expr '(' @@ -595,30 +595,30 @@ expr: { set_location(@1, @6); - if ( $1->Tag() == EXPR_NAME && $1->AsNameExpr()->Id()->IsType() ) + if ( $1->Tag() == zeek::detail::EXPR_NAME && $1->AsNameExpr()->Id()->IsType() ) { 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); - $$ = new RecordCoerceExpr(std::move(rce), std::move(rt)); + auto rce = make_intrusive( + IntrusivePtr{AdoptRef{}, $4}); + 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 TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); + $$ = new zeek::detail::TableConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); else - $$ = new SetConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); + $$ = new zeek::detail::SetConstructorExpr({AdoptRef{}, $4}, 0, ctor_type); break; - case TYPE_VECTOR: - $$ = new VectorConstructorExpr({AdoptRef{}, $4}, ctor_type); + case zeek::TYPE_VECTOR: + $$ = new zeek::detail::VectorConstructorExpr({AdoptRef{}, $4}, ctor_type); break; default: @@ -628,14 +628,14 @@ expr: } else - $$ = new CallExpr({AdoptRef{}, $1}, {AdoptRef{}, $4}, in_hook > 0); + $$ = new zeek::detail::CallExpr({AdoptRef{}, $1}, {AdoptRef{}, $4}, in_hook > 0); } | TOK_HOOK { ++in_hook; } expr { --in_hook; set_location(@1, @3); - if ( $3->Tag() != EXPR_CALL ) + if ( $3->Tag() != zeek::detail::EXPR_CALL ) $3->Error("not a valid hook call expression"); $$ = $3; } @@ -643,7 +643,7 @@ expr: | expr TOK_HAS_FIELD TOK_ID { set_location(@1, @3); - $$ = new HasFieldExpr({AdoptRef{}, $1}, $3); + $$ = new zeek::detail::HasFieldExpr({AdoptRef{}, $1}, $3); } | anonymous_function @@ -652,7 +652,7 @@ expr: | TOK_SCHEDULE expr '{' event '}' { set_location(@1, @5); - $$ = new ScheduleExpr({AdoptRef{}, $2}, {AdoptRef{}, $4}); + $$ = new zeek::detail::ScheduleExpr({AdoptRef{}, $2}, {AdoptRef{}, $4}); } | TOK_ID @@ -686,22 +686,22 @@ expr: if ( ! id->GetType() ) { id->Error("undeclared variable"); - id->SetType(error_type()); - $$ = new NameExpr(std::move(id)); + 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 ) reporter->InternalError("enum value not found for %s", id->Name()); - $$ = new ConstExpr(t->GetVal(intval)); + $$ = new zeek::detail::ConstExpr(t->GetVal(intval)); } else { - $$ = new NameExpr(std::move(id)); + $$ = new zeek::detail::NameExpr(std::move(id)); } } } @@ -709,7 +709,7 @@ expr: | TOK_CONSTANT { set_location(@1); - $$ = new ConstExpr({AdoptRef{}, $1}); + $$ = new zeek::detail::ConstExpr({AdoptRef{}, $1}); } | '/' { begin_RE(); } TOK_PATTERN_TEXT TOK_PATTERN_END @@ -723,30 +723,30 @@ expr: re->MakeCaseInsensitive(); re->Compile(); - $$ = new ConstExpr(make_intrusive(re)); + $$ = new zeek::detail::ConstExpr(make_intrusive(re)); } | '|' expr '|' %prec '(' { set_location(@1, @3); - IntrusivePtr e{AdoptRef{}, $2}; + 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 SizeExpr(std::move(e)); + $$ = new zeek::detail::SizeExpr(std::move(e)); } | expr TOK_AS type { set_location(@1, @3); - $$ = new CastExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::CastExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } | expr TOK_IS type { set_location(@1, @3); - $$ = new IsExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); + $$ = new zeek::detail::IsExpr({AdoptRef{}, $1}, {AdoptRef{}, $3}); } ; @@ -760,27 +760,27 @@ expr_list: | expr { set_location(@1); - $$ = new ListExpr({AdoptRef{}, $1}); + $$ = new zeek::detail::ListExpr({AdoptRef{}, $1}); } ; opt_expr_list: expr_list | - { $$ = new ListExpr(); } + { $$ = new zeek::detail::ListExpr(); } ; 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,41 +963,41 @@ 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 { if ( ! $1 || ! ($$ = $1->IsType() ? $1->GetType().get() : nullptr) ) { - NullStmt here; + 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)); } ; @@ -1083,7 +1083,7 @@ decl: { IntrusivePtr id{AdoptRef{}, $2}; add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_REGULAR); zeekygen_mgr->Identifier(std::move(id)); } @@ -1092,7 +1092,7 @@ decl: { IntrusivePtr id{AdoptRef{}, $2}; add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_OPTION); zeekygen_mgr->Identifier(std::move(id)); } @@ -1101,7 +1101,7 @@ decl: { IntrusivePtr id{AdoptRef{}, $2}; add_global(id, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_CONST); zeekygen_mgr->Identifier(std::move(id)); } @@ -1109,9 +1109,9 @@ decl: | TOK_REDEF global_id opt_type init_class opt_init opt_attr ';' { IntrusivePtr id{AdoptRef{}, $2}; - IntrusivePtr init{AdoptRef{}, $5}; + IntrusivePtr init{AdoptRef{}, $5}; add_global(id, {AdoptRef{}, $3}, $4, init, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_REDEF); zeekygen_mgr->Redef(id.get(), ::filename, $4, std::move(init)); } @@ -1136,8 +1136,8 @@ decl: if ( ! $3->GetType() ) $3->Error("unknown identifier"); else - extend_record($3, std::unique_ptr($8), - std::unique_ptr>>($11)); + extend_record($3, std::unique_ptr($8), + std::unique_ptr>>($11)); } | TOK_TYPE global_id ':' @@ -1147,7 +1147,7 @@ decl: cur_decl_type_id = 0; IntrusivePtr id{AdoptRef{}, $2}; add_type(id.get(), {AdoptRef{}, $5}, - std::unique_ptr>>{$6}); + std::unique_ptr>>{$6}); zeekygen_mgr->Identifier(std::move(id)); } @@ -1180,8 +1180,8 @@ func_hdr: { IntrusivePtr id{AdoptRef{}, $2}; begin_func(id, current_module.c_str(), - FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, - std::unique_ptr>>{$4}); + zeek::FUNC_FLAVOR_FUNCTION, 0, {NewRef{}, $3}, + std::unique_ptr>>{$4}); $$ = $3; zeekygen_mgr->Identifier(std::move(id)); } @@ -1195,24 +1195,24 @@ func_hdr: } begin_func({NewRef{}, $2}, current_module.c_str(), - FUNC_FLAVOR_EVENT, 0, {NewRef{}, $3}, - std::unique_ptr>>{$4}); + 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}, - std::unique_ptr>>{$4}); + 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}, - std::unique_ptr>>{$5}); + zeek::FUNC_FLAVOR_EVENT, 1, {NewRef{}, $4}, + std::unique_ptr>>{$5}); $$ = $4; } ; @@ -1262,7 +1262,7 @@ lambda_body: auto ingredients = std::make_unique(IntrusivePtr{NewRef{}, current_scope()}, IntrusivePtr{AdoptRef{}, $3}); id_list outer_ids = gather_outer_ids(pop_scope().get(), ingredients->body.get()); - $$ = new LambdaExpr(std::move(ingredients), std::move(outer_ids)); + $$ = new zeek::detail::LambdaExpr(std::move(ingredients), std::move(outer_ids)); } ; @@ -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: @@ -1295,10 +1295,10 @@ opt_type: ; init_class: - { $$ = INIT_NONE; } - | '=' { $$ = INIT_FULL; } - | TOK_ADD_TO { $$ = INIT_EXTRA; } - | TOK_REMOVE_FROM { $$ = INIT_REMOVE; } + { $$ = zeek::detail::INIT_NONE; } + | '=' { $$ = zeek::detail::INIT_FULL; } + | TOK_ADD_TO { $$ = zeek::detail::INIT_EXTRA; } + | TOK_REMOVE_FROM { $$ = zeek::detail::INIT_REMOVE; } ; opt_init: @@ -1321,19 +1321,19 @@ index_slice: { set_location(@1, @6); - auto low = $3 ? IntrusivePtr{AdoptRef{}, $3} : - make_intrusive(val_mgr->Count(0)); + auto low = $3 ? IntrusivePtr{AdoptRef{}, $3} : + make_intrusive(val_mgr->Count(0)); - auto high = $5 ? IntrusivePtr{AdoptRef{}, $5} : - make_intrusive( - IntrusivePtr{NewRef{}, $1}); + auto high = $5 ? IntrusivePtr{AdoptRef{}, $5} : + 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)); + auto le = make_intrusive(std::move(low)); le->Append(std::move(high)); - $$ = new IndexExpr({AdoptRef{}, $1}, std::move(le), true); + $$ = new zeek::detail::IndexExpr({AdoptRef{}, $1}, std::move(le), true); } opt_attr: @@ -1347,48 +1347,50 @@ attr_list: { $1->emplace_back(AdoptRef{}, $2); } | attr { - $$ = new std::vector>; + $$ = new std::vector>; $$->emplace_back(AdoptRef{}, $1); } ; attr: TOK_ATTR_DEFAULT '=' expr - { $$ = new Attr(ATTR_DEFAULT, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_DEFAULT, {AdoptRef{}, $3}); } | TOK_ATTR_OPTIONAL - { $$ = new Attr(ATTR_OPTIONAL); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_OPTIONAL); } | TOK_ATTR_REDEF - { $$ = new Attr(ATTR_REDEF); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_REDEF); } | TOK_ATTR_ADD_FUNC '=' expr - { $$ = new Attr(ATTR_ADD_FUNC, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_ADD_FUNC, {AdoptRef{}, $3}); } | TOK_ATTR_DEL_FUNC '=' expr - { $$ = new Attr(ATTR_DEL_FUNC, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_DEL_FUNC, {AdoptRef{}, $3}); } | TOK_ATTR_ON_CHANGE '=' expr - { $$ = new Attr(ATTR_ON_CHANGE, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_ON_CHANGE, {AdoptRef{}, $3}); } | TOK_ATTR_EXPIRE_FUNC '=' expr - { $$ = new Attr(ATTR_EXPIRE_FUNC, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_EXPIRE_FUNC, {AdoptRef{}, $3}); } | TOK_ATTR_EXPIRE_CREATE '=' expr - { $$ = new Attr(ATTR_EXPIRE_CREATE, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_EXPIRE_CREATE, {AdoptRef{}, $3}); } | TOK_ATTR_EXPIRE_READ '=' expr - { $$ = new Attr(ATTR_EXPIRE_READ, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_EXPIRE_READ, {AdoptRef{}, $3}); } | TOK_ATTR_EXPIRE_WRITE '=' expr - { $$ = new Attr(ATTR_EXPIRE_WRITE, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_EXPIRE_WRITE, {AdoptRef{}, $3}); } | TOK_ATTR_RAW_OUTPUT - { $$ = new Attr(ATTR_RAW_OUTPUT); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_RAW_OUTPUT); } | TOK_ATTR_PRIORITY '=' expr - { $$ = new Attr(ATTR_PRIORITY, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_PRIORITY, {AdoptRef{}, $3}); } | TOK_ATTR_TYPE_COLUMN '=' expr - { $$ = new Attr(ATTR_TYPE_COLUMN, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_TYPE_COLUMN, {AdoptRef{}, $3}); } | TOK_ATTR_LOG - { $$ = new Attr(ATTR_LOG); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_LOG); } | TOK_ATTR_ERROR_HANDLER - { $$ = new Attr(ATTR_ERROR_HANDLER); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_ERROR_HANDLER); } | TOK_ATTR_DEPRECATED - { $$ = new Attr(ATTR_DEPRECATED); } + { $$ = new zeek::detail::Attr(zeek::detail::ATTR_DEPRECATED); } | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->GetType()->Tag()) ) - $$ = new Attr(ATTR_DEPRECATED, make_intrusive(IntrusivePtr{AdoptRef{}, $3})); + if ( zeek::IsString($3->GetType()->Tag()) ) + $$ = new zeek::detail::Attr( + zeek::detail::ATTR_DEPRECATED, + make_intrusive(IntrusivePtr{AdoptRef{}, $3})); else { ODesc d; @@ -1396,7 +1398,7 @@ attr: Unref($3); reporter->Error("'&deprecated=%s' must use a string literal", d.Description()); - $$ = new Attr(ATTR_DEPRECATED); + $$ = new zeek::detail::Attr(zeek::detail::ATTR_DEPRECATED); } } ; @@ -1413,7 +1415,7 @@ stmt: | TOK_PRINT expr_list ';' opt_no_test { set_location(@1, @3); - $$ = new PrintStmt(IntrusivePtr{AdoptRef{}, $2}); + $$ = new zeek::detail::PrintStmt(IntrusivePtr{AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1421,7 +1423,7 @@ stmt: | TOK_EVENT event ';' opt_no_test { set_location(@1, @3); - $$ = new EventStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::EventStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1429,19 +1431,19 @@ stmt: | TOK_IF '(' expr ')' stmt { set_location(@1, @4); - $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive()); + $$ = new zeek::detail::IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, make_intrusive()); } | TOK_IF '(' expr ')' stmt TOK_ELSE stmt { set_location(@1, @4); - $$ = new IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7}); + $$ = new zeek::detail::IfStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, {AdoptRef{}, $7}); } | TOK_SWITCH expr '{' case_list '}' { set_location(@1, @2); - $$ = new SwitchStmt({AdoptRef{}, $2}, $4); + $$ = new zeek::detail::SwitchStmt({AdoptRef{}, $2}, $4); } | for_head stmt @@ -1451,13 +1453,13 @@ stmt: | TOK_WHILE '(' expr ')' stmt { - $$ = new WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}); + $$ = new zeek::detail::WhileStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}); } | TOK_NEXT ';' opt_no_test { set_location(@1, @2); - $$ = new NextStmt; + $$ = new zeek::detail::NextStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1465,7 +1467,7 @@ stmt: | TOK_BREAK ';' opt_no_test { set_location(@1, @2); - $$ = new BreakStmt; + $$ = new zeek::detail::BreakStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1473,7 +1475,7 @@ stmt: | TOK_FALLTHROUGH ';' opt_no_test { set_location(@1, @2); - $$ = new FallthroughStmt; + $$ = new zeek::detail::FallthroughStmt; if ( ! $3 ) brofiler.AddStmt($$); } @@ -1481,7 +1483,7 @@ stmt: | TOK_RETURN ';' opt_no_test { set_location(@1, @2); - $$ = new ReturnStmt(0); + $$ = new zeek::detail::ReturnStmt(0); if ( ! $3 ) brofiler.AddStmt($$); } @@ -1489,7 +1491,7 @@ stmt: | TOK_RETURN expr ';' opt_no_test { set_location(@1, @2); - $$ = new ReturnStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::ReturnStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1497,7 +1499,7 @@ stmt: | TOK_ADD expr ';' opt_no_test { set_location(@1, @3); - $$ = new AddStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::AddStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1505,7 +1507,7 @@ stmt: | TOK_DELETE expr ';' opt_no_test { set_location(@1, @3); - $$ = new DelStmt({AdoptRef{}, $2}); + $$ = new zeek::detail::DelStmt({AdoptRef{}, $2}); if ( ! $4 ) brofiler.AddStmt($$); } @@ -1515,7 +1517,7 @@ stmt: set_location(@1, @7); $$ = add_local({AdoptRef{}, $2}, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_REGULAR).release(); if ( ! $8 ) brofiler.AddStmt($$); @@ -1526,7 +1528,7 @@ stmt: set_location(@1, @6); $$ = add_local({AdoptRef{}, $2}, {AdoptRef{}, $3}, $4, {AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>>{$6}, VAR_CONST).release(); if ( ! $8 ) brofiler.AddStmt($$); @@ -1535,15 +1537,15 @@ stmt: | TOK_WHEN '(' expr ')' stmt { set_location(@3, @5); - $$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, - nullptr, nullptr, false); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, + nullptr, nullptr, false); } | TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}' { set_location(@3, @9); - $$ = new WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, - {AdoptRef{}, $10}, {AdoptRef{}, $7}, false); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $3}, {AdoptRef{}, $5}, + {AdoptRef{}, $10}, {AdoptRef{}, $7}, false); if ( $9 ) brofiler.DecIgnoreDepth(); } @@ -1552,15 +1554,15 @@ stmt: | TOK_RETURN TOK_WHEN '(' expr ')' stmt { set_location(@4, @6); - $$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, nullptr, + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, nullptr, nullptr, true); } | TOK_RETURN TOK_WHEN '(' expr ')' stmt TOK_TIMEOUT expr '{' opt_no_test_block stmt_list '}' { set_location(@4, @10); - $$ = new WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, - {AdoptRef{}, $11}, {AdoptRef{}, $8}, true); + $$ = new zeek::detail::WhenStmt({AdoptRef{}, $4}, {AdoptRef{}, $6}, + {AdoptRef{}, $11}, {AdoptRef{}, $8}, true); if ( $10 ) brofiler.DecIgnoreDepth(); } @@ -1568,7 +1570,7 @@ stmt: | index_slice '=' expr ';' opt_no_test { set_location(@1, @4); - $$ = new ExprStmt(get_assign_expr({AdoptRef{}, $1}, + $$ = new zeek::detail::ExprStmt(zeek::detail::get_assign_expr({AdoptRef{}, $1}, {AdoptRef{}, $3}, in_init)); if ( ! $5 ) @@ -1578,7 +1580,7 @@ stmt: | expr ';' opt_no_test { set_location(@1, @2); - $$ = new ExprStmt({AdoptRef{}, $1}); + $$ = new zeek::detail::ExprStmt({AdoptRef{}, $1}); if ( ! $3 ) brofiler.AddStmt($$); } @@ -1586,11 +1588,11 @@ stmt: | ';' { set_location(@1, @1); - $$ = new NullStmt; + $$ = new zeek::detail::NullStmt; } | conditional - { $$ = new NullStmt; } + { $$ = new zeek::detail::NullStmt; } ; stmt_list: @@ -1601,7 +1603,7 @@ stmt_list: $1->UpdateLocationEndInfo(@2); } | - { $$ = new StmtList(); } + { $$ = new zeek::detail::StmtList(); } ; event: @@ -1622,7 +1624,7 @@ event: reporter->Warning("%s", id->GetDeprecationWarning().c_str()); } - $$ = new EventExpr($1, {AdoptRef{}, $3}); + $$ = new zeek::detail::EventExpr($1, {AdoptRef{}, $3}); } ; @@ -1630,18 +1632,18 @@ case_list: case_list case { $1->push_back($2); } | - { $$ = new case_list; } + { $$ = new zeek::detail::case_list; } ; case: TOK_CASE expr_list ':' stmt_list - { $$ = new Case({AdoptRef{}, $2}, 0, {AdoptRef{}, $4}); } + { $$ = new zeek::detail::Case({AdoptRef{}, $2}, 0, {AdoptRef{}, $4}); } | TOK_CASE case_type_list ':' stmt_list - { $$ = new Case(nullptr, $2, {AdoptRef{}, $4}); } + { $$ = new zeek::detail::Case(nullptr, $2, {AdoptRef{}, $4}); } | TOK_DEFAULT ':' stmt_list - { $$ = new Case(nullptr, 0, {AdoptRef{}, $3}); } + { $$ = new zeek::detail::Case(nullptr, 0, {AdoptRef{}, $3}); } ; case_type_list: @@ -1658,14 +1660,14 @@ case_type_list: case_type: TOK_TYPE type { - $$ = new ID(0, SCOPE_FUNCTION, 0); + $$ = new zeek::detail::ID(0, zeek::detail::SCOPE_FUNCTION, 0); $$->SetType({AdoptRef{}, $2}); } | 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() ) @@ -1673,7 +1675,7 @@ case_type: else case_var = install_ID(name, current_module.c_str(), false, false); - add_local(case_var, std::move(type), INIT_NONE, nullptr, nullptr, + add_local(case_var, std::move(type), zeek::detail::INIT_NONE, nullptr, nullptr, VAR_REGULAR); $$ = case_var.release(); } @@ -1704,12 +1706,12 @@ for_head: id_list* loop_vars = new id_list; loop_vars->push_back(loop_var.release()); - $$ = new ForStmt(loop_vars, {AdoptRef{}, $5}); + $$ = new zeek::detail::ForStmt(loop_vars, {AdoptRef{}, $5}); } | TOK_FOR '(' '[' local_id_list ']' TOK_IN expr ')' { - $$ = new ForStmt($4, {AdoptRef{}, $7}); + $$ = new zeek::detail::ForStmt($4, {AdoptRef{}, $7}); } | TOK_FOR '(' TOK_ID ',' TOK_ID TOK_IN expr ')' @@ -1742,7 +1744,7 @@ for_head: id_list* loop_vars = new id_list; loop_vars->push_back(key_var.release()); - $$ = new ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var)); + $$ = new zeek::detail::ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var)); } | TOK_FOR '(' '[' local_id_list ']' ',' TOK_ID TOK_IN expr ')' @@ -1761,7 +1763,7 @@ for_head: else val_var = install_ID($7, module, false, false); - $$ = new ForStmt($4, {AdoptRef{}, $9}, std::move(val_var)); + $$ = new zeek::detail::ForStmt($4, {AdoptRef{}, $9}, std::move(val_var)); } ; @@ -1829,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()); } @@ -1878,19 +1880,19 @@ opt_no_test_block: opt_deprecated: TOK_ATTR_DEPRECATED - { $$ = new ConstExpr(make_intrusive("")); } + { $$ = new zeek::detail::ConstExpr(make_intrusive("")); } | TOK_ATTR_DEPRECATED '=' TOK_CONSTANT { - if ( IsString($3->GetType()->Tag()) ) - $$ = new ConstExpr({AdoptRef{}, $3}); + if ( zeek::IsString($3->GetType()->Tag()) ) + $$ = new zeek::detail::ConstExpr({AdoptRef{}, $3}); else { ODesc d; $3->Describe(&d); reporter->Error("'&deprecated=%s' must use a string literal", d.Description()); - $$ = new ConstExpr(make_intrusive("")); + $$ = new zeek::detail::ConstExpr(make_intrusive("")); } } | diff --git a/src/plugin/Component.cc b/src/plugin/Component.cc index 4ace2f96af..4154cf2add 100644 --- a/src/plugin/Component.cc +++ b/src/plugin/Component.cc @@ -5,7 +5,7 @@ #include "../Desc.h" #include "../Reporter.h" -using namespace plugin; +using namespace zeek::plugin; Component::Component(component::Type arg_type, const std::string& arg_name) { @@ -14,6 +14,16 @@ Component::Component(component::Type arg_type, const std::string& arg_name) canon_name = canonify_name(name); } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +Component::Component(::plugin::component::Type arg_type, const std::string& arg_name) + { + type = static_cast(arg_type); + name = arg_name; + canon_name = canonify_name(name); + } +#pragma GCC diagnostic pop + Component::~Component() { } diff --git a/src/plugin/Component.h b/src/plugin/Component.h index 4b47481935..fd88d8485c 100644 --- a/src/plugin/Component.h +++ b/src/plugin/Component.h @@ -6,7 +6,21 @@ class ODesc; -namespace plugin { +namespace plugin::component { + +enum [[deprecated("Remove in v4.1. Use zeek::plugin::component::Type instead.")]] Type { + READER, /// An input reader (not currently used). + WRITER, /// A logging writer (not currenly used). + ANALYZER, /// A protocol analyzer. + FILE_ANALYZER, /// A file analyzer. + IOSOURCE, /// An I/O source, excluding packet sources. + PKTSRC, /// A packet source. + PKTDUMPER /// A packet dumper. + }; + +} + +namespace zeek::plugin { namespace component { @@ -22,6 +36,7 @@ enum Type { PKTSRC, /// A packet source. PKTDUMPER /// A packet dumper. }; + } /** @@ -42,6 +57,20 @@ public: */ Component(component::Type type, const std::string& name); + /** + * Constructor. + * + * @param type The type of the compoment. + * + * @param name A descriptive name for the component. This name must + * be unique across all components of the same type. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::component::Type instead")]] + Component(::plugin::component::Type type, const std::string& name); +#pragma GCC diagnostic pop + /** * Destructor. */ @@ -104,3 +133,8 @@ private: }; } + +namespace plugin + { + using Component [[deprecated("Remove in v4.1. Use zeek::plugin::Component instead.")]] = zeek::plugin::Component; + } diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 3c66fe9dd7..f503066a51 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -13,7 +13,7 @@ #include "zeekygen/Manager.h" #include "DebugLogger.h" -namespace plugin { +namespace zeek::plugin { /** * A class that manages tracking of plugin components (e.g. analyzers) and @@ -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(); } @@ -267,3 +267,9 @@ void ComponentManager::RegisterComponent(C* component, } } // namespace plugin + +namespace plugin { + template + using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] = + zeek::plugin::ComponentManager; +} diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index 09a3bb5d9f..ae90115c89 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -19,7 +19,7 @@ #include "../input.h" using namespace std; -using namespace plugin; +using namespace zeek::plugin; Plugin* Manager::current_plugin = nullptr; const char* Manager::current_dir = nullptr; @@ -515,28 +515,22 @@ static bool hook_cmp(std::pair a, std::pair b) return a.first > b.first; } -std::list > Manager::HooksEnabledForPlugin(const Plugin* plugin) const +std::list > Manager::HooksEnabledForPlugin(const Plugin* plugin) const { - std::list > enabled; + std::list > enabled; for ( int i = 0; i < NUM_HOOKS; i++ ) { - hook_list* l = hooks[i]; - - if ( ! l ) - continue; - - for ( hook_list::iterator j = l->begin(); j != l->end(); j++ ) - { - if ( (*j).second == plugin ) - enabled.push_back(std::make_pair((HookType)i, (*j).first)); - } + if ( hook_list* l = hooks[i] ) + for ( const auto& [hook, hook_plugin] : *l ) + if ( hook_plugin == plugin ) + enabled.push_back(std::make_pair(static_cast(i), hook)); } return enabled; } -void Manager::EnableHook(HookType hook, Plugin* plugin, int prio) +void Manager::EnableHook(zeek::plugin::HookType hook, Plugin* plugin, int prio) { if ( ! hooks[hook] ) hooks[hook] = new hook_list; @@ -554,7 +548,7 @@ void Manager::EnableHook(HookType hook, Plugin* plugin, int prio) l->sort(hook_cmp); } -void Manager::DisableHook(HookType hook, Plugin* plugin) +void Manager::DisableHook(zeek::plugin::HookType hook, Plugin* plugin) { hook_list* l = hooks[hook]; @@ -577,6 +571,19 @@ void Manager::DisableHook(HookType hook, Plugin* plugin) } } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void Manager::EnableHook(::plugin::HookType hook, Plugin* plugin, int prio) + { + EnableHook(static_cast(hook), plugin, prio); + } + +void Manager::DisableHook(::plugin::HookType hook, Plugin* plugin) + { + DisableHook(static_cast(hook), plugin); + } +#pragma GCC diagnostic pop + void Manager::RequestEvent(EventHandlerPtr handler, Plugin* plugin) { DBG_LOG(DBG_PLUGINS, "Plugin %s requested event %s", @@ -593,15 +600,15 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(type)); args.push_back(HookArgument(file)); args.push_back(HookArgument(resolved)); - MetaHookPre(HOOK_LOAD_FILE, args); + MetaHookPre(zeek::plugin::HOOK_LOAD_FILE, args); } - hook_list* l = hooks[HOOK_LOAD_FILE]; + hook_list* l = hooks[zeek::plugin::HOOK_LOAD_FILE]; int rc = -1; @@ -616,8 +623,8 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const break; } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOAD_FILE, args, HookArgument(rc)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOAD_FILE, args, HookArgument(rc)); return rc; } @@ -629,7 +636,7 @@ Manager::HookCallFunction(const Func* func, Frame* parent, HookArgumentList args; val_list vargs; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { vargs.resize(vecargs->size()); @@ -639,10 +646,10 @@ Manager::HookCallFunction(const Func* func, Frame* parent, args.push_back(HookArgument(func)); args.push_back(HookArgument(parent)); args.push_back(HookArgument(&vargs)); - MetaHookPre(HOOK_CALL_FUNCTION, args); + MetaHookPre(zeek::plugin::HOOK_CALL_FUNCTION, args); } - hook_list* l = hooks[HOOK_CALL_FUNCTION]; + hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION]; std::pair> rval{false, nullptr}; @@ -659,8 +666,8 @@ Manager::HookCallFunction(const Func* func, Frame* parent, } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_CALL_FUNCTION, args, + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_CALL_FUNCTION, args, HookArgument(std::make_pair(rval.first, rval.second.get()))); return rval; @@ -670,13 +677,13 @@ bool Manager::HookQueueEvent(Event* event) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(event)); - MetaHookPre(HOOK_QUEUE_EVENT, args); + MetaHookPre(zeek::plugin::HOOK_QUEUE_EVENT, args); } - hook_list* l = hooks[HOOK_QUEUE_EVENT]; + hook_list* l = hooks[zeek::plugin::HOOK_QUEUE_EVENT]; bool result = false; @@ -692,8 +699,8 @@ bool Manager::HookQueueEvent(Event* event) const } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_QUEUE_EVENT, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_QUEUE_EVENT, args, HookArgument(result)); return result; } @@ -702,10 +709,10 @@ void Manager::HookDrainEvents() const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) - MetaHookPre(HOOK_DRAIN_EVENTS, args); + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) + MetaHookPre(zeek::plugin::HOOK_DRAIN_EVENTS, args); - hook_list* l = hooks[HOOK_DRAIN_EVENTS]; + hook_list* l = hooks[zeek::plugin::HOOK_DRAIN_EVENTS]; if ( l ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -714,8 +721,8 @@ void Manager::HookDrainEvents() const p->HookDrainEvents(); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_DRAIN_EVENTS, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_DRAIN_EVENTS, args, HookArgument()); } @@ -723,13 +730,13 @@ void Manager::HookSetupAnalyzerTree(Connection *conn) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(conn)); - MetaHookPre(HOOK_SETUP_ANALYZER_TREE, args); + MetaHookPre(zeek::plugin::HOOK_SETUP_ANALYZER_TREE, args); } - hook_list *l = hooks[HOOK_SETUP_ANALYZER_TREE]; + hook_list *l = hooks[zeek::plugin::HOOK_SETUP_ANALYZER_TREE]; if ( l ) { @@ -740,9 +747,9 @@ void Manager::HookSetupAnalyzerTree(Connection *conn) const } } - if ( HavePluginForHook(META_HOOK_POST) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) { - MetaHookPost(HOOK_SETUP_ANALYZER_TREE, args, HookArgument()); + MetaHookPost(zeek::plugin::HOOK_SETUP_ANALYZER_TREE, args, HookArgument()); } } @@ -750,13 +757,13 @@ void Manager::HookUpdateNetworkTime(double network_time) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(network_time)); - MetaHookPre(HOOK_UPDATE_NETWORK_TIME, args); + MetaHookPre(zeek::plugin::HOOK_UPDATE_NETWORK_TIME, args); } - hook_list* l = hooks[HOOK_UPDATE_NETWORK_TIME]; + hook_list* l = hooks[zeek::plugin::HOOK_UPDATE_NETWORK_TIME]; if ( l ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -765,21 +772,21 @@ void Manager::HookUpdateNetworkTime(double network_time) const p->HookUpdateNetworkTime(network_time); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_UPDATE_NETWORK_TIME, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_UPDATE_NETWORK_TIME, args, HookArgument()); } void Manager::HookBroObjDtor(void* obj) const { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(obj)); - MetaHookPre(HOOK_BRO_OBJ_DTOR, args); + MetaHookPre(zeek::plugin::HOOK_BRO_OBJ_DTOR, args); } - hook_list* l = hooks[HOOK_BRO_OBJ_DTOR]; + hook_list* l = hooks[zeek::plugin::HOOK_BRO_OBJ_DTOR]; if ( l ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -788,8 +795,8 @@ void Manager::HookBroObjDtor(void* obj) const p->HookBroObjDtor(obj); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_BRO_OBJ_DTOR, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_BRO_OBJ_DTOR, args, HookArgument()); } void Manager::HookLogInit(const std::string& writer, @@ -801,7 +808,7 @@ void Manager::HookLogInit(const std::string& writer, { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(writer)); args.push_back(HookArgument(instantiating_filter)); @@ -810,10 +817,10 @@ void Manager::HookLogInit(const std::string& writer, args.push_back(HookArgument(&info)); args.push_back(HookArgument(num_fields)); args.push_back(HookArgument(std::make_pair(num_fields, fields))); - MetaHookPre(HOOK_LOG_INIT, args); + MetaHookPre(zeek::plugin::HOOK_LOG_INIT, args); } - hook_list* l = hooks[HOOK_LOG_INIT]; + hook_list* l = hooks[zeek::plugin::HOOK_LOG_INIT]; if ( l ) for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) @@ -823,8 +830,8 @@ void Manager::HookLogInit(const std::string& writer, num_fields, fields); } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOG_INIT, args, HookArgument()); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOG_INIT, args, HookArgument()); } bool Manager::HookLogWrite(const std::string& writer, @@ -836,7 +843,7 @@ bool Manager::HookLogWrite(const std::string& writer, { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(writer)); args.push_back(HookArgument(filter)); @@ -844,10 +851,10 @@ bool Manager::HookLogWrite(const std::string& writer, args.push_back(HookArgument(num_fields)); args.push_back(HookArgument(std::make_pair(num_fields, fields))); args.push_back(HookArgument(vals)); - MetaHookPre(HOOK_LOG_WRITE, args); + MetaHookPre(zeek::plugin::HOOK_LOG_WRITE, args); } - hook_list* l = hooks[HOOK_LOG_WRITE]; + hook_list* l = hooks[zeek::plugin::HOOK_LOG_WRITE]; bool result = true; @@ -864,8 +871,8 @@ bool Manager::HookLogWrite(const std::string& writer, } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_LOG_WRITE, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_LOG_WRITE, args, HookArgument(result)); return result; } @@ -878,7 +885,7 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even { HookArgumentList args; - if ( HavePluginForHook(META_HOOK_PRE) ) + if ( HavePluginForHook(zeek::plugin::META_HOOK_PRE) ) { args.push_back(HookArgument(prefix)); args.push_back(HookArgument(conn)); @@ -888,10 +895,10 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even args.push_back(HookArgument(location)); args.push_back(HookArgument(time)); args.push_back(HookArgument(message)); - MetaHookPre(HOOK_REPORTER, args); + MetaHookPre(zeek::plugin::HOOK_REPORTER, args); } - hook_list* l = hooks[HOOK_REPORTER]; + hook_list* l = hooks[zeek::plugin::HOOK_REPORTER]; bool result = true; @@ -909,33 +916,23 @@ bool Manager::HookReporter(const std::string& prefix, const EventHandlerPtr even } } - if ( HavePluginForHook(META_HOOK_POST) ) - MetaHookPost(HOOK_REPORTER, args, HookArgument(result)); + if ( HavePluginForHook(zeek::plugin::META_HOOK_POST) ) + MetaHookPost(zeek::plugin::HOOK_REPORTER, args, HookArgument(result)); return result; } -void Manager::MetaHookPre(HookType hook, const HookArgumentList& args) const +void Manager::MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) const { - hook_list* l = hooks[HOOK_CALL_FUNCTION]; - - if ( l ) - for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) - { - Plugin* p = (*i).second; - p->MetaHookPre(hook, args); - } + if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] ) + for ( const auto& [hook_type, plugin] : *l ) + plugin->MetaHookPre(hook, args); } -void Manager::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) const +void Manager::MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) const { - hook_list* l = hooks[HOOK_CALL_FUNCTION]; - - if ( l ) - for ( hook_list::iterator i = l->begin(); i != l->end(); ++i ) - { - Plugin* p = (*i).second; - p->MetaHookPost(hook, args, result); - } + if ( hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION] ) + for ( const auto& [hook_type, plugin] : *l ) + plugin->MetaHookPost(hook, args, result); } diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index b3080cf733..987deb7941 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -12,7 +12,7 @@ #include "../Reporter.h" #include "../ZeekArgs.h" -namespace plugin { +namespace zeek::plugin { // Macros that trigger plugin hooks. We put this into macros to short-cut the // code for the most common case that no plugin defines the hook. @@ -25,7 +25,7 @@ namespace plugin { * @param method_call The \a Manager method corresponding to the hook. */ #define PLUGIN_HOOK_VOID(hook, method_call) \ - { if ( plugin_mgr->HavePluginForHook(plugin::hook) ) plugin_mgr->method_call; } + { if ( plugin_mgr->HavePluginForHook(zeek::plugin::hook) ) plugin_mgr->method_call; } /** * Macro to trigger hooks that return a result. @@ -38,7 +38,7 @@ namespace plugin { * the hook. */ #define PLUGIN_HOOK_WITH_RESULT(hook, method_call, default_result) \ - (plugin_mgr->HavePluginForHook(::plugin::hook) ? plugin_mgr->method_call : (default_result)) + (plugin_mgr->HavePluginForHook(zeek::plugin::hook) ? plugin_mgr->method_call : (default_result)) /** * A singleton object managing all plugins. @@ -47,9 +47,9 @@ class Manager { public: typedef void (*bif_init_func)(Plugin *); - typedef std::list plugin_list; - typedef Plugin::component_list component_list; - typedef std::list > inactive_plugin_list; + using plugin_list = std::list; + using component_list = Plugin::component_list; + using inactive_plugin_list = std::list>; /** * Constructor. @@ -165,19 +165,29 @@ public: * * @return True if there's a plugin for that hook. */ - bool HavePluginForHook(HookType hook) const + bool HavePluginForHook(zeek::plugin::HookType hook) const { // Inline to avoid the function call. return hooks[hook] != nullptr; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]] + bool HavePluginForHook(::plugin::HookType hook) const + { + // Inline to avoid the function call. + return HavePluginForHook(static_cast(hook)); + } +#pragma GCC diagnostic pop + /** * Returns all the hooks, with their priorities, that are currently * enabled for a given plugin. * * @param plugin The plugin to return the hooks for. */ - std::list > HooksEnabledForPlugin(const Plugin* plugin) const; + std::list > HooksEnabledForPlugin(const Plugin* plugin) const; /** * Enables a hook for a given plugin. @@ -188,7 +198,7 @@ public: * * prio: The priority to associate with the plugin for this hook. */ - void EnableHook(HookType hook, Plugin* plugin, int prio); + void EnableHook(zeek::plugin::HookType hook, Plugin* plugin, int prio); /** * Disables a hook for a given plugin. @@ -197,7 +207,16 @@ public: * * plugin: The plugin that used to define the hook. */ - void DisableHook(HookType hook, Plugin* plugin); + void DisableHook(zeek::plugin::HookType hook, Plugin* plugin); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]] + void EnableHook(::plugin::HookType hook, Plugin* plugin, int prio); + + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin::HookType")]] + void DisableHook(::plugin::HookType hook, Plugin* plugin); +#pragma GCC diagnostic pop /** * Registers interest in an event by a plugin, even if there's no handler @@ -415,23 +434,23 @@ public: private: bool ActivateDynamicPluginInternal(const std::string& name, bool ok_if_not_found = false); void UpdateInputFiles(); - void MetaHookPre(HookType hook, const HookArgumentList& args) const; - void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) const; + void MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) const; + void MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) const; // All found dynamic plugins, mapping their names to base directory. - typedef std::map dynamic_plugin_map; + using dynamic_plugin_map = std::map; dynamic_plugin_map dynamic_plugins; // We temporarliy buffer scripts to load to get them to load in the // right order. - typedef std::list file_list; + using file_list = std::list; file_list scripts_to_load; bool init; // Flag indicating whether InitPreScript() has run yet. // A hook list keeps pairs of plugin and priority interested in a // given hook. - typedef std::list > hook_list; + using hook_list = std::list>; // An array indexed by HookType. An entry is null if there's no hook // of that type enabled. @@ -450,8 +469,8 @@ private: // even before the manager exists. static plugin_list* ActivePluginsInternal(); - typedef std::list bif_init_func_list; - typedef std::map bif_init_func_map; + using bif_init_func_list = std::list; + using bif_init_func_map = std::map; // Returns a modifiable map of all bif files. This is a static method // so that plugins can register their bifs even before the manager @@ -480,20 +499,29 @@ std::list Manager::Components() const return result; } +} + +// TOOD: should this just be zeek::detail? +namespace zeek::detail::plugin { + /** * Internal class used by bifcl-generated code to register its init functions at runtime. */ class __RegisterBif { public: - __RegisterBif(const char* plugin, Manager::bif_init_func init) + __RegisterBif(const char* plugin, zeek::plugin::Manager::bif_init_func init) { - Manager::RegisterBifFile(plugin, init); + zeek::plugin::Manager::RegisterBifFile(plugin, init); } }; } +namespace plugin { + using Manager [[deprecated("Remove in v4.1. Use zeek::plugin::Manager instead.")]] = zeek::plugin::Manager; +} + /** * The global plugin manager singleton. */ -extern plugin::Manager* plugin_mgr; +extern zeek::plugin::Manager* plugin_mgr; diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 262ee2cc64..f1cfbf3fd8 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -17,11 +17,11 @@ #include "../input.h" #include "threading/SerialTypes.h" -using namespace plugin; +using namespace zeek::plugin; -const char* plugin::hook_name(HookType h) +const char* zeek::plugin::hook_name(zeek::plugin::HookType h) { - static const char* hook_names[int(NUM_HOOKS) + 1] = { +static constexpr const char* hook_names[int(zeek::plugin::NUM_HOOKS) + 1] = { // Order must match that of HookType. "LoadFile", "CallFunction", @@ -42,6 +42,14 @@ const char* plugin::hook_name(HookType h) return hook_names[int(h)]; } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +const char* plugin::hook_name(::plugin::HookType h) + { + return hook_name(static_cast(h)); + } +#pragma GCC diagnostic pop + BifItem::BifItem(const std::string& arg_id, Type arg_type) { id = arg_id; @@ -319,7 +327,7 @@ Plugin::component_list Plugin::Components() const return components; } -static bool component_cmp(const Component* a, const Component* b) +static bool component_cmp(const zeek::plugin::Component* a, const zeek::plugin::Component* b) { return a->Name() < b->Name(); } @@ -336,7 +344,7 @@ void Plugin::AddBifItem(const std::string& name, BifItem::Type type) bif_items.push_back(bi); } -void Plugin::AddComponent(Component* c) +void Plugin::AddComponent(zeek::plugin::Component* c) { components.push_back(c); @@ -350,12 +358,25 @@ Plugin::hook_list Plugin::EnabledHooks() const return plugin_mgr->HooksEnabledForPlugin(this); } -void Plugin::EnableHook(HookType hook, int priority) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void Plugin::EnableHook(::plugin::HookType hook, int priority) + { + plugin_mgr->EnableHook(static_cast(hook), this, priority); + } + +void Plugin::DisableHook(::plugin::HookType hook) + { + plugin_mgr->DisableHook(static_cast(hook), this); + } +#pragma GCC diagnostic pop + +void Plugin::EnableHook(zeek::plugin::HookType hook, int priority) { plugin_mgr->EnableHook(hook, this, priority); } -void Plugin::DisableHook(HookType hook) +void Plugin::DisableHook(zeek::plugin::HookType hook) { plugin_mgr->DisableHook(hook, this); } @@ -446,13 +467,32 @@ bool Plugin::HookReporter(const std::string& prefix, const EventHandlerPtr event return true; } -void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +void Plugin::MetaHookPre(::plugin::HookType hook, const HookArgumentList& args) { } -void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) +void Plugin::MetaHookPost(::plugin::HookType hook, const HookArgumentList& args, HookArgument result) { } +#pragma GCC diagnostic pop + +void Plugin::MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args) + { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + MetaHookPre(static_cast<::plugin::HookType>(hook), args); +#pragma GCC diagnostic pop + } + +void Plugin::MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result) + { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + MetaHookPost(static_cast<::plugin::HookType>(hook), args, result); +#pragma GCC diagnostic pop + } void Plugin::InitializeComponents() { @@ -555,4 +595,3 @@ void Plugin::Describe(ODesc* d) const d->Add(")\n"); } } - diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index 096b796429..1d82ad0cd8 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -26,7 +26,45 @@ namespace threading { struct Field; } -namespace plugin { +namespace plugin { + +/** + * Hook types that a plugin may define. Each label maps to the corresponding + * virtual method in \a Plugin. + */ +enum [[deprecated("Remove in v4.1. Use the zeek::plugin::HookType instead.")]] HookType { + // Note: when changing this table, update hook_name() in Plugin.cc. + HOOK_LOAD_FILE, //< Activates Plugin::HookLoadFile(). + HOOK_CALL_FUNCTION, //< Activates Plugin::HookCallFunction(). + HOOK_QUEUE_EVENT, //< Activates Plugin::HookQueueEvent(). + HOOK_DRAIN_EVENTS, //< Activates Plugin::HookDrainEvents() + HOOK_UPDATE_NETWORK_TIME, //< Activates Plugin::HookUpdateNetworkTime. + HOOK_BRO_OBJ_DTOR, //< Activates Plugin::HookBroObjDtor. + HOOK_SETUP_ANALYZER_TREE, //< Activates Plugin::HookAddToAnalyzerTree + HOOK_LOG_INIT, //< Activates Plugin::HookLogInit + HOOK_LOG_WRITE, //< Activates Plugin::HookLogWrite + HOOK_REPORTER, //< Activates Plugin::HookReporter + + // Meta hooks. + META_HOOK_PRE, //< Activates Plugin::MetaHookPre(). + META_HOOK_POST, //< Activates Plugin::MetaHookPost(). + + // End marker. + NUM_HOOKS, +}; + +/** + * Converts a hook type into a readable hook name. + */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +[[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]] +extern const char* hook_name(::plugin::HookType h); +#pragma GCC diagnostic pop + +} + +namespace zeek::plugin { class Manager; class Component; @@ -60,25 +98,15 @@ enum HookType { /** * Converts a hook type into a readable hook name. */ -extern const char* hook_name(HookType h); +extern const char* hook_name(zeek::plugin::HookType h); /** * Helper class to capture a plugin's version. * */ struct VersionNumber { - int major; //< Major version number. - int minor; //< Minor version number. - int patch; //< Patch version number (available since Zeek 3.0). - - /** - * Constructor. - */ - VersionNumber() { - // Major and minor versions are required. - major = minor = -1; - // Patch version is optional, and set to 0 if not manually set. - patch = 0; - } + int major = -1; //< Major version number. + int minor = -1; //< Minor version number. + int patch = 0; //< Patch version number (available since Zeek 3.0). /** * Returns true if the version is set to a non-negative value. @@ -91,14 +119,17 @@ struct VersionNumber { */ class Configuration { public: - std::string name; //< The plugin's name, including a namespace. Mandatory. - std::string description; //< A short textual description of the plugin. Mandatory. - VersionNumber version; //< THe plugin's version. Optional. + std::string name = ""; //< The plugin's name, including a namespace. Mandatory. + std::string description= ""; //< A short textual description of the plugin. Mandatory. + VersionNumber version; //< THe plugin's version. Optional. // We force this to inline so that the API version gets hardcoded // into the external plugin. (Technically, it's not a "force", just a // strong hint.). The attribute seems generally available. - inline Configuration() __attribute__((always_inline)); + inline Configuration() __attribute__((always_inline)) + { + bro_version = BRO_PLUGIN_BRO_VERSION; + } /** * One can assign BRO_PLUGIN_BRO_VERSION to this to catch @@ -110,13 +141,6 @@ private: friend class Plugin; }; -inline Configuration::Configuration() - { - name = ""; - description = ""; - bro_version = BRO_PLUGIN_BRO_VERSION; - } - /** * A class describing an item defined in \c *.bif file. */ @@ -392,7 +416,7 @@ private: std::string arg_string; }; -typedef std::list HookArgumentList; +using HookArgumentList = std::list; /** * Base class for all plugins. @@ -423,7 +447,7 @@ typedef std::list HookArgumentList; */ class Plugin { public: - typedef std::list component_list; + typedef std::list component_list; typedef std::list bif_item_list; typedef std::list > hook_list; @@ -538,7 +562,7 @@ public: bool LoadBroFile(const std::string& file); protected: - friend class Manager; + friend class zeek::plugin::Manager; /** * First-stage initialization of the plugin called early during Bro's @@ -568,7 +592,7 @@ protected: * * @param c The component. The method takes ownership. */ - void AddComponent(Component* c); + void AddComponent(zeek::plugin::Component* c); /** * Calls the Initialize() function of all components. @@ -594,7 +618,7 @@ protected: * highest to lowest. If two plugins specify the same priority, order * is undefined. */ - void EnableHook(HookType hook, int priority = 0); + void EnableHook(zeek::plugin::HookType hook, int priority = 0); /** * Disables a hook. Bro will no longer call the corresponding virtual @@ -602,7 +626,16 @@ protected: * * @param hook The hook to disable. */ - void DisableHook(HookType hook); + void DisableHook(zeek::plugin::HookType hook); + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]] + void EnableHook(::plugin::HookType hook, int priority = 0); + + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]] + void DisableHook(::plugin::HookType hook); +#pragma GCC diagnostic pop /** * Returns a list of hooks that are currently enabled for the plugin, @@ -855,7 +888,13 @@ protected: * * args: A list of the hooks arguments. */ - virtual void MetaHookPre(HookType hook, const HookArgumentList& args); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]] + virtual void MetaHookPre(::plugin::HookType hook, const HookArgumentList& args); +#pragma GCC diagnostic pop + + virtual void MetaHookPre(zeek::plugin::HookType hook, const HookArgumentList& args); /** * A meta hook called just after another hook got to execute. This @@ -870,7 +909,13 @@ protected: * implementation for the hook, this will be the default result. If * the hook doesn't yield a result, this will be of type VOID. */ - virtual void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[deprecated("Remove in v4.1. Use the version that takes zeek::plugin:HookType instead.")]] + virtual void MetaHookPost(::plugin::HookType hook, const HookArgumentList& args, HookArgument result); +#pragma GCC diagnostic pop + + virtual void MetaHookPost(zeek::plugin::HookType hook, const HookArgumentList& args, HookArgument result); private: @@ -925,3 +970,12 @@ private: }; } + +namespace plugin { + using VersionNumber [[deprecated("Remove in v4.1. Use zeek::plugin::VersionNumber instead")]] = zeek::plugin::VersionNumber; + using Configuration [[deprecated("Remove in v4.1. Use zeek::plugin::Configuration instead")]] = zeek::plugin::Configuration; + using BifItem [[deprecated("Remove in v4.1. Use zeek::plugin::BifItem instead")]] = zeek::plugin::BifItem; + using HookArgument [[deprecated("Remove in v4.1. Use zeek::plugin::HookArgument instead")]] = zeek::plugin::HookArgument; + using HookArgumentList [[deprecated("Remove in v4.1. Use zeek::plugin::HookArgumentList instead")]] = zeek::plugin::HookArgumentList; + using Plugin [[deprecated("Remove in v4.1. Use zeek::plugin::Plugin instead")]] = zeek::plugin::Plugin; +} diff --git a/src/plugin/TaggedComponent.h b/src/plugin/TaggedComponent.h index 27ca497171..1fcb8fccc0 100644 --- a/src/plugin/TaggedComponent.h +++ b/src/plugin/TaggedComponent.h @@ -2,7 +2,7 @@ #include -namespace plugin { +namespace zeek::plugin { /** * A class which has a tag of a given type associated with it. @@ -71,3 +71,9 @@ T TaggedComponent::Tag() const template typename T::type_t TaggedComponent::type_counter(0); } // namespace plugin + +namespace plugin { + template + using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] = + zeek::plugin::TaggedComponent; +} diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 0de42bef47..1cd1027b1e 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..24db217a59 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 f1c37f494e..b359a5f593 100644 --- a/src/scan.l +++ b/src/scan.l @@ -37,6 +37,8 @@ #include "plugin/Manager.h" +using namespace zeek::detail; + namespace { struct ZeekINode { dev_t dev; @@ -45,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; @@ -362,7 +364,7 @@ when return TOK_WHEN; @load-sigs{WS}{FILE} { const char* file = skip_whitespace(yytext + 10); std::string path = find_relative_file(file, ".sig"); - int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::SIGNATURES, file, path), -1); + int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::SIGNATURES, file, path), -1); switch ( rc ) { case -1: @@ -393,7 +395,7 @@ when return TOK_WHEN; @load-plugin{WS}{ID} { const char* plugin = skip_whitespace(yytext + 12); - int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::PLUGIN, plugin, ""), -1); + int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::PLUGIN, plugin, ""), -1); switch ( rc ) { case -1: @@ -613,7 +615,7 @@ static bool already_scanned(const std::string& path) static int load_files(const char* orig_file) { std::string file_path = find_relative_script_file(orig_file); - int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(plugin::Plugin::SCRIPT, orig_file, file_path), -1); + int rc = PLUGIN_HOOK_WITH_RESULT(HOOK_LOAD_FILE, HookLoadFile(zeek::plugin::Plugin::SCRIPT, orig_file, file_path), -1); if ( rc == 1 ) return 0; // A plugin took care of it, just skip. @@ -724,12 +726,12 @@ public: LocalNameFinder() {} - virtual TraversalCode PreExpr(const Expr* expr) + virtual TraversalCode PreExpr(const zeek::detail::Expr* expr) { if ( expr->Tag() != EXPR_NAME ) return TC_CONTINUE; - const NameExpr* name_expr = static_cast(expr); + const zeek::detail::NameExpr* name_expr = static_cast(expr); if ( name_expr->Id()->IsGlobal() ) return TC_CONTINUE; @@ -738,10 +740,10 @@ public: return TC_CONTINUE; } - std::vector local_names; + std::vector local_names; }; -void do_atif(Expr* expr) +void do_atif(zeek::detail::Expr* expr) { ++current_depth; @@ -1003,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 df8aa63026..bcf9a1c9f6 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -83,8 +83,8 @@ struct Stem { pid_t parent_pid; int last_signal = -1; - std::unique_ptr signal_flare; - std::unique_ptr pipe; + std::unique_ptr signal_flare; + std::unique_ptr pipe; std::map nodes; std::string msg_buffer; bool shutting_down = false; @@ -426,7 +426,7 @@ size_t Supervisor::ProcessMessages() } Stem::Stem(Supervisor::StemState ss) - : parent_pid(ss.parent_pid), signal_flare(new bro::Flare()), pipe(std::move(ss.pipe)) + : parent_pid(ss.parent_pid), signal_flare(new zeek::detail::Flare()), pipe(std::move(ss.pipe)) { zeek::set_thread_name("zeek.stem"); pipe->Swap(); @@ -928,7 +928,7 @@ std::optional Supervisor::CreateStem(bool supervisor_mode fds[i] = std::stoi(zeek_stem_nums[i + 1]); StemState ss; - ss.pipe = std::make_unique(FD_CLOEXEC, O_NONBLOCK, fds); + ss.pipe = std::make_unique(FD_CLOEXEC, O_NONBLOCK, fds); ss.parent_pid = stem_ppid; zeek::Supervisor::RunStem(std::move(ss)); return {}; @@ -938,7 +938,7 @@ std::optional Supervisor::CreateStem(bool supervisor_mode return {}; StemState ss; - ss.pipe = std::make_unique(FD_CLOEXEC, O_NONBLOCK); + ss.pipe = std::make_unique(FD_CLOEXEC, O_NONBLOCK); ss.parent_pid = getpid(); ss.pid = fork(); @@ -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/supervisor/Supervisor.h b/src/supervisor/Supervisor.h index b7800a2c83..ba381ad6dd 100644 --- a/src/supervisor/Supervisor.h +++ b/src/supervisor/Supervisor.h @@ -241,7 +241,7 @@ public: /** * Bidirectional pipes that allow the Supervisor and Stem to talk. */ - std::unique_ptr pipe; + std::unique_ptr pipe; /** * The Stem's parent process ID (i.e. PID of the Supervisor). */ @@ -382,9 +382,9 @@ private: Config config; pid_t stem_pid; - std::unique_ptr stem_pipe; + std::unique_ptr stem_pipe; int last_signal = -1; - bro::Flare signal_flare; + zeek::detail::Flare signal_flare; NodeMap nodes; std::string msg_buffer; }; 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/MsgThread.h b/src/threading/MsgThread.h index 42ce20984f..c95a424777 100644 --- a/src/threading/MsgThread.h +++ b/src/threading/MsgThread.h @@ -338,7 +338,7 @@ private: bool child_sent_finish; // Child thread asked to be finished. bool failed; // Set to true when a command failed. - bro::Flare flare; + zeek::detail::Flare flare; }; /** diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index e3f82b9b55..c2a0610561 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::Type* 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..a78af7ce4a 100644 --- a/src/threading/SerialTypes.h +++ b/src/threading/SerialTypes.h @@ -21,18 +21,26 @@ 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) { } +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop + /** * Copy constructor. */ @@ -85,8 +93,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 +148,18 @@ 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) + {} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop /** * Constructor. @@ -154,8 +171,17 @@ 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) + {} + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" + [[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) + {} +#pragma GCC diagnostic pop /** * Destructor. @@ -185,7 +211,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::Type* t, bool atomic_only=false); /** * Convenience function to delete an array of value pointers. @@ -209,7 +235,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/util.h b/src/util.h index 1b94bc2fc5..045db03b5d 100644 --- a/src/util.h +++ b/src/util.h @@ -61,6 +61,11 @@ extern HeapLeakChecker* heap_checker; #include #endif +// Note: macro for internal use only during deprecation/namespacing process. +#define ZEEK_FORWARD_DECLARE_NAMESPACED(cls, ns) \ + namespace ns { class cls; } \ + using cls [[deprecated("Remove in v4.1. Use " #ns "::" #cls " instead.")]] = ns::cls; + [[deprecated("Remove in v4.1. Use uint64_t instead.")]] typedef uint64_t uint64; [[deprecated("Remove in v4.1. Use uint32_t instead.")]] diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 988b7abb7c..0563f5ef7d 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -91,17 +91,17 @@ ValManager* val_mgr = nullptr; logging::Manager* log_mgr = nullptr; threading::Manager* thread_mgr = nullptr; input::Manager* input_mgr = nullptr; -plugin::Manager* plugin_mgr = nullptr; +zeek::plugin::Manager* plugin_mgr = nullptr; analyzer::Manager* analyzer_mgr = nullptr; file_analysis::Manager* file_mgr = nullptr; zeekygen::Manager* zeekygen_mgr = nullptr; iosource::Manager* iosource_mgr = nullptr; bro_broker::Manager* broker_mgr = nullptr; zeek::Supervisor* zeek::supervisor_mgr = nullptr; -trigger::Manager* trigger_mgr = nullptr; +zeek::detail::trigger::Manager* trigger_mgr = nullptr; std::vector zeek_script_prefixes; -Stmt* stmts; +zeek::detail::Stmt* stmts; RuleMatcher* rule_matcher = nullptr; EventRegistry* event_registry = nullptr; ProfileLogger* profiling_logger = nullptr; @@ -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; @@ -160,7 +160,7 @@ static std::vector to_cargs(const std::vector& args) bool show_plugins(int level) { - plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); + zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); if ( ! plugins.size() ) { @@ -175,7 +175,7 @@ bool show_plugins(int level) int count = 0; - for ( plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ ) + for ( zeek::plugin::Manager::plugin_list::const_iterator i = plugins.begin(); i != plugins.end(); i++ ) { if ( requested_plugins.size() && requested_plugins.find((*i)->Name()) == requested_plugins.end() ) @@ -191,13 +191,13 @@ bool show_plugins(int level) printf("%s", d.Description()); - plugin::Manager::inactive_plugin_list inactives = plugin_mgr->InactivePlugins(); + zeek::plugin::Manager::inactive_plugin_list inactives = plugin_mgr->InactivePlugins(); if ( inactives.size() && ! requested_plugins.size() ) { printf("\nInactive dynamic plugins:\n"); - for ( plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin(); i != inactives.end(); i++ ) + for ( zeek::plugin::Manager::inactive_plugin_list::const_iterator i = inactives.begin(); i != inactives.end(); i++ ) { string name = (*i).first; string path = (*i).second; @@ -467,7 +467,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, val_mgr = new ValManager(); reporter = new Reporter(options.abort_on_scripting_errors); thread_mgr = new threading::Manager(); - plugin_mgr = new plugin::Manager(); + plugin_mgr = new zeek::plugin::Manager(); #ifdef DEBUG if ( options.debug_log_streams ) @@ -570,7 +570,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv, file_mgr = new file_analysis::Manager(); auto broker_real_time = ! options.pcap_file && ! options.deterministic_mode; broker_mgr = new bro_broker::Manager(broker_real_time); - trigger_mgr = new trigger::Manager(); + trigger_mgr = new zeek::detail::trigger::Manager(); plugin_mgr->InitPreScript(); analyzer_mgr->InitPreScript(); @@ -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 1c81e87026..d63bf1453f 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); @@ -1918,7 +1918,7 @@ function global_sizes%(%): var_sizes for ( const auto& global : globals ) { - ID* id = global.second.get(); + auto& id = global.second; if ( id->HasVal() ) { auto id_name = make_intrusive(id->Name()); @@ -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 ) { - ID* id = global.second.get(); - static auto script_id = zeek::id::find_type("script_id"); + const auto& id = global.second; + 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; %} @@ -3479,7 +3479,7 @@ function dump_packet%(pkt: pcap_packet, file_name: string%) : bool class LookupHostCallback : public DNS_Mgr::LookupCallback { public: - LookupHostCallback(trigger::Trigger* arg_trigger, const CallExpr* arg_call, + LookupHostCallback(zeek::detail::trigger::Trigger* arg_trigger, const zeek::detail::CallExpr* arg_call, bool arg_lookup_name) { Ref(arg_trigger); @@ -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()); @@ -3531,8 +3531,8 @@ public: } private: - trigger::Trigger* trigger; - const CallExpr* call; + zeek::detail::trigger::Trigger* trigger; + const zeek::detail::CallExpr* call; bool lookup_name; }; %%} @@ -3550,7 +3550,7 @@ function lookup_addr%(host: addr%) : string %{ // FIXME: It should be easy to adapt the function to synchronous // lookups if we're reading a trace. - trigger::Trigger* trigger = frame->GetTrigger(); + zeek::detail::trigger::Trigger* trigger = frame->GetTrigger(); if ( ! trigger) { @@ -3579,7 +3579,7 @@ function lookup_hostname_txt%(host: string%) : string %{ // FIXME: Is should be easy to adapt the function to synchronous // lookups if we're reading a trace. - trigger::Trigger* trigger = frame->GetTrigger(); + zeek::detail::trigger::Trigger* trigger = frame->GetTrigger(); if ( ! trigger) { @@ -3608,7 +3608,7 @@ function lookup_hostname%(host: string%) : addr_set %{ // FIXME: Is should be easy to adapt the function to synchronous // lookups if we're reading a trace. - trigger::Trigger* trigger = frame->GetTrigger(); + zeek::detail::trigger::Trigger* trigger = frame->GetTrigger(); if ( ! trigger) { @@ -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; @@ -5024,7 +5024,7 @@ function match_signatures%(c: connection, pattern_type: int, s: string, ## .. todo:: Currently dysfunctional. function preserve_prefix%(a: addr, width: count%): any %{ - AnonymizeIPAddr* ip_anon = ip_anonymizer[PREFIX_PRESERVING_A50]; + zeek::detail::AnonymizeIPAddr* ip_anon = zeek::detail::ip_anonymizer[zeek::detail::PREFIX_PRESERVING_A50]; if ( ip_anon ) { if ( a->AsAddr().GetFamily() == IPv6 ) @@ -5037,7 +5037,6 @@ function preserve_prefix%(a: addr, width: count%): any } } - return nullptr; %} @@ -5051,7 +5050,7 @@ function preserve_prefix%(a: addr, width: count%): any function preserve_subnet%(a: subnet%): any %{ DEBUG_MSG("%s/%d\n", a->Prefix().AsString().c_str(), a->Width()); - AnonymizeIPAddr* ip_anon = ip_anonymizer[PREFIX_PRESERVING_A50]; + zeek::detail::AnonymizeIPAddr* ip_anon = zeek::detail::ip_anonymizer[zeek::detail::PREFIX_PRESERVING_A50]; if ( ip_anon ) { if ( a->AsSubNet().Prefix().GetFamily() == IPv6 ) @@ -5087,7 +5086,7 @@ function preserve_subnet%(a: subnet%): any function anonymize_addr%(a: addr, cl: IPAddrAnonymizationClass%): addr %{ int anon_class = cl->InternalInt(); - if ( anon_class < 0 || anon_class >= NUM_ADDR_ANONYMIZATION_CLASSES ) + if ( anon_class < 0 || anon_class >= zeek::detail::NUM_ADDR_ANONYMIZATION_CLASSES ) builtin_error("anonymize_addr(): invalid ip addr anonymization class"); if ( a->AsAddr().GetFamily() == IPv6 ) @@ -5099,8 +5098,8 @@ function anonymize_addr%(a: addr, cl: IPAddrAnonymizationClass%): addr { const uint32_t* bytes; a->AsAddr().GetBytes(&bytes); - return make_intrusive(anonymize_ip(*bytes, - (enum ip_addr_anonymization_class_t) anon_class)); + return make_intrusive(zeek::detail::anonymize_ip(*bytes, + static_cast(anon_class))); } %} diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index 744aab928b..0175a42380 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -11,7 +11,7 @@ using namespace std; using namespace zeekygen; -IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) +IdentifierInfo::IdentifierInfo(IntrusivePtr arg_id, ScriptInfo* script) : Info(), comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) @@ -31,19 +31,19 @@ IdentifierInfo::~IdentifierInfo() delete it->second; } -void IdentifierInfo::AddRedef(const string& script, init_class ic, - IntrusivePtr init_expr, const vector& comments) +void IdentifierInfo::AddRedef(const string& script, zeek::detail::init_class ic, + IntrusivePtr init_expr, const vector& comments) { Redefinition* redef = new Redefinition(script, ic, std::move(init_expr), comments); 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]; @@ -141,8 +141,8 @@ time_t IdentifierInfo::DoGetModificationTime() const IdentifierInfo::Redefinition::Redefinition( std::string arg_script, - init_class arg_ic, - IntrusivePtr arg_expr, + zeek::detail::init_class arg_ic, + IntrusivePtr arg_expr, std::vector arg_comments) : from_script(std::move(arg_script)), ic(arg_ic), diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index a2292844d1..d9756e46c9 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; +ZEEK_FORWARD_DECLARE_NAMESPACED(TypeDecl, zeek); namespace zeekygen { @@ -32,7 +32,7 @@ public: * @param script The info object associated with the script in which \a id * is declared. */ - IdentifierInfo(IntrusivePtr id, ScriptInfo* script); + IdentifierInfo(IntrusivePtr id, ScriptInfo* script); /** * Dtor. Releases any references to script-level objects. @@ -70,8 +70,8 @@ public: * @param init_expr The initialization expression used. * @param comments Comments associated with the redef statement. */ - void AddRedef(const std::string& from_script, init_class ic, - IntrusivePtr init_expr, + void AddRedef(const std::string& from_script, zeek::detail::init_class ic, + IntrusivePtr init_expr, const std::vector& comments); /** @@ -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); /** @@ -96,7 +96,7 @@ public: /** * @return the script-level ID tracked by this info object. */ - ID* GetID() const + zeek::detail::ID* GetID() const { return id.get(); } /** @@ -127,12 +127,12 @@ public: */ struct Redefinition { std::string from_script; /**< Name of script doing the redef. */ - init_class ic; - IntrusivePtr init_expr; + zeek::detail::init_class ic; + IntrusivePtr init_expr; std::vector comments; /**< Zeekygen comments on redef. */ - Redefinition(std::string arg_script, init_class arg_ic, - IntrusivePtr arg_expr, + Redefinition(std::string arg_script, zeek::detail::init_class arg_ic, + IntrusivePtr arg_expr, std::vector arg_comments); ~Redefinition(); @@ -165,7 +165,7 @@ private: struct RecordField { ~RecordField(); - TypeDecl* field; + zeek::TypeDecl* field; std::string from_script; std::vector comments; }; @@ -174,7 +174,7 @@ private: typedef std::map record_field_map; std::vector comments; - IntrusivePtr id; + IntrusivePtr id; IntrusivePtr initial_val; redef_list redefs; record_field_map fields; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 868b27e39b..071940eb25 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -27,7 +27,7 @@ static void DbgAndWarn(const char* msg) DBG_LOG(DBG_ZEEKYGEN, "%s", msg); } -static void WarnMissingScript(const char* type, const ID* id, +static void WarnMissingScript(const char* type, const zeek::detail::ID* id, const string& script) { if ( script == "" ) @@ -54,7 +54,7 @@ static string RemoveLeadingSpace(const string& s) // use for indexing. static string NormalizeScriptPath(const string& path) { - if ( auto p = plugin_mgr->LookupPluginByPath(path) ) + if ( auto p = plugin_mgr->LookupPluginByPath(path) ) { auto rval = normalize_path(path); auto prefix = SafeBasename(p->PluginDirectory()).result; @@ -216,7 +216,7 @@ void Manager::ModuleUsage(const string& path, const string& module) module.c_str(), name.c_str()); } -IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) +IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script) { const auto& id_name = id->Name(); auto prev = identifiers.GetInfo(id_name); @@ -247,7 +247,7 @@ IdentifierInfo* Manager::CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* s return rval; } -void Manager::StartType(IntrusivePtr id) +void Manager::StartType(IntrusivePtr id) { if ( disabled ) return; @@ -273,12 +273,12 @@ void Manager::StartType(IntrusivePtr id) incomplete_type = CreateIdentifierInfo(std::move(id), script_info); } -static bool IsEnumType(ID* 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) +void Manager::Identifier(IntrusivePtr id) { if ( disabled ) return; @@ -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 ID* id, const TypeDecl* field, +void Manager::RecordField(const zeek::detail::ID* id, const zeek::TypeDecl* field, const string& path) { if ( disabled ) @@ -360,8 +360,8 @@ void Manager::RecordField(const ID* id, const TypeDecl* field, field->id, id->Name(), script.c_str()); } -void Manager::Redef(const ID* id, const string& path, - init_class ic, IntrusivePtr init_expr) +void Manager::Redef(const zeek::detail::ID* id, const string& path, + zeek::detail::init_class ic, IntrusivePtr init_expr) { if ( disabled ) return; @@ -397,8 +397,8 @@ void Manager::Redef(const ID* id, const string& path, id->Name(), from_script.c_str()); } -void Manager::Redef(const ID* id, const std::string& path, - init_class ic) +void Manager::Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic) { Redef(id, path, ic, nullptr); } diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index 6edc9c1d17..4c64c99a6b 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; +ZEEK_FORWARD_DECLARE_NAMESPACED(TypeDecl, zeek); namespace zeekygen { @@ -110,14 +111,14 @@ public: * Signal that a record or enum type is now being parsed. * @param id The record or enum type identifier. */ - void StartType(IntrusivePtr id); + void StartType(IntrusivePtr id); /** * Register a script-level identifier for which information/documentation * will be gathered. * @param id The script-level identifier. */ - void Identifier(IntrusivePtr id); + void Identifier(IntrusivePtr id); /** * Register a record-field for which information/documentation will be @@ -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 ID* id, const TypeDecl* field, + void RecordField(const zeek::detail::ID* id, const zeek::TypeDecl* field, const std::string& path); /** @@ -138,10 +139,10 @@ public: * @param ic The initialization class that was used (e.g. =, +=, -=). * @param init_expr The intiialization expression that was used. */ - void Redef(const ID* id, const std::string& path, - init_class ic, IntrusivePtr init_expr); - void Redef(const ID* id, const std::string& path, - init_class ic = INIT_NONE); + void Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic, IntrusivePtr init_expr); + void Redef(const zeek::detail::ID* id, const std::string& path, + zeek::detail::init_class ic = zeek::detail::INIT_NONE); /** * Register Zeekygen script summary content. @@ -217,7 +218,7 @@ private: typedef std::vector comment_buffer_t; typedef std::map comment_buffer_map_t; - IdentifierInfo* CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script); + IdentifierInfo* CreateIdentifierInfo(IntrusivePtr id, ScriptInfo* script); bool disabled; comment_buffer_t comment_buffer; // For whatever next identifier comes in. diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index ddd0d8009c..0bbd64ad66 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -82,7 +82,7 @@ static string make_summary(const string& heading, char underline, char border, for ( id_info_list::const_iterator it = id_list.begin(); it != id_list.end(); ++it ) { - ID* id = (*it)->GetID(); + auto* id = (*it)->GetID(); ODesc d; d.SetQuotes(true); id->DescribeReSTShort(&d); @@ -105,7 +105,7 @@ static string make_redef_summary(const string& heading, char underline, for ( id_info_set::const_iterator it = id_set.begin(); it != id_set.end(); ++it ) { - ID* id = (*it)->GetID(); + auto* id = (*it)->GetID(); ODesc d; d.SetQuotes(true); id->DescribeReSTShort(&d); @@ -179,7 +179,7 @@ void ScriptInfo::DoInitPostScript() it != id_info.end(); ++it ) { IdentifierInfo* info = it->second; - ID* id = info->GetID(); + auto* id = info->GetID(); if ( ! zeekygen::is_public_api(id) ) continue; @@ -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); @@ -220,7 +220,7 @@ void ScriptInfo::DoInitPostScript() if ( id->IsConst() ) { - if ( id->GetAttr(ATTR_REDEF) ) + if ( id->GetAttr(zeek::detail::ATTR_REDEF) ) { DBG_LOG(DBG_ZEEKYGEN, "Filter id '%s' in '%s' as a redef_option", id->Name(), name.c_str()); @@ -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/src/zeekygen/Target.cc b/src/zeekygen/Target.cc index 34e6f3519a..71f4c7dfa8 100644 --- a/src/zeekygen/Target.cc +++ b/src/zeekygen/Target.cc @@ -21,7 +21,7 @@ using namespace std; using namespace zeekygen; -static void write_plugin_section_heading(FILE* f, const plugin::Plugin* p) +static void write_plugin_section_heading(FILE* f, const zeek::plugin::Plugin* p) { const string& name = p->Name(); @@ -55,21 +55,20 @@ static void write_analyzer_component(FILE* f, const file_analysis::Component* c) fprintf(f, ":zeek:enum:`Files::%s`\n\n", tag.c_str()); } -static void write_plugin_components(FILE* f, const plugin::Plugin* p) +static void write_plugin_components(FILE* f, const zeek::plugin::Plugin* p) { - plugin::Plugin::component_list components = p->Components(); - plugin::Plugin::component_list::const_iterator it; + zeek::plugin::Plugin::component_list components = p->Components(); fprintf(f, "Components\n"); fprintf(f, "++++++++++\n\n"); - for ( it = components.begin(); it != components.end(); ++it ) + for ( const auto& component : components ) { - switch ( (*it)->Type() ) { - case plugin::component::ANALYZER: + switch ( component->Type() ) { + case zeek::plugin::component::ANALYZER: { const analyzer::Component* c = - dynamic_cast(*it); + dynamic_cast(component); if ( c ) write_analyzer_component(f, c); @@ -78,10 +77,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) } break; - case plugin::component::FILE_ANALYZER: + case zeek::plugin::component::FILE_ANALYZER: { const file_analysis::Component* c = - dynamic_cast(*it); + dynamic_cast(component); if ( c ) write_analyzer_component(f, c); @@ -90,10 +89,10 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) } break; - case plugin::component::READER: + case zeek::plugin::component::READER: reporter->InternalError("docs for READER component unimplemented"); - case plugin::component::WRITER: + case zeek::plugin::component::WRITER: reporter->InternalError("docs for WRITER component unimplemented"); default: @@ -102,11 +101,11 @@ static void write_plugin_components(FILE* f, const plugin::Plugin* p) } } -static void write_plugin_bif_items(FILE* f, const plugin::Plugin* p, - plugin::BifItem::Type t, const string& heading) +static void write_plugin_bif_items(FILE* f, const zeek::plugin::Plugin* p, + zeek::plugin::BifItem::Type t, const string& heading) { - plugin::Plugin::bif_item_list bifitems = p->BifItems(); - plugin::Plugin::bif_item_list::iterator it = bifitems.begin(); + zeek::plugin::Plugin::bif_item_list bifitems = p->BifItems(); + zeek::plugin::Plugin::bif_item_list::iterator it = bifitems.begin(); while ( it != bifitems.end() ) { @@ -150,11 +149,11 @@ static void WriteAnalyzerTagDefn(FILE* f, const string& module) fprintf(f, "%s\n", doc->ReStructuredText().c_str()); } -static bool ComponentsMatch(const plugin::Plugin* p, plugin::component::Type t, +static bool ComponentsMatch(const zeek::plugin::Plugin* p, zeek::plugin::component::Type t, bool match_empty = false) { - plugin::Plugin::component_list components = p->Components(); - plugin::Plugin::component_list::const_iterator it; + zeek::plugin::Plugin::component_list components = p->Components(); + zeek::plugin::Plugin::component_list::const_iterator it; if ( components.empty() ) return match_empty; @@ -266,22 +265,22 @@ void ProtoAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const WriteAnalyzerTagDefn(f, "Analyzer"); - plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); - plugin::Manager::plugin_list::const_iterator it; + zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); + zeek::plugin::Manager::plugin_list::const_iterator it; for ( it = plugins.begin(); it != plugins.end(); ++it ) { - if ( ! ComponentsMatch(*it, plugin::component::ANALYZER, true) ) + if ( ! ComponentsMatch(*it, zeek::plugin::component::ANALYZER, true) ) continue; write_plugin_section_heading(f, *it); write_plugin_components(f, *it); - write_plugin_bif_items(f, *it, plugin::BifItem::CONSTANT, + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::CONSTANT, "Options/Constants"); - write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals"); - write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types"); - write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events"); - write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions"); } } @@ -292,22 +291,22 @@ void FileAnalyzerTarget::DoCreateAnalyzerDoc(FILE* f) const WriteAnalyzerTagDefn(f, "Files"); - plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); - plugin::Manager::plugin_list::const_iterator it; + zeek::plugin::Manager::plugin_list plugins = plugin_mgr->ActivePlugins(); + zeek::plugin::Manager::plugin_list::const_iterator it; for ( it = plugins.begin(); it != plugins.end(); ++it ) { - if ( ! ComponentsMatch(*it, plugin::component::FILE_ANALYZER) ) + if ( ! ComponentsMatch(*it, zeek::plugin::component::FILE_ANALYZER) ) continue; write_plugin_section_heading(f, *it); write_plugin_components(f, *it); - write_plugin_bif_items(f, *it, plugin::BifItem::CONSTANT, + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::CONSTANT, "Options/Constants"); - write_plugin_bif_items(f, *it, plugin::BifItem::GLOBAL, "Globals"); - write_plugin_bif_items(f, *it, plugin::BifItem::TYPE, "Types"); - write_plugin_bif_items(f, *it, plugin::BifItem::EVENT, "Events"); - write_plugin_bif_items(f, *it, plugin::BifItem::FUNCTION, "Functions"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::GLOBAL, "Globals"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::TYPE, "Types"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::EVENT, "Events"); + write_plugin_bif_items(f, *it, zeek::plugin::BifItem::FUNCTION, "Functions"); } } diff --git a/src/zeekygen/utils.cc b/src/zeekygen/utils.cc index c661b84539..fb016270b4 100644 --- a/src/zeekygen/utils.cc +++ b/src/zeekygen/utils.cc @@ -78,10 +78,10 @@ bool zeekygen::prettify_params(string& s) return false; } -bool zeekygen::is_public_api(const ID* id) +bool zeekygen::is_public_api(const zeek::detail::ID* id) { - return (id->Scope() == SCOPE_GLOBAL) || - (id->Scope() == SCOPE_MODULE && id->IsExport()); + return (id->Scope() == zeek::detail::SCOPE_GLOBAL) || + (id->Scope() == zeek::detail::SCOPE_MODULE && id->IsExport()); } time_t zeekygen::get_mtime(const string& filename) diff --git a/src/zeekygen/utils.h b/src/zeekygen/utils.h index e5ddcc49a4..3bf79101b0 100644 --- a/src/zeekygen/utils.h +++ b/src/zeekygen/utils.h @@ -6,7 +6,8 @@ #include // for time_t -class ID; +namespace zeek::detail { class ID; } +using ID [[deprecated("Remove in v4.1. Use zeek::detail::ID instead")]] = zeek::detail::ID; namespace zeekygen { @@ -25,7 +26,7 @@ bool prettify_params(std::string& s); * @return true if the ID is in the global scope or if it's exported in to * any modules namespace. */ -bool is_public_api(const ID* id); +bool is_public_api(const zeek::detail::ID* id); /** * Get the modification time of a file or abort if there's an error. diff --git a/testing/btest/plugins/func-hook-plugin/src/Plugin.cc b/testing/btest/plugins/func-hook-plugin/src/Plugin.cc index f1b089e65e..c71788fa86 100644 --- a/testing/btest/plugins/func-hook-plugin/src/Plugin.cc +++ b/testing/btest/plugins/func-hook-plugin/src/Plugin.cc @@ -61,7 +61,7 @@ std::pair> Plugin::HookFunctionCall(const Func* func, return {}; } -void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) +void Plugin::MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) { ODesc d; d.SetShort(); @@ -70,7 +70,9 @@ void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) hook_name(hook), d.Description()); } -void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) +void Plugin::MetaHookPost(zeek::plugin::HookType hook, + const zeek::plugin::HookArgumentList& args, + zeek::plugin::HookArgument result) { ODesc d1; d1.SetShort(); diff --git a/testing/btest/plugins/func-hook-plugin/src/Plugin.h b/testing/btest/plugins/func-hook-plugin/src/Plugin.h index c480466e9e..d437213719 100644 --- a/testing/btest/plugins/func-hook-plugin/src/Plugin.h +++ b/testing/btest/plugins/func-hook-plugin/src/Plugin.h @@ -6,7 +6,7 @@ namespace plugin { namespace Demo_Hooks { -class Plugin : public ::plugin::Plugin +class Plugin : public zeek::plugin::Plugin { protected: @@ -14,8 +14,11 @@ protected: Frame* frame, zeek::Args* args) override; - void MetaHookPre(HookType hook, const HookArgumentList& args) override; - void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) override; + void MetaHookPre(zeek::plugin::HookType hook, + const zeek::plugin::HookArgumentList& args) override; + void MetaHookPost(zeek::plugin::HookType hook, + const zeek::plugin::HookArgumentList& args, + zeek::plugin::HookArgument result) override; // Overridden from plugin::Plugin. plugin::Configuration Configure() override; diff --git a/testing/btest/plugins/hooks-plugin/src/Plugin.cc b/testing/btest/plugins/hooks-plugin/src/Plugin.cc index 473de5f5c0..4166443a6a 100644 --- a/testing/btest/plugins/hooks-plugin/src/Plugin.cc +++ b/testing/btest/plugins/hooks-plugin/src/Plugin.cc @@ -11,21 +11,21 @@ namespace plugin { namespace Demo_Hooks { Plugin plugin; } } using namespace plugin::Demo_Hooks; -plugin::Configuration Plugin::Configure() +zeek::plugin::Configuration Plugin::Configure() { - EnableHook(HOOK_LOAD_FILE); - EnableHook(HOOK_CALL_FUNCTION); - EnableHook(HOOK_QUEUE_EVENT); - EnableHook(HOOK_DRAIN_EVENTS); - EnableHook(HOOK_UPDATE_NETWORK_TIME); - EnableHook(META_HOOK_PRE); - EnableHook(META_HOOK_POST); - EnableHook(HOOK_BRO_OBJ_DTOR); - EnableHook(HOOK_SETUP_ANALYZER_TREE); - EnableHook(HOOK_LOG_INIT); - EnableHook(HOOK_LOG_WRITE); + EnableHook(zeek::plugin::HOOK_LOAD_FILE); + EnableHook(zeek::plugin::HOOK_CALL_FUNCTION); + EnableHook(zeek::plugin::HOOK_QUEUE_EVENT); + EnableHook(zeek::plugin::HOOK_DRAIN_EVENTS); + EnableHook(zeek::plugin::HOOK_UPDATE_NETWORK_TIME); + EnableHook(zeek::plugin::META_HOOK_PRE); + EnableHook(zeek::plugin::META_HOOK_POST); + EnableHook(zeek::plugin::HOOK_BRO_OBJ_DTOR); + EnableHook(zeek::plugin::HOOK_SETUP_ANALYZER_TREE); + EnableHook(zeek::plugin::HOOK_LOG_INIT); + EnableHook(zeek::plugin::HOOK_LOG_WRITE); - plugin::Configuration config; + zeek::plugin::Configuration config; config.name = "Demo::Hooks"; config.description = "Exercises all plugin hooks"; config.version.major = 1; @@ -34,11 +34,11 @@ plugin::Configuration Plugin::Configure() return config; } -static void describe_hook_args(const plugin::HookArgumentList& args, ODesc* d) +static void describe_hook_args(const zeek::plugin::HookArgumentList& args, ODesc* d) { bool first = true; - for ( plugin::HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ ) + for ( zeek::plugin::HookArgumentList::const_iterator i = args.begin(); i != args.end(); i++ ) { if ( ! first ) d->Add(", "); @@ -59,8 +59,8 @@ std::pair Plugin::HookCallFunction(const Func* func, Frame* frame, v { ODesc d; d.SetShort(); - HookArgument(func).Describe(&d); - HookArgument(args).Describe(&d); + zeek::plugin::HookArgument(func).Describe(&d); + zeek::plugin::HookArgument(args).Describe(&d); fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookCallFunction", d.Description()); @@ -71,7 +71,7 @@ bool Plugin::HookQueueEvent(Event* event) { ODesc d; d.SetShort(); - HookArgument(event).Describe(&d); + zeek::plugin::HookArgument(event).Describe(&d); fprintf(stderr, "%.6f %-15s %s\n", network_time, "| HookQueueEvent", d.Description()); @@ -105,7 +105,7 @@ void Plugin::HookBroObjDtor(void* obj) fprintf(stderr, "%.6f %-15s\n", ::network_time, "| HookBroObjDtor"); } -void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) +void Plugin::MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) { ODesc d; d.SetShort(); @@ -114,7 +114,7 @@ void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) hook_name(hook), d.Description()); } -void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) +void Plugin::MetaHookPost(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args, zeek::plugin::HookArgument result) { ODesc d1; d1.SetShort(); diff --git a/testing/btest/plugins/hooks-plugin/src/Plugin.h b/testing/btest/plugins/hooks-plugin/src/Plugin.h index 9319663e70..91ba95b387 100644 --- a/testing/btest/plugins/hooks-plugin/src/Plugin.h +++ b/testing/btest/plugins/hooks-plugin/src/Plugin.h @@ -6,7 +6,7 @@ namespace plugin { namespace Demo_Hooks { -class Plugin : public ::plugin::Plugin +class Plugin : public zeek::plugin::Plugin { protected: int HookLoadFile(const LoadType type, const std::string& file, const std::string& resolved) override; @@ -18,13 +18,13 @@ protected: void HookLogInit(const std::string& writer, const std::string& instantiating_filter, bool local, bool remote, const logging::WriterBackend::WriterInfo& info, int num_fields, const threading::Field* const* fields) override; bool HookLogWrite(const std::string& writer, const std::string& filter, const logging::WriterBackend::WriterInfo& info, int num_fields, const threading::Field* const* fields, threading::Value** vals) override; void HookSetupAnalyzerTree(Connection *conn) override; - void MetaHookPre(HookType hook, const HookArgumentList& args) override; - void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) override; + void MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) override; + void MetaHookPost(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args, zeek::plugin::HookArgument result) override; void RenderVal(const threading::Value* val, ODesc &d) const; - // Overridden from plugin::Plugin. - plugin::Configuration Configure() override; + // Overridden from zeek::plugin::Plugin. + zeek::plugin::Configuration Configure() override; }; extern Plugin plugin; diff --git a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc index c4f06fc651..7dba8c0a97 100644 --- a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc +++ b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.cc @@ -80,7 +80,7 @@ std::pair Plugin::HookCallFunction(const Func* func, Frame* frame, v /* return {}; */ /* } */ -void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) +void Plugin::MetaHookPre(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args) { ODesc d; d.SetShort(); @@ -89,7 +89,8 @@ void Plugin::MetaHookPre(HookType hook, const HookArgumentList& args) hook_name(hook), d.Description()); } -void Plugin::MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) +void Plugin::MetaHookPost(zeek::plugin::HookType hook, const zeek::plugin::HookArgumentList& args, + zeek::plugin::HookArgument result) { ODesc d1; d1.SetShort(); diff --git a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h index 305192b31e..5a3a79b4a7 100644 --- a/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h +++ b/testing/btest/plugins/legacy-func-hook-plugin/src/Plugin.h @@ -6,7 +6,7 @@ namespace plugin { namespace Demo_Hooks { -class Plugin : public ::plugin::Plugin +class Plugin : public zeek::plugin::Plugin { protected: std::pair HookCallFunction(const Func* func, Frame* frame, val_list* args) override; @@ -15,8 +15,11 @@ protected: /* Frame* frame, */ /* zeek::Args* args) override; */ - void MetaHookPre(HookType hook, const HookArgumentList& args) override; - void MetaHookPost(HookType hook, const HookArgumentList& args, HookArgument result) override; + void MetaHookPre(zeek::plugin::HookType hook, + const zeek::plugin::HookArgumentList& args) override; + void MetaHookPost(zeek::plugin::HookType hook, + const zeek::plugin::HookArgumentList& args, + zeek::plugin::HookArgument result) override; // Overridden from plugin::Plugin. plugin::Configuration Configure() override; 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; };