From ec9eff0bd5ce14619c0b4409df67800d16c975e7 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 24 Jun 2020 16:46:34 -0400 Subject: [PATCH] Use type aliases for IntrusivePtr definitions --- src/Anon.cc | 6 +- src/Attr.cc | 22 +- src/Attr.h | 42 ++- src/BifReturnVal.h | 3 +- src/CompHash.cc | 20 +- src/CompHash.h | 12 +- src/Conn.cc | 2 +- src/Conn.h | 9 +- src/DNS_Mgr.cc | 34 +- src/DNS_Mgr.h | 18 +- src/Debug.cc | 4 +- src/Debug.h | 3 +- src/Discard.h | 9 +- src/Event.h | 2 +- src/EventHandler.cc | 4 +- src/EventHandler.h | 11 +- src/Expr.cc | 342 ++++++++---------- src/Expr.h | 332 ++++++++--------- src/File.cc | 4 +- src/File.h | 14 +- src/Frame.cc | 15 +- src/Frame.h | 33 +- src/Func.cc | 42 +-- src/Func.h | 71 ++-- src/ID.cc | 57 +-- src/ID.h | 83 +++-- src/IP.cc | 18 +- src/IP.h | 15 +- src/OpaqueVal.cc | 48 +-- src/OpaqueVal.h | 65 ++-- src/Reporter.cc | 2 +- src/Reporter.h | 5 +- src/Scope.cc | 22 +- src/Scope.h | 55 +-- src/Sessions.cc | 2 +- src/Stmt.cc | 96 ++--- src/Stmt.h | 124 ++++--- src/Tag.cc | 7 +- src/Tag.h | 13 +- src/Trigger.cc | 8 +- src/Trigger.h | 3 + src/TunnelEncapsulation.cc | 2 +- src/TunnelEncapsulation.h | 5 +- src/Type.cc | 69 ++-- src/Type.h | 186 +++++----- src/Val.cc | 196 +++++----- src/Val.h | 265 +++++++------- src/Var.cc | 73 ++-- src/Var.h | 42 ++- src/analyzer/Analyzer.cc | 8 +- src/analyzer/Analyzer.h | 12 +- src/analyzer/Manager.cc | 2 +- src/analyzer/Tag.cc | 4 +- src/analyzer/Tag.h | 4 +- src/analyzer/protocol/arp/ARP.cc | 4 +- src/analyzer/protocol/arp/ARP.h | 4 +- src/analyzer/protocol/asn1/asn1.pac | 24 +- .../protocol/bittorrent/BitTorrentTracker.cc | 10 +- .../protocol/dce-rpc/dce_rpc-analyzer.pac | 2 +- src/analyzer/protocol/dhcp/dhcp-analyzer.pac | 4 +- src/analyzer/protocol/dhcp/dhcp-options.pac | 2 +- src/analyzer/protocol/dns/DNS.cc | 22 +- src/analyzer/protocol/dns/DNS.h | 20 +- src/analyzer/protocol/ftp/functions.bif | 4 +- .../protocol/gtpv1/gtpv1-analyzer.pac | 52 +-- src/analyzer/protocol/http/HTTP.cc | 8 +- src/analyzer/protocol/http/HTTP.h | 16 +- src/analyzer/protocol/icmp/ICMP.cc | 10 +- src/analyzer/protocol/icmp/ICMP.h | 13 +- src/analyzer/protocol/krb/KRB.cc | 6 +- src/analyzer/protocol/krb/KRB.h | 6 +- src/analyzer/protocol/krb/KRB_TCP.h | 6 +- src/analyzer/protocol/krb/krb-analyzer.pac | 10 +- src/analyzer/protocol/krb/krb-asn1.pac | 8 +- src/analyzer/protocol/krb/krb-padata.pac | 4 +- src/analyzer/protocol/krb/krb-types.pac | 24 +- src/analyzer/protocol/login/Login.cc | 14 +- src/analyzer/protocol/mime/MIME.cc | 10 +- src/analyzer/protocol/mime/MIME.h | 21 +- .../protocol/modbus/modbus-analyzer.pac | 12 +- src/analyzer/protocol/ntlm/ntlm-analyzer.pac | 12 +- src/analyzer/protocol/ntp/ntp-analyzer.pac | 20 +- .../protocol/radius/radius-analyzer.pac | 2 +- src/analyzer/protocol/rpc/MOUNT.cc | 16 +- src/analyzer/protocol/rpc/MOUNT.h | 10 +- src/analyzer/protocol/rpc/NFS.cc | 76 ++-- src/analyzer/protocol/rpc/NFS.h | 74 ++-- src/analyzer/protocol/rpc/Portmap.cc | 10 +- src/analyzer/protocol/rpc/Portmap.h | 8 +- src/analyzer/protocol/rpc/RPC.h | 8 +- src/analyzer/protocol/sip/sip-analyzer.pac | 4 +- src/analyzer/protocol/smb/smb-strings.pac | 16 +- src/analyzer/protocol/smb/smb-time.pac | 12 +- .../smb/smb1-com-transaction-secondary.pac | 2 +- .../protocol/smb/smb1-com-transaction.pac | 8 +- src/analyzer/protocol/smb/smb1-protocol.pac | 4 +- src/analyzer/protocol/smb/smb2-protocol.pac | 16 +- src/analyzer/protocol/snmp/snmp-analyzer.pac | 40 +- .../protocol/socks/socks-analyzer.pac | 4 +- src/analyzer/protocol/ssh/ssh-analyzer.pac | 4 +- src/analyzer/protocol/tcp/TCP.cc | 6 +- src/analyzer/protocol/tcp/TCP.h | 4 +- src/analyzer/protocol/tcp/TCP_Endpoint.cc | 2 +- src/analyzer/protocol/tcp/TCP_Endpoint.h | 6 +- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 8 +- src/analyzer/protocol/tcp/TCP_Reassembler.h | 12 +- src/analyzer/protocol/teredo/Teredo.cc | 4 +- src/analyzer/protocol/teredo/Teredo.h | 2 +- src/binpac_bro-lib.pac | 2 +- src/binpac_bro.h | 4 +- src/broker/Data.cc | 26 +- src/broker/Data.h | 25 +- src/broker/Manager.cc | 2 +- src/broker/Manager.h | 5 +- src/broker/Store.cc | 4 +- src/broker/Store.h | 10 +- src/broker/messaging.bif | 2 +- src/broker/store.bif | 14 +- src/file_analysis/Analyzer.cc | 4 +- src/file_analysis/Analyzer.h | 10 +- src/file_analysis/AnalyzerSet.cc | 14 +- src/file_analysis/AnalyzerSet.h | 16 +- src/file_analysis/Component.h | 3 +- src/file_analysis/File.cc | 10 +- src/file_analysis/File.h | 19 +- src/file_analysis/Manager.cc | 10 +- src/file_analysis/Manager.h | 10 +- src/file_analysis/Tag.cc | 4 +- src/file_analysis/Tag.h | 4 +- .../analyzer/data_event/DataEvent.cc | 4 +- .../analyzer/data_event/DataEvent.h | 4 +- src/file_analysis/analyzer/entropy/Entropy.cc | 4 +- src/file_analysis/analyzer/entropy/Entropy.h | 4 +- src/file_analysis/analyzer/extract/Extract.cc | 8 +- src/file_analysis/analyzer/extract/Extract.h | 4 +- src/file_analysis/analyzer/hash/Hash.cc | 2 +- src/file_analysis/analyzer/hash/Hash.h | 14 +- src/file_analysis/analyzer/pe/PE.cc | 2 +- src/file_analysis/analyzer/pe/PE.h | 4 +- src/file_analysis/analyzer/pe/pe-analyzer.pac | 8 +- .../analyzer/unified2/Unified2.cc | 4 +- .../analyzer/unified2/Unified2.h | 5 +- .../analyzer/unified2/unified2-analyzer.pac | 8 +- src/file_analysis/analyzer/x509/OCSP.cc | 16 +- src/file_analysis/analyzer/x509/OCSP.h | 6 +- src/file_analysis/analyzer/x509/X509.cc | 16 +- src/file_analysis/analyzer/x509/X509.h | 18 +- src/file_analysis/analyzer/x509/X509Common.cc | 4 +- src/file_analysis/analyzer/x509/X509Common.h | 8 +- src/file_analysis/analyzer/x509/functions.bif | 8 +- src/input/Manager.cc | 22 +- src/input/Tag.cc | 4 +- src/input/Tag.h | 4 +- src/iosource/Packet.cc | 5 +- src/iosource/Packet.h | 13 +- src/logging/Manager.cc | 6 +- src/logging/Tag.cc | 4 +- src/logging/Tag.h | 4 +- src/option.bif | 5 +- src/parse.y | 59 ++- src/plugin/ComponentManager.h | 11 +- src/plugin/Manager.cc | 4 +- src/plugin/Manager.h | 2 +- src/plugin/Plugin.cc | 2 +- src/plugin/Plugin.h | 4 +- src/probabilistic/Topk.cc | 9 +- src/probabilistic/Topk.h | 14 +- src/scan.l | 2 +- src/stats.bif | 26 +- src/strings.bif | 8 +- src/supervisor/Supervisor.cc | 8 +- src/supervisor/Supervisor.h | 6 +- src/threading/SerialTypes.cc | 6 +- src/zeek-setup.cc | 20 +- src/zeek.bif | 24 +- src/zeekygen/IdentifierInfo.cc | 13 +- src/zeekygen/IdentifierInfo.h | 14 +- src/zeekygen/Manager.cc | 9 +- src/zeekygen/Manager.h | 9 +- src/zeekygen/zeekygen.bif | 2 +- 180 files changed, 2026 insertions(+), 1893 deletions(-) diff --git a/src/Anon.cc b/src/Anon.cc index e2e1d73a54..9c53b40cec 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -358,9 +358,9 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a) return nullptr; } -static zeek::IntrusivePtr anon_preserve_orig_addr; -static zeek::IntrusivePtr anon_preserve_resp_addr; -static zeek::IntrusivePtr anon_preserve_other_addr; +static TableValPtr anon_preserve_orig_addr; +static TableValPtr anon_preserve_resp_addr; +static TableValPtr anon_preserve_other_addr; void zeek::detail::init_ip_addr_anonymizers() { diff --git a/src/Attr.cc b/src/Attr.cc index a7a0717e18..a32cc89668 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -25,7 +25,7 @@ const char* attr_name(AttrTag t) return attr_names[int(t)]; } -Attr::Attr(AttrTag t, zeek::IntrusivePtr e) +Attr::Attr(AttrTag t, ExprPtr e) : expr(std::move(e)) { tag = t; @@ -37,7 +37,7 @@ Attr::Attr(AttrTag t) { } -void Attr::SetAttrExpr(zeek::IntrusivePtr e) +void Attr::SetAttrExpr(ExprPtr e) { expr = std::move(e); } void Attr::Describe(ODesc* d) const @@ -136,7 +136,7 @@ void Attr::AddTag(ODesc* d) const d->Add(attr_name(Tag())); } -Attributes::Attributes(attr_list* a, zeek::IntrusivePtr t, bool arg_in_record, bool is_global) +Attributes::Attributes(attr_list* a, TypePtr t, bool arg_in_record, bool is_global) { attrs_list.resize(a->length()); attrs.reserve(a->length()); @@ -155,15 +155,13 @@ Attributes::Attributes(attr_list* a, zeek::IntrusivePtr t, bool arg_in_rec delete a; } -Attributes::Attributes(zeek::IntrusivePtr t, - bool arg_in_record, bool is_global) - : Attributes(std::vector>{}, std::move(t), +Attributes::Attributes(TypePtr t, bool arg_in_record, bool is_global) + : Attributes(std::vector{}, std::move(t), arg_in_record, is_global) {} -Attributes::Attributes(std::vector> a, - zeek::IntrusivePtr t, - bool arg_in_record, bool is_global) +Attributes::Attributes(std::vector a, + TypePtr t, bool arg_in_record, bool is_global) : type(std::move(t)) { attrs_list.resize(a.size()); @@ -181,7 +179,7 @@ Attributes::Attributes(std::vector> a, AddAttr(std::move(attr)); } -void Attributes::AddAttr(zeek::IntrusivePtr attr) +void Attributes::AddAttr(AttrPtr attr) { // We overwrite old attributes by deleting them first. RemoveAttr(attr->Tag()); @@ -212,7 +210,7 @@ void Attributes::AddAttr(zeek::IntrusivePtr attr) } } -void Attributes::AddAttrs(const zeek::IntrusivePtr& a) +void Attributes::AddAttrs(const AttributesPtr& a) { for ( const auto& attr : a->GetAttrs() ) AddAttr(attr); @@ -235,7 +233,7 @@ Attr* Attributes::FindAttr(AttrTag t) const return nullptr; } -const zeek::IntrusivePtr& Attributes::Find(AttrTag t) const +const AttrPtr& Attributes::Find(AttrTag t) const { for ( const auto& a : attrs ) if ( a->Tag() == t ) diff --git a/src/Attr.h b/src/Attr.h index 671a428f98..a1ff47dcc7 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -10,6 +10,15 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +namespace zeek { +class Type; +using TypePtr = IntrusivePtr; + +namespace detail { +using ExprPtr = zeek::IntrusivePtr; +} +} + // 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. @@ -38,11 +47,16 @@ enum AttrTag { NUM_ATTRS // this item should always be last }; +class Attr; +using AttrPtr = zeek::IntrusivePtr; +class Attributes; +using AttributesPtr = zeek::IntrusivePtr; + class Attr final : public BroObj { public: - static inline const zeek::IntrusivePtr nil; + static inline const AttrPtr nil; - Attr(AttrTag t, zeek::IntrusivePtr e); + Attr(AttrTag t, ExprPtr e); explicit Attr(AttrTag t); ~Attr() override = default; @@ -52,10 +66,10 @@ public: [[deprecated("Remove in v4.1. Use GetExpr().")]] zeek::detail::Expr* AttrExpr() const { return expr.get(); } - const zeek::IntrusivePtr& GetExpr() const + const ExprPtr& GetExpr() const { return expr; } - void SetAttrExpr(zeek::IntrusivePtr e); + void SetAttrExpr(ExprPtr e); void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool shorten = false) const; @@ -78,24 +92,24 @@ protected: void AddTag(ODesc* d) const; AttrTag tag; - zeek::IntrusivePtr expr; + ExprPtr expr; }; // Manages a collection of attributes. class Attributes final : public BroObj { public: [[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]] - Attributes(attr_list* a, zeek::IntrusivePtr t, bool in_record, bool is_global); + Attributes(attr_list* a, zeek::TypePtr t, bool in_record, bool is_global); - Attributes(std::vector> a, zeek::IntrusivePtr t, + Attributes(std::vector a, zeek::TypePtr t, bool in_record, bool is_global); - Attributes(zeek::IntrusivePtr t, bool in_record, bool is_global); + Attributes(TypePtr t, bool in_record, bool is_global); ~Attributes() override = default; - void AddAttr(zeek::IntrusivePtr a); + void AddAttr(AttrPtr a); - void AddAttrs(const zeek::IntrusivePtr& a); + void AddAttrs(const AttributesPtr& a); [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] void AddAttrs(Attributes* a); // Unref's 'a' when done @@ -103,7 +117,7 @@ public: [[deprecated("Remove in v4.1. Use Find().")]] Attr* FindAttr(AttrTag t) const; - const zeek::IntrusivePtr& Find(AttrTag t) const; + const AttrPtr& Find(AttrTag t) const; void RemoveAttr(AttrTag t); @@ -114,7 +128,7 @@ public: const attr_list* Attrs() const { return &attrs_list; } - const std::vector>& GetAttrs() const + const std::vector& GetAttrs() const { return attrs; } bool operator==(const Attributes& other) const; @@ -122,8 +136,8 @@ public: protected: void CheckAttr(Attr* attr); - zeek::IntrusivePtr type; - std::vector> attrs; + TypePtr type; + std::vector attrs; // Remove in v4.1. This is used by Attrs(), which is deprecated. attr_list attrs_list; diff --git a/src/BifReturnVal.h b/src/BifReturnVal.h index 143aaf500d..6398093d6d 100644 --- a/src/BifReturnVal.h +++ b/src/BifReturnVal.h @@ -5,6 +5,7 @@ #include "IntrusivePtr.h" class Val; +using ValPtr = zeek::IntrusivePtr; /** * A simple wrapper class to use for the return value of BIFs so that @@ -24,5 +25,5 @@ public: [[deprecated("Remove in v4.1. Return an IntrusivePtr instead.")]] BifReturnVal(Val* v) noexcept; - zeek::IntrusivePtr rval; + ValPtr rval; }; diff --git a/src/CompHash.cc b/src/CompHash.cc index ca72584ea4..f64bb801ed 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -15,7 +15,7 @@ #include "Func.h" #include "IPAddr.h" -CompositeHash::CompositeHash(zeek::IntrusivePtr composite_type) +CompositeHash::CompositeHash(zeek::TypeListPtr composite_type) : type(std::move(composite_type)) { singleton_tag = zeek::TYPE_INTERNAL_ERROR; @@ -709,7 +709,7 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const return offset; } -zeek::IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const +ListValPtr CompositeHash::RecoverVals(const HashKey& k) const { auto l = zeek::make_intrusive(zeek::TYPE_ANY); const auto& tl = type->GetTypes(); @@ -718,7 +718,7 @@ zeek::IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const for ( const auto& type : tl ) { - zeek::IntrusivePtr v; + ValPtr v; kp = RecoverOneVal(k, kp, k_end, type.get(), &v, false); ASSERT(v); l->Append(std::move(v)); @@ -733,7 +733,7 @@ zeek::IntrusivePtr CompositeHash::RecoverVals(const HashKey& k) const const char* CompositeHash::RecoverOneVal( const HashKey& k, const char* kp0, const char* const k_end, zeek::Type* t, - zeek::IntrusivePtr* pval, bool optional) const + ValPtr* pval, bool optional) const { // k->Size() == 0 for a single empty string. if ( kp0 >= k_end && k.Size() > 0 ) @@ -904,11 +904,11 @@ const char* CompositeHash::RecoverOneVal( zeek::RecordType* rt = t->AsRecordType(); int num_fields = rt->NumFields(); - std::vector> values; + std::vector values; int i; for ( i = 0; i < num_fields; ++i ) { - zeek::IntrusivePtr v; + ValPtr v; zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL)); @@ -952,14 +952,14 @@ const char* CompositeHash::RecoverOneVal( for ( int i = 0; i < n; ++i ) { - zeek::IntrusivePtr key; + ValPtr key; kp1 = RecoverOneVal(k, kp1, k_end, tt->GetIndices().get(), &key, false); if ( t->IsSet() ) tv->Assign(std::move(key), nullptr); else { - zeek::IntrusivePtr value; + ValPtr value; kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value, false); tv->Assign(std::move(key), std::move(value)); @@ -987,7 +987,7 @@ const char* CompositeHash::RecoverOneVal( kp = AlignType(kp1); unsigned int have_val = *kp; kp1 = reinterpret_cast(kp+1); - zeek::IntrusivePtr value; + ValPtr value; if ( have_val ) kp1 = RecoverOneVal(k, kp1, k_end, vt->Yield().get(), &value, @@ -1011,7 +1011,7 @@ const char* CompositeHash::RecoverOneVal( for ( int i = 0; i < n; ++i ) { - zeek::IntrusivePtr v; + ValPtr v; zeek::Type* it = tl->GetTypes()[i].get(); kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); lv->Append(std::move(v)); diff --git a/src/CompHash.h b/src/CompHash.h index c900366680..c2103e0cb3 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -10,9 +10,11 @@ class ListVal; class HashKey; +using ListValPtr = zeek::IntrusivePtr; + class CompositeHash { public: - explicit CompositeHash(zeek::IntrusivePtr composite_type); + explicit CompositeHash(zeek::TypeListPtr composite_type); ~CompositeHash(); // Compute the hash corresponding to the given index val, @@ -24,10 +26,10 @@ public: { return MakeHashKey(*v, type_check).release(); } // Given a hash key, recover the values used to create it. - zeek::IntrusivePtr RecoverVals(const HashKey& k) const; + ListValPtr RecoverVals(const HashKey& k) const; [[deprecated("Remove in v4.1. Pass in HashKey& instead.")]] - zeek::IntrusivePtr RecoverVals(const HashKey* k) const + ListValPtr RecoverVals(const HashKey* k) const { return RecoverVals(*k); } unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); } @@ -46,7 +48,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, - zeek::Type* t, zeek::IntrusivePtr* pval, bool optional) const; + zeek::Type* t, ValPtr* pval, bool optional) const; // Rounds the given pointer up to the nearest multiple of the // given size, if not already a multiple. @@ -89,7 +91,7 @@ protected: bool type_check, int sz, bool optional, bool calc_static_size) const; - zeek::IntrusivePtr type; + zeek::TypeListPtr type; char* key; // space for composite key int size; bool is_singleton; // if just one type in index diff --git a/src/Conn.cc b/src/Conn.cc index 81d6667300..7b393c5e9a 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -342,7 +342,7 @@ RecordVal* Connection::BuildConnVal() return ConnVal()->Ref()->AsRecordVal(); } -const zeek::IntrusivePtr& Connection::ConnVal() +const RecordValPtr& Connection::ConnVal() { if ( ! conn_val ) { diff --git a/src/Conn.h b/src/Conn.h index 0297eb8310..9182868c7d 100644 --- a/src/Conn.h +++ b/src/Conn.h @@ -32,6 +32,9 @@ class EncapsulationStack; class Val; class RecordVal; +using ValPtr = zeek::IntrusivePtr; +using RecordValPtr = zeek::IntrusivePtr; + namespace analyzer { class TransportLayerAnalyzer; } typedef enum { @@ -169,7 +172,7 @@ public: /** * Returns the associated "connection" record. */ - const zeek::IntrusivePtr& ConnVal(); + const RecordValPtr& ConnVal(); void AppendAddl(const char* str); @@ -235,7 +238,7 @@ public: template std::enable_if_t< std::is_convertible_v< - std::tuple_element_t<0, std::tuple>, zeek::IntrusivePtr>> + std::tuple_element_t<0, std::tuple>, ValPtr>> EnqueueEvent(EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args) { return EnqueueEvent(h, analyzer, zeek::Args{std::forward(args)...}); } @@ -355,7 +358,7 @@ protected: u_char resp_l2_addr[Packet::l2_addr_len]; // Link-layer responder address, if available double start_time, last_time; double inactivity_timeout; - zeek::IntrusivePtr conn_val; + RecordValPtr conn_val; LoginConn* login_conn; // either nil, or this const EncapsulationStack* encapsulation; // tunnels int suppress_event; // suppress certain events to once per conn. diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 2c714a72d5..54599e2747 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -122,9 +122,9 @@ public: return req_host ? req_host : req_addr.AsString(); } - zeek::IntrusivePtr Addrs(); - zeek::IntrusivePtr AddrsSet(); // addresses returned as a set - zeek::IntrusivePtr Host(); + ListValPtr Addrs(); + TableValPtr AddrsSet(); // addresses returned as a set + StringValPtr Host(); double CreationTime() const { return creation_time; } @@ -155,11 +155,11 @@ protected: int num_names; char** names; - zeek::IntrusivePtr host_val; + StringValPtr host_val; int num_addrs; IPAddr* addrs; - zeek::IntrusivePtr addrs_val; + ListValPtr addrs_val; double creation_time; int map_type; @@ -173,7 +173,7 @@ void DNS_Mgr_mapping_delete_func(void* v) delete (DNS_Mapping*) v; } -static zeek::IntrusivePtr empty_addr_set() +static TableValPtr empty_addr_set() { auto addr_t = zeek::base_type(zeek::TYPE_ADDR); auto set_index = zeek::make_intrusive(addr_t); @@ -276,7 +276,7 @@ DNS_Mapping::~DNS_Mapping() delete [] addrs; } -zeek::IntrusivePtr DNS_Mapping::Addrs() +ListValPtr DNS_Mapping::Addrs() { if ( failed ) return nullptr; @@ -292,7 +292,7 @@ zeek::IntrusivePtr DNS_Mapping::Addrs() return addrs_val; } -zeek::IntrusivePtr DNS_Mapping::AddrsSet() { +TableValPtr DNS_Mapping::AddrsSet() { auto l = Addrs(); if ( ! l ) @@ -301,7 +301,7 @@ zeek::IntrusivePtr DNS_Mapping::AddrsSet() { return l->ToSetVal(); } -zeek::IntrusivePtr DNS_Mapping::Host() +StringValPtr DNS_Mapping::Host() { if ( failed || num_names == 0 || ! names[0] ) return nullptr; @@ -461,7 +461,7 @@ void DNS_Mgr::InitPostScript() LoadCache(fopen(cache_name, "r")); } -static zeek::IntrusivePtr fake_name_lookup_result(const char* name) +static TableValPtr fake_name_lookup_result(const char* name) { hash128_t hash; KeyedHash::StaticHash128(name, strlen(name), &hash); @@ -485,7 +485,7 @@ static const char* fake_addr_lookup_result(const IPAddr& addr) return tmp; } -zeek::IntrusivePtr DNS_Mgr::LookupHost(const char* name) +TableValPtr DNS_Mgr::LookupHost(const char* name) { if ( mode == DNS_FAKE ) return fake_name_lookup_result(name); @@ -542,7 +542,7 @@ zeek::IntrusivePtr DNS_Mgr::LookupHost(const char* name) } } -zeek::IntrusivePtr DNS_Mgr::LookupAddr(const IPAddr& addr) +ValPtr DNS_Mgr::LookupAddr(const IPAddr& addr) { InitSource(); @@ -698,7 +698,7 @@ void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm) } void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm, - zeek::IntrusivePtr l1, zeek::IntrusivePtr l2) + ListValPtr l1, ListValPtr l2) { if ( ! e ) return; @@ -714,7 +714,7 @@ void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* old_dm, DNS_Mapping* new_dm) mgr.Enqueue(e, BuildMappingVal(old_dm), BuildMappingVal(new_dm)); } -zeek::IntrusivePtr DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) +ValPtr DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) { auto r = zeek::make_intrusive(dm_rec); @@ -870,7 +870,7 @@ void DNS_Mgr::CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm) Event(dns_mapping_altered, new_dm, std::move(prev_delta), std::move(new_delta)); } -zeek::IntrusivePtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) +ListValPtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) { auto delta = zeek::make_intrusive(zeek::TYPE_ADDR); @@ -980,7 +980,7 @@ const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr) return d->names ? d->names[0] : "<\?\?\?>"; } -zeek::IntrusivePtr DNS_Mgr::LookupNameInCache(const string& name) +TableValPtr DNS_Mgr::LookupNameInCache(const string& name) { HostMap::iterator it = host_mappings.find(name); if ( it == host_mappings.end() ) @@ -1030,7 +1030,7 @@ const char* DNS_Mgr::LookupTextInCache(const string& name) } static void resolve_lookup_cb(DNS_Mgr::LookupCallback* callback, - zeek::IntrusivePtr result) + TableValPtr result) { callback->Resolved(result.get()); delete callback; diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 55696900ae..2669d2c2b7 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -21,6 +21,10 @@ class Func; class EventHandler; class DNS_Mgr_Request; +using ValPtr = zeek::IntrusivePtr; +using ListValPtr = zeek::IntrusivePtr; +using TableValPtr = zeek::IntrusivePtr; + ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); typedef PList DNS_mgr_request_list; @@ -50,9 +54,9 @@ public: // Looks up the address or addresses of the given host, and returns // a set of addr. - zeek::IntrusivePtr LookupHost(const char* host); + TableValPtr LookupHost(const char* host); - zeek::IntrusivePtr LookupAddr(const IPAddr& addr); + ValPtr LookupAddr(const IPAddr& addr); // Define the directory where to store the data. void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); } @@ -62,7 +66,7 @@ public: bool Save(); const char* LookupAddrInCache(const IPAddr& addr); - zeek::IntrusivePtr LookupNameInCache(const std::string& name); + TableValPtr LookupNameInCache(const std::string& name); const char* LookupTextInCache(const std::string& name); // Support for async lookups. @@ -100,14 +104,14 @@ protected: void Event(EventHandlerPtr e, DNS_Mapping* dm); void Event(EventHandlerPtr e, DNS_Mapping* dm, - zeek::IntrusivePtr l1, zeek::IntrusivePtr l2); + ListValPtr l1, ListValPtr l2); void Event(EventHandlerPtr e, DNS_Mapping* old_dm, DNS_Mapping* new_dm); - zeek::IntrusivePtr BuildMappingVal(DNS_Mapping* dm); + ValPtr BuildMappingVal(DNS_Mapping* dm); void AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r); void CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm); - zeek::IntrusivePtr AddrListDelta(ListVal* al1, ListVal* al2); + ListValPtr AddrListDelta(ListVal* al1, ListVal* al2); void DumpAddrList(FILE* f, ListVal* al); typedef std::map > HostMap; @@ -151,7 +155,7 @@ protected: bool did_init; - zeek::IntrusivePtr dm_rec; + zeek::RecordTypePtr dm_rec; typedef std::list CallbackList; diff --git a/src/Debug.cc b/src/Debug.cc index 6d81564617..90fbdf3e7c 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -948,7 +948,7 @@ extern YYLTYPE yylloc; // holds start line and column of token extern int line_number; extern const char* filename; -zeek::IntrusivePtr dbg_eval_expr(const char* expr) +ValPtr dbg_eval_expr(const char* expr) { // Push the current frame's associated scope. // Note: g_debugger_state.curr_frame_idx is the user-visible number, @@ -983,7 +983,7 @@ zeek::IntrusivePtr dbg_eval_expr(const char* expr) yylloc.first_line = yylloc.last_line = line_number = 1; // Parse the thing into an expr. - zeek::IntrusivePtr result; + ValPtr result; if ( yyparse() ) { if ( g_curr_debug_error ) diff --git a/src/Debug.h b/src/Debug.h index bcd743fc2d..8e885d9fc2 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -16,6 +16,7 @@ template class IntrusivePtr; } class Val; +using ValPtr = zeek::IntrusivePtr; ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); @@ -165,7 +166,7 @@ int dbg_handle_debug_input(); // read a line and then have it executed int dbg_execute_command(const char* cmd); // Interactive expression evaluation. -zeek::IntrusivePtr dbg_eval_expr(const char* expr); +ValPtr dbg_eval_expr(const char* expr); // Extra debugging facilities. // TODO: current connections, memory allocated, other internal data structures. diff --git a/src/Discard.h b/src/Discard.h index d04ee2dcd8..df29df2175 100644 --- a/src/Discard.h +++ b/src/Discard.h @@ -9,6 +9,7 @@ class IP_Hdr; class Val; class Func; +using FuncPtr = zeek::IntrusivePtr; class Discarder { public: @@ -22,10 +23,10 @@ public: protected: Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); - zeek::IntrusivePtr check_ip; - zeek::IntrusivePtr check_tcp; - zeek::IntrusivePtr check_udp; - zeek::IntrusivePtr check_icmp; + FuncPtr check_ip; + FuncPtr check_tcp; + FuncPtr check_udp; + FuncPtr check_icmp; // Maximum amount of application data passed to filtering functions. int discarder_maxlen; diff --git a/src/Event.h b/src/Event.h index 75ff3450a0..c8f9083d2f 100644 --- a/src/Event.h +++ b/src/Event.h @@ -108,7 +108,7 @@ public: template std::enable_if_t< std::is_convertible_v< - std::tuple_element_t<0, std::tuple>, zeek::IntrusivePtr>> + std::tuple_element_t<0, std::tuple>, ValPtr>> Enqueue(const EventHandlerPtr& h, Args&&... args) { return Enqueue(h, zeek::Args{std::forward(args)...}); } diff --git a/src/EventHandler.cc b/src/EventHandler.cc index d73dc1fdd1..a5a238529e 100644 --- a/src/EventHandler.cc +++ b/src/EventHandler.cc @@ -26,7 +26,7 @@ EventHandler::operator bool() const || ! auto_publish.empty()); } -const zeek::IntrusivePtr& EventHandler::GetType(bool check_export) +const zeek::FuncTypePtr& EventHandler::GetType(bool check_export) { if ( type ) return type; @@ -44,7 +44,7 @@ const zeek::IntrusivePtr& EventHandler::GetType(bool check_expor return type; } -void EventHandler::SetFunc(zeek::IntrusivePtr f) +void EventHandler::SetFunc(FuncPtr f) { local = std::move(f); } void EventHandler::SetLocalHandler(Func* f) diff --git a/src/EventHandler.h b/src/EventHandler.h index 746522f53f..f73ab78a86 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -10,6 +10,7 @@ #include class Func; +using FuncPtr = zeek::IntrusivePtr; class EventHandler { public: @@ -17,19 +18,19 @@ public: const char* Name() { return name.data(); } - const zeek::IntrusivePtr& GetFunc() + const FuncPtr& GetFunc() { return local; } [[deprecated("Remove in v4.1. Use GetFunc().")]] Func* LocalHandler() { return local.get(); } - const zeek::IntrusivePtr& GetType(bool check_export = true); + const zeek::FuncTypePtr& GetType(bool check_export = true); [[deprecated("Remove in v4.1. Use GetType().")]] zeek::FuncType* FType(bool check_export = true) { return GetType().get(); } - void SetFunc(zeek::IntrusivePtr f); + void SetFunc(FuncPtr f); [[deprecated("Remove in v4.1. Use SetFunc().")]] void SetLocalHandler(Func* f); @@ -68,8 +69,8 @@ private: void NewEvent(zeek::Args* vl); // Raise new_event() meta event. std::string name; - zeek::IntrusivePtr local; - zeek::IntrusivePtr type; + FuncPtr local; + zeek::FuncTypePtr 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 12f0c639e2..b94f2d161c 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -82,7 +82,7 @@ void Expr::Delete(Frame* /* f */) Internal("Expr::Delete called"); } -zeek::IntrusivePtr Expr::MakeLvalue() +ExprPtr Expr::MakeLvalue() { if ( ! IsError() ) ExprError("can't be assigned to"); @@ -96,12 +96,12 @@ void Expr::EvalIntoAggregate(const zeek::Type* /* t */, Val* /* aggr */, Internal("Expr::EvalIntoAggregate called"); } -void Expr::Assign(Frame* /* f */, zeek::IntrusivePtr /* v */) +void Expr::Assign(Frame* /* f */, ValPtr /* v */) { Internal("Expr::Assign called"); } -zeek::IntrusivePtr Expr::InitType() const +zeek::TypePtr Expr::InitType() const { return type; } @@ -116,7 +116,7 @@ bool Expr::IsPure() const return true; } -zeek::IntrusivePtr Expr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr Expr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( aggr ) { @@ -182,7 +182,7 @@ void Expr::Canonicize() { } -void Expr::SetType(zeek::IntrusivePtr t) +void Expr::SetType(zeek::TypePtr t) { if ( ! type || type->Tag() != zeek::TYPE_ERROR ) type = std::move(t); @@ -215,7 +215,7 @@ void Expr::RuntimeErrorWithCallStack(const std::string& msg) const } } -NameExpr::NameExpr(zeek::IntrusivePtr arg_id, bool const_init) +NameExpr::NameExpr(zeek::detail::IDPtr arg_id, bool const_init) : Expr(EXPR_NAME), id(std::move(arg_id)) { in_const_init = const_init; @@ -230,9 +230,9 @@ NameExpr::NameExpr(zeek::IntrusivePtr arg_id, bool const_init) h->SetUsed(); } -zeek::IntrusivePtr NameExpr::Eval(Frame* f) const +ValPtr NameExpr::Eval(Frame* f) const { - zeek::IntrusivePtr v; + ValPtr v; if ( id->IsType() ) return zeek::make_intrusive(id->GetType(), true); @@ -256,7 +256,7 @@ zeek::IntrusivePtr NameExpr::Eval(Frame* f) const } } -zeek::IntrusivePtr NameExpr::MakeLvalue() +ExprPtr NameExpr::MakeLvalue() { if ( id->IsType() ) ExprError("Type name is not an lvalue"); @@ -270,7 +270,7 @@ zeek::IntrusivePtr NameExpr::MakeLvalue() return zeek::make_intrusive(IntrusivePtr{zeek::NewRef{}, this}); } -void NameExpr::Assign(Frame* f, zeek::IntrusivePtr v) +void NameExpr::Assign(Frame* f, ValPtr v) { if ( id->IsGlobal() ) id->SetVal(std::move(v)); @@ -309,7 +309,7 @@ void NameExpr::ExprDescribe(ODesc* d) const } } -ConstExpr::ConstExpr(zeek::IntrusivePtr arg_val) +ConstExpr::ConstExpr(ValPtr arg_val) : Expr(EXPR_CONST), val(std::move(arg_val)) { if ( val->GetType()->Tag() == zeek::TYPE_LIST && val->AsListVal()->Length() == 1 ) @@ -323,7 +323,7 @@ void ConstExpr::ExprDescribe(ODesc* d) const val->Describe(d); } -zeek::IntrusivePtr ConstExpr::Eval(Frame* /* f */) const +ValPtr ConstExpr::Eval(Frame* /* f */) const { return {zeek::NewRef{}, Value()}; } @@ -337,14 +337,14 @@ TraversalCode ConstExpr::Traverse(TraversalCallback* cb) const HANDLE_TC_EXPR_POST(tc); } -UnaryExpr::UnaryExpr(BroExprTag arg_tag, zeek::IntrusivePtr arg_op) +UnaryExpr::UnaryExpr(BroExprTag arg_tag, ExprPtr arg_op) : Expr(arg_tag), op(std::move(arg_op)) { if ( op->IsError() ) SetError(); } -zeek::IntrusivePtr UnaryExpr::Eval(Frame* f) const +ValPtr UnaryExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -357,7 +357,7 @@ zeek::IntrusivePtr UnaryExpr::Eval(Frame* f) const if ( is_vector(v) && Tag() != EXPR_IS && Tag() != EXPR_CAST ) { VectorVal* v_op = v->AsVectorVal(); - zeek::IntrusivePtr out_t; + zeek::VectorTypePtr out_t; if ( GetType()->Tag() == zeek::TYPE_ANY ) out_t = v->GetType(); @@ -397,7 +397,7 @@ TraversalCode UnaryExpr::Traverse(TraversalCallback* cb) const HANDLE_TC_EXPR_POST(tc); } -zeek::IntrusivePtr UnaryExpr::Fold(Val* v) const +ValPtr UnaryExpr::Fold(Val* v) const { return {zeek::NewRef{}, v}; } @@ -426,7 +426,7 @@ void UnaryExpr::ExprDescribe(ODesc* d) const } } -zeek::IntrusivePtr BinaryExpr::Eval(Frame* f) const +ValPtr BinaryExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -523,7 +523,7 @@ void BinaryExpr::ExprDescribe(ODesc* d) const op2->Describe(d); } -zeek::IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const +ValPtr BinaryExpr::Fold(Val* v1, Val* v2) const { InternalTypeTag it = v1->GetType()->InternalType(); @@ -690,7 +690,7 @@ zeek::IntrusivePtr BinaryExpr::Fold(Val* v1, Val* v2) const return val_mgr->Int(i3); } -zeek::IntrusivePtr BinaryExpr::StringFold(Val* v1, Val* v2) const +ValPtr BinaryExpr::StringFold(Val* v1, Val* v2) const { const BroString* s1 = v1->AsString(); const BroString* s2 = v2->AsString(); @@ -725,7 +725,7 @@ zeek::IntrusivePtr BinaryExpr::StringFold(Val* v1, Val* v2) const } -zeek::IntrusivePtr BinaryExpr::PatternFold(Val* v1, Val* v2) const +ValPtr BinaryExpr::PatternFold(Val* v1, Val* v2) const { const RE_Matcher* re1 = v1->AsPattern(); const RE_Matcher* re2 = v2->AsPattern(); @@ -740,7 +740,7 @@ zeek::IntrusivePtr BinaryExpr::PatternFold(Val* v1, Val* v2) const return zeek::make_intrusive(res); } -zeek::IntrusivePtr BinaryExpr::SetFold(Val* v1, Val* v2) const +ValPtr BinaryExpr::SetFold(Val* v1, Val* v2) const { TableVal* tv1 = v1->AsTableVal(); TableVal* tv2 = v2->AsTableVal(); @@ -800,7 +800,7 @@ zeek::IntrusivePtr BinaryExpr::SetFold(Val* v1, Val* v2) const return val_mgr->Bool(res); } -zeek::IntrusivePtr BinaryExpr::AddrFold(Val* v1, Val* v2) const +ValPtr BinaryExpr::AddrFold(Val* v1, Val* v2) const { IPAddr a1 = v1->AsAddr(); IPAddr a2 = v2->AsAddr(); @@ -834,7 +834,7 @@ zeek::IntrusivePtr BinaryExpr::AddrFold(Val* v1, Val* v2) const return val_mgr->Bool(result); } -zeek::IntrusivePtr BinaryExpr::SubNetFold(Val* v1, Val* v2) const +ValPtr BinaryExpr::SubNetFold(Val* v1, Val* v2) const { const IPPrefix& n1 = v1->AsSubNet(); const IPPrefix& n2 = v2->AsSubNet(); @@ -886,7 +886,7 @@ void BinaryExpr::PromoteType(TypeTag t, bool is_vector) SetType(base_type(t)); } -CloneExpr::CloneExpr(zeek::IntrusivePtr arg_op) +CloneExpr::CloneExpr(ExprPtr arg_op) : UnaryExpr(EXPR_CLONE, std::move(arg_op)) { if ( IsError() ) @@ -895,7 +895,7 @@ CloneExpr::CloneExpr(zeek::IntrusivePtr arg_op) SetType(op->GetType()); } -zeek::IntrusivePtr CloneExpr::Eval(Frame* f) const +ValPtr CloneExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -906,12 +906,12 @@ zeek::IntrusivePtr CloneExpr::Eval(Frame* f) const return nullptr; } -zeek::IntrusivePtr CloneExpr::Fold(Val* v) const +ValPtr CloneExpr::Fold(Val* v) const { return v->Clone(); } -IncrExpr::IncrExpr(BroExprTag arg_tag, zeek::IntrusivePtr arg_op) +IncrExpr::IncrExpr(BroExprTag arg_tag, ExprPtr arg_op) : UnaryExpr(arg_tag, arg_op->MakeLvalue()) { if ( IsError() ) @@ -938,7 +938,7 @@ IncrExpr::IncrExpr(BroExprTag arg_tag, zeek::IntrusivePtr arg_op) } } -zeek::IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const +ValPtr IncrExpr::DoSingleEval(Frame* f, Val* v) const { bro_int_t k = v->CoerceToInt(); @@ -962,7 +962,7 @@ zeek::IntrusivePtr IncrExpr::DoSingleEval(Frame* f, Val* v) const } -zeek::IntrusivePtr IncrExpr::Eval(Frame* f) const +ValPtr IncrExpr::Eval(Frame* f) const { auto v = op->Eval(f); @@ -971,7 +971,7 @@ zeek::IntrusivePtr IncrExpr::Eval(Frame* f) const if ( is_vector(v) ) { - zeek::IntrusivePtr v_vec{zeek::NewRef{}, v->AsVectorVal()}; + VectorValPtr v_vec{zeek::NewRef{}, v->AsVectorVal()}; for ( unsigned int i = 0; i < v_vec->Size(); ++i ) { @@ -999,7 +999,7 @@ bool IncrExpr::IsPure() const return false; } -ComplementExpr::ComplementExpr(zeek::IntrusivePtr arg_op) +ComplementExpr::ComplementExpr(ExprPtr arg_op) : UnaryExpr(EXPR_COMPLEMENT, std::move(arg_op)) { if ( IsError() ) @@ -1014,12 +1014,12 @@ ComplementExpr::ComplementExpr(zeek::IntrusivePtr arg_op) SetType(base_type(zeek::TYPE_COUNT)); } -zeek::IntrusivePtr ComplementExpr::Fold(Val* v) const +ValPtr ComplementExpr::Fold(Val* v) const { return val_mgr->Count(~ v->InternalUnsigned()); } -NotExpr::NotExpr(zeek::IntrusivePtr arg_op) +NotExpr::NotExpr(ExprPtr arg_op) : UnaryExpr(EXPR_NOT, std::move(arg_op)) { if ( IsError() ) @@ -1033,12 +1033,12 @@ NotExpr::NotExpr(zeek::IntrusivePtr arg_op) SetType(base_type(zeek::TYPE_BOOL)); } -zeek::IntrusivePtr NotExpr::Fold(Val* v) const +ValPtr NotExpr::Fold(Val* v) const { return val_mgr->Bool(! v->InternalInt()); } -PosExpr::PosExpr(zeek::IntrusivePtr arg_op) +PosExpr::PosExpr(ExprPtr arg_op) : UnaryExpr(EXPR_POSITIVE, std::move(arg_op)) { if ( IsError() ) @@ -1047,7 +1047,7 @@ PosExpr::PosExpr(zeek::IntrusivePtr arg_op) const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); - zeek::IntrusivePtr base_result_type; + zeek::TypePtr base_result_type; if ( IsIntegral(bt) ) // Promote count and counter to int. @@ -1063,7 +1063,7 @@ PosExpr::PosExpr(zeek::IntrusivePtr arg_op) SetType(std::move(base_result_type)); } -zeek::IntrusivePtr PosExpr::Fold(Val* v) const +ValPtr PosExpr::Fold(Val* v) const { TypeTag t = v->GetType()->Tag(); @@ -1073,7 +1073,7 @@ zeek::IntrusivePtr PosExpr::Fold(Val* v) const return val_mgr->Int(v->CoerceToInt()); } -NegExpr::NegExpr(zeek::IntrusivePtr arg_op) +NegExpr::NegExpr(ExprPtr arg_op) : UnaryExpr(EXPR_NEGATE, std::move(arg_op)) { if ( IsError() ) @@ -1082,7 +1082,7 @@ NegExpr::NegExpr(zeek::IntrusivePtr arg_op) const auto& t = IsVector(op->GetType()->Tag()) ? op->GetType()->Yield() : op->GetType(); TypeTag bt = t->Tag(); - zeek::IntrusivePtr base_result_type; + zeek::TypePtr base_result_type; if ( IsIntegral(bt) ) // Promote count and counter to int. @@ -1098,7 +1098,7 @@ NegExpr::NegExpr(zeek::IntrusivePtr arg_op) SetType(std::move(base_result_type)); } -zeek::IntrusivePtr NegExpr::Fold(Val* v) const +ValPtr NegExpr::Fold(Val* v) const { if ( v->GetType()->Tag() == zeek::TYPE_DOUBLE ) return zeek::make_intrusive(- v->InternalDouble()); @@ -1108,7 +1108,7 @@ zeek::IntrusivePtr NegExpr::Fold(Val* v) const return val_mgr->Int(- v->CoerceToInt()); } -SizeExpr::SizeExpr(zeek::IntrusivePtr arg_op) +SizeExpr::SizeExpr(ExprPtr arg_op) : UnaryExpr(EXPR_SIZE, std::move(arg_op)) { if ( IsError() ) @@ -1120,7 +1120,7 @@ SizeExpr::SizeExpr(zeek::IntrusivePtr arg_op) SetType(base_type(zeek::TYPE_COUNT)); } -zeek::IntrusivePtr SizeExpr::Eval(Frame* f) const +ValPtr SizeExpr::Eval(Frame* f) const { auto v = op->Eval(f); @@ -1130,12 +1130,12 @@ zeek::IntrusivePtr SizeExpr::Eval(Frame* f) const return Fold(v.get()); } -zeek::IntrusivePtr SizeExpr::Fold(Val* v) const +ValPtr SizeExpr::Fold(Val* v) const { return v->SizeVal(); } -AddExpr::AddExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +AddExpr::AddExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_ADD, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1151,7 +1151,7 @@ AddExpr::AddExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_ if ( IsVector(bt2) ) bt2 = op2->GetType()->AsVectorType()->Yield()->Tag(); - zeek::IntrusivePtr base_result_type; + zeek::TypePtr base_result_type; if ( bt2 == zeek::TYPE_INTERVAL && ( bt1 == zeek::TYPE_TIME || bt1 == zeek::TYPE_INTERVAL ) ) base_result_type = base_type(bt1); @@ -1182,7 +1182,7 @@ void AddExpr::Canonicize() SwapOps(); } -AddToExpr::AddToExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +AddToExpr::AddToExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_ADD_TO, is_vector(arg_op1) ? std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op2)) @@ -1228,7 +1228,7 @@ AddToExpr::AddToExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr ExprError("requires two arithmetic or two string operands"); } -zeek::IntrusivePtr AddToExpr::Eval(Frame* f) const +ValPtr AddToExpr::Eval(Frame* f) const { auto v1 = op1->Eval(f); @@ -1259,7 +1259,7 @@ zeek::IntrusivePtr AddToExpr::Eval(Frame* f) const return nullptr; } -SubExpr::SubExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +SubExpr::SubExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_SUB, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1276,7 +1276,7 @@ SubExpr::SubExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_ if ( IsVector(bt2) ) bt2 = t2->AsVectorType()->Yield()->Tag(); - zeek::IntrusivePtr base_result_type; + zeek::TypePtr base_result_type; if ( bt2 == zeek::TYPE_INTERVAL && ( bt1 == zeek::TYPE_TIME || bt1 == zeek::TYPE_INTERVAL ) ) base_result_type = base_type(bt1); @@ -1307,8 +1307,7 @@ SubExpr::SubExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_ } } -RemoveFromExpr::RemoveFromExpr(zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +RemoveFromExpr::RemoveFromExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_REMOVE_FROM, arg_op1->MakeLvalue(), std::move(arg_op2)) { if ( IsError() ) @@ -1325,7 +1324,7 @@ RemoveFromExpr::RemoveFromExpr(zeek::IntrusivePtr arg_op1, ExprError("requires two arithmetic operands"); } -zeek::IntrusivePtr RemoveFromExpr::Eval(Frame* f) const +ValPtr RemoveFromExpr::Eval(Frame* f) const { auto v1 = op1->Eval(f); @@ -1346,7 +1345,7 @@ zeek::IntrusivePtr RemoveFromExpr::Eval(Frame* f) const return nullptr; } -TimesExpr::TimesExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +TimesExpr::TimesExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_TIMES, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1384,8 +1383,7 @@ void TimesExpr::Canonicize() SwapOps(); } -DivideExpr::DivideExpr(zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +DivideExpr::DivideExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_DIVIDE, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1427,7 +1425,7 @@ DivideExpr::DivideExpr(zeek::IntrusivePtr arg_op1, ExprError("requires arithmetic operands"); } -zeek::IntrusivePtr DivideExpr::AddrFold(Val* v1, Val* v2) const +ValPtr DivideExpr::AddrFold(Val* v1, Val* v2) const { uint32_t mask; @@ -1452,7 +1450,7 @@ zeek::IntrusivePtr DivideExpr::AddrFold(Val* v1, Val* v2) const return zeek::make_intrusive(a, mask); } -ModExpr::ModExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +ModExpr::ModExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_MOD, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1474,9 +1472,7 @@ ModExpr::ModExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_ ExprError("requires integral operands"); } -BoolExpr::BoolExpr(BroExprTag arg_tag, - zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +BoolExpr::BoolExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1507,7 +1503,7 @@ BoolExpr::BoolExpr(BroExprTag arg_tag, ExprError("requires boolean operands"); } -zeek::IntrusivePtr BoolExpr::DoSingleEval(Frame* f, zeek::IntrusivePtr v1, Expr* op2) const +ValPtr BoolExpr::DoSingleEval(Frame* f, ValPtr v1, Expr* op2) const { if ( ! v1 ) return nullptr; @@ -1529,7 +1525,7 @@ zeek::IntrusivePtr BoolExpr::DoSingleEval(Frame* f, zeek::IntrusivePtr } } -zeek::IntrusivePtr BoolExpr::Eval(Frame* f) const +ValPtr BoolExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -1551,8 +1547,8 @@ zeek::IntrusivePtr BoolExpr::Eval(Frame* f) const // a vector in order to find out its length. if ( ! (is_vec1 && is_vec2) ) { // Only one is a vector. - zeek::IntrusivePtr scalar_v; - zeek::IntrusivePtr vector_v; + ValPtr scalar_v; + VectorValPtr vector_v; if ( is_vec1 ) { @@ -1568,7 +1564,7 @@ zeek::IntrusivePtr BoolExpr::Eval(Frame* f) const if ( ! scalar_v || ! vector_v ) return nullptr; - zeek::IntrusivePtr result; + VectorValPtr result; // It's either an EXPR_AND_AND or an EXPR_OR_OR. bool is_and = (tag == EXPR_AND_AND); @@ -1622,9 +1618,7 @@ zeek::IntrusivePtr BoolExpr::Eval(Frame* f) const return result; } -BitExpr::BitExpr(BroExprTag arg_tag, - zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +BitExpr::BitExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1676,9 +1670,7 @@ BitExpr::BitExpr(BroExprTag arg_tag, ExprError("requires \"count\" or compatible \"set\" operands"); } -EqExpr::EqExpr(BroExprTag arg_tag, - zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +EqExpr::EqExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1763,7 +1755,7 @@ void EqExpr::Canonicize() SwapOps(); } -zeek::IntrusivePtr EqExpr::Fold(Val* v1, Val* v2) const +ValPtr EqExpr::Fold(Val* v1, Val* v2) const { if ( op1->GetType()->Tag() == zeek::TYPE_PATTERN ) { @@ -1779,9 +1771,7 @@ zeek::IntrusivePtr EqExpr::Fold(Val* v1, Val* v2) const return BinaryExpr::Fold(v1, v2); } -RelExpr::RelExpr(BroExprTag arg_tag, - zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2) +RelExpr::RelExpr(BroExprTag arg_tag, ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(arg_tag, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -1838,9 +1828,7 @@ void RelExpr::Canonicize() } } -CondExpr::CondExpr(zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2, - zeek::IntrusivePtr arg_op3) +CondExpr::CondExpr(ExprPtr arg_op1, ExprPtr arg_op2, ExprPtr arg_op3) : Expr(EXPR_COND), op1(std::move(arg_op1)), op2(std::move(arg_op2)), op3(std::move(arg_op3)) { @@ -1901,7 +1889,7 @@ CondExpr::CondExpr(zeek::IntrusivePtr arg_op1, } } -zeek::IntrusivePtr CondExpr::Eval(Frame* f) const +ValPtr CondExpr::Eval(Frame* f) const { if ( ! is_vector(op1) ) { @@ -1987,7 +1975,7 @@ void CondExpr::ExprDescribe(ODesc* d) const op3->Describe(d); } -RefExpr::RefExpr(zeek::IntrusivePtr arg_op) +RefExpr::RefExpr(ExprPtr arg_op) : UnaryExpr(EXPR_REF, std::move(arg_op)) { if ( IsError() ) @@ -1999,20 +1987,20 @@ RefExpr::RefExpr(zeek::IntrusivePtr arg_op) SetType(op->GetType()); } -zeek::IntrusivePtr RefExpr::MakeLvalue() +ExprPtr RefExpr::MakeLvalue() { return {zeek::NewRef{}, this}; } -void RefExpr::Assign(Frame* f, zeek::IntrusivePtr v) +void RefExpr::Assign(Frame* f, ValPtr v) { op->Assign(f, std::move(v)); } -AssignExpr::AssignExpr(zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2, - bool arg_is_init, zeek::IntrusivePtr arg_val, - const zeek::IntrusivePtr& attrs) +AssignExpr::AssignExpr(ExprPtr arg_op1, + ExprPtr arg_op2, + bool arg_is_init, ValPtr arg_val, + const AttributesPtr& attrs) : BinaryExpr(EXPR_ASSIGN, arg_is_init ? std::move(arg_op1) : arg_op1->MakeLvalue(), std::move(arg_op2)) @@ -2044,7 +2032,7 @@ AssignExpr::AssignExpr(zeek::IntrusivePtr arg_op1, SetLocationInfo(op1->GetLocationInfo(), op2->GetLocationInfo()); } -bool AssignExpr::TypeCheck(const zeek::IntrusivePtr& attrs) +bool AssignExpr::TypeCheck(const AttributesPtr& attrs) { TypeTag bt1 = op1->GetType()->Tag(); TypeTag bt2 = op2->GetType()->Tag(); @@ -2079,10 +2067,10 @@ bool AssignExpr::TypeCheck(const zeek::IntrusivePtr& attrs) if ( bt1 == zeek::TYPE_TABLE && op2->Tag() == EXPR_LIST ) { - std::unique_ptr>> attr_copy; + std::unique_ptr> attr_copy; if ( attrs ) - attr_copy = std::make_unique>>(attrs->GetAttrs()); + attr_copy = std::make_unique>(attrs->GetAttrs()); bool empty_list_assignment = (op2->AsListExpr()->Exprs().empty()); @@ -2173,13 +2161,13 @@ bool AssignExpr::TypeCheck(const zeek::IntrusivePtr& attrs) return false; } - std::unique_ptr>> attr_copy; + std::unique_ptr> attr_copy; if ( sce->GetAttrs() ) { const auto& a = sce->GetAttrs()->GetAttrs(); - attr_copy = std::make_unique>>(a); + attr_copy = std::make_unique>(a); } int errors_before = reporter->Errors(); @@ -2247,7 +2235,7 @@ bool AssignExpr::TypeCheckArithmetics(TypeTag bt1, TypeTag bt2) } -zeek::IntrusivePtr AssignExpr::Eval(Frame* f) const +ValPtr AssignExpr::Eval(Frame* f) const { if ( is_init ) { @@ -2268,7 +2256,7 @@ zeek::IntrusivePtr AssignExpr::Eval(Frame* f) const return nullptr; } -zeek::IntrusivePtr AssignExpr::InitType() const +zeek::TypePtr AssignExpr::InitType() const { if ( op1->Tag() != EXPR_LIST ) { @@ -2334,7 +2322,7 @@ void AssignExpr::EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) con RuntimeError("type clash in table assignment"); } -zeek::IntrusivePtr AssignExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr AssignExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( ! aggr ) { @@ -2434,13 +2422,12 @@ bool AssignExpr::IsPure() const return false; } -IndexSliceAssignExpr::IndexSliceAssignExpr(zeek::IntrusivePtr op1, - zeek::IntrusivePtr op2, bool is_init) +IndexSliceAssignExpr::IndexSliceAssignExpr(ExprPtr op1, ExprPtr op2, bool is_init) : AssignExpr(std::move(op1), std::move(op2), is_init) { } -zeek::IntrusivePtr IndexSliceAssignExpr::Eval(Frame* f) const +ValPtr IndexSliceAssignExpr::Eval(Frame* f) const { if ( is_init ) { @@ -2454,8 +2441,7 @@ zeek::IntrusivePtr IndexSliceAssignExpr::Eval(Frame* f) const return nullptr; } -IndexExpr::IndexExpr(zeek::IntrusivePtr arg_op1, - zeek::IntrusivePtr arg_op2, bool arg_is_slice) +IndexExpr::IndexExpr(ExprPtr arg_op1, ListExprPtr arg_op2, bool arg_is_slice) : BinaryExpr(EXPR_INDEX, std::move(arg_op1), std::move(arg_op2)), is_slice(arg_is_slice) { @@ -2562,7 +2548,7 @@ void IndexExpr::Delete(Frame* f) v1->AsTableVal()->Remove(*v2); } -zeek::IntrusivePtr IndexExpr::MakeLvalue() +ExprPtr IndexExpr::MakeLvalue() { if ( IsString(op1->GetType()->Tag()) ) ExprError("cannot assign to string index expression"); @@ -2570,7 +2556,7 @@ zeek::IntrusivePtr IndexExpr::MakeLvalue() return zeek::make_intrusive(IntrusivePtr{zeek::NewRef{}, this}); } -zeek::IntrusivePtr IndexExpr::Eval(Frame* f) const +ValPtr IndexExpr::Eval(Frame* f) const { auto v1 = op1->Eval(f); @@ -2631,12 +2617,12 @@ static int get_slice_index(int idx, int len) return idx; } -zeek::IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const +ValPtr IndexExpr::Fold(Val* v1, Val* v2) const { if ( IsError() ) return nullptr; - zeek::IntrusivePtr v; + ValPtr v; switch ( v1->GetType()->Tag() ) { case zeek::TYPE_VECTOR: @@ -2716,7 +2702,7 @@ zeek::IntrusivePtr IndexExpr::Fold(Val* v1, Val* v2) const return nullptr; } -void IndexExpr::Assign(Frame* f, zeek::IntrusivePtr v) +void IndexExpr::Assign(Frame* f, ValPtr v) { if ( IsError() ) return; @@ -2836,7 +2822,7 @@ TraversalCode IndexExpr::Traverse(TraversalCallback* cb) const HANDLE_TC_EXPR_POST(tc); } -FieldExpr::FieldExpr(zeek::IntrusivePtr arg_op, const char* arg_field_name) +FieldExpr::FieldExpr(ExprPtr arg_op, const char* arg_field_name) : UnaryExpr(EXPR_FIELD, std::move(arg_op)), field_name(copy_string(arg_field_name)), td(nullptr), field(0) { @@ -2868,7 +2854,7 @@ FieldExpr::~FieldExpr() delete [] field_name; } -zeek::IntrusivePtr FieldExpr::MakeLvalue() +ExprPtr FieldExpr::MakeLvalue() { return zeek::make_intrusive(IntrusivePtr{zeek::NewRef{}, this}); } @@ -2878,7 +2864,7 @@ bool FieldExpr::CanDel() const return td->GetAttr(ATTR_DEFAULT) || td->GetAttr(ATTR_OPTIONAL); } -void FieldExpr::Assign(Frame* f, zeek::IntrusivePtr v) +void FieldExpr::Assign(Frame* f, ValPtr v) { if ( IsError() ) return; @@ -2895,7 +2881,7 @@ void FieldExpr::Delete(Frame* f) Assign(f, nullptr); } -zeek::IntrusivePtr FieldExpr::Fold(Val* v) const +ValPtr FieldExpr::Fold(Val* v) const { if ( const auto& result = v->AsRecordVal()->GetField(field) ) return result; @@ -2927,8 +2913,7 @@ void FieldExpr::ExprDescribe(ODesc* d) const d->Add(field); } -HasFieldExpr::HasFieldExpr(zeek::IntrusivePtr arg_op, - const char* arg_field_name) +HasFieldExpr::HasFieldExpr(ExprPtr arg_op, const char* arg_field_name) : UnaryExpr(EXPR_HAS_FIELD, std::move(arg_op)), field_name(arg_field_name), field(0) { @@ -2956,7 +2941,7 @@ HasFieldExpr::~HasFieldExpr() delete field_name; } -zeek::IntrusivePtr HasFieldExpr::Fold(Val* v) const +ValPtr HasFieldExpr::Fold(Val* v) const { auto rv = v->AsRecordVal(); return val_mgr->Bool(rv->GetField(field) != nullptr); @@ -2977,7 +2962,7 @@ void HasFieldExpr::ExprDescribe(ODesc* d) const d->Add(field); } -RecordConstructorExpr::RecordConstructorExpr(zeek::IntrusivePtr constructor_list) +RecordConstructorExpr::RecordConstructorExpr(ListExprPtr constructor_list) : UnaryExpr(EXPR_RECORD_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3011,7 +2996,7 @@ RecordConstructorExpr::~RecordConstructorExpr() { } -zeek::IntrusivePtr RecordConstructorExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr RecordConstructorExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { auto v = Eval(nullptr); @@ -3019,7 +3004,7 @@ zeek::IntrusivePtr RecordConstructorExpr::InitVal(const zeek::Type* t, zeek { RecordVal* rv = v->AsRecordVal(); auto bt = const_cast(t); - zeek::IntrusivePtr rt{zeek::NewRef{}, bt->AsRecordType()}; + RecordTypePtr rt{zeek::NewRef{}, bt->AsRecordType()}; auto aggr_rec = zeek::cast_intrusive(std::move(aggr)); auto ar = rv->CoerceTo(std::move(rt), std::move(aggr_rec)); @@ -3031,7 +3016,7 @@ zeek::IntrusivePtr RecordConstructorExpr::InitVal(const zeek::Type* t, zeek return nullptr; } -zeek::IntrusivePtr RecordConstructorExpr::Fold(Val* v) const +ValPtr RecordConstructorExpr::Fold(Val* v) const { ListVal* lv = v->AsListVal(); auto rt = zeek::cast_intrusive(type); @@ -3054,9 +3039,9 @@ void RecordConstructorExpr::ExprDescribe(ODesc* d) const d->Add("]"); } -TableConstructorExpr::TableConstructorExpr(zeek::IntrusivePtr constructor_list, - std::unique_ptr>> arg_attrs, - zeek::IntrusivePtr arg_type) +TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list, + std::unique_ptr> arg_attrs, + zeek::TypePtr arg_type) : UnaryExpr(EXPR_TABLE_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3134,7 +3119,7 @@ TableConstructorExpr::TableConstructorExpr(zeek::IntrusivePtr construc } } -zeek::IntrusivePtr TableConstructorExpr::Eval(Frame* f) const +ValPtr TableConstructorExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -3150,7 +3135,7 @@ zeek::IntrusivePtr TableConstructorExpr::Eval(Frame* f) const return aggr; } -zeek::IntrusivePtr TableConstructorExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr TableConstructorExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( IsError() ) return nullptr; @@ -3158,7 +3143,7 @@ zeek::IntrusivePtr TableConstructorExpr::InitVal(const zeek::Type* t, zeek: auto tt = GetType(); auto tval = aggr ? - zeek::IntrusivePtr{zeek::AdoptRef{}, aggr.release()->AsTableVal()} : + TableValPtr{zeek::AdoptRef{}, aggr.release()->AsTableVal()} : zeek::make_intrusive(std::move(tt), attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); @@ -3175,9 +3160,9 @@ void TableConstructorExpr::ExprDescribe(ODesc* d) const d->Add(")"); } -SetConstructorExpr::SetConstructorExpr(zeek::IntrusivePtr constructor_list, - std::unique_ptr>> arg_attrs, - zeek::IntrusivePtr arg_type) +SetConstructorExpr::SetConstructorExpr(ListExprPtr constructor_list, + std::unique_ptr> arg_attrs, + zeek::TypePtr arg_type) : UnaryExpr(EXPR_SET_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3243,7 +3228,7 @@ SetConstructorExpr::SetConstructorExpr(zeek::IntrusivePtr constructor_ } } -zeek::IntrusivePtr SetConstructorExpr::Eval(Frame* f) const +ValPtr SetConstructorExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -3261,7 +3246,7 @@ zeek::IntrusivePtr SetConstructorExpr::Eval(Frame* f) const return aggr; } -zeek::IntrusivePtr SetConstructorExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr SetConstructorExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( IsError() ) return nullptr; @@ -3269,7 +3254,7 @@ zeek::IntrusivePtr SetConstructorExpr::InitVal(const zeek::Type* t, zeek::I const auto& index_type = t->AsTableType()->GetIndices(); auto tt = GetType(); auto tval = aggr ? - zeek::IntrusivePtr{zeek::AdoptRef{}, aggr.release()->AsTableVal()} : + TableValPtr{zeek::AdoptRef{}, aggr.release()->AsTableVal()} : zeek::make_intrusive(std::move(tt), attrs); const expr_list& exprs = op->AsListExpr()->Exprs(); @@ -3294,8 +3279,8 @@ void SetConstructorExpr::ExprDescribe(ODesc* d) const d->Add(")"); } -VectorConstructorExpr::VectorConstructorExpr(zeek::IntrusivePtr constructor_list, - zeek::IntrusivePtr arg_type) +VectorConstructorExpr::VectorConstructorExpr(ListExprPtr constructor_list, + zeek::TypePtr arg_type) : UnaryExpr(EXPR_VECTOR_CONSTRUCTOR, std::move(constructor_list)) { if ( IsError() ) @@ -3337,7 +3322,7 @@ VectorConstructorExpr::VectorConstructorExpr(zeek::IntrusivePtr constr ExprError("inconsistent types in vector constructor"); } -zeek::IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const +ValPtr VectorConstructorExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -3359,14 +3344,14 @@ zeek::IntrusivePtr VectorConstructorExpr::Eval(Frame* f) const return vec; } -zeek::IntrusivePtr VectorConstructorExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr VectorConstructorExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( IsError() ) return nullptr; auto vt = GetType(); auto vec = aggr ? - zeek::IntrusivePtr{zeek::AdoptRef{}, aggr.release()->AsVectorVal()} : + VectorValPtr{zeek::AdoptRef{}, aggr.release()->AsVectorVal()} : zeek::make_intrusive(std::move(vt)); const expr_list& exprs = op->AsListExpr()->Exprs(); @@ -3392,8 +3377,7 @@ void VectorConstructorExpr::ExprDescribe(ODesc* d) const d->Add(")"); } -FieldAssignExpr::FieldAssignExpr(const char* arg_field_name, - zeek::IntrusivePtr value) +FieldAssignExpr::FieldAssignExpr(const char* arg_field_name, ExprPtr value) : UnaryExpr(EXPR_FIELD_ASSIGN, std::move(value)), field_name(arg_field_name) { SetType(op->GetType()); @@ -3439,7 +3423,7 @@ void FieldAssignExpr::ExprDescribe(ODesc* d) const op->Describe(d); } -ArithCoerceExpr::ArithCoerceExpr(zeek::IntrusivePtr arg_op, TypeTag t) +ArithCoerceExpr::ArithCoerceExpr(ExprPtr arg_op, TypeTag t) : UnaryExpr(EXPR_ARITH_COERCE, std::move(arg_op)) { if ( IsError() ) @@ -3468,7 +3452,7 @@ ArithCoerceExpr::ArithCoerceExpr(zeek::IntrusivePtr arg_op, TypeTag t) ExprError("bad coercion value"); } -zeek::IntrusivePtr ArithCoerceExpr::FoldSingleVal(Val* v, InternalTypeTag t) const +ValPtr ArithCoerceExpr::FoldSingleVal(Val* v, InternalTypeTag t) const { switch ( t ) { case zeek::TYPE_INTERNAL_DOUBLE: @@ -3486,7 +3470,7 @@ zeek::IntrusivePtr ArithCoerceExpr::FoldSingleVal(Val* v, InternalTypeTag t } } -zeek::IntrusivePtr ArithCoerceExpr::Fold(Val* v) const +ValPtr ArithCoerceExpr::Fold(Val* v) const { InternalTypeTag t = type->InternalType(); @@ -3517,8 +3501,7 @@ zeek::IntrusivePtr ArithCoerceExpr::Fold(Val* v) const return result; } -RecordCoerceExpr::RecordCoerceExpr(zeek::IntrusivePtr arg_op, - zeek::IntrusivePtr r) +RecordCoerceExpr::RecordCoerceExpr(ExprPtr arg_op, zeek::RecordTypePtr r) : UnaryExpr(EXPR_RECORD_COERCE, std::move(arg_op)), map(nullptr), map_size(0) { @@ -3630,13 +3613,13 @@ RecordCoerceExpr::~RecordCoerceExpr() delete [] map; } -zeek::IntrusivePtr RecordCoerceExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr RecordCoerceExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { if ( auto v = Eval(nullptr) ) { RecordVal* rv = v->AsRecordVal(); auto bt = const_cast(t); - zeek::IntrusivePtr rt{zeek::NewRef{}, bt->AsRecordType()}; + zeek::RecordTypePtr rt{zeek::NewRef{}, bt->AsRecordType()}; auto aggr_rec = zeek::cast_intrusive(std::move(aggr)); if ( auto ar = rv->CoerceTo(std::move(rt), std::move(aggr_rec)) ) @@ -3647,7 +3630,7 @@ zeek::IntrusivePtr RecordCoerceExpr::InitVal(const zeek::Type* t, zeek::Int return nullptr; } -zeek::IntrusivePtr RecordCoerceExpr::Fold(Val* v) const +ValPtr RecordCoerceExpr::Fold(Val* v) const { auto val = zeek::make_intrusive(GetType()); RecordType* val_type = val->GetType()->AsRecordType(); @@ -3728,8 +3711,7 @@ zeek::IntrusivePtr RecordCoerceExpr::Fold(Val* v) const return val; } -TableCoerceExpr::TableCoerceExpr(zeek::IntrusivePtr arg_op, - zeek::IntrusivePtr r) +TableCoerceExpr::TableCoerceExpr(ExprPtr arg_op, zeek::TableTypePtr r) : UnaryExpr(EXPR_TABLE_COERCE, std::move(arg_op)) { if ( IsError() ) @@ -3749,7 +3731,7 @@ TableCoerceExpr::~TableCoerceExpr() { } -zeek::IntrusivePtr TableCoerceExpr::Fold(Val* v) const +ValPtr TableCoerceExpr::Fold(Val* v) const { TableVal* tv = v->AsTableVal(); @@ -3759,8 +3741,7 @@ zeek::IntrusivePtr TableCoerceExpr::Fold(Val* v) const return zeek::make_intrusive(GetType(), tv->GetAttrs()); } -VectorCoerceExpr::VectorCoerceExpr(zeek::IntrusivePtr arg_op, - zeek::IntrusivePtr v) +VectorCoerceExpr::VectorCoerceExpr(ExprPtr arg_op, zeek::VectorTypePtr v) : UnaryExpr(EXPR_VECTOR_COERCE, std::move(arg_op)) { if ( IsError() ) @@ -3780,7 +3761,7 @@ VectorCoerceExpr::~VectorCoerceExpr() { } -zeek::IntrusivePtr VectorCoerceExpr::Fold(Val* v) const +ValPtr VectorCoerceExpr::Fold(Val* v) const { VectorVal* vv = v->AsVectorVal(); @@ -3807,8 +3788,7 @@ void ScheduleTimer::Dispatch(double /* t */, bool /* is_expire */) mgr.Enqueue(event, std::move(args)); } -ScheduleExpr::ScheduleExpr(zeek::IntrusivePtr arg_when, - zeek::IntrusivePtr arg_event) +ScheduleExpr::ScheduleExpr(ExprPtr arg_when, EventExprPtr arg_event) : Expr(EXPR_SCHEDULE), when(std::move(arg_when)), event(std::move(arg_event)) { @@ -3828,7 +3808,7 @@ bool ScheduleExpr::IsPure() const return false; } -zeek::IntrusivePtr ScheduleExpr::Eval(Frame* f) const +ValPtr ScheduleExpr::Eval(Frame* f) const { if ( terminating ) return nullptr; @@ -3886,7 +3866,7 @@ void ScheduleExpr::ExprDescribe(ODesc* d) const event->Describe(d); } -InExpr::InExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) +InExpr::InExpr(ExprPtr arg_op1, ExprPtr arg_op2) : BinaryExpr(EXPR_IN, std::move(arg_op1), std::move(arg_op2)) { if ( IsError() ) @@ -3963,7 +3943,7 @@ InExpr::InExpr(zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op } } -zeek::IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const +ValPtr InExpr::Fold(Val* v1, Val* v2) const { if ( v1->GetType()->Tag() == zeek::TYPE_PATTERN ) { @@ -3997,8 +3977,7 @@ zeek::IntrusivePtr InExpr::Fold(Val* v1, Val* v2) const return val_mgr->Bool(res); } -CallExpr::CallExpr(zeek::IntrusivePtr arg_func, - zeek::IntrusivePtr arg_args, bool in_hook) +CallExpr::CallExpr(ExprPtr arg_func, ListExprPtr arg_args, bool in_hook) : Expr(EXPR_CALL), func(std::move(arg_func)), args(std::move(arg_args)) { if ( func->IsError() || args->IsError() ) @@ -4058,7 +4037,7 @@ CallExpr::CallExpr(zeek::IntrusivePtr arg_func, SetType(yield); // Check for call to built-ins that can be statically analyzed. - zeek::IntrusivePtr func_val; + ValPtr func_val; if ( func->Tag() == EXPR_NAME && // This is cheating, but without it processing gets @@ -4107,7 +4086,7 @@ bool CallExpr::IsPure() const return pure; } -zeek::IntrusivePtr CallExpr::Eval(Frame* f) const +ValPtr CallExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -4129,7 +4108,7 @@ zeek::IntrusivePtr CallExpr::Eval(Frame* f) const } } - zeek::IntrusivePtr ret; + ValPtr ret; auto func_val = func->Eval(f); auto v = eval_list(f, args.get()); @@ -4238,7 +4217,7 @@ Scope* LambdaExpr::GetScope() const return ingredients->scope.get(); } -zeek::IntrusivePtr LambdaExpr::Eval(Frame* f) const +ValPtr LambdaExpr::Eval(Frame* f) const { auto lamb = zeek::make_intrusive( ingredients->id, @@ -4274,7 +4253,7 @@ TraversalCode LambdaExpr::Traverse(TraversalCallback* cb) const HANDLE_TC_EXPR_POST(tc); } -EventExpr::EventExpr(const char* arg_name, zeek::IntrusivePtr arg_args) +EventExpr::EventExpr(const char* arg_name, ListExprPtr arg_args) : Expr(EXPR_EVENT), name(arg_name), args(std::move(arg_args)) { EventHandler* h = event_registry->Lookup(name); @@ -4316,7 +4295,7 @@ EventExpr::EventExpr(const char* arg_name, zeek::IntrusivePtr arg_args } } -zeek::IntrusivePtr EventExpr::Eval(Frame* f) const +ValPtr EventExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -4359,7 +4338,7 @@ ListExpr::ListExpr() : Expr(EXPR_LIST) SetType(zeek::make_intrusive()); } -ListExpr::ListExpr(zeek::IntrusivePtr e) : Expr(EXPR_LIST) +ListExpr::ListExpr(ExprPtr e) : Expr(EXPR_LIST) { SetType(zeek::make_intrusive()); Append(std::move(e)); @@ -4371,7 +4350,7 @@ ListExpr::~ListExpr() Unref(expr); } -void ListExpr::Append(zeek::IntrusivePtr e) +void ListExpr::Append(ExprPtr e) { exprs.push_back(e.release()); ((TypeList*) type.get())->Append(exprs.back()->GetType()); @@ -4386,7 +4365,7 @@ bool ListExpr::IsPure() const return true; } -zeek::IntrusivePtr ListExpr::Eval(Frame* f) const +ValPtr ListExpr::Eval(Frame* f) const { auto v = zeek::make_intrusive(zeek::TYPE_ANY); @@ -4406,7 +4385,7 @@ zeek::IntrusivePtr ListExpr::Eval(Frame* f) const return v; } -zeek::IntrusivePtr ListExpr::InitType() const +zeek::TypePtr ListExpr::InitType() const { if ( exprs.empty() ) { @@ -4464,7 +4443,7 @@ zeek::IntrusivePtr ListExpr::InitType() const } } -zeek::IntrusivePtr ListExpr::InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr ListExpr::InitVal(const zeek::Type* t, ValPtr aggr) const { // While fairly similar to the EvalIntoAggregate() code, // we keep this separate since it also deals with initialization @@ -4608,7 +4587,7 @@ zeek::IntrusivePtr ListExpr::InitVal(const zeek::Type* t, zeek::IntrusivePt return aggr; } -zeek::IntrusivePtr ListExpr::AddSetInit(const zeek::Type* t, zeek::IntrusivePtr aggr) const +ValPtr ListExpr::AddSetInit(const zeek::Type* t, ValPtr aggr) const { if ( aggr->GetType()->Tag() != zeek::TYPE_TABLE ) Internal("bad aggregate in ListExpr::InitVal"); @@ -4619,7 +4598,7 @@ zeek::IntrusivePtr ListExpr::AddSetInit(const zeek::Type* t, zeek::Intrusiv for ( const auto& expr : exprs ) { - zeek::IntrusivePtr element; + ValPtr element; if ( expr->GetType()->IsSet() ) // A set to flatten. @@ -4674,7 +4653,7 @@ void ListExpr::ExprDescribe(ODesc* d) const } } -zeek::IntrusivePtr ListExpr::MakeLvalue() +ExprPtr ListExpr::MakeLvalue() { for ( const auto & expr : exprs ) if ( expr->Tag() != EXPR_NAME ) @@ -4683,7 +4662,7 @@ zeek::IntrusivePtr ListExpr::MakeLvalue() return zeek::make_intrusive(IntrusivePtr{zeek::NewRef{}, this}); } -void ListExpr::Assign(Frame* f, zeek::IntrusivePtr v) +void ListExpr::Assign(Frame* f, ValPtr v) { ListVal* lv = v->AsListVal(); @@ -4709,8 +4688,8 @@ TraversalCode ListExpr::Traverse(TraversalCallback* cb) const HANDLE_TC_EXPR_POST(tc); } -RecordAssignExpr::RecordAssignExpr(const zeek::IntrusivePtr& record, - const zeek::IntrusivePtr& init_list, bool is_init) +RecordAssignExpr::RecordAssignExpr(const ExprPtr& record, + const ExprPtr& init_list, bool is_init) { const expr_list& inits = init_list->AsListExpr()->Exprs(); @@ -4751,7 +4730,7 @@ RecordAssignExpr::RecordAssignExpr(const zeek::IntrusivePtr& record, if ( lhs->HasField(field_name) ) { auto fe_lhs = zeek::make_intrusive(record, field_name); - zeek::IntrusivePtr fe_rhs = {zeek::NewRef{}, rf->Op()}; + ExprPtr fe_rhs = {zeek::NewRef{}, rf->Op()}; Append(get_assign_expr(std::move(fe_lhs), std::move(fe_rhs), is_init)); } else @@ -4771,7 +4750,7 @@ RecordAssignExpr::RecordAssignExpr(const zeek::IntrusivePtr& record, } } -CastExpr::CastExpr(zeek::IntrusivePtr arg_op, zeek::IntrusivePtr t) +CastExpr::CastExpr(ExprPtr arg_op, zeek::TypePtr t) : UnaryExpr(EXPR_CAST, std::move(arg_op)) { auto stype = Op()->GetType(); @@ -4782,7 +4761,7 @@ CastExpr::CastExpr(zeek::IntrusivePtr arg_op, zeek::IntrusivePtr CastExpr::Eval(Frame* f) const +ValPtr CastExpr::Eval(Frame* f) const { if ( IsError() ) return nullptr; @@ -4819,13 +4798,13 @@ void CastExpr::ExprDescribe(ODesc* d) const GetType()->Describe(d); } -IsExpr::IsExpr(zeek::IntrusivePtr arg_op, zeek::IntrusivePtr arg_t) +IsExpr::IsExpr(ExprPtr arg_op, zeek::TypePtr arg_t) : UnaryExpr(EXPR_IS, std::move(arg_op)), t(std::move(arg_t)) { SetType(zeek::base_type(zeek::TYPE_BOOL)); } -zeek::IntrusivePtr IsExpr::Fold(Val* v) const +ValPtr IsExpr::Fold(Val* v) const { if ( IsError() ) return nullptr; @@ -4840,8 +4819,7 @@ void IsExpr::ExprDescribe(ODesc* d) const t->Describe(d); } -zeek::IntrusivePtr get_assign_expr(zeek::IntrusivePtr op1, - zeek::IntrusivePtr op2, bool is_init) +ExprPtr get_assign_expr(ExprPtr op1, ExprPtr op2, bool is_init) { if ( op1->GetType()->Tag() == zeek::TYPE_RECORD && op2->GetType()->Tag() == zeek::TYPE_LIST ) @@ -4857,7 +4835,7 @@ zeek::IntrusivePtr get_assign_expr(zeek::IntrusivePtr op1, std::move(op1), std::move(op2), is_init); } -zeek::IntrusivePtr check_and_promote_expr(Expr* const e, zeek::Type* t) +ExprPtr check_and_promote_expr(Expr* const e, zeek::Type* t) { const auto& et = e->GetType(); TypeTag e_tag = et->Tag(); @@ -5044,10 +5022,10 @@ bool check_and_promote_exprs_to_type(ListExpr* const elements, zeek::Type* type) return true; } -std::optional>> eval_list(Frame* f, const ListExpr* l) +std::optional> eval_list(Frame* f, const ListExpr* l) { const expr_list& e = l->Exprs(); - auto rval = std::make_optional>>(); + auto rval = std::make_optional>(); rval->reserve(e.length()); for ( const auto& expr : e ) diff --git a/src/Expr.h b/src/Expr.h index 25fbe5086e..f7599c3a65 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -24,6 +24,8 @@ struct function_ingredients; namespace zeek::detail { +using IDPtr = zeek::IntrusivePtr; + enum BroExprTag : int { EXPR_ANY = -1, EXPR_NAME, EXPR_CONST, @@ -73,12 +75,17 @@ class CallExpr; class EventExpr; class Stmt; +class Expr; +using ExprPtr = zeek::IntrusivePtr; +using EventExprPtr = zeek::IntrusivePtr; +using ListExprPtr = zeek::IntrusivePtr; + class Expr : public BroObj { public: [[deprecated("Remove in v4.1. Use GetType().")]] zeek::Type* Type() const { return type.get(); } - const zeek::IntrusivePtr& GetType() const + const zeek::TypePtr& GetType() const { return type; } template @@ -91,21 +98,20 @@ public: // Evaluates the expression and returns a corresponding Val*, // or nil if the expression's value isn't fixed. - virtual zeek::IntrusivePtr Eval(Frame* f) const = 0; + virtual ValPtr Eval(Frame* f) const = 0; // Same, but the context is that we are adding an element // 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 zeek::Type* t, Val* aggr, Frame* f) - const; + virtual void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const; // Assign to the given value, if appropriate. - virtual void Assign(Frame* f, zeek::IntrusivePtr v); + virtual void Assign(Frame* f, ValPtr v); // Returns the type corresponding to this expression interpreted // as an initialization. Returns nil if the initialization is illegal. - virtual zeek::IntrusivePtr InitType() const; + virtual zeek::TypePtr InitType() const; // Returns true if this expression, interpreted as an initialization, // constitutes a record element, false otherwise. If the TypeDecl* @@ -118,7 +124,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 zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const; + virtual ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const; // True if the expression has no side effects, false otherwise. virtual bool IsPure() const; @@ -154,7 +160,7 @@ public: // Return the expression converted to L-value form. If expr // cannot be used as an L-value, reports an error and returns // the current value of expr (this is the default method). - virtual zeek::IntrusivePtr MakeLvalue(); + virtual ExprPtr MakeLvalue(); // Marks the expression as one requiring (or at least appearing // with) parentheses. Used for pretty-printing. @@ -223,7 +229,7 @@ protected: // Puts the expression in canonical form. virtual void Canonicize(); - void SetType(zeek::IntrusivePtr t); + void SetType(zeek::TypePtr t); // Reports the given error and sets the expression's type to // TYPE_ERROR. @@ -235,19 +241,19 @@ protected: [[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const; BroExprTag tag; - zeek::IntrusivePtr type; + zeek::TypePtr type; bool paren; }; class NameExpr final : public Expr { public: - explicit NameExpr(zeek::IntrusivePtr id, bool const_init = false); + explicit NameExpr(zeek::detail::IDPtr id, bool const_init = false); ID* Id() const { return id.get(); } - zeek::IntrusivePtr Eval(Frame* f) const override; - void Assign(Frame* f, zeek::IntrusivePtr v) override; - zeek::IntrusivePtr MakeLvalue() override; + ValPtr Eval(Frame* f) const override; + void Assign(Frame* f, ValPtr v) override; + ExprPtr MakeLvalue() override; bool IsPure() const override; TraversalCode Traverse(TraversalCallback* cb) const override; @@ -255,23 +261,23 @@ public: protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr id; + zeek::detail::IDPtr id; bool in_const_init; }; class ConstExpr final : public Expr { public: - explicit ConstExpr(zeek::IntrusivePtr val); + explicit ConstExpr(ValPtr val); Val* Value() const { return val.get(); } - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr val; + ValPtr val; }; class UnaryExpr : public Expr { @@ -281,21 +287,21 @@ public: // UnaryExpr::Eval correctly handles vector types. Any child // class that overrides Eval() should be modified to handle // vectors correctly as necessary. - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; bool IsPure() const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: - UnaryExpr(BroExprTag arg_tag, zeek::IntrusivePtr arg_op); + UnaryExpr(BroExprTag arg_tag, ExprPtr arg_op); void ExprDescribe(ODesc* d) const override; // Returns the expression folded using the given constant. - virtual zeek::IntrusivePtr Fold(Val* v) const; + virtual ValPtr Fold(Val* v) const; - zeek::IntrusivePtr op; + ExprPtr op; }; class BinaryExpr : public Expr { @@ -308,13 +314,13 @@ public: // BinaryExpr::Eval correctly handles vector types. Any child // class that overrides Eval() should be modified to handle // vectors correctly as necessary. - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: BinaryExpr(BroExprTag arg_tag, - zeek::IntrusivePtr arg_op1, zeek::IntrusivePtr arg_op2) + ExprPtr arg_op1, ExprPtr arg_op2) : Expr(arg_tag), op1(std::move(arg_op1)), op2(std::move(arg_op2)) { if ( ! (op1 && op2) ) @@ -324,20 +330,20 @@ protected: } // Returns the expression folded using the given constants. - virtual zeek::IntrusivePtr Fold(Val* v1, Val* v2) const; + virtual ValPtr Fold(Val* v1, Val* v2) const; // Same for when the constants are strings. - virtual zeek::IntrusivePtr StringFold(Val* v1, Val* v2) const; + virtual ValPtr StringFold(Val* v1, Val* v2) const; // Same for when the constants are patterns. - virtual zeek::IntrusivePtr PatternFold(Val* v1, Val* v2) const; + virtual ValPtr PatternFold(Val* v1, Val* v2) const; // Same for when the constants are sets. - virtual zeek::IntrusivePtr SetFold(Val* v1, Val* v2) const; + virtual ValPtr SetFold(Val* v1, Val* v2) const; // Same for when the constants are addresses or subnets. - virtual zeek::IntrusivePtr AddrFold(Val* v1, Val* v2) const; - virtual zeek::IntrusivePtr SubNetFold(Val* v1, Val* v2) const; + virtual ValPtr AddrFold(Val* v1, Val* v2) const; + virtual ValPtr SubNetFold(Val* v1, Val* v2) const; bool BothConst() const { return op1->IsConst() && op2->IsConst(); } @@ -353,148 +359,148 @@ protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr op1; - zeek::IntrusivePtr op2; + ExprPtr op1; + ExprPtr op2; }; class CloneExpr final : public UnaryExpr { public: - explicit CloneExpr(zeek::IntrusivePtr op); - zeek::IntrusivePtr Eval(Frame* f) const override; + explicit CloneExpr(ExprPtr op); + ValPtr Eval(Frame* f) const override; protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class IncrExpr final : public UnaryExpr { public: - IncrExpr(BroExprTag tag, zeek::IntrusivePtr op); + IncrExpr(BroExprTag tag, ExprPtr op); - zeek::IntrusivePtr Eval(Frame* f) const override; - zeek::IntrusivePtr DoSingleEval(Frame* f, Val* v) const; + ValPtr Eval(Frame* f) const override; + ValPtr DoSingleEval(Frame* f, Val* v) const; bool IsPure() const override; }; class ComplementExpr final : public UnaryExpr { public: - explicit ComplementExpr(zeek::IntrusivePtr op); + explicit ComplementExpr(ExprPtr op); protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class NotExpr final : public UnaryExpr { public: - explicit NotExpr(zeek::IntrusivePtr op); + explicit NotExpr(ExprPtr op); protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class PosExpr final : public UnaryExpr { public: - explicit PosExpr(zeek::IntrusivePtr op); + explicit PosExpr(ExprPtr op); protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class NegExpr final : public UnaryExpr { public: - explicit NegExpr(zeek::IntrusivePtr op); + explicit NegExpr(ExprPtr op); protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class SizeExpr final : public UnaryExpr { public: - explicit SizeExpr(zeek::IntrusivePtr op); - zeek::IntrusivePtr Eval(Frame* f) const override; + explicit SizeExpr(ExprPtr op); + ValPtr Eval(Frame* f) const override; protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class AddExpr final : public BinaryExpr { public: - AddExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + AddExpr(ExprPtr op1, ExprPtr op2); void Canonicize() override; }; class AddToExpr final : public BinaryExpr { public: - AddToExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); - zeek::IntrusivePtr Eval(Frame* f) const override; + AddToExpr(ExprPtr op1, ExprPtr op2); + ValPtr Eval(Frame* f) const override; }; class RemoveFromExpr final : public BinaryExpr { public: - RemoveFromExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); - zeek::IntrusivePtr Eval(Frame* f) const override; + RemoveFromExpr(ExprPtr op1, ExprPtr op2); + ValPtr Eval(Frame* f) const override; }; class SubExpr final : public BinaryExpr { public: - SubExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + SubExpr(ExprPtr op1, ExprPtr op2); }; class TimesExpr final : public BinaryExpr { public: - TimesExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + TimesExpr(ExprPtr op1, ExprPtr op2); void Canonicize() override; }; class DivideExpr final : public BinaryExpr { public: - DivideExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + DivideExpr(ExprPtr op1, ExprPtr op2); protected: - zeek::IntrusivePtr AddrFold(Val* v1, Val* v2) const override; + ValPtr AddrFold(Val* v1, Val* v2) const override; }; class ModExpr final : public BinaryExpr { public: - ModExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + ModExpr(ExprPtr op1, ExprPtr op2); }; class BoolExpr final : public BinaryExpr { public: - BoolExpr(BroExprTag tag, zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + BoolExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2); - zeek::IntrusivePtr Eval(Frame* f) const override; - zeek::IntrusivePtr DoSingleEval(Frame* f, zeek::IntrusivePtr v1, Expr* op2) const; + ValPtr Eval(Frame* f) const override; + ValPtr DoSingleEval(Frame* f, ValPtr v1, Expr* op2) const; }; class BitExpr final : public BinaryExpr { public: - BitExpr(BroExprTag tag, zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + BitExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2); }; class EqExpr final : public BinaryExpr { public: - EqExpr(BroExprTag tag, zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + EqExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2); void Canonicize() override; protected: - zeek::IntrusivePtr Fold(Val* v1, Val* v2) const override; + ValPtr Fold(Val* v1, Val* v2) const override; }; class RelExpr final : public BinaryExpr { public: - RelExpr(BroExprTag tag, zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + RelExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2); void Canonicize() override; }; class CondExpr final : public Expr { public: - CondExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2, zeek::IntrusivePtr op3); + CondExpr(ExprPtr op1, ExprPtr op2, ExprPtr op3); const Expr* Op1() const { return op1.get(); } const Expr* Op2() const { return op2.get(); } const Expr* Op3() const { return op3.get(); } - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; bool IsPure() const override; TraversalCode Traverse(TraversalCallback* cb) const override; @@ -502,53 +508,53 @@ public: protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr op1; - zeek::IntrusivePtr op2; - zeek::IntrusivePtr op3; + ExprPtr op1; + ExprPtr op2; + ExprPtr op3; }; class RefExpr final : public UnaryExpr { public: - explicit RefExpr(zeek::IntrusivePtr op); + explicit RefExpr(ExprPtr op); - void Assign(Frame* f, zeek::IntrusivePtr v) override; - zeek::IntrusivePtr MakeLvalue() override; + void Assign(Frame* f, ValPtr v) override; + ExprPtr MakeLvalue() override; }; class AssignExpr : public BinaryExpr { public: // If val is given, evaluating this expression will always yield the val // yet still perform the assignment. Used for triggers. - AssignExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2, bool is_init, - zeek::IntrusivePtr val = nullptr, - const zeek::IntrusivePtr& attrs = nullptr); + AssignExpr(ExprPtr op1, ExprPtr op2, bool is_init, + ValPtr val = nullptr, + const AttributesPtr& attrs = nullptr); - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override; - zeek::IntrusivePtr InitType() const override; + zeek::TypePtr InitType() const override; bool IsRecordElement(TypeDecl* td) const override; - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; bool IsPure() const override; protected: - bool TypeCheck(const zeek::IntrusivePtr& attrs = nullptr); + bool TypeCheck(const AttributesPtr& attrs = nullptr); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool is_init; - zeek::IntrusivePtr val; // optional + ValPtr val; // optional }; class IndexSliceAssignExpr final : public AssignExpr { public: - IndexSliceAssignExpr(zeek::IntrusivePtr op1, - zeek::IntrusivePtr op2, bool is_init); - zeek::IntrusivePtr Eval(Frame* f) const override; + IndexSliceAssignExpr(ExprPtr op1, + ExprPtr op2, bool is_init); + ValPtr Eval(Frame* f) const override; }; class IndexExpr final : public BinaryExpr { public: - IndexExpr(zeek::IntrusivePtr op1, - zeek::IntrusivePtr op2, bool is_slice = false); + IndexExpr(ExprPtr op1, + ListExprPtr op2, bool is_slice = false); bool CanAdd() const override; bool CanDel() const override; @@ -556,19 +562,19 @@ public: void Add(Frame* f) override; void Delete(Frame* f) override; - void Assign(Frame* f, zeek::IntrusivePtr v) override; - zeek::IntrusivePtr MakeLvalue() override; + void Assign(Frame* f, ValPtr v) override; + ExprPtr MakeLvalue() override; // Need to override Eval since it can take a vector arg but does // not necessarily return a vector. - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; bool IsSlice() const { return is_slice; } protected: - zeek::IntrusivePtr Fold(Val* v1, Val* v2) const override; + ValPtr Fold(Val* v1, Val* v2) const override; void ExprDescribe(ODesc* d) const override; @@ -577,7 +583,7 @@ protected: class FieldExpr final : public UnaryExpr { public: - FieldExpr(zeek::IntrusivePtr op, const char* field_name); + FieldExpr(ExprPtr op, const char* field_name); ~FieldExpr() override; int Field() const { return field; } @@ -585,13 +591,13 @@ public: bool CanDel() const override; - void Assign(Frame* f, zeek::IntrusivePtr v) override; + void Assign(Frame* f, ValPtr v) override; void Delete(Frame* f) override; - zeek::IntrusivePtr MakeLvalue() override; + ExprPtr MakeLvalue() override; protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; @@ -604,13 +610,13 @@ protected: // "rec?$$attrname" is true if the attribute attrname is not nil. class HasFieldExpr final : public UnaryExpr { public: - HasFieldExpr(zeek::IntrusivePtr op, const char* field_name); + HasFieldExpr(ExprPtr op, const char* field_name); ~HasFieldExpr() override; const char* FieldName() const { return field_name; } protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; @@ -620,76 +626,76 @@ protected: class RecordConstructorExpr final : public UnaryExpr { public: - explicit RecordConstructorExpr(zeek::IntrusivePtr constructor_list); + explicit RecordConstructorExpr(ListExprPtr constructor_list); ~RecordConstructorExpr() override; protected: - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; + ValPtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; }; class TableConstructorExpr final : public UnaryExpr { public: - TableConstructorExpr(zeek::IntrusivePtr constructor_list, - std::unique_ptr>> attrs, - zeek::IntrusivePtr arg_type = nullptr); + TableConstructorExpr(ListExprPtr constructor_list, + std::unique_ptr> attrs, + zeek::TypePtr arg_type = nullptr); [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } - const zeek::IntrusivePtr& GetAttrs() const + const AttributesPtr& GetAttrs() const { return attrs; } - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; protected: - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr attrs; + AttributesPtr attrs; }; class SetConstructorExpr final : public UnaryExpr { public: - SetConstructorExpr(zeek::IntrusivePtr constructor_list, - std::unique_ptr>> attrs, - zeek::IntrusivePtr arg_type = nullptr); + SetConstructorExpr(ListExprPtr constructor_list, + std::unique_ptr> attrs, + zeek::TypePtr arg_type = nullptr); [[deprecated("Remove in v4.1. Use GetAttrs().")]] Attributes* Attrs() { return attrs.get(); } - const zeek::IntrusivePtr& GetAttrs() const + const AttributesPtr& GetAttrs() const { return attrs; } - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; protected: - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr attrs; + AttributesPtr attrs; }; class VectorConstructorExpr final : public UnaryExpr { public: - explicit VectorConstructorExpr(zeek::IntrusivePtr constructor_list, - zeek::IntrusivePtr arg_type = nullptr); + explicit VectorConstructorExpr(ListExprPtr constructor_list, + zeek::TypePtr arg_type = nullptr); - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; protected: - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; void ExprDescribe(ODesc* d) const override; }; class FieldAssignExpr final : public UnaryExpr { public: - FieldAssignExpr(const char* field_name, zeek::IntrusivePtr value); + FieldAssignExpr(const char* field_name, ExprPtr value); const char* FieldName() const { return field_name.c_str(); } @@ -704,21 +710,21 @@ protected: class ArithCoerceExpr final : public UnaryExpr { public: - ArithCoerceExpr(zeek::IntrusivePtr op, zeek::TypeTag t); + ArithCoerceExpr(ExprPtr op, zeek::TypeTag t); protected: - zeek::IntrusivePtr FoldSingleVal(Val* v, InternalTypeTag t) const; - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr FoldSingleVal(Val* v, InternalTypeTag t) const; + ValPtr Fold(Val* v) const override; }; class RecordCoerceExpr final : public UnaryExpr { public: - RecordCoerceExpr(zeek::IntrusivePtr op, zeek::IntrusivePtr r); + RecordCoerceExpr(ExprPtr op, RecordTypePtr r); ~RecordCoerceExpr() override; protected: - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; + ValPtr Fold(Val* v) const override; // For each super-record slot, gives subrecord slot with which to // fill it. @@ -728,20 +734,20 @@ protected: class TableCoerceExpr final : public UnaryExpr { public: - TableCoerceExpr(zeek::IntrusivePtr op, zeek::IntrusivePtr r); + TableCoerceExpr(ExprPtr op, TableTypePtr r); ~TableCoerceExpr() override; protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class VectorCoerceExpr final : public UnaryExpr { public: - VectorCoerceExpr(zeek::IntrusivePtr op, zeek::IntrusivePtr v); + VectorCoerceExpr(ExprPtr op, VectorTypePtr v); ~VectorCoerceExpr() override; protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; }; class ScheduleTimer final : public Timer { @@ -758,11 +764,11 @@ protected: class ScheduleExpr final : public Expr { public: - ScheduleExpr(zeek::IntrusivePtr when, zeek::IntrusivePtr event); + ScheduleExpr(ExprPtr when, EventExprPtr event); bool IsPure() const override; - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; Expr* When() const { return when.get(); } EventExpr* Event() const { return event.get(); } @@ -772,22 +778,22 @@ public: protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr when; - zeek::IntrusivePtr event; + ExprPtr when; + EventExprPtr event; }; class InExpr final : public BinaryExpr { public: - InExpr(zeek::IntrusivePtr op1, zeek::IntrusivePtr op2); + InExpr(ExprPtr op1, ExprPtr op2); protected: - zeek::IntrusivePtr Fold(Val* v1, Val* v2) const override; + ValPtr Fold(Val* v1, Val* v2) const override; }; class CallExpr final : public Expr { public: - CallExpr(zeek::IntrusivePtr func, zeek::IntrusivePtr args, + CallExpr(ExprPtr func, ListExprPtr args, bool in_hook = false); Expr* Func() const { return func.get(); } @@ -795,15 +801,15 @@ public: bool IsPure() const override; - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: void ExprDescribe(ODesc* d) const override; - zeek::IntrusivePtr func; - zeek::IntrusivePtr args; + ExprPtr func; + ListExprPtr args; }; @@ -817,7 +823,7 @@ public: LambdaExpr(std::unique_ptr ingredients, id_list outer_ids); - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; Scope* GetScope() const; @@ -834,13 +840,13 @@ private: class EventExpr final : public Expr { public: - EventExpr(const char* name, zeek::IntrusivePtr args); + EventExpr(const char* name, ListExprPtr args); const char* Name() const { return name.c_str(); } ListExpr* Args() const { return args.get(); } EventHandlerPtr Handler() const { return handler; } - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; TraversalCode Traverse(TraversalCallback* cb) const override; @@ -849,16 +855,16 @@ protected: std::string name; EventHandlerPtr handler; - zeek::IntrusivePtr args; + ListExprPtr args; }; class ListExpr : public Expr { public: ListExpr(); - explicit ListExpr(zeek::IntrusivePtr e); + explicit ListExpr(ExprPtr e); ~ListExpr() override; - void Append(zeek::IntrusivePtr e); + void Append(ExprPtr e); const expr_list& Exprs() const { return exprs; } expr_list& Exprs() { return exprs; } @@ -866,17 +872,17 @@ public: // True if the entire list represents pure values. bool IsPure() const override; - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; - zeek::IntrusivePtr InitType() const override; - zeek::IntrusivePtr InitVal(const zeek::Type* t, zeek::IntrusivePtr aggr) const override; - zeek::IntrusivePtr MakeLvalue() override; - void Assign(Frame* f, zeek::IntrusivePtr v) override; + zeek::TypePtr InitType() const override; + ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override; + ExprPtr MakeLvalue() override; + void Assign(Frame* f, ValPtr v) override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr AddSetInit(const zeek::Type* t, zeek::IntrusivePtr aggr) const; + ValPtr AddSetInit(const zeek::Type* t, ValPtr aggr) const; void ExprDescribe(ODesc* d) const override; @@ -886,28 +892,28 @@ protected: class RecordAssignExpr final : public ListExpr { public: - RecordAssignExpr(const zeek::IntrusivePtr& record, const zeek::IntrusivePtr& init_list, bool is_init); + RecordAssignExpr(const ExprPtr& record, const ExprPtr& init_list, bool is_init); }; class CastExpr final : public UnaryExpr { public: - CastExpr(zeek::IntrusivePtr op, zeek::IntrusivePtr t); + CastExpr(ExprPtr op, zeek::TypePtr t); protected: - zeek::IntrusivePtr Eval(Frame* f) const override; + ValPtr Eval(Frame* f) const override; void ExprDescribe(ODesc* d) const override; }; class IsExpr final : public UnaryExpr { public: - IsExpr(zeek::IntrusivePtr op, zeek::IntrusivePtr t); + IsExpr(ExprPtr op, zeek::TypePtr t); protected: - zeek::IntrusivePtr Fold(Val* v) const override; + ValPtr Fold(Val* v) const override; void ExprDescribe(ODesc* d) const override; private: - zeek::IntrusivePtr t; + zeek::TypePtr t; }; inline Val* Expr::ExprVal() const @@ -918,9 +924,9 @@ inline Val* Expr::ExprVal() const } // Decides whether to return an AssignExpr or a RecordAssignExpr. -zeek::IntrusivePtr get_assign_expr( - zeek::IntrusivePtr op1, - zeek::IntrusivePtr op2, bool is_init); +ExprPtr get_assign_expr( + ExprPtr op1, + ExprPtr op2, bool is_init); // Type-check the given expression(s) against the given type(s). Complain // if the expression cannot match the given type, returning 0. If it can @@ -937,7 +943,7 @@ zeek::IntrusivePtr get_assign_expr( * Returns nullptr if the expression cannot match or a promoted * expression. */ -extern zeek::IntrusivePtr check_and_promote_expr(Expr* e, Type* t); +extern ExprPtr 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); @@ -945,7 +951,7 @@ 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. -std::optional>> eval_list(Frame* f, const ListExpr* l); +std::optional> eval_list(Frame* f, const ListExpr* l); // Returns true if e1 is "greater" than e2 - here "greater" is just // a heuristic, used with commutative operators to put them into @@ -954,7 +960,7 @@ 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 zeek::IntrusivePtr& e) { return is_vector(e.get()); } +inline bool is_vector(const ExprPtr& e) { return is_vector(e.get()); } } diff --git a/src/File.cc b/src/File.cc index bf3cc294f2..f7c04a0a2c 100644 --- a/src/File.cc +++ b/src/File.cc @@ -328,7 +328,7 @@ void BroFile::RaiseOpenEvent() if ( ! ::file_opened ) return; - zeek::IntrusivePtr bf{zeek::NewRef{}, this}; + BroFilePtr bf{zeek::NewRef{}, this}; Event* event = new ::Event(::file_opened, {zeek::make_intrusive(std::move(bf))}); mgr.Dispatch(event, true); } @@ -346,7 +346,7 @@ double BroFile::Size() return s.st_size; } -zeek::IntrusivePtr BroFile::Get(const char* name) +BroFilePtr BroFile::Get(const char* name) { for ( const auto &el : open_files ) if ( el.first == name ) diff --git a/src/File.h b/src/File.h index a3c834a116..8a7017a250 100644 --- a/src/File.h +++ b/src/File.h @@ -18,12 +18,18 @@ class RecordVal; -namespace zeek { class Type; } +namespace zeek { + class Type; + using TypePtr = zeek::IntrusivePtr; +} 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; +using BroFilePtr = zeek::IntrusivePtr; + class BroFile final : public BroObj { public: explicit BroFile(FILE* arg_f); @@ -45,7 +51,7 @@ public: [[deprecated("Remove in v4.1. Use GetType().")]] zeek::Type* FType() const { return t.get(); } - const zeek::IntrusivePtr& GetType() const + const zeek::TypePtr& GetType() const { return t; } // Whether the file is open in a general sense; it might @@ -72,7 +78,7 @@ public: static void CloseOpenFiles(); // Get the file with the given name, opening it if it doesn't yet exist. - static zeek::IntrusivePtr Get(const char* name); + static BroFilePtr Get(const char* name); [[deprecated("Remove in v4.1. Use BroFile::Get().")]] static BroFile* GetFile(const char* name) { return Get(name).release(); } @@ -106,7 +112,7 @@ protected: void RaiseOpenEvent(); FILE* f; - zeek::IntrusivePtr t; + zeek::TypePtr t; char* name; char* access; zeek::detail::Attributes* attrs; diff --git a/src/Frame.cc b/src/Frame.cc index 6692b4e012..c79ac6abda 100644 --- a/src/Frame.cc +++ b/src/Frame.cc @@ -7,7 +7,6 @@ #include "Func.h" #include "Desc.h" -#include "IntrusivePtr.h" #include "Trigger.h" #include "Val.h" #include "ID.h" @@ -65,7 +64,7 @@ void Frame::AddFunctionWithClosureRef(BroFunc* func) void Frame::SetElement(int n, Val* v) { SetElement(n, {zeek::AdoptRef{}, v}); } -void Frame::SetElement(int n, zeek::IntrusivePtr v) +void Frame::SetElement(int n, ValPtr v) { ClearElement(n); frame[n] = {std::move(v), false}; @@ -77,7 +76,7 @@ void Frame::SetElementWeak(int n, Val* v) frame[n] = {{zeek::AdoptRef{}, v}, true}; } -void Frame::SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr v) +void Frame::SetElement(const zeek::detail::ID* id, ValPtr v) { if ( closure ) { @@ -106,7 +105,7 @@ void Frame::SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr v) SetElement(id->Offset(), std::move(v)); } -const zeek::IntrusivePtr& Frame::GetElementByID(const zeek::detail::ID* id) const +const ValPtr& Frame::GetElementByID(const zeek::detail::ID* id) const { if ( closure ) { @@ -173,7 +172,7 @@ Frame* Frame::Clone() const return other; } -static bool val_is_func(const zeek::IntrusivePtr& v, BroFunc* func) +static bool val_is_func(const ValPtr& v, BroFunc* func) { if ( v->GetType()->Tag() != zeek::TYPE_FUNC ) return false; @@ -348,14 +347,14 @@ broker::expected Frame::Serialize(const Frame* target, const id_li return {std::move(rval)}; } -std::pair> Frame::Unserialize(const broker::vector& data) +std::pair Frame::Unserialize(const broker::vector& data) { if ( data.size() == 0 ) return std::make_pair(true, nullptr); id_list outer_ids; OffsetMap offset_map; - zeek::IntrusivePtr closure; + FramePtr closure; auto where = data.begin(); @@ -505,7 +504,7 @@ void Frame::CaptureClosure(Frame* c, id_list arg_outer_ids) // if (c) closure = c->SelectiveClone(outer_ids); } -void Frame::SetTrigger(zeek::IntrusivePtr arg_trigger) +void Frame::SetTrigger(zeek::detail::trigger::TriggerPtr arg_trigger) { trigger = std::move(arg_trigger); } diff --git a/src/Frame.h b/src/Frame.h index 87720c6bc8..7f8cba9dad 100644 --- a/src/Frame.h +++ b/src/Frame.h @@ -21,6 +21,19 @@ class BroFunc; ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger); +namespace zeek::detail { +using IDPtr = zeek::IntrusivePtr; + +namespace trigger { + using TriggerPtr = zeek::IntrusivePtr; +} +} + +using ValPtr = zeek::IntrusivePtr; + +class Frame; +using FramePtr = zeek::IntrusivePtr; + class Frame : public BroObj { public: /** @@ -43,7 +56,7 @@ public: * @param n the index to get. * @return the value at index *n* of the underlying array. */ - const zeek::IntrusivePtr& GetElement(int n) const + const ValPtr& GetElement(int n) const { return frame[n].val; } [[deprecated("Remove in v4.1. Use GetElement(int).")]] @@ -54,7 +67,7 @@ public: * @param n the index to set * @param v the value to set it to */ - void SetElement(int n, zeek::IntrusivePtr v); + void SetElement(int n, ValPtr v); [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] void SetElement(int n, Val* v); @@ -66,8 +79,8 @@ public: * @param id the ID to associate * @param v the value to associate it with */ - void SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr v); - void SetElement(const zeek::IntrusivePtr& id, zeek::IntrusivePtr v) + void SetElement(const zeek::detail::ID* id, ValPtr v); + void SetElement(const zeek::detail::IDPtr& id, ValPtr v) { SetElement(id.get(), std::move(v)); } /** @@ -77,7 +90,7 @@ public: * @param id the id who's value to retreive * @return the value associated with *id* */ - const zeek::IntrusivePtr& GetElementByID(const zeek::IntrusivePtr& id) const + const ValPtr& GetElementByID(const zeek::detail::IDPtr& id) const { return GetElementByID(id.get()); } [[deprecated("Remove in v4.1. Use GetElementByID().")]] @@ -195,7 +208,7 @@ public: * and the second is the unserialized frame with reference count +1, or * null if the serialization wasn't successful. */ - static std::pair> Unserialize(const broker::vector& data); + static std::pair Unserialize(const broker::vector& data); /** * Sets the IDs that the frame knows offsets for. These offsets will @@ -216,7 +229,7 @@ public: // If the frame is run in the context of a trigger condition evaluation, // the trigger needs to be registered. - void SetTrigger(zeek::IntrusivePtr arg_trigger); + void SetTrigger(zeek::detail::trigger::TriggerPtr arg_trigger); void ClearTrigger(); zeek::detail::trigger::Trigger* GetTrigger() const { return trigger.get(); } @@ -241,13 +254,13 @@ private: using OffsetMap = std::unordered_map; struct Element { - zeek::IntrusivePtr val; + ValPtr val; // Weak reference is used to prevent circular reference memory leaks // in lambdas/closures. bool weak_ref; }; - const zeek::IntrusivePtr& GetElementByID(const zeek::detail::ID* id) const; + const ValPtr& GetElementByID(const zeek::detail::ID* id) const; /** * Sets the element at index *n* of the underlying array to *v*, but does @@ -322,7 +335,7 @@ private: /** The next statement to be evaluted in the context of this frame. */ zeek::detail::Stmt* next_stmt; - zeek::IntrusivePtr trigger; + zeek::detail::trigger::TriggerPtr 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 c3a007b997..f50e8fdaa4 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -60,7 +60,7 @@ extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; bool did_builtin_init = false; -static const std::pair> empty_hook_result(false, nullptr); +static const std::pair empty_hook_result(false, nullptr); std::string render_call_stack() { @@ -122,19 +122,19 @@ Func::Func(Kind arg_kind) : kind(arg_kind) Func::~Func() = default; -void Func::AddBody(zeek::IntrusivePtr /* new_body */, - const std::vector>& /* new_inits */, +void Func::AddBody(zeek::detail::StmtPtr /* new_body */, + const std::vector& /* new_inits */, size_t /* new_frame_size */, int /* priority */) { Internal("Func::AddBody called"); } -void Func::SetScope(zeek::IntrusivePtr newscope) +void Func::SetScope(ScopePtr newscope) { scope = std::move(newscope); } -zeek::IntrusivePtr Func::DoClone() +FuncPtr Func::DoClone() { // By default, ok just to return a reference. Func does not have any state // that is different across instances. @@ -216,7 +216,7 @@ void Func::CopyStateInto(Func* other) const other->unique_id = unique_id; } -void Func::CheckPluginResult(bool handled, const zeek::IntrusivePtr& hook_result, +void Func::CheckPluginResult(bool handled, const ValPtr& hook_result, zeek::FunctionFlavor flavor) const { // Helper function factoring out this code from BroFunc:Call() for @@ -269,8 +269,8 @@ void Func::CheckPluginResult(bool handled, const zeek::IntrusivePtr& hook_r } } -BroFunc::BroFunc(const zeek::IntrusivePtr& arg_id, zeek::IntrusivePtr arg_body, - const std::vector>& aggr_inits, +BroFunc::BroFunc(const zeek::detail::IDPtr& arg_id, zeek::detail::StmtPtr arg_body, + const std::vector& aggr_inits, size_t arg_frame_size, int priority) : Func(BRO_FUNC) { @@ -305,7 +305,7 @@ Val* Func::Call(val_list* args, Frame* parent) const return Invoke(&zargs, parent).release(); }; -zeek::IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const +ValPtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -357,7 +357,7 @@ zeek::IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const } stmt_flow_type flow = FLOW_NEXT; - zeek::IntrusivePtr result; + ValPtr result; for ( const auto& body : bodies ) { @@ -450,8 +450,8 @@ zeek::IntrusivePtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const return result; } -void BroFunc::AddBody(zeek::IntrusivePtr new_body, - const std::vector>& new_inits, +void BroFunc::AddBody(zeek::detail::StmtPtr new_body, + const std::vector& new_inits, size_t new_frame_size, int priority) { if ( new_frame_size > frame_size ) @@ -541,7 +541,7 @@ bool BroFunc::UpdateClosure(const broker::vector& data) } -zeek::IntrusivePtr BroFunc::DoClone() +FuncPtr BroFunc::DoClone() { // BroFunc could hold a closure. In this case a clone of it must // store a copy of this closure. @@ -575,9 +575,9 @@ void BroFunc::Describe(ODesc* d) const } } -zeek::IntrusivePtr BroFunc::AddInits( - zeek::IntrusivePtr body, - const std::vector>& inits) +zeek::detail::StmtPtr BroFunc::AddInits( + zeek::detail::StmtPtr body, + const std::vector& inits) { if ( inits.empty() ) return body; @@ -616,7 +616,7 @@ bool BuiltinFunc::IsPure() const return is_pure; } -zeek::IntrusivePtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const +ValPtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const { #ifdef PROFILE_BRO_FUNCTIONS DEBUG_MSG("Function: %s\n", Name()); @@ -667,10 +667,10 @@ void BuiltinFunc::Describe(ODesc* d) const void builtin_error(const char* msg) { - builtin_error(msg, zeek::IntrusivePtr{}); + builtin_error(msg, ValPtr{}); } -void builtin_error(const char* msg, zeek::IntrusivePtr arg) +void builtin_error(const char* msg, ValPtr arg) { builtin_error(msg, arg.get()); } @@ -846,7 +846,7 @@ bool check_built_in_call(BuiltinFunc* f, zeek::detail::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; @@ -881,7 +881,7 @@ static int get_func_priority(const std::vector scope, zeek::IntrusivePtr body) +function_ingredients::function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body) { frame_size = scope->Length(); inits = scope->GetInits(); diff --git a/src/Func.h b/src/Func.h index 03efa7c9f8..b116d3418c 100644 --- a/src/Func.h +++ b/src/Func.h @@ -20,12 +20,18 @@ class Val; class Frame; class Scope; +using ScopePtr = zeek::IntrusivePtr; 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 zeek::detail { +using IDPtr = zeek::IntrusivePtr; +using StmtPtr = zeek::IntrusivePtr; +} + namespace caf { template class expected; } @@ -36,9 +42,12 @@ using vector = std::vector; using caf::expected; } +class Func; +using FuncPtr = zeek::IntrusivePtr; + class Func : public BroObj { public: - static inline const zeek::IntrusivePtr nil; + static inline const FuncPtr nil; enum Kind { BRO_FUNC, BUILTIN_FUNC }; @@ -50,7 +59,7 @@ public: zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); } struct Body { - zeek::IntrusivePtr stmts; + zeek::detail::StmtPtr stmts; int priority; bool operator<(const Body& other) const { return priority > other.priority; } // reverse sort @@ -68,7 +77,7 @@ public: * @param parent the frame from which the function is being called. * @return the return value of the function call. */ - virtual zeek::IntrusivePtr Invoke( + virtual ValPtr Invoke( zeek::Args* args, Frame* parent = nullptr) const = 0; /** @@ -77,8 +86,8 @@ public: template std::enable_if_t< std::is_convertible_v>, - zeek::IntrusivePtr>, - zeek::IntrusivePtr> + ValPtr>, + ValPtr> Invoke(Args&&... args) const { auto zargs = zeek::Args{std::forward(args)...}; @@ -86,17 +95,17 @@ public: } // Add a new event handler to an existing function (event). - virtual void AddBody(zeek::IntrusivePtr new_body, - const std::vector>& new_inits, + virtual void AddBody(zeek::detail::StmtPtr new_body, + const std::vector& new_inits, size_t new_frame_size, int priority = 0); - virtual void SetScope(zeek::IntrusivePtr newscope); + virtual void SetScope(ScopePtr newscope); virtual Scope* GetScope() const { return scope.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] virtual zeek::FuncType* FType() const { return type.get(); } - const zeek::IntrusivePtr& GetType() const + const zeek::FuncTypePtr& GetType() const { return type; } Kind GetKind() const { return kind; } @@ -107,12 +116,12 @@ public: void Describe(ODesc* d) const override = 0; virtual void DescribeDebug(ODesc* d, const zeek::Args* args) const; - virtual zeek::IntrusivePtr DoClone(); + virtual FuncPtr DoClone(); virtual TraversalCode Traverse(TraversalCallback* cb) const; uint32_t GetUniqueFuncID() const { return unique_id; } - static const zeek::IntrusivePtr& GetFuncPtrByID(uint32_t id) + static const FuncPtr& GetFuncPtrByID(uint32_t id) { return id >= unique_ids.size() ? Func::nil : unique_ids[id]; } protected: @@ -122,29 +131,29 @@ protected: void CopyStateInto(Func* other) const; // Helper function for checking result of plugin hook. - void CheckPluginResult(bool handled, const zeek::IntrusivePtr& hook_result, + void CheckPluginResult(bool handled, const ValPtr& hook_result, zeek::FunctionFlavor flavor) const; std::vector bodies; - zeek::IntrusivePtr scope; + ScopePtr scope; Kind kind; uint32_t unique_id; - zeek::IntrusivePtr type; + zeek::FuncTypePtr type; std::string name; - static inline std::vector> unique_ids; + static inline std::vector unique_ids; }; class BroFunc final : public Func { public: - BroFunc(const zeek::IntrusivePtr& id, zeek::IntrusivePtr body, - const std::vector>& inits, + BroFunc(const zeek::detail::IDPtr& id, zeek::detail::StmtPtr body, + const std::vector& inits, size_t frame_size, int priority); ~BroFunc() override; bool IsPure() const override; - zeek::IntrusivePtr Invoke(zeek::Args* args, Frame* parent) const override; + ValPtr Invoke(zeek::Args* args, Frame* parent) const override; /** * Adds adds a closure to the function. Closures are cloned and @@ -175,8 +184,8 @@ public: */ broker::expected SerializeClosure() const; - void AddBody(zeek::IntrusivePtr new_body, - const std::vector>& new_inits, + void AddBody(zeek::detail::StmtPtr new_body, + const std::vector& new_inits, size_t new_frame_size, int priority) override; /** Sets this function's outer_id list. */ @@ -187,14 +196,14 @@ public: protected: BroFunc() : Func(BRO_FUNC) {} - zeek::IntrusivePtr AddInits( - zeek::IntrusivePtr body, - const std::vector>& inits); + zeek::detail::StmtPtr AddInits( + zeek::detail::StmtPtr body, + const std::vector& inits); /** * Clones this function along with its closures. */ - zeek::IntrusivePtr DoClone() override; + FuncPtr DoClone() override; /** * Performs a selective clone of *f* using the IDs that were @@ -222,7 +231,7 @@ public: ~BuiltinFunc() override; bool IsPure() const override; - zeek::IntrusivePtr Invoke(zeek::Args* args, Frame* parent) const override; + ValPtr Invoke(zeek::Args* args, Frame* parent) const override; built_in_func TheFunc() const { return func; } void Describe(ODesc* d) const override; @@ -236,7 +245,7 @@ protected: extern void builtin_error(const char* msg); -extern void builtin_error(const char* msg, zeek::IntrusivePtr); +extern void builtin_error(const char* msg, ValPtr); extern void builtin_error(const char* msg, BroObj* arg); extern void init_builtin_funcs(); extern void init_builtin_funcs_subdirs(); @@ -255,14 +264,14 @@ struct function_ingredients { // Gathers all of the information from a scope and a function body needed // to build a function. - function_ingredients(zeek::IntrusivePtr scope, zeek::IntrusivePtr body); + function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body); - zeek::IntrusivePtr id; - zeek::IntrusivePtr body; - std::vector> inits; + zeek::detail::IDPtr id; + zeek::detail::StmtPtr body; + std::vector inits; int frame_size; int priority; - zeek::IntrusivePtr scope; + ScopePtr scope; }; extern std::vector call_stack; diff --git a/src/ID.cc b/src/ID.cc index 4f2558fd80..7e82d300c3 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -1,3 +1,4 @@ + // See the file "COPYING" in the main distribution directory for copyright. #include "zeek-config.h" @@ -19,24 +20,24 @@ #include "zeekygen/ScriptInfo.h" #include "module_util.h" -zeek::IntrusivePtr zeek::id::conn_id; -zeek::IntrusivePtr zeek::id::endpoint; -zeek::IntrusivePtr zeek::id::connection; -zeek::IntrusivePtr zeek::id::fa_file; -zeek::IntrusivePtr zeek::id::fa_metadata; -zeek::IntrusivePtr zeek::id::transport_proto; -zeek::IntrusivePtr zeek::id::string_set; -zeek::IntrusivePtr zeek::id::string_array; -zeek::IntrusivePtr zeek::id::count_set; -zeek::IntrusivePtr zeek::id::string_vec; -zeek::IntrusivePtr zeek::id::index_vec; +zeek::RecordTypePtr zeek::id::conn_id; +zeek::RecordTypePtr zeek::id::endpoint; +zeek::RecordTypePtr zeek::id::connection; +zeek::RecordTypePtr zeek::id::fa_file; +zeek::RecordTypePtr zeek::id::fa_metadata; +zeek::EnumTypePtr zeek::id::transport_proto; +zeek::TableTypePtr zeek::id::string_set; +zeek::TableTypePtr zeek::id::string_array; +zeek::TableTypePtr zeek::id::count_set; +zeek::VectorTypePtr zeek::id::string_vec; +zeek::VectorTypePtr zeek::id::index_vec; -const zeek::IntrusivePtr& zeek::id::find(std::string_view name) +const zeek::detail::IDPtr& zeek::id::find(std::string_view name) { return global_scope()->Find(name); } -const zeek::IntrusivePtr& zeek::id::find_type(std::string_view name) +const zeek::TypePtr& zeek::id::find_type(std::string_view name) { auto id = global_scope()->Find(name); @@ -47,7 +48,7 @@ const zeek::IntrusivePtr& zeek::id::find_type(std::string_view name) return id->GetType(); } -const zeek::IntrusivePtr& zeek::id::find_val(std::string_view name) +const ValPtr& zeek::id::find_val(std::string_view name) { auto id = global_scope()->Find(name); @@ -58,7 +59,7 @@ const zeek::IntrusivePtr& zeek::id::find_val(std::string_view name) return id->GetVal(); } -const zeek::IntrusivePtr& zeek::id::find_const(std::string_view name) +const ValPtr& zeek::id::find_const(std::string_view name) { auto id = global_scope()->Find(name); @@ -73,7 +74,7 @@ const zeek::IntrusivePtr& zeek::id::find_const(std::string_view name) return id->GetVal(); } -zeek::IntrusivePtr zeek::id::find_func(std::string_view name) +FuncPtr zeek::id::find_func(std::string_view name) { const auto& v = zeek::id::find_val(name); @@ -130,7 +131,7 @@ std::string ID::ModuleName() const return extract_module_name(name); } -void ID::SetType(zeek::IntrusivePtr t) +void ID::SetType(zeek::TypePtr t) { type = std::move(t); } @@ -140,7 +141,7 @@ void ID::ClearVal() val = nullptr; } -void ID::SetVal(zeek::IntrusivePtr v) +void ID::SetVal(ValPtr v) { val = std::move(v); Modified(); @@ -169,7 +170,7 @@ void ID::SetVal(zeek::IntrusivePtr v) } } -void ID::SetVal(zeek::IntrusivePtr v, InitClass c) +void ID::SetVal(ValPtr v, InitClass c) { if ( c == INIT_NONE || c == INIT_FULL ) { @@ -207,7 +208,7 @@ void ID::SetVal(zeek::IntrusivePtr v, InitClass c) } } -void ID::SetVal(zeek::IntrusivePtr ev, InitClass c) +void ID::SetVal(ExprPtr ev, InitClass c) { const auto& a = attrs->Find(c == INIT_EXTRA ? ATTR_ADD_FUNC : ATTR_DEL_FUNC); @@ -222,7 +223,7 @@ bool ID::IsRedefinable() const return GetAttr(ATTR_REDEF) != nullptr; } -void ID::SetAttrs(zeek::IntrusivePtr a) +void ID::SetAttrs(AttributesPtr a) { attrs = nullptr; AddAttrs(std::move(a)); @@ -268,7 +269,7 @@ void ID::UpdateValAttrs() } } -const zeek::IntrusivePtr& ID::GetAttr(AttrTag t) const +const AttrPtr& ID::GetAttr(AttrTag t) const { return attrs ? attrs->Find(t) : Attr::nil; } @@ -278,12 +279,12 @@ bool ID::IsDeprecated() const return GetAttr(ATTR_DEPRECATED) != nullptr; } -void ID::MakeDeprecated(zeek::IntrusivePtr deprecation) +void ID::MakeDeprecated(ExprPtr deprecation) { if ( IsDeprecated() ) return; - std::vector> attrv{zeek::make_intrusive(ATTR_DEPRECATED, std::move(deprecation))}; + std::vector attrv{zeek::make_intrusive(ATTR_DEPRECATED, std::move(deprecation))}; AddAttrs(zeek::make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); } @@ -308,7 +309,7 @@ std::string ID::GetDeprecationWarning() const return fmt("deprecated (%s): %s", Name(), result.c_str()); } -void ID::AddAttrs(zeek::IntrusivePtr a) +void ID::AddAttrs(AttributesPtr a) { if ( attrs ) attrs->AddAttrs(a); @@ -334,12 +335,12 @@ void ID::SetOption() // option implied redefinable if ( ! IsRedefinable() ) { - std::vector> attrv{zeek::make_intrusive(ATTR_REDEF)}; + std::vector attrv{zeek::make_intrusive(ATTR_REDEF)}; AddAttrs(zeek::make_intrusive(std::move(attrv), GetType(), false, IsGlobal())); } } -void ID::EvalFunc(zeek::IntrusivePtr ef, zeek::IntrusivePtr ev) +void ID::EvalFunc(ExprPtr ef, ExprPtr ev) { auto arg1 = zeek::make_intrusive(val); auto args = zeek::make_intrusive(); @@ -642,7 +643,7 @@ void ID::UpdateValID() } #endif -void ID::AddOptionHandler(zeek::IntrusivePtr callback, int priority) +void ID::AddOptionHandler(FuncPtr callback, int priority) { option_handlers.emplace(priority, std::move(callback)); } diff --git a/src/ID.h b/src/ID.h index 4c0d4313fc..632abf64cb 100644 --- a/src/ID.h +++ b/src/ID.h @@ -14,7 +14,10 @@ #include class Val; +using ValPtr = zeek::IntrusivePtr; + class Func; +using FuncPtr = zeek::IntrusivePtr; namespace zeek { class Type; } using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; @@ -24,17 +27,27 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(TableType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek); +using TypePtr = zeek::IntrusivePtr; +using RecordTypePtr = zeek::IntrusivePtr; +using TableTypePtr = zeek::IntrusivePtr; +using VectorTypePtr = zeek::IntrusivePtr; +using EnumTypePtr = zeek::IntrusivePtr; + namespace zeek::detail { class Attributes; class Expr; +using ExprPtr = zeek::IntrusivePtr; enum InitClass { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; +class ID; +using IDPtr = zeek::IntrusivePtr; + class ID final : public BroObj, public notifier::Modifiable { public: - static inline const zeek::IntrusivePtr nil; + static inline const IDPtr nil; ID(const char* name, IDScope arg_scope, bool arg_is_export); @@ -50,14 +63,14 @@ public: std::string ModuleName() const; - void SetType(zeek::IntrusivePtr t); + void SetType(TypePtr t); [[deprecated("Remove in v4.1. Use GetType().")]] zeek::Type* Type() { return type.get(); } [[deprecated("Remove in v4.1. Use GetType().")]] const zeek::Type* Type() const { return type.get(); } - const zeek::IntrusivePtr& GetType() const + const TypePtr& GetType() const { return type; } template @@ -74,10 +87,10 @@ public: void MakeType() { is_type = true; } - void SetVal(zeek::IntrusivePtr v); + void SetVal(ValPtr v); - void SetVal(zeek::IntrusivePtr v, InitClass c); - void SetVal(zeek::IntrusivePtr ev, InitClass c); + void SetVal(ValPtr v, InitClass c); + void SetVal(ExprPtr ev, InitClass c); bool HasVal() const { return val != nullptr; } @@ -86,7 +99,7 @@ public: [[deprecated("Remove in v4.1. Use GetVal().")]] const Val* ID_Val() const { return val.get(); } - const zeek::IntrusivePtr& GetVal() const + const ValPtr& GetVal() const { return val; } void ClearVal(); @@ -105,22 +118,22 @@ public: bool IsRedefinable() const; - void SetAttrs(zeek::IntrusivePtr attr); - void AddAttrs(zeek::IntrusivePtr attr); - void RemoveAttr(zeek::detail::AttrTag a); + void SetAttrs(AttributesPtr attr); + void AddAttrs(AttributesPtr attr); + void RemoveAttr(AttrTag a); void UpdateValAttrs(); - const zeek::IntrusivePtr& GetAttrs() const + const AttributesPtr& GetAttrs() const { return attrs; } [[deprecated("Remove in 4.1. Use GetAttrs().")]] Attributes* Attrs() const { return attrs.get(); } - const zeek::IntrusivePtr& GetAttr(zeek::detail::AttrTag t) const; + const AttrPtr& GetAttr(zeek::detail::AttrTag t) const; bool IsDeprecated() const; - void MakeDeprecated(zeek::IntrusivePtr deprecation); + void MakeDeprecated(ExprPtr deprecation); std::string GetDeprecationWarning() const; @@ -143,11 +156,11 @@ public: bool HasOptionHandlers() const { return !option_handlers.empty(); } - void AddOptionHandler(zeek::IntrusivePtr callback, int priority); + void AddOptionHandler(FuncPtr callback, int priority); std::vector GetOptionHandlers() const; protected: - void EvalFunc(zeek::IntrusivePtr ef, zeek::IntrusivePtr ev); + void EvalFunc(ExprPtr ef, ExprPtr ev); #ifdef DEBUG void UpdateValID(); @@ -157,13 +170,13 @@ protected: IDScope scope; bool is_export; bool infer_return_type; - zeek::IntrusivePtr type; + TypePtr type; bool is_const, is_enum_const, is_type, is_option; int offset; - zeek::IntrusivePtr val; - zeek::IntrusivePtr attrs; + ValPtr val; + AttributesPtr attrs; // contains list of functions that are called when an option changes - std::multimap> option_handlers; + std::multimap option_handlers; }; @@ -179,7 +192,7 @@ namespace zeek::id { * @return The identifier, which may reference a nil object if no such * name exists. */ -const zeek::IntrusivePtr& find(std::string_view name); +const detail::IDPtr& find(std::string_view name); /** * Lookup an ID by its name and return its type. A fatal occurs if the ID @@ -187,7 +200,7 @@ const zeek::IntrusivePtr& find(std::string_view name); * @param name The identifier name to lookup * @return The type of the identifier. */ -const zeek::IntrusivePtr& find_type(std::string_view name); +const TypePtr& find_type(std::string_view name); /** * Lookup an ID by its name and return its type (as cast to @c T). @@ -205,7 +218,7 @@ zeek::IntrusivePtr find_type(std::string_view name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const zeek::IntrusivePtr& find_val(std::string_view name); +const ValPtr& find_val(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -223,7 +236,7 @@ zeek::IntrusivePtr find_val(std::string_view name) * @param name The identifier name to lookup * @return The current value of the identifier */ -const zeek::IntrusivePtr& find_const(std::string_view name); +const ValPtr& find_const(std::string_view name); /** * Lookup an ID by its name and return its value (as cast to @c T). @@ -241,19 +254,19 @@ zeek::IntrusivePtr find_const(std::string_view name) * @param name The identifier name to lookup * @return The current function value the identifier references. */ -zeek::IntrusivePtr find_func(std::string_view name); +FuncPtr find_func(std::string_view name); -extern zeek::IntrusivePtr conn_id; -extern zeek::IntrusivePtr endpoint; -extern zeek::IntrusivePtr connection; -extern zeek::IntrusivePtr fa_file; -extern zeek::IntrusivePtr fa_metadata; -extern zeek::IntrusivePtr transport_proto; -extern zeek::IntrusivePtr string_set; -extern zeek::IntrusivePtr string_array; -extern zeek::IntrusivePtr count_set; -extern zeek::IntrusivePtr string_vec; -extern zeek::IntrusivePtr index_vec; +extern RecordTypePtr conn_id; +extern RecordTypePtr endpoint; +extern RecordTypePtr connection; +extern RecordTypePtr fa_file; +extern RecordTypePtr fa_metadata; +extern EnumTypePtr transport_proto; +extern TableTypePtr string_set; +extern TableTypePtr string_array; +extern TableTypePtr count_set; +extern VectorTypePtr string_vec; +extern VectorTypePtr index_vec; namespace detail { diff --git a/src/IP.cc b/src/IP.cc index b17f1f85ac..bd0b5237ac 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,7 +13,7 @@ #include "BroString.h" #include "Reporter.h" -static zeek::IntrusivePtr BuildOptionsVal(const u_char* data, int len) +static VectorValPtr BuildOptionsVal(const u_char* data, int len) { auto vv = zeek::make_intrusive(zeek::id::find_type("ip6_options")); @@ -49,9 +49,9 @@ static zeek::IntrusivePtr BuildOptionsVal(const u_char* data, int len return vv; } -zeek::IntrusivePtr IPv6_Hdr::ToVal(zeek::IntrusivePtr chain) const +RecordValPtr IPv6_Hdr::ToVal(VectorValPtr chain) const { - zeek::IntrusivePtr rv; + RecordValPtr rv; switch ( type ) { case IPPROTO_IPV6: @@ -298,7 +298,7 @@ zeek::IntrusivePtr IPv6_Hdr::ToVal(zeek::IntrusivePtr chai return rv; } -zeek::IntrusivePtr IPv6_Hdr::ToVal() const +RecordValPtr IPv6_Hdr::ToVal() const { return ToVal(nullptr); } RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const @@ -326,9 +326,9 @@ IPAddr IP_Hdr::DstAddr() const return ip4 ? IPAddr(ip4->ip_dst) : ip6_hdrs->DstAddr(); } -zeek::IntrusivePtr IP_Hdr::ToIPHdrVal() const +RecordValPtr IP_Hdr::ToIPHdrVal() const { - zeek::IntrusivePtr rval; + RecordValPtr rval; if ( ip4 ) { @@ -356,7 +356,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const return ToIPHdrVal().release(); } -zeek::IntrusivePtr IP_Hdr::ToPktHdrVal() const +RecordValPtr IP_Hdr::ToPktHdrVal() const { static auto pkt_hdr_type = zeek::id::find_type("pkt_hdr"); return ToPktHdrVal(zeek::make_intrusive(pkt_hdr_type), 0); @@ -367,7 +367,7 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const return ToPktHdrVal().release(); } -zeek::IntrusivePtr IP_Hdr::ToPktHdrVal(zeek::IntrusivePtr pkt_hdr, int sindex) const +RecordValPtr IP_Hdr::ToPktHdrVal(RecordValPtr 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"); @@ -676,7 +676,7 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len) } #endif -zeek::IntrusivePtr IPv6_Hdr_Chain::ToVal() const +VectorValPtr 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"); diff --git a/src/IP.h b/src/IP.h index ffd9c8bbb9..639994013a 100644 --- a/src/IP.h +++ b/src/IP.h @@ -20,6 +20,9 @@ class IPAddr; class RecordVal; class VectorVal; +using RecordValPtr = zeek::IntrusivePtr; +using VectorValPtr = zeek::IntrusivePtr; + #ifdef ENABLE_MOBILE_IPV6 #ifndef IPPROTO_MOBILITY @@ -136,8 +139,8 @@ public: /** * Returns the script-layer record representation of the header. */ - zeek::IntrusivePtr ToVal(zeek::IntrusivePtr chain) const; - zeek::IntrusivePtr ToVal() const; + RecordValPtr ToVal(VectorValPtr chain) const; + RecordValPtr ToVal() const; [[deprecated("Remove in v4.1. Use ToVal() instead.")]] RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const; @@ -229,7 +232,7 @@ public: * Returns a vector of ip6_ext_hdr RecordVals that includes script-layer * representation of all extension headers in the chain. */ - zeek::IntrusivePtr ToVal() const; + VectorValPtr ToVal() const; [[deprecated("Remove in v4.1. Use ToVal() instead.")]] VectorVal* BuildVal() const; @@ -526,7 +529,7 @@ public: /** * Returns an ip_hdr or ip6_hdr_chain RecordVal. */ - zeek::IntrusivePtr ToIPHdrVal() const; + RecordValPtr ToIPHdrVal() const; [[deprecated("Remove in v4.1. Use ToIPHdrVal() instead.")]] RecordVal* BuildIPHdrVal() const; @@ -535,7 +538,7 @@ public: * Returns a pkt_hdr RecordVal, which includes not only the IP header, but * also upper-layer (tcp/udp/icmp) headers. */ - zeek::IntrusivePtr ToPktHdrVal() const; + RecordValPtr ToPktHdrVal() const; [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] RecordVal* BuildPktHdrVal() const; @@ -544,7 +547,7 @@ public: * Same as above, but simply add our values into the record at the * specified starting index. */ - zeek::IntrusivePtr ToPktHdrVal(zeek::IntrusivePtr pkt_hdr, int sindex) const; + RecordValPtr ToPktHdrVal(RecordValPtr pkt_hdr, int sindex) const; [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const; diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index caeb486aca..1ce842cbed 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -40,7 +40,7 @@ OpaqueMgr* OpaqueMgr::mgr() OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({zeek::NewRef{}, t}) {} -OpaqueVal::OpaqueVal(zeek::IntrusivePtr t) : Val(std::move(t)) +OpaqueVal::OpaqueVal(zeek::OpaqueTypePtr t) : Val(std::move(t)) {} OpaqueVal::~OpaqueVal() @@ -58,7 +58,7 @@ const std::string& OpaqueMgr::TypeID(const OpaqueVal* v) const return x->first; } -zeek::IntrusivePtr OpaqueMgr::Instantiate(const std::string& id) const +OpaqueValPtr OpaqueMgr::Instantiate(const std::string& id) const { auto x = _types.find(id); return x != _types.end() ? (*x->second)() : nullptr; @@ -75,7 +75,7 @@ broker::expected OpaqueVal::Serialize() const return {broker::vector{std::move(type), std::move(*d)}}; } -zeek::IntrusivePtr OpaqueVal::Unserialize(const broker::data& data) +OpaqueValPtr OpaqueVal::Unserialize(const broker::data& data) { auto v = caf::get_if(&data); @@ -96,7 +96,7 @@ zeek::IntrusivePtr OpaqueVal::Unserialize(const broker::data& data) return val; } -broker::expected OpaqueVal::SerializeType(const zeek::IntrusivePtr& t) +broker::expected OpaqueVal::SerializeType(const zeek::TypePtr& t) { if ( t->InternalType() == zeek::TYPE_INTERNAL_ERROR ) return broker::ec::invalid_data; @@ -112,7 +112,7 @@ broker::expected OpaqueVal::SerializeType(const zeek::IntrusivePtr return {broker::vector{false, static_cast(t->Tag())}}; } -zeek::IntrusivePtr OpaqueVal::UnserializeType(const broker::data& data) +zeek::TypePtr OpaqueVal::UnserializeType(const broker::data& data) { auto v = caf::get_if(&data); if ( ! (v && v->size() == 2) ) @@ -145,7 +145,7 @@ zeek::IntrusivePtr OpaqueVal::UnserializeType(const broker::data& da return zeek::base_type(static_cast(*tag)); } -zeek::IntrusivePtr OpaqueVal::DoClone(CloneState* state) +ValPtr OpaqueVal::DoClone(CloneState* state) { auto d = OpaqueVal::Serialize(); if ( ! d ) @@ -169,7 +169,7 @@ bool HashVal::Init() return valid; } -zeek::IntrusivePtr HashVal::Get() +StringValPtr HashVal::Get() { if ( ! valid ) return val_mgr->EmptyString(); @@ -200,13 +200,13 @@ bool HashVal::DoFeed(const void*, size_t) return false; } -zeek::IntrusivePtr HashVal::DoGet() +StringValPtr HashVal::DoGet() { assert(! "missing implementation of DoGet()"); return val_mgr->EmptyString(); } -HashVal::HashVal(zeek::IntrusivePtr t) : OpaqueVal(std::move(t)) +HashVal::HashVal(zeek::OpaqueTypePtr t) : OpaqueVal(std::move(t)) { valid = false; } @@ -239,12 +239,12 @@ void HashVal::digest_one(EVP_MD_CTX* h, const Val* v) } } -void HashVal::digest_one(EVP_MD_CTX* h, const zeek::IntrusivePtr& v) +void HashVal::digest_one(EVP_MD_CTX* h, const ValPtr& v) { digest_one(h, v.get()); } -zeek::IntrusivePtr MD5Val::DoClone(CloneState* state) +ValPtr MD5Val::DoClone(CloneState* state) { auto out = zeek::make_intrusive(); @@ -275,7 +275,7 @@ bool MD5Val::DoFeed(const void* data, size_t size) return true; } -zeek::IntrusivePtr MD5Val::DoGet() +StringValPtr MD5Val::DoGet() { if ( ! IsValid() ) return val_mgr->EmptyString(); @@ -364,7 +364,7 @@ SHA1Val::~SHA1Val() EVP_MD_CTX_free(ctx); } -zeek::IntrusivePtr SHA1Val::DoClone(CloneState* state) +ValPtr SHA1Val::DoClone(CloneState* state) { auto out = zeek::make_intrusive(); @@ -395,7 +395,7 @@ bool SHA1Val::DoFeed(const void* data, size_t size) return true; } -zeek::IntrusivePtr SHA1Val::DoGet() +StringValPtr SHA1Val::DoGet() { if ( ! IsValid() ) return val_mgr->EmptyString(); @@ -487,7 +487,7 @@ SHA256Val::~SHA256Val() EVP_MD_CTX_free(ctx); } -zeek::IntrusivePtr SHA256Val::DoClone(CloneState* state) +ValPtr SHA256Val::DoClone(CloneState* state) { auto out = zeek::make_intrusive(); @@ -518,7 +518,7 @@ bool SHA256Val::DoFeed(const void* data, size_t size) return true; } -zeek::IntrusivePtr SHA256Val::DoGet() +StringValPtr SHA256Val::DoGet() { if ( ! IsValid() ) return val_mgr->EmptyString(); @@ -711,7 +711,7 @@ BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf) bloom_filter = bf; } -zeek::IntrusivePtr BloomFilterVal::DoClone(CloneState* state) +ValPtr BloomFilterVal::DoClone(CloneState* state) { if ( bloom_filter ) { @@ -723,7 +723,7 @@ zeek::IntrusivePtr BloomFilterVal::DoClone(CloneState* state) return state->NewClone(this, zeek::make_intrusive()); } -bool BloomFilterVal::Typify(zeek::IntrusivePtr arg_type) +bool BloomFilterVal::Typify(zeek::TypePtr arg_type) { if ( type ) return false; @@ -765,8 +765,8 @@ std::string BloomFilterVal::InternalState() const return bloom_filter->InternalState(); } -zeek::IntrusivePtr BloomFilterVal::Merge(const BloomFilterVal* x, - const BloomFilterVal* y) +BloomFilterValPtr BloomFilterVal::Merge(const BloomFilterVal* x, + const BloomFilterVal* y) { if ( x->Type() && // any one 0 is ok here y->Type() && @@ -876,13 +876,13 @@ CardinalityVal::~CardinalityVal() delete hash; } -zeek::IntrusivePtr CardinalityVal::DoClone(CloneState* state) +ValPtr CardinalityVal::DoClone(CloneState* state) { return state->NewClone(this, zeek::make_intrusive(new probabilistic::CardinalityCounter(*c))); } -bool CardinalityVal::Typify(zeek::IntrusivePtr arg_type) +bool CardinalityVal::Typify(zeek::TypePtr arg_type) { if ( type ) return false; @@ -957,7 +957,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) this->internal_paraglob = std::move(p); } -zeek::IntrusivePtr ParaglobVal::Get(StringVal* &pattern) +VectorValPtr ParaglobVal::Get(StringVal* &pattern) { auto rval = zeek::make_intrusive(zeek::id::string_vec); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); @@ -1018,7 +1018,7 @@ bool ParaglobVal::DoUnserialize(const broker::data& data) return true; } -zeek::IntrusivePtr ParaglobVal::DoClone(CloneState* state) +ValPtr ParaglobVal::DoClone(CloneState* state) { try { return zeek::make_intrusive diff --git a/src/OpaqueVal.h b/src/OpaqueVal.h index 2c9a9a912c..502769f429 100644 --- a/src/OpaqueVal.h +++ b/src/OpaqueVal.h @@ -13,7 +13,12 @@ #include // for u_char namespace broker { class data; } + class OpaqueVal; +using OpaqueValPtr = zeek::IntrusivePtr; + +class BloomFilterVal; +using BloomFilterValPtr = zeek::IntrusivePtr; /** * Singleton that registers all available all available types of opaque @@ -21,7 +26,7 @@ class OpaqueVal; */ class OpaqueMgr { public: - using Factory = zeek::IntrusivePtr (); + using Factory = OpaqueValPtr (); /** * Return's a unique ID for the type of an opaque value. @@ -45,7 +50,7 @@ public: * is unknown, this will return null. * */ - zeek::IntrusivePtr Instantiate(const std::string& id) const; + OpaqueValPtr Instantiate(const std::string& id) const; /** Returns the global manager singleton object. */ static OpaqueMgr* mgr(); @@ -72,7 +77,7 @@ private: broker::expected DoSerialize() const override; \ bool DoUnserialize(const broker::data& data) override; \ const char* OpaqueName() const override { return #T; } \ - static zeek::IntrusivePtr OpaqueInstantiate() { return zeek::make_intrusive(); } + static OpaqueValPtr OpaqueInstantiate() { return zeek::make_intrusive(); } #define __OPAQUE_MERGE(a, b) a ## b #define __OPAQUE_ID(x) __OPAQUE_MERGE(_opaque, x) @@ -89,7 +94,7 @@ class OpaqueVal : public Val { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit OpaqueVal(zeek::OpaqueType* t); - explicit OpaqueVal(zeek::IntrusivePtr t); + explicit OpaqueVal(zeek::OpaqueTypePtr t); ~OpaqueVal() override; /** @@ -106,7 +111,7 @@ public: * @param data Broker representation as returned by *Serialize()*. * @return unserialized instances with reference count at +1 */ - static zeek::IntrusivePtr Unserialize(const broker::data& data); + static OpaqueValPtr Unserialize(const broker::data& data); protected: friend class Val; @@ -142,19 +147,19 @@ protected: * may also override this with a more efficient custom clone * implementation of their own. */ - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; /** * Helper function for derived class that need to record a type * during serialization. */ - static broker::expected SerializeType(const zeek::IntrusivePtr& t); + static broker::expected SerializeType(const zeek::TypePtr& t); /** * Helper function for derived class that need to restore a type * during unserialization. Returns the type at reference count +1. */ - static zeek::IntrusivePtr UnserializeType(const broker::data& data); + static zeek::TypePtr UnserializeType(const broker::data& data); }; namespace probabilistic { @@ -178,21 +183,21 @@ public: bool IsValid() const; bool Init(); bool Feed(const void* data, size_t size); - zeek::IntrusivePtr Get(); + StringValPtr Get(); protected: static void digest_one(EVP_MD_CTX* h, const Val* v); - static void digest_one(EVP_MD_CTX* h, const zeek::IntrusivePtr& v); + static void digest_one(EVP_MD_CTX* h, const ValPtr& v); HashVal() { valid = false; } [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit HashVal(zeek::OpaqueType* t); - explicit HashVal(zeek::IntrusivePtr t); + explicit HashVal(zeek::OpaqueTypePtr t); virtual bool DoInit(); virtual bool DoFeed(const void* data, size_t size); - virtual zeek::IntrusivePtr DoGet(); + virtual StringValPtr DoGet(); private: // This flag exists because Get() can only be called once. @@ -221,14 +226,14 @@ public: MD5Val(); ~MD5Val(); - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; protected: friend class Val; bool DoInit() override; bool DoFeed(const void* data, size_t size) override; - zeek::IntrusivePtr DoGet() override; + StringValPtr DoGet() override; DECLARE_OPAQUE_VALUE(MD5Val) private: @@ -244,14 +249,14 @@ public: SHA1Val(); ~SHA1Val(); - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; protected: friend class Val; bool DoInit() override; bool DoFeed(const void* data, size_t size) override; - zeek::IntrusivePtr DoGet() override; + StringValPtr DoGet() override; DECLARE_OPAQUE_VALUE(SHA1Val) private: @@ -267,14 +272,14 @@ public: SHA256Val(); ~SHA256Val(); - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; protected: friend class Val; bool DoInit() override; bool DoFeed(const void* data, size_t size) override; - zeek::IntrusivePtr DoGet() override; + StringValPtr DoGet() override; DECLARE_OPAQUE_VALUE(SHA256Val) private: @@ -302,12 +307,12 @@ public: explicit BloomFilterVal(probabilistic::BloomFilter* bf); ~BloomFilterVal() override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; - const zeek::IntrusivePtr& Type() const + const zeek::TypePtr& Type() const { return type; } - bool Typify(zeek::IntrusivePtr type); + bool Typify(zeek::TypePtr type); void Add(const Val* val); size_t Count(const Val* val) const; @@ -315,8 +320,8 @@ public: bool Empty() const; std::string InternalState() const; - static zeek::IntrusivePtr Merge(const BloomFilterVal* x, - const BloomFilterVal* y); + static BloomFilterValPtr Merge(const BloomFilterVal* x, + const BloomFilterVal* y); protected: friend class Val; @@ -328,7 +333,7 @@ private: BloomFilterVal(const BloomFilterVal&); BloomFilterVal& operator=(const BloomFilterVal&); - zeek::IntrusivePtr type; + zeek::TypePtr type; CompositeHash* hash; probabilistic::BloomFilter* bloom_filter; }; @@ -339,14 +344,14 @@ public: explicit CardinalityVal(probabilistic::CardinalityCounter*); ~CardinalityVal() override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; void Add(const Val* val); - const zeek::IntrusivePtr& Type() const + const zeek::TypePtr& Type() const { return type; } - bool Typify(zeek::IntrusivePtr type); + bool Typify(zeek::TypePtr type); probabilistic::CardinalityCounter* Get() { return c; }; @@ -355,7 +360,7 @@ protected: DECLARE_OPAQUE_VALUE(CardinalityVal) private: - zeek::IntrusivePtr type; + zeek::TypePtr type; CompositeHash* hash; probabilistic::CardinalityCounter* c; }; @@ -363,8 +368,8 @@ private: class ParaglobVal : public OpaqueVal { public: explicit ParaglobVal(std::unique_ptr p); - zeek::IntrusivePtr Get(StringVal* &pattern); - zeek::IntrusivePtr DoClone(CloneState* state) override; + VectorValPtr Get(StringVal* &pattern); + ValPtr DoClone(CloneState* state) override; bool operator==(const ParaglobVal& other) const; protected: diff --git a/src/Reporter.cc b/src/Reporter.cc index 32f5a8f943..0cfdbb6e62 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -417,7 +417,7 @@ void Reporter::Weird(Connection* conn, const char* name, const char* addl) "%s", name); } -void Reporter::Weird(zeek::IntrusivePtr conn_id, zeek::IntrusivePtr uid, +void Reporter::Weird(RecordValPtr conn_id, StringValPtr uid, const char* name, const char* addl) { UpdateWeirdStats(name); diff --git a/src/Reporter.h b/src/Reporter.h index 7a71264464..080b96ba74 100644 --- a/src/Reporter.h +++ b/src/Reporter.h @@ -28,6 +28,9 @@ namespace zeek { template class IntrusivePtr; } +using RecordValPtr = zeek::IntrusivePtr; +using StringValPtr = zeek::IntrusivePtr; + // One cannot raise this exception directly, go through the // Reporter's methods instead. @@ -99,7 +102,7 @@ public: void Weird(const char* name, const char* addl = ""); // Raises net_weird(). void Weird(file_analysis::File* f, const char* name, const char* addl = ""); // Raises file_weird(). void Weird(Connection* conn, const char* name, const char* addl = ""); // Raises conn_weird(). - void Weird(zeek::IntrusivePtr conn_id, zeek::IntrusivePtr uid, + void Weird(RecordValPtr conn_id, StringValPtr uid, const char* name, const char* addl = ""); // Raises expired_conn_weird(). void Weird(const IPAddr& orig, const IPAddr& resp, const char* name, const char* addl = ""); // Raises flow_weird(). diff --git a/src/Scope.cc b/src/Scope.cc index c3cef0501e..2aee17b8be 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(zeek::IntrusivePtr id, - std::unique_ptr>> al) +Scope::Scope(zeek::detail::IDPtr id, + std::unique_ptr> al) : scope_id(std::move(id)), attrs(std::move(al)) { return_type = nullptr; @@ -35,7 +35,7 @@ Scope::Scope(zeek::IntrusivePtr id, } } -const zeek::IntrusivePtr& Scope::Find(std::string_view name) const +const zeek::detail::IDPtr& Scope::Find(std::string_view name) const { auto entry = local.find(name); @@ -45,7 +45,7 @@ const zeek::IntrusivePtr& Scope::Find(std::string_view name) c return zeek::detail::ID::nil; } -zeek::IntrusivePtr Scope::Remove(std::string_view name) +zeek::detail::IDPtr Scope::Remove(std::string_view name) { auto entry = local.find(name); @@ -59,12 +59,12 @@ zeek::IntrusivePtr Scope::Remove(std::string_view name) return nullptr; } -zeek::IntrusivePtr Scope::GenerateTemporary(const char* name) +zeek::detail::IDPtr Scope::GenerateTemporary(const char* name) { return zeek::make_intrusive(name, zeek::detail::SCOPE_FUNCTION, false); } -std::vector> Scope::GetInits() +std::vector Scope::GetInits() { auto rval = std::move(inits); inits = {}; @@ -119,7 +119,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const } -const zeek::IntrusivePtr& lookup_ID( +const zeek::detail::IDPtr& lookup_ID( const char* name, const char* curr_module, bool no_global, bool same_module_only, bool check_export) @@ -154,7 +154,7 @@ const zeek::IntrusivePtr& lookup_ID( return zeek::detail::ID::nil; } -zeek::IntrusivePtr install_ID( +zeek::detail::IDPtr install_ID( const char* name, const char* module_name, bool is_global, bool is_export) { @@ -191,14 +191,14 @@ void push_existing_scope(Scope* scope) scopes.push_back(scope); } -void push_scope(zeek::IntrusivePtr id, - std::unique_ptr>> attrs) +void push_scope(zeek::detail::IDPtr id, + std::unique_ptr> attrs) { top_scope = new Scope(std::move(id), std::move(attrs)); scopes.push_back(top_scope); } -zeek::IntrusivePtr pop_scope() +ScopePtr pop_scope() { if ( scopes.empty() ) reporter->InternalError("scope underflow"); diff --git a/src/Scope.h b/src/Scope.h index 86726eb172..8fb5c9bff7 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -13,18 +13,29 @@ #include "TraverseTypes.h" template class IntrusivePtr; -class ListVal; -namespace zeek { class Type; } +namespace zeek { + class Type; + using TypePtr = zeek::IntrusivePtr; +} using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); +namespace zeek::detail { + class Attr; + using AttrPtr = zeek::IntrusivePtr; + using IDPtr = zeek::IntrusivePtr; +} + +class Scope; +using ScopePtr = zeek::IntrusivePtr; + class Scope : public BroObj { public: - explicit Scope(zeek::IntrusivePtr id, - std::unique_ptr>> al); + explicit Scope(zeek::detail::IDPtr id, + std::unique_ptr> al); - const zeek::IntrusivePtr& Find(std::string_view name) const; + const zeek::detail::IDPtr& Find(std::string_view name) const; template [[deprecated("Remove in v4.1. Use Find().")]] @@ -34,34 +45,34 @@ public: template void Insert(N&& name, I&& id) { local[std::forward(name)] = std::forward(id); } - zeek::IntrusivePtr Remove(std::string_view name); + zeek::detail::IDPtr Remove(std::string_view name); [[deprecated("Remove in v4.1. Use GetID().")]] zeek::detail::ID* ScopeID() const { return scope_id.get(); } - const zeek::IntrusivePtr& GetID() const + const zeek::detail::IDPtr& 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().")]] zeek::Type* ReturnType() const { return return_type.get(); } - const zeek::IntrusivePtr& GetReturnType() const + const zeek::TypePtr& GetReturnType() const { return return_type; } size_t Length() const { return local.size(); } const auto& Vars() { return local; } - zeek::IntrusivePtr GenerateTemporary(const char* name); + zeek::detail::IDPtr 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(zeek::IntrusivePtr id) + void AddInit(zeek::detail::IDPtr id) { inits.emplace_back(std::move(id)); } void Describe(ODesc* d) const override; @@ -69,33 +80,33 @@ public: TraversalCode Traverse(TraversalCallback* cb) const; protected: - zeek::IntrusivePtr scope_id; - std::unique_ptr>> attrs; - zeek::IntrusivePtr return_type; - std::map, std::less<>> local; - std::vector> inits; + zeek::detail::IDPtr scope_id; + std::unique_ptr> attrs; + zeek::TypePtr return_type; + std::map> local; + std::vector inits; }; extern bool in_debug; // If no_global is true, don't search in the default "global" namespace. -extern const zeek::IntrusivePtr& lookup_ID( +extern const zeek::detail::IDPtr& lookup_ID( const char* name, const char* module, bool no_global = false, bool same_module_only = false, bool check_export = true); -extern zeek::IntrusivePtr install_ID( +extern zeek::detail::IDPtr install_ID( const char* name, const char* module_name, bool is_global, bool is_export); -extern void push_scope(zeek::IntrusivePtr id, - std::unique_ptr>> attrs); +extern void push_scope(zeek::detail::IDPtr id, + std::unique_ptr> attrs); extern void push_existing_scope(Scope* scope); // Returns the one popped off. -extern zeek::IntrusivePtr pop_scope(); +extern ScopePtr pop_scope(); extern Scope* current_scope(); extern Scope* global_scope(); diff --git a/src/Sessions.cc b/src/Sessions.cc index 836ec66400..f55bf4452f 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -703,7 +703,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); - zeek::IntrusivePtr pkt_hdr_val; + ValPtr pkt_hdr_val; if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 ) { diff --git a/src/Stmt.cc b/src/Stmt.cc index b4e2b81764..42fc8f4db8 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -133,7 +133,7 @@ void Stmt::AccessStats(ODesc* d) const } } -ExprListStmt::ExprListStmt(BroStmtTag t, zeek::IntrusivePtr arg_l) +ExprListStmt::ExprListStmt(BroStmtTag t, ListExprPtr arg_l) : Stmt(t), l(std::move(arg_l)) { const expr_list& e = l->Exprs(); @@ -149,7 +149,7 @@ ExprListStmt::ExprListStmt(BroStmtTag t, zeek::IntrusivePtr arg_l) ExprListStmt::~ExprListStmt() = default; -zeek::IntrusivePtr ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const { last_access = network_time; flow = FLOW_NEXT; @@ -187,7 +187,7 @@ TraversalCode ExprListStmt::Traverse(TraversalCallback* cb) const static BroFile* print_stdout = nullptr; -static zeek::IntrusivePtr lookup_enum_val(const char* module_name, const char* name) +static EnumValPtr lookup_enum_val(const char* module_name, const char* name) { const auto& id = lookup_ID(name, module_name); assert(id); @@ -201,7 +201,7 @@ static zeek::IntrusivePtr lookup_enum_val(const char* module_name, cons return et->GetVal(index); } -static void print_log(const std::vector>& vals) +static void print_log(const std::vector& vals) { static auto plval = lookup_enum_val("Log", "PRINTLOG"); static auto lpli = zeek::id::find_type("Log::PrintLogInfo"); @@ -220,8 +220,8 @@ static void print_log(const std::vector>& vals) log_mgr->Write(plval.get(), record.get()); } -zeek::IntrusivePtr PrintStmt::DoExec(std::vector> vals, - stmt_flow_type& /* flow */) const +ValPtr PrintStmt::DoExec(std::vector vals, + stmt_flow_type& /* flow */) const { RegisterAccess(); @@ -290,7 +290,7 @@ zeek::IntrusivePtr PrintStmt::DoExec(std::vector> v return nullptr; } -ExprStmt::ExprStmt(zeek::IntrusivePtr arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e)) +ExprStmt::ExprStmt(ExprPtr arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e)) { if ( e && e->IsPure() ) Warn("expression value ignored"); @@ -298,7 +298,7 @@ ExprStmt::ExprStmt(zeek::IntrusivePtr arg_e) : Stmt(STMT_EXPR), e(std::mov SetLocationInfo(e->GetLocationInfo()); } -ExprStmt::ExprStmt(BroStmtTag t, zeek::IntrusivePtr arg_e) : Stmt(t), e(std::move(arg_e)) +ExprStmt::ExprStmt(BroStmtTag t, ExprPtr arg_e) : Stmt(t), e(std::move(arg_e)) { if ( e ) SetLocationInfo(e->GetLocationInfo()); @@ -306,7 +306,7 @@ ExprStmt::ExprStmt(BroStmtTag t, zeek::IntrusivePtr arg_e) : Stmt(t), e(st ExprStmt::~ExprStmt() = default; -zeek::IntrusivePtr ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -319,7 +319,7 @@ zeek::IntrusivePtr ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const return nullptr; } -zeek::IntrusivePtr ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const +ValPtr ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const { return nullptr; } @@ -365,9 +365,9 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -IfStmt::IfStmt(zeek::IntrusivePtr test, - zeek::IntrusivePtr arg_s1, - zeek::IntrusivePtr arg_s2) +IfStmt::IfStmt(ExprPtr test, + StmtPtr arg_s1, + StmtPtr arg_s2) : ExprStmt(STMT_IF, std::move(test)), s1(std::move(arg_s1)), s2(std::move(arg_s2)) { @@ -381,7 +381,7 @@ IfStmt::IfStmt(zeek::IntrusivePtr test, IfStmt::~IfStmt() = default; -zeek::IntrusivePtr IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const +ValPtr IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const { // Treat 0 as false, but don't require 1 for true. Stmt* do_stmt = v->IsZero() ? s2.get() : s1.get(); @@ -466,8 +466,8 @@ static BroStmtTag get_last_stmt_tag(const Stmt* stmt) return get_last_stmt_tag(stmts->Stmts()[len - 1]); } -Case::Case(zeek::IntrusivePtr arg_expr_cases, id_list* arg_type_cases, - zeek::IntrusivePtr arg_s) +Case::Case(ListExprPtr arg_expr_cases, id_list* arg_type_cases, + StmtPtr arg_s) : expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases), s(std::move(arg_s)) { @@ -591,7 +591,7 @@ void SwitchStmt::Init() case_label_value_map.SetDeleteFunc(int_del_func); } -SwitchStmt::SwitchStmt(zeek::IntrusivePtr index, case_list* arg_cases) +SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases) : ExprStmt(STMT_SWITCH, std::move(index)), cases(arg_cases), default_case_idx(-1) { @@ -797,9 +797,9 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const return std::make_pair(label_idx, label_id); } -zeek::IntrusivePtr SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const +ValPtr SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const { - zeek::IntrusivePtr rval; + ValPtr rval; auto m = FindCaseLabelMatch(v); int matching_label_idx = m.first; @@ -882,7 +882,7 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -AddStmt::AddStmt(zeek::IntrusivePtr arg_e) : ExprStmt(STMT_ADD, std::move(arg_e)) +AddStmt::AddStmt(ExprPtr arg_e) : ExprStmt(STMT_ADD, std::move(arg_e)) { if ( ! e->CanAdd() ) Error("illegal add statement"); @@ -893,7 +893,7 @@ bool AddStmt::IsPure() const return false; } -zeek::IntrusivePtr AddStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr AddStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -915,7 +915,7 @@ TraversalCode AddStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -DelStmt::DelStmt(zeek::IntrusivePtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e)) +DelStmt::DelStmt(ExprPtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e)) { if ( e->IsError() ) return; @@ -929,7 +929,7 @@ bool DelStmt::IsPure() const return false; } -zeek::IntrusivePtr DelStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr DelStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -950,12 +950,12 @@ TraversalCode DelStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -EventStmt::EventStmt(zeek::IntrusivePtr arg_e) +EventStmt::EventStmt(EventExprPtr arg_e) : ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e)) { } -zeek::IntrusivePtr EventStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr EventStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); auto args = eval_list(f, event_expr->Args()); @@ -981,8 +981,8 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -WhileStmt::WhileStmt(zeek::IntrusivePtr arg_loop_condition, - zeek::IntrusivePtr arg_body) +WhileStmt::WhileStmt(ExprPtr arg_loop_condition, + StmtPtr arg_body) : loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body)) { if ( ! loop_condition->IsError() && @@ -1031,11 +1031,11 @@ TraversalCode WhileStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; - zeek::IntrusivePtr rval; + ValPtr rval; for ( ; ; ) { @@ -1060,7 +1060,7 @@ zeek::IntrusivePtr WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const return rval; } -ForStmt::ForStmt(id_list* arg_loop_vars, zeek::IntrusivePtr loop_expr) +ForStmt::ForStmt(id_list* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR, std::move(loop_expr)) { loop_vars = arg_loop_vars; @@ -1143,7 +1143,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, zeek::IntrusivePtr loop_expr) } ForStmt::ForStmt(id_list* arg_loop_vars, - zeek::IntrusivePtr loop_expr, zeek::IntrusivePtr val_var) + ExprPtr loop_expr, IDPtr val_var) : ForStmt(arg_loop_vars, std::move(loop_expr)) { value_var = std::move(val_var); @@ -1174,9 +1174,9 @@ ForStmt::~ForStmt() delete loop_vars; } -zeek::IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const +ValPtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const { - zeek::IntrusivePtr ret; + ValPtr ret; if ( v->GetType()->Tag() == TYPE_TABLE ) { @@ -1332,7 +1332,7 @@ TraversalCode ForStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const +ValPtr NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_LOOP; @@ -1359,7 +1359,7 @@ TraversalCode NextStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const +ValPtr BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_BREAK; @@ -1386,7 +1386,7 @@ TraversalCode BreakStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const +ValPtr FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_FALLTHROUGH; @@ -1413,7 +1413,7 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -ReturnStmt::ReturnStmt(zeek::IntrusivePtr arg_e) +ReturnStmt::ReturnStmt(ExprPtr arg_e) : ExprStmt(STMT_RETURN, std::move(arg_e)) { Scope* s = current_scope(); @@ -1457,7 +1457,7 @@ ReturnStmt::ReturnStmt(zeek::IntrusivePtr arg_e) } } -zeek::IntrusivePtr ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_RETURN; @@ -1496,7 +1496,7 @@ StmtList::~StmtList() Unref(stmt); } -zeek::IntrusivePtr StmtList::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr StmtList::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -1575,7 +1575,7 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -1633,7 +1633,7 @@ void EventBodyList::Describe(ODesc* d) const StmtList::Describe(d); } -InitStmt::InitStmt(std::vector> arg_inits) : Stmt(STMT_INIT) +InitStmt::InitStmt(std::vector arg_inits) : Stmt(STMT_INIT) { inits = std::move(arg_inits); @@ -1641,7 +1641,7 @@ InitStmt::InitStmt(std::vector> arg_inits) : Stmt(STMT_IN SetLocationInfo(inits[0]->GetLocationInfo()); } -zeek::IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -1650,7 +1650,7 @@ zeek::IntrusivePtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const { const auto& t = aggr->GetType(); - zeek::IntrusivePtr v; + ValPtr v; switch ( t->Tag() ) { case TYPE_RECORD: @@ -1706,7 +1706,7 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -zeek::IntrusivePtr NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const +ValPtr NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; @@ -1735,9 +1735,9 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const HANDLE_TC_STMT_POST(tc); } -WhenStmt::WhenStmt(zeek::IntrusivePtr arg_cond, - zeek::IntrusivePtr arg_s1, zeek::IntrusivePtr arg_s2, - zeek::IntrusivePtr arg_timeout, bool arg_is_return) +WhenStmt::WhenStmt(ExprPtr arg_cond, + StmtPtr arg_s1, StmtPtr arg_s2, + ExprPtr arg_timeout, bool arg_is_return) : Stmt(STMT_WHEN), cond(std::move(arg_cond)), s1(std::move(arg_s1)), s2(std::move(arg_s2)), timeout(std::move(arg_timeout)), is_return(arg_is_return) @@ -1761,7 +1761,7 @@ WhenStmt::WhenStmt(zeek::IntrusivePtr arg_cond, WhenStmt::~WhenStmt() = default; -zeek::IntrusivePtr WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const +ValPtr WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const { RegisterAccess(); flow = FLOW_NEXT; diff --git a/src/Stmt.h b/src/Stmt.h index 342674980b..b85f0ab7d2 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -23,13 +23,19 @@ class ForStmt; class EventExpr; class ListExpr; +using EventExprPtr = zeek::IntrusivePtr; +using ListExprPtr = zeek::IntrusivePtr; + +class Stmt; +using StmtPtr = zeek::IntrusivePtr; + class Stmt : public BroObj { public: BroStmtTag Tag() const { return tag; } ~Stmt() override; - virtual zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const = 0; + virtual ValPtr Exec(Frame* f, stmt_flow_type& flow) const = 0; Stmt* Ref() { ::Ref(this); return this; } @@ -93,17 +99,17 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - ExprListStmt(BroStmtTag t, zeek::IntrusivePtr arg_l); + ExprListStmt(BroStmtTag t, ListExprPtr arg_l); ~ExprListStmt() override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - virtual zeek::IntrusivePtr DoExec(std::vector> vals, - stmt_flow_type& flow) const = 0; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; + virtual ValPtr DoExec(std::vector vals, + stmt_flow_type& flow) const = 0; void Describe(ODesc* d) const override; - zeek::IntrusivePtr l; + ListExprPtr l; }; class PrintStmt final : public ExprListStmt { @@ -112,16 +118,16 @@ public: explicit PrintStmt(L&& l) : ExprListStmt(STMT_PRINT, std::forward(l)) { } protected: - zeek::IntrusivePtr DoExec(std::vector> vals, - stmt_flow_type& flow) const override; + ValPtr DoExec(std::vector vals, + stmt_flow_type& flow) const override; }; class ExprStmt : public Stmt { public: - explicit ExprStmt(zeek::IntrusivePtr e); + explicit ExprStmt(ExprPtr e); ~ExprStmt() override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; const Expr* StmtExpr() const { return e.get(); } @@ -130,18 +136,18 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - ExprStmt(BroStmtTag t, zeek::IntrusivePtr e); + ExprStmt(BroStmtTag t, ExprPtr e); - virtual zeek::IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const; + virtual ValPtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const; bool IsPure() const override; - zeek::IntrusivePtr e; + ExprPtr e; }; class IfStmt final : public ExprStmt { public: - IfStmt(zeek::IntrusivePtr test, zeek::IntrusivePtr s1, zeek::IntrusivePtr s2); + IfStmt(ExprPtr test, StmtPtr s1, StmtPtr s2); ~IfStmt() override; const Stmt* TrueBranch() const { return s1.get(); } @@ -152,16 +158,16 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; + ValPtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; bool IsPure() const override; - zeek::IntrusivePtr s1; - zeek::IntrusivePtr s2; + StmtPtr s1; + StmtPtr s2; }; class Case final : public BroObj { public: - Case(zeek::IntrusivePtr c, id_list* types, zeek::IntrusivePtr arg_s); + Case(ListExprPtr c, id_list* types, StmtPtr arg_s); ~Case() override; const ListExpr* ExprCases() const { return expr_cases.get(); } @@ -178,16 +184,16 @@ public: TraversalCode Traverse(TraversalCallback* cb) const; protected: - zeek::IntrusivePtr expr_cases; + ListExprPtr expr_cases; id_list* type_cases; - zeek::IntrusivePtr s; + StmtPtr s; }; using case_list = PList; class SwitchStmt final : public ExprStmt { public: - SwitchStmt(zeek::IntrusivePtr index, case_list* cases); + SwitchStmt(ExprPtr index, case_list* cases); ~SwitchStmt() override; const case_list* Cases() const { return cases; } @@ -197,7 +203,7 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; + ValPtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; bool IsPure() const override; // Initialize composite hash and case label map. @@ -228,40 +234,40 @@ protected: class AddStmt final : public ExprStmt { public: - explicit AddStmt(zeek::IntrusivePtr e); + explicit AddStmt(ExprPtr e); bool IsPure() const override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; TraversalCode Traverse(TraversalCallback* cb) const override; }; class DelStmt final : public ExprStmt { public: - explicit DelStmt(zeek::IntrusivePtr e); + explicit DelStmt(ExprPtr e); bool IsPure() const override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; TraversalCode Traverse(TraversalCallback* cb) const override; }; class EventStmt final : public ExprStmt { public: - explicit EventStmt(zeek::IntrusivePtr e); + explicit EventStmt(EventExprPtr e); - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr event_expr; + EventExprPtr event_expr; }; class WhileStmt final : public Stmt { public: - WhileStmt(zeek::IntrusivePtr loop_condition, zeek::IntrusivePtr body); + WhileStmt(ExprPtr loop_condition, StmtPtr body); ~WhileStmt() override; bool IsPure() const override; @@ -271,20 +277,20 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; - zeek::IntrusivePtr loop_condition; - zeek::IntrusivePtr body; + ExprPtr loop_condition; + StmtPtr body; }; class ForStmt final : public ExprStmt { public: - ForStmt(id_list* loop_vars, zeek::IntrusivePtr loop_expr); + ForStmt(id_list* loop_vars, ExprPtr loop_expr); // Special constructor for key value for loop. - ForStmt(id_list* loop_vars, zeek::IntrusivePtr loop_expr, zeek::IntrusivePtr val_var); + ForStmt(id_list* loop_vars, ExprPtr loop_expr, IDPtr val_var); ~ForStmt() override; - void AddBody(zeek::IntrusivePtr arg_body) { body = std::move(arg_body); } + void AddBody(StmtPtr arg_body) { body = std::move(arg_body); } const id_list* LoopVar() const { return loop_vars; } const Expr* LoopExpr() const { return e.get(); } @@ -297,20 +303,20 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; + ValPtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; id_list* loop_vars; - zeek::IntrusivePtr body; + StmtPtr body; // Stores the value variable being used for a key value for loop. // Always set to nullptr unless special constructor is called. - zeek::IntrusivePtr value_var; + IDPtr value_var; }; class NextStmt final : public Stmt { public: NextStmt() : Stmt(STMT_NEXT) { } - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; bool IsPure() const override; void Describe(ODesc* d) const override; @@ -324,7 +330,7 @@ class BreakStmt final : public Stmt { public: BreakStmt() : Stmt(STMT_BREAK) { } - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; bool IsPure() const override; void Describe(ODesc* d) const override; @@ -338,7 +344,7 @@ class FallthroughStmt final : public Stmt { public: FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { } - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; bool IsPure() const override; void Describe(ODesc* d) const override; @@ -350,9 +356,9 @@ protected: class ReturnStmt final : public ExprStmt { public: - explicit ReturnStmt(zeek::IntrusivePtr e); + explicit ReturnStmt(ExprPtr e); - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; void Describe(ODesc* d) const override; }; @@ -362,7 +368,7 @@ public: StmtList(); ~StmtList() override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; const stmt_list& Stmts() const { return stmts; } stmt_list& Stmts() { return stmts; } @@ -382,7 +388,7 @@ public: EventBodyList() : StmtList() { topmost = false; tag = STMT_EVENT_BODY_LIST; } - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; void Describe(ODesc* d) const override; @@ -396,11 +402,11 @@ protected: class InitStmt final : public Stmt { public: - explicit InitStmt(std::vector> arg_inits); + explicit InitStmt(std::vector arg_inits); - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; - const std::vector>& Inits() const + const std::vector& Inits() const { return inits; } void Describe(ODesc* d) const override; @@ -408,14 +414,14 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - std::vector> inits; + std::vector inits; }; class NullStmt final : public Stmt { public: NullStmt() : Stmt(STMT_NULL) { } - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; bool IsPure() const override; void Describe(ODesc* d) const override; @@ -426,12 +432,12 @@ public: class WhenStmt final : public Stmt { public: // s2 is null if no timeout block given. - WhenStmt(zeek::IntrusivePtr cond, - zeek::IntrusivePtr s1, zeek::IntrusivePtr s2, - zeek::IntrusivePtr timeout, bool is_return); + WhenStmt(ExprPtr cond, + StmtPtr s1, StmtPtr s2, + ExprPtr timeout, bool is_return); ~WhenStmt() override; - zeek::IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; + ValPtr Exec(Frame* f, stmt_flow_type& flow) const override; bool IsPure() const override; const Expr* Cond() const { return cond.get(); } @@ -444,10 +450,10 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - zeek::IntrusivePtr cond; - zeek::IntrusivePtr s1; - zeek::IntrusivePtr s2; - zeek::IntrusivePtr timeout; + ExprPtr cond; + StmtPtr s1; + StmtPtr s2; + ExprPtr timeout; bool is_return; }; diff --git a/src/Tag.cc b/src/Tag.cc index 604bca933f..aa3d977831 100644 --- a/src/Tag.cc +++ b/src/Tag.cc @@ -2,9 +2,8 @@ #include "Tag.h" #include "Val.h" -#include "IntrusivePtr.h" -Tag::Tag(const zeek::IntrusivePtr& etype, type_t arg_type, subtype_t arg_subtype) +Tag::Tag(const zeek::EnumTypePtr& etype, type_t arg_type, subtype_t arg_subtype) { assert(arg_type > 0); @@ -18,7 +17,7 @@ Tag::Tag(zeek::EnumType* etype, type_t arg_type, subtype_t arg_subtype) : Tag({zeek::NewRef{}, etype}, arg_type, arg_subtype) { } -Tag::Tag(zeek::IntrusivePtr arg_val) +Tag::Tag(EnumValPtr arg_val) { assert(arg_val); @@ -73,7 +72,7 @@ Tag& Tag::operator=(const Tag&& other) noexcept return *this; } -const zeek::IntrusivePtr& Tag::AsVal(const zeek::IntrusivePtr& etype) const +const EnumValPtr& Tag::AsVal(const zeek::EnumTypePtr& etype) const { if ( ! val ) { diff --git a/src/Tag.h b/src/Tag.h index 11c2aa49cc..31064c8aaf 100644 --- a/src/Tag.h +++ b/src/Tag.h @@ -11,7 +11,12 @@ #include "util.h" class EnumVal; +using EnumValPtr = zeek::IntrusivePtr; + ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek); +namespace zeek { +using EnumTypePtr = zeek::IntrusivePtr; +} /** * Class to identify an analyzer type. @@ -116,7 +121,7 @@ protected: * * @param etype the script-layer enum type associated with the tag. */ - const zeek::IntrusivePtr& AsVal(const zeek::IntrusivePtr& etype) const; + const EnumValPtr& AsVal(const zeek::EnumTypePtr& etype) const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal(zeek::EnumType* etype) const; @@ -132,7 +137,7 @@ protected: * @param subtype The sub type, which is left to an analyzer for * interpretation. By default it's set to zero. */ - Tag(const zeek::IntrusivePtr& etype, type_t type, subtype_t subtype = 0); + Tag(const zeek::EnumTypePtr& etype, type_t type, subtype_t subtype = 0); [[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr& instead.")]] Tag(zeek::EnumType* etype, type_t type, subtype_t subtype = 0); @@ -142,7 +147,7 @@ protected: * * @param val An enum value of script type \c Analyzer::Tag. */ - explicit Tag(zeek::IntrusivePtr val); + explicit Tag(EnumValPtr val); [[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr instead.")]] explicit Tag(EnumVal* val); @@ -150,5 +155,5 @@ protected: private: type_t type; // Main type. subtype_t subtype; // Subtype. - mutable zeek::IntrusivePtr val; // Script-layer value. + mutable EnumValPtr val; // Script-layer value. }; diff --git a/src/Trigger.cc b/src/Trigger.cc index 7f2ed3f802..a8045dda47 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -151,7 +151,7 @@ Trigger::Trigger(zeek::detail::Expr* arg_cond, zeek::detail::Stmt* arg_body, arg_frame->SetDelayed(); } - zeek::IntrusivePtr timeout_val; + ValPtr timeout_val; if ( arg_timeout ) { @@ -264,7 +264,7 @@ bool Trigger::Eval() f->SetTrigger({zeek::NewRef{}, this}); - zeek::IntrusivePtr v; + ValPtr v; try { @@ -348,8 +348,8 @@ void Trigger::Timeout() if ( timeout_stmts ) { stmt_flow_type flow; - zeek::IntrusivePtr f{zeek::AdoptRef{}, frame->Clone()}; - zeek::IntrusivePtr v; + FramePtr f{zeek::AdoptRef{}, frame->Clone()}; + ValPtr v; try { diff --git a/src/Trigger.h b/src/Trigger.h index 368238208c..cc24c3a6d5 100644 --- a/src/Trigger.h +++ b/src/Trigger.h @@ -8,6 +8,7 @@ #include "Notifier.h" #include "iosource/IOSource.h" #include "util.h" +#include "IntrusivePtr.h" class Frame; class Val; @@ -115,6 +116,8 @@ private: ValCache cache; }; +using TriggerPtr = zeek::IntrusivePtr; + class Manager final : public iosource::IOSource { public: diff --git a/src/TunnelEncapsulation.cc b/src/TunnelEncapsulation.cc index 8649308a5a..dc86ba890c 100644 --- a/src/TunnelEncapsulation.cc +++ b/src/TunnelEncapsulation.cc @@ -16,7 +16,7 @@ EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t) } } -zeek::IntrusivePtr EncapsulatingConn::ToVal() const +RecordValPtr EncapsulatingConn::ToVal() const { auto rv = zeek::make_intrusive(zeek::BifType::Record::Tunnel::EncapsulatingConn); diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 53b792832c..7375b7490d 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -6,7 +6,6 @@ #include -#include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" #include "ID.h" @@ -81,7 +80,7 @@ public: /** * Returns record value of type "EncapsulatingConn" representing the tunnel. */ - zeek::IntrusivePtr ToVal() const; + RecordValPtr ToVal() const; [[deprecated("Remove in v4.1. Use ToVal() instead.")]] RecordVal* GetRecordVal() const @@ -196,7 +195,7 @@ public: * Get the value of type "EncapsulatingConnVector" represented by the * entire encapsulation chain. */ - zeek::IntrusivePtr ToVal() const + VectorValPtr ToVal() const { auto vv = zeek::make_intrusive( zeek::id::find_type("EncapsulatingConnVector")); diff --git a/src/Type.cc b/src/Type.cc index 1385254446..0ebc558fd0 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -71,7 +71,7 @@ Type::Type(zeek::TypeTag t, bool arg_base_type) { } -zeek::IntrusivePtr Type::ShallowClone() +TypePtr Type::ShallowClone() { switch ( tag ) { case TYPE_VOID: @@ -111,7 +111,7 @@ int Type::MatchesIndex(zeek::detail::ListExpr* const index) const return DOES_NOT_MATCH_INDEX; } -const zeek::IntrusivePtr& Type::Yield() const +const TypePtr& Type::Yield() const { return Type::nil; } @@ -163,7 +163,7 @@ bool TypeList::AllMatch(const Type* t, bool is_init) const return true; } -void TypeList::Append(zeek::IntrusivePtr t) +void TypeList::Append(TypePtr t) { if ( pure_type && ! same_type(t, pure_type) ) reporter->InternalError("pure type-list violation"); @@ -172,7 +172,7 @@ void TypeList::Append(zeek::IntrusivePtr t) types.emplace_back(std::move(t)); } -void TypeList::AppendEvenIfNotPure(zeek::IntrusivePtr t) +void TypeList::AppendEvenIfNotPure(TypePtr t) { if ( pure_type && ! same_type(t, pure_type) ) pure_type = nullptr; @@ -317,7 +317,7 @@ bool IndexType::IsSubNetIndex() const return false; } -TableType::TableType(zeek::IntrusivePtr ind, zeek::IntrusivePtr yield) +TableType::TableType(TypeListPtr ind, TypePtr yield) : IndexType(TYPE_TABLE, std::move(ind), std::move(yield)) { if ( ! indices ) @@ -344,7 +344,7 @@ TableType::TableType(zeek::IntrusivePtr ind, zeek::IntrusivePtr } } -zeek::IntrusivePtr TableType::ShallowClone() +TypePtr TableType::ShallowClone() { return zeek::make_intrusive(indices, yield_type); } @@ -355,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const return indices->GetTypes().empty(); } -SetType::SetType(zeek::IntrusivePtr ind, zeek::IntrusivePtr arg_elements) +SetType::SetType(TypeListPtr ind, zeek::detail::ListExprPtr arg_elements) : TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) { if ( elements ) @@ -378,7 +378,7 @@ SetType::SetType(zeek::IntrusivePtr ind, zeek::IntrusivePtr ft{zeek::NewRef{}, flatten_type(tl[0].get())}; + TypePtr ft{zeek::NewRef{}, flatten_type(tl[0].get())}; indices = zeek::make_intrusive(ft); indices->Append(std::move(ft)); } @@ -403,15 +403,15 @@ SetType::SetType(zeek::IntrusivePtr ind, zeek::IntrusivePtr SetType::ShallowClone() +TypePtr SetType::ShallowClone() { return zeek::make_intrusive(indices, elements); } SetType::~SetType() = default; -FuncType::FuncType(zeek::IntrusivePtr arg_args, - zeek::IntrusivePtr arg_yield, FunctionFlavor arg_flavor) +FuncType::FuncType(RecordTypePtr arg_args, + TypePtr arg_yield, FunctionFlavor arg_flavor) : Type(TYPE_FUNC), args(std::move(arg_args)), arg_types(zeek::make_intrusive()), yield(std::move(arg_yield)) { @@ -441,7 +441,7 @@ FuncType::FuncType(zeek::IntrusivePtr arg_args, prototypes.emplace_back(Prototype{false, args, std::move(offsets)}); } -zeek::IntrusivePtr FuncType::ShallowClone() +TypePtr FuncType::ShallowClone() { auto f = zeek::make_intrusive(); f->args = args; @@ -481,7 +481,7 @@ int FuncType::MatchesIndex(zeek::detail::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 ) @@ -490,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->GetTypes(); @@ -609,8 +609,7 @@ std::optional FuncType::FindPrototype(const RecordType& arg return {}; } -TypeDecl::TypeDecl(const char* i, zeek::IntrusivePtr t, - zeek::IntrusivePtr arg_attrs) +TypeDecl::TypeDecl(const char* i, TypePtr t, zeek::detail::AttributesPtr arg_attrs) : type(std::move(t)), attrs(std::move(arg_attrs)), id(i) @@ -658,7 +657,7 @@ RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD) // in this case the clone is actually not so shallow, since // it gets modified by everyone. -zeek::IntrusivePtr RecordType::ShallowClone() +TypePtr RecordType::ShallowClone() { auto pass = new type_decl_list(); for ( const auto& type : *types ) @@ -682,7 +681,7 @@ bool RecordType::HasField(const char* field) const return FieldOffset(field) >= 0; } -zeek::IntrusivePtr RecordType::FieldDefault(int field) const +ValPtr RecordType::FieldDefault(int field) const { const TypeDecl* td = FieldDecl(field); @@ -794,7 +793,7 @@ static string container_type_name(const Type* ft) return s; } -zeek::IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const +TableValPtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { static auto record_field = zeek::id::find_type("record_field"); static auto record_field_table = zeek::id::find_type("record_field_table"); @@ -804,7 +803,7 @@ zeek::IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) { const auto& ft = GetFieldType(i); const TypeDecl* fd = FieldDecl(i); - zeek::IntrusivePtr fv; + ValPtr fv; if ( rv ) fv = rv->GetField(i); @@ -1028,7 +1027,7 @@ void SubNetType::Describe(ODesc* d) const d->Add(int(Tag())); } -FileType::FileType(zeek::IntrusivePtr yield_type) +FileType::FileType(TypePtr yield_type) : Type(TYPE_FILE), yield(std::move(yield_type)) { } @@ -1083,7 +1082,7 @@ EnumType::EnumType(const EnumType* e) SetName(e->GetName()); } -zeek::IntrusivePtr EnumType::ShallowClone() +TypePtr EnumType::ShallowClone() { if ( counter == 0 ) return zeek::make_intrusive(GetName()); @@ -1213,7 +1212,7 @@ EnumType::enum_name_list EnumType::Names() const return n; } -const zeek::IntrusivePtr& EnumType::GetVal(bro_int_t i) +const EnumValPtr& EnumType::GetVal(bro_int_t i) { auto it = vals.find(i); @@ -1303,19 +1302,19 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const } } -VectorType::VectorType(zeek::IntrusivePtr element_type) +VectorType::VectorType(TypePtr element_type) : Type(TYPE_VECTOR), yield_type(std::move(element_type)) { } -zeek::IntrusivePtr VectorType::ShallowClone() +TypePtr VectorType::ShallowClone() { return zeek::make_intrusive(yield_type); } VectorType::~VectorType() = default; -const zeek::IntrusivePtr& VectorType::Yield() const +const TypePtr& 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 @@ -1684,8 +1683,8 @@ TypeTag max_type(TypeTag t1, TypeTag t2) } } -zeek::IntrusivePtr merge_types(const zeek::IntrusivePtr& arg_t1, - const zeek::IntrusivePtr& arg_t2) +TypePtr merge_types(const TypePtr& arg_t1, + const TypePtr& arg_t2) { auto t1 = arg_t1.get(); auto t2 = arg_t2.get(); @@ -1758,7 +1757,7 @@ zeek::IntrusivePtr merge_types(const zeek::IntrusivePtr& arg_t1, const auto& tl1 = it1->GetIndexTypes(); const auto& tl2 = it2->GetIndexTypes(); - zeek::IntrusivePtr tl3; + TypeListPtr tl3; if ( tl1.size() != tl2.size() ) { @@ -1779,7 +1778,7 @@ zeek::IntrusivePtr merge_types(const zeek::IntrusivePtr& arg_t1, const auto& y1 = t1->Yield(); const auto& y2 = t2->Yield(); - zeek::IntrusivePtr y3; + TypePtr y3; if ( y1 || y2 ) { @@ -1924,7 +1923,7 @@ zeek::IntrusivePtr merge_types(const zeek::IntrusivePtr& arg_t1, } } -zeek::IntrusivePtr merge_type_list(zeek::detail::ListExpr* elements) +TypePtr merge_type_list(zeek::detail::ListExpr* elements) { TypeList* tl_type = elements->GetType()->AsTypeList(); const auto& tl = tl_type->GetTypes(); @@ -1969,7 +1968,7 @@ static Type* reduce_type(Type* t) return t; } -zeek::IntrusivePtr init_type(zeek::detail::Expr* init) +TypePtr init_type(zeek::detail::Expr* init) { if ( init->Tag() != zeek::detail::EXPR_LIST ) { @@ -2016,7 +2015,7 @@ zeek::IntrusivePtr init_type(zeek::detail::Expr* init) for ( int i = 1; t && i < el.length(); ++i ) { auto el_t = el[i]->InitType(); - zeek::IntrusivePtr ti; + TypePtr ti; if ( el_t ) ti = {zeek::NewRef{}, reduce_type(el_t.get())}; @@ -2068,9 +2067,9 @@ bool is_atomic_type(const Type& t) } } -const zeek::IntrusivePtr& base_type(zeek::TypeTag tag) +const TypePtr& base_type(zeek::TypeTag tag) { - static zeek::IntrusivePtr base_types[NUM_TYPES]; + static TypePtr base_types[NUM_TYPES]; // We could check here that "tag" actually corresponds to a basic type. if ( ! base_types[tag] ) diff --git a/src/Type.h b/src/Type.h index 71260b6458..d6da7b9b38 100644 --- a/src/Type.h +++ b/src/Type.h @@ -18,10 +18,18 @@ class Val; class EnumVal; class TableVal; +using ValPtr = zeek::IntrusivePtr; +using EnumValPtr = zeek::IntrusivePtr; +using TableValPtr = zeek::IntrusivePtr; + ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); +namespace zeek::detail { +using ListExprPtr = zeek::IntrusivePtr; +} + namespace zeek { // BRO types. @@ -139,6 +147,20 @@ class EnumType; class VectorType; class TypeType; class OpaqueType; +class FileType; + +using TypePtr = zeek::IntrusivePtr; +using TypeListPtr = zeek::IntrusivePtr; +using TableTypePtr = zeek::IntrusivePtr; +using SetTypePtr = zeek::IntrusivePtr; +using RecordTypePtr = zeek::IntrusivePtr; +using SubNetTypePtr = zeek::IntrusivePtr; +using FuncTypePtr = zeek::IntrusivePtr; +using EnumTypePtr = zeek::IntrusivePtr; +using VectorTypePtr = zeek::IntrusivePtr; +using TypeTypePtr = zeek::IntrusivePtr; +using OpaqueTypePtr = zeek::IntrusivePtr; +using FileTypePtr = zeek::IntrusivePtr; constexpr int DOES_NOT_MATCH_INDEX = 0; constexpr int MATCHES_INDEX_SCALAR = 1; @@ -146,7 +168,7 @@ constexpr int MATCHES_INDEX_VECTOR = 2; class Type : public BroObj { public: - static inline const zeek::IntrusivePtr nil; + static inline const TypePtr nil; explicit Type(zeek::TypeTag tag, bool base_type = false); @@ -158,7 +180,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 zeek::IntrusivePtr ShallowClone(); + virtual TypePtr ShallowClone(); TypeTag Tag() const { return tag; } InternalTypeTag InternalType() const { return internal_tag; } @@ -178,7 +200,7 @@ public: // 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 zeek::IntrusivePtr& Yield() const; + virtual const TypePtr& Yield() const; [[deprecated("Remove in v4.1. Use Yield() instead.")]] virtual Type* YieldType() @@ -362,7 +384,7 @@ private: class TypeList final : public Type { public: - explicit TypeList(zeek::IntrusivePtr arg_pure_type = nullptr) + explicit TypeList(TypePtr arg_pure_type = nullptr) : Type(TYPE_LIST), pure_type(std::move(arg_pure_type)) { } @@ -373,14 +395,14 @@ public: const type_list* Types() const { return &types_list; } - const std::vector>& GetTypes() const + const std::vector& GetTypes() 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 zeek::IntrusivePtr& GetPureType() const + const TypePtr& GetPureType() const { return pure_type; } [[deprecated("Remove in v4.1. Use GetPureType() instead.")]] @@ -392,19 +414,19 @@ public: // is_init is true, then the matching is done in the context // of an initialization. bool AllMatch(const Type* t, bool is_init) const; - bool AllMatch(const zeek::IntrusivePtr& t, bool is_init) const + bool AllMatch(const TypePtr& t, bool is_init) const { return AllMatch(t.get(), is_init); } - void Append(zeek::IntrusivePtr t); - void AppendEvenIfNotPure(zeek::IntrusivePtr t); + void Append(TypePtr t); + void AppendEvenIfNotPure(TypePtr t); void Describe(ODesc* d) const override; unsigned int MemoryAllocation() const override; protected: - zeek::IntrusivePtr pure_type; - std::vector> types; + TypePtr pure_type; + std::vector types; // Remove in v4.1. This is used by Types(), which is deprecated. type_list types_list; @@ -415,7 +437,7 @@ public: int MatchesIndex(zeek::detail::ListExpr* index) const override; - const zeek::IntrusivePtr& GetIndices() const + const TypeListPtr& GetIndices() const { return indices; } [[deprecated("Remove in v4.1. Use GetIndices().")]] @@ -425,10 +447,10 @@ public: const type_list* IndexTypes() const { return indices->Types(); } - const std::vector>& GetIndexTypes() const + const std::vector& GetIndexTypes() const { return indices->GetTypes(); } - const zeek::IntrusivePtr& Yield() const override + const TypePtr& Yield() const override { return yield_type; } void Describe(ODesc* d) const override; @@ -438,8 +460,8 @@ public: bool IsSubNetIndex() const; protected: - IndexType(TypeTag t, zeek::IntrusivePtr arg_indices, - zeek::IntrusivePtr arg_yield_type) + IndexType(TypeTag t, TypeListPtr arg_indices, + TypePtr arg_yield_type) : Type(t), indices(std::move(arg_indices)), yield_type(std::move(arg_yield_type)) { @@ -447,15 +469,15 @@ protected: ~IndexType() override = default; - zeek::IntrusivePtr indices; - zeek::IntrusivePtr yield_type; + TypeListPtr indices; + TypePtr yield_type; }; class TableType : public IndexType { public: - TableType(zeek::IntrusivePtr ind, zeek::IntrusivePtr yield); + TableType(TypeListPtr ind, TypePtr yield); - zeek::IntrusivePtr ShallowClone() override; + TypePtr ShallowClone() override; // Returns true if this table type is "unspecified", which is // what one gets using an empty "set()" or "table()" constructor. @@ -464,24 +486,24 @@ public: class SetType final : public TableType { public: - SetType(zeek::IntrusivePtr ind, zeek::IntrusivePtr arg_elements); + SetType(TypeListPtr ind, zeek::detail::ListExprPtr arg_elements); ~SetType() override; - zeek::IntrusivePtr ShallowClone() override; + TypePtr ShallowClone() override; [[deprecated("Remove in v4.1. Use Elements() isntead.")]] zeek::detail::ListExpr* SetElements() const { return elements.get(); } - const zeek::IntrusivePtr& Elements() const + const zeek::detail::ListExprPtr& Elements() const { return elements; } protected: - zeek::IntrusivePtr elements; + zeek::detail::ListExprPtr elements; }; class FuncType final : public Type { public: - static inline const zeek::IntrusivePtr nil; + static inline const FuncTypePtr nil; /** * Prototype is only currently used for events and hooks which declare @@ -490,27 +512,27 @@ public: */ struct Prototype { bool deprecated; - zeek::IntrusivePtr args; + RecordTypePtr args; std::map offsets; }; - FuncType(zeek::IntrusivePtr args, zeek::IntrusivePtr yield, + FuncType(RecordTypePtr args, TypePtr yield, FunctionFlavor f); - zeek::IntrusivePtr ShallowClone() override; + TypePtr ShallowClone() override; ~FuncType() override; [[deprecated("Remove in v4.1. Use Params().")]] RecordType* Args() const { return args.get(); } - const zeek::IntrusivePtr& Params() const + const RecordTypePtr& Params() const { return args; } - const zeek::IntrusivePtr& Yield() const override + const TypePtr& Yield() const override { return yield; } - void SetYieldType(zeek::IntrusivePtr arg_yield) { yield = std::move(arg_yield); } + void SetYieldType(TypePtr arg_yield) { yield = std::move(arg_yield); } FunctionFlavor Flavor() const { return flavor; } std::string FlavorString() const; @@ -520,13 +542,13 @@ public: 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().")]] TypeList* ArgTypes() const { return arg_types.get(); } - const zeek::IntrusivePtr& ParamList() const + const TypeListPtr& ParamList() const { return arg_types; } void Describe(ODesc* d) const override; @@ -549,22 +571,22 @@ public: { return prototypes; } protected: - friend zeek::IntrusivePtr zeek::make_intrusive(); + friend FuncTypePtr zeek::make_intrusive(); FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } - zeek::IntrusivePtr args; - zeek::IntrusivePtr arg_types; - zeek::IntrusivePtr yield; + RecordTypePtr args; + TypeListPtr arg_types; + TypePtr yield; FunctionFlavor flavor; std::vector prototypes; }; class TypeType final : public Type { public: - explicit TypeType(zeek::IntrusivePtr t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {} - zeek::IntrusivePtr ShallowClone() override { return zeek::make_intrusive(type); } + explicit TypeType(TypePtr t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {} + TypePtr ShallowClone() override { return zeek::make_intrusive(type); } - const zeek::IntrusivePtr& GetType() const + const TypePtr& GetType() const { return type; } template @@ -577,24 +599,23 @@ public: const zeek::Type* Type() const { return type.get(); } protected: - zeek::IntrusivePtr type; + TypePtr type; }; class TypeDecl final { public: TypeDecl() = default; - TypeDecl(const char* i, zeek::IntrusivePtr t, - zeek::IntrusivePtr attrs = nullptr); + TypeDecl(const char* i, TypePtr t, zeek::detail::AttributesPtr attrs = nullptr); TypeDecl(const TypeDecl& other); ~TypeDecl(); - const zeek::IntrusivePtr& GetAttr(zeek::detail::AttrTag a) const + const zeek::detail::AttrPtr& GetAttr(zeek::detail::AttrTag a) const { return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; } void DescribeReST(ODesc* d, bool roles_only = false) const; - zeek::IntrusivePtr type; - zeek::IntrusivePtr attrs; + TypePtr type; + zeek::detail::AttributesPtr attrs; const char* id = nullptr; }; @@ -603,7 +624,7 @@ using type_decl_list = PList; class RecordType final : public Type { public: explicit RecordType(type_decl_list* types); - zeek::IntrusivePtr ShallowClone() override; + TypePtr ShallowClone() override; ~RecordType() override; @@ -624,7 +645,7 @@ public: * Looks up a field by name and returns its type. No check for invalid * field name is performed. */ - const zeek::IntrusivePtr& GetFieldType(const char* field_name) const + const TypePtr& GetFieldType(const char* field_name) const { return GetFieldType(FieldOffset(field_name)); } /** @@ -639,7 +660,7 @@ public: * Looks up a field by its index and returns its type. No check for * invalid field offset is performed. */ - const zeek::IntrusivePtr& GetFieldType(int field_index) const + const TypePtr& GetFieldType(int field_index) const { return (*types)[field_index]->type; } /** @@ -650,7 +671,7 @@ public: zeek::IntrusivePtr GetFieldType(int field_index) const { return zeek::cast_intrusive((*types)[field_index]->type); } - zeek::IntrusivePtr FieldDefault(int field) const; + ValPtr FieldDefault(int field) const; // A field's offset is its position in the type_decl_list, // starting at 0. Returns negative if the field doesn't exist. @@ -672,7 +693,7 @@ public: * @param rv an optional record value, if given the values of * all fields will be provided in the returned table. */ - zeek::IntrusivePtr GetRecordFieldsVal(const RecordVal* rv = nullptr) const; + TableValPtr GetRecordFieldsVal(const RecordVal* rv = nullptr) const; // Returns null if all is ok, otherwise a pointer to an error message. const char* AddFields(const type_decl_list& types, @@ -712,23 +733,23 @@ public: class FileType final : public Type { public: - explicit FileType(zeek::IntrusivePtr yield_type); - zeek::IntrusivePtr ShallowClone() override { return zeek::make_intrusive(yield); } + explicit FileType(TypePtr yield_type); + TypePtr ShallowClone() override { return zeek::make_intrusive(yield); } ~FileType() override; - const zeek::IntrusivePtr& Yield() const override + const TypePtr& Yield() const override { return yield; } void Describe(ODesc* d) const override; protected: - zeek::IntrusivePtr yield; + TypePtr yield; }; class OpaqueType final : public Type { public: explicit OpaqueType(const std::string& name); - zeek::IntrusivePtr ShallowClone() override { return zeek::make_intrusive(name); } + TypePtr ShallowClone() override { return zeek::make_intrusive(name); } ~OpaqueType() override { }; const std::string& Name() const { return name; } @@ -748,7 +769,7 @@ public: explicit EnumType(const EnumType* e); explicit EnumType(const std::string& arg_name); - zeek::IntrusivePtr ShallowClone() override; + TypePtr ShallowClone() override; ~EnumType() override; // The value of this name is next internal counter value, starting @@ -770,7 +791,7 @@ public: void DescribeReST(ODesc* d, bool roles_only = false) const override; - const zeek::IntrusivePtr& GetVal(bro_int_t i); + const EnumValPtr& GetVal(bro_int_t i); protected: void AddNameInternal(const std::string& module_name, @@ -783,7 +804,7 @@ protected: typedef std::map NameMap; NameMap names; - using ValMap = std::unordered_map>; + using ValMap = std::unordered_map; ValMap vals; // The counter is initialized to 0 and incremented on every implicit @@ -797,11 +818,11 @@ protected: class VectorType final : public Type { public: - explicit VectorType(zeek::IntrusivePtr t); - zeek::IntrusivePtr ShallowClone() override; + explicit VectorType(TypePtr t); + TypePtr ShallowClone() override; ~VectorType() override; - const zeek::IntrusivePtr& Yield() const override; + const TypePtr& Yield() const override; int MatchesIndex(zeek::detail::ListExpr* index) const override; @@ -813,7 +834,7 @@ public: void DescribeReST(ODesc* d, bool roles_only = false) const override; protected: - zeek::IntrusivePtr yield_type; + TypePtr yield_type; }; // True if the two types are equivalent. If is_init is true then the test is @@ -821,16 +842,16 @@ protected: // true then for record types the field names have to match, too. 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 zeek::IntrusivePtr& t1, const zeek::IntrusivePtr& t2, +inline bool same_type(const TypePtr& t1, const TypePtr& 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 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 zeek::IntrusivePtr& t1, const Type* t2, +inline bool same_type(const TypePtr& 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 Type* t1, const zeek::IntrusivePtr& t2, +inline bool same_type(const Type* t1, const TypePtr& t2, bool is_init=false, bool match_record_field_names=true) { return same_type(*t1, *t2, is_init, match_record_field_names); } @@ -853,22 +874,21 @@ 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. -zeek::IntrusivePtr merge_types(const zeek::IntrusivePtr& t1, - const zeek::IntrusivePtr& t2); +TypePtr merge_types(const TypePtr& t1, const TypePtr& 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. -zeek::IntrusivePtr merge_type_list(zeek::detail::ListExpr* elements); +TypePtr merge_type_list(zeek::detail::ListExpr* elements); // Given an expression, infer its type when used for an initialization. -zeek::IntrusivePtr init_type(zeek::detail::Expr* init); +TypePtr init_type(zeek::detail::Expr* init); // Returns true if argument is an atomic type. 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 zeek::IntrusivePtr& t) +inline bool is_atomic_type(const TypePtr& t) { return is_atomic_type(*t); } // True if the given type tag corresponds to type that can be assigned to. @@ -925,10 +945,10 @@ inline bool BothString(TypeTag t1, TypeTag t2) { return (IsString(t1) && IsStrin inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); } // Returns the basic (non-parameterized) type with the given type. -const zeek::IntrusivePtr& base_type(zeek::TypeTag tag); +const TypePtr& base_type(zeek::TypeTag tag); // Returns the basic error type. -inline const zeek::IntrusivePtr& error_type() { return base_type(TYPE_ERROR); } +inline const TypePtr& error_type() { return base_type(TYPE_ERROR); } } // namespace zeek @@ -938,16 +958,16 @@ inline const zeek::IntrusivePtr& error_type() { return base_type(TYP inline zeek::Type* base_type_no_ref(zeek::TypeTag tag) { return zeek::base_type(tag).get(); } -extern zeek::IntrusivePtr md5_type; -extern zeek::IntrusivePtr sha1_type; -extern zeek::IntrusivePtr sha256_type; -extern zeek::IntrusivePtr entropy_type; -extern zeek::IntrusivePtr cardinality_type; -extern zeek::IntrusivePtr topk_type; -extern zeek::IntrusivePtr bloomfilter_type; -extern zeek::IntrusivePtr x509_opaque_type; -extern zeek::IntrusivePtr ocsp_resp_opaque_type; -extern zeek::IntrusivePtr paraglob_type; +extern zeek::OpaqueTypePtr md5_type; +extern zeek::OpaqueTypePtr sha1_type; +extern zeek::OpaqueTypePtr sha256_type; +extern zeek::OpaqueTypePtr entropy_type; +extern zeek::OpaqueTypePtr cardinality_type; +extern zeek::OpaqueTypePtr topk_type; +extern zeek::OpaqueTypePtr bloomfilter_type; +extern zeek::OpaqueTypePtr x509_opaque_type; +extern zeek::OpaqueTypePtr ocsp_resp_opaque_type; +extern zeek::OpaqueTypePtr 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; diff --git a/src/Val.cc b/src/Val.cc index f64b4032e1..f30fe361b0 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -45,13 +45,13 @@ using namespace std; Val::Val(Func* f) : Val({zeek::NewRef{}, f}) {} -Val::Val(zeek::IntrusivePtr f) +Val::Val(FuncPtr f) : val(f.release()), type(val.func_val->GetType()) {} -static const zeek::IntrusivePtr& GetStringFileType() noexcept +static const zeek::FileTypePtr& GetStringFileType() noexcept { - static zeek::IntrusivePtr string_file_type + static auto string_file_type = zeek::make_intrusive(zeek::base_type(zeek::TYPE_STRING)); return string_file_type; @@ -60,7 +60,7 @@ static const zeek::IntrusivePtr& GetStringFileType() noexcept Val::Val(BroFile* f) : Val({zeek::AdoptRef{}, f}) {} -Val::Val(zeek::IntrusivePtr f) +Val::Val(BroFilePtr f) : val(f.release()), type(GetStringFileType()) { assert(val.file_val->GetType()->Tag() == zeek::TYPE_STRING); @@ -82,19 +82,19 @@ Val::~Val() #endif } -zeek::IntrusivePtr Val::CloneState::NewClone(Val* src, zeek::IntrusivePtr dst) +ValPtr Val::CloneState::NewClone(Val* src, ValPtr dst) { clones.insert(std::make_pair(src, dst.get())); return dst; } -zeek::IntrusivePtr Val::Clone() +ValPtr Val::Clone() { Val::CloneState state; return Clone(&state); } -zeek::IntrusivePtr Val::Clone(CloneState* state) +ValPtr Val::Clone(CloneState* state) { auto i = state->clones.find(this); @@ -109,7 +109,7 @@ zeek::IntrusivePtr Val::Clone(CloneState* state) return c; } -zeek::IntrusivePtr Val::DoClone(CloneState* state) +ValPtr Val::DoClone(CloneState* state) { switch ( type->InternalType() ) { case zeek::TYPE_INTERNAL_INT: @@ -153,7 +153,7 @@ zeek::IntrusivePtr Val::DoClone(CloneState* state) return nullptr; } -zeek::IntrusivePtr Val::AsFuncPtr() const +FuncPtr Val::AsFuncPtr() const { CHECK_TAG(type->Tag(), zeek::TYPE_FUNC, "Val::Func", zeek::type_name) return {zeek::NewRef{}, val.func_val}; @@ -256,7 +256,7 @@ double Val::CoerceToDouble() const return 0.0; } -zeek::IntrusivePtr Val::SizeVal() const +ValPtr Val::SizeVal() const { switch ( type->InternalType() ) { case zeek::TYPE_INTERNAL_INT: @@ -419,7 +419,7 @@ bool Val::WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, return false; } -zeek::IntrusivePtr Val::GetRecordFields() +TableValPtr Val::GetRecordFields() { static auto record_field_table = zeek::id::find_type("record_field_table"); auto t = GetType().get(); @@ -656,7 +656,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* } } -zeek::IntrusivePtr Val::ToJSON(bool only_loggable, RE_Matcher* re) +StringValPtr Val::ToJSON(bool only_loggable, RE_Matcher* re) { rapidjson::StringBuffer buffer; threading::formatter::JSON::NullDoubleWriter writer(buffer); @@ -739,7 +739,7 @@ void IntervalVal::ValDescribe(ODesc* d) const } } -zeek::IntrusivePtr PortVal::SizeVal() const +ValPtr PortVal::SizeVal() const { return val_mgr->Int(val.uint_val); } @@ -820,7 +820,7 @@ void PortVal::ValDescribe(ODesc* d) const d->Add(Protocol()); } -zeek::IntrusivePtr PortVal::DoClone(CloneState* state) +ValPtr PortVal::DoClone(CloneState* state) { // Immutable. return {zeek::NewRef{}, this}; @@ -857,7 +857,7 @@ unsigned int AddrVal::MemoryAllocation() const return padded_sizeof(*this) + val.addr_val->MemoryAllocation(); } -zeek::IntrusivePtr AddrVal::SizeVal() const +ValPtr AddrVal::SizeVal() const { if ( val.addr_val->GetFamily() == IPv4 ) return val_mgr->Count(32); @@ -865,7 +865,7 @@ zeek::IntrusivePtr AddrVal::SizeVal() const return val_mgr->Count(128); } -zeek::IntrusivePtr AddrVal::DoClone(CloneState* state) +ValPtr AddrVal::DoClone(CloneState* state) { // Immutable. return {zeek::NewRef{}, this}; @@ -917,7 +917,7 @@ unsigned int SubNetVal::MemoryAllocation() const return padded_sizeof(*this) + val.subnet_val->MemoryAllocation(); } -zeek::IntrusivePtr SubNetVal::SizeVal() const +ValPtr SubNetVal::SizeVal() const { int retained = 128 - val.subnet_val->LengthIPv6(); return zeek::make_intrusive(pow(2.0, double(retained))); @@ -962,7 +962,7 @@ bool SubNetVal::Contains(const IPAddr& addr) const return val.subnet_val->Contains(addr); } -zeek::IntrusivePtr SubNetVal::DoClone(CloneState* state) +ValPtr SubNetVal::DoClone(CloneState* state) { // Immutable. return {zeek::NewRef{}, this}; @@ -986,7 +986,7 @@ StringVal::StringVal(const string& s) : StringVal(s.length(), s.data()) { } -zeek::IntrusivePtr StringVal::SizeVal() const +ValPtr StringVal::SizeVal() const { return val_mgr->Count(val.string_val->Len()); } @@ -1033,7 +1033,7 @@ unsigned int StringVal::MemoryAllocation() const return padded_sizeof(*this) + val.string_val->MemoryAllocation(); } -zeek::IntrusivePtr StringVal::Replace( +StringValPtr StringVal::Replace( RE_Matcher* re, const BroString& repl, bool do_all) { const u_char* s = Bytes(); @@ -1118,7 +1118,7 @@ zeek::IntrusivePtr StringVal::Replace( return zeek::make_intrusive(new BroString(true, result, r - result)); } -zeek::IntrusivePtr StringVal::DoClone(CloneState* state) +ValPtr StringVal::DoClone(CloneState* state) { // We could likely treat this type as immutable and return a reference // instead of creating a new copy, but we first need to be careful and @@ -1176,7 +1176,7 @@ unsigned int PatternVal::MemoryAllocation() const return padded_sizeof(*this) + val.re_val->MemoryAllocation(); } -zeek::IntrusivePtr PatternVal::DoClone(CloneState* state) +ValPtr PatternVal::DoClone(CloneState* state) { // We could likely treat this type as immutable and return a reference // instead of creating a new copy, but we first need to be careful and @@ -1197,7 +1197,7 @@ ListVal::~ListVal() { } -zeek::IntrusivePtr ListVal::SizeVal() const +ValPtr ListVal::SizeVal() const { return val_mgr->Count(vals.size()); } @@ -1217,7 +1217,7 @@ RE_Matcher* ListVal::BuildRE() const return re; } -void ListVal::Append(zeek::IntrusivePtr v) +void ListVal::Append(ValPtr v) { if ( type->AsTypeList()->IsPure() ) { @@ -1235,7 +1235,7 @@ void ListVal::Append(Val* v) Append({zeek::AdoptRef{}, v}); } -zeek::IntrusivePtr ListVal::ToSetVal() const +TableValPtr ListVal::ToSetVal() const { if ( tag == zeek::TYPE_ANY ) Internal("conversion of heterogeneous list to set"); @@ -1282,7 +1282,7 @@ void ListVal::Describe(ODesc* d) const } } -zeek::IntrusivePtr ListVal::DoClone(CloneState* state) +ValPtr ListVal::DoClone(CloneState* state) { auto lv = zeek::make_intrusive(tag); lv->vals.reserve(vals.size()); @@ -1336,7 +1336,7 @@ static void table_entry_val_delete_func(void* val) delete tv; } -static void find_nested_record_types(const zeek::IntrusivePtr& t, std::set* found) +static void find_nested_record_types(const zeek::TypePtr& t, std::set* found) { if ( ! t ) return; @@ -1376,7 +1376,7 @@ static void find_nested_record_types(const zeek::IntrusivePtr& t, st } } -TableVal::TableVal(zeek::IntrusivePtr t, zeek::IntrusivePtr a) : Val(t) +TableVal::TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr a) : Val(t) { Init(std::move(t)); SetAttrs(std::move(a)); @@ -1396,7 +1396,7 @@ TableVal::TableVal(zeek::IntrusivePtr t, zeek::IntrusivePtr t) +void TableVal::Init(zeek::TableTypePtr t) { table_type = std::move(t); expire_func = nullptr; @@ -1459,7 +1459,7 @@ int TableVal::RecursiveSize() const return n; } -void TableVal::SetAttrs(zeek::IntrusivePtr a) +void TableVal::SetAttrs(zeek::detail::AttributesPtr a) { attrs = std::move(a); @@ -1507,7 +1507,7 @@ void TableVal::CheckExpireAttr(zeek::detail::AttrTag at) } } -bool TableVal::Assign(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val) +bool TableVal::Assign(ValPtr index, ValPtr new_val) { auto k = MakeHashKey(*index); @@ -1525,8 +1525,8 @@ bool TableVal::Assign(Val* index, Val* new_val) return Assign({zeek::NewRef{}, index}, {zeek::AdoptRef{}, new_val}); } -bool TableVal::Assign(zeek::IntrusivePtr index, std::unique_ptr k, - zeek::IntrusivePtr new_val) +bool TableVal::Assign(ValPtr index, std::unique_ptr k, + ValPtr new_val) { bool is_set = table_type->IsSet(); @@ -1576,7 +1576,7 @@ bool TableVal::Assign(Val* index, HashKey* k, Val* new_val) return Assign({zeek::NewRef{}, index}, std::unique_ptr{k}, {zeek::AdoptRef{}, new_val}); } -zeek::IntrusivePtr TableVal::SizeVal() const +ValPtr TableVal::SizeVal() const { return val_mgr->Count(Size()); } @@ -1668,7 +1668,7 @@ bool TableVal::RemoveFrom(Val* val) const return true; } -zeek::IntrusivePtr TableVal::Intersection(const TableVal& tv) const +TableValPtr TableVal::Intersection(const TableVal& tv) const { auto result = zeek::make_intrusive(table_type); @@ -1753,7 +1753,7 @@ bool TableVal::IsSubsetOf(const TableVal& tv) const return true; } -bool TableVal::ExpandAndInit(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val) +bool TableVal::ExpandAndInit(ValPtr index, ValPtr new_val) { const auto& index_type = index->GetType(); @@ -1805,7 +1805,7 @@ bool TableVal::ExpandAndInit(zeek::IntrusivePtr index, zeek::IntrusivePtr TableVal::Default(const zeek::IntrusivePtr& index) +ValPtr TableVal::Default(const ValPtr& index) { const auto& def_attr = GetAttr(zeek::detail::ATTR_DEFAULT); @@ -1870,7 +1870,7 @@ zeek::IntrusivePtr TableVal::Default(const zeek::IntrusivePtr& index) else vl.emplace_back(index); - zeek::IntrusivePtr result; + ValPtr result; try { @@ -1889,7 +1889,7 @@ zeek::IntrusivePtr TableVal::Default(const zeek::IntrusivePtr& index) return result; } -const zeek::IntrusivePtr& TableVal::Find(const zeek::IntrusivePtr& index) +const ValPtr& TableVal::Find(const ValPtr& index) { if ( subnets ) { @@ -1934,7 +1934,7 @@ const zeek::IntrusivePtr& TableVal::Find(const zeek::IntrusivePtr& ind return Val::nil; } -zeek::IntrusivePtr TableVal::FindOrDefault(const zeek::IntrusivePtr& index) +ValPtr TableVal::FindOrDefault(const ValPtr& index) { if ( auto rval = Find(index) ) return rval; @@ -1944,9 +1944,9 @@ zeek::IntrusivePtr TableVal::FindOrDefault(const zeek::IntrusivePtr& i Val* TableVal::Lookup(Val* index, bool use_default_val) { - static zeek::IntrusivePtr last_default; + static ValPtr last_default; last_default = nullptr; - zeek::IntrusivePtr idx{zeek::NewRef{}, index}; + ValPtr idx{zeek::NewRef{}, index}; if ( const auto& rval = Find(idx) ) return rval.get(); @@ -1958,7 +1958,7 @@ Val* TableVal::Lookup(Val* index, bool use_default_val) return last_default.get(); } -zeek::IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) +VectorValPtr TableVal::LookupSubnets(const SubNetVal* search) { if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); @@ -1972,7 +1972,7 @@ zeek::IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) return result; } -zeek::IntrusivePtr TableVal::LookupSubnetValues(const SubNetVal* search) +TableValPtr TableVal::LookupSubnetValues(const SubNetVal* search) { if ( ! subnets ) reporter->InternalError("LookupSubnetValues called on wrong table type"); @@ -2024,13 +2024,13 @@ bool TableVal::UpdateTimestamp(Val* index) return true; } -zeek::IntrusivePtr TableVal::RecreateIndex(const HashKey& k) const +ListValPtr TableVal::RecreateIndex(const HashKey& k) const { return table_hash->RecoverVals(k); } void TableVal::CallChangeFunc(const Val* index, - const zeek::IntrusivePtr& old_value, + const ValPtr& old_value, OnChangeType tpe) { if ( ! change_func || ! index || in_change_func ) @@ -2092,11 +2092,11 @@ void TableVal::CallChangeFunc(const Val* index, in_change_func = false; } -zeek::IntrusivePtr TableVal::Remove(const Val& index) +ValPtr TableVal::Remove(const Val& index) { auto k = MakeHashKey(index); TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k.get()) : nullptr; - zeek::IntrusivePtr va; + ValPtr va; if ( v ) va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this}; @@ -2114,10 +2114,10 @@ zeek::IntrusivePtr TableVal::Remove(const Val& index) return va; } -zeek::IntrusivePtr TableVal::Remove(const HashKey& k) +ValPtr TableVal::Remove(const HashKey& k) { TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); - zeek::IntrusivePtr va; + ValPtr va; if ( v ) va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this}; @@ -2143,7 +2143,7 @@ zeek::IntrusivePtr TableVal::Remove(const HashKey& k) return va; } -zeek::IntrusivePtr TableVal::ToListVal(zeek::TypeTag t) const +ListValPtr TableVal::ToListVal(zeek::TypeTag t) const { auto l = zeek::make_intrusive(t); @@ -2177,7 +2177,7 @@ ListVal* TableVal::ConvertToList(zeek::TypeTag t) const return ToListVal().release(); } -zeek::IntrusivePtr TableVal::ToPureListVal() const +ListValPtr TableVal::ToPureListVal() const { const auto& tl = table_type->GetIndices()->GetTypes(); if ( tl.size() != 1 ) @@ -2194,7 +2194,7 @@ ListVal* TableVal::ConvertToPureList() const return ToPureListVal().release(); } -const zeek::IntrusivePtr& TableVal::GetAttr(zeek::detail::AttrTag t) const +const zeek::detail::AttrPtr& TableVal::GetAttr(zeek::detail::AttrTag t) const { return attrs ? attrs->Find(t) : zeek::detail::Attr::nil; } @@ -2285,12 +2285,12 @@ void TableVal::Describe(ODesc* d) const } } -bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr new_val) +bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, ValPtr new_val) { Val* ind_k_v = lv->Idx(k).get(); auto ind_k = ind_k_v->GetType()->IsSet() ? ind_k_v->AsTableVal()->ToListVal() : - zeek::IntrusivePtr{zeek::NewRef{}, ind_k_v->AsListVal()}; + ListValPtr{zeek::NewRef{}, ind_k_v->AsListVal()}; for ( int i = 0; i < ind_k->Length(); ++i ) { @@ -2314,7 +2314,7 @@ bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr return true; } -bool TableVal::CheckAndAssign(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val) +bool TableVal::CheckAndAssign(ValPtr index, ValPtr new_val) { Val* v = nullptr; if ( subnets ) @@ -2397,7 +2397,7 @@ void TableVal::DoExpire(double t) else if ( v->ExpireAccessTime() + timeout < t ) { - zeek::IntrusivePtr idx = nullptr; + ListValPtr idx = nullptr; if ( expire_func ) { @@ -2491,7 +2491,7 @@ double TableVal::GetExpireTime() return -1; } -double TableVal::CallExpireFunc(zeek::IntrusivePtr idx) +double TableVal::CallExpireFunc(ListValPtr idx) { if ( ! expire_func ) return 0; @@ -2554,7 +2554,7 @@ double TableVal::CallExpireFunc(zeek::IntrusivePtr idx) return secs; } -zeek::IntrusivePtr TableVal::DoClone(CloneState* state) +ValPtr TableVal::DoClone(CloneState* state) { auto tv = zeek::make_intrusive(table_type); state->NewClone(this, tv); @@ -2691,12 +2691,12 @@ RecordVal::RecordVal(zeek::RecordType* t, bool init_fields) : RecordVal({zeek::NewRef{}, t}, init_fields) {} -RecordVal::RecordVal(zeek::IntrusivePtr t, bool init_fields) : Val(std::move(t)) +RecordVal::RecordVal(zeek::RecordTypePtr t, bool init_fields) : Val(std::move(t)) { origin = nullptr; auto rt = GetType()->AsRecordType(); int n = rt->NumFields(); - auto vl = val.record_val = new std::vector>; + auto vl = val.record_val = new std::vector; vl->reserve(n); if ( is_parsing ) @@ -2733,7 +2733,7 @@ RecordVal::RecordVal(zeek::IntrusivePtr t, bool init_fields) : else if ( tag == zeek::TYPE_TABLE ) def = zeek::make_intrusive(zeek::IntrusivePtr{zeek::NewRef{}, type->AsTableType()}, - zeek::IntrusivePtr{zeek::NewRef{}, a}); + zeek::IntrusivePtr{zeek::NewRef{}, a}); else if ( tag == zeek::TYPE_VECTOR ) def = zeek::make_intrusive(zeek::cast_intrusive(type)); @@ -2748,12 +2748,12 @@ RecordVal::~RecordVal() delete AsNonConstRecord(); } -zeek::IntrusivePtr RecordVal::SizeVal() const +ValPtr RecordVal::SizeVal() const { return val_mgr->Count(GetType()->AsRecordType()->NumFields()); } -void RecordVal::Assign(int field, zeek::IntrusivePtr new_val) +void RecordVal::Assign(int field, ValPtr new_val) { (*AsNonConstRecord())[field] = std::move(new_val); Modified(); @@ -2764,7 +2764,7 @@ void RecordVal::Assign(int field, Val* new_val) Assign(field, {zeek::AdoptRef{}, new_val}); } -zeek::IntrusivePtr RecordVal::GetFieldOrDefault(int field) const +ValPtr RecordVal::GetFieldOrDefault(int field) const { const auto& val = (*AsRecord())[field]; @@ -2804,7 +2804,7 @@ void RecordVal::DoneParsing() parse_time_records.clear(); } -const zeek::IntrusivePtr& RecordVal::GetField(const char* field) const +const ValPtr& RecordVal::GetField(const char* field) const { int idx = GetType()->AsRecordType()->FieldOffset(field); @@ -2814,7 +2814,7 @@ const zeek::IntrusivePtr& RecordVal::GetField(const char* field) const return GetField(idx); } -zeek::IntrusivePtr RecordVal::GetFieldOrDefault(const char* field) const +ValPtr RecordVal::GetFieldOrDefault(const char* field) const { int idx = GetType()->AsRecordType()->FieldOffset(field); @@ -2824,10 +2824,9 @@ zeek::IntrusivePtr RecordVal::GetFieldOrDefault(const char* field) const return GetFieldOrDefault(idx); } -zeek::IntrusivePtr RecordVal::CoerceTo( - zeek::IntrusivePtr t, - zeek::IntrusivePtr aggr, - bool allow_orphaning) const +RecordValPtr RecordVal::CoerceTo(zeek::RecordTypePtr t, + RecordValPtr aggr, + bool allow_orphaning) const { if ( ! record_promotion_compatible(t.get(), GetType()->AsRecordType()) ) return nullptr; @@ -2889,8 +2888,7 @@ zeek::IntrusivePtr RecordVal::CoerceTo( return aggr; } -zeek::IntrusivePtr RecordVal::CoerceTo(zeek::IntrusivePtr t, - bool allow_orphaning) +RecordValPtr RecordVal::CoerceTo(zeek::RecordTypePtr t, bool allow_orphaning) { if ( same_type(GetType(), t) ) return {zeek::NewRef{}, this}; @@ -2898,7 +2896,7 @@ zeek::IntrusivePtr RecordVal::CoerceTo(zeek::IntrusivePtr RecordVal::GetRecordFieldsVal() const +TableValPtr RecordVal::GetRecordFieldsVal() const { return GetType()->AsRecordType()->GetRecordFieldsVal(this); } @@ -2970,7 +2968,7 @@ void RecordVal::DescribeReST(ODesc* d) const d->Add("}"); } -zeek::IntrusivePtr RecordVal::DoClone(CloneState* state) +ValPtr RecordVal::DoClone(CloneState* state) { // We set origin to 0 here. Origin only seems to be used for exactly one // purpose - to find the connection record that is associated with a @@ -3001,12 +2999,12 @@ unsigned int RecordVal::MemoryAllocation() const size += v->MemoryAllocation(); } - size += pad_size(vl.capacity() * sizeof(zeek::IntrusivePtr)); + size += pad_size(vl.capacity() * sizeof(ValPtr)); size += padded_sizeof(vl); return size + padded_sizeof(*this); } -zeek::IntrusivePtr EnumVal::SizeVal() const +ValPtr EnumVal::SizeVal() const { return val_mgr->Int(val.int_val); } @@ -3021,7 +3019,7 @@ void EnumVal::ValDescribe(ODesc* d) const d->Add(ename); } -zeek::IntrusivePtr EnumVal::DoClone(CloneState* state) +ValPtr EnumVal::DoClone(CloneState* state) { // Immutable. return {zeek::NewRef{}, this}; @@ -3030,9 +3028,9 @@ zeek::IntrusivePtr EnumVal::DoClone(CloneState* state) VectorVal::VectorVal(zeek::VectorType* t) : VectorVal({zeek::NewRef{}, t}) { } -VectorVal::VectorVal(zeek::IntrusivePtr t) : Val(std::move(t)) +VectorVal::VectorVal(zeek::VectorTypePtr t) : Val(std::move(t)) { - val.vector_val = new vector>(); + val.vector_val = new vector(); } VectorVal::~VectorVal() @@ -3040,12 +3038,12 @@ VectorVal::~VectorVal() delete val.vector_val; } -zeek::IntrusivePtr VectorVal::SizeVal() const +ValPtr VectorVal::SizeVal() const { return val_mgr->Count(uint32_t(val.vector_val->size())); } -bool VectorVal::Assign(unsigned int index, zeek::IntrusivePtr element) +bool VectorVal::Assign(unsigned int index, ValPtr element) { if ( element && ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) @@ -3061,7 +3059,7 @@ bool VectorVal::Assign(unsigned int index, zeek::IntrusivePtr element) } bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, - zeek::IntrusivePtr element) + ValPtr element) { ResizeAtLeast(index + how_many); @@ -3072,7 +3070,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, return true; } -bool VectorVal::Insert(unsigned int index, zeek::IntrusivePtr element) +bool VectorVal::Insert(unsigned int index, ValPtr element) { if ( element && ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) @@ -3080,7 +3078,7 @@ bool VectorVal::Insert(unsigned int index, zeek::IntrusivePtr element) return false; } - vector>::iterator it; + vector::iterator it; if ( index < val.vector_val->size() ) it = std::next(val.vector_val->begin(), index); @@ -3129,7 +3127,7 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const return true; } -const zeek::IntrusivePtr& VectorVal::At(unsigned int index) const +const ValPtr& VectorVal::At(unsigned int index) const { if ( index >= val.vector_val->size() ) return Val::nil; @@ -3154,7 +3152,7 @@ unsigned int VectorVal::ResizeAtLeast(unsigned int new_num_elements) return Resize(new_num_elements); } -zeek::IntrusivePtr VectorVal::DoClone(CloneState* state) +ValPtr VectorVal::DoClone(CloneState* state) { auto vv = zeek::make_intrusive(GetType()); vv->val.vector_val->reserve(val.vector_val->size()); @@ -3188,10 +3186,10 @@ void VectorVal::ValDescribe(ODesc* d) const d->Add("]"); } -zeek::IntrusivePtr check_and_promote(zeek::IntrusivePtr v, - const zeek::Type* t, - bool is_init, - const Location* expr_location) +ValPtr check_and_promote(ValPtr v, + const zeek::Type* t, + bool is_init, + const Location* expr_location) { if ( ! v ) return nullptr; @@ -3248,7 +3246,7 @@ zeek::IntrusivePtr check_and_promote(zeek::IntrusivePtr v, // Already has the right internal type. return v; - zeek::IntrusivePtr promoted_v; + ValPtr promoted_v; switch ( it ) { case zeek::TYPE_INTERNAL_INT: @@ -3365,7 +3363,7 @@ void describe_vals(const val_list* vals, ODesc* d, int offset) } } -void describe_vals(const std::vector>& vals, +void describe_vals(const std::vector& vals, ODesc* d, size_t offset) { if ( ! d->IsReadable() ) @@ -3393,7 +3391,7 @@ void delete_vals(val_list* vals) } } -zeek::IntrusivePtr cast_value_to_type(Val* v, zeek::Type* t) +ValPtr 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(). @@ -3464,17 +3462,17 @@ bool can_cast_value_to_type(const zeek::Type* s, zeek::Type* t) return false; } -zeek::IntrusivePtr Val::MakeBool(bool b) +ValPtr Val::MakeBool(bool b) { return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(bro_int_t(b), zeek::TYPE_BOOL)}; } -zeek::IntrusivePtr Val::MakeInt(bro_int_t i) +ValPtr Val::MakeInt(bro_int_t i) { return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(i, zeek::TYPE_INT)}; } -zeek::IntrusivePtr Val::MakeCount(bro_uint_t u) +ValPtr Val::MakeCount(bro_uint_t u) { return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(u, zeek::TYPE_COUNT)}; } @@ -3506,7 +3504,7 @@ StringVal* ValManager::GetEmptyString() const return empty_string->Ref()->AsStringVal(); } -const zeek::IntrusivePtr& ValManager::Port(uint32_t port_num, TransportProto port_type) const +const PortValPtr& ValManager::Port(uint32_t port_num, TransportProto port_type) const { if ( port_num >= 65536 ) { @@ -3522,7 +3520,7 @@ PortVal* ValManager::GetPort(uint32_t port_num, TransportProto port_type) const return Port(port_num, port_type)->Ref()->AsPortVal(); } -const zeek::IntrusivePtr& ValManager::Port(uint32_t port_num) const +const PortValPtr& ValManager::Port(uint32_t port_num) const { auto mask = port_num & PORT_SPACE_MASK; port_num &= ~PORT_SPACE_MASK; diff --git a/src/Val.h b/src/Val.h index 55b9b0cf95..e6deffa576 100644 --- a/src/Val.h +++ b/src/Val.h @@ -34,6 +34,9 @@ class Func; class BroFile; class PrefixTable; +using BroFilePtr = zeek::IntrusivePtr; +using FuncPtr = zeek::IntrusivePtr; + class Val; class PortVal; class AddrVal; @@ -49,6 +52,16 @@ class OpaqueVal; class VectorVal; class TableEntryVal; +using AddrValPtr = zeek::IntrusivePtr; +using EnumValPtr = zeek::IntrusivePtr; +using ListValPtr = zeek::IntrusivePtr; +using PortValPtr = zeek::IntrusivePtr; +using RecordValPtr = zeek::IntrusivePtr; +using StringValPtr = zeek::IntrusivePtr; +using TableValPtr = zeek::IntrusivePtr; +using ValPtr = zeek::IntrusivePtr; +using VectorValPtr = zeek::IntrusivePtr; + class IPAddr; class IPPrefix; @@ -77,8 +90,8 @@ union BroValUnion { BroFile* file_val; RE_Matcher* re_val; PDict* table_val; - std::vector>* record_val; - std::vector>* vector_val; + std::vector* record_val; + std::vector* vector_val; BroValUnion() = default; @@ -115,7 +128,7 @@ union BroValUnion { class Val : public BroObj { public: - static inline const zeek::IntrusivePtr nil; + static inline const ValPtr nil; [[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]] Val(double d, zeek::TypeTag t) @@ -124,16 +137,16 @@ public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(Func* f); - explicit Val(zeek::IntrusivePtr f); + explicit Val(FuncPtr f); [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Val(BroFile* f); // Note, the file will be closed after this Val is destructed if there's // no other remaining references. - explicit Val(zeek::IntrusivePtr f); + explicit Val(BroFilePtr f); // Extra arg to differentiate from protected version. - Val(zeek::IntrusivePtr t, bool type_type) + Val(zeek::TypePtr t, bool type_type) : type(zeek::make_intrusive(std::move(t))) {} @@ -148,7 +161,7 @@ public: ~Val() override; Val* Ref() { ::Ref(this); return this; } - zeek::IntrusivePtr Clone(); + ValPtr Clone(); bool IsZero() const; bool IsOne() const; @@ -163,7 +176,7 @@ public: // Returns a new Val with the "size" of this Val. What constitutes // size depends on the Val's type. - virtual zeek::IntrusivePtr SizeVal() const; + virtual ValPtr SizeVal() const; // Bytes in total value object. virtual unsigned int MemoryAllocation() const; @@ -182,7 +195,7 @@ public: [[deprecated("Remove in v4.1. Use GetType().")]] const zeek::Type* Type() const { return type.get(); } - const zeek::IntrusivePtr& GetType() const + const zeek::TypePtr& GetType() const { return type; } template @@ -215,10 +228,10 @@ public: 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_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_ACCESSOR(zeek::TYPE_VECTOR, std::vector*, vector_val, AsVector) const IPPrefix& AsSubNet() const { @@ -252,9 +265,9 @@ public: 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) + ACCESSOR(zeek::TYPE_VECTOR, std::vector*, vector_val, AsVector) - zeek::IntrusivePtr AsFuncPtr() const; + FuncPtr AsFuncPtr() const; const IPPrefix& AsSubNet() { @@ -328,9 +341,9 @@ public: static bool WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, const Val* val); - zeek::IntrusivePtr GetRecordFields(); + TableValPtr GetRecordFields(); - zeek::IntrusivePtr ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr); + StringValPtr ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr); protected: @@ -344,9 +357,9 @@ protected: virtual void ValDescribe(ODesc* d) const; virtual void ValDescribeReST(ODesc* d) const; - static zeek::IntrusivePtr MakeBool(bool b); - static zeek::IntrusivePtr MakeInt(bro_int_t i); - static zeek::IntrusivePtr MakeCount(bro_uint_t u); + static ValPtr MakeBool(bool b); + static ValPtr MakeInt(bro_int_t i); + static ValPtr MakeCount(bro_uint_t u); template Val(V&& v, zeek::TypeTag t) noexcept @@ -354,32 +367,32 @@ protected: {} template - Val(V&& v, zeek::IntrusivePtr t) noexcept + Val(V&& v, zeek::TypePtr t) noexcept : val(std::forward(v)), type(std::move(t)) {} - explicit Val(zeek::IntrusivePtr t) noexcept + explicit Val(zeek::TypePtr t) noexcept : type(std::move(t)) {} ACCESSOR(zeek::TYPE_TABLE, PDict*, table_val, AsNonConstTable) - ACCESSOR(zeek::TYPE_RECORD, std::vector>*, record_val, AsNonConstRecord) + ACCESSOR(zeek::TYPE_RECORD, std::vector*, record_val, AsNonConstRecord) // For internal use by the Val::Clone() methods. struct CloneState { // Caches a cloned value for later reuse during the same // cloning operation. For recursive types, call this *before* // descending down. - zeek::IntrusivePtr NewClone(Val* src, zeek::IntrusivePtr dst); + ValPtr NewClone(Val* src, ValPtr dst); std::unordered_map clones; }; - zeek::IntrusivePtr Clone(CloneState* state); - virtual zeek::IntrusivePtr DoClone(CloneState* state); + ValPtr Clone(CloneState* state); + virtual ValPtr DoClone(CloneState* state); BroValUnion val; - zeek::IntrusivePtr type; + zeek::TypePtr type; #ifdef DEBUG // For debugging, we keep the name of the ID to which a Val is bound. @@ -405,21 +418,21 @@ public: inline Val* GetTrue() const { return b_true->Ref(); } - inline const zeek::IntrusivePtr& True() const + inline const ValPtr& True() const { return b_true; } [[deprecated("Remove in v4.1. Use val_mgr->False() instead.")]] inline Val* GetFalse() const { return b_false->Ref(); } - inline const zeek::IntrusivePtr& False() const + inline const ValPtr& False() const { return b_false; } [[deprecated("Remove in v4.1. Use val_mgr->Bool() instead.")]] inline Val* GetBool(bool b) const { return b ? b_true->Ref() : b_false->Ref(); } - inline const zeek::IntrusivePtr& Bool(bool b) const + inline const ValPtr& Bool(bool b) const { return b ? b_true : b_false; } [[deprecated("Remove in v4.1. Use val_mgr->Int() instead.")]] @@ -429,7 +442,7 @@ public: Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref(); } - inline zeek::IntrusivePtr Int(int64_t i) const + inline ValPtr Int(int64_t i) const { return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ? Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST]; @@ -441,7 +454,7 @@ public: return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i).release() : counts[i]->Ref(); } - inline zeek::IntrusivePtr Count(uint64_t i) const + inline ValPtr Count(uint64_t i) const { return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i]; } @@ -449,7 +462,7 @@ public: [[deprecated("Remove in v4.1. Use val_mgr->EmptyString() instead.")]] StringVal* GetEmptyString() const; - inline const zeek::IntrusivePtr& EmptyString() const + inline const StringValPtr& EmptyString() const { return empty_string; } // Port number given in host order. @@ -457,23 +470,23 @@ public: PortVal* GetPort(uint32_t port_num, TransportProto port_type) const; // Port number given in host order. - const zeek::IntrusivePtr& Port(uint32_t port_num, TransportProto port_type) const; + const PortValPtr& Port(uint32_t port_num, TransportProto port_type) const; // Host-order port number already masked with port space protocol mask. [[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]] PortVal* GetPort(uint32_t port_num) const; // Host-order port number already masked with port space protocol mask. - const zeek::IntrusivePtr& Port(uint32_t port_num) const; + const PortValPtr& Port(uint32_t port_num) const; private: - std::array, 65536>, NUM_PORT_SPACES> ports; - std::array, PREALLOCATED_COUNTS> counts; - std::array, PREALLOCATED_INTS> ints; - zeek::IntrusivePtr empty_string; - zeek::IntrusivePtr b_true; - zeek::IntrusivePtr b_false; + std::array, NUM_PORT_SPACES> ports; + std::array counts; + std::array ints; + StringValPtr empty_string; + ValPtr b_true; + ValPtr b_false; }; extern ValManager* val_mgr; @@ -511,7 +524,7 @@ public: class PortVal final : public Val { public: - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; // Returns the port number in host order (not including the mask). uint32_t Port() const; @@ -542,7 +555,7 @@ protected: PortVal(uint32_t p); void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; class AddrVal final : public Val { @@ -551,7 +564,7 @@ public: explicit AddrVal(const std::string& text); ~AddrVal() override; - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; // Constructor for address already in network order. explicit AddrVal(uint32_t addr); // IPv4. @@ -561,7 +574,7 @@ public: unsigned int MemoryAllocation() const override; protected: - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; class SubNetVal final : public Val { @@ -574,7 +587,7 @@ public: explicit SubNetVal(const IPPrefix& prefix); ~SubNetVal() override; - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; const IPAddr& Prefix() const; int Width() const; @@ -586,7 +599,7 @@ public: protected: void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; class StringVal final : public Val { @@ -596,7 +609,7 @@ public: explicit StringVal(const std::string& s); StringVal(int length, const char* s); - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; int Len(); const u_char* Bytes(); @@ -612,7 +625,7 @@ public: unsigned int MemoryAllocation() const override; - zeek::IntrusivePtr Replace(RE_Matcher* re, const BroString& repl, + StringValPtr Replace(RE_Matcher* re, const BroString& repl, bool do_all); [[deprecated("Remove in v4.1. Use Replace().")]] @@ -621,7 +634,7 @@ public: protected: void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; class PatternVal final : public Val { @@ -637,7 +650,7 @@ public: protected: void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; // ListVals are mainly used to index tables that have more than one @@ -650,11 +663,11 @@ public: zeek::TypeTag BaseTag() const { return tag; } - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; int Length() const { return vals.size(); } - const zeek::IntrusivePtr& Idx(size_t i) const { return vals[i]; } + const ValPtr& Idx(size_t i) const { return vals[i]; } [[deprecated("Remove in v4.1. Use Idx() instead")]] Val* Index(const int n) { return vals[n].get(); } @@ -675,27 +688,27 @@ public: * Appends a value to the list. * @param v the value to append. */ - void Append(zeek::IntrusivePtr v); + void Append(ValPtr v); [[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]] void Append(Val* v); // Returns a Set representation of the list (which must be homogeneous). - zeek::IntrusivePtr ToSetVal() const; + TableValPtr ToSetVal() const; [[deprecated("Remove in v4.1. Use ToSetVal() instead.")]] TableVal* ConvertToSet() const; - const std::vector>& Vals() const { return vals; } + const std::vector& Vals() const { return vals; } void Describe(ODesc* d) const override; unsigned int MemoryAllocation() const override; protected: - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; - std::vector> vals; + std::vector vals; zeek::TypeTag tag; }; @@ -703,7 +716,7 @@ extern double bro_start_network_time; class TableEntryVal { public: - explicit TableEntryVal(zeek::IntrusivePtr v) + explicit TableEntryVal(ValPtr v) : val(std::move(v)) { expire_access_time = @@ -715,7 +728,7 @@ public: [[deprecated("Remove in v4.1. Use GetVal().")]] Val* Value() { return val.get(); } - const zeek::IntrusivePtr& GetVal() const + const ValPtr& GetVal() const { return val; } // Returns/sets time of last expiration relevant access to this value. @@ -727,7 +740,7 @@ public: protected: friend class TableVal; - zeek::IntrusivePtr val; + ValPtr val; // The next entry stores seconds since Bro's start. We use ints here // to save a few bytes, as we do not need a high resolution for these @@ -754,7 +767,7 @@ class Frame; class TableVal final : public Val, public notifier::Modifiable { public: - explicit TableVal(zeek::IntrusivePtr t, zeek::IntrusivePtr attrs = nullptr); + explicit TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr attrs = nullptr); [[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]] explicit TableVal(zeek::TableType* t, zeek::detail::Attributes* attrs = nullptr) @@ -771,7 +784,7 @@ public: * must be nullptr. * @return True if the assignment type-checked. */ - bool Assign(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val); + bool Assign(ValPtr index, ValPtr new_val); /** * Assigns a value at an associated index in the table (or in the @@ -783,8 +796,8 @@ public: * must be nullptr. * @return True if the assignment type-checked. */ - bool Assign(zeek::IntrusivePtr index, std::unique_ptr k, - zeek::IntrusivePtr new_val); + bool Assign(ValPtr index, std::unique_ptr k, + ValPtr new_val); // Returns true if the assignment typechecked, false if not. The // methods take ownership of new_val, but not of the index. If we're @@ -797,7 +810,7 @@ public: [[deprecated("Remove in v4.1. Use IntrusivePtr overload instead.")]] bool Assign(Val* index, HashKey* k, Val* new_val); - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; // Add the entire contents of the table to the given value, // which must also be a TableVal. @@ -825,7 +838,7 @@ public: * @param v The intersecting table. * @return The intersection of this table and the given one. */ - zeek::IntrusivePtr Intersection(const TableVal& v) const; + TableValPtr Intersection(const TableVal& v) const; [[deprecated("Remove in v4.1. Use Intersection() instead.")]] TableVal* Intersect(const TableVal* v) const @@ -851,7 +864,7 @@ public: // Expands any lists in the index into multiple initializations. // Returns true if the initializations typecheck, false if not. - bool ExpandAndInit(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val); + bool ExpandAndInit(ValPtr index, ValPtr new_val); /** * Finds an index in the table and returns its associated value. @@ -862,7 +875,7 @@ public: * non-existent index (nullptr), but otherwise has no meaning in relation * to the set's contents. */ - const zeek::IntrusivePtr& Find(const zeek::IntrusivePtr& index); + const ValPtr& Find(const ValPtr& index); /** * Finds an index in the table and returns its associated value or else @@ -872,7 +885,7 @@ public: * exist, instead returns the &default value. If there's no &default * attribute, then nullptr is still returned for non-existent index. */ - zeek::IntrusivePtr FindOrDefault(const zeek::IntrusivePtr& index); + ValPtr FindOrDefault(const ValPtr& index); // Returns the element's value if it exists in the table, // nil otherwise. Note, "index" is not const because we @@ -883,12 +896,12 @@ public: // For a table[subnet]/set[subnet], return all subnets that cover // the given subnet. // Causes an internal error if called for any other kind of table. - zeek::IntrusivePtr LookupSubnets(const SubNetVal* s); + VectorValPtr LookupSubnets(const SubNetVal* s); // For a set[subnet]/table[subnet], return a new table that only contains // entries that cover the given subnet. // Causes an internal error if called for any other kind of table. - zeek::IntrusivePtr LookupSubnetValues(const SubNetVal* s); + TableValPtr LookupSubnetValues(const SubNetVal* s); // Sets the timestamp for the given index to network time. // Returns false if index does not exist. @@ -897,7 +910,7 @@ public: /** * @return The index corresponding to the given HashKey. */ - zeek::IntrusivePtr RecreateIndex(const HashKey& k) const; + ListValPtr RecreateIndex(const HashKey& k) const; [[deprecated("Remove in v4.1. Use RecreateIndex().")]] ListVal* RecoverIndex(const HashKey* k) const @@ -911,14 +924,14 @@ public: * value is returned to differentiate it from non-existent index (nullptr), * but otherwise has no meaning in relation to the set's contents. */ - zeek::IntrusivePtr Remove(const Val& index); + ValPtr Remove(const Val& index); /** * Same as Remove(const Val&), but uses a precomputed hash key. * @param k The hash key to lookup. * @return Same as Remove(const Val&). */ - zeek::IntrusivePtr Remove(const HashKey& k); + ValPtr Remove(const HashKey& k); [[deprecated("Remove in v4.1. Use Remove().")]] Val* Delete(const Val* index) @@ -929,25 +942,25 @@ public: { return Remove(*k).release(); } // Returns a ListVal representation of the table (which must be a set). - zeek::IntrusivePtr ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const; + ListValPtr 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). - zeek::IntrusivePtr ToPureListVal() const; + ListValPtr ToPureListVal() const; [[deprecated("Remove in v4.1. Use ToListVal() instead.")]] 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(zeek::IntrusivePtr attrs); + void SetAttrs(zeek::detail::AttributesPtr attrs); - const zeek::IntrusivePtr& GetAttr(zeek::detail::AttrTag t) const; + const zeek::detail::AttrPtr& GetAttr(zeek::detail::AttrTag t) const; [[deprecated("Remove in v4.1. Use GetAttrs().")]] zeek::detail::Attributes* Attrs() { return attrs.get(); } - const zeek::IntrusivePtr& GetAttrs() const + const zeek::detail::AttributesPtr& GetAttrs() const { return attrs; } // Returns the size of the table. @@ -1003,22 +1016,22 @@ public: static void DoneParsing(); protected: - void Init(zeek::IntrusivePtr t); + void Init(zeek::TableTypePtr t); - using TableRecordDependencies = std::unordered_map>>; + using TableRecordDependencies = std::unordered_map>; - using ParseTimeTableState = std::vector, zeek::IntrusivePtr>>; + using ParseTimeTableState = std::vector>; using ParseTimeTableStates = std::unordered_map; ParseTimeTableState DumpTableState(); void RebuildTable(ParseTimeTableState ptts); void CheckExpireAttr(zeek::detail::AttrTag at); - bool ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr new_val); - bool CheckAndAssign(zeek::IntrusivePtr index, zeek::IntrusivePtr new_val); + bool ExpandCompoundAndInit(ListVal* lv, int k, ValPtr new_val); + bool CheckAndAssign(ValPtr index, ValPtr new_val); // Calculates default value for index. Returns nullptr if none. - zeek::IntrusivePtr Default(const zeek::IntrusivePtr& index); + ValPtr Default(const ValPtr& index); // Returns true if item expiration is enabled. bool ExpirationEnabled() { return expire_time != nullptr; } @@ -1029,27 +1042,27 @@ protected: double GetExpireTime(); // Calls &expire_func and returns its return interval; - double CallExpireFunc(zeek::IntrusivePtr idx); + double CallExpireFunc(ListValPtr idx); // Enum for the different kinds of changes an &on_change handler can see enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED }; // Calls &change_func. Does not take ownership of values. (Refs if needed). - void CallChangeFunc(const Val* index, const zeek::IntrusivePtr& old_value, + void CallChangeFunc(const Val* index, const ValPtr& old_value, OnChangeType tpe); - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; - zeek::IntrusivePtr table_type; + zeek::TableTypePtr table_type; CompositeHash* table_hash; - zeek::IntrusivePtr attrs; - zeek::IntrusivePtr expire_time; - zeek::IntrusivePtr expire_func; + zeek::detail::AttributesPtr attrs; + zeek::detail::ExprPtr expire_time; + zeek::detail::ExprPtr expire_func; TableValTimer* timer; IterCookie* expire_cookie; PrefixTable* subnets; - zeek::IntrusivePtr def_val; - zeek::IntrusivePtr change_func; + ValPtr def_val; + zeek::detail::ExprPtr change_func; // prevent recursion of change functions bool in_change_func = false; @@ -1061,18 +1074,18 @@ class RecordVal final : public Val, public notifier::Modifiable { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit RecordVal(zeek::RecordType* t, bool init_fields = true); - explicit RecordVal(zeek::IntrusivePtr t, bool init_fields = true); + explicit RecordVal(zeek::RecordTypePtr t, bool init_fields = true); ~RecordVal() override; - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; /** * Assign a value to a record field. * @param field The field index to assign. * @param new_val The value to assign. */ - void Assign(int field, zeek::IntrusivePtr new_val); + void Assign(int field, ValPtr new_val); /** * Assign a value of type @c T to a record field, as constructed from @@ -1089,7 +1102,7 @@ public: void Assign(int field, Val* new_val); // Note: the following nullptr method can also go upon removing the above. void Assign(int field, std::nullptr_t) - { Assign(field, zeek::IntrusivePtr{}); } + { Assign(field, ValPtr{}); } [[deprecated("Remove in v4.1. Use GetField().")]] Val* Lookup(int field) const // Does not Ref() value. @@ -1100,7 +1113,7 @@ public: * @param field The field index to retrieve. * @return The value at the given field index. */ - const zeek::IntrusivePtr& GetField(int field) const + const ValPtr& GetField(int field) const { return (*AsRecord())[field]; } /** @@ -1120,7 +1133,7 @@ public: * @return The value at the given field index or the default value if * the field hasn't been assigned yet. */ - zeek::IntrusivePtr GetFieldOrDefault(int field) const; + ValPtr GetFieldOrDefault(int field) const; [[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]] Val* LookupWithDefault(int field) const @@ -1132,7 +1145,7 @@ public: * @return The value of the given field. If no such field name exists, * a fatal error occurs. */ - const zeek::IntrusivePtr& GetField(const char* field) const; + const ValPtr& GetField(const char* field) const; /** * Returns the value of a given field name as cast to type @c T. @@ -1153,7 +1166,7 @@ public: * if the field hasn't been assigned yet. If no such field name exists, * a fatal error occurs. */ - zeek::IntrusivePtr GetFieldOrDefault(const char* field) const; + ValPtr GetFieldOrDefault(const char* field) const; /** * Returns the value of a given field name or its default value @@ -1183,7 +1196,7 @@ public: /** * Returns a "record_field_table" value for introspection purposes. */ - zeek::IntrusivePtr GetRecordFieldsVal() const; + TableValPtr GetRecordFieldsVal() const; // This is an experiment to associate a BroObj within the // event engine to a record value in bro script. @@ -1201,13 +1214,11 @@ public: // // The *allow_orphaning* parameter allows for a record to be demoted // down to a record type that contains less fields. - zeek::IntrusivePtr CoerceTo( - zeek::IntrusivePtr other, - zeek::IntrusivePtr aggr, - bool allow_orphaning = false) const; - zeek::IntrusivePtr CoerceTo( - zeek::IntrusivePtr other, - bool allow_orphaning = false); + RecordValPtr CoerceTo(zeek::RecordTypePtr other, + RecordValPtr aggr, + bool allow_orphaning = false) const; + RecordValPtr CoerceTo(zeek::RecordTypePtr other, + bool allow_orphaning = false); unsigned int MemoryAllocation() const override; void DescribeReST(ODesc* d) const override; @@ -1222,17 +1233,17 @@ public: static void DoneParsing(); protected: - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; BroObj* origin; - using RecordTypeValMap = std::unordered_map>>; + using RecordTypeValMap = std::unordered_map>; static RecordTypeValMap parse_time_records; }; class EnumVal final : public Val { public: - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; protected: friend class Val; @@ -1241,11 +1252,11 @@ protected: template friend zeek::IntrusivePtr zeek::make_intrusive(Ts&&... args); - EnumVal(zeek::IntrusivePtr t, int i) : Val(bro_int_t(i), std::move(t)) + EnumVal(zeek::EnumTypePtr t, int i) : Val(bro_int_t(i), std::move(t)) {} void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; @@ -1253,10 +1264,10 @@ class VectorVal final : public Val, public notifier::Modifiable { public: [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit VectorVal(zeek::VectorType* t); - explicit VectorVal(zeek::IntrusivePtr t); + explicit VectorVal(zeek::VectorTypePtr t); ~VectorVal() override; - zeek::IntrusivePtr SizeVal() const override; + ValPtr SizeVal() const override; /** * Assigns an element to a given vector index. @@ -1265,7 +1276,7 @@ public: * @return True if the element was successfully assigned, or false if * the element was the wrong type. */ - bool Assign(unsigned int index, zeek::IntrusivePtr element); + bool Assign(unsigned int index, ValPtr element); // Note: does NOT Ref() the element! Remember to do so unless // the element was just created and thus has refcount 1. @@ -1274,7 +1285,7 @@ public: { return Assign(index, {zeek::AdoptRef{}, element}); } // Note: the following nullptr method can also go upon removing the above. void Assign(unsigned int index, std::nullptr_t) - { Assign(index, zeek::IntrusivePtr{}); } + { Assign(index, ValPtr{}); } [[deprecated("Remove in v4.1. Assign using integer index and IntrusivePtr element.")]] bool Assign(Val* index, Val* element) @@ -1291,7 +1302,7 @@ public: * the element was the wrong type. */ bool AssignRepeat(unsigned int index, unsigned int how_many, - zeek::IntrusivePtr element); + ValPtr element); [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] bool AssignRepeat(unsigned int index, unsigned int how_many, Val* element) @@ -1307,7 +1318,7 @@ public: * @return The element at the given index or nullptr if the index * does not exist (it's greater than or equal to vector's current size). */ - const zeek::IntrusivePtr& At(unsigned int index) const; + const ValPtr& At(unsigned int index) const; [[deprecated("Remove in v4.1. Use At().")]] Val* Lookup(unsigned int index) const @@ -1339,7 +1350,7 @@ public: * @return True if the element was inserted or false if the element was * the wrong type. */ - bool Insert(unsigned int index, zeek::IntrusivePtr element); + bool Insert(unsigned int index, ValPtr element); [[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]] bool Insert(unsigned int index, Val* element) @@ -1350,33 +1361,33 @@ public: protected: void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; }; // Checks the given value for consistency with the given type. If an // exact match, returns it. If promotable, returns the promoted version. // 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 zeek::IntrusivePtr check_and_promote( - zeek::IntrusivePtr v, const zeek::Type* t, bool is_init, +extern ValPtr check_and_promote( + ValPtr v, const zeek::Type* t, bool is_init, const Location* expr_location = nullptr); extern bool same_val(const Val* v1, const Val* v2); extern bool same_atomic_val(const Val* v1, const Val* v2); extern bool is_atomic_val(const Val* v); extern void describe_vals(const val_list* vals, ODesc* d, int offset=0); -extern void describe_vals(const std::vector>& vals, +extern void describe_vals(const std::vector& vals, ODesc* d, size_t offset = 0); 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() == zeek::TYPE_VECTOR; } -inline bool is_vector(const zeek::IntrusivePtr& v) { return is_vector(v.get()); } +inline bool is_vector(const ValPtr& 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 zeek::IntrusivePtr cast_value_to_type(Val* v, zeek::Type* t); +extern ValPtr 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. diff --git a/src/Var.cc b/src/Var.cc index 6a3356d2ec..4ec3c6b910 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -19,9 +19,9 @@ using namespace zeek::detail; -static zeek::IntrusivePtr init_val(zeek::detail::Expr* init, - const zeek::Type* t, - zeek::IntrusivePtr aggr) +static ValPtr init_val(zeek::detail::Expr* init, + const zeek::Type* t, + ValPtr aggr) { try { @@ -33,9 +33,9 @@ static zeek::IntrusivePtr init_val(zeek::detail::Expr* init, } } -static bool add_prototype(const zeek::IntrusivePtr& id, zeek::Type* t, - std::vector>* attrs, - const zeek::IntrusivePtr& init) +static bool add_prototype(const zeek::detail::IDPtr& id, zeek::Type* t, + std::vector* attrs, + const zeek::detail::ExprPtr& init) { if ( ! zeek::IsFunc(id->GetType()->Tag()) ) return false; @@ -111,10 +111,10 @@ static bool add_prototype(const zeek::IntrusivePtr& id, zeek:: return true; } -static void make_var(const zeek::IntrusivePtr& id, zeek::IntrusivePtr t, +static void make_var(const zeek::detail::IDPtr& id, zeek::TypePtr t, zeek::detail::InitClass c, - zeek::IntrusivePtr init, - std::unique_ptr>> attr, + zeek::detail::ExprPtr init, + std::unique_ptr> attr, decl_type dt, bool do_init) { @@ -244,7 +244,7 @@ static void make_var(const zeek::IntrusivePtr& id, zeek::Intru else if ( dt != VAR_REDEF || init || ! attr ) { - zeek::IntrusivePtr aggr; + ValPtr aggr; if ( t->Tag() == zeek::TYPE_RECORD ) { @@ -264,7 +264,7 @@ static void make_var(const zeek::IntrusivePtr& id, zeek::Intru else if ( t->Tag() == zeek::TYPE_VECTOR ) aggr = zeek::make_intrusive(zeek::cast_intrusive(t)); - zeek::IntrusivePtr v; + ValPtr v; if ( init ) { @@ -306,24 +306,27 @@ static void make_var(const zeek::IntrusivePtr& id, zeek::Intru // 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 = zeek::make_intrusive(id, nullptr, inits, 0, 0); id->SetVal(zeek::make_intrusive(std::move(f))); } } -void add_global(const zeek::IntrusivePtr& id, zeek::IntrusivePtr t, - zeek::detail::InitClass c, zeek::IntrusivePtr init, - std::unique_ptr>> attr, - decl_type dt) +void add_global( + const zeek::detail::IDPtr& id, + zeek::TypePtr t, + zeek::detail::InitClass c, zeek::detail::ExprPtr init, + std::unique_ptr> attr, + decl_type dt) { make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); } -zeek::IntrusivePtr add_local(zeek::IntrusivePtr id, zeek::IntrusivePtr t, - zeek::detail::InitClass c, zeek::IntrusivePtr init, - std::unique_ptr>> attr, - decl_type dt) +zeek::detail::StmtPtr add_local( + zeek::detail::IDPtr id, zeek::TypePtr t, + zeek::detail::InitClass c, zeek::detail::ExprPtr init, + std::unique_ptr> attr, + decl_type dt) { make_var(id, std::move(t), c, init, std::move(attr), dt, false); @@ -352,10 +355,10 @@ zeek::IntrusivePtr add_local(zeek::IntrusivePtr add_and_assign_local( - zeek::IntrusivePtr id, - zeek::IntrusivePtr init, - zeek::IntrusivePtr val) +extern zeek::detail::ExprPtr add_and_assign_local( + zeek::detail::IDPtr id, + zeek::detail::ExprPtr init, + ValPtr val) { make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false); auto name_expr = zeek::make_intrusive(std::move(id)); @@ -363,12 +366,12 @@ extern zeek::IntrusivePtr add_and_assign_local( std::move(name_expr), std::move(init), false, std::move(val)); } -void add_type(zeek::detail::ID* id, zeek::IntrusivePtr t, - std::unique_ptr>> attr) +void add_type(zeek::detail::ID* id, zeek::TypePtr t, + std::unique_ptr> attr) { std::string new_type_name = id->Name(); std::string old_type_name = t->GetName(); - zeek::IntrusivePtr tnew; + zeek::TypePtr tnew; if ( (t->Tag() == zeek::TYPE_RECORD || t->Tag() == zeek::TYPE_ENUM) && old_type_name.empty() ) @@ -406,10 +409,10 @@ static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv if ( ! recv_i->attrs ) { - std::vector> a{def}; + std::vector a{def}; recv_i->attrs = zeek::make_intrusive(std::move(a), - recv_i->type, - true, false); + recv_i->type, + true, false); } else if ( ! recv_i->attrs->Find(zeek::detail::ATTR_DEFAULT) ) @@ -417,7 +420,7 @@ static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv } } -static zeek::detail::Attr* find_attr(const std::vector>* al, +static zeek::detail::Attr* find_attr(const std::vector* al, zeek::detail::AttrTag tag) { if ( ! al ) @@ -465,10 +468,10 @@ static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::Fu return true; } -void begin_func(zeek::IntrusivePtr id, const char* module_name, +void begin_func(zeek::detail::IDPtr id, const char* module_name, zeek::FunctionFlavor flavor, bool is_redef, - zeek::IntrusivePtr t, - std::unique_ptr>> attrs) + zeek::FuncTypePtr t, + std::unique_ptr> attrs) { if ( flavor == zeek::FUNC_FLAVOR_EVENT ) { @@ -639,7 +642,7 @@ TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr) return TC_CONTINUE; } -void end_func(zeek::IntrusivePtr body) +void end_func(zeek::detail::StmtPtr body) { auto ingredients = std::make_unique(pop_scope(), std::move(body)); diff --git a/src/Var.h b/src/Var.h index 61d7b8052e..5af1fb2c2f 100644 --- a/src/Var.h +++ b/src/Var.h @@ -16,37 +16,41 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); +namespace zeek::detail { +using StmtPtr = zeek::IntrusivePtr; +} + typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; -extern void add_global(const zeek::IntrusivePtr& id, - zeek::IntrusivePtr t, +extern void add_global(const zeek::detail::IDPtr& id, + zeek::TypePtr t, zeek::detail::InitClass c, - zeek::IntrusivePtr init, - std::unique_ptr>> attr, + zeek::detail::ExprPtr init, + std::unique_ptr> attr, decl_type dt); -extern zeek::IntrusivePtr add_local( - zeek::IntrusivePtr id, - zeek::IntrusivePtr t, +extern zeek::detail::StmtPtr add_local( + zeek::detail::IDPtr id, + zeek::TypePtr t, zeek::detail::InitClass c, - zeek::IntrusivePtr init, - std::unique_ptr>> attr, + zeek::detail::ExprPtr init, + std::unique_ptr> attr, decl_type dt); -extern zeek::IntrusivePtr add_and_assign_local( - zeek::IntrusivePtr id, - zeek::IntrusivePtr init, - zeek::IntrusivePtr val = nullptr); +extern zeek::detail::ExprPtr add_and_assign_local( + zeek::detail::IDPtr id, + zeek::detail::ExprPtr init, + ValPtr val = nullptr); -extern void add_type(zeek::detail::ID* id, zeek::IntrusivePtr t, - std::unique_ptr>> attr); +extern void add_type(zeek::detail::ID* id, zeek::TypePtr t, + std::unique_ptr> attr); -extern void begin_func(zeek::IntrusivePtr id, const char* module_name, +extern void begin_func(zeek::detail::IDPtr id, const char* module_name, zeek::FunctionFlavor flavor, bool is_redef, - zeek::IntrusivePtr t, - std::unique_ptr>> attrs = nullptr); + zeek::FuncTypePtr t, + std::unique_ptr> attrs = nullptr); -extern void end_func(zeek::IntrusivePtr body); +extern void end_func(zeek::detail::StmtPtr body); // Gather all IDs referenced inside a body that aren't part of a given scope. extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body); diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index 39ee2e439d..9ebc4ccd2b 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -710,7 +710,7 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len) if ( ! protocol_violation ) return; - zeek::IntrusivePtr r; + StringValPtr r; if ( data && len ) { @@ -794,7 +794,7 @@ RecordVal* Analyzer::BuildConnVal() return conn->ConnVal()->Ref()->AsRecordVal(); } -const zeek::IntrusivePtr& Analyzer::ConnVal() +const RecordValPtr& Analyzer::ConnVal() { return conn->ConnVal(); } @@ -926,12 +926,12 @@ void TransportLayerAnalyzer::Done() } void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */, - zeek::IntrusivePtr /* f */) + BroFilePtr /* f */) { reporter->Error("analyzer type does not support writing to a contents file"); } -zeek::IntrusivePtr TransportLayerAnalyzer::GetContentsFile(unsigned int /* direction */) const +BroFilePtr TransportLayerAnalyzer::GetContentsFile(unsigned int /* direction */) const { reporter->Error("analyzer type does not support writing to a contents file"); return nullptr; diff --git a/src/analyzer/Analyzer.h b/src/analyzer/Analyzer.h index bf4cab4ae9..8aa1491bca 100644 --- a/src/analyzer/Analyzer.h +++ b/src/analyzer/Analyzer.h @@ -17,6 +17,8 @@ #include "../IntrusivePtr.h" class BroFile; +using BroFilePtr = zeek::IntrusivePtr; + class Rule; class Connection; class IP_Hdr; @@ -35,6 +37,8 @@ using analyzer_list = std::list; typedef uint32_t ID; typedef void (Analyzer::*analyzer_timer_func)(double t); +using RecordValPtr = zeek::IntrusivePtr; + /** * Class to receive processed output from an anlyzer. */ @@ -556,7 +560,7 @@ public: * Convenience function that forwards directly to * Connection::ConnVal(). */ - const zeek::IntrusivePtr& ConnVal(); + const RecordValPtr& ConnVal(); /** * Convenience function that forwards directly to the corresponding @@ -604,7 +608,7 @@ public: template std::enable_if_t< std::is_convertible_v< - std::tuple_element_t<0, std::tuple>, zeek::IntrusivePtr>> + std::tuple_element_t<0, std::tuple>, ValPtr>> EnqueueConnEvent(EventHandlerPtr h, Args&&... args) { return EnqueueConnEvent(h, zeek::Args{std::forward(args)...}); } @@ -911,7 +915,7 @@ public: * @param f The file to record to. * */ - virtual void SetContentsFile(unsigned int direction, zeek::IntrusivePtr f); + virtual void SetContentsFile(unsigned int direction, BroFilePtr f); /** * Returns an associated contents file, if any. This must only be @@ -921,7 +925,7 @@ public: * @param direction One of the CONTENTS_* constants indicating which * direction the query is for. */ - virtual zeek::IntrusivePtr GetContentsFile(unsigned int direction) const; + virtual BroFilePtr GetContentsFile(unsigned int direction) const; /** * Associates a PIA with this analyzer. A PIA takes the diff --git a/src/analyzer/Manager.cc b/src/analyzer/Manager.cc index dce69f8a53..88bf70eaf5 100644 --- a/src/analyzer/Manager.cc +++ b/src/analyzer/Manager.cc @@ -576,7 +576,7 @@ void Manager::ScheduleAnalyzer(const IPAddr& orig, const IPAddr& resp, void Manager::ScheduleAnalyzer(const IPAddr& orig, const IPAddr& resp, PortVal* resp_p, Val* analyzer, double timeout) { - zeek::IntrusivePtr ev{zeek::NewRef{}, analyzer->AsEnumVal()}; + EnumValPtr ev{zeek::NewRef{}, analyzer->AsEnumVal()}; return ScheduleAnalyzer(orig, resp, resp_p->Port(), resp_p->PortType(), Tag(std::move(ev)), timeout); } diff --git a/src/analyzer/Tag.cc b/src/analyzer/Tag.cc index e082734c90..bc6b71e3af 100644 --- a/src/analyzer/Tag.cc +++ b/src/analyzer/Tag.cc @@ -16,7 +16,7 @@ analyzer::Tag& analyzer::Tag::operator=(const analyzer::Tag& other) return *this; } -const zeek::IntrusivePtr& analyzer::Tag::AsVal() const +const EnumValPtr& analyzer::Tag::AsVal() const { return ::Tag::AsVal(analyzer_mgr->GetTagType()); } @@ -26,7 +26,7 @@ EnumVal* analyzer::Tag::AsEnumVal() const return AsVal().get(); } -analyzer::Tag::Tag(zeek::IntrusivePtr val) +analyzer::Tag::Tag(EnumValPtr val) : ::Tag(std::move(val)) { } diff --git a/src/analyzer/Tag.h b/src/analyzer/Tag.h index 6b6dd2e8d5..2d757e16fa 100644 --- a/src/analyzer/Tag.h +++ b/src/analyzer/Tag.h @@ -89,7 +89,7 @@ public: * * @param etype the script-layer enum type associated with the tag. */ - const zeek::IntrusivePtr& AsVal() const; + const EnumValPtr& AsVal() const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; @@ -118,7 +118,7 @@ protected: * * @param val An enum value of script type \c Analyzer::Tag. */ - explicit Tag(zeek::IntrusivePtr val); + explicit Tag(EnumValPtr val); [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead")]] explicit Tag(EnumVal* val); diff --git a/src/analyzer/protocol/arp/ARP.cc b/src/analyzer/protocol/arp/ARP.cc index cb0486c522..ea9b12a96d 100644 --- a/src/analyzer/protocol/arp/ARP.cc +++ b/src/analyzer/protocol/arp/ARP.cc @@ -226,7 +226,7 @@ void ARP_Analyzer::RREvent(EventHandlerPtr e, AddrVal* ARP_Analyzer::ConstructAddrVal(const void* addr) { return ToAddrVal(addr).release(); } -zeek::IntrusivePtr ARP_Analyzer::ToAddrVal(const void* addr) +AddrValPtr ARP_Analyzer::ToAddrVal(const void* addr) { // ### For now, we only handle IPv4 addresses. return zeek::make_intrusive(*(const uint32_t*) addr); @@ -235,7 +235,7 @@ zeek::IntrusivePtr ARP_Analyzer::ToAddrVal(const void* addr) StringVal* ARP_Analyzer::EthAddrToStr(const u_char* addr) { return ToEthAddrStr(addr).release(); } -zeek::IntrusivePtr ARP_Analyzer::ToEthAddrStr(const u_char* addr) +StringValPtr ARP_Analyzer::ToEthAddrStr(const u_char* addr) { char buf[1024]; snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", diff --git a/src/analyzer/protocol/arp/ARP.h b/src/analyzer/protocol/arp/ARP.h index fb710bc61f..a7d933d1ed 100644 --- a/src/analyzer/protocol/arp/ARP.h +++ b/src/analyzer/protocol/arp/ARP.h @@ -51,8 +51,8 @@ protected: [[deprecated("Remove in v4.1. Use ToEthAddrStr().")]] StringVal* EthAddrToStr(const u_char* addr); - zeek::IntrusivePtr ToAddrVal(const void* addr); - zeek::IntrusivePtr ToEthAddrStr(const u_char* addr); + AddrValPtr ToAddrVal(const void* addr); + StringValPtr ToEthAddrStr(const u_char* addr); void BadARP(const struct arp_pkthdr* hdr, const char* string); void Corrupted(const char* string); }; diff --git a/src/analyzer/protocol/asn1/asn1.pac b/src/analyzer/protocol/asn1/asn1.pac index b96b5e620a..ceb43920ef 100644 --- a/src/analyzer/protocol/asn1/asn1.pac +++ b/src/analyzer/protocol/asn1/asn1.pac @@ -3,12 +3,12 @@ %} %header{ - zeek::IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t); - zeek::IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t); - zeek::IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid); - zeek::IntrusivePtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid); - zeek::IntrusivePtr asn1_octet_string_to_val(const ASN1Encoding* s); - zeek::IntrusivePtr asn1_octet_string_to_val(const ASN1OctetString* s); + ValPtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t); + ValPtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t); + StringValPtr asn1_oid_to_val(const ASN1Encoding* oid); + StringValPtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid); + StringValPtr asn1_octet_string_to_val(const ASN1Encoding* s); + StringValPtr asn1_octet_string_to_val(const ASN1OctetString* s); %} ############################## ASN.1 Encodings @@ -102,12 +102,12 @@ function binary_to_int64(bs: bytestring): int64 %code{ -zeek::IntrusivePtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t) +ValPtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t) { return asn1_integer_to_val(i->encoding(), t); } -zeek::IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t) +ValPtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t) { auto v = binary_to_int64(i->content()); @@ -125,12 +125,12 @@ zeek::IntrusivePtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag } } -zeek::IntrusivePtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid) +StringValPtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid) { return asn1_oid_to_val(oid->encoding()); } -zeek::IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid) +StringValPtr asn1_oid_to_val(const ASN1Encoding* oid) { vector oid_components; vector > subidentifiers; @@ -194,12 +194,12 @@ zeek::IntrusivePtr asn1_oid_to_val(const ASN1Encoding* oid) return zeek::make_intrusive(rval); } -zeek::IntrusivePtr asn1_octet_string_to_val(const ASN1OctetString* s) +StringValPtr asn1_octet_string_to_val(const ASN1OctetString* s) { return asn1_octet_string_to_val(s->encoding()); } -zeek::IntrusivePtr asn1_octet_string_to_val(const ASN1Encoding* s) +StringValPtr asn1_octet_string_to_val(const ASN1Encoding* s) { bytestring const& bs = s->content(); return zeek::make_intrusive(bs.length(), reinterpret_cast(bs.data())); diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index 628a1fdbf7..4c1347ea50 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -15,11 +15,11 @@ using namespace analyzer::bittorrent; -static zeek::IntrusivePtr bt_tracker_headers; -static zeek::IntrusivePtr bittorrent_peer; -static zeek::IntrusivePtr bittorrent_peer_set; -static zeek::IntrusivePtr bittorrent_benc_value; -static zeek::IntrusivePtr bittorrent_benc_dir; +static zeek::TableTypePtr bt_tracker_headers; +static zeek::RecordTypePtr bittorrent_peer; +static zeek::TableTypePtr bittorrent_peer_set; +static zeek::RecordTypePtr bittorrent_benc_value; +static zeek::TableTypePtr bittorrent_benc_dir; BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) : tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c) diff --git a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac index 7cfe0ab250..8862c58ab8 100644 --- a/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac +++ b/src/analyzer/protocol/dce-rpc/dce_rpc-analyzer.pac @@ -83,7 +83,7 @@ refine connection DCE_RPC_Conn += { %{ if ( dce_rpc_bind_ack ) { - zeek::IntrusivePtr sec_addr; + StringValPtr sec_addr; // Remove the null from the end of the string if it's there. if ( ${bind.sec_addr}.length() > 0 && diff --git a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac index 4adb8ee1a4..7c4f88452e 100644 --- a/src/analyzer/protocol/dhcp/dhcp-analyzer.pac +++ b/src/analyzer/protocol/dhcp/dhcp-analyzer.pac @@ -1,8 +1,8 @@ refine flow DHCP_Flow += { %member{ - zeek::IntrusivePtr options; - zeek::IntrusivePtr all_options; + RecordValPtr options; + VectorValPtr all_options; %} %init{ diff --git a/src/analyzer/protocol/dhcp/dhcp-options.pac b/src/analyzer/protocol/dhcp/dhcp-options.pac index 6c35fb202f..3f5e0eb834 100644 --- a/src/analyzer/protocol/dhcp/dhcp-options.pac +++ b/src/analyzer/protocol/dhcp/dhcp-options.pac @@ -627,7 +627,7 @@ refine flow DHCP_Flow += { %{ auto client_id = zeek::make_intrusive(zeek::BifType::Record::DHCP::ClientID); client_id->Assign(0, val_mgr->Count(${v.client_id.hwtype})); - zeek::IntrusivePtr sv; + StringValPtr sv; if ( ${v.client_id.hwtype} == 0 ) sv = zeek::make_intrusive(${v.client_id.hwaddr}.length(), diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 9f370155d5..fdf73e8537 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -1260,7 +1260,7 @@ bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg, return true; } -static zeek::IntrusivePtr +static StringValPtr extract_char_string(analyzer::Analyzer* analyzer, const u_char*& data, int& len, int& rdlen) { @@ -1300,7 +1300,7 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, } auto char_strings = zeek::make_intrusive(zeek::id::string_vec); - zeek::IntrusivePtr char_string; + StringValPtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) char_strings->Assign(char_strings->Size(), std::move(char_string)); @@ -1328,7 +1328,7 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, } auto char_strings = zeek::make_intrusive(zeek::id::string_vec); - zeek::IntrusivePtr char_string; + StringValPtr char_string; while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) char_strings->Assign(char_strings->Size(), std::move(char_string)); @@ -1446,7 +1446,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query) skip_event = 0; } -zeek::IntrusivePtr DNS_MsgInfo::BuildHdrVal() +RecordValPtr DNS_MsgInfo::BuildHdrVal() { static auto dns_msg = zeek::id::find_type("dns_msg"); auto r = zeek::make_intrusive(dns_msg); @@ -1468,7 +1468,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildHdrVal() return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildAnswerVal() +RecordValPtr DNS_MsgInfo::BuildAnswerVal() { static auto dns_answer = zeek::id::find_type("dns_answer"); auto r = zeek::make_intrusive(dns_answer); @@ -1482,7 +1482,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildAnswerVal() return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() +RecordValPtr DNS_MsgInfo::BuildEDNS_Val() { // We have to treat the additional record type in EDNS differently // than a regular resource record. @@ -1518,7 +1518,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildEDNS_Val() return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) +RecordValPtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) { static auto dns_tsig_additional = zeek::id::find_type("dns_tsig_additional"); auto r = zeek::make_intrusive(dns_tsig_additional); @@ -1538,7 +1538,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) +RecordValPtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) { static auto dns_rrsig_rr = zeek::id::find_type("dns_rrsig_rr"); auto r = zeek::make_intrusive(dns_rrsig_rr); @@ -1559,7 +1559,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) +RecordValPtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) { static auto dns_dnskey_rr = zeek::id::find_type("dns_dnskey_rr"); auto r = zeek::make_intrusive(dns_dnskey_rr); @@ -1575,7 +1575,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) +RecordValPtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) { static auto dns_nsec3_rr = zeek::id::find_type("dns_nsec3_rr"); auto r = zeek::make_intrusive(dns_nsec3_rr); @@ -1595,7 +1595,7 @@ zeek::IntrusivePtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) return r; } -zeek::IntrusivePtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) +RecordValPtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) { static auto dns_ds_rr = zeek::id::find_type("dns_ds_rr"); auto r = zeek::make_intrusive(dns_ds_rr); diff --git a/src/analyzer/protocol/dns/DNS.h b/src/analyzer/protocol/dns/DNS.h index 63787b9da1..51875dc08d 100644 --- a/src/analyzer/protocol/dns/DNS.h +++ b/src/analyzer/protocol/dns/DNS.h @@ -165,7 +165,7 @@ struct NSEC3_DATA { BroString* nsec_salt; unsigned short nsec_hlen; BroString* nsec_hash; - zeek::IntrusivePtr bitmaps; + VectorValPtr bitmaps; }; struct DS_DATA { @@ -179,14 +179,14 @@ class DNS_MsgInfo { public: DNS_MsgInfo(DNS_RawMsgHdr* hdr, int is_query); - zeek::IntrusivePtr BuildHdrVal(); - zeek::IntrusivePtr BuildAnswerVal(); - zeek::IntrusivePtr BuildEDNS_Val(); - zeek::IntrusivePtr BuildTSIG_Val(struct TSIG_DATA*); - zeek::IntrusivePtr BuildRRSIG_Val(struct RRSIG_DATA*); - zeek::IntrusivePtr BuildDNSKEY_Val(struct DNSKEY_DATA*); - zeek::IntrusivePtr BuildNSEC3_Val(struct NSEC3_DATA*); - zeek::IntrusivePtr BuildDS_Val(struct DS_DATA*); + RecordValPtr BuildHdrVal(); + RecordValPtr BuildAnswerVal(); + RecordValPtr BuildEDNS_Val(); + RecordValPtr BuildTSIG_Val(struct TSIG_DATA*); + RecordValPtr BuildRRSIG_Val(struct RRSIG_DATA*); + RecordValPtr BuildDNSKEY_Val(struct DNSKEY_DATA*); + RecordValPtr BuildNSEC3_Val(struct NSEC3_DATA*); + RecordValPtr BuildDS_Val(struct DS_DATA*); int id; int opcode; ///< query type, see DNS_Opcode @@ -203,7 +203,7 @@ public: int arcount; ///< number of additional RRs int is_query; ///< whether it came from the session initiator - zeek::IntrusivePtr query_name; + StringValPtr query_name; RR_Type atype; int aclass; ///< normally = 1, inet uint32_t ttl; diff --git a/src/analyzer/protocol/ftp/functions.bif b/src/analyzer/protocol/ftp/functions.bif index aa6557baac..527d6cf370 100644 --- a/src/analyzer/protocol/ftp/functions.bif +++ b/src/analyzer/protocol/ftp/functions.bif @@ -4,7 +4,7 @@ type ftp_port: record; %%{ #include "Reporter.h" -static zeek::IntrusivePtr parse_port(const char* line) +static ValPtr parse_port(const char* line) { auto r = zeek::make_intrusive(zeek::BifType::Record::ftp_port); @@ -47,7 +47,7 @@ static zeek::IntrusivePtr parse_port(const char* line) return r; } -static zeek::IntrusivePtr parse_eftp(const char* line) +static ValPtr parse_eftp(const char* line) { auto r = zeek::make_intrusive(zeek::BifType::Record::ftp_port); diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index 24168e79ff..316dca5f52 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -4,7 +4,7 @@ %} %code{ -zeek::IntrusivePtr BuildGTPv1Hdr(const GTPv1_Header* pdu) +RecordValPtr BuildGTPv1Hdr(const GTPv1_Header* pdu) { auto rv = zeek::make_intrusive(zeek::BifType::Record::gtpv1_hdr); @@ -28,12 +28,12 @@ zeek::IntrusivePtr BuildGTPv1Hdr(const GTPv1_Header* pdu) return rv; } -static zeek::IntrusivePtr BuildIMSI(const InformationElement* ie) +static ValPtr BuildIMSI(const InformationElement* ie) { return val_mgr->Count(ie->imsi()->value()); } -static zeek::IntrusivePtr BuildRAI(const InformationElement* ie) +static ValPtr BuildRAI(const InformationElement* ie) { auto ev = zeek::make_intrusive(zeek::BifType::Record::gtp_rai); ev->Assign(0, val_mgr->Count(ie->rai()->mcc())); @@ -43,47 +43,47 @@ static zeek::IntrusivePtr BuildRAI(const InformationElement* ie) return ev; } -static zeek::IntrusivePtr BuildRecovery(const InformationElement* ie) +static ValPtr BuildRecovery(const InformationElement* ie) { return val_mgr->Count(ie->recovery()->restart_counter()); } -static zeek::IntrusivePtr BuildSelectionMode(const InformationElement* ie) +static ValPtr BuildSelectionMode(const InformationElement* ie) { return val_mgr->Count(ie->selection_mode()->mode()); } -static zeek::IntrusivePtr BuildTEID1(const InformationElement* ie) +static ValPtr BuildTEID1(const InformationElement* ie) { return val_mgr->Count(ie->teid1()->value()); } -static zeek::IntrusivePtr BuildTEID_ControlPlane(const InformationElement* ie) +static ValPtr BuildTEID_ControlPlane(const InformationElement* ie) { return val_mgr->Count(ie->teidcp()->value()); } -static zeek::IntrusivePtr BuildNSAPI(const InformationElement* ie) +static ValPtr BuildNSAPI(const InformationElement* ie) { return val_mgr->Count(ie->nsapi()->nsapi()); } -static zeek::IntrusivePtr BuildChargingCharacteristics(const InformationElement* ie) +static ValPtr BuildChargingCharacteristics(const InformationElement* ie) { return val_mgr->Count(ie->charging_characteristics()->value()); } -static zeek::IntrusivePtr BuildTraceReference(const InformationElement* ie) +static ValPtr BuildTraceReference(const InformationElement* ie) { return val_mgr->Count(ie->trace_reference()->value()); } -static zeek::IntrusivePtr BuildTraceType(const InformationElement* ie) +static ValPtr BuildTraceType(const InformationElement* ie) { return val_mgr->Count(ie->trace_type()->value()); } -zeek::IntrusivePtr BuildEndUserAddr(const InformationElement* ie) +ValPtr BuildEndUserAddr(const InformationElement* ie) { auto ev = zeek::make_intrusive(zeek::BifType::Record::gtp_end_user_addr); ev->Assign(0, val_mgr->Count(ie->end_user_addr()->pdp_type_org())); @@ -114,21 +114,21 @@ zeek::IntrusivePtr BuildEndUserAddr(const InformationElement* ie) return ev; } -zeek::IntrusivePtr BuildAccessPointName(const InformationElement* ie) +ValPtr BuildAccessPointName(const InformationElement* ie) { BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(), ie->ap_name()->value().length(), false); return zeek::make_intrusive(bs); } -zeek::IntrusivePtr BuildProtoConfigOptions(const InformationElement* ie) +ValPtr BuildProtoConfigOptions(const InformationElement* ie) { const u_char* d = (const u_char*) ie->proto_config_opts()->value().data(); int len = ie->proto_config_opts()->value().length(); return zeek::make_intrusive(new BroString(d, len, false)); } -zeek::IntrusivePtr BuildGSN_Addr(const InformationElement* ie) +ValPtr BuildGSN_Addr(const InformationElement* ie) { auto ev = zeek::make_intrusive(zeek::BifType::Record::gtp_gsn_addr); @@ -147,14 +147,14 @@ zeek::IntrusivePtr BuildGSN_Addr(const InformationElement* ie) return ev; } -zeek::IntrusivePtr BuildMSISDN(const InformationElement* ie) +ValPtr BuildMSISDN(const InformationElement* ie) { const u_char* d = (const u_char*) ie->msisdn()->value().data(); int len = ie->msisdn()->value().length(); return zeek::make_intrusive(new BroString(d, len, false)); } -zeek::IntrusivePtr BuildQoS_Profile(const InformationElement* ie) +ValPtr BuildQoS_Profile(const InformationElement* ie) { auto ev = zeek::make_intrusive(zeek::BifType::Record::gtp_qos_profile); @@ -167,28 +167,28 @@ zeek::IntrusivePtr BuildQoS_Profile(const InformationElement* ie) return ev; } -zeek::IntrusivePtr BuildTrafficFlowTemplate(const InformationElement* ie) +ValPtr BuildTrafficFlowTemplate(const InformationElement* ie) { const uint8* d = ie->traffic_flow_template()->value().data(); int len = ie->traffic_flow_template()->value().length(); return zeek::make_intrusive(new BroString((const u_char*) d, len, false)); } -zeek::IntrusivePtr BuildTriggerID(const InformationElement* ie) +ValPtr BuildTriggerID(const InformationElement* ie) { const uint8* d = ie->trigger_id()->value().data(); int len = ie->trigger_id()->value().length(); return zeek::make_intrusive(new BroString((const u_char*) d, len, false)); } -zeek::IntrusivePtr BuildOMC_ID(const InformationElement* ie) +ValPtr BuildOMC_ID(const InformationElement* ie) { const uint8* d = ie->omc_id()->value().data(); int len = ie->omc_id()->value().length(); return zeek::make_intrusive(new BroString((const u_char*) d, len, false)); } -zeek::IntrusivePtr BuildPrivateExt(const InformationElement* ie) +ValPtr BuildPrivateExt(const InformationElement* ie) { auto ev = zeek::make_intrusive(zeek::BifType::Record::gtp_private_extension); @@ -201,22 +201,22 @@ zeek::IntrusivePtr BuildPrivateExt(const InformationElement* ie) return ev; } -static zeek::IntrusivePtr BuildCause(const InformationElement* ie) +static ValPtr BuildCause(const InformationElement* ie) { return val_mgr->Count(ie->cause()->value()); } -static zeek::IntrusivePtr BuildReorderReq(const InformationElement* ie) +static ValPtr BuildReorderReq(const InformationElement* ie) { return val_mgr->Bool(ie->reorder_req()->req()); } -static zeek::IntrusivePtr BuildChargingID(const InformationElement* ie) +static ValPtr BuildChargingID(const InformationElement* ie) { return val_mgr->Count(ie->charging_id()->value());; } -zeek::IntrusivePtr BuildChargingGatewayAddr(const InformationElement* ie) +ValPtr BuildChargingGatewayAddr(const InformationElement* ie) { const uint8* d = ie->charging_gateway_addr()->value().data(); int len = ie->charging_gateway_addr()->value().length(); @@ -228,7 +228,7 @@ zeek::IntrusivePtr BuildChargingGatewayAddr(const InformationElement* ie) return nullptr; } -static zeek::IntrusivePtr BuildTeardownInd(const InformationElement* ie) +static ValPtr BuildTeardownInd(const InformationElement* ie) { return val_mgr->Bool(ie->teardown_ind()->ind()); } diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index cd2865cc60..34b23044fc 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -613,7 +613,7 @@ HTTP_Message::~HTTP_Message() delete [] entity_data_buffer; } -zeek::IntrusivePtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) +RecordValPtr HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { static auto http_message_stat = zeek::id::find_type("http_message_stat"); auto stat = zeek::make_intrusive(http_message_stat); @@ -1355,7 +1355,7 @@ void HTTP_Analyzer::HTTP_Event(const char* category, const char* detail) HTTP_Event(category, zeek::make_intrusive(detail)); } -void HTTP_Analyzer::HTTP_Event(const char* category, zeek::IntrusivePtr detail) +void HTTP_Analyzer::HTTP_Event(const char* category, StringValPtr detail) { if ( http_event ) // DEBUG_MSG("%.6f http_event\n", network_time); @@ -1365,8 +1365,8 @@ void HTTP_Analyzer::HTTP_Event(const char* category, zeek::IntrusivePtr -HTTP_Analyzer::TruncateURI(const zeek::IntrusivePtr& uri) +StringValPtr +HTTP_Analyzer::TruncateURI(const StringValPtr& uri) { const BroString* str = uri->AsString(); diff --git a/src/analyzer/protocol/http/HTTP.h b/src/analyzer/protocol/http/HTTP.h index 4cc9995222..91340bdfde 100644 --- a/src/analyzer/protocol/http/HTTP.h +++ b/src/analyzer/protocol/http/HTTP.h @@ -145,7 +145,7 @@ protected: HTTP_Entity* current_entity; - zeek::IntrusivePtr BuildMessageStat(bool interrupted, const char* msg); + RecordValPtr BuildMessageStat(bool interrupted, const char* msg); }; class HTTP_Analyzer final : public tcp::TCP_ApplicationAnalyzer { @@ -156,7 +156,7 @@ public: void HTTP_EntityData(bool is_orig, BroString* entity_data); void HTTP_MessageDone(bool is_orig, HTTP_Message* message); void HTTP_Event(const char* category, const char* detail); - void HTTP_Event(const char* category, zeek::IntrusivePtr detail); + void HTTP_Event(const char* category, StringValPtr detail); void SkipEntityData(bool is_orig); @@ -237,7 +237,7 @@ protected: int HTTP_ReplyCode(const char* code_str); int ExpectReplyMessageBody(); - zeek::IntrusivePtr TruncateURI(const zeek::IntrusivePtr& uri); + StringValPtr TruncateURI(const StringValPtr& uri); int request_state, reply_state; int num_requests, num_replies; @@ -257,19 +257,19 @@ protected: // in a reply. std::string upgrade_protocol; - zeek::IntrusivePtr request_method; + StringValPtr request_method; // request_URI is in the original form (may contain '%' // sequences). - zeek::IntrusivePtr request_URI; + StringValPtr request_URI; // unescaped_URI does not contain escaped sequences. - zeek::IntrusivePtr unescaped_URI; + StringValPtr unescaped_URI; - std::queue> unanswered_requests; + std::queue unanswered_requests; int reply_code; - zeek::IntrusivePtr reply_reason_phrase; + StringValPtr reply_reason_phrase; tcp::ContentLine_Analyzer* content_line_orig; tcp::ContentLine_Analyzer* content_line_resp; diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 11d057bdae..af6824f6f6 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -219,7 +219,7 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen, } } -zeek::IntrusivePtr +RecordValPtr ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, int icmpv6, const IP_Hdr* ip_hdr) { @@ -305,7 +305,7 @@ TransportProto ICMP_Analyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t* return proto; } -zeek::IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) +RecordValPtr ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) { const IP_Hdr ip_hdr_data((const struct ip*) data, false); const IP_Hdr* ip_hdr = &ip_hdr_data; @@ -372,7 +372,7 @@ zeek::IntrusivePtr ICMP_Analyzer::ExtractICMP4Context(int len, const return iprec; } -zeek::IntrusivePtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) +RecordValPtr ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) { int DF = 0, MF = 0, bad_hdr_len = 0; TransportProto proto = TRANSPORT_UNKNOWN; @@ -469,7 +469,7 @@ void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val) Analyzer::UpdateConnVal(conn_val); } -void ICMP_Analyzer::UpdateEndpointVal(const zeek::IntrusivePtr& endp_arg, bool is_orig) +void ICMP_Analyzer::UpdateEndpointVal(const ValPtr& endp_arg, bool is_orig) { Conn()->EnableStatusUpdateTimer(); @@ -722,7 +722,7 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp, ); } -zeek::IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) +VectorValPtr 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"); diff --git a/src/analyzer/protocol/icmp/ICMP.h b/src/analyzer/protocol/icmp/ICMP.h index 502f094a03..f102b64006 100644 --- a/src/analyzer/protocol/icmp/ICMP.h +++ b/src/analyzer/protocol/icmp/ICMP.h @@ -7,6 +7,7 @@ #include "net_util.h" class VectorVal; +using VectorValPtr = zeek::IntrusivePtr; namespace analyzer { namespace icmp { @@ -51,13 +52,13 @@ protected: void Describe(ODesc* d) const; - zeek::IntrusivePtr BuildICMPVal(const struct icmp* icmpp, int len, + RecordValPtr BuildICMPVal(const struct icmp* icmpp, int len, int icmpv6, const IP_Hdr* ip_hdr); void NextICMP4(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr ); - zeek::IntrusivePtr ExtractICMP4Context(int len, const u_char*& data); + RecordValPtr ExtractICMP4Context(int len, const u_char*& data); void Context4(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr); @@ -68,15 +69,15 @@ protected: void NextICMP6(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr ); - zeek::IntrusivePtr ExtractICMP6Context(int len, const u_char*& data); + RecordValPtr ExtractICMP6Context(int len, const u_char*& data); void Context6(double t, const struct icmp* icmpp, int len, int caplen, const u_char*& data, const IP_Hdr* ip_hdr); // RFC 4861 Neighbor Discover message options - zeek::IntrusivePtr BuildNDOptionsVal(int caplen, const u_char* data); + VectorValPtr BuildNDOptionsVal(int caplen, const u_char* data); - zeek::IntrusivePtr icmp_conn_val; + RecordValPtr icmp_conn_val; int type; int code; int request_len, reply_len; @@ -84,7 +85,7 @@ protected: RuleMatcherState matcher_state; private: - void UpdateEndpointVal(const zeek::IntrusivePtr& endp, bool is_orig); + void UpdateEndpointVal(const ValPtr& endp, bool is_orig); }; // Returns the counterpart type to the given type (e.g., the counterpart diff --git a/src/analyzer/protocol/krb/KRB.cc b/src/analyzer/protocol/krb/KRB.cc index 498911c1bf..dd882cd1cc 100644 --- a/src/analyzer/protocol/krb/KRB.cc +++ b/src/analyzer/protocol/krb/KRB.cc @@ -87,9 +87,9 @@ void KRB_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, } } -zeek::IntrusivePtr KRB_Analyzer::GetAuthenticationInfo(const BroString* principal, - const BroString* ciphertext, - const bro_uint_t enctype) +StringValPtr KRB_Analyzer::GetAuthenticationInfo(const BroString* principal, + const BroString* ciphertext, + const bro_uint_t enctype) { #ifdef USE_KRB5 if ( !krb_available ) diff --git a/src/analyzer/protocol/krb/KRB.h b/src/analyzer/protocol/krb/KRB.h index dde2110d5d..0539a9b8ec 100644 --- a/src/analyzer/protocol/krb/KRB.h +++ b/src/analyzer/protocol/krb/KRB.h @@ -25,9 +25,9 @@ public: static analyzer::Analyzer* Instantiate(Connection* conn) { return new KRB_Analyzer(conn); } - zeek::IntrusivePtr GetAuthenticationInfo(const BroString* principal, - const BroString* ciphertext, - const bro_uint_t enctype); + StringValPtr GetAuthenticationInfo(const BroString* principal, + const BroString* ciphertext, + const bro_uint_t enctype); protected: diff --git a/src/analyzer/protocol/krb/KRB_TCP.h b/src/analyzer/protocol/krb/KRB_TCP.h index 5f6718d854..31d076c83c 100644 --- a/src/analyzer/protocol/krb/KRB_TCP.h +++ b/src/analyzer/protocol/krb/KRB_TCP.h @@ -21,9 +21,9 @@ public: // Overriden from tcp::TCP_ApplicationAnalyzer. void EndpointEOF(bool is_orig) override; - zeek::IntrusivePtr GetAuthenticationInfo(const BroString* principal, - const BroString* ciphertext, - const bro_uint_t enctype) + StringValPtr GetAuthenticationInfo(const BroString* principal, + const BroString* ciphertext, + const bro_uint_t enctype) { return val_mgr->EmptyString(); } static analyzer::Analyzer* Instantiate(Connection* conn) diff --git a/src/analyzer/protocol/krb/krb-analyzer.pac b/src/analyzer/protocol/krb/krb-analyzer.pac index aa26e2d748..f2d97e813d 100644 --- a/src/analyzer/protocol/krb/krb-analyzer.pac +++ b/src/analyzer/protocol/krb/krb-analyzer.pac @@ -1,12 +1,12 @@ %header{ -zeek::IntrusivePtr proc_krb_kdc_options(const KRB_KDC_Options* opts); -zeek::IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer); +RecordValPtr proc_krb_kdc_options(const KRB_KDC_Options* opts); +RecordValPtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer); bool proc_error_arguments(RecordVal* rv, const std::vector* args, int64 error_code); %} %code{ -zeek::IntrusivePtr proc_krb_kdc_options(const KRB_KDC_Options* opts) +RecordValPtr proc_krb_kdc_options(const KRB_KDC_Options* opts) { auto rv = zeek::make_intrusive(zeek::BifType::Record::KRB::KDC_Options); @@ -27,7 +27,7 @@ zeek::IntrusivePtr proc_krb_kdc_options(const KRB_KDC_Options* opts) return rv; } -zeek::IntrusivePtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) +RecordValPtr proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) { auto rv = zeek::make_intrusive(zeek::BifType::Record::KRB::KDC_Request); @@ -201,7 +201,7 @@ refine connection KRB_Conn += { %{ bro_analyzer()->ProtocolConfirmation(); auto msg_type = binary_to_int64(${msg.msg_type.data.content}); - auto make_arg = [this, msg]() -> zeek::IntrusivePtr + auto make_arg = [this, msg]() -> RecordValPtr { auto rv = zeek::make_intrusive(zeek::BifType::Record::KRB::KDC_Response); diff --git a/src/analyzer/protocol/krb/krb-asn1.pac b/src/analyzer/protocol/krb/krb-asn1.pac index ad83f0c22c..a9c0101cd1 100644 --- a/src/analyzer/protocol/krb/krb-asn1.pac +++ b/src/analyzer/protocol/krb/krb-asn1.pac @@ -2,20 +2,20 @@ %include ../asn1/asn1.pac %header{ - zeek::IntrusivePtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs); - zeek::IntrusivePtr GetTimeFromAsn1(StringVal* atime, int64 usecs); + ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs); + ValPtr GetTimeFromAsn1(StringVal* atime, int64 usecs); %} %code{ -zeek::IntrusivePtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs) +ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs) { auto atime_bytestring = to_stringval(atime->time()); auto result = GetTimeFromAsn1(atime_bytestring.get(), usecs); return result; } -zeek::IntrusivePtr GetTimeFromAsn1(StringVal* atime, int64 usecs) +ValPtr GetTimeFromAsn1(StringVal* atime, int64 usecs) { time_t lResult = 0; diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 79a8877ae9..ed99231c18 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -7,11 +7,11 @@ %} %header{ -zeek::IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error); +VectorValPtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error); %} %code{ -zeek::IntrusivePtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) +VectorValPtr proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { auto vv = zeek::make_intrusive(zeek::id::find_type("KRB::Type_Value_Vector")); diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 9181a0e02b..fe3a00b814 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -1,19 +1,19 @@ # Fundamental KRB types %header{ -zeek::IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname); +ValPtr GetStringFromPrincipalName(const KRB_Principal_Name* pname); -zeek::IntrusivePtr proc_cipher_list(const Array* list); +VectorValPtr proc_cipher_list(const Array* list); -zeek::IntrusivePtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list); -zeek::IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr); +VectorValPtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list); +RecordValPtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr); -zeek::IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list); -zeek::IntrusivePtr proc_ticket(const KRB_Ticket* ticket); +VectorValPtr proc_tickets(const KRB_Ticket_Sequence* list); +RecordValPtr proc_ticket(const KRB_Ticket* ticket); %} %code{ -zeek::IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) +ValPtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) { if ( pname->data()->size() == 1 ) return to_stringval(pname->data()[0][0]->encoding()->content()); @@ -25,7 +25,7 @@ zeek::IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pna return zeek::make_intrusive("unknown"); } -zeek::IntrusivePtr proc_cipher_list(const Array* list) +VectorValPtr proc_cipher_list(const Array* list) { auto ciphers = zeek::make_intrusive(zeek::id::index_vec); for ( uint i = 0; i < list->data()->size(); ++i ) @@ -33,7 +33,7 @@ zeek::IntrusivePtr proc_cipher_list(const Array* list) return ciphers; } -zeek::IntrusivePtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) +VectorValPtr proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { auto addrs = zeek::make_intrusive(zeek::id::find_type("KRB::Host_Address_Vector")); @@ -45,7 +45,7 @@ zeek::IntrusivePtr proc_host_address_list(const BroAnalyzer a, const return addrs; } -zeek::IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) +RecordValPtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) { auto rv = zeek::make_intrusive(zeek::BifType::Record::KRB::Host_Address); const auto& addr_bytes = addr->address()->data()->content(); @@ -92,7 +92,7 @@ zeek::IntrusivePtr proc_host_address(const BroAnalyzer a, const KRB_H return rv; } -zeek::IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) +VectorValPtr proc_tickets(const KRB_Ticket_Sequence* list) { auto tickets = zeek::make_intrusive(zeek::id::find_type("KRB::Ticket_Vector")); @@ -105,7 +105,7 @@ zeek::IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) return tickets; } -zeek::IntrusivePtr proc_ticket(const KRB_Ticket* ticket) +RecordValPtr proc_ticket(const KRB_Ticket* ticket) { auto rv = zeek::make_intrusive(zeek::BifType::Record::KRB::Ticket); diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index de309f34b2..f7f462024f 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -45,13 +45,13 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) if ( ! re_skip_authentication ) { - zeek::IntrusivePtr skip_authentication = zeek::id::find_val("skip_authentication")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr direct_login_prompts = zeek::id::find_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr login_prompts = zeek::id::find_val("login_prompts")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr login_non_failure_msgs = zeek::id::find_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr login_failure_msgs = zeek::id::find_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr login_success_msgs = zeek::id::find_val("login_success_msgs")->AsTableVal()->ToPureListVal(); - zeek::IntrusivePtr login_timeouts = zeek::id::find_val("login_timeouts")->AsTableVal()->ToPureListVal(); + ListValPtr skip_authentication = zeek::id::find_val("skip_authentication")->AsTableVal()->ToPureListVal(); + ListValPtr direct_login_prompts = zeek::id::find_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); + ListValPtr login_prompts = zeek::id::find_val("login_prompts")->AsTableVal()->ToPureListVal(); + ListValPtr login_non_failure_msgs = zeek::id::find_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); + ListValPtr login_failure_msgs = zeek::id::find_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); + ListValPtr login_success_msgs = zeek::id::find_val("login_success_msgs")->AsTableVal()->ToPureListVal(); + ListValPtr login_timeouts = zeek::id::find_val("login_timeouts")->AsTableVal()->ToPureListVal(); #ifdef USE_PERFTOOLS_DEBUG HeapLeakChecker::Disabler disabler; diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index a7dfa0d7db..39e13d9bcb 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -117,17 +117,17 @@ StringVal* new_string_val(const char* data, const char* end_of_data) StringVal* new_string_val(const data_chunk_t buf) { return to_string_val(buf).release(); } -zeek::IntrusivePtr to_string_val(int length, const char* data) +StringValPtr to_string_val(int length, const char* data) { return zeek::make_intrusive(length, data); } -zeek::IntrusivePtr to_string_val(const char* data, const char* end_of_data) +StringValPtr to_string_val(const char* data, const char* end_of_data) { return zeek::make_intrusive(end_of_data - data, data); } -zeek::IntrusivePtr to_string_val(const data_chunk_t buf) +StringValPtr to_string_val(const data_chunk_t buf) { return to_string_val(buf.length, buf.data); } @@ -1301,7 +1301,7 @@ void MIME_Entity::DebugPrintHeaders() RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h) { return ToHeaderVal(h).release(); } -zeek::IntrusivePtr MIME_Message::ToHeaderVal(MIME_Header* h) +RecordValPtr MIME_Message::ToHeaderVal(MIME_Header* h) { static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); auto header_record = zeek::make_intrusive(mime_header_rec); @@ -1316,7 +1316,7 @@ zeek::IntrusivePtr MIME_Message::ToHeaderVal(MIME_Header* h) TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) { return ToHeaderTable(hlist).release(); } -zeek::IntrusivePtr MIME_Message::ToHeaderTable(MIME_HeaderList& hlist) +TableValPtr MIME_Message::ToHeaderTable(MIME_HeaderList& hlist) { static auto mime_header_list = zeek::id::find_type("mime_header_list"); auto t = zeek::make_intrusive(mime_header_list); diff --git a/src/analyzer/protocol/mime/MIME.h b/src/analyzer/protocol/mime/MIME.h index 4597b63da5..009d8d0aec 100644 --- a/src/analyzer/protocol/mime/MIME.h +++ b/src/analyzer/protocol/mime/MIME.h @@ -14,6 +14,9 @@ class TableVal; class StringVal; class Base64Converter; +using TableValPtr = zeek::IntrusivePtr; +using StringValPtr = zeek::IntrusivePtr; + namespace analyzer { namespace mime { // MIME: Multipurpose Internet Mail Extensions @@ -102,8 +105,8 @@ public: StringVal* ContentType() const { return content_type_str.get(); } [[deprecated("Remove in v4.1. Use GetContentSubType().")]] StringVal* ContentSubType() const { return content_subtype_str.get(); } - const zeek::IntrusivePtr& GetContentType() const { return content_type_str; } - const zeek::IntrusivePtr& GetContentSubType() const { return content_subtype_str; } + const StringValPtr& GetContentType() const { return content_type_str; } + const StringValPtr& GetContentSubType() const { return content_subtype_str; } int ContentTransferEncoding() const { return content_encoding; } protected: @@ -159,8 +162,8 @@ protected: int current_field_type; int need_to_parse_parameters; - zeek::IntrusivePtr content_type_str; - zeek::IntrusivePtr content_subtype_str; + StringValPtr content_type_str; + StringValPtr content_subtype_str; BroString* content_encoding_str; BroString* multipart_boundary; @@ -235,8 +238,8 @@ protected: [[deprecated("Remove in v4.1. Use ToHeaderTable().")]] TableVal* BuildHeaderTable(MIME_HeaderList& hlist); - zeek::IntrusivePtr ToHeaderVal(MIME_Header* h); - zeek::IntrusivePtr ToHeaderTable(MIME_HeaderList& hlist); + RecordValPtr ToHeaderVal(MIME_Header* h); + TableValPtr ToHeaderTable(MIME_HeaderList& hlist); }; class MIME_Mail final : public MIME_Message { @@ -281,9 +284,9 @@ extern StringVal* new_string_val(int length, const char* data); extern StringVal* new_string_val(const char* data, const char* end_of_data); [[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]] extern StringVal* new_string_val(const data_chunk_t buf); -extern zeek::IntrusivePtr to_string_val(int length, const char* data); -extern zeek::IntrusivePtr to_string_val(const char* data, const char* end_of_data); -extern zeek::IntrusivePtr to_string_val(const data_chunk_t buf); +extern StringValPtr to_string_val(int length, const char* data); +extern StringValPtr to_string_val(const char* data, const char* end_of_data); +extern StringValPtr to_string_val(const data_chunk_t buf); extern int fputs(data_chunk_t b, FILE* fp); extern bool istrequal(data_chunk_t s, const char* t); extern bool is_lws(char ch); diff --git a/src/analyzer/protocol/modbus/modbus-analyzer.pac b/src/analyzer/protocol/modbus/modbus-analyzer.pac index 968f28cd23..512210c85a 100644 --- a/src/analyzer/protocol/modbus/modbus-analyzer.pac +++ b/src/analyzer/protocol/modbus/modbus-analyzer.pac @@ -8,13 +8,13 @@ # %header{ - zeek::IntrusivePtr bytestring_to_coils(const bytestring& coils, uint quantity); - zeek::IntrusivePtr HeaderToVal(ModbusTCP_TransportHeader* header); - zeek::IntrusivePtr create_vector_of_count(); + VectorValPtr bytestring_to_coils(const bytestring& coils, uint quantity); + RecordValPtr HeaderToVal(ModbusTCP_TransportHeader* header); + VectorValPtr create_vector_of_count(); %} %code{ - zeek::IntrusivePtr bytestring_to_coils(const bytestring& coils, uint quantity) + VectorValPtr bytestring_to_coils(const bytestring& coils, uint quantity) { auto modbus_coils = zeek::make_intrusive(zeek::BifType::Vector::ModbusCoils); @@ -27,7 +27,7 @@ return modbus_coils; } - zeek::IntrusivePtr HeaderToVal(ModbusTCP_TransportHeader* header) + RecordValPtr HeaderToVal(ModbusTCP_TransportHeader* header) { auto modbus_header = zeek::make_intrusive(zeek::BifType::Record::ModbusHeaders); modbus_header->Assign(0, val_mgr->Count(header->tid())); @@ -37,7 +37,7 @@ return modbus_header; } - zeek::IntrusivePtr create_vector_of_count() + VectorValPtr create_vector_of_count() { auto vt = zeek::make_intrusive(zeek::base_type(zeek::TYPE_COUNT)); auto vv = zeek::make_intrusive(std::move(vt)); diff --git a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac index 9aa4d7b63d..2f8330be85 100644 --- a/src/analyzer/protocol/ntlm/ntlm-analyzer.pac +++ b/src/analyzer/protocol/ntlm/ntlm-analyzer.pac @@ -1,12 +1,12 @@ %header{ - zeek::IntrusivePtr filetime2brotime(uint64_t ts); - zeek::IntrusivePtr build_version_record(NTLM_Version* val); - zeek::IntrusivePtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val); + ValPtr filetime2brotime(uint64_t ts); + RecordValPtr build_version_record(NTLM_Version* val); + RecordValPtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val); %} %code{ // This is replicated from the SMB analyzer. :( - zeek::IntrusivePtr filetime2brotime(uint64_t ts) + ValPtr filetime2brotime(uint64_t ts) { double secs = (ts / 10000000.0); @@ -17,7 +17,7 @@ return bro_ts; } - zeek::IntrusivePtr build_version_record(NTLM_Version* val) + RecordValPtr build_version_record(NTLM_Version* val) { auto result = zeek::make_intrusive(zeek::BifType::Record::NTLM::Version); result->Assign(0, val_mgr->Count(${val.major_version})); @@ -28,7 +28,7 @@ return result; } - zeek::IntrusivePtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val) + RecordValPtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val) { auto flags = zeek::make_intrusive(zeek::BifType::Record::NTLM::NegotiateFlags); flags->Assign(0, val_mgr->Bool(${val.negotiate_56})); diff --git a/src/analyzer/protocol/ntp/ntp-analyzer.pac b/src/analyzer/protocol/ntp/ntp-analyzer.pac index 68704fe86b..aaa7764dbd 100644 --- a/src/analyzer/protocol/ntp/ntp-analyzer.pac +++ b/src/analyzer/protocol/ntp/ntp-analyzer.pac @@ -8,23 +8,23 @@ %} %header{ - zeek::IntrusivePtr proc_ntp_short(const NTP_Short_Time* t); - zeek::IntrusivePtr proc_ntp_timestamp(const NTP_Time* t); - zeek::IntrusivePtr BuildNTPStdMsg(NTP_std_msg* nsm); - zeek::IntrusivePtr BuildNTPControlMsg(NTP_control_msg* ncm); - zeek::IntrusivePtr BuildNTPMode7Msg(NTP_mode7_msg* m7); + ValPtr proc_ntp_short(const NTP_Short_Time* t); + ValPtr proc_ntp_timestamp(const NTP_Time* t); + RecordValPtr BuildNTPStdMsg(NTP_std_msg* nsm); + RecordValPtr BuildNTPControlMsg(NTP_control_msg* ncm); + RecordValPtr BuildNTPMode7Msg(NTP_mode7_msg* m7); %} %code{ - zeek::IntrusivePtr proc_ntp_short(const NTP_Short_Time* t) + ValPtr proc_ntp_short(const NTP_Short_Time* t) { if ( t->seconds() == 0 && t->fractions() == 0 ) return zeek::make_intrusive(0.0); return zeek::make_intrusive(t->seconds() + t->fractions()*FRAC_16); } - zeek::IntrusivePtr proc_ntp_timestamp(const NTP_Time* t) + ValPtr proc_ntp_timestamp(const NTP_Time* t) { if ( t->seconds() == 0 && t->fractions() == 0) return zeek::make_intrusive(0.0); @@ -32,7 +32,7 @@ } // This builds the standard msg record - zeek::IntrusivePtr BuildNTPStdMsg(NTP_std_msg* nsm) + RecordValPtr BuildNTPStdMsg(NTP_std_msg* nsm) { auto rv = zeek::make_intrusive(zeek::BifType::Record::NTP::StandardMessage); @@ -85,7 +85,7 @@ } // This builds the control msg record - zeek::IntrusivePtr BuildNTPControlMsg(NTP_control_msg* ncm) + RecordValPtr BuildNTPControlMsg(NTP_control_msg* ncm) { auto rv = zeek::make_intrusive(zeek::BifType::Record::NTP::ControlMessage); @@ -110,7 +110,7 @@ } // This builds the mode7 msg record - zeek::IntrusivePtr BuildNTPMode7Msg(NTP_mode7_msg* m7) + RecordValPtr BuildNTPMode7Msg(NTP_mode7_msg* m7) { auto rv = zeek::make_intrusive(zeek::BifType::Record::NTP::Mode7Message); diff --git a/src/analyzer/protocol/radius/radius-analyzer.pac b/src/analyzer/protocol/radius/radius-analyzer.pac index d1885e3bad..7822e8e1d4 100644 --- a/src/analyzer/protocol/radius/radius-analyzer.pac +++ b/src/analyzer/protocol/radius/radius-analyzer.pac @@ -22,7 +22,7 @@ refine flow RADIUS_Flow += { // Do we already have a vector of attributes for this type? auto current = attributes->FindOrDefault(index); - zeek::IntrusivePtr val = to_stringval(${msg.attributes[i].value}); + ValPtr val = to_stringval(${msg.attributes[i].value}); if ( current ) { diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index 58f0d74cd9..64201c7f24 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -22,7 +22,7 @@ bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) uint32_t proc = c->Proc(); // The call arguments, depends on the call type obviously ... - zeek::IntrusivePtr callarg; + RecordValPtr callarg; switch ( proc ) { case BifEnum::MOUNT3::PROC_NULL: @@ -69,7 +69,7 @@ bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_statu double last_time, int reply_len) { EventHandlerPtr event = nullptr; - zeek::IntrusivePtr reply; + ValPtr reply; BifEnum::MOUNT3::status_t mount_status = BifEnum::MOUNT3::MNT3_OK; bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); @@ -203,14 +203,14 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, return vl; } -zeek::IntrusivePtr MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) +EnumValPtr MOUNT_Interp::mount3_auth_flavor(const u_char*& buf, int& n) { BifEnum::MOUNT3::auth_flavor_t t = (BifEnum::MOUNT3::auth_flavor_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t); return rval; } -zeek::IntrusivePtr MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) +StringValPtr MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) { int fh_n; const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); @@ -221,7 +221,7 @@ zeek::IntrusivePtr MOUNT_Interp::mount3_fh(const u_char*& buf, int& n return zeek::make_intrusive(new BroString(fh, fh_n, false)); } -zeek::IntrusivePtr MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) +StringValPtr MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) { int name_len; const u_char* name = extract_XDR_opaque(buf, n, name_len); @@ -232,15 +232,15 @@ zeek::IntrusivePtr MOUNT_Interp::mount3_filename(const u_char*& buf, return zeek::make_intrusive(new BroString(name, name_len, false)); } -zeek::IntrusivePtr MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) +RecordValPtr MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) { auto dirmntargs = zeek::make_intrusive(zeek::BifType::Record::MOUNT3::dirmntargs_t); dirmntargs->Assign(0, mount3_filename(buf, n)); return dirmntargs; } -zeek::IntrusivePtr MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, - BifEnum::MOUNT3::status_t status) +RecordValPtr MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, + BifEnum::MOUNT3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::MOUNT3::mnt_reply_t); diff --git a/src/analyzer/protocol/rpc/MOUNT.h b/src/analyzer/protocol/rpc/MOUNT.h index b275cd2eaa..ab062ae712 100644 --- a/src/analyzer/protocol/rpc/MOUNT.h +++ b/src/analyzer/protocol/rpc/MOUNT.h @@ -29,12 +29,12 @@ protected: // to 0. However, the methods might still return an allocated Val * ! // So, you might want to Unref() the Val if buf is 0. Method names // are based on the type names of RFC 1813. - zeek::IntrusivePtr mount3_auth_flavor(const u_char*& buf, int& n); - zeek::IntrusivePtr mount3_fh(const u_char*& buf, int& n); - zeek::IntrusivePtr mount3_dirmntargs(const u_char*&buf, int &n); - zeek::IntrusivePtr mount3_filename(const u_char*& buf, int& n); + EnumValPtr mount3_auth_flavor(const u_char*& buf, int& n); + StringValPtr mount3_fh(const u_char*& buf, int& n); + RecordValPtr mount3_dirmntargs(const u_char*&buf, int &n); + StringValPtr mount3_filename(const u_char*& buf, int& n); - zeek::IntrusivePtr mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status); + RecordValPtr mount3_mnt_reply(const u_char*& buf, int& n, BifEnum::MOUNT3::status_t status); }; class MOUNT_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index 394d3a39e1..281067a0c1 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -22,7 +22,7 @@ bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) uint32_t proc = c->Proc(); // The call arguments, depends on the call type obviously ... - zeek::IntrusivePtr callarg; + ValPtr callarg; switch ( proc ) { case BifEnum::NFS3::PROC_NULL: @@ -124,7 +124,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, double last_time, int reply_len) { EventHandlerPtr event = nullptr; - zeek::IntrusivePtr reply; + ValPtr reply; BifEnum::NFS3::status_t nfs_status = BifEnum::NFS3::NFS3ERR_OK; bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); @@ -278,7 +278,7 @@ bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, return true; } -zeek::IntrusivePtr NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) +StringValPtr NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) { int data_n; @@ -336,7 +336,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ return vl; } -zeek::IntrusivePtr NFS_Interp::nfs3_fh(const u_char*& buf, int& n) +StringValPtr NFS_Interp::nfs3_fh(const u_char*& buf, int& n) { int fh_n; const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); @@ -348,7 +348,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_fh(const u_char*& buf, int& n) } -zeek::IntrusivePtr NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) { auto attrs = zeek::make_intrusive(zeek::BifType::Record::NFS3::sattr_t); @@ -379,7 +379,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_sattr(const u_char*& buf, int& n) return attrs; } -zeek::IntrusivePtr NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::sattr_reply_t); @@ -397,7 +397,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_sattr_reply(const u_char*& buf, i return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) { auto attrs = zeek::make_intrusive(zeek::BifType::Record::NFS3::fattr_t); @@ -419,21 +419,21 @@ zeek::IntrusivePtr NFS_Interp::nfs3_fattr(const u_char*& buf, int& n) return attrs; } -zeek::IntrusivePtr NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) +EnumValPtr NFS_Interp::nfs3_time_how(const u_char*& buf, int& n) { BifEnum::NFS3::time_how_t t = (BifEnum::NFS3::time_how_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::time_how_t->GetVal(t); return rval; } -zeek::IntrusivePtr NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) +EnumValPtr NFS_Interp::nfs3_ftype(const u_char*& buf, int& n) { BifEnum::NFS3::file_type_t t = (BifEnum::NFS3::file_type_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::file_type_t->GetVal(t); return rval; } -zeek::IntrusivePtr NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& n) { auto attrs = zeek::make_intrusive(zeek::BifType::Record::NFS3::wcc_attr_t); @@ -444,7 +444,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int& return attrs; } -zeek::IntrusivePtr NFS_Interp::nfs3_filename(const u_char*& buf, int& n) +StringValPtr NFS_Interp::nfs3_filename(const u_char*& buf, int& n) { int name_len; const u_char* name = extract_XDR_opaque(buf, n, name_len); @@ -455,7 +455,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_filename(const u_char*& buf, int& return zeek::make_intrusive(new BroString(name, name_len, false)); } -zeek::IntrusivePtr NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) { auto diropargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::diropargs_t); @@ -465,7 +465,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_diropargs(const u_char*& buf, int return diropargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_symlinkdata(const u_char*& buf, int& n) { auto symlinkdata = zeek::make_intrusive(zeek::BifType::Record::NFS3::symlinkdata_t); @@ -475,7 +475,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_symlinkdata(const u_char*& buf, i return symlinkdata; } -zeek::IntrusivePtr NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_renameopargs(const u_char*& buf, int& n) { auto renameopargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::renameopargs_t); @@ -487,7 +487,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_renameopargs(const u_char*& buf, return renameopargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_post_op_attr(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_post_op_attr(const u_char*& buf, int& n) { int have_attrs = extract_XDR_uint32(buf, n); @@ -497,7 +497,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_post_op_attr(const u_char*& buf, return nullptr; } -zeek::IntrusivePtr NFS_Interp::nfs3_post_op_fh(const u_char*& buf, int& n) +StringValPtr NFS_Interp::nfs3_post_op_fh(const u_char*& buf, int& n) { int have_fh = extract_XDR_uint32(buf, n); @@ -507,7 +507,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_post_op_fh(const u_char*& buf, in return nullptr; } -zeek::IntrusivePtr NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, int& n) { int have_attrs = extract_XDR_uint32(buf, n); @@ -516,14 +516,14 @@ zeek::IntrusivePtr NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, i return nullptr; } -zeek::IntrusivePtr NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) +EnumValPtr NFS_Interp::nfs3_stable_how(const u_char*& buf, int& n) { BifEnum::NFS3::stable_how_t stable = (BifEnum::NFS3::stable_how_t)extract_XDR_uint32(buf, n); auto rval = zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable); return rval; } -zeek::IntrusivePtr NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::lookup_reply_t); @@ -542,7 +542,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_lookup_reply(const u_char*& buf, return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_readargs(const u_char*& buf, int& n) { auto readargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::readargs_t); @@ -553,7 +553,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_readargs(const u_char*& buf, int& return readargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, +RecordValPtr NFS_Interp::nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::read_reply_t); @@ -576,7 +576,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_read_reply(const u_char*& buf, in return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::readlink_reply_t); @@ -593,7 +593,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_readlink_reply(const u_char*& buf return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::link_reply_t); @@ -609,7 +609,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_link_reply(const u_char*& buf, in return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_symlinkargs(const u_char*& buf, int& n) { auto symlinkargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::symlinkargs_t); @@ -619,7 +619,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_symlinkargs(const u_char*& buf, i return symlinkargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_sattrargs(const u_char*& buf, int& n) { auto sattrargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::sattrargs_t); @@ -629,7 +629,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_sattrargs(const u_char*& buf, int return sattrargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_linkargs(const u_char*& buf, int& n) { auto linkargs = zeek::make_intrusive(zeek::BifType::Record::NFS3::linkargs_t); @@ -639,7 +639,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_linkargs(const u_char*& buf, int& return linkargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) { uint32_t bytes; uint64_t offset; @@ -657,7 +657,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_writeargs(const u_char*& buf, int return writeargs; } -zeek::IntrusivePtr NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::write_reply_t); @@ -682,7 +682,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_write_reply(const u_char*& buf, i return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) +RecordValPtr NFS_Interp::nfs3_newobj_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::newobj_reply_t); @@ -706,7 +706,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_newobj_reply(const u_char*& buf, return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_delobj_reply(const u_char*& buf, int& n) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::delobj_reply_t); @@ -717,7 +717,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_delobj_reply(const u_char*& buf, return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) +RecordValPtr NFS_Interp::nfs3_renameobj_reply(const u_char*& buf, int& n) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::renameobj_reply_t); @@ -730,7 +730,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_renameobj_reply(const u_char*& bu return rep; } -zeek::IntrusivePtr NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) +RecordValPtr NFS_Interp::nfs3_readdirargs(bool isplus, const u_char*& buf, int&n) { auto args = zeek::make_intrusive(zeek::BifType::Record::NFS3::readdirargs_t); @@ -746,7 +746,7 @@ zeek::IntrusivePtr NFS_Interp::nfs3_readdirargs(bool isplus, const u_ return args; } -zeek::IntrusivePtr NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, +RecordValPtr NFS_Interp::nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status) { auto rep = zeek::make_intrusive(zeek::BifType::Record::NFS3::readdir_reply_t); @@ -791,27 +791,27 @@ zeek::IntrusivePtr NFS_Interp::nfs3_readdir_reply(bool isplus, const return rep; } -zeek::IntrusivePtr NFS_Interp::ExtractUint32(const u_char*& buf, int& n) +ValPtr NFS_Interp::ExtractUint32(const u_char*& buf, int& n) { return val_mgr->Count(extract_XDR_uint32(buf, n)); } -zeek::IntrusivePtr NFS_Interp::ExtractUint64(const u_char*& buf, int& n) +ValPtr NFS_Interp::ExtractUint64(const u_char*& buf, int& n) { return val_mgr->Count(extract_XDR_uint64(buf, n)); } -zeek::IntrusivePtr NFS_Interp::ExtractTime(const u_char*& buf, int& n) +ValPtr NFS_Interp::ExtractTime(const u_char*& buf, int& n) { return zeek::make_intrusive(extract_XDR_time(buf, n)); } -zeek::IntrusivePtr NFS_Interp::ExtractInterval(const u_char*& buf, int& n) +ValPtr NFS_Interp::ExtractInterval(const u_char*& buf, int& n) { return zeek::make_intrusive(double(extract_XDR_uint32(buf, n)), 1.0); } -zeek::IntrusivePtr NFS_Interp::ExtractBool(const u_char*& buf, int& n) +ValPtr NFS_Interp::ExtractBool(const u_char*& buf, int& n) { return val_mgr->Bool(extract_XDR_uint32(buf, n)); } diff --git a/src/analyzer/protocol/rpc/NFS.h b/src/analyzer/protocol/rpc/NFS.h index ea3c9d2ae3..fee77490c3 100644 --- a/src/analyzer/protocol/rpc/NFS.h +++ b/src/analyzer/protocol/rpc/NFS.h @@ -30,53 +30,53 @@ protected: // to 0. However, the methods might still return an allocated Val * ! // So, you might want to Unref() the Val if buf is 0. Method names // are based on the type names of RFC 1813. - zeek::IntrusivePtr nfs3_fh(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_fattr(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_sattr(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_ftype(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_time_how(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_wcc_attr(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_diropargs(const u_char*&buf, int &n); - zeek::IntrusivePtr nfs3_symlinkdata(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_renameopargs(const u_char*&buf, int &n); - zeek::IntrusivePtr nfs3_filename(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_linkargs(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_symlinkargs(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_sattrargs(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_nfspath(const u_char*& buf, int& n) + StringValPtr nfs3_fh(const u_char*& buf, int& n); + RecordValPtr nfs3_fattr(const u_char*& buf, int& n); + RecordValPtr nfs3_sattr(const u_char*& buf, int& n); + EnumValPtr nfs3_ftype(const u_char*& buf, int& n); + EnumValPtr nfs3_time_how(const u_char*& buf, int& n); + RecordValPtr nfs3_wcc_attr(const u_char*& buf, int& n); + RecordValPtr nfs3_diropargs(const u_char*&buf, int &n); + RecordValPtr nfs3_symlinkdata(const u_char*& buf, int& n); + RecordValPtr nfs3_renameopargs(const u_char*&buf, int &n); + StringValPtr nfs3_filename(const u_char*& buf, int& n); + RecordValPtr nfs3_linkargs(const u_char*& buf, int& n); + RecordValPtr nfs3_symlinkargs(const u_char*& buf, int& n); + RecordValPtr nfs3_sattrargs(const u_char*& buf, int& n); + StringValPtr nfs3_nfspath(const u_char*& buf, int& n) { return nfs3_filename(buf,n); } - zeek::IntrusivePtr nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr - zeek::IntrusivePtr nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr - zeek::IntrusivePtr nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_readargs(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset); - zeek::IntrusivePtr nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_writeargs(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_stable_how(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_newobj_reply(const u_char*& buf, int&n, BifEnum::NFS3::status_t status); - zeek::IntrusivePtr nfs3_delobj_reply(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_renameobj_reply(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_post_op_fh(const u_char*& buf, int& n); - zeek::IntrusivePtr nfs3_readdirargs(bool isplus, const u_char*& buf, int&n); - zeek::IntrusivePtr nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr + RecordValPtr nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr + RecordValPtr nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_lookup_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_readargs(const u_char*& buf, int& n); + RecordValPtr nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset); + RecordValPtr nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_link_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_writeargs(const u_char*& buf, int& n); + EnumValPtr nfs3_stable_how(const u_char*& buf, int& n); + RecordValPtr nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_newobj_reply(const u_char*& buf, int&n, BifEnum::NFS3::status_t status); + RecordValPtr nfs3_delobj_reply(const u_char*& buf, int& n); + RecordValPtr nfs3_renameobj_reply(const u_char*& buf, int& n); + StringValPtr nfs3_post_op_fh(const u_char*& buf, int& n); + RecordValPtr nfs3_readdirargs(bool isplus, const u_char*& buf, int&n); + RecordValPtr nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status); // Consumes the file data in the RPC message. Depending on NFS::return_data* consts // in bro.init returns NULL or the data as string val: // * offset is the offset of the read/write call // * size is the amount of bytes read (or requested to be written), - zeek::IntrusivePtr nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size); + StringValPtr nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size); - zeek::IntrusivePtr ExtractUint32(const u_char*& buf, int& n); - zeek::IntrusivePtr ExtractUint64(const u_char*& buf, int& n); - zeek::IntrusivePtr ExtractTime(const u_char*& buf, int& n); - zeek::IntrusivePtr ExtractInterval(const u_char*& buf, int& n); - zeek::IntrusivePtr ExtractBool(const u_char*& buf, int& n); + ValPtr ExtractUint32(const u_char*& buf, int& n); + ValPtr ExtractUint64(const u_char*& buf, int& n); + ValPtr ExtractTime(const u_char*& buf, int& n); + ValPtr ExtractInterval(const u_char*& buf, int& n); + ValPtr ExtractBool(const u_char*& buf, int& n); }; class NFS_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 5cb9b484b9..4d9d57e341 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -79,7 +79,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu int reply_len) { EventHandlerPtr event; - zeek::IntrusivePtr reply; + ValPtr reply; int success = (status == BifEnum::RPC_SUCCESS); switch ( c->Proc() ) { @@ -189,7 +189,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu return true; } -zeek::IntrusivePtr PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) +ValPtr PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) { static auto pm_mapping = zeek::id::find_type("pm_mapping"); auto mapping = zeek::make_intrusive(pm_mapping); @@ -207,7 +207,7 @@ zeek::IntrusivePtr PortmapperInterp::ExtractMapping(const u_char*& buf, int return mapping; } -zeek::IntrusivePtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) +ValPtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) { static auto pm_port_request = zeek::id::find_type("pm_port_request"); auto pr = zeek::make_intrusive(pm_port_request); @@ -225,7 +225,7 @@ zeek::IntrusivePtr PortmapperInterp::ExtractPortRequest(const u_char*& buf, return pr; } -zeek::IntrusivePtr PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) +ValPtr PortmapperInterp::ExtractCallItRequest(const u_char*& buf, int& len) { static auto pm_callit_request = zeek::id::find_type("pm_callit_request"); auto c = zeek::make_intrusive(pm_callit_request); @@ -262,7 +262,7 @@ uint32_t PortmapperInterp::CheckPort(uint32_t port) return port; } -void PortmapperInterp::Event(EventHandlerPtr f, zeek::IntrusivePtr request, BifEnum::rpc_status status, zeek::IntrusivePtr reply) +void PortmapperInterp::Event(EventHandlerPtr f, ValPtr request, BifEnum::rpc_status status, ValPtr reply) { if ( ! f ) return; diff --git a/src/analyzer/protocol/rpc/Portmap.h b/src/analyzer/protocol/rpc/Portmap.h index 428ec87af3..dd783e22ae 100644 --- a/src/analyzer/protocol/rpc/Portmap.h +++ b/src/analyzer/protocol/rpc/Portmap.h @@ -17,11 +17,11 @@ protected: double last_time, int reply_len) override; uint32_t CheckPort(uint32_t port); - void Event(EventHandlerPtr f, zeek::IntrusivePtr request, BifEnum::rpc_status status, zeek::IntrusivePtr reply); + void Event(EventHandlerPtr f, ValPtr request, BifEnum::rpc_status status, ValPtr reply); - zeek::IntrusivePtr ExtractMapping(const u_char*& buf, int& len); - zeek::IntrusivePtr ExtractPortRequest(const u_char*& buf, int& len); - zeek::IntrusivePtr ExtractCallItRequest(const u_char*& buf, int& len); + ValPtr ExtractMapping(const u_char*& buf, int& len); + ValPtr ExtractPortRequest(const u_char*& buf, int& len); + ValPtr ExtractCallItRequest(const u_char*& buf, int& len); }; class Portmapper_Analyzer : public RPC_Analyzer { diff --git a/src/analyzer/protocol/rpc/RPC.h b/src/analyzer/protocol/rpc/RPC.h index c7d1648a01..a4f0fa20fd 100644 --- a/src/analyzer/protocol/rpc/RPC.h +++ b/src/analyzer/protocol/rpc/RPC.h @@ -52,9 +52,9 @@ public: double last_time, int rpc_len); ~RPC_CallInfo(); - void AddVal(zeek::IntrusivePtr arg_v) { v = std::move(arg_v); } - const zeek::IntrusivePtr& RequestVal() const { return v; } - zeek::IntrusivePtr TakeRequestVal() { auto rv = std::move(v); return rv; } + void AddVal(ValPtr arg_v) { v = std::move(arg_v); } + const ValPtr& RequestVal() const { return v; } + ValPtr TakeRequestVal() { auto rv = std::move(v); return rv; } bool CompareRexmit(const u_char* buf, int n) const; @@ -95,7 +95,7 @@ protected: int header_len; // size of data before the arguments bool valid_call; // whether call was well-formed - zeek::IntrusivePtr v; // single (perhaps compound) value corresponding to call + ValPtr v; // single (perhaps compound) value corresponding to call }; class RPC_Interpreter { diff --git a/src/analyzer/protocol/sip/sip-analyzer.pac b/src/analyzer/protocol/sip/sip-analyzer.pac index 8f08ed2bc7..2a8a2802d6 100644 --- a/src/analyzer/protocol/sip/sip-analyzer.pac +++ b/src/analyzer/protocol/sip/sip-analyzer.pac @@ -3,7 +3,7 @@ refine flow SIP_Flow += { %member{ int content_length; bool build_headers; - std::vector> headers; + std::vector headers; %} %init{ @@ -104,7 +104,7 @@ refine flow SIP_Flow += { %{ static auto mime_header_rec = zeek::id::find_type("mime_header_rec"); RecordVal* header_record = new RecordVal(mime_header_rec); - zeek::IntrusivePtr name_val; + StringValPtr name_val; if ( name.length() > 0 ) { diff --git a/src/analyzer/protocol/smb/smb-strings.pac b/src/analyzer/protocol/smb/smb-strings.pac index 42e9ab0416..fe7e2155d2 100644 --- a/src/analyzer/protocol/smb/smb-strings.pac +++ b/src/analyzer/protocol/smb/smb-strings.pac @@ -3,7 +3,7 @@ %} %code{ -zeek::IntrusivePtr binpac::SMB::SMB_Conn::uint8s_to_stringval(std::vector* data) +StringValPtr binpac::SMB::SMB_Conn::uint8s_to_stringval(std::vector* data) { int length = data->size(); auto buf = std::make_unique(length); @@ -15,7 +15,7 @@ zeek::IntrusivePtr binpac::SMB::SMB_Conn::uint8s_to_stringval(std::ve return utf16_to_utf8_val(bro_analyzer()->Conn(), bs); } -zeek::IntrusivePtr binpac::SMB::SMB_Conn::extract_string(SMB_string* s) +StringValPtr binpac::SMB::SMB_Conn::extract_string(SMB_string* s) { if ( s->unicode() == false ) { @@ -37,12 +37,12 @@ zeek::IntrusivePtr binpac::SMB::SMB_Conn::extract_string(SMB_string* return uint8s_to_stringval(s->u()->s()); } -zeek::IntrusivePtr binpac::SMB::SMB_Conn::smb_string2stringval(SMB_string* s) +StringValPtr binpac::SMB::SMB_Conn::smb_string2stringval(SMB_string* s) { return extract_string(s); } -zeek::IntrusivePtr binpac::SMB::SMB_Conn::smb2_string2stringval(SMB2_string* s) +StringValPtr binpac::SMB::SMB_Conn::smb2_string2stringval(SMB2_string* s) { return uint8s_to_stringval(s->s()); } @@ -50,10 +50,10 @@ zeek::IntrusivePtr binpac::SMB::SMB_Conn::smb2_string2stringval(SMB2_ refine connection SMB_Conn += { %member{ - zeek::IntrusivePtr uint8s_to_stringval(std::vector* data); - zeek::IntrusivePtr extract_string(SMB_string* s); - zeek::IntrusivePtr smb_string2stringval(SMB_string* s); - zeek::IntrusivePtr smb2_string2stringval(SMB2_string* s); + StringValPtr uint8s_to_stringval(std::vector* data); + StringValPtr extract_string(SMB_string* s); + StringValPtr smb_string2stringval(SMB_string* s); + StringValPtr smb2_string2stringval(SMB2_string* s); SMB_unicode_string* me; %} diff --git a/src/analyzer/protocol/smb/smb-time.pac b/src/analyzer/protocol/smb/smb-time.pac index f8a36476bb..ff5109edc1 100644 --- a/src/analyzer/protocol/smb/smb-time.pac +++ b/src/analyzer/protocol/smb/smb-time.pac @@ -1,13 +1,13 @@ %header{ -zeek::IntrusivePtr filetime2brotime(uint64_t ts); -zeek::IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz); +ValPtr filetime2brotime(uint64_t ts); +ValPtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz); -zeek::IntrusivePtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, +RecordValPtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, uint64_t create, uint64_t change); %} %code{ -zeek::IntrusivePtr filetime2brotime(uint64_t ts) +ValPtr filetime2brotime(uint64_t ts) { // Bro can't support times back to the 1600's // so we subtract a lot of seconds. @@ -15,7 +15,7 @@ zeek::IntrusivePtr filetime2brotime(uint64_t ts) return zeek::make_intrusive(secs); } -zeek::IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz) +ValPtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz) { tm lTime; lTime.tm_sec = ${t.two_seconds} * 2; @@ -29,7 +29,7 @@ zeek::IntrusivePtr time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz) return zeek::make_intrusive(lResult + tz); } -zeek::IntrusivePtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, +RecordValPtr SMB_BuildMACTimes(uint64_t modify, uint64_t access, uint64_t create, uint64_t change) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB::MACTimes); diff --git a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac index e63c601064..c0abbc23b2 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction-secondary.pac @@ -17,7 +17,7 @@ refine connection SMB_Conn += { auto parameters = zeek::make_intrusive(${val.parameters}.length(), (const char*)${val.parameters}.data()); - zeek::IntrusivePtr payload_str; + StringValPtr payload_str; SMB1_transaction_data* payload = nullptr; if ( ${val.data_count} > 0 ) diff --git a/src/analyzer/protocol/smb/smb1-com-transaction.pac b/src/analyzer/protocol/smb/smb1-com-transaction.pac index ba61ffd9f9..acf7fdeec6 100644 --- a/src/analyzer/protocol/smb/smb1-com-transaction.pac +++ b/src/analyzer/protocol/smb/smb1-com-transaction.pac @@ -5,7 +5,7 @@ enum Trans_subcommands { }; %code{ - zeek::IntrusivePtr SMB_Conn::transaction_data_to_val(SMB1_transaction_data* payload) + StringValPtr SMB_Conn::transaction_data_to_val(SMB1_transaction_data* payload) { switch ( payload->trans_type() ) { case SMB_PIPE: @@ -26,7 +26,7 @@ refine connection SMB_Conn += { %member{ map is_file_a_pipe; - static zeek::IntrusivePtr transaction_data_to_val(SMB1_transaction_data* payload); + static StringValPtr transaction_data_to_val(SMB1_transaction_data* payload); %} function get_is_file_a_pipe(id: uint16): bool @@ -55,7 +55,7 @@ refine connection SMB_Conn += { auto parameters = zeek::make_intrusive(${val.parameters}.length(), (const char*)${val.parameters}.data()); - zeek::IntrusivePtr payload_str; + StringValPtr payload_str; if ( ${val.data_count} > 0 ) payload_str = transaction_data_to_val(${val.data}); @@ -80,7 +80,7 @@ refine connection SMB_Conn += { auto parameters = zeek::make_intrusive(${val.parameters}.length(), (const char*)${val.parameters}.data()); - zeek::IntrusivePtr payload_str; + StringValPtr payload_str; if ( ${val.data_count} > 0 ) payload_str = transaction_data_to_val(${val.data[0]}); diff --git a/src/analyzer/protocol/smb/smb1-protocol.pac b/src/analyzer/protocol/smb/smb1-protocol.pac index 6f802f7742..6ef9caf51b 100644 --- a/src/analyzer/protocol/smb/smb1-protocol.pac +++ b/src/analyzer/protocol/smb/smb1-protocol.pac @@ -3,11 +3,11 @@ %} %header{ - zeek::IntrusivePtr SMBHeaderVal(SMB_Header* hdr); + RecordValPtr SMBHeaderVal(SMB_Header* hdr); %} %code{ - zeek::IntrusivePtr SMBHeaderVal(SMB_Header* hdr) + RecordValPtr SMBHeaderVal(SMB_Header* hdr) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB1::Header); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index 368a3f46f7..490b375c70 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -2,14 +2,14 @@ # http://msdn.microsoft.com/en-us/library/cc246497(v=PROT.13).aspx %header{ -zeek::IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr); -zeek::IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id); -zeek::IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val); -zeek::IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv); +RecordValPtr BuildSMB2HeaderVal(SMB2_Header* hdr); +RecordValPtr BuildSMB2GUID(SMB2_guid* file_id); +RecordValPtr smb2_file_attrs_to_bro(SMB2_file_attributes* val); +RecordValPtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv); %} %code{ -zeek::IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr) +RecordValPtr BuildSMB2HeaderVal(SMB2_Header* hdr) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB2::Header); r->Assign(0, val_mgr->Count(${hdr.credit_charge})); @@ -25,7 +25,7 @@ zeek::IntrusivePtr BuildSMB2HeaderVal(SMB2_Header* hdr) return r; } -zeek::IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id) +RecordValPtr BuildSMB2GUID(SMB2_guid* file_id) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB2::GUID); r->Assign(0, val_mgr->Count(${file_id.persistent})); @@ -33,7 +33,7 @@ zeek::IntrusivePtr BuildSMB2GUID(SMB2_guid* file_id) return r; } -zeek::IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) +RecordValPtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB2::FileAttrs); r->Assign(0, val_mgr->Bool(${val.read_only})); @@ -54,7 +54,7 @@ zeek::IntrusivePtr smb2_file_attrs_to_bro(SMB2_file_attributes* val) return r; } -zeek::IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) +RecordValPtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) { auto r = zeek::make_intrusive(zeek::BifType::Record::SMB2::NegotiateContextValue); diff --git a/src/analyzer/protocol/snmp/snmp-analyzer.pac b/src/analyzer/protocol/snmp/snmp-analyzer.pac index 8ab454088b..4ded91a635 100644 --- a/src/analyzer/protocol/snmp/snmp-analyzer.pac +++ b/src/analyzer/protocol/snmp/snmp-analyzer.pac @@ -8,26 +8,26 @@ %} %header{ -zeek::IntrusivePtr network_address_to_val(const ASN1Encoding* na); -zeek::IntrusivePtr network_address_to_val(const NetworkAddress* na); -zeek::IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj); +AddrValPtr network_address_to_val(const ASN1Encoding* na); +AddrValPtr network_address_to_val(const NetworkAddress* na); +ValPtr asn1_obj_to_val(const ASN1Encoding* obj); -zeek::IntrusivePtr build_hdr(const Header* header); -zeek::IntrusivePtr build_hdrV3(const Header* header); -zeek::IntrusivePtr build_bindings(const VarBindList* vbl); -zeek::IntrusivePtr build_pdu(const CommonPDU* pdu); -zeek::IntrusivePtr build_trap_pdu(const TrapPDU* pdu); -zeek::IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu); +RecordValPtr build_hdr(const Header* header); +RecordValPtr build_hdrV3(const Header* header); +VectorValPtr build_bindings(const VarBindList* vbl); +RecordValPtr build_pdu(const CommonPDU* pdu); +RecordValPtr build_trap_pdu(const TrapPDU* pdu); +RecordValPtr build_bulk_pdu(const GetBulkRequestPDU* pdu); %} %code{ -zeek::IntrusivePtr network_address_to_val(const NetworkAddress* na) +AddrValPtr network_address_to_val(const NetworkAddress* na) { return network_address_to_val(na->encoding()); } -zeek::IntrusivePtr network_address_to_val(const ASN1Encoding* na) +AddrValPtr network_address_to_val(const ASN1Encoding* na) { bytestring const& bs = na->content(); @@ -42,9 +42,9 @@ zeek::IntrusivePtr network_address_to_val(const ASN1Encoding* na) return zeek::make_intrusive(ntohl(network_order)); } -zeek::IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) +ValPtr asn1_obj_to_val(const ASN1Encoding* obj) { - zeek::IntrusivePtr rval = zeek::make_intrusive(zeek::BifType::Record::SNMP::ObjectValue); + RecordValPtr rval = zeek::make_intrusive(zeek::BifType::Record::SNMP::ObjectValue); uint8 tag = obj->meta()->tag(); rval->Assign(0, val_mgr->Count(tag)); @@ -85,12 +85,12 @@ zeek::IntrusivePtr asn1_obj_to_val(const ASN1Encoding* obj) return rval; } -zeek::IntrusivePtr time_ticks_to_val(const TimeTicks* tt) +ValPtr time_ticks_to_val(const TimeTicks* tt) { return asn1_integer_to_val(tt->asn1_integer(), zeek::TYPE_COUNT); } -zeek::IntrusivePtr build_hdr(const Header* header) +RecordValPtr build_hdr(const Header* header) { auto rv = zeek::make_intrusive(zeek::BifType::Record::SNMP::Header); rv->Assign(0, val_mgr->Count(header->version())); @@ -122,7 +122,7 @@ zeek::IntrusivePtr build_hdr(const Header* header) return rv; } -zeek::IntrusivePtr build_hdrV3(const Header* header) +RecordValPtr build_hdrV3(const Header* header) { auto v3 = zeek::make_intrusive(zeek::BifType::Record::SNMP::HeaderV3); const v3Header* v3hdr = header->v3(); @@ -151,7 +151,7 @@ zeek::IntrusivePtr build_hdrV3(const Header* header) return v3; } -zeek::IntrusivePtr build_bindings(const VarBindList* vbl) +VectorValPtr build_bindings(const VarBindList* vbl) { auto vv = zeek::make_intrusive(zeek::BifType::Vector::SNMP::Bindings); @@ -167,7 +167,7 @@ zeek::IntrusivePtr build_bindings(const VarBindList* vbl) return vv; } -zeek::IntrusivePtr build_pdu(const CommonPDU* pdu) +RecordValPtr build_pdu(const CommonPDU* pdu) { auto rv = zeek::make_intrusive(zeek::BifType::Record::SNMP::PDU); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); @@ -177,7 +177,7 @@ zeek::IntrusivePtr build_pdu(const CommonPDU* pdu) return rv; } -zeek::IntrusivePtr build_trap_pdu(const TrapPDU* pdu) +RecordValPtr build_trap_pdu(const TrapPDU* pdu) { auto rv = zeek::make_intrusive(zeek::BifType::Record::SNMP::TrapPDU); rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); @@ -189,7 +189,7 @@ zeek::IntrusivePtr build_trap_pdu(const TrapPDU* pdu) return rv; } -zeek::IntrusivePtr build_bulk_pdu(const GetBulkRequestPDU* pdu) +RecordValPtr build_bulk_pdu(const GetBulkRequestPDU* pdu) { auto rv = zeek::make_intrusive(zeek::BifType::Record::SNMP::BulkPDU); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); diff --git a/src/analyzer/protocol/socks/socks-analyzer.pac b/src/analyzer/protocol/socks/socks-analyzer.pac index 6aa9da8aac..3509621b20 100644 --- a/src/analyzer/protocol/socks/socks-analyzer.pac +++ b/src/analyzer/protocol/socks/socks-analyzer.pac @@ -1,10 +1,10 @@ %header{ -zeek::IntrusivePtr array_to_string(vector *a); +StringValPtr array_to_string(vector *a); %} %code{ -zeek::IntrusivePtr array_to_string(vector *a) +StringValPtr array_to_string(vector *a) { int len = a->size(); auto tmp = std::make_unique(len); diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index f400b60f04..de770a0ade 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -5,12 +5,12 @@ %} %header{ -zeek::IntrusivePtr name_list_to_vector(const bytestring& nl); +VectorValPtr name_list_to_vector(const bytestring& nl); %} %code{ // Copied from IRC_Analyzer::SplitWords -zeek::IntrusivePtr name_list_to_vector(const bytestring& nl) +VectorValPtr name_list_to_vector(const bytestring& nl) { auto vv = zeek::make_intrusive(zeek::id::string_vec); diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index dbbfec478c..35fd0eadfa 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1358,7 +1358,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto option_list = zeek::make_intrusive(zeek::BifType::Vector::TCP::OptionList); - auto add_option_data = [](const zeek::IntrusivePtr& rv, const u_char* odata, int olen) + auto add_option_data = [](const RecordValPtr& rv, const u_char* odata, int olen) { if ( olen <= 2 ) return; @@ -1584,7 +1584,7 @@ void TCP_Analyzer::ConnDeleteTimer(double t) Conn()->DeleteTimer(t); } -void TCP_Analyzer::SetContentsFile(unsigned int direction, zeek::IntrusivePtr f) +void TCP_Analyzer::SetContentsFile(unsigned int direction, BroFilePtr f) { if ( direction == CONTENTS_NONE ) { @@ -1601,7 +1601,7 @@ void TCP_Analyzer::SetContentsFile(unsigned int direction, zeek::IntrusivePtr
TCP_Analyzer::GetContentsFile(unsigned int direction) const +BroFilePtr TCP_Analyzer::GetContentsFile(unsigned int direction) const { switch ( direction ) { case CONTENTS_NONE: diff --git a/src/analyzer/protocol/tcp/TCP.h b/src/analyzer/protocol/tcp/TCP.h index 364bd740e1..696d1d1526 100644 --- a/src/analyzer/protocol/tcp/TCP.h +++ b/src/analyzer/protocol/tcp/TCP.h @@ -60,8 +60,8 @@ public: // the test is whether it has any outstanding, un-acked data. bool DataPending(TCP_Endpoint* closing_endp); - void SetContentsFile(unsigned int direction, zeek::IntrusivePtr f) override; - zeek::IntrusivePtr GetContentsFile(unsigned int direction) const override; + void SetContentsFile(unsigned int direction, BroFilePtr f) override; + BroFilePtr GetContentsFile(unsigned int direction) const override; // From Analyzer.h void UpdateConnVal(RecordVal *conn_val) override; diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.cc b/src/analyzer/protocol/tcp/TCP_Endpoint.cc index 3d5eeb0817..1d0f787594 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.cc +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.cc @@ -254,7 +254,7 @@ void TCP_Endpoint::AckReceived(uint64_t seq) contents_processor->AckReceived(seq); } -void TCP_Endpoint::SetContentsFile(zeek::IntrusivePtr f) +void TCP_Endpoint::SetContentsFile(BroFilePtr f) { contents_file = std::move(f); contents_start_seq = ToRelativeSeqSpace(last_seq, seq_wraps); diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.h b/src/analyzer/protocol/tcp/TCP_Endpoint.h index 521859be96..960cee689c 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.h +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.h @@ -187,8 +187,8 @@ public: void AckReceived(uint64_t seq); - void SetContentsFile(zeek::IntrusivePtr f); - const zeek::IntrusivePtr& GetContentsFile() const { return contents_file; } + void SetContentsFile(BroFilePtr f); + const BroFilePtr& GetContentsFile() const { return contents_file; } // Codes used for tracking history. For responders, we shift these // over by 16 bits in order to fit both originator and responder @@ -211,7 +211,7 @@ public: TCP_Endpoint* peer; TCP_Reassembler* contents_processor; TCP_Analyzer* tcp_analyzer; - zeek::IntrusivePtr contents_file; + BroFilePtr contents_file; uint32_t checksum_base; double start_time, last_time; diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index f6278dcebb..63b37668aa 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -92,7 +92,7 @@ uint64_t TCP_Reassembler::NumUndeliveredBytes() const return last_block.upper - last_reassem_seq; } -void TCP_Reassembler::SetContentsFile(zeek::IntrusivePtr f) +void TCP_Reassembler::SetContentsFile(BroFilePtr f) { if ( ! f->IsOpen() ) { @@ -317,7 +317,7 @@ void TCP_Reassembler::MatchUndelivered(uint64_t up_to_seq, bool use_last_upper) } } -void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const zeek::IntrusivePtr& f) +void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const BroFilePtr& f) { auto it = block_list.Begin(); @@ -348,7 +348,7 @@ void TCP_Reassembler::RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const z RecordGap(last_seq, stop_seq, f); } -void TCP_Reassembler::RecordBlock(const DataBlock& b, const zeek::IntrusivePtr& f) +void TCP_Reassembler::RecordBlock(const DataBlock& b, const BroFilePtr& f) { if ( f->Write((const char*) b.block, b.Size()) ) return; @@ -363,7 +363,7 @@ void TCP_Reassembler::RecordBlock(const DataBlock& b, const zeek::IntrusivePtr& f) +void TCP_Reassembler::RecordGap(uint64_t start_seq, uint64_t upper_seq, const BroFilePtr& f) { if ( f->Write(fmt("\n<>\n", upper_seq - start_seq)) ) return; diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.h b/src/analyzer/protocol/tcp/TCP_Reassembler.h index b7f0327f07..7470e1b6bf 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.h +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.h @@ -49,8 +49,8 @@ public: // from waiting_on_hole above; and is computed in a different fashion). uint64_t NumUndeliveredBytes() const; - void SetContentsFile(zeek::IntrusivePtr f); - const zeek::IntrusivePtr& GetContentsFile() const { return record_contents_file; } + void SetContentsFile(BroFilePtr f); + const BroFilePtr& GetContentsFile() const { return record_contents_file; } void MatchUndelivered(uint64_t up_to_seq, bool use_last_upper); @@ -89,9 +89,9 @@ private: void Undelivered(uint64_t up_to_seq) override; void Gap(uint64_t seq, uint64_t len); - void RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const zeek::IntrusivePtr& f); - void RecordBlock(const DataBlock& b, const zeek::IntrusivePtr& f); - void RecordGap(uint64_t start_seq, uint64_t upper_seq, const zeek::IntrusivePtr& f); + void RecordToSeq(uint64_t start_seq, uint64_t stop_seq, const BroFilePtr& f); + void RecordBlock(const DataBlock& b, const BroFilePtr& f); + void RecordGap(uint64_t start_seq, uint64_t upper_seq, const BroFilePtr& f); void BlockInserted(DataBlockMap::const_iterator it) override; void Overlap(const u_char* b1, const u_char* b2, uint64_t n) override; @@ -108,7 +108,7 @@ private: bool in_delivery; analyzer::tcp::TCP_Flags flags; - zeek::IntrusivePtr record_contents_file; // file on which to reassemble contents + BroFilePtr record_contents_file; // file on which to reassemble contents Analyzer* dst_analyzer; TCP_Analyzer* tcp_analyzer; diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index e5feec521a..5c546ffc25 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -96,7 +96,7 @@ bool TeredoEncapsulation::DoParse(const u_char* data, int& len, return false; } -zeek::IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const +RecordValPtr 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"); @@ -194,7 +194,7 @@ void Teredo_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, return; } - zeek::IntrusivePtr teredo_hdr; + ValPtr teredo_hdr; if ( teredo_packet ) { diff --git a/src/analyzer/protocol/teredo/Teredo.h b/src/analyzer/protocol/teredo/Teredo.h index 4a13ee6f5d..c80bef0905 100644 --- a/src/analyzer/protocol/teredo/Teredo.h +++ b/src/analyzer/protocol/teredo/Teredo.h @@ -74,7 +74,7 @@ public: const u_char* Authentication() const { return auth; } - zeek::IntrusivePtr BuildVal(const IP_Hdr* inner) const; + RecordValPtr BuildVal(const IP_Hdr* inner) const; protected: bool DoParse(const u_char* data, int& len, bool found_orig, bool found_au); diff --git a/src/binpac_bro-lib.pac b/src/binpac_bro-lib.pac index b2398d1e4b..ead66b5d0b 100644 --- a/src/binpac_bro-lib.pac +++ b/src/binpac_bro-lib.pac @@ -7,7 +7,7 @@ %} %code{ -zeek::IntrusivePtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16) +StringValPtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16) { std::string resultstring; diff --git a/src/binpac_bro.h b/src/binpac_bro.h index 49dddf56b4..004f8e4e6a 100644 --- a/src/binpac_bro.h +++ b/src/binpac_bro.h @@ -35,12 +35,12 @@ inline StringVal* bytestring_to_val(const_bytestring const &str) return new StringVal(str.length(), (const char*) str.begin()); } -inline zeek::IntrusivePtr to_stringval(const_bytestring const& str) +inline StringValPtr to_stringval(const_bytestring const& str) { return zeek::make_intrusive(str.length(), (const char*) str.begin()); } -zeek::IntrusivePtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16); +StringValPtr utf16_to_utf8_val(Connection* conn, const bytestring& utf16); [[deprecated("Remove in v4.1. Use utf16_to_utf8_val() instead.")]] StringVal* utf16_bytestring_to_utf8_val(Connection* conn, const bytestring& utf16); diff --git a/src/broker/Data.cc b/src/broker/Data.cc index c686fc8abf..8104d20de2 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -14,11 +14,11 @@ using namespace std; -zeek::IntrusivePtr bro_broker::opaque_of_data_type; -zeek::IntrusivePtr bro_broker::opaque_of_set_iterator; -zeek::IntrusivePtr bro_broker::opaque_of_table_iterator; -zeek::IntrusivePtr bro_broker::opaque_of_vector_iterator; -zeek::IntrusivePtr bro_broker::opaque_of_record_iterator; +zeek::OpaqueTypePtr bro_broker::opaque_of_data_type; +zeek::OpaqueTypePtr bro_broker::opaque_of_set_iterator; +zeek::OpaqueTypePtr bro_broker::opaque_of_table_iterator; +zeek::OpaqueTypePtr bro_broker::opaque_of_vector_iterator; +zeek::OpaqueTypePtr bro_broker::opaque_of_record_iterator; static bool data_type_check(const broker::data& d, zeek::Type* t); @@ -73,7 +73,7 @@ TEST_CASE("converting Broker to Zeek protocol constants") } struct val_converter { - using result_type = zeek::IntrusivePtr; + using result_type = ValPtr; zeek::Type* type; @@ -779,7 +779,7 @@ static bool data_type_check(const broker::data& d, zeek::Type* t) return caf::visit(type_checker{t}, d); } -zeek::IntrusivePtr bro_broker::data_to_val(broker::data d, zeek::Type* type) +ValPtr bro_broker::data_to_val(broker::data d, zeek::Type* type) { if ( type->Tag() == zeek::TYPE_ANY ) return bro_broker::make_data_val(move(d)); @@ -1010,7 +1010,7 @@ broker::expected bro_broker::val_to_data(const Val* v) return broker::ec::invalid_data; } -zeek::IntrusivePtr bro_broker::make_data_val(Val* v) +RecordValPtr bro_broker::make_data_val(Val* v) { auto rval = zeek::make_intrusive(zeek::BifType::Record::Broker::Data); auto data = val_to_data(v); @@ -1023,7 +1023,7 @@ zeek::IntrusivePtr bro_broker::make_data_val(Val* v) return rval; } -zeek::IntrusivePtr bro_broker::make_data_val(broker::data d) +RecordValPtr bro_broker::make_data_val(broker::data d) { auto rval = zeek::make_intrusive(zeek::BifType::Record::Broker::Data); rval->Assign(0, zeek::make_intrusive(move(d))); @@ -1031,7 +1031,7 @@ zeek::IntrusivePtr bro_broker::make_data_val(broker::data d) } struct data_type_getter { - using result_type = zeek::IntrusivePtr; + using result_type = EnumValPtr; result_type operator()(broker::none) { @@ -1112,7 +1112,7 @@ struct data_type_getter { } }; -zeek::IntrusivePtr bro_broker::get_data_type(RecordVal* v, Frame* frame) +EnumValPtr bro_broker::get_data_type(RecordVal* v, Frame* frame) { return caf::visit(data_type_getter{}, opaque_field_to_data(v, frame)); } @@ -1142,12 +1142,12 @@ bool bro_broker::DataVal::canCastTo(zeek::Type* t) const return data_type_check(data, t); } -zeek::IntrusivePtr bro_broker::DataVal::castTo(zeek::Type* t) +ValPtr bro_broker::DataVal::castTo(zeek::Type* t) { return data_to_val(data, t); } -const zeek::IntrusivePtr& bro_broker::DataVal::ScriptDataType() +const zeek::TypePtr& bro_broker::DataVal::ScriptDataType() { static auto script_data_type = zeek::id::find_type("Broker::Data"); return script_data_type; diff --git a/src/broker/Data.h b/src/broker/Data.h index 1b6ec33148..2d8d6f6a9b 100644 --- a/src/broker/Data.h +++ b/src/broker/Data.h @@ -5,9 +5,6 @@ #include "Frame.h" #include "Expr.h" -template -class IntrusivePtr; - class ODesc; namespace threading { @@ -17,11 +14,11 @@ struct Field; namespace bro_broker { -extern zeek::IntrusivePtr opaque_of_data_type; -extern zeek::IntrusivePtr opaque_of_set_iterator; -extern zeek::IntrusivePtr opaque_of_table_iterator; -extern zeek::IntrusivePtr opaque_of_vector_iterator; -extern zeek::IntrusivePtr opaque_of_record_iterator; +extern zeek::OpaqueTypePtr opaque_of_data_type; +extern zeek::OpaqueTypePtr opaque_of_set_iterator; +extern zeek::OpaqueTypePtr opaque_of_table_iterator; +extern zeek::OpaqueTypePtr opaque_of_vector_iterator; +extern zeek::OpaqueTypePtr opaque_of_record_iterator; /** * Convert a broker port protocol to a bro port protocol. @@ -34,14 +31,14 @@ TransportProto to_bro_port_proto(broker::port::protocol tp); * @return a Broker::Data value, where the optional field is set if the conversion * was possible, else it is unset. */ -zeek::IntrusivePtr make_data_val(Val* v); +RecordValPtr make_data_val(Val* v); /** * Create a Broker::Data value from a Broker data value. * @param d the Broker value to wrap in an opaque type. * @return a Broker::Data value that wraps the Broker value. */ -zeek::IntrusivePtr make_data_val(broker::data d); +RecordValPtr make_data_val(broker::data d); /** * Get the type of Broker data that Broker::Data wraps. @@ -49,7 +46,7 @@ zeek::IntrusivePtr make_data_val(broker::data d); * @param frame used to get location info upon error. * @return a Broker::DataType value. */ -zeek::IntrusivePtr get_data_type(RecordVal* v, Frame* frame); +EnumValPtr get_data_type(RecordVal* v, Frame* frame); /** * Convert a Bro value to a Broker data value. @@ -65,7 +62,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. */ -zeek::IntrusivePtr data_to_val(broker::data d, zeek::Type* type); +ValPtr data_to_val(broker::data d, zeek::Type* type); /** * Convert a Bro threading::Value to a Broker data value. @@ -109,13 +106,13 @@ public: void ValDescribe(ODesc* d) const override; - zeek::IntrusivePtr castTo(zeek::Type* t); + ValPtr 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 zeek::IntrusivePtr& ScriptDataType(); + static const zeek::TypePtr& ScriptDataType(); broker::data data; diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index 26a8b0c66e..4228008811 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -753,7 +753,7 @@ RecordVal* Manager::MakeEvent(val_list* args, Frame* frame) return rval; } - zeek::IntrusivePtr data_val; + RecordValPtr data_val; if ( same_type(got_type, bro_broker::DataVal::ScriptDataType()) ) data_val = {zeek::NewRef{}, (*args)[i]->AsRecordVal()}; diff --git a/src/broker/Manager.h b/src/broker/Manager.h index 36d9db9216..3b1286ad8b 100644 --- a/src/broker/Manager.h +++ b/src/broker/Manager.h @@ -25,6 +25,9 @@ class Frame; class Func; ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek); +namespace zeek { +using VectorTypePtr = zeek::IntrusivePtr; +} namespace bro_broker { @@ -397,7 +400,7 @@ private: size_t log_batch_size; Func* log_topic_func; - zeek::IntrusivePtr vector_of_data_type; + zeek::VectorTypePtr vector_of_data_type; zeek::EnumType* log_id_type; zeek::EnumType* writer_id_type; diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 8047c7d5f7..8af0d840e0 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -5,9 +5,9 @@ namespace bro_broker { -zeek::IntrusivePtr opaque_of_store_handle; +zeek::OpaqueTypePtr opaque_of_store_handle; -zeek::IntrusivePtr query_status(bool success) +EnumValPtr query_status(bool success) { static zeek::EnumType* store_query_status = nullptr; static int success_val; diff --git a/src/broker/Store.h b/src/broker/Store.h index eb8d1e37e9..5cfaf88a80 100644 --- a/src/broker/Store.h +++ b/src/broker/Store.h @@ -11,20 +11,20 @@ namespace bro_broker { -extern zeek::IntrusivePtr opaque_of_store_handle; +extern zeek::OpaqueTypePtr opaque_of_store_handle; /** * Create a Broker::QueryStatus value. * @param success whether the query status should be set to success or failure. * @return a Broker::QueryStatus value. */ -zeek::IntrusivePtr query_status(bool success); +EnumValPtr query_status(bool success); /** * @return a Broker::QueryResult value that has a Broker::QueryStatus indicating * a failure. */ -inline zeek::IntrusivePtr query_result() +inline RecordValPtr query_result() { auto rval = zeek::make_intrusive(zeek::BifType::Record::Broker::QueryResult); rval->Assign(0, query_status(false)); @@ -37,7 +37,7 @@ inline zeek::IntrusivePtr query_result() * @return a Broker::QueryResult value that has a Broker::QueryStatus indicating * a success. */ -inline zeek::IntrusivePtr query_result(zeek::IntrusivePtr data) +inline RecordValPtr query_result(RecordValPtr data) { auto rval = zeek::make_intrusive(zeek::BifType::Record::Broker::QueryResult); rval->Assign(0, query_status(true)); @@ -62,7 +62,7 @@ public: Unref(trigger); } - void Result(const zeek::IntrusivePtr& result) + void Result(const RecordValPtr& result) { trigger->Cache(call, result.get()); trigger->Release(); diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 53b0b0a3d0..2dd75aaf74 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -89,7 +89,7 @@ function Broker::make_event%(...%): Broker::Event for ( auto i = 0u; i < bif_args->size(); ++i ) args.push_back((*bif_args)[i].get()); - return zeek::IntrusivePtr{zeek::AdoptRef{}, broker_mgr->MakeEvent(&args, frame)}; + return RecordValPtr{zeek::AdoptRef{}, broker_mgr->MakeEvent(&args, frame)}; %} ## Publishes an event at a given topic. diff --git a/src/broker/store.bif b/src/broker/store.bif index 972b279346..dd94602041 100644 --- a/src/broker/store.bif +++ b/src/broker/store.bif @@ -42,13 +42,13 @@ function Broker::__create_master%(id: string, b: BackendType, auto rval = broker_mgr->LookupStore(name); if ( rval ) - return zeek::IntrusivePtr{zeek::NewRef{}, rval}; + return ValPtr{zeek::NewRef{}, rval}; auto e = static_cast(b->AsEnum()); auto type = bro_broker::to_backend_type(e); auto opts = bro_broker::to_backend_options(type, options->AsRecordVal()); - zeek::IntrusivePtr store{zeek::AdoptRef{}, broker_mgr->MakeMaster(name, type, std::move(opts))}; + ValPtr store{zeek::AdoptRef{}, broker_mgr->MakeMaster(name, type, std::move(opts))}; if ( ! store ) { @@ -68,12 +68,12 @@ function Broker::__create_clone%(id: string, resync_interval: interval, auto rval = broker_mgr->LookupStore(name); if ( rval ) - return zeek::IntrusivePtr{zeek::NewRef{}, rval}; + return ValPtr{zeek::NewRef{}, rval}; - zeek::IntrusivePtr store {zeek::AdoptRef{}, - broker_mgr->MakeClone(name, resync_interval, - stale_interval, - mutation_buffer_interval)}; + ValPtr store {zeek::AdoptRef{}, + broker_mgr->MakeClone(name, resync_interval, + stale_interval, + mutation_buffer_interval)}; if ( ! store ) { diff --git a/src/file_analysis/Analyzer.cc b/src/file_analysis/Analyzer.cc index 6cb37b506d..02fc8e5861 100644 --- a/src/file_analysis/Analyzer.cc +++ b/src/file_analysis/Analyzer.cc @@ -19,7 +19,7 @@ void file_analysis::Analyzer::SetAnalyzerTag(const file_analysis::Tag& arg_tag) } file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, - zeek::IntrusivePtr arg_args, + RecordValPtr arg_args, File* arg_file) : tag(arg_tag), args(std::move(arg_args)), @@ -30,7 +30,7 @@ file_analysis::Analyzer::Analyzer(file_analysis::Tag arg_tag, id = ++id_counter; } -file_analysis::Analyzer::Analyzer(zeek::IntrusivePtr arg_args, File* arg_file) +file_analysis::Analyzer::Analyzer(RecordValPtr arg_args, File* arg_file) : Analyzer({}, std::move(arg_args), arg_file) {} diff --git a/src/file_analysis/Analyzer.h b/src/file_analysis/Analyzer.h index b78b587041..f42a87b72b 100644 --- a/src/file_analysis/Analyzer.h +++ b/src/file_analysis/Analyzer.h @@ -7,6 +7,7 @@ #include // for u_char class RecordVal; +using RecordValPtr = zeek::IntrusivePtr; namespace file_analysis { @@ -95,7 +96,7 @@ public: /** * @return the AnalyzerArgs associated with the analyzer. */ - const zeek::IntrusivePtr& GetArgs() const + const RecordValPtr& GetArgs() const { return args; } [[deprecated("Remove in v4.1. Use GetArgs().")]] @@ -151,8 +152,7 @@ protected: * tunable options, if any, related to a particular analyzer type. * @param arg_file the file to which the the analyzer is being attached. */ - Analyzer(file_analysis::Tag arg_tag, zeek::IntrusivePtr arg_args, - File* arg_file); + Analyzer(file_analysis::Tag arg_tag, RecordValPtr arg_args, File* arg_file); [[deprecated("Remove in v4.1.. Construct using IntrusivePtr instead.")]] Analyzer(file_analysis::Tag arg_tag, RecordVal* arg_args, File* arg_file); @@ -166,7 +166,7 @@ protected: * tunable options, if any, related to a particular analyzer type. * @param arg_file the file to which the the analyzer is being attached. */ - Analyzer(zeek::IntrusivePtr arg_args, File* arg_file); + Analyzer(RecordValPtr arg_args, File* arg_file); [[deprecated("Remove in v4.1.. Construct using IntrusivePtr instead.")]] Analyzer(RecordVal* arg_args, File* arg_file); @@ -175,7 +175,7 @@ private: ID id; /**< Unique instance ID. */ file_analysis::Tag tag; /**< The particular type of the analyzer instance. */ - zeek::IntrusivePtr args; /**< \c AnalyzerArgs val gives tunable analyzer params. */ + RecordValPtr args; /**< \c AnalyzerArgs val gives tunable analyzer params. */ File* file; /**< The file to which the analyzer is attached. */ bool got_stream_delivery; bool skip; diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index 5593be4fe3..5e563fb3de 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -41,14 +41,14 @@ AnalyzerSet::~AnalyzerSet() } Analyzer* AnalyzerSet::Find(const file_analysis::Tag& tag, - zeek::IntrusivePtr args) + RecordValPtr args) { auto key = GetKey(tag, std::move(args)); Analyzer* rval = analyzer_map.Lookup(key.get()); return rval; } -bool AnalyzerSet::Add(const file_analysis::Tag& tag, zeek::IntrusivePtr args) +bool AnalyzerSet::Add(const file_analysis::Tag& tag, RecordValPtr args) { auto key = GetKey(tag, args); @@ -72,7 +72,7 @@ bool AnalyzerSet::Add(const file_analysis::Tag& tag, zeek::IntrusivePtr args) + RecordValPtr args) { auto key = GetKey(tag, args); file_analysis::Analyzer* a = InstantiateAnalyzer(tag, std::move(args)); @@ -108,7 +108,7 @@ void AnalyzerSet::AddMod::Abort() } bool AnalyzerSet::Remove(const file_analysis::Tag& tag, - zeek::IntrusivePtr args) + RecordValPtr args) { return Remove(tag, GetKey(tag, std::move(args))); } @@ -140,7 +140,7 @@ bool AnalyzerSet::Remove(const file_analysis::Tag& tag, } bool AnalyzerSet::QueueRemove(const file_analysis::Tag& tag, - zeek::IntrusivePtr args) + RecordValPtr args) { auto key = GetKey(tag, std::move(args)); auto rval = analyzer_map.Lookup(key.get()); @@ -154,7 +154,7 @@ bool AnalyzerSet::RemoveMod::Perform(AnalyzerSet* set) } std::unique_ptr AnalyzerSet::GetKey(const file_analysis::Tag& t, - zeek::IntrusivePtr args) const + RecordValPtr args) const { auto lv = zeek::make_intrusive(zeek::TYPE_ANY); lv->Append(t.AsVal()); @@ -168,7 +168,7 @@ std::unique_ptr AnalyzerSet::GetKey(const file_analysis::Tag& t, } file_analysis::Analyzer* AnalyzerSet::InstantiateAnalyzer(const Tag& tag, - zeek::IntrusivePtr args) const + RecordValPtr args) const { auto a = file_mgr->InstantiateAnalyzer(tag, std::move(args), file); diff --git a/src/file_analysis/AnalyzerSet.h b/src/file_analysis/AnalyzerSet.h index a18f67bd77..bc5bd197d1 100644 --- a/src/file_analysis/AnalyzerSet.h +++ b/src/file_analysis/AnalyzerSet.h @@ -9,7 +9,9 @@ #include "Tag.h" class CompositeHash; + class RecordVal; +using RecordValPtr = zeek::IntrusivePtr; namespace file_analysis { @@ -43,7 +45,7 @@ public: * @param args an \c AnalyzerArgs record. * @return pointer to an analyzer instance, or a null pointer if not found. */ - Analyzer* Find(const file_analysis::Tag& tag, zeek::IntrusivePtr args); + Analyzer* Find(const file_analysis::Tag& tag, RecordValPtr args); /** * Attach an analyzer to #file immediately. @@ -51,7 +53,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return true if analyzer was instantiated/attached, else false. */ - bool Add(const file_analysis::Tag& tag, zeek::IntrusivePtr args); + bool Add(const file_analysis::Tag& tag, RecordValPtr args); /** * Queue the attachment of an analyzer to #file. @@ -61,7 +63,7 @@ public: * a null pointer. The caller does *not* take ownership of the memory. */ file_analysis::Analyzer* QueueAdd(const file_analysis::Tag& tag, - zeek::IntrusivePtr args); + RecordValPtr args); /** * Remove an analyzer from #file immediately. @@ -69,7 +71,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return false if analyzer didn't exist and so wasn't removed, else true. */ - bool Remove(const file_analysis::Tag& tag, zeek::IntrusivePtr args); + bool Remove(const file_analysis::Tag& tag, RecordValPtr args); /** * Queue the removal of an analyzer from #file. @@ -77,7 +79,7 @@ public: * @param args an \c AnalyzerArgs value which specifies an analyzer. * @return true if analyzer exists at time of call, else false; */ - bool QueueRemove(const file_analysis::Tag& tag, zeek::IntrusivePtr args); + bool QueueRemove(const file_analysis::Tag& tag, RecordValPtr args); /** * Perform all queued modifications to the current analyzer set. @@ -111,7 +113,7 @@ protected: * @return the hash key calculated from \a args */ std::unique_ptr GetKey(const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const; + RecordValPtr args) const; /** * Create an instance of a file analyzer. @@ -120,7 +122,7 @@ protected: * @return a new file analyzer instance. */ file_analysis::Analyzer* InstantiateAnalyzer(const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const; + RecordValPtr args) const; /** * Insert an analyzer instance in to the set. diff --git a/src/file_analysis/Component.h b/src/file_analysis/Component.h index 7476f26d61..749579ea58 100644 --- a/src/file_analysis/Component.h +++ b/src/file_analysis/Component.h @@ -9,6 +9,7 @@ #include "../zeek-config.h" class RecordVal; +using RecordValPtr = zeek::IntrusivePtr; namespace file_analysis { @@ -26,7 +27,7 @@ class Component : public zeek::plugin::Component, public plugin::TaggedComponent { public: typedef Analyzer* (*factory_callback)(RecordVal* args, File* file); - using factory_function = Analyzer* (*)(zeek::IntrusivePtr args, File* file); + using factory_function = Analyzer* (*)(RecordValPtr args, File* file); /** * Constructor. diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 4f62c3fc5a..600793b6ae 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -21,7 +21,7 @@ using namespace file_analysis; -static zeek::IntrusivePtr empty_connection_table() +static TableValPtr empty_connection_table() { auto tbl_index = zeek::make_intrusive(zeek::id::conn_id); tbl_index->Append(zeek::id::conn_id); @@ -30,7 +30,7 @@ static zeek::IntrusivePtr empty_connection_table() return zeek::make_intrusive(std::move(tbl_type)); } -static zeek::IntrusivePtr get_conn_id_val(const Connection* conn) +static RecordValPtr get_conn_id_val(const Connection* conn) { auto v = zeek::make_intrusive(zeek::id::conn_id); v->Assign(0, zeek::make_intrusive(conn->OrigAddr())); @@ -206,7 +206,7 @@ void File::SetTimeoutInterval(double interval) bool File::SetExtractionLimit(RecordVal* args, uint64_t bytes) { return SetExtractionLimit({zeek::NewRef{}, args}, bytes); } -bool File::SetExtractionLimit(zeek::IntrusivePtr args, uint64_t bytes) +bool File::SetExtractionLimit(RecordValPtr args, uint64_t bytes) { Analyzer* a = analyzers.Find(file_mgr->GetComponentTag("EXTRACT"), std::move(args)); @@ -256,7 +256,7 @@ void File::ScheduleInactivityTimer() const bool File::AddAnalyzer(file_analysis::Tag tag, RecordVal* args) { return AddAnalyzer(tag, {zeek::NewRef{}, args}); } -bool File::AddAnalyzer(file_analysis::Tag tag, zeek::IntrusivePtr args) +bool File::AddAnalyzer(file_analysis::Tag tag, RecordValPtr args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing addition of %s analyzer", id.c_str(), file_mgr->GetComponentName(tag).c_str()); @@ -270,7 +270,7 @@ bool File::AddAnalyzer(file_analysis::Tag tag, zeek::IntrusivePtr arg bool File::RemoveAnalyzer(file_analysis::Tag tag, RecordVal* args) { return RemoveAnalyzer(tag, {zeek::NewRef{}, args}); } -bool File::RemoveAnalyzer(file_analysis::Tag tag, zeek::IntrusivePtr args) +bool File::RemoveAnalyzer(file_analysis::Tag tag, RecordValPtr args) { DBG_LOG(DBG_FILE_ANALYSIS, "[%s] Queuing remove of %s analyzer", id.c_str(), file_mgr->GetComponentName(tag).c_str()); diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 628a5f2d69..4501de0747 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -14,10 +14,15 @@ #include "WeirdState.h" class Connection; -class RecordVal; class EventHandlerPtr; ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); +namespace zeek { +using RecordTypePtr = zeek::IntrusivePtr; +} + +class RecordVal; +using RecordValPtr = zeek::IntrusivePtr; namespace file_analysis { @@ -39,7 +44,7 @@ public: /** * @return the wrapped \c fa_file record value, #val. */ - const zeek::IntrusivePtr& ToVal() const + const RecordValPtr& ToVal() const { return val; } [[deprecated("Remove in v4.1. Use ToVal().")]] @@ -75,7 +80,7 @@ public: * @param bytes new limit. * @return false if no extraction analyzer is active, else true. */ - bool SetExtractionLimit(zeek::IntrusivePtr args, uint64_t bytes); + bool SetExtractionLimit(RecordValPtr args, uint64_t bytes); [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool SetExtractionLimit(RecordVal* args, uint64_t bytes); @@ -123,7 +128,7 @@ public: * @param args an \c AnalyzerArgs value representing a file analyzer. * @return false if analyzer can't be instantiated, else true. */ - bool AddAnalyzer(file_analysis::Tag tag, zeek::IntrusivePtr args); + bool AddAnalyzer(file_analysis::Tag tag, RecordValPtr args); [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool AddAnalyzer(file_analysis::Tag tag, RecordVal* args); @@ -134,7 +139,7 @@ public: * @param args an \c AnalyzerArgs value representing a file analyzer. * @return true if analyzer was active at time of call, else false. */ - bool RemoveAnalyzer(file_analysis::Tag tag, zeek::IntrusivePtr args); + bool RemoveAnalyzer(file_analysis::Tag tag, RecordValPtr args); [[deprecated("Remove in v4.1. Pass an IntrusivePtr instead.")]] bool RemoveAnalyzer(file_analysis::Tag tag, RecordVal* args); @@ -338,7 +343,7 @@ protected: * @return the field offset in #val record corresponding to \a field_name. */ static int Idx(const std::string& field_name, const zeek::RecordType* type); - static int Idx(const std::string& field_name, const zeek::IntrusivePtr& type) + static int Idx(const std::string& field_name, const zeek::RecordTypePtr& type) { return Idx(field_name, type.get()); } /** @@ -348,7 +353,7 @@ protected: protected: std::string id; /**< A pretty hash that likely identifies file */ - zeek::IntrusivePtr val; /**< \c fa_file from script layer. */ + RecordValPtr val; /**< \c fa_file from script layer. */ FileReassembler* file_reassembler; /**< A reassembler for the file if it's needed. */ uint64_t stream_offset; /**< The offset of the file which has been forwarded. */ uint64_t reassembly_max_buffer; /**< Maximum allowed buffer for reassembly. */ diff --git a/src/file_analysis/Manager.cc b/src/file_analysis/Manager.cc index 9b79cfdf0d..e30e036620 100644 --- a/src/file_analysis/Manager.cc +++ b/src/file_analysis/Manager.cc @@ -263,7 +263,7 @@ bool Manager::SetExtractionLimit(const string& file_id, RecordVal* args, { return SetExtractionLimit(file_id, {zeek::NewRef{}, args}, n); } bool Manager::SetExtractionLimit(const string& file_id, - zeek::IntrusivePtr args, uint64_t n) const + RecordValPtr args, uint64_t n) const { File* file = LookupFile(file_id); @@ -278,7 +278,7 @@ bool Manager::AddAnalyzer(const string& file_id, const file_analysis::Tag& tag, { return AddAnalyzer(file_id, tag, {zeek::NewRef{}, args}); } bool Manager::AddAnalyzer(const string& file_id, const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const + RecordValPtr args) const { File* file = LookupFile(file_id); @@ -293,7 +293,7 @@ bool Manager::RemoveAnalyzer(const string& file_id, const file_analysis::Tag& ta { return RemoveAnalyzer(file_id, tag, {zeek::NewRef{}, args}); } bool Manager::RemoveAnalyzer(const string& file_id, const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const + RecordValPtr args) const { File* file = LookupFile(file_id); @@ -458,7 +458,7 @@ Analyzer* Manager::InstantiateAnalyzer(const Tag& tag, RecordVal* args, File* f) { return InstantiateAnalyzer(tag, {zeek::NewRef{}, args}, f); } Analyzer* Manager::InstantiateAnalyzer(const Tag& tag, - zeek::IntrusivePtr args, + RecordValPtr args, File* f) const { Component* c = Lookup(tag); @@ -517,7 +517,7 @@ string Manager::DetectMIME(const u_char* data, uint64_t len) const return *(matches.begin()->second.begin()); } -zeek::IntrusivePtr file_analysis::GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m) +VectorValPtr 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"); diff --git a/src/file_analysis/Manager.h b/src/file_analysis/Manager.h index 03cdabfc1e..2592247aa6 100644 --- a/src/file_analysis/Manager.h +++ b/src/file_analysis/Manager.h @@ -254,7 +254,7 @@ public: * else true. */ bool SetExtractionLimit(const std::string& file_id, - zeek::IntrusivePtr args, uint64_t n) const; + RecordValPtr args, uint64_t n) const; [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool SetExtractionLimit(const std::string& file_id, RecordVal* args, @@ -278,7 +278,7 @@ public: * @return false if the analyzer failed to be instantiated, else true. */ bool AddAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const; + RecordValPtr args) const; [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool AddAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, @@ -292,7 +292,7 @@ public: * @return true if the analyzer is active at the time of call, else false. */ bool RemoveAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, - zeek::IntrusivePtr args) const; + RecordValPtr args) const; [[deprecated("Remove in v4.1. Pass IntrusivePtr args param instead.")]] bool RemoveAnalyzer(const std::string& file_id, const file_analysis::Tag& tag, @@ -312,7 +312,7 @@ public: * @param f The file analzer is to be associated with. * @return The new analyzer instance or null if tag is invalid. */ - Analyzer* InstantiateAnalyzer(const Tag& tag, zeek::IntrusivePtr args, + Analyzer* InstantiateAnalyzer(const Tag& tag, RecordValPtr args, File* f) const; [[deprecated("Remove in v4.1. Pass in IntrusivePtr args instead.")]] @@ -438,7 +438,7 @@ private: * Returns a script-layer value corresponding to the \c mime_matches type. * @param m The MIME match information with which to populate the value. */ -zeek::IntrusivePtr GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m); +VectorValPtr GenMIMEMatchesVal(const RuleMatcher::MIME_Matches& m); } // namespace file_analysis diff --git a/src/file_analysis/Tag.cc b/src/file_analysis/Tag.cc index eb7d62fee0..6d285d5e08 100644 --- a/src/file_analysis/Tag.cc +++ b/src/file_analysis/Tag.cc @@ -18,7 +18,7 @@ file_analysis::Tag& file_analysis::Tag::operator=(const file_analysis::Tag& othe return *this; } -const zeek::IntrusivePtr& file_analysis::Tag::AsVal() const +const EnumValPtr& file_analysis::Tag::AsVal() const { return ::Tag::AsVal(file_mgr->GetTagType()); } @@ -28,7 +28,7 @@ EnumVal* file_analysis::Tag::AsEnumVal() const return AsVal().get(); } -file_analysis::Tag::Tag(zeek::IntrusivePtr val) +file_analysis::Tag::Tag(EnumValPtr val) : ::Tag(std::move(val)) { } diff --git a/src/file_analysis/Tag.h b/src/file_analysis/Tag.h index 1f5e22c882..e4c52c2032 100644 --- a/src/file_analysis/Tag.h +++ b/src/file_analysis/Tag.h @@ -88,7 +88,7 @@ public: * * @param etype the script-layer enum type associated with the tag. */ - const zeek::IntrusivePtr& AsVal() const; + const EnumValPtr& AsVal() const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; @@ -116,7 +116,7 @@ protected: * * @param val An enum value of script type \c Files::Tag. */ - explicit Tag(zeek::IntrusivePtr val); + explicit Tag(EnumValPtr val); [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Tag(EnumVal* val); diff --git a/src/file_analysis/analyzer/data_event/DataEvent.cc b/src/file_analysis/analyzer/data_event/DataEvent.cc index 4fd09744ff..cc660e19ac 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.cc +++ b/src/file_analysis/analyzer/data_event/DataEvent.cc @@ -11,7 +11,7 @@ using namespace file_analysis; -DataEvent::DataEvent(zeek::IntrusivePtr args, File* file, +DataEvent::DataEvent(RecordValPtr args, File* file, EventHandlerPtr ce, EventHandlerPtr se) : file_analysis::Analyzer(file_mgr->GetComponentTag("DATA_EVENT"), std::move(args), file), @@ -19,7 +19,7 @@ DataEvent::DataEvent(zeek::IntrusivePtr args, File* file, { } -file_analysis::Analyzer* DataEvent::Instantiate(zeek::IntrusivePtr args, +file_analysis::Analyzer* DataEvent::Instantiate(RecordValPtr args, File* file) { const auto& chunk_val = args->GetField("chunk_event"); diff --git a/src/file_analysis/analyzer/data_event/DataEvent.h b/src/file_analysis/analyzer/data_event/DataEvent.h index 5290925f80..125eb7a548 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.h +++ b/src/file_analysis/analyzer/data_event/DataEvent.h @@ -43,7 +43,7 @@ public: * @return the new DataEvent analyzer instance or a null pointer if * no "chunk_event" or "stream_event" field was specfied in \a args. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file); protected: @@ -57,7 +57,7 @@ protected: * @param se pointer to event handler which will be called to receive * sequential file data. */ - DataEvent(zeek::IntrusivePtr args, File* file, + DataEvent(RecordValPtr args, File* file, EventHandlerPtr ce, EventHandlerPtr se); private: diff --git a/src/file_analysis/analyzer/entropy/Entropy.cc b/src/file_analysis/analyzer/entropy/Entropy.cc index 21a445b78e..98ebfbb040 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.cc +++ b/src/file_analysis/analyzer/entropy/Entropy.cc @@ -9,7 +9,7 @@ using namespace file_analysis; -Entropy::Entropy(zeek::IntrusivePtr args, File* file) +Entropy::Entropy(RecordValPtr args, File* file) : file_analysis::Analyzer(file_mgr->GetComponentTag("ENTROPY"), std::move(args), file) { @@ -23,7 +23,7 @@ Entropy::~Entropy() Unref(entropy); } -file_analysis::Analyzer* Entropy::Instantiate(zeek::IntrusivePtr args, +file_analysis::Analyzer* Entropy::Instantiate(RecordValPtr args, File* file) { return new Entropy(std::move(args), file); diff --git a/src/file_analysis/analyzer/entropy/Entropy.h b/src/file_analysis/analyzer/entropy/Entropy.h index 1b5634d520..df1e7702a4 100644 --- a/src/file_analysis/analyzer/entropy/Entropy.h +++ b/src/file_analysis/analyzer/entropy/Entropy.h @@ -31,7 +31,7 @@ public: * @return the new Entropy analyzer instance or a null pointer if the * the "extraction_file" field of \a args wasn't set. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file); /** @@ -66,7 +66,7 @@ protected: * @param hv specific hash calculator object. * @param kind human readable name of the hash algorithm to use. */ - Entropy(zeek::IntrusivePtr args, File* file); + Entropy(RecordValPtr args, File* file); /** * If some file contents have been seen, finalizes the entropy of them and diff --git a/src/file_analysis/analyzer/extract/Extract.cc b/src/file_analysis/analyzer/extract/Extract.cc index c20f10097d..cd468353a8 100644 --- a/src/file_analysis/analyzer/extract/Extract.cc +++ b/src/file_analysis/analyzer/extract/Extract.cc @@ -10,7 +10,7 @@ using namespace file_analysis; -Extract::Extract(zeek::IntrusivePtr args, File* file, +Extract::Extract(RecordValPtr args, File* file, const std::string& arg_filename, uint64_t arg_limit) : file_analysis::Analyzer(file_mgr->GetComponentTag("EXTRACT"), std::move(args), file), @@ -33,8 +33,8 @@ Extract::~Extract() safe_close(fd); } -static const zeek::IntrusivePtr& get_extract_field_val(const zeek::IntrusivePtr& args, - const char* name) +static const ValPtr& get_extract_field_val(const RecordValPtr& args, + const char* name) { const auto& rval = args->GetField(name); @@ -44,7 +44,7 @@ static const zeek::IntrusivePtr& get_extract_field_val(const zeek::Intrusiv return rval; } -file_analysis::Analyzer* Extract::Instantiate(zeek::IntrusivePtr args, File* file) +file_analysis::Analyzer* Extract::Instantiate(RecordValPtr args, File* file) { const auto& fname = get_extract_field_val(args, "extract_filename"); const auto& limit = get_extract_field_val(args, "extract_limit"); diff --git a/src/file_analysis/analyzer/extract/Extract.h b/src/file_analysis/analyzer/extract/Extract.h index d8aa58205e..104df05469 100644 --- a/src/file_analysis/analyzer/extract/Extract.h +++ b/src/file_analysis/analyzer/extract/Extract.h @@ -47,7 +47,7 @@ public: * @return the new Extract analyzer instance or a null pointer if the * the "extraction_file" field of \a args wasn't set. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file); /** @@ -67,7 +67,7 @@ protected: * to which the contents of the file will be extracted/written. * @param arg_limit the maximum allowed file size. */ - Extract(zeek::IntrusivePtr args, File* file, + Extract(RecordValPtr args, File* file, const std::string& arg_filename, uint64_t arg_limit); private: diff --git a/src/file_analysis/analyzer/hash/Hash.cc b/src/file_analysis/analyzer/hash/Hash.cc index bde87188df..54274e6eb8 100644 --- a/src/file_analysis/analyzer/hash/Hash.cc +++ b/src/file_analysis/analyzer/hash/Hash.cc @@ -9,7 +9,7 @@ using namespace file_analysis; -Hash::Hash(zeek::IntrusivePtr args, File* file, HashVal* hv, const char* arg_kind) +Hash::Hash(RecordValPtr args, File* file, HashVal* hv, const char* arg_kind) : file_analysis::Analyzer(file_mgr->GetComponentTag(to_upper(arg_kind).c_str()), std::move(args), file), hash(hv), fed(false), kind(arg_kind) diff --git a/src/file_analysis/analyzer/hash/Hash.h b/src/file_analysis/analyzer/hash/Hash.h index 042d720338..a3ddc2eb69 100644 --- a/src/file_analysis/analyzer/hash/Hash.h +++ b/src/file_analysis/analyzer/hash/Hash.h @@ -56,7 +56,7 @@ protected: * @param hv specific hash calculator object. * @param kind human readable name of the hash algorithm to use. */ - Hash(zeek::IntrusivePtr args, File* file, HashVal* hv, const char* kind); + Hash(RecordValPtr args, File* file, HashVal* hv, const char* kind); /** * If some file contents have been seen, finalizes the hash of them and @@ -83,7 +83,7 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file) { return file_hash ? new MD5(std::move(args), file) : nullptr; } @@ -94,7 +94,7 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - MD5(zeek::IntrusivePtr args, File* file) + MD5(RecordValPtr args, File* file) : Hash(std::move(args), file, new MD5Val(), "md5") {} }; @@ -112,7 +112,7 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file) { return file_hash ? new SHA1(std::move(args), file) : nullptr; } @@ -123,7 +123,7 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - SHA1(zeek::IntrusivePtr args, File* file) + SHA1(RecordValPtr args, File* file) : Hash(std::move(args), file, new SHA1Val(), "sha1") {} }; @@ -141,7 +141,7 @@ public: * @return the new MD5 analyzer instance or a null pointer if there's no * handler for the "file_hash" event. */ - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file) { return file_hash ? new SHA256(std::move(args), file) : nullptr; } @@ -152,7 +152,7 @@ protected: * @param args the \c AnalyzerArgs value which represents the analyzer. * @param file the file to which the analyzer will be attached. */ - SHA256(zeek::IntrusivePtr args, File* file) + SHA256(RecordValPtr args, File* file) : Hash(std::move(args), file, new SHA256Val(), "sha256") {} }; diff --git a/src/file_analysis/analyzer/pe/PE.cc b/src/file_analysis/analyzer/pe/PE.cc index 695be58ff4..8b03360d73 100644 --- a/src/file_analysis/analyzer/pe/PE.cc +++ b/src/file_analysis/analyzer/pe/PE.cc @@ -3,7 +3,7 @@ using namespace file_analysis; -PE::PE(zeek::IntrusivePtr args, File* file) +PE::PE(RecordValPtr args, File* file) : file_analysis::Analyzer(file_mgr->GetComponentTag("PE"), std::move(args), file) { diff --git a/src/file_analysis/analyzer/pe/PE.h b/src/file_analysis/analyzer/pe/PE.h index 44bdc5567e..fd4477dcba 100644 --- a/src/file_analysis/analyzer/pe/PE.h +++ b/src/file_analysis/analyzer/pe/PE.h @@ -15,7 +15,7 @@ class PE : public file_analysis::Analyzer { public: ~PE(); - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file) { return new PE(std::move(args), file); } @@ -24,7 +24,7 @@ public: virtual bool EndOfFile(); protected: - PE(zeek::IntrusivePtr args, File* file); + PE(RecordValPtr args, File* file); binpac::PE::File* interp; binpac::PE::MockConnection* conn; bool done; diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 52cd3b609a..91e5b3b839 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -5,12 +5,12 @@ %} %header{ -zeek::IntrusivePtr process_rvas(const RVAS* rvas); -zeek::IntrusivePtr characteristics_to_bro(uint32_t c, uint8_t len); +VectorValPtr process_rvas(const RVAS* rvas); +TableValPtr characteristics_to_bro(uint32_t c, uint8_t len); %} %code{ -zeek::IntrusivePtr process_rvas(const RVAS* rva_table) +VectorValPtr process_rvas(const RVAS* rva_table) { auto rvas = zeek::make_intrusive(zeek::id::index_vec); @@ -20,7 +20,7 @@ zeek::IntrusivePtr process_rvas(const RVAS* rva_table) return rvas; } -zeek::IntrusivePtr characteristics_to_bro(uint32_t c, uint8_t len) +TableValPtr characteristics_to_bro(uint32_t c, uint8_t len) { uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; auto char_set = zeek::make_intrusive(zeek::id::count_set); diff --git a/src/file_analysis/analyzer/unified2/Unified2.cc b/src/file_analysis/analyzer/unified2/Unified2.cc index d0cd8c53ff..83674823e8 100644 --- a/src/file_analysis/analyzer/unified2/Unified2.cc +++ b/src/file_analysis/analyzer/unified2/Unified2.cc @@ -5,7 +5,7 @@ using namespace file_analysis; -Unified2::Unified2(zeek::IntrusivePtr args, File* file) +Unified2::Unified2(RecordValPtr args, File* file) : file_analysis::Analyzer(file_mgr->GetComponentTag("UNIFIED2"), std::move(args), file) { interp = new binpac::Unified2::Unified2_Analyzer(this); @@ -16,7 +16,7 @@ Unified2::~Unified2() delete interp; } -file_analysis::Analyzer* Unified2::Instantiate(zeek::IntrusivePtr args, File* file) +file_analysis::Analyzer* Unified2::Instantiate(RecordValPtr args, File* file) { return new Unified2(std::move(args), file); } diff --git a/src/file_analysis/analyzer/unified2/Unified2.h b/src/file_analysis/analyzer/unified2/Unified2.h index 39a00d073c..981da3534a 100644 --- a/src/file_analysis/analyzer/unified2/Unified2.h +++ b/src/file_analysis/analyzer/unified2/Unified2.h @@ -20,11 +20,10 @@ public: bool DeliverStream(const u_char* data, uint64_t len) override; - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, - File* file); + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file); protected: - Unified2(zeek::IntrusivePtr args, File* file); + Unified2(RecordValPtr args, File* file); private: binpac::Unified2::Unified2_Analyzer* interp; diff --git a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac index eabaa6bb4b..06c3f36305 100644 --- a/src/file_analysis/analyzer/unified2/unified2-analyzer.pac +++ b/src/file_analysis/analyzer/unified2/unified2-analyzer.pac @@ -8,7 +8,7 @@ %} %code{ -zeek::IntrusivePtr binpac::Unified2::Flow::unified2_addr_to_bro_addr(std::vector* a) +AddrValPtr binpac::Unified2::Flow::unified2_addr_to_bro_addr(std::vector* a) { if ( a->size() == 1 ) { @@ -26,7 +26,7 @@ zeek::IntrusivePtr binpac::Unified2::Flow::unified2_addr_to_bro_addr(st } } -zeek::IntrusivePtr binpac::Unified2::Flow::to_port(uint16_t n, uint8_t p) +ValPtr binpac::Unified2::Flow::to_port(uint16_t n, uint8_t p) { TransportProto proto = TRANSPORT_UNKNOWN; switch ( p ) { @@ -42,8 +42,8 @@ zeek::IntrusivePtr binpac::Unified2::Flow::to_port(uint16_t n, uint8_t p) refine flow Flow += { %member{ - zeek::IntrusivePtr unified2_addr_to_bro_addr(std::vector* a); - zeek::IntrusivePtr to_port(uint16_t n, uint8_t p); + AddrValPtr unified2_addr_to_bro_addr(std::vector* a); + ValPtr to_port(uint16_t n, uint8_t p); %} %init{ diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 1ba8b5f132..3226042c3c 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -113,19 +113,17 @@ static bool ocsp_add_cert_id(const OCSP_CERTID* cert_id, zeek::Args* vl, BIO* bi return true; } -file_analysis::Analyzer* OCSP::InstantiateRequest(zeek::IntrusivePtr args, - File* file) +file_analysis::Analyzer* OCSP::InstantiateRequest(RecordValPtr args, File* file) { return new OCSP(std::move(args), file, true); } -file_analysis::Analyzer* OCSP::InstantiateReply(zeek::IntrusivePtr args, - File* file) +file_analysis::Analyzer* OCSP::InstantiateReply(RecordValPtr args, File* file) { return new OCSP(std::move(args), file, false); } -file_analysis::OCSP::OCSP(zeek::IntrusivePtr args, file_analysis::File* file, +file_analysis::OCSP::OCSP(RecordValPtr args, file_analysis::File* file, bool arg_request) : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("OCSP"), std::move(args), file), @@ -211,9 +209,9 @@ typedef struct ocsp_basic_response_st { STACK_OF(X509) *certs; } OCSP_BASICRESP; */ -static zeek::IntrusivePtr parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, - BIO* bio, char* buf, - size_t buf_len) +static StringValPtr parse_basic_resp_sig_alg(OCSP_BASICRESP* basic_resp, + BIO* bio, char* buf, + size_t buf_len) { int der_basic_resp_len = 0; unsigned char* der_basic_resp_dat = nullptr; @@ -285,7 +283,7 @@ static zeek::IntrusivePtr parse_basic_resp_sig_alg(OCSP_BASICRESP* ba return rval; } -static zeek::IntrusivePtr parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) +static ValPtr parse_basic_resp_data_version(OCSP_BASICRESP* basic_resp) { int der_basic_resp_len = 0; unsigned char* der_basic_resp_dat = nullptr; diff --git a/src/file_analysis/analyzer/x509/OCSP.h b/src/file_analysis/analyzer/x509/OCSP.h index f9d235b23c..a8d330fb11 100644 --- a/src/file_analysis/analyzer/x509/OCSP.h +++ b/src/file_analysis/analyzer/x509/OCSP.h @@ -18,13 +18,13 @@ public: bool Undelivered(uint64_t offset, uint64_t len) override; bool EndOfFile() override; - static file_analysis::Analyzer* InstantiateRequest(zeek::IntrusivePtr args, + static file_analysis::Analyzer* InstantiateRequest(RecordValPtr args, File* file); - static file_analysis::Analyzer* InstantiateReply(zeek::IntrusivePtr args, + static file_analysis::Analyzer* InstantiateReply(RecordValPtr args, File* file); protected: - OCSP(zeek::IntrusivePtr args, File* file, bool request); + OCSP(RecordValPtr args, File* file, bool request); private: void ParseResponse(OCSP_RESPONSE*); diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index ff74f61592..b4a6667848 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -23,7 +23,7 @@ using namespace file_analysis; -file_analysis::X509::X509(zeek::IntrusivePtr args, file_analysis::File* file) +file_analysis::X509::X509(RecordValPtr args, file_analysis::File* file) : file_analysis::X509Common::X509Common(file_mgr->GetComponentTag("X509"), std::move(args), file) { @@ -113,7 +113,7 @@ bool file_analysis::X509::EndOfFile() return false; } -zeek::IntrusivePtr file_analysis::X509::ParseCertificate(X509Val* cert_val, File* f) +RecordValPtr file_analysis::X509::ParseCertificate(X509Val* cert_val, File* f) { ::X509* ssl_cert = cert_val->GetCertificate(); @@ -340,10 +340,10 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) return; } - zeek::IntrusivePtr names; - zeek::IntrusivePtr emails; - zeek::IntrusivePtr uris; - zeek::IntrusivePtr ips; + VectorValPtr names; + VectorValPtr emails; + VectorValPtr uris; + VectorValPtr ips; bool otherfields = false; @@ -443,7 +443,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) GENERAL_NAMES_free(altname); } -zeek::IntrusivePtr file_analysis::X509::KeyCurve(EVP_PKEY* key) +StringValPtr file_analysis::X509::KeyCurve(EVP_PKEY* key) { assert(key != nullptr); @@ -543,7 +543,7 @@ X509Val::~X509Val() X509_free(certificate); } -zeek::IntrusivePtr X509Val::DoClone(CloneState* state) +ValPtr X509Val::DoClone(CloneState* state) { auto copy = zeek::make_intrusive(); if ( certificate ) diff --git a/src/file_analysis/analyzer/x509/X509.h b/src/file_analysis/analyzer/x509/X509.h index f7c49eb11d..965b4eef4b 100644 --- a/src/file_analysis/analyzer/x509/X509.h +++ b/src/file_analysis/analyzer/x509/X509.h @@ -86,9 +86,9 @@ public: * @param Returns the new record value and passes ownership to * caller. */ - static zeek::IntrusivePtr ParseCertificate(X509Val* cert_val, File* file = nullptr); + static RecordValPtr ParseCertificate(X509Val* cert_val, File* file = nullptr); - static file_analysis::Analyzer* Instantiate(zeek::IntrusivePtr args, + static file_analysis::Analyzer* Instantiate(RecordValPtr args, File* file) { return new X509(std::move(args), file); } @@ -117,17 +117,17 @@ public: /** * Sets the table[string] that used as the certificate cache inside of Zeek. */ - static void SetCertificateCache(zeek::IntrusivePtr cache) + static void SetCertificateCache(TableValPtr cache) { certificate_cache = std::move(cache); } /** * Sets the callback when a certificate cache hit is encountered */ - static void SetCertificateCacheHitCallback(zeek::IntrusivePtr func) + static void SetCertificateCacheHitCallback(FuncPtr func) { cache_hit_callback = std::move(func); } protected: - X509(zeek::IntrusivePtr args, File* file); + X509(RecordValPtr args, File* file); private: void ParseBasicConstraints(X509_EXTENSION* ex); @@ -137,12 +137,12 @@ private: std::string cert_data; // Helpers for ParseCertificate. - static zeek::IntrusivePtr KeyCurve(EVP_PKEY* key); + static StringValPtr KeyCurve(EVP_PKEY* key); static unsigned int KeyLength(EVP_PKEY *key); /** X509 stores associated with global script-layer values */ inline static std::map x509_stores = std::map(); - inline static zeek::IntrusivePtr certificate_cache = nullptr; - inline static zeek::IntrusivePtr cache_hit_callback = nullptr; + inline static TableValPtr certificate_cache = nullptr; + inline static FuncPtr cache_hit_callback = nullptr; }; /** @@ -170,7 +170,7 @@ public: * * @return A cloned X509Val. */ - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; /** * Destructor. diff --git a/src/file_analysis/analyzer/x509/X509Common.cc b/src/file_analysis/analyzer/x509/X509Common.cc index 4eba1cbaef..3d57df810e 100644 --- a/src/file_analysis/analyzer/x509/X509Common.cc +++ b/src/file_analysis/analyzer/x509/X509Common.cc @@ -17,7 +17,7 @@ using namespace file_analysis; X509Common::X509Common(const file_analysis::Tag& arg_tag, - zeek::IntrusivePtr arg_args, File* arg_file) + RecordValPtr arg_args, File* arg_file) : file_analysis::Analyzer(arg_tag, std::move(arg_args), arg_file) { } @@ -298,7 +298,7 @@ void file_analysis::X509Common::ParseExtension(X509_EXTENSION* ex, const EventHa ParseExtensionsSpecific(ex, global, ext_asn, oid); } -zeek::IntrusivePtr file_analysis::X509Common::GetExtensionFromBIO(BIO* bio, File* f) +StringValPtr file_analysis::X509Common::GetExtensionFromBIO(BIO* bio, File* f) { BIO_flush(bio); ERR_clear_error(); diff --git a/src/file_analysis/analyzer/x509/X509Common.h b/src/file_analysis/analyzer/x509/X509Common.h index f8b399f9ee..02a74f0589 100644 --- a/src/file_analysis/analyzer/x509/X509Common.h +++ b/src/file_analysis/analyzer/x509/X509Common.h @@ -12,9 +12,11 @@ class EventHandlerPtr; class Reporter; -class StringVal; template class IntrusivePtr; +class StringVal; +using StringValPtr = zeek::IntrusivePtr; + namespace file_analysis { class Tag; @@ -35,13 +37,13 @@ public: * * @return The X509 extension value. */ - static zeek::IntrusivePtr GetExtensionFromBIO(BIO* bio, File* f = nullptr); + static StringValPtr GetExtensionFromBIO(BIO* bio, File* f = nullptr); static double GetTimeFromAsn1(const ASN1_TIME* atime, File* f, Reporter* reporter); protected: X509Common(const file_analysis::Tag& arg_tag, - zeek::IntrusivePtr arg_args, File* arg_file); + RecordValPtr arg_args, File* arg_file); void ParseExtension(X509_EXTENSION* ex, const EventHandlerPtr& h, bool global); void ParseSignedCertificateTimestamps(X509_EXTENSION* ext); diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index fdea883934..84a0716ac6 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -11,7 +11,7 @@ #include // construct an error record -static zeek::IntrusivePtr x509_result_record(uint64_t num, const char* reason, zeek::IntrusivePtr chainVector = nullptr) +static RecordValPtr x509_result_record(uint64_t num, const char* reason, ValPtr chainVector = nullptr) { auto rrecord = zeek::make_intrusive(zeek::BifType::Record::X509::Result); @@ -215,7 +215,7 @@ function x509_get_certificate_string%(cert: opaque of x509, pem: bool &default=F ## x509_get_certificate_string x509_verify function x509_ocsp_verify%(certs: x509_opaque_vector, ocsp_reply: string, root_certs: table_string_of_string, verify_time: time &default=network_time()%): X509::Result %{ - zeek::IntrusivePtr rval; + RecordValPtr rval; X509_STORE* ctx = ::file_analysis::X509::GetRootStore(root_certs->AsTableVal()); if ( ! ctx ) return x509_result_record(-1, "Problem initializing root store"); @@ -542,7 +542,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str int result = X509_verify_cert(csc); - zeek::IntrusivePtr chainVector; + VectorValPtr chainVector; if ( result == 1 ) // we have a valid chain. try to get it... { @@ -761,7 +761,7 @@ sct_verify_err: * 1 -> issuer name * 2 -> pubkey */ -zeek::IntrusivePtr x509_entity_hash(file_analysis::X509Val *cert_handle, unsigned int hash_alg, unsigned int type) +StringValPtr x509_entity_hash(file_analysis::X509Val *cert_handle, unsigned int hash_alg, unsigned int type) { assert(cert_handle); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 624a6e7834..c81e949f0b 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -472,7 +472,7 @@ bool Manager::CreateTableStream(RecordVal* fval) auto idx_val = fval->GetFieldOrDefault("idx"); zeek::RecordType* idx = idx_val->AsType()->AsTypeType()->GetType()->AsRecordType(); - zeek::IntrusivePtr val; + zeek::RecordTypePtr val; auto val_val = fval->GetFieldOrDefault("val"); if ( val_val ) @@ -929,7 +929,7 @@ bool Manager::UnrollRecordType(vector *fields, const zeek::RecordType *r { string name = nameprepend + rec->FieldName(i); const char* secondary = nullptr; - zeek::IntrusivePtr c; + ValPtr c; zeek::TypeTag ty = rec->GetFieldType(i)->Tag(); zeek::TypeTag st = zeek::TYPE_VOID; bool optional = false; @@ -991,7 +991,7 @@ bool Manager::ForceUpdate(const string &name) Val* Manager::RecordValToIndexVal(RecordVal *r) const { - zeek::IntrusivePtr idxval; + ValPtr idxval; zeek::RecordType *type = r->GetType()->AsRecordType(); @@ -1159,7 +1159,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) // call stream first to determine if we really add / change the entry if ( stream->pred && ! convert_error ) { - zeek::IntrusivePtr ev; + EnumValPtr ev; int startpos = 0; bool pred_convert_error = false; predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, pred_convert_error); @@ -1230,7 +1230,7 @@ int Manager::SendEntryTable(Stream* i, const Value* const *vals) assert(idxval); - zeek::IntrusivePtr oldval; + ValPtr oldval; if ( updated == true ) { assert(stream->num_val_fields > 0); @@ -1326,9 +1326,9 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) while ( ( ih = stream->lastDict->NextEntry(lastDictIdxKey, c) ) ) { - zeek::IntrusivePtr val; - zeek::IntrusivePtr predidx; - zeek::IntrusivePtr ev; + ValPtr val; + ValPtr predidx; + EnumValPtr ev; int startpos = 0; if ( stream->pred || stream->event ) @@ -1541,7 +1541,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) if ( stream->pred || stream->event ) { bool updated = false; - zeek::IntrusivePtr oldval; + ValPtr oldval; if ( stream->num_val_fields > 0 ) { @@ -1559,7 +1559,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) // predicate if we want the update or not if ( stream->pred ) { - zeek::IntrusivePtr ev; + EnumValPtr ev; int startpos = 0; bool pred_convert_error = false; Val* predidx = ValueToRecordVal(i, vals, stream->itype, &startpos, pred_convert_error); @@ -2435,7 +2435,7 @@ void Manager::ErrorHandler(const Stream* i, ErrorType et, bool reporter_send, co // send our script level error event if ( i->error_event ) { - zeek::IntrusivePtr ev; + EnumValPtr ev; switch (et) { case ErrorType::INFO: diff --git a/src/input/Tag.cc b/src/input/Tag.cc index 00dd51811e..ab2f4823d4 100644 --- a/src/input/Tag.cc +++ b/src/input/Tag.cc @@ -16,7 +16,7 @@ input::Tag& input::Tag::operator=(const input::Tag& other) return *this; } -const zeek::IntrusivePtr& input::Tag::AsVal() const +const EnumValPtr& input::Tag::AsVal() const { return ::Tag::AsVal(input_mgr->GetTagType()); } @@ -26,7 +26,7 @@ EnumVal* input::Tag::AsEnumVal() const return AsVal().get(); } -input::Tag::Tag(zeek::IntrusivePtr val) +input::Tag::Tag(EnumValPtr val) : ::Tag(std::move(val)) { } diff --git a/src/input/Tag.h b/src/input/Tag.h index 1ed52e34ad..436ca66d4a 100644 --- a/src/input/Tag.h +++ b/src/input/Tag.h @@ -89,7 +89,7 @@ public: * * @param etype the script-layer enum type associated with the tag. */ - const zeek::IntrusivePtr& AsVal() const; + const EnumValPtr& AsVal() const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; @@ -117,7 +117,7 @@ protected: * * @param val An enum value of script type \c Input::Reader. */ - explicit Tag(zeek::IntrusivePtr val); + explicit Tag(EnumValPtr val); [[deprecated("Remove in v4.1. Construct from IntrusivePtr isntead.")]] explicit Tag(EnumVal* val); diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 654969c0ce..12e089c2ad 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -2,7 +2,6 @@ #include "Sessions.h" #include "Desc.h" #include "IP.h" -#include "IntrusivePtr.h" #include "iosource/Manager.h" #include "Var.h" @@ -592,7 +591,7 @@ void Packet::ProcessLayer2() hdr_size = (pdata - data); } -zeek::IntrusivePtr Packet::ToRawPktHdrVal() const +RecordValPtr 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"); @@ -674,7 +673,7 @@ RecordVal* Packet::BuildPktHdrVal() const return ToRawPktHdrVal().release(); } -zeek::IntrusivePtr Packet::FmtEUI48(const u_char* mac) const +ValPtr Packet::FmtEUI48(const u_char* mac) const { char buf[20]; snprintf(buf, sizeof buf, "%02x:%02x:%02x:%02x:%02x:%02x", diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index 6f96c7a06b..9ada3be841 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -13,14 +13,17 @@ typedef struct bpf_timeval pkt_timeval; typedef struct timeval pkt_timeval; #endif +namespace zeek { +template class IntrusivePtr; +} + class Val; class ODesc; class IP_Hdr; class RecordVal; -namespace zeek { -template class IntrusivePtr; -} +using ValPtr = zeek::IntrusivePtr; +using RecordValPtr = zeek::IntrusivePtr; /** * The Layer 3 type of a packet, as determined by the parsing code in Packet. @@ -132,7 +135,7 @@ public: * Returns a \c raw_pkt_hdr RecordVal, which includes layer 2 and * also everything in IP_Hdr (i.e., IP4/6 + TCP/UDP/ICMP). */ - zeek::IntrusivePtr ToRawPktHdrVal() const; + RecordValPtr ToRawPktHdrVal() const; [[deprecated("Remove in v4.1. Use ToRawPktHdrval() instead.")]] RecordVal* BuildPktHdrVal() const; @@ -229,7 +232,7 @@ private: void Weird(const char* name); // Renders an MAC address into its ASCII representation. - zeek::IntrusivePtr FmtEUI48(const u_char* mac) const; + ValPtr FmtEUI48(const u_char* mac) const; // True if we need to delete associated packet memory upon // destruction. diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index d72deaf8eb..4c22072382 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -730,14 +730,14 @@ bool Manager::Write(EnumVal* id, RecordVal* columns_arg) if ( filter->path_func ) { - zeek::IntrusivePtr path_arg; + ValPtr path_arg; if ( filter->path_val ) path_arg = {zeek::NewRef{}, filter->path_val}; else path_arg = val_mgr->EmptyString(); - zeek::IntrusivePtr rec_arg; + ValPtr rec_arg; const auto& rt = filter->path_func->GetType()->Params()->GetFieldType("rec"); if ( rt->Tag() == zeek::TYPE_RECORD ) @@ -1048,7 +1048,7 @@ threading::Value* Manager::ValToLogVal(Val* val, zeek::Type* ty) threading::Value** Manager::RecordToFilterVals(Stream* stream, Filter* filter, RecordVal* columns) { - zeek::IntrusivePtr ext_rec; + RecordValPtr ext_rec; if ( filter->num_ext_fields > 0 ) { diff --git a/src/logging/Tag.cc b/src/logging/Tag.cc index 6058758035..07165f561a 100644 --- a/src/logging/Tag.cc +++ b/src/logging/Tag.cc @@ -22,7 +22,7 @@ logging::Tag& logging::Tag::operator=(const logging::Tag&& other) noexcept return *this; } -const zeek::IntrusivePtr& logging::Tag::AsVal() const +const EnumValPtr& logging::Tag::AsVal() const { return ::Tag::AsVal(log_mgr->GetTagType()); } @@ -32,7 +32,7 @@ EnumVal* logging::Tag::AsEnumVal() const return AsVal().get(); } -logging::Tag::Tag(zeek::IntrusivePtr val) +logging::Tag::Tag(EnumValPtr val) : ::Tag(std::move(val)) { } diff --git a/src/logging/Tag.h b/src/logging/Tag.h index b7f5430036..25baaa0635 100644 --- a/src/logging/Tag.h +++ b/src/logging/Tag.h @@ -94,7 +94,7 @@ public: * * @param etype the script-layer enum type associated with the tag. */ - const zeek::IntrusivePtr& AsVal() const; + const EnumValPtr& AsVal() const; [[deprecated("Remove in v4.1. Use AsVal() instead.")]] EnumVal* AsEnumVal() const; @@ -122,7 +122,7 @@ protected: * * @param val An enum value of script type \c Log::Writer. */ - explicit Tag(zeek::IntrusivePtr val); + explicit Tag(EnumValPtr val); [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] explicit Tag(EnumVal* val); diff --git a/src/option.bif b/src/option.bif index af24ce698f..94287978b4 100644 --- a/src/option.bif +++ b/src/option.bif @@ -7,9 +7,8 @@ module Option; #include "NetVar.h" #include "broker/Data.h" -static bool call_option_handlers_and_set_value(StringVal* name, const zeek::IntrusivePtr& i, - zeek::IntrusivePtr val, - StringVal* location) +static bool call_option_handlers_and_set_value(StringVal* name, const zeek::detail::IDPtr& i, + ValPtr val, StringVal* location) { if ( i->HasOptionHandlers() ) { diff --git a/src/parse.y b/src/parse.y index 5b963af194..f240c88813 100644 --- a/src/parse.y +++ b/src/parse.y @@ -82,7 +82,6 @@ #include "Desc.h" #include "Expr.h" #include "Func.h" -#include "IntrusivePtr.h" #include "Stmt.h" #include "Val.h" #include "Var.h" @@ -167,7 +166,7 @@ static void parser_redef_enum (zeek::detail::ID *id) } static void extend_record(zeek::detail::ID* id, std::unique_ptr fields, - std::unique_ptr>> attrs) + std::unique_ptr> attrs) { std::set types = zeek::Type::GetAliases(id->Name()); @@ -199,9 +198,9 @@ static void extend_record(zeek::detail::ID* id, std::unique_ptr -make_attributes(std::vector>* attrs, - zeek::IntrusivePtr t, bool in_record, bool is_global) +static zeek::detail::AttributesPtr +make_attributes(std::vector* attrs, + zeek::TypePtr t, bool in_record, bool is_global) { if ( ! attrs ) return nullptr; @@ -250,7 +249,7 @@ static bool expr_is_table_type_name(const zeek::detail::Expr* expr) zeek::detail::Case* c_case; zeek::detail::case_list* case_l; zeek::detail::Attr* attr; - std::vector>* attr_l; + std::vector* attr_l; zeek::detail::AttrTag attrtag; } @@ -516,8 +515,8 @@ expr: { set_location(@1, @3); $$ = new zeek::detail::NotExpr(zeek::make_intrusive( - zeek::IntrusivePtr{zeek::AdoptRef{}, $1}, - zeek::IntrusivePtr{zeek::AdoptRef{}, $3})); + zeek::detail::ExprPtr{zeek::AdoptRef{}, $1}, + zeek::detail::ExprPtr{zeek::AdoptRef{}, $3})); } | '[' expr_list ']' @@ -562,14 +561,14 @@ expr: opt_attr { // the ++in_init fixes up the parsing of "[x] = y" set_location(@1, @5); - std::unique_ptr>> attrs{$7}; + std::unique_ptr> attrs{$7}; $$ = new zeek::detail::TableConstructorExpr({zeek::AdoptRef{}, $4}, std::move(attrs)); } | TOK_SET '(' opt_expr_list ')' opt_attr { set_location(@1, @4); - std::unique_ptr>> attrs{$5}; + std::unique_ptr> attrs{$5}; $$ = new zeek::detail::SetConstructorExpr({zeek::AdoptRef{}, $3}, std::move(attrs)); } @@ -603,7 +602,7 @@ expr: case zeek::TYPE_RECORD: { auto rce = zeek::make_intrusive( - zeek::IntrusivePtr{zeek::AdoptRef{}, $4}); + zeek::detail::ListExprPtr{zeek::AdoptRef{}, $4}); auto rt = zeek::cast_intrusive(ctor_type); $$ = new zeek::detail::RecordCoerceExpr(std::move(rce), std::move(rt)); } @@ -729,7 +728,7 @@ expr: | '|' expr '|' %prec '(' { set_location(@1, @3); - zeek::IntrusivePtr e{zeek::AdoptRef{}, $2}; + zeek::detail::ExprPtr e{zeek::AdoptRef{}, $2}; if ( zeek::IsIntegral(e->GetType()->Tag()) ) e = zeek::make_intrusive(std::move(e), zeek::TYPE_INT); @@ -1083,7 +1082,7 @@ decl: { zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; add_global(id, {zeek::AdoptRef{}, $3}, $4, {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_REGULAR); zeekygen_mgr->Identifier(std::move(id)); } @@ -1092,7 +1091,7 @@ decl: { zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; add_global(id, {zeek::AdoptRef{}, $3}, $4, {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_OPTION); zeekygen_mgr->Identifier(std::move(id)); } @@ -1101,7 +1100,7 @@ decl: { zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; add_global(id, {zeek::AdoptRef{}, $3}, $4, {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_CONST); zeekygen_mgr->Identifier(std::move(id)); } @@ -1109,9 +1108,9 @@ decl: | TOK_REDEF global_id opt_type init_class opt_init opt_attr ';' { zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; - zeek::IntrusivePtr init{zeek::AdoptRef{}, $5}; + zeek::detail::ExprPtr init{zeek::AdoptRef{}, $5}; add_global(id, {zeek::AdoptRef{}, $3}, $4, init, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_REDEF); zeekygen_mgr->Redef(id.get(), ::filename, $4, std::move(init)); } @@ -1137,7 +1136,7 @@ decl: $3->Error("unknown identifier"); else extend_record($3, std::unique_ptr($8), - std::unique_ptr>>($11)); + std::unique_ptr>($11)); } | TOK_TYPE global_id ':' @@ -1147,7 +1146,7 @@ decl: cur_decl_type_id = 0; zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; add_type(id.get(), {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}); + std::unique_ptr>{$6}); zeekygen_mgr->Identifier(std::move(id)); } @@ -1181,7 +1180,7 @@ func_hdr: zeek::IntrusivePtr id{zeek::AdoptRef{}, $2}; begin_func(id, current_module.c_str(), zeek::FUNC_FLAVOR_FUNCTION, 0, {zeek::NewRef{}, $3}, - std::unique_ptr>>{$4}); + std::unique_ptr>{$4}); $$ = $3; zeekygen_mgr->Identifier(std::move(id)); } @@ -1196,7 +1195,7 @@ func_hdr: begin_func({zeek::NewRef{}, $2}, current_module.c_str(), zeek::FUNC_FLAVOR_EVENT, 0, {zeek::NewRef{}, $3}, - std::unique_ptr>>{$4}); + std::unique_ptr>{$4}); $$ = $3; } | TOK_HOOK def_global_id func_params opt_attr @@ -1205,14 +1204,14 @@ func_hdr: $3->SetYieldType(zeek::base_type(zeek::TYPE_BOOL)); begin_func({zeek::NewRef{}, $2}, current_module.c_str(), zeek::FUNC_FLAVOR_HOOK, 0, {zeek::NewRef{}, $3}, - std::unique_ptr>>{$4}); + std::unique_ptr>{$4}); $$ = $3; } | TOK_REDEF TOK_EVENT event_id func_params opt_attr { begin_func({zeek::NewRef{}, $3}, current_module.c_str(), zeek::FUNC_FLAVOR_EVENT, 1, {zeek::NewRef{}, $4}, - std::unique_ptr>>{$5}); + std::unique_ptr>{$5}); $$ = $4; } ; @@ -1321,12 +1320,12 @@ index_slice: { set_location(@1, @6); - auto low = $3 ? zeek::IntrusivePtr{zeek::AdoptRef{}, $3} : + auto low = $3 ? zeek::detail::ExprPtr{zeek::AdoptRef{}, $3} : zeek::make_intrusive(val_mgr->Count(0)); - auto high = $5 ? zeek::IntrusivePtr{zeek::AdoptRef{}, $5} : + auto high = $5 ? zeek::detail::ExprPtr{zeek::AdoptRef{}, $5} : zeek::make_intrusive( - zeek::IntrusivePtr{zeek::NewRef{}, $1}); + zeek::detail::ExprPtr{zeek::NewRef{}, $1}); if ( ! zeek::IsIntegral(low->GetType()->Tag()) || ! zeek::IsIntegral(high->GetType()->Tag()) ) reporter->Error("slice notation must have integral values as indexes"); @@ -1347,7 +1346,7 @@ attr_list: { $1->emplace_back(zeek::AdoptRef{}, $2); } | attr { - $$ = new std::vector>; + $$ = new std::vector; $$->emplace_back(zeek::AdoptRef{}, $1); } ; @@ -1517,7 +1516,7 @@ stmt: set_location(@1, @7); $$ = add_local({zeek::AdoptRef{}, $2}, {zeek::AdoptRef{}, $3}, $4, {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_REGULAR).release(); if ( ! $8 ) brofiler.AddStmt($$); @@ -1528,7 +1527,7 @@ stmt: set_location(@1, @6); $$ = add_local({zeek::AdoptRef{}, $2}, {zeek::AdoptRef{}, $3}, $4, {zeek::AdoptRef{}, $5}, - std::unique_ptr>>{$6}, + std::unique_ptr>{$6}, VAR_CONST).release(); if ( ! $8 ) brofiler.AddStmt($$); @@ -1667,7 +1666,7 @@ case_type: | TOK_TYPE type TOK_AS TOK_ID { const char* name = $4; - zeek::IntrusivePtr type{zeek::AdoptRef{}, $2}; + zeek::TypePtr type{zeek::AdoptRef{}, $2}; auto case_var = lookup_ID(name, current_module.c_str()); if ( case_var && case_var->IsGlobal() ) diff --git a/src/plugin/ComponentManager.h b/src/plugin/ComponentManager.h index 45e9ae0ebb..a47e557e24 100644 --- a/src/plugin/ComponentManager.h +++ b/src/plugin/ComponentManager.h @@ -4,7 +4,6 @@ #include #include -#include "IntrusivePtr.h" #include "Type.h" #include "Var.h" // for add_type() #include "Val.h" @@ -52,7 +51,7 @@ public: /** * @return The enum type associated with the script-layer "Tag". */ - const zeek::IntrusivePtr& GetTagType() const; + const zeek::EnumTypePtr& GetTagType() const; [[deprecated("Remove in v4.1. Use GetTagType() instead.")]] zeek::EnumType* GetTagEnumType() const; @@ -71,7 +70,7 @@ public: * @param val A component's enum value. * @return The canonical component name. */ - const std::string& GetComponentName(zeek::IntrusivePtr val) const; + const std::string& GetComponentName(EnumValPtr val) const; [[deprecated("Remove in v4.1. Use IntrusivePtr argument instead.")]] const std::string& GetComponentName(Val* val) const; @@ -128,7 +127,7 @@ public: private: std::string module; /**< Script layer module in which component tags live. */ - zeek::IntrusivePtr tag_enum_type; /**< Enum type of component tags. */ + zeek::EnumTypePtr tag_enum_type; /**< Enum type of component tags. */ std::map components_by_name; std::map components_by_tag; std::map components_by_val; @@ -163,7 +162,7 @@ std::list ComponentManager::GetComponents() const } template -const zeek::IntrusivePtr& ComponentManager::GetTagType() const +const zeek::EnumTypePtr& ComponentManager::GetTagType() const { return tag_enum_type; } @@ -193,7 +192,7 @@ const std::string& ComponentManager::GetComponentName(T tag) const } template -const std::string& ComponentManager::GetComponentName(zeek::IntrusivePtr val) const +const std::string& ComponentManager::GetComponentName(EnumValPtr val) const { return GetComponentName(T(std::move(val))); } diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index f4feb6e964..cea23645fc 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -616,7 +616,7 @@ int Manager::HookLoadFile(const Plugin::LoadType type, const string& file, const return rc; } -std::pair> +std::pair Manager::HookCallFunction(const Func* func, Frame* parent, zeek::Args* vecargs) const { @@ -638,7 +638,7 @@ Manager::HookCallFunction(const Func* func, Frame* parent, hook_list* l = hooks[zeek::plugin::HOOK_CALL_FUNCTION]; - std::pair> rval{false, nullptr}; + std::pair rval{false, nullptr}; if ( l ) { diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index a52a4d54be..9e74e911ac 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -255,7 +255,7 @@ public: * it may be any Val and must be ignored). If no plugin handled the call, * the method returns null. */ - std::pair> + std::pair HookCallFunction(const Func* func, Frame* parent, zeek::Args* args) const; /** diff --git a/src/plugin/Plugin.cc b/src/plugin/Plugin.cc index 3bc07413e9..59284a2474 100644 --- a/src/plugin/Plugin.cc +++ b/src/plugin/Plugin.cc @@ -375,7 +375,7 @@ int Plugin::HookLoadFile(const LoadType type, const std::string& file, const std return -1; } -std::pair> +std::pair Plugin::HookFunctionCall(const Func* func, Frame* parent, zeek::Args* args) { diff --git a/src/plugin/Plugin.h b/src/plugin/Plugin.h index b46bae6b10..7c60937017 100644 --- a/src/plugin/Plugin.h +++ b/src/plugin/Plugin.h @@ -21,6 +21,8 @@ class Frame; class Func; class Event; +using ValPtr = zeek::IntrusivePtr; + namespace zeek { template class IntrusivePtr; } @@ -671,7 +673,7 @@ protected: * interpreter. If the plugin did not handle the call, it must return a * pair with the first member set to 'false' and null result value. */ - virtual std::pair> + virtual std::pair HookFunctionCall(const Func* func, Frame* parent, zeek::Args* args); [[deprecated("Remove in v4.1. Use HookFunctionCall()")]] diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 6faa2d5c70..40b7d3d10a 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -6,7 +6,6 @@ #include "broker/Data.h" #include "CompHash.h" -#include "IntrusivePtr.h" #include "Reporter.h" #include "Dict.h" @@ -18,7 +17,7 @@ static void topk_element_hash_delete_func(void* val) delete e; } -void TopkVal::Typify(zeek::IntrusivePtr t) +void TopkVal::Typify(zeek::TypePtr t) { assert(!hash && !type); type = std::move(t); @@ -176,14 +175,14 @@ void TopkVal::Merge(const TopkVal* value, bool doPrune) } } -zeek::IntrusivePtr TopkVal::DoClone(CloneState* state) +ValPtr TopkVal::DoClone(CloneState* state) { auto clone = zeek::make_intrusive(size); clone->Merge(this); return state->NewClone(this, std::move(clone)); } -zeek::IntrusivePtr TopkVal::GetTopK(int k) const // returns vector +VectorValPtr TopkVal::GetTopK(int k) const // returns vector { if ( numElements == 0 ) { @@ -269,7 +268,7 @@ uint64_t TopkVal::GetSum() const return sum; } -void TopkVal::Encountered(zeek::IntrusivePtr encountered) +void TopkVal::Encountered(ValPtr encountered) { // ok, let's see if we already know this one. diff --git a/src/probabilistic/Topk.h b/src/probabilistic/Topk.h index 1f008b4638..2f7bd883dd 100644 --- a/src/probabilistic/Topk.h +++ b/src/probabilistic/Topk.h @@ -27,7 +27,7 @@ struct Bucket { struct Element { uint64_t epsilon; - zeek::IntrusivePtr value; + ValPtr value; Bucket* parent; }; @@ -55,7 +55,7 @@ public: * * @param value The encountered element */ - void Encountered(zeek::IntrusivePtr value); + void Encountered(ValPtr value); /** * Get the first *k* elements of the result vector. At the moment, @@ -66,7 +66,7 @@ public: * * @returns The top-k encountered elements */ - zeek::IntrusivePtr GetTopK(int k) const; + VectorValPtr GetTopK(int k) const; /** * Get the current count tracked in the top-k data structure for a @@ -125,7 +125,7 @@ public: * * @returns cloned TopkVal */ - zeek::IntrusivePtr DoClone(CloneState* state) override; + ValPtr DoClone(CloneState* state) override; DECLARE_OPAQUE_VALUE(TopkVal) @@ -153,7 +153,7 @@ private: * @returns HashKey for value */ HashKey* GetHash(Val* v) const; // this probably should go somewhere else. - HashKey* GetHash(const zeek::IntrusivePtr& v) const + HashKey* GetHash(const ValPtr& v) const { return GetHash(v.get()); } /** @@ -161,9 +161,9 @@ private: * * @param t type that is tracked */ - void Typify(zeek::IntrusivePtr t); + void Typify(zeek::TypePtr t); - zeek::IntrusivePtr type; + zeek::TypePtr type; CompositeHash* hash; std::list buckets; PDict* elementDict; diff --git a/src/scan.l b/src/scan.l index 41129ead9a..34e05f4b05 100644 --- a/src/scan.l +++ b/src/scan.l @@ -749,7 +749,7 @@ void do_atif(zeek::detail::Expr* expr) LocalNameFinder cb; expr->Traverse(&cb); - zeek::IntrusivePtr val; + ValPtr val; if ( cb.local_names.empty() ) val = expr->Eval(nullptr); diff --git a/src/stats.bif b/src/stats.bif index 96780b344c..d1a6295211 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -4,19 +4,19 @@ #include "threading/Manager.h" #include "broker/Manager.h" -zeek::IntrusivePtr ProcStats; -zeek::IntrusivePtr NetStats; -zeek::IntrusivePtr MatcherStats; -zeek::IntrusivePtr ReassemblerStats; -zeek::IntrusivePtr DNSStats; -zeek::IntrusivePtr ConnStats; -zeek::IntrusivePtr GapStats; -zeek::IntrusivePtr EventStats; -zeek::IntrusivePtr ThreadStats; -zeek::IntrusivePtr TimerStats; -zeek::IntrusivePtr FileAnalysisStats; -zeek::IntrusivePtr BrokerStats; -zeek::IntrusivePtr ReporterStats; +zeek::RecordTypePtr ProcStats; +zeek::RecordTypePtr NetStats; +zeek::RecordTypePtr MatcherStats; +zeek::RecordTypePtr ReassemblerStats; +zeek::RecordTypePtr DNSStats; +zeek::RecordTypePtr ConnStats; +zeek::RecordTypePtr GapStats; +zeek::RecordTypePtr EventStats; +zeek::RecordTypePtr ThreadStats; +zeek::RecordTypePtr TimerStats; +zeek::RecordTypePtr FileAnalysisStats; +zeek::RecordTypePtr BrokerStats; +zeek::RecordTypePtr ReporterStats; %%} ## Returns packet capture statistics. Statistics include the number of diff --git a/src/strings.bif b/src/strings.bif index e450f65e93..7520726f44 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -199,9 +199,9 @@ static int match_prefix(int s_len, const char* s, int t_len, const char* t) return 1; } -static zeek::IntrusivePtr do_split_string(StringVal* str_val, - RE_Matcher* re, int incl_sep, - int max_num_sep) +static VectorValPtr do_split_string(StringVal* str_val, + RE_Matcher* re, int incl_sep, + int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. auto rval = zeek::make_intrusive(zeek::id::find_type("string_vec")); @@ -686,7 +686,7 @@ function str_smith_waterman%(s1: string, s2: string, params: sw_params%) : sw_su BroSubstring::Vec* subseq = smith_waterman(s1->AsString(), s2->AsString(), sw_params); - auto result = zeek::IntrusivePtr{zeek::AdoptRef{}, BroSubstring::VecToPolicy(subseq)}; + auto result = VectorValPtr{zeek::AdoptRef{}, BroSubstring::VecToPolicy(subseq)}; delete_each(subseq); delete subseq; diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index 73353e4fc6..f4beb97069 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -1102,7 +1102,7 @@ std::string Supervisor::NodeConfig::ToJSON() const return ToRecord()->ToJSON(false, re.get())->ToStdString(); } -zeek::IntrusivePtr Supervisor::NodeConfig::ToRecord() const +RecordValPtr Supervisor::NodeConfig::ToRecord() const { const auto& rt = zeek::BifType::Record::Supervisor::NodeConfig; auto rval = zeek::make_intrusive(rt); @@ -1156,7 +1156,7 @@ zeek::IntrusivePtr Supervisor::NodeConfig::ToRecord() const return rval; } -zeek::IntrusivePtr Supervisor::Node::ToRecord() const +RecordValPtr Supervisor::Node::ToRecord() const { const auto& rt = zeek::BifType::Record::Supervisor::NodeStatus; auto rval = zeek::make_intrusive(rt); @@ -1170,7 +1170,7 @@ zeek::IntrusivePtr Supervisor::Node::ToRecord() const } -static zeek::IntrusivePtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) +static ValPtr supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role) { static auto node_type = zeek::id::find_type("Cluster::NodeType"); @@ -1312,7 +1312,7 @@ void Supervisor::SupervisedNode::Init(zeek::Options* options) const options->scripts_to_load.emplace_back(s); } -zeek::IntrusivePtr Supervisor::Status(std::string_view node_name) +RecordValPtr Supervisor::Status(std::string_view node_name) { auto rval = zeek::make_intrusive(zeek::BifType::Record::Supervisor::Status); const auto& tt = zeek::BifType::Record::Supervisor::Status->GetFieldType("nodes"); diff --git a/src/supervisor/Supervisor.h b/src/supervisor/Supervisor.h index 1d92d60b77..114385366b 100644 --- a/src/supervisor/Supervisor.h +++ b/src/supervisor/Supervisor.h @@ -103,7 +103,7 @@ public: * Convert his object into script-layer record value. * @return the script-layer record value representing the node config. */ - zeek::IntrusivePtr ToRecord() const; + RecordValPtr ToRecord() const; /** * The name of the supervised Zeek node. These are unique within @@ -183,7 +183,7 @@ public: * Convert the node into script-layer Supervisor::NodeStatus record * representation. */ - zeek::IntrusivePtr ToRecord() const; + RecordValPtr ToRecord() const; /** * @return the name of the node. @@ -311,7 +311,7 @@ public: * @return script-layer Supervisor::Status record value describing the * status of a node or set of nodes. */ - zeek::IntrusivePtr Status(std::string_view node_name); + RecordValPtr Status(std::string_view node_name); /** * Create a new supervised node. diff --git a/src/threading/SerialTypes.cc b/src/threading/SerialTypes.cc index a46cb87e7b..c6e95c18fc 100644 --- a/src/threading/SerialTypes.cc +++ b/src/threading/SerialTypes.cc @@ -524,7 +524,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e case zeek::TYPE_TABLE: { - zeek::IntrusivePtr set_index; + zeek::TypeListPtr set_index; if ( val->val.set_val.size == 0 && val->subtype == zeek::TYPE_VOID ) // don't know type - unspecified table. set_index = zeek::make_intrusive(); @@ -535,7 +535,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e if ( stag == zeek::TYPE_VOID ) stag = val->val.set_val.vals[0]->type; - zeek::IntrusivePtr index_type; + zeek::TypePtr index_type; if ( stag == zeek::TYPE_ENUM ) { @@ -575,7 +575,7 @@ Val* Value::ValueToVal(const std::string& source, const Value* val, bool& have_e case zeek::TYPE_VECTOR: { - zeek::IntrusivePtr type; + zeek::TypePtr type; if ( val->val.vector_val.size == 0 && val->subtype == zeek::TYPE_VOID ) // don't know type - unspecified table. diff --git a/src/zeek-setup.cc b/src/zeek-setup.cc index 91e2749c25..aa637a8f79 100644 --- a/src/zeek-setup.cc +++ b/src/zeek-setup.cc @@ -114,16 +114,16 @@ vector params; set requested_plugins; const char* proc_status_file = nullptr; -zeek::IntrusivePtr md5_type; -zeek::IntrusivePtr sha1_type; -zeek::IntrusivePtr sha256_type; -zeek::IntrusivePtr entropy_type; -zeek::IntrusivePtr cardinality_type; -zeek::IntrusivePtr topk_type; -zeek::IntrusivePtr bloomfilter_type; -zeek::IntrusivePtr x509_opaque_type; -zeek::IntrusivePtr ocsp_resp_opaque_type; -zeek::IntrusivePtr paraglob_type; +zeek::OpaqueTypePtr md5_type; +zeek::OpaqueTypePtr sha1_type; +zeek::OpaqueTypePtr sha256_type; +zeek::OpaqueTypePtr entropy_type; +zeek::OpaqueTypePtr cardinality_type; +zeek::OpaqueTypePtr topk_type; +zeek::OpaqueTypePtr bloomfilter_type; +zeek::OpaqueTypePtr x509_opaque_type; +zeek::OpaqueTypePtr ocsp_resp_opaque_type; +zeek::OpaqueTypePtr paraglob_type; // Keep copy of command line int bro_argc; diff --git a/src/zeek.bif b/src/zeek.bif index 360a8defda..046b0c3b96 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -1328,9 +1328,9 @@ function all_set%(v: any%) : bool %%{ static Func* sort_function_comp = nullptr; -static std::vector*> index_map; // used for indirect sorting to support order() +static std::vector index_map; // used for indirect sorting to support order() -bool sort_function(const zeek::IntrusivePtr& a, const zeek::IntrusivePtr& b) +bool sort_function(const ValPtr& a, const ValPtr& b) { // Sort missing values as "high". if ( ! a ) @@ -1349,7 +1349,7 @@ bool indirect_sort_function(size_t a, size_t b) return sort_function(*index_map[a], *index_map[b]); } -bool signed_sort_function (const zeek::IntrusivePtr& a, const zeek::IntrusivePtr& b) +bool signed_sort_function (const ValPtr& a, const ValPtr& b) { if ( ! a ) return 0; @@ -1362,7 +1362,7 @@ bool signed_sort_function (const zeek::IntrusivePtr& a, const zeek::Intrusi return ia < ib; } -bool unsigned_sort_function (const zeek::IntrusivePtr& a, const zeek::IntrusivePtr& b) +bool unsigned_sort_function (const ValPtr& a, const ValPtr& b) { if ( ! a ) return 0; @@ -1401,7 +1401,7 @@ bool indirect_unsigned_sort_function(size_t a, size_t b) ## .. zeek:see:: order function sort%(v: any, ...%) : any %{ - zeek::IntrusivePtr rval{zeek::NewRef{}, v}; + ValPtr rval{zeek::NewRef{}, v}; if ( v->GetType()->Tag() != zeek::TYPE_VECTOR ) { @@ -1491,7 +1491,7 @@ function order%(v: any, ...%) : index_vec if ( ! IsFunc(comp_val->GetType()->Tag()) ) { builtin_error("second argument to order() needs to be comparison function"); - return zeek::IntrusivePtr{zeek::NewRef{}, v}; + return ValPtr{zeek::NewRef{}, v}; } comp = comp_val->AsFunc(); @@ -1521,7 +1521,7 @@ function order%(v: any, ...%) : index_vec ! comp_type->ParamList()->AllMatch(elt_type, 0) ) { builtin_error("invalid comparison function in call to order()"); - return zeek::IntrusivePtr{zeek::NewRef{}, v}; + return ValPtr{zeek::NewRef{}, v}; } sort_function_comp = comp; @@ -2440,7 +2440,7 @@ function count_to_port%(num: count, proto: transport_proto%): port function to_addr%(ip: string%): addr %{ char* s = ip->AsString()->Render(); - zeek::IntrusivePtr ret; + ValPtr ret; in6_addr tmp; if ( IPAddr::ConvertString(s, &tmp) ) @@ -3209,7 +3209,7 @@ function is_icmp_port%(p: port%): bool %} %%{ -static zeek::IntrusivePtr map_conn_type(TransportProto tp) +static EnumValPtr map_conn_type(TransportProto tp) { switch ( tp ) { case TRANSPORT_UNKNOWN: @@ -3862,8 +3862,8 @@ static bool mmdb_lookup_asn(const IPAddr& addr, MMDB_lookup_result_s& result) return mmdb_lookup(addr, result, true); } -static zeek::IntrusivePtr mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, - int data_type ) +static ValPtr mmdb_getvalue(MMDB_entry_data_s* entry_data, int status, + int data_type ) { switch (status) { @@ -4623,7 +4623,7 @@ function get_file_name%(f: file%): string ## .. zeek:see:: rotate_file_by_name calc_next_rotate function rotate_file%(f: file%): rotate_info %{ - zeek::IntrusivePtr info{zeek::AdoptRef{}, f->Rotate()}; + RecordValPtr info{zeek::AdoptRef{}, f->Rotate()}; if ( info ) return info; diff --git a/src/zeekygen/IdentifierInfo.cc b/src/zeekygen/IdentifierInfo.cc index ee24605743..46ee45dbe3 100644 --- a/src/zeekygen/IdentifierInfo.cc +++ b/src/zeekygen/IdentifierInfo.cc @@ -11,7 +11,7 @@ using namespace std; using namespace zeekygen; -IdentifierInfo::IdentifierInfo(zeek::IntrusivePtr arg_id, ScriptInfo* script) +IdentifierInfo::IdentifierInfo(zeek::detail::IDPtr arg_id, ScriptInfo* script) : Info(), comments(), id(std::move(arg_id)), initial_val(), redefs(), fields(), last_field_seen(), declaring_script(script) @@ -32,7 +32,7 @@ IdentifierInfo::~IdentifierInfo() } void IdentifierInfo::AddRedef(const string& script, zeek::detail::InitClass ic, - zeek::IntrusivePtr init_expr, const vector& comments) + zeek::detail::ExprPtr init_expr, const vector& comments) { Redefinition* redef = new Redefinition(script, ic, std::move(init_expr), comments); redefs.push_back(redef); @@ -139,11 +139,10 @@ time_t IdentifierInfo::DoGetModificationTime() const return declaring_script->GetModificationTime(); } -IdentifierInfo::Redefinition::Redefinition( - std::string arg_script, - zeek::detail::InitClass arg_ic, - zeek::IntrusivePtr arg_expr, - std::vector arg_comments) +IdentifierInfo::Redefinition::Redefinition(std::string arg_script, + zeek::detail::InitClass arg_ic, + zeek::detail::ExprPtr arg_expr, + std::vector arg_comments) : from_script(std::move(arg_script)), ic(arg_ic), init_expr(std::move(arg_expr)), diff --git a/src/zeekygen/IdentifierInfo.h b/src/zeekygen/IdentifierInfo.h index 17bc2a78b6..77dad0488d 100644 --- a/src/zeekygen/IdentifierInfo.h +++ b/src/zeekygen/IdentifierInfo.h @@ -32,7 +32,7 @@ public: * @param script The info object associated with the script in which \a id * is declared. */ - IdentifierInfo(zeek::IntrusivePtr id, ScriptInfo* script); + IdentifierInfo(zeek::detail::IDPtr id, ScriptInfo* script); /** * Dtor. Releases any references to script-level objects. @@ -42,7 +42,7 @@ public: /** * Returns the initial value of the identifier. */ - const zeek::IntrusivePtr& InitialVal() const + const ValPtr& InitialVal() const { return initial_val; } /** @@ -71,7 +71,7 @@ public: * @param comments Comments associated with the redef statement. */ void AddRedef(const std::string& from_script, zeek::detail::InitClass ic, - zeek::IntrusivePtr init_expr, + zeek::detail::ExprPtr init_expr, const std::vector& comments); /** @@ -128,11 +128,11 @@ public: struct Redefinition { std::string from_script; /**< Name of script doing the redef. */ zeek::detail::InitClass ic; - zeek::IntrusivePtr init_expr; + zeek::detail::ExprPtr init_expr; std::vector comments; /**< Zeekygen comments on redef. */ Redefinition(std::string arg_script, zeek::detail::InitClass arg_ic, - zeek::IntrusivePtr arg_expr, + zeek::detail::ExprPtr arg_expr, std::vector arg_comments); ~Redefinition(); @@ -174,8 +174,8 @@ private: typedef std::map record_field_map; std::vector comments; - zeek::IntrusivePtr id; - zeek::IntrusivePtr initial_val; + zeek::detail::IDPtr id; + ValPtr initial_val; redef_list redefs; record_field_map fields; RecordField* last_field_seen; diff --git a/src/zeekygen/Manager.cc b/src/zeekygen/Manager.cc index 117dac8652..59ef519491 100644 --- a/src/zeekygen/Manager.cc +++ b/src/zeekygen/Manager.cc @@ -216,7 +216,7 @@ void Manager::ModuleUsage(const string& path, const string& module) module.c_str(), name.c_str()); } -IdentifierInfo* Manager::CreateIdentifierInfo(zeek::IntrusivePtr id, ScriptInfo* script) +IdentifierInfo* Manager::CreateIdentifierInfo(zeek::detail::IDPtr id, ScriptInfo* script) { const auto& id_name = id->Name(); auto prev = identifiers.GetInfo(id_name); @@ -247,7 +247,7 @@ IdentifierInfo* Manager::CreateIdentifierInfo(zeek::IntrusivePtr id) +void Manager::StartType(zeek::detail::IDPtr id) { if ( disabled ) return; @@ -278,7 +278,7 @@ static bool IsEnumType(zeek::detail::ID* id) return id->IsType() ? id->GetType()->Tag() == zeek::TYPE_ENUM : false; } -void Manager::Identifier(zeek::IntrusivePtr id) +void Manager::Identifier(zeek::detail::IDPtr id) { if ( disabled ) return; @@ -361,7 +361,8 @@ void Manager::RecordField(const zeek::detail::ID* id, const zeek::TypeDecl* fiel } void Manager::Redef(const zeek::detail::ID* id, const string& path, - zeek::detail::InitClass ic, zeek::IntrusivePtr init_expr) + zeek::detail::InitClass ic, + zeek::detail::ExprPtr init_expr) { if ( disabled ) return; diff --git a/src/zeekygen/Manager.h b/src/zeekygen/Manager.h index 2dff34318e..f5162131ea 100644 --- a/src/zeekygen/Manager.h +++ b/src/zeekygen/Manager.h @@ -15,7 +15,6 @@ #include "ID.h" #include "util.h" -template class IntrusivePtr; ZEEK_FORWARD_DECLARE_NAMESPACED(TypeDecl, zeek); namespace zeekygen { @@ -111,14 +110,14 @@ public: * Signal that a record or enum type is now being parsed. * @param id The record or enum type identifier. */ - void StartType(zeek::IntrusivePtr id); + void StartType(zeek::detail::IDPtr id); /** * Register a script-level identifier for which information/documentation * will be gathered. * @param id The script-level identifier. */ - void Identifier(zeek::IntrusivePtr id); + void Identifier(zeek::detail::IDPtr id); /** * Register a record-field for which information/documentation will be @@ -140,7 +139,7 @@ public: * @param init_expr The intiialization expression that was used. */ void Redef(const zeek::detail::ID* id, const std::string& path, - zeek::detail::InitClass ic, zeek::IntrusivePtr init_expr); + zeek::detail::InitClass ic, zeek::detail::ExprPtr init_expr); void Redef(const zeek::detail::ID* id, const std::string& path, zeek::detail::InitClass ic = zeek::detail::INIT_NONE); @@ -218,7 +217,7 @@ private: typedef std::vector comment_buffer_t; typedef std::map comment_buffer_map_t; - IdentifierInfo* CreateIdentifierInfo(zeek::IntrusivePtr id, ScriptInfo* script); + IdentifierInfo* CreateIdentifierInfo(zeek::detail::IDPtr id, ScriptInfo* script); bool disabled; comment_buffer_t comment_buffer; // For whatever next identifier comes in. diff --git a/src/zeekygen/zeekygen.bif b/src/zeekygen/zeekygen.bif index 1ce3daada7..f7a84c840e 100644 --- a/src/zeekygen/zeekygen.bif +++ b/src/zeekygen/zeekygen.bif @@ -9,7 +9,7 @@ #include "zeekygen/ScriptInfo.h" #include "util.h" -static zeek::IntrusivePtr comments_to_val(const vector& comments) +static StringValPtr comments_to_val(const vector& comments) { return zeek::make_intrusive(implode_string_vector(comments)); }