Use type aliases for IntrusivePtr definitions

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:46:34 -04:00
parent f6a251cdac
commit ec9eff0bd5
180 changed files with 2026 additions and 1893 deletions

View file

@ -358,9 +358,9 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a)
return nullptr; return nullptr;
} }
static zeek::IntrusivePtr<TableVal> anon_preserve_orig_addr; static TableValPtr anon_preserve_orig_addr;
static zeek::IntrusivePtr<TableVal> anon_preserve_resp_addr; static TableValPtr anon_preserve_resp_addr;
static zeek::IntrusivePtr<TableVal> anon_preserve_other_addr; static TableValPtr anon_preserve_other_addr;
void zeek::detail::init_ip_addr_anonymizers() void zeek::detail::init_ip_addr_anonymizers()
{ {

View file

@ -25,7 +25,7 @@ const char* attr_name(AttrTag t)
return attr_names[int(t)]; return attr_names[int(t)];
} }
Attr::Attr(AttrTag t, zeek::IntrusivePtr<Expr> e) Attr::Attr(AttrTag t, ExprPtr e)
: expr(std::move(e)) : expr(std::move(e))
{ {
tag = t; tag = t;
@ -37,7 +37,7 @@ Attr::Attr(AttrTag t)
{ {
} }
void Attr::SetAttrExpr(zeek::IntrusivePtr<zeek::detail::Expr> e) void Attr::SetAttrExpr(ExprPtr e)
{ expr = std::move(e); } { expr = std::move(e); }
void Attr::Describe(ODesc* d) const void Attr::Describe(ODesc* d) const
@ -136,7 +136,7 @@ void Attr::AddTag(ODesc* d) const
d->Add(attr_name(Tag())); d->Add(attr_name(Tag()));
} }
Attributes::Attributes(attr_list* a, zeek::IntrusivePtr<Type> 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_list.resize(a->length());
attrs.reserve(a->length()); attrs.reserve(a->length());
@ -155,15 +155,13 @@ Attributes::Attributes(attr_list* a, zeek::IntrusivePtr<Type> t, bool arg_in_rec
delete a; delete a;
} }
Attributes::Attributes(zeek::IntrusivePtr<Type> t, Attributes::Attributes(TypePtr t, bool arg_in_record, bool is_global)
bool arg_in_record, bool is_global) : Attributes(std::vector<AttrPtr>{}, std::move(t),
: Attributes(std::vector<zeek::IntrusivePtr<Attr>>{}, std::move(t),
arg_in_record, is_global) arg_in_record, is_global)
{} {}
Attributes::Attributes(std::vector<zeek::IntrusivePtr<Attr>> a, Attributes::Attributes(std::vector<AttrPtr> a,
zeek::IntrusivePtr<Type> t, TypePtr t, bool arg_in_record, bool is_global)
bool arg_in_record, bool is_global)
: type(std::move(t)) : type(std::move(t))
{ {
attrs_list.resize(a.size()); attrs_list.resize(a.size());
@ -181,7 +179,7 @@ Attributes::Attributes(std::vector<zeek::IntrusivePtr<Attr>> a,
AddAttr(std::move(attr)); AddAttr(std::move(attr));
} }
void Attributes::AddAttr(zeek::IntrusivePtr<Attr> attr) void Attributes::AddAttr(AttrPtr attr)
{ {
// We overwrite old attributes by deleting them first. // We overwrite old attributes by deleting them first.
RemoveAttr(attr->Tag()); RemoveAttr(attr->Tag());
@ -212,7 +210,7 @@ void Attributes::AddAttr(zeek::IntrusivePtr<Attr> attr)
} }
} }
void Attributes::AddAttrs(const zeek::IntrusivePtr<Attributes>& a) void Attributes::AddAttrs(const AttributesPtr& a)
{ {
for ( const auto& attr : a->GetAttrs() ) for ( const auto& attr : a->GetAttrs() )
AddAttr(attr); AddAttr(attr);
@ -235,7 +233,7 @@ Attr* Attributes::FindAttr(AttrTag t) const
return nullptr; return nullptr;
} }
const zeek::IntrusivePtr<Attr>& Attributes::Find(AttrTag t) const const AttrPtr& Attributes::Find(AttrTag t) const
{ {
for ( const auto& a : attrs ) for ( const auto& a : attrs )
if ( a->Tag() == t ) if ( a->Tag() == t )

View file

@ -10,6 +10,15 @@
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
namespace zeek {
class Type;
using TypePtr = IntrusivePtr<Type>;
namespace detail {
using ExprPtr = zeek::IntrusivePtr<Expr>;
}
}
// Note that there are two kinds of attributes: the kind (here) which // Note that there are two kinds of attributes: the kind (here) which
// modify expressions or supply metadata on types, and the kind that // modify expressions or supply metadata on types, and the kind that
// are extra metadata on every variable instance. // are extra metadata on every variable instance.
@ -38,11 +47,16 @@ enum AttrTag {
NUM_ATTRS // this item should always be last NUM_ATTRS // this item should always be last
}; };
class Attr;
using AttrPtr = zeek::IntrusivePtr<Attr>;
class Attributes;
using AttributesPtr = zeek::IntrusivePtr<Attributes>;
class Attr final : public BroObj { class Attr final : public BroObj {
public: public:
static inline const zeek::IntrusivePtr<zeek::detail::Attr> nil; static inline const AttrPtr nil;
Attr(AttrTag t, zeek::IntrusivePtr<zeek::detail::Expr> e); Attr(AttrTag t, ExprPtr e);
explicit Attr(AttrTag t); explicit Attr(AttrTag t);
~Attr() override = default; ~Attr() override = default;
@ -52,10 +66,10 @@ public:
[[deprecated("Remove in v4.1. Use GetExpr().")]] [[deprecated("Remove in v4.1. Use GetExpr().")]]
zeek::detail::Expr* AttrExpr() const { return expr.get(); } zeek::detail::Expr* AttrExpr() const { return expr.get(); }
const zeek::IntrusivePtr<zeek::detail::Expr>& GetExpr() const const ExprPtr& GetExpr() const
{ return expr; } { return expr; }
void SetAttrExpr(zeek::IntrusivePtr<zeek::detail::Expr> e); void SetAttrExpr(ExprPtr e);
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
void DescribeReST(ODesc* d, bool shorten = false) const; void DescribeReST(ODesc* d, bool shorten = false) const;
@ -78,24 +92,24 @@ protected:
void AddTag(ODesc* d) const; void AddTag(ODesc* d) const;
AttrTag tag; AttrTag tag;
zeek::IntrusivePtr<Expr> expr; ExprPtr expr;
}; };
// Manages a collection of attributes. // Manages a collection of attributes.
class Attributes final : public BroObj { class Attributes final : public BroObj {
public: public:
[[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]] [[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]]
Attributes(attr_list* a, zeek::IntrusivePtr<Type> t, bool in_record, bool is_global); Attributes(attr_list* a, zeek::TypePtr t, bool in_record, bool is_global);
Attributes(std::vector<zeek::IntrusivePtr<Attr>> a, zeek::IntrusivePtr<Type> t, Attributes(std::vector<AttrPtr> a, zeek::TypePtr t,
bool in_record, bool is_global); bool in_record, bool is_global);
Attributes(zeek::IntrusivePtr<Type> t, bool in_record, bool is_global); Attributes(TypePtr t, bool in_record, bool is_global);
~Attributes() override = default; ~Attributes() override = default;
void AddAttr(zeek::IntrusivePtr<Attr> a); void AddAttr(AttrPtr a);
void AddAttrs(const zeek::IntrusivePtr<Attributes>& a); void AddAttrs(const AttributesPtr& a);
[[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]]
void AddAttrs(Attributes* a); // Unref's 'a' when done void AddAttrs(Attributes* a); // Unref's 'a' when done
@ -103,7 +117,7 @@ public:
[[deprecated("Remove in v4.1. Use Find().")]] [[deprecated("Remove in v4.1. Use Find().")]]
Attr* FindAttr(AttrTag t) const; Attr* FindAttr(AttrTag t) const;
const zeek::IntrusivePtr<Attr>& Find(AttrTag t) const; const AttrPtr& Find(AttrTag t) const;
void RemoveAttr(AttrTag t); void RemoveAttr(AttrTag t);
@ -114,7 +128,7 @@ public:
const attr_list* Attrs() const const attr_list* Attrs() const
{ return &attrs_list; } { return &attrs_list; }
const std::vector<zeek::IntrusivePtr<Attr>>& GetAttrs() const const std::vector<AttrPtr>& GetAttrs() const
{ return attrs; } { return attrs; }
bool operator==(const Attributes& other) const; bool operator==(const Attributes& other) const;
@ -122,8 +136,8 @@ public:
protected: protected:
void CheckAttr(Attr* attr); void CheckAttr(Attr* attr);
zeek::IntrusivePtr<Type> type; TypePtr type;
std::vector<zeek::IntrusivePtr<Attr>> attrs; std::vector<AttrPtr> attrs;
// Remove in v4.1. This is used by Attrs(), which is deprecated. // Remove in v4.1. This is used by Attrs(), which is deprecated.
attr_list attrs_list; attr_list attrs_list;

View file

@ -5,6 +5,7 @@
#include "IntrusivePtr.h" #include "IntrusivePtr.h"
class Val; class Val;
using ValPtr = zeek::IntrusivePtr<Val>;
/** /**
* A simple wrapper class to use for the return value of BIFs so that * 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.")]] [[deprecated("Remove in v4.1. Return an IntrusivePtr instead.")]]
BifReturnVal(Val* v) noexcept; BifReturnVal(Val* v) noexcept;
zeek::IntrusivePtr<Val> rval; ValPtr rval;
}; };

View file

@ -15,7 +15,7 @@
#include "Func.h" #include "Func.h"
#include "IPAddr.h" #include "IPAddr.h"
CompositeHash::CompositeHash(zeek::IntrusivePtr<zeek::TypeList> composite_type) CompositeHash::CompositeHash(zeek::TypeListPtr composite_type)
: type(std::move(composite_type)) : type(std::move(composite_type))
{ {
singleton_tag = zeek::TYPE_INTERNAL_ERROR; singleton_tag = zeek::TYPE_INTERNAL_ERROR;
@ -709,7 +709,7 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const
return offset; return offset;
} }
zeek::IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const ListValPtr CompositeHash::RecoverVals(const HashKey& k) const
{ {
auto l = zeek::make_intrusive<ListVal>(zeek::TYPE_ANY); auto l = zeek::make_intrusive<ListVal>(zeek::TYPE_ANY);
const auto& tl = type->GetTypes(); const auto& tl = type->GetTypes();
@ -718,7 +718,7 @@ zeek::IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
for ( const auto& type : tl ) for ( const auto& type : tl )
{ {
zeek::IntrusivePtr<Val> v; ValPtr v;
kp = RecoverOneVal(k, kp, k_end, type.get(), &v, false); kp = RecoverOneVal(k, kp, k_end, type.get(), &v, false);
ASSERT(v); ASSERT(v);
l->Append(std::move(v)); l->Append(std::move(v));
@ -733,7 +733,7 @@ zeek::IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
const char* CompositeHash::RecoverOneVal( const char* CompositeHash::RecoverOneVal(
const HashKey& k, const char* kp0, const HashKey& k, const char* kp0,
const char* const k_end, zeek::Type* t, const char* const k_end, zeek::Type* t,
zeek::IntrusivePtr<Val>* pval, bool optional) const ValPtr* pval, bool optional) const
{ {
// k->Size() == 0 for a single empty string. // k->Size() == 0 for a single empty string.
if ( kp0 >= k_end && k.Size() > 0 ) if ( kp0 >= k_end && k.Size() > 0 )
@ -904,11 +904,11 @@ const char* CompositeHash::RecoverOneVal(
zeek::RecordType* rt = t->AsRecordType(); zeek::RecordType* rt = t->AsRecordType();
int num_fields = rt->NumFields(); int num_fields = rt->NumFields();
std::vector<zeek::IntrusivePtr<Val>> values; std::vector<ValPtr> values;
int i; int i;
for ( i = 0; i < num_fields; ++i ) for ( i = 0; i < num_fields; ++i )
{ {
zeek::IntrusivePtr<Val> v; ValPtr v;
zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get(); zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL)); bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL));
@ -952,14 +952,14 @@ const char* CompositeHash::RecoverOneVal(
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
{ {
zeek::IntrusivePtr<Val> key; ValPtr key;
kp1 = RecoverOneVal(k, kp1, k_end, tt->GetIndices().get(), &key, false); kp1 = RecoverOneVal(k, kp1, k_end, tt->GetIndices().get(), &key, false);
if ( t->IsSet() ) if ( t->IsSet() )
tv->Assign(std::move(key), nullptr); tv->Assign(std::move(key), nullptr);
else else
{ {
zeek::IntrusivePtr<Val> value; ValPtr value;
kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value, kp1 = RecoverOneVal(k, kp1, k_end, tt->Yield().get(), &value,
false); false);
tv->Assign(std::move(key), std::move(value)); tv->Assign(std::move(key), std::move(value));
@ -987,7 +987,7 @@ const char* CompositeHash::RecoverOneVal(
kp = AlignType<unsigned int>(kp1); kp = AlignType<unsigned int>(kp1);
unsigned int have_val = *kp; unsigned int have_val = *kp;
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
zeek::IntrusivePtr<Val> value; ValPtr value;
if ( have_val ) if ( have_val )
kp1 = RecoverOneVal(k, kp1, k_end, vt->Yield().get(), &value, 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 ) for ( int i = 0; i < n; ++i )
{ {
zeek::IntrusivePtr<Val> v; ValPtr v;
zeek::Type* it = tl->GetTypes()[i].get(); zeek::Type* it = tl->GetTypes()[i].get();
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false); kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
lv->Append(std::move(v)); lv->Append(std::move(v));

View file

@ -10,9 +10,11 @@
class ListVal; class ListVal;
class HashKey; class HashKey;
using ListValPtr = zeek::IntrusivePtr<ListVal>;
class CompositeHash { class CompositeHash {
public: public:
explicit CompositeHash(zeek::IntrusivePtr<zeek::TypeList> composite_type); explicit CompositeHash(zeek::TypeListPtr composite_type);
~CompositeHash(); ~CompositeHash();
// Compute the hash corresponding to the given index val, // Compute the hash corresponding to the given index val,
@ -24,10 +26,10 @@ public:
{ return MakeHashKey(*v, type_check).release(); } { return MakeHashKey(*v, type_check).release(); }
// Given a hash key, recover the values used to create it. // Given a hash key, recover the values used to create it.
zeek::IntrusivePtr<ListVal> RecoverVals(const HashKey& k) const; ListValPtr RecoverVals(const HashKey& k) const;
[[deprecated("Remove in v4.1. Pass in HashKey& instead.")]] [[deprecated("Remove in v4.1. Pass in HashKey& instead.")]]
zeek::IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const ListValPtr RecoverVals(const HashKey* k) const
{ return RecoverVals(*k); } { return RecoverVals(*k); }
unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); } 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. // upon errors, so there is no return value for invalid input.
const char* RecoverOneVal( const char* RecoverOneVal(
const HashKey& k, const char* kp, const char* const k_end, const HashKey& k, const char* kp, const char* const k_end,
zeek::Type* t, zeek::IntrusivePtr<Val>* pval, bool optional) const; zeek::Type* t, ValPtr* pval, bool optional) const;
// Rounds the given pointer up to the nearest multiple of the // Rounds the given pointer up to the nearest multiple of the
// given size, if not already a multiple. // given size, if not already a multiple.
@ -89,7 +91,7 @@ protected:
bool type_check, int sz, bool optional, bool type_check, int sz, bool optional,
bool calc_static_size) const; bool calc_static_size) const;
zeek::IntrusivePtr<zeek::TypeList> type; zeek::TypeListPtr type;
char* key; // space for composite key char* key; // space for composite key
int size; int size;
bool is_singleton; // if just one type in index bool is_singleton; // if just one type in index

View file

@ -342,7 +342,7 @@ RecordVal* Connection::BuildConnVal()
return ConnVal()->Ref()->AsRecordVal(); return ConnVal()->Ref()->AsRecordVal();
} }
const zeek::IntrusivePtr<RecordVal>& Connection::ConnVal() const RecordValPtr& Connection::ConnVal()
{ {
if ( ! conn_val ) if ( ! conn_val )
{ {

View file

@ -32,6 +32,9 @@ class EncapsulationStack;
class Val; class Val;
class RecordVal; class RecordVal;
using ValPtr = zeek::IntrusivePtr<Val>;
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
namespace analyzer { class TransportLayerAnalyzer; } namespace analyzer { class TransportLayerAnalyzer; }
typedef enum { typedef enum {
@ -169,7 +172,7 @@ public:
/** /**
* Returns the associated "connection" record. * Returns the associated "connection" record.
*/ */
const zeek::IntrusivePtr<RecordVal>& ConnVal(); const RecordValPtr& ConnVal();
void AppendAddl(const char* str); void AppendAddl(const char* str);
@ -235,7 +238,7 @@ public:
template <class... Args> template <class... Args>
std::enable_if_t< std::enable_if_t<
std::is_convertible_v< std::is_convertible_v<
std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>>
EnqueueEvent(EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args) EnqueueEvent(EventHandlerPtr h, analyzer::Analyzer* analyzer, Args&&... args)
{ return EnqueueEvent(h, analyzer, zeek::Args{std::forward<Args>(args)...}); } { return EnqueueEvent(h, analyzer, zeek::Args{std::forward<Args>(args)...}); }
@ -355,7 +358,7 @@ protected:
u_char resp_l2_addr[Packet::l2_addr_len]; // Link-layer responder address, if available u_char resp_l2_addr[Packet::l2_addr_len]; // Link-layer responder address, if available
double start_time, last_time; double start_time, last_time;
double inactivity_timeout; double inactivity_timeout;
zeek::IntrusivePtr<RecordVal> conn_val; RecordValPtr conn_val;
LoginConn* login_conn; // either nil, or this LoginConn* login_conn; // either nil, or this
const EncapsulationStack* encapsulation; // tunnels const EncapsulationStack* encapsulation; // tunnels
int suppress_event; // suppress certain events to once per conn. int suppress_event; // suppress certain events to once per conn.

View file

@ -122,9 +122,9 @@ public:
return req_host ? req_host : req_addr.AsString(); return req_host ? req_host : req_addr.AsString();
} }
zeek::IntrusivePtr<ListVal> Addrs(); ListValPtr Addrs();
zeek::IntrusivePtr<TableVal> AddrsSet(); // addresses returned as a set TableValPtr AddrsSet(); // addresses returned as a set
zeek::IntrusivePtr<StringVal> Host(); StringValPtr Host();
double CreationTime() const { return creation_time; } double CreationTime() const { return creation_time; }
@ -155,11 +155,11 @@ protected:
int num_names; int num_names;
char** names; char** names;
zeek::IntrusivePtr<StringVal> host_val; StringValPtr host_val;
int num_addrs; int num_addrs;
IPAddr* addrs; IPAddr* addrs;
zeek::IntrusivePtr<ListVal> addrs_val; ListValPtr addrs_val;
double creation_time; double creation_time;
int map_type; int map_type;
@ -173,7 +173,7 @@ void DNS_Mgr_mapping_delete_func(void* v)
delete (DNS_Mapping*) v; delete (DNS_Mapping*) v;
} }
static zeek::IntrusivePtr<TableVal> empty_addr_set() static TableValPtr empty_addr_set()
{ {
auto addr_t = zeek::base_type(zeek::TYPE_ADDR); auto addr_t = zeek::base_type(zeek::TYPE_ADDR);
auto set_index = zeek::make_intrusive<zeek::TypeList>(addr_t); auto set_index = zeek::make_intrusive<zeek::TypeList>(addr_t);
@ -276,7 +276,7 @@ DNS_Mapping::~DNS_Mapping()
delete [] addrs; delete [] addrs;
} }
zeek::IntrusivePtr<ListVal> DNS_Mapping::Addrs() ListValPtr DNS_Mapping::Addrs()
{ {
if ( failed ) if ( failed )
return nullptr; return nullptr;
@ -292,7 +292,7 @@ zeek::IntrusivePtr<ListVal> DNS_Mapping::Addrs()
return addrs_val; return addrs_val;
} }
zeek::IntrusivePtr<TableVal> DNS_Mapping::AddrsSet() { TableValPtr DNS_Mapping::AddrsSet() {
auto l = Addrs(); auto l = Addrs();
if ( ! l ) if ( ! l )
@ -301,7 +301,7 @@ zeek::IntrusivePtr<TableVal> DNS_Mapping::AddrsSet() {
return l->ToSetVal(); return l->ToSetVal();
} }
zeek::IntrusivePtr<StringVal> DNS_Mapping::Host() StringValPtr DNS_Mapping::Host()
{ {
if ( failed || num_names == 0 || ! names[0] ) if ( failed || num_names == 0 || ! names[0] )
return nullptr; return nullptr;
@ -461,7 +461,7 @@ void DNS_Mgr::InitPostScript()
LoadCache(fopen(cache_name, "r")); LoadCache(fopen(cache_name, "r"));
} }
static zeek::IntrusivePtr<TableVal> fake_name_lookup_result(const char* name) static TableValPtr fake_name_lookup_result(const char* name)
{ {
hash128_t hash; hash128_t hash;
KeyedHash::StaticHash128(name, strlen(name), &hash); KeyedHash::StaticHash128(name, strlen(name), &hash);
@ -485,7 +485,7 @@ static const char* fake_addr_lookup_result(const IPAddr& addr)
return tmp; return tmp;
} }
zeek::IntrusivePtr<TableVal> DNS_Mgr::LookupHost(const char* name) TableValPtr DNS_Mgr::LookupHost(const char* name)
{ {
if ( mode == DNS_FAKE ) if ( mode == DNS_FAKE )
return fake_name_lookup_result(name); return fake_name_lookup_result(name);
@ -542,7 +542,7 @@ zeek::IntrusivePtr<TableVal> DNS_Mgr::LookupHost(const char* name)
} }
} }
zeek::IntrusivePtr<Val> DNS_Mgr::LookupAddr(const IPAddr& addr) ValPtr DNS_Mgr::LookupAddr(const IPAddr& addr)
{ {
InitSource(); InitSource();
@ -698,7 +698,7 @@ void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm)
} }
void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm, void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm,
zeek::IntrusivePtr<ListVal> l1, zeek::IntrusivePtr<ListVal> l2) ListValPtr l1, ListValPtr l2)
{ {
if ( ! e ) if ( ! e )
return; 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)); mgr.Enqueue(e, BuildMappingVal(old_dm), BuildMappingVal(new_dm));
} }
zeek::IntrusivePtr<Val> DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) ValPtr DNS_Mgr::BuildMappingVal(DNS_Mapping* dm)
{ {
auto r = zeek::make_intrusive<RecordVal>(dm_rec); auto r = zeek::make_intrusive<RecordVal>(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)); Event(dns_mapping_altered, new_dm, std::move(prev_delta), std::move(new_delta));
} }
zeek::IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) ListValPtr DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2)
{ {
auto delta = zeek::make_intrusive<ListVal>(zeek::TYPE_ADDR); auto delta = zeek::make_intrusive<ListVal>(zeek::TYPE_ADDR);
@ -980,7 +980,7 @@ const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr)
return d->names ? d->names[0] : "<\?\?\?>"; return d->names ? d->names[0] : "<\?\?\?>";
} }
zeek::IntrusivePtr<TableVal> DNS_Mgr::LookupNameInCache(const string& name) TableValPtr DNS_Mgr::LookupNameInCache(const string& name)
{ {
HostMap::iterator it = host_mappings.find(name); HostMap::iterator it = host_mappings.find(name);
if ( it == host_mappings.end() ) 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, static void resolve_lookup_cb(DNS_Mgr::LookupCallback* callback,
zeek::IntrusivePtr<TableVal> result) TableValPtr result)
{ {
callback->Resolved(result.get()); callback->Resolved(result.get());
delete callback; delete callback;

View file

@ -21,6 +21,10 @@ class Func;
class EventHandler; class EventHandler;
class DNS_Mgr_Request; class DNS_Mgr_Request;
using ValPtr = zeek::IntrusivePtr<Val>;
using ListValPtr = zeek::IntrusivePtr<ListVal>;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek);
typedef PList<DNS_Mgr_Request> DNS_mgr_request_list; typedef PList<DNS_Mgr_Request> DNS_mgr_request_list;
@ -50,9 +54,9 @@ public:
// Looks up the address or addresses of the given host, and returns // Looks up the address or addresses of the given host, and returns
// a set of addr. // a set of addr.
zeek::IntrusivePtr<TableVal> LookupHost(const char* host); TableValPtr LookupHost(const char* host);
zeek::IntrusivePtr<Val> LookupAddr(const IPAddr& addr); ValPtr LookupAddr(const IPAddr& addr);
// Define the directory where to store the data. // Define the directory where to store the data.
void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); } void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); }
@ -62,7 +66,7 @@ public:
bool Save(); bool Save();
const char* LookupAddrInCache(const IPAddr& addr); const char* LookupAddrInCache(const IPAddr& addr);
zeek::IntrusivePtr<TableVal> LookupNameInCache(const std::string& name); TableValPtr LookupNameInCache(const std::string& name);
const char* LookupTextInCache(const std::string& name); const char* LookupTextInCache(const std::string& name);
// Support for async lookups. // Support for async lookups.
@ -100,14 +104,14 @@ protected:
void Event(EventHandlerPtr e, DNS_Mapping* dm); void Event(EventHandlerPtr e, DNS_Mapping* dm);
void Event(EventHandlerPtr e, DNS_Mapping* dm, void Event(EventHandlerPtr e, DNS_Mapping* dm,
zeek::IntrusivePtr<ListVal> l1, zeek::IntrusivePtr<ListVal> l2); ListValPtr l1, ListValPtr l2);
void Event(EventHandlerPtr e, DNS_Mapping* old_dm, DNS_Mapping* new_dm); void Event(EventHandlerPtr e, DNS_Mapping* old_dm, DNS_Mapping* new_dm);
zeek::IntrusivePtr<Val> BuildMappingVal(DNS_Mapping* dm); ValPtr BuildMappingVal(DNS_Mapping* dm);
void AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r); void AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r);
void CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm); void CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm);
zeek::IntrusivePtr<ListVal> AddrListDelta(ListVal* al1, ListVal* al2); ListValPtr AddrListDelta(ListVal* al1, ListVal* al2);
void DumpAddrList(FILE* f, ListVal* al); void DumpAddrList(FILE* f, ListVal* al);
typedef std::map<std::string, std::pair<DNS_Mapping*, DNS_Mapping*> > HostMap; typedef std::map<std::string, std::pair<DNS_Mapping*, DNS_Mapping*> > HostMap;
@ -151,7 +155,7 @@ protected:
bool did_init; bool did_init;
zeek::IntrusivePtr<zeek::RecordType> dm_rec; zeek::RecordTypePtr dm_rec;
typedef std::list<LookupCallback*> CallbackList; typedef std::list<LookupCallback*> CallbackList;

View file

@ -948,7 +948,7 @@ extern YYLTYPE yylloc; // holds start line and column of token
extern int line_number; extern int line_number;
extern const char* filename; extern const char* filename;
zeek::IntrusivePtr<Val> dbg_eval_expr(const char* expr) ValPtr dbg_eval_expr(const char* expr)
{ {
// Push the current frame's associated scope. // Push the current frame's associated scope.
// Note: g_debugger_state.curr_frame_idx is the user-visible number, // Note: g_debugger_state.curr_frame_idx is the user-visible number,
@ -983,7 +983,7 @@ zeek::IntrusivePtr<Val> dbg_eval_expr(const char* expr)
yylloc.first_line = yylloc.last_line = line_number = 1; yylloc.first_line = yylloc.last_line = line_number = 1;
// Parse the thing into an expr. // Parse the thing into an expr.
zeek::IntrusivePtr<Val> result; ValPtr result;
if ( yyparse() ) if ( yyparse() )
{ {
if ( g_curr_debug_error ) if ( g_curr_debug_error )

View file

@ -16,6 +16,7 @@ template <class T> class IntrusivePtr;
} }
class Val; class Val;
using ValPtr = zeek::IntrusivePtr<Val>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); 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); int dbg_execute_command(const char* cmd);
// Interactive expression evaluation. // Interactive expression evaluation.
zeek::IntrusivePtr<Val> dbg_eval_expr(const char* expr); ValPtr dbg_eval_expr(const char* expr);
// Extra debugging facilities. // Extra debugging facilities.
// TODO: current connections, memory allocated, other internal data structures. // TODO: current connections, memory allocated, other internal data structures.

View file

@ -9,6 +9,7 @@
class IP_Hdr; class IP_Hdr;
class Val; class Val;
class Func; class Func;
using FuncPtr = zeek::IntrusivePtr<Func>;
class Discarder { class Discarder {
public: public:
@ -22,10 +23,10 @@ public:
protected: protected:
Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); Val* BuildData(const u_char* data, int hdrlen, int len, int caplen);
zeek::IntrusivePtr<Func> check_ip; FuncPtr check_ip;
zeek::IntrusivePtr<Func> check_tcp; FuncPtr check_tcp;
zeek::IntrusivePtr<Func> check_udp; FuncPtr check_udp;
zeek::IntrusivePtr<Func> check_icmp; FuncPtr check_icmp;
// Maximum amount of application data passed to filtering functions. // Maximum amount of application data passed to filtering functions.
int discarder_maxlen; int discarder_maxlen;

View file

@ -108,7 +108,7 @@ public:
template <class... Args> template <class... Args>
std::enable_if_t< std::enable_if_t<
std::is_convertible_v< std::is_convertible_v<
std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>>
Enqueue(const EventHandlerPtr& h, Args&&... args) Enqueue(const EventHandlerPtr& h, Args&&... args)
{ return Enqueue(h, zeek::Args{std::forward<Args>(args)...}); } { return Enqueue(h, zeek::Args{std::forward<Args>(args)...}); }

View file

@ -26,7 +26,7 @@ EventHandler::operator bool() const
|| ! auto_publish.empty()); || ! auto_publish.empty());
} }
const zeek::IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_export) const zeek::FuncTypePtr& EventHandler::GetType(bool check_export)
{ {
if ( type ) if ( type )
return type; return type;
@ -44,7 +44,7 @@ const zeek::IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_expor
return type; return type;
} }
void EventHandler::SetFunc(zeek::IntrusivePtr<Func> f) void EventHandler::SetFunc(FuncPtr f)
{ local = std::move(f); } { local = std::move(f); }
void EventHandler::SetLocalHandler(Func* f) void EventHandler::SetLocalHandler(Func* f)

View file

@ -10,6 +10,7 @@
#include <string> #include <string>
class Func; class Func;
using FuncPtr = zeek::IntrusivePtr<Func>;
class EventHandler { class EventHandler {
public: public:
@ -17,19 +18,19 @@ public:
const char* Name() { return name.data(); } const char* Name() { return name.data(); }
const zeek::IntrusivePtr<Func>& GetFunc() const FuncPtr& GetFunc()
{ return local; } { return local; }
[[deprecated("Remove in v4.1. Use GetFunc().")]] [[deprecated("Remove in v4.1. Use GetFunc().")]]
Func* LocalHandler() { return local.get(); } Func* LocalHandler() { return local.get(); }
const zeek::IntrusivePtr<zeek::FuncType>& GetType(bool check_export = true); const zeek::FuncTypePtr& GetType(bool check_export = true);
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
zeek::FuncType* FType(bool check_export = true) zeek::FuncType* FType(bool check_export = true)
{ return GetType().get(); } { return GetType().get(); }
void SetFunc(zeek::IntrusivePtr<Func> f); void SetFunc(FuncPtr f);
[[deprecated("Remove in v4.1. Use SetFunc().")]] [[deprecated("Remove in v4.1. Use SetFunc().")]]
void SetLocalHandler(Func* f); void SetLocalHandler(Func* f);
@ -68,8 +69,8 @@ private:
void NewEvent(zeek::Args* vl); // Raise new_event() meta event. void NewEvent(zeek::Args* vl); // Raise new_event() meta event.
std::string name; std::string name;
zeek::IntrusivePtr<Func> local; FuncPtr local;
zeek::IntrusivePtr<zeek::FuncType> type; zeek::FuncTypePtr type;
bool used; // this handler is indeed used somewhere bool used; // this handler is indeed used somewhere
bool enabled; bool enabled;
bool error_handler; // this handler reports error messages. bool error_handler; // this handler reports error messages.

File diff suppressed because it is too large Load diff

View file

@ -24,6 +24,8 @@ struct function_ingredients;
namespace zeek::detail { namespace zeek::detail {
using IDPtr = zeek::IntrusivePtr<ID>;
enum BroExprTag : int { enum BroExprTag : int {
EXPR_ANY = -1, EXPR_ANY = -1,
EXPR_NAME, EXPR_CONST, EXPR_NAME, EXPR_CONST,
@ -73,12 +75,17 @@ class CallExpr;
class EventExpr; class EventExpr;
class Stmt; class Stmt;
class Expr;
using ExprPtr = zeek::IntrusivePtr<Expr>;
using EventExprPtr = zeek::IntrusivePtr<EventExpr>;
using ListExprPtr = zeek::IntrusivePtr<ListExpr>;
class Expr : public BroObj { class Expr : public BroObj {
public: public:
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
zeek::Type* Type() const { return type.get(); } zeek::Type* Type() const { return type.get(); }
const zeek::IntrusivePtr<zeek::Type>& GetType() const const zeek::TypePtr& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
@ -91,21 +98,20 @@ public:
// Evaluates the expression and returns a corresponding Val*, // Evaluates the expression and returns a corresponding Val*,
// or nil if the expression's value isn't fixed. // or nil if the expression's value isn't fixed.
virtual zeek::IntrusivePtr<Val> Eval(Frame* f) const = 0; virtual ValPtr Eval(Frame* f) const = 0;
// Same, but the context is that we are adding an element // Same, but the context is that we are adding an element
// into the given aggregate of the given type. Note that // into the given aggregate of the given type. Note that
// return type is void since it's updating an existing // return type is void since it's updating an existing
// value, rather than creating a new one. // value, rather than creating a new one.
virtual void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) virtual void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const;
const;
// Assign to the given value, if appropriate. // Assign to the given value, if appropriate.
virtual void Assign(Frame* f, zeek::IntrusivePtr<Val> v); virtual void Assign(Frame* f, ValPtr v);
// Returns the type corresponding to this expression interpreted // Returns the type corresponding to this expression interpreted
// as an initialization. Returns nil if the initialization is illegal. // as an initialization. Returns nil if the initialization is illegal.
virtual zeek::IntrusivePtr<zeek::Type> InitType() const; virtual zeek::TypePtr InitType() const;
// Returns true if this expression, interpreted as an initialization, // Returns true if this expression, interpreted as an initialization,
// constitutes a record element, false otherwise. If the TypeDecl* // 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 // 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 // is an element of the given aggregate, and it is added to it
// accordingly. // accordingly.
virtual zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const; virtual ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const;
// True if the expression has no side effects, false otherwise. // True if the expression has no side effects, false otherwise.
virtual bool IsPure() const; virtual bool IsPure() const;
@ -154,7 +160,7 @@ public:
// Return the expression converted to L-value form. If expr // Return the expression converted to L-value form. If expr
// cannot be used as an L-value, reports an error and returns // cannot be used as an L-value, reports an error and returns
// the current value of expr (this is the default method). // the current value of expr (this is the default method).
virtual zeek::IntrusivePtr<Expr> MakeLvalue(); virtual ExprPtr MakeLvalue();
// Marks the expression as one requiring (or at least appearing // Marks the expression as one requiring (or at least appearing
// with) parentheses. Used for pretty-printing. // with) parentheses. Used for pretty-printing.
@ -223,7 +229,7 @@ protected:
// Puts the expression in canonical form. // Puts the expression in canonical form.
virtual void Canonicize(); virtual void Canonicize();
void SetType(zeek::IntrusivePtr<zeek::Type> t); void SetType(zeek::TypePtr t);
// Reports the given error and sets the expression's type to // Reports the given error and sets the expression's type to
// TYPE_ERROR. // TYPE_ERROR.
@ -235,19 +241,19 @@ protected:
[[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const; [[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const;
BroExprTag tag; BroExprTag tag;
zeek::IntrusivePtr<zeek::Type> type; zeek::TypePtr type;
bool paren; bool paren;
}; };
class NameExpr final : public Expr { class NameExpr final : public Expr {
public: public:
explicit NameExpr(zeek::IntrusivePtr<ID> id, bool const_init = false); explicit NameExpr(zeek::detail::IDPtr id, bool const_init = false);
ID* Id() const { return id.get(); } ID* Id() const { return id.get(); }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override; void Assign(Frame* f, ValPtr v) override;
zeek::IntrusivePtr<Expr> MakeLvalue() override; ExprPtr MakeLvalue() override;
bool IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -255,23 +261,23 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<ID> id; zeek::detail::IDPtr id;
bool in_const_init; bool in_const_init;
}; };
class ConstExpr final : public Expr { class ConstExpr final : public Expr {
public: public:
explicit ConstExpr(zeek::IntrusivePtr<Val> val); explicit ConstExpr(ValPtr val);
Val* Value() const { return val.get(); } Val* Value() const { return val.get(); }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> val; ValPtr val;
}; };
class UnaryExpr : public Expr { class UnaryExpr : public Expr {
@ -281,21 +287,21 @@ public:
// UnaryExpr::Eval correctly handles vector types. Any child // UnaryExpr::Eval correctly handles vector types. Any child
// class that overrides Eval() should be modified to handle // class that overrides Eval() should be modified to handle
// vectors correctly as necessary. // vectors correctly as necessary.
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
bool IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
UnaryExpr(BroExprTag arg_tag, zeek::IntrusivePtr<Expr> arg_op); UnaryExpr(BroExprTag arg_tag, ExprPtr arg_op);
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
// Returns the expression folded using the given constant. // Returns the expression folded using the given constant.
virtual zeek::IntrusivePtr<Val> Fold(Val* v) const; virtual ValPtr Fold(Val* v) const;
zeek::IntrusivePtr<Expr> op; ExprPtr op;
}; };
class BinaryExpr : public Expr { class BinaryExpr : public Expr {
@ -308,13 +314,13 @@ public:
// BinaryExpr::Eval correctly handles vector types. Any child // BinaryExpr::Eval correctly handles vector types. Any child
// class that overrides Eval() should be modified to handle // class that overrides Eval() should be modified to handle
// vectors correctly as necessary. // vectors correctly as necessary.
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
BinaryExpr(BroExprTag arg_tag, BinaryExpr(BroExprTag arg_tag,
zeek::IntrusivePtr<Expr> arg_op1, zeek::IntrusivePtr<Expr> arg_op2) ExprPtr arg_op1, ExprPtr arg_op2)
: Expr(arg_tag), op1(std::move(arg_op1)), op2(std::move(arg_op2)) : Expr(arg_tag), op1(std::move(arg_op1)), op2(std::move(arg_op2))
{ {
if ( ! (op1 && op2) ) if ( ! (op1 && op2) )
@ -324,20 +330,20 @@ protected:
} }
// Returns the expression folded using the given constants. // Returns the expression folded using the given constants.
virtual zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const; virtual ValPtr Fold(Val* v1, Val* v2) const;
// Same for when the constants are strings. // Same for when the constants are strings.
virtual zeek::IntrusivePtr<Val> StringFold(Val* v1, Val* v2) const; virtual ValPtr StringFold(Val* v1, Val* v2) const;
// Same for when the constants are patterns. // Same for when the constants are patterns.
virtual zeek::IntrusivePtr<Val> PatternFold(Val* v1, Val* v2) const; virtual ValPtr PatternFold(Val* v1, Val* v2) const;
// Same for when the constants are sets. // Same for when the constants are sets.
virtual zeek::IntrusivePtr<Val> SetFold(Val* v1, Val* v2) const; virtual ValPtr SetFold(Val* v1, Val* v2) const;
// Same for when the constants are addresses or subnets. // Same for when the constants are addresses or subnets.
virtual zeek::IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const; virtual ValPtr AddrFold(Val* v1, Val* v2) const;
virtual zeek::IntrusivePtr<Val> SubNetFold(Val* v1, Val* v2) const; virtual ValPtr SubNetFold(Val* v1, Val* v2) const;
bool BothConst() const { return op1->IsConst() && op2->IsConst(); } bool BothConst() const { return op1->IsConst() && op2->IsConst(); }
@ -353,148 +359,148 @@ protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Expr> op1; ExprPtr op1;
zeek::IntrusivePtr<Expr> op2; ExprPtr op2;
}; };
class CloneExpr final : public UnaryExpr { class CloneExpr final : public UnaryExpr {
public: public:
explicit CloneExpr(zeek::IntrusivePtr<Expr> op); explicit CloneExpr(ExprPtr op);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class IncrExpr final : public UnaryExpr { class IncrExpr final : public UnaryExpr {
public: public:
IncrExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op); IncrExpr(BroExprTag tag, ExprPtr op);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
zeek::IntrusivePtr<Val> DoSingleEval(Frame* f, Val* v) const; ValPtr DoSingleEval(Frame* f, Val* v) const;
bool IsPure() const override; bool IsPure() const override;
}; };
class ComplementExpr final : public UnaryExpr { class ComplementExpr final : public UnaryExpr {
public: public:
explicit ComplementExpr(zeek::IntrusivePtr<Expr> op); explicit ComplementExpr(ExprPtr op);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class NotExpr final : public UnaryExpr { class NotExpr final : public UnaryExpr {
public: public:
explicit NotExpr(zeek::IntrusivePtr<Expr> op); explicit NotExpr(ExprPtr op);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class PosExpr final : public UnaryExpr { class PosExpr final : public UnaryExpr {
public: public:
explicit PosExpr(zeek::IntrusivePtr<Expr> op); explicit PosExpr(ExprPtr op);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class NegExpr final : public UnaryExpr { class NegExpr final : public UnaryExpr {
public: public:
explicit NegExpr(zeek::IntrusivePtr<Expr> op); explicit NegExpr(ExprPtr op);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class SizeExpr final : public UnaryExpr { class SizeExpr final : public UnaryExpr {
public: public:
explicit SizeExpr(zeek::IntrusivePtr<Expr> op); explicit SizeExpr(ExprPtr op);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class AddExpr final : public BinaryExpr { class AddExpr final : public BinaryExpr {
public: public:
AddExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); AddExpr(ExprPtr op1, ExprPtr op2);
void Canonicize() override; void Canonicize() override;
}; };
class AddToExpr final : public BinaryExpr { class AddToExpr final : public BinaryExpr {
public: public:
AddToExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); AddToExpr(ExprPtr op1, ExprPtr op2);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
}; };
class RemoveFromExpr final : public BinaryExpr { class RemoveFromExpr final : public BinaryExpr {
public: public:
RemoveFromExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); RemoveFromExpr(ExprPtr op1, ExprPtr op2);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
}; };
class SubExpr final : public BinaryExpr { class SubExpr final : public BinaryExpr {
public: public:
SubExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); SubExpr(ExprPtr op1, ExprPtr op2);
}; };
class TimesExpr final : public BinaryExpr { class TimesExpr final : public BinaryExpr {
public: public:
TimesExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); TimesExpr(ExprPtr op1, ExprPtr op2);
void Canonicize() override; void Canonicize() override;
}; };
class DivideExpr final : public BinaryExpr { class DivideExpr final : public BinaryExpr {
public: public:
DivideExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); DivideExpr(ExprPtr op1, ExprPtr op2);
protected: protected:
zeek::IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const override; ValPtr AddrFold(Val* v1, Val* v2) const override;
}; };
class ModExpr final : public BinaryExpr { class ModExpr final : public BinaryExpr {
public: public:
ModExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); ModExpr(ExprPtr op1, ExprPtr op2);
}; };
class BoolExpr final : public BinaryExpr { class BoolExpr final : public BinaryExpr {
public: public:
BoolExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); BoolExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
zeek::IntrusivePtr<Val> DoSingleEval(Frame* f, zeek::IntrusivePtr<Val> v1, Expr* op2) const; ValPtr DoSingleEval(Frame* f, ValPtr v1, Expr* op2) const;
}; };
class BitExpr final : public BinaryExpr { class BitExpr final : public BinaryExpr {
public: public:
BitExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); BitExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2);
}; };
class EqExpr final : public BinaryExpr { class EqExpr final : public BinaryExpr {
public: public:
EqExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); EqExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2);
void Canonicize() override; void Canonicize() override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; ValPtr Fold(Val* v1, Val* v2) const override;
}; };
class RelExpr final : public BinaryExpr { class RelExpr final : public BinaryExpr {
public: public:
RelExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); RelExpr(BroExprTag tag, ExprPtr op1, ExprPtr op2);
void Canonicize() override; void Canonicize() override;
}; };
class CondExpr final : public Expr { class CondExpr final : public Expr {
public: public:
CondExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2, zeek::IntrusivePtr<Expr> op3); CondExpr(ExprPtr op1, ExprPtr op2, ExprPtr op3);
const Expr* Op1() const { return op1.get(); } const Expr* Op1() const { return op1.get(); }
const Expr* Op2() const { return op2.get(); } const Expr* Op2() const { return op2.get(); }
const Expr* Op3() const { return op3.get(); } const Expr* Op3() const { return op3.get(); }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
bool IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -502,53 +508,53 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Expr> op1; ExprPtr op1;
zeek::IntrusivePtr<Expr> op2; ExprPtr op2;
zeek::IntrusivePtr<Expr> op3; ExprPtr op3;
}; };
class RefExpr final : public UnaryExpr { class RefExpr final : public UnaryExpr {
public: public:
explicit RefExpr(zeek::IntrusivePtr<Expr> op); explicit RefExpr(ExprPtr op);
void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override; void Assign(Frame* f, ValPtr v) override;
zeek::IntrusivePtr<Expr> MakeLvalue() override; ExprPtr MakeLvalue() override;
}; };
class AssignExpr : public BinaryExpr { class AssignExpr : public BinaryExpr {
public: public:
// If val is given, evaluating this expression will always yield the val // If val is given, evaluating this expression will always yield the val
// yet still perform the assignment. Used for triggers. // yet still perform the assignment. Used for triggers.
AssignExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2, bool is_init, AssignExpr(ExprPtr op1, ExprPtr op2, bool is_init,
zeek::IntrusivePtr<Val> val = nullptr, ValPtr val = nullptr,
const zeek::IntrusivePtr<Attributes>& attrs = nullptr); const AttributesPtr& attrs = nullptr);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override; void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override;
zeek::IntrusivePtr<zeek::Type> InitType() const override; zeek::TypePtr InitType() const override;
bool IsRecordElement(TypeDecl* td) const override; bool IsRecordElement(TypeDecl* td) const override;
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
bool IsPure() const override; bool IsPure() const override;
protected: protected:
bool TypeCheck(const zeek::IntrusivePtr<Attributes>& attrs = nullptr); bool TypeCheck(const AttributesPtr& attrs = nullptr);
bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2);
bool is_init; bool is_init;
zeek::IntrusivePtr<Val> val; // optional ValPtr val; // optional
}; };
class IndexSliceAssignExpr final : public AssignExpr { class IndexSliceAssignExpr final : public AssignExpr {
public: public:
IndexSliceAssignExpr(zeek::IntrusivePtr<Expr> op1, IndexSliceAssignExpr(ExprPtr op1,
zeek::IntrusivePtr<Expr> op2, bool is_init); ExprPtr op2, bool is_init);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
}; };
class IndexExpr final : public BinaryExpr { class IndexExpr final : public BinaryExpr {
public: public:
IndexExpr(zeek::IntrusivePtr<Expr> op1, IndexExpr(ExprPtr op1,
zeek::IntrusivePtr<ListExpr> op2, bool is_slice = false); ListExprPtr op2, bool is_slice = false);
bool CanAdd() const override; bool CanAdd() const override;
bool CanDel() const override; bool CanDel() const override;
@ -556,19 +562,19 @@ public:
void Add(Frame* f) override; void Add(Frame* f) override;
void Delete(Frame* f) override; void Delete(Frame* f) override;
void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override; void Assign(Frame* f, ValPtr v) override;
zeek::IntrusivePtr<Expr> MakeLvalue() override; ExprPtr MakeLvalue() override;
// Need to override Eval since it can take a vector arg but does // Need to override Eval since it can take a vector arg but does
// not necessarily return a vector. // not necessarily return a vector.
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
bool IsSlice() const { return is_slice; } bool IsSlice() const { return is_slice; }
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; ValPtr Fold(Val* v1, Val* v2) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -577,7 +583,7 @@ protected:
class FieldExpr final : public UnaryExpr { class FieldExpr final : public UnaryExpr {
public: public:
FieldExpr(zeek::IntrusivePtr<Expr> op, const char* field_name); FieldExpr(ExprPtr op, const char* field_name);
~FieldExpr() override; ~FieldExpr() override;
int Field() const { return field; } int Field() const { return field; }
@ -585,13 +591,13 @@ public:
bool CanDel() const override; bool CanDel() const override;
void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override; void Assign(Frame* f, ValPtr v) override;
void Delete(Frame* f) override; void Delete(Frame* f) override;
zeek::IntrusivePtr<Expr> MakeLvalue() override; ExprPtr MakeLvalue() override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -604,13 +610,13 @@ protected:
// "rec?$$attrname" is true if the attribute attrname is not nil. // "rec?$$attrname" is true if the attribute attrname is not nil.
class HasFieldExpr final : public UnaryExpr { class HasFieldExpr final : public UnaryExpr {
public: public:
HasFieldExpr(zeek::IntrusivePtr<Expr> op, const char* field_name); HasFieldExpr(ExprPtr op, const char* field_name);
~HasFieldExpr() override; ~HasFieldExpr() override;
const char* FieldName() const { return field_name; } const char* FieldName() const { return field_name; }
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -620,76 +626,76 @@ protected:
class RecordConstructorExpr final : public UnaryExpr { class RecordConstructorExpr final : public UnaryExpr {
public: public:
explicit RecordConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list); explicit RecordConstructorExpr(ListExprPtr constructor_list);
~RecordConstructorExpr() override; ~RecordConstructorExpr() override;
protected: protected:
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
}; };
class TableConstructorExpr final : public UnaryExpr { class TableConstructorExpr final : public UnaryExpr {
public: public:
TableConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list, TableConstructorExpr(ListExprPtr constructor_list,
std::unique_ptr<std::vector<zeek::IntrusivePtr<Attr>>> attrs, std::unique_ptr<std::vector<AttrPtr>> attrs,
zeek::IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::TypePtr arg_type = nullptr);
[[deprecated("Remove in v4.1. Use GetAttrs().")]] [[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); } Attributes* Attrs() { return attrs.get(); }
const zeek::IntrusivePtr<Attributes>& GetAttrs() const const AttributesPtr& GetAttrs() const
{ return attrs; } { return attrs; }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
protected: protected:
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Attributes> attrs; AttributesPtr attrs;
}; };
class SetConstructorExpr final : public UnaryExpr { class SetConstructorExpr final : public UnaryExpr {
public: public:
SetConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list, SetConstructorExpr(ListExprPtr constructor_list,
std::unique_ptr<std::vector<zeek::IntrusivePtr<Attr>>> attrs, std::unique_ptr<std::vector<AttrPtr>> attrs,
zeek::IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::TypePtr arg_type = nullptr);
[[deprecated("Remove in v4.1. Use GetAttrs().")]] [[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); } Attributes* Attrs() { return attrs.get(); }
const zeek::IntrusivePtr<Attributes>& GetAttrs() const const AttributesPtr& GetAttrs() const
{ return attrs; } { return attrs; }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
protected: protected:
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Attributes> attrs; AttributesPtr attrs;
}; };
class VectorConstructorExpr final : public UnaryExpr { class VectorConstructorExpr final : public UnaryExpr {
public: public:
explicit VectorConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list, explicit VectorConstructorExpr(ListExprPtr constructor_list,
zeek::IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::TypePtr arg_type = nullptr);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
protected: protected:
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
}; };
class FieldAssignExpr final : public UnaryExpr { class FieldAssignExpr final : public UnaryExpr {
public: public:
FieldAssignExpr(const char* field_name, zeek::IntrusivePtr<Expr> value); FieldAssignExpr(const char* field_name, ExprPtr value);
const char* FieldName() const { return field_name.c_str(); } const char* FieldName() const { return field_name.c_str(); }
@ -704,21 +710,21 @@ protected:
class ArithCoerceExpr final : public UnaryExpr { class ArithCoerceExpr final : public UnaryExpr {
public: public:
ArithCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::TypeTag t); ArithCoerceExpr(ExprPtr op, zeek::TypeTag t);
protected: protected:
zeek::IntrusivePtr<Val> FoldSingleVal(Val* v, InternalTypeTag t) const; ValPtr FoldSingleVal(Val* v, InternalTypeTag t) const;
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class RecordCoerceExpr final : public UnaryExpr { class RecordCoerceExpr final : public UnaryExpr {
public: public:
RecordCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<RecordType> r); RecordCoerceExpr(ExprPtr op, RecordTypePtr r);
~RecordCoerceExpr() override; ~RecordCoerceExpr() override;
protected: protected:
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
// For each super-record slot, gives subrecord slot with which to // For each super-record slot, gives subrecord slot with which to
// fill it. // fill it.
@ -728,20 +734,20 @@ protected:
class TableCoerceExpr final : public UnaryExpr { class TableCoerceExpr final : public UnaryExpr {
public: public:
TableCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<TableType> r); TableCoerceExpr(ExprPtr op, TableTypePtr r);
~TableCoerceExpr() override; ~TableCoerceExpr() override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class VectorCoerceExpr final : public UnaryExpr { class VectorCoerceExpr final : public UnaryExpr {
public: public:
VectorCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<VectorType> v); VectorCoerceExpr(ExprPtr op, VectorTypePtr v);
~VectorCoerceExpr() override; ~VectorCoerceExpr() override;
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
}; };
class ScheduleTimer final : public Timer { class ScheduleTimer final : public Timer {
@ -758,11 +764,11 @@ protected:
class ScheduleExpr final : public Expr { class ScheduleExpr final : public Expr {
public: public:
ScheduleExpr(zeek::IntrusivePtr<Expr> when, zeek::IntrusivePtr<EventExpr> event); ScheduleExpr(ExprPtr when, EventExprPtr event);
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
Expr* When() const { return when.get(); } Expr* When() const { return when.get(); }
EventExpr* Event() const { return event.get(); } EventExpr* Event() const { return event.get(); }
@ -772,22 +778,22 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Expr> when; ExprPtr when;
zeek::IntrusivePtr<EventExpr> event; EventExprPtr event;
}; };
class InExpr final : public BinaryExpr { class InExpr final : public BinaryExpr {
public: public:
InExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2); InExpr(ExprPtr op1, ExprPtr op2);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; ValPtr Fold(Val* v1, Val* v2) const override;
}; };
class CallExpr final : public Expr { class CallExpr final : public Expr {
public: public:
CallExpr(zeek::IntrusivePtr<Expr> func, zeek::IntrusivePtr<ListExpr> args, CallExpr(ExprPtr func, ListExprPtr args,
bool in_hook = false); bool in_hook = false);
Expr* Func() const { return func.get(); } Expr* Func() const { return func.get(); }
@ -795,15 +801,15 @@ public:
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Expr> func; ExprPtr func;
zeek::IntrusivePtr<ListExpr> args; ListExprPtr args;
}; };
@ -817,7 +823,7 @@ public:
LambdaExpr(std::unique_ptr<function_ingredients> ingredients, LambdaExpr(std::unique_ptr<function_ingredients> ingredients,
id_list outer_ids); id_list outer_ids);
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
Scope* GetScope() const; Scope* GetScope() const;
@ -834,13 +840,13 @@ private:
class EventExpr final : public Expr { class EventExpr final : public Expr {
public: public:
EventExpr(const char* name, zeek::IntrusivePtr<ListExpr> args); EventExpr(const char* name, ListExprPtr args);
const char* Name() const { return name.c_str(); } const char* Name() const { return name.c_str(); }
ListExpr* Args() const { return args.get(); } ListExpr* Args() const { return args.get(); }
EventHandlerPtr Handler() const { return handler; } EventHandlerPtr Handler() const { return handler; }
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -849,16 +855,16 @@ protected:
std::string name; std::string name;
EventHandlerPtr handler; EventHandlerPtr handler;
zeek::IntrusivePtr<ListExpr> args; ListExprPtr args;
}; };
class ListExpr : public Expr { class ListExpr : public Expr {
public: public:
ListExpr(); ListExpr();
explicit ListExpr(zeek::IntrusivePtr<Expr> e); explicit ListExpr(ExprPtr e);
~ListExpr() override; ~ListExpr() override;
void Append(zeek::IntrusivePtr<Expr> e); void Append(ExprPtr e);
const expr_list& Exprs() const { return exprs; } const expr_list& Exprs() const { return exprs; }
expr_list& Exprs() { return exprs; } expr_list& Exprs() { return exprs; }
@ -866,17 +872,17 @@ public:
// True if the entire list represents pure values. // True if the entire list represents pure values.
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
zeek::IntrusivePtr<zeek::Type> InitType() const override; zeek::TypePtr InitType() const override;
zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override; ValPtr InitVal(const zeek::Type* t, ValPtr aggr) const override;
zeek::IntrusivePtr<Expr> MakeLvalue() override; ExprPtr MakeLvalue() override;
void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override; void Assign(Frame* f, ValPtr v) override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Val> AddSetInit(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const; ValPtr AddSetInit(const zeek::Type* t, ValPtr aggr) const;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -886,28 +892,28 @@ protected:
class RecordAssignExpr final : public ListExpr { class RecordAssignExpr final : public ListExpr {
public: public:
RecordAssignExpr(const zeek::IntrusivePtr<Expr>& record, const zeek::IntrusivePtr<Expr>& init_list, bool is_init); RecordAssignExpr(const ExprPtr& record, const ExprPtr& init_list, bool is_init);
}; };
class CastExpr final : public UnaryExpr { class CastExpr final : public UnaryExpr {
public: public:
CastExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<zeek::Type> t); CastExpr(ExprPtr op, zeek::TypePtr t);
protected: protected:
zeek::IntrusivePtr<Val> Eval(Frame* f) const override; ValPtr Eval(Frame* f) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
}; };
class IsExpr final : public UnaryExpr { class IsExpr final : public UnaryExpr {
public: public:
IsExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<zeek::Type> t); IsExpr(ExprPtr op, zeek::TypePtr t);
protected: protected:
zeek::IntrusivePtr<Val> Fold(Val* v) const override; ValPtr Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
private: private:
zeek::IntrusivePtr<zeek::Type> t; zeek::TypePtr t;
}; };
inline Val* Expr::ExprVal() const inline Val* Expr::ExprVal() const
@ -918,9 +924,9 @@ inline Val* Expr::ExprVal() const
} }
// Decides whether to return an AssignExpr or a RecordAssignExpr. // Decides whether to return an AssignExpr or a RecordAssignExpr.
zeek::IntrusivePtr<Expr> get_assign_expr( ExprPtr get_assign_expr(
zeek::IntrusivePtr<Expr> op1, ExprPtr op1,
zeek::IntrusivePtr<Expr> op2, bool is_init); ExprPtr op2, bool is_init);
// Type-check the given expression(s) against the given type(s). Complain // 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 // if the expression cannot match the given type, returning 0. If it can
@ -937,7 +943,7 @@ zeek::IntrusivePtr<Expr> get_assign_expr(
* Returns nullptr if the expression cannot match or a promoted * Returns nullptr if the expression cannot match or a promoted
* expression. * expression.
*/ */
extern zeek::IntrusivePtr<Expr> 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_exprs(ListExpr* elements, TypeList* types);
extern bool check_and_promote_args(ListExpr* args, RecordType* 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 // Returns a ListExpr simplified down to a list a values, or nil
// if they couldn't all be reduced. // if they couldn't all be reduced.
std::optional<std::vector<zeek::IntrusivePtr<Val>>> eval_list(Frame* f, const ListExpr* l); std::optional<std::vector<ValPtr>> eval_list(Frame* f, const ListExpr* l);
// Returns true if e1 is "greater" than e2 - here "greater" is just // Returns true if e1 is "greater" than e2 - here "greater" is just
// a heuristic, used with commutative operators to put them into // 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 // 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(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; }
inline bool is_vector(const zeek::IntrusivePtr<Expr>& e) { return is_vector(e.get()); } inline bool is_vector(const ExprPtr& e) { return is_vector(e.get()); }
} }

View file

@ -328,7 +328,7 @@ void BroFile::RaiseOpenEvent()
if ( ! ::file_opened ) if ( ! ::file_opened )
return; return;
zeek::IntrusivePtr<BroFile> bf{zeek::NewRef{}, this}; BroFilePtr bf{zeek::NewRef{}, this};
Event* event = new ::Event(::file_opened, {zeek::make_intrusive<Val>(std::move(bf))}); Event* event = new ::Event(::file_opened, {zeek::make_intrusive<Val>(std::move(bf))});
mgr.Dispatch(event, true); mgr.Dispatch(event, true);
} }
@ -346,7 +346,7 @@ double BroFile::Size()
return s.st_size; return s.st_size;
} }
zeek::IntrusivePtr<BroFile> BroFile::Get(const char* name) BroFilePtr BroFile::Get(const char* name)
{ {
for ( const auto &el : open_files ) for ( const auto &el : open_files )
if ( el.first == name ) if ( el.first == name )

View file

@ -18,12 +18,18 @@
class RecordVal; class RecordVal;
namespace zeek { class Type; } namespace zeek {
class Type;
using TypePtr = zeek::IntrusivePtr<zeek::Type>;
}
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
ZEEK_FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
class BroFile;
using BroFilePtr = zeek::IntrusivePtr<BroFile>;
class BroFile final : public BroObj { class BroFile final : public BroObj {
public: public:
explicit BroFile(FILE* arg_f); explicit BroFile(FILE* arg_f);
@ -45,7 +51,7 @@ public:
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
zeek::Type* FType() const { return t.get(); } zeek::Type* FType() const { return t.get(); }
const zeek::IntrusivePtr<zeek::Type>& GetType() const const zeek::TypePtr& GetType() const
{ return t; } { return t; }
// Whether the file is open in a general sense; it might // Whether the file is open in a general sense; it might
@ -72,7 +78,7 @@ public:
static void CloseOpenFiles(); static void CloseOpenFiles();
// Get the file with the given name, opening it if it doesn't yet exist. // Get the file with the given name, opening it if it doesn't yet exist.
static zeek::IntrusivePtr<BroFile> Get(const char* name); static BroFilePtr Get(const char* name);
[[deprecated("Remove in v4.1. Use BroFile::Get().")]] [[deprecated("Remove in v4.1. Use BroFile::Get().")]]
static BroFile* GetFile(const char* name) static BroFile* GetFile(const char* name)
{ return Get(name).release(); } { return Get(name).release(); }
@ -106,7 +112,7 @@ protected:
void RaiseOpenEvent(); void RaiseOpenEvent();
FILE* f; FILE* f;
zeek::IntrusivePtr<zeek::Type> t; zeek::TypePtr t;
char* name; char* name;
char* access; char* access;
zeek::detail::Attributes* attrs; zeek::detail::Attributes* attrs;

View file

@ -7,7 +7,6 @@
#include "Func.h" #include "Func.h"
#include "Desc.h" #include "Desc.h"
#include "IntrusivePtr.h"
#include "Trigger.h" #include "Trigger.h"
#include "Val.h" #include "Val.h"
#include "ID.h" #include "ID.h"
@ -65,7 +64,7 @@ void Frame::AddFunctionWithClosureRef(BroFunc* func)
void Frame::SetElement(int n, Val* v) void Frame::SetElement(int n, Val* v)
{ SetElement(n, {zeek::AdoptRef{}, v}); } { SetElement(n, {zeek::AdoptRef{}, v}); }
void Frame::SetElement(int n, zeek::IntrusivePtr<Val> v) void Frame::SetElement(int n, ValPtr v)
{ {
ClearElement(n); ClearElement(n);
frame[n] = {std::move(v), false}; frame[n] = {std::move(v), false};
@ -77,7 +76,7 @@ void Frame::SetElementWeak(int n, Val* v)
frame[n] = {{zeek::AdoptRef{}, v}, true}; frame[n] = {{zeek::AdoptRef{}, v}, true};
} }
void Frame::SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr<Val> v) void Frame::SetElement(const zeek::detail::ID* id, ValPtr v)
{ {
if ( closure ) if ( closure )
{ {
@ -106,7 +105,7 @@ void Frame::SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr<Val> v)
SetElement(id->Offset(), std::move(v)); SetElement(id->Offset(), std::move(v));
} }
const zeek::IntrusivePtr<Val>& Frame::GetElementByID(const zeek::detail::ID* id) const const ValPtr& Frame::GetElementByID(const zeek::detail::ID* id) const
{ {
if ( closure ) if ( closure )
{ {
@ -173,7 +172,7 @@ Frame* Frame::Clone() const
return other; return other;
} }
static bool val_is_func(const zeek::IntrusivePtr<Val>& v, BroFunc* func) static bool val_is_func(const ValPtr& v, BroFunc* func)
{ {
if ( v->GetType()->Tag() != zeek::TYPE_FUNC ) if ( v->GetType()->Tag() != zeek::TYPE_FUNC )
return false; return false;
@ -348,14 +347,14 @@ broker::expected<broker::data> Frame::Serialize(const Frame* target, const id_li
return {std::move(rval)}; return {std::move(rval)};
} }
std::pair<bool, zeek::IntrusivePtr<Frame>> Frame::Unserialize(const broker::vector& data) std::pair<bool, FramePtr> Frame::Unserialize(const broker::vector& data)
{ {
if ( data.size() == 0 ) if ( data.size() == 0 )
return std::make_pair(true, nullptr); return std::make_pair(true, nullptr);
id_list outer_ids; id_list outer_ids;
OffsetMap offset_map; OffsetMap offset_map;
zeek::IntrusivePtr<Frame> closure; FramePtr closure;
auto where = data.begin(); 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); // if (c) closure = c->SelectiveClone(outer_ids);
} }
void Frame::SetTrigger(zeek::IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger) void Frame::SetTrigger(zeek::detail::trigger::TriggerPtr arg_trigger)
{ {
trigger = std::move(arg_trigger); trigger = std::move(arg_trigger);
} }

View file

@ -21,6 +21,19 @@ class BroFunc;
ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger); ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger);
namespace zeek::detail {
using IDPtr = zeek::IntrusivePtr<ID>;
namespace trigger {
using TriggerPtr = zeek::IntrusivePtr<Trigger>;
}
}
using ValPtr = zeek::IntrusivePtr<Val>;
class Frame;
using FramePtr = zeek::IntrusivePtr<Frame>;
class Frame : public BroObj { class Frame : public BroObj {
public: public:
/** /**
@ -43,7 +56,7 @@ public:
* @param n the index to get. * @param n the index to get.
* @return the value at index *n* of the underlying array. * @return the value at index *n* of the underlying array.
*/ */
const zeek::IntrusivePtr<Val>& GetElement(int n) const const ValPtr& GetElement(int n) const
{ return frame[n].val; } { return frame[n].val; }
[[deprecated("Remove in v4.1. Use GetElement(int).")]] [[deprecated("Remove in v4.1. Use GetElement(int).")]]
@ -54,7 +67,7 @@ public:
* @param n the index to set * @param n the index to set
* @param v the value to set it to * @param v the value to set it to
*/ */
void SetElement(int n, zeek::IntrusivePtr<Val> v); void SetElement(int n, ValPtr v);
[[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Pass IntrusivePtr instead.")]]
void SetElement(int n, Val* v); void SetElement(int n, Val* v);
@ -66,8 +79,8 @@ public:
* @param id the ID to associate * @param id the ID to associate
* @param v the value to associate it with * @param v the value to associate it with
*/ */
void SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr<Val> v); void SetElement(const zeek::detail::ID* id, ValPtr v);
void SetElement(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<Val> v) void SetElement(const zeek::detail::IDPtr& id, ValPtr v)
{ SetElement(id.get(), std::move(v)); } { SetElement(id.get(), std::move(v)); }
/** /**
@ -77,7 +90,7 @@ public:
* @param id the id who's value to retreive * @param id the id who's value to retreive
* @return the value associated with *id* * @return the value associated with *id*
*/ */
const zeek::IntrusivePtr<Val>& GetElementByID(const zeek::IntrusivePtr<zeek::detail::ID>& id) const const ValPtr& GetElementByID(const zeek::detail::IDPtr& id) const
{ return GetElementByID(id.get()); } { return GetElementByID(id.get()); }
[[deprecated("Remove in v4.1. Use GetElementByID().")]] [[deprecated("Remove in v4.1. Use GetElementByID().")]]
@ -195,7 +208,7 @@ public:
* and the second is the unserialized frame with reference count +1, or * and the second is the unserialized frame with reference count +1, or
* null if the serialization wasn't successful. * null if the serialization wasn't successful.
*/ */
static std::pair<bool, zeek::IntrusivePtr<Frame>> Unserialize(const broker::vector& data); static std::pair<bool, FramePtr> Unserialize(const broker::vector& data);
/** /**
* Sets the IDs that the frame knows offsets for. These offsets will * 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, // If the frame is run in the context of a trigger condition evaluation,
// the trigger needs to be registered. // the trigger needs to be registered.
void SetTrigger(zeek::IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger); void SetTrigger(zeek::detail::trigger::TriggerPtr arg_trigger);
void ClearTrigger(); void ClearTrigger();
zeek::detail::trigger::Trigger* GetTrigger() const { return trigger.get(); } zeek::detail::trigger::Trigger* GetTrigger() const { return trigger.get(); }
@ -241,13 +254,13 @@ private:
using OffsetMap = std::unordered_map<std::string, int>; using OffsetMap = std::unordered_map<std::string, int>;
struct Element { struct Element {
zeek::IntrusivePtr<Val> val; ValPtr val;
// Weak reference is used to prevent circular reference memory leaks // Weak reference is used to prevent circular reference memory leaks
// in lambdas/closures. // in lambdas/closures.
bool weak_ref; bool weak_ref;
}; };
const zeek::IntrusivePtr<Val>& 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 * 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. */ /** The next statement to be evaluted in the context of this frame. */
zeek::detail::Stmt* next_stmt; zeek::detail::Stmt* next_stmt;
zeek::IntrusivePtr<zeek::detail::trigger::Trigger> trigger; zeek::detail::trigger::TriggerPtr trigger;
const zeek::detail::CallExpr* call; const zeek::detail::CallExpr* call;
std::unique_ptr<std::vector<BroFunc*>> functions_with_closure_frame_reference; std::unique_ptr<std::vector<BroFunc*>> functions_with_closure_frame_reference;

View file

@ -60,7 +60,7 @@ extern RETSIGTYPE sig_handler(int signo);
std::vector<CallInfo> call_stack; std::vector<CallInfo> call_stack;
bool did_builtin_init = false; bool did_builtin_init = false;
static const std::pair<bool, zeek::IntrusivePtr<Val>> empty_hook_result(false, nullptr); static const std::pair<bool, ValPtr> empty_hook_result(false, nullptr);
std::string render_call_stack() std::string render_call_stack()
{ {
@ -122,19 +122,19 @@ Func::Func(Kind arg_kind) : kind(arg_kind)
Func::~Func() = default; Func::~Func() = default;
void Func::AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> /* new_body */, void Func::AddBody(zeek::detail::StmtPtr /* new_body */,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& /* new_inits */, const std::vector<zeek::detail::IDPtr>& /* new_inits */,
size_t /* new_frame_size */, int /* priority */) size_t /* new_frame_size */, int /* priority */)
{ {
Internal("Func::AddBody called"); Internal("Func::AddBody called");
} }
void Func::SetScope(zeek::IntrusivePtr<Scope> newscope) void Func::SetScope(ScopePtr newscope)
{ {
scope = std::move(newscope); scope = std::move(newscope);
} }
zeek::IntrusivePtr<Func> Func::DoClone() FuncPtr Func::DoClone()
{ {
// By default, ok just to return a reference. Func does not have any state // By default, ok just to return a reference. Func does not have any state
// that is different across instances. // that is different across instances.
@ -216,7 +216,7 @@ void Func::CopyStateInto(Func* other) const
other->unique_id = unique_id; other->unique_id = unique_id;
} }
void Func::CheckPluginResult(bool handled, const zeek::IntrusivePtr<Val>& hook_result, void Func::CheckPluginResult(bool handled, const ValPtr& hook_result,
zeek::FunctionFlavor flavor) const zeek::FunctionFlavor flavor) const
{ {
// Helper function factoring out this code from BroFunc:Call() for // Helper function factoring out this code from BroFunc:Call() for
@ -269,8 +269,8 @@ void Func::CheckPluginResult(bool handled, const zeek::IntrusivePtr<Val>& hook_r
} }
} }
BroFunc::BroFunc(const zeek::IntrusivePtr<zeek::detail::ID>& arg_id, zeek::IntrusivePtr<zeek::detail::Stmt> arg_body, BroFunc::BroFunc(const zeek::detail::IDPtr& arg_id, zeek::detail::StmtPtr arg_body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& aggr_inits, const std::vector<zeek::detail::IDPtr>& aggr_inits,
size_t arg_frame_size, int priority) size_t arg_frame_size, int priority)
: Func(BRO_FUNC) : Func(BRO_FUNC)
{ {
@ -305,7 +305,7 @@ Val* Func::Call(val_list* args, Frame* parent) const
return Invoke(&zargs, parent).release(); return Invoke(&zargs, parent).release();
}; };
zeek::IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const ValPtr BroFunc::Invoke(zeek::Args* args, Frame* parent) const
{ {
#ifdef PROFILE_BRO_FUNCTIONS #ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", Name()); DEBUG_MSG("Function: %s\n", Name());
@ -357,7 +357,7 @@ zeek::IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
} }
stmt_flow_type flow = FLOW_NEXT; stmt_flow_type flow = FLOW_NEXT;
zeek::IntrusivePtr<Val> result; ValPtr result;
for ( const auto& body : bodies ) for ( const auto& body : bodies )
{ {
@ -450,8 +450,8 @@ zeek::IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
return result; return result;
} }
void BroFunc::AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body, void BroFunc::AddBody(zeek::detail::StmtPtr new_body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::detail::IDPtr>& new_inits,
size_t new_frame_size, int priority) size_t new_frame_size, int priority)
{ {
if ( new_frame_size > frame_size ) if ( new_frame_size > frame_size )
@ -541,7 +541,7 @@ bool BroFunc::UpdateClosure(const broker::vector& data)
} }
zeek::IntrusivePtr<Func> BroFunc::DoClone() FuncPtr BroFunc::DoClone()
{ {
// BroFunc could hold a closure. In this case a clone of it must // BroFunc could hold a closure. In this case a clone of it must
// store a copy of this closure. // store a copy of this closure.
@ -575,9 +575,9 @@ void BroFunc::Describe(ODesc* d) const
} }
} }
zeek::IntrusivePtr<zeek::detail::Stmt> BroFunc::AddInits( zeek::detail::StmtPtr BroFunc::AddInits(
zeek::IntrusivePtr<zeek::detail::Stmt> body, zeek::detail::StmtPtr body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& inits) const std::vector<zeek::detail::IDPtr>& inits)
{ {
if ( inits.empty() ) if ( inits.empty() )
return body; return body;
@ -616,7 +616,7 @@ bool BuiltinFunc::IsPure() const
return is_pure; return is_pure;
} }
zeek::IntrusivePtr<Val> BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const ValPtr BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const
{ {
#ifdef PROFILE_BRO_FUNCTIONS #ifdef PROFILE_BRO_FUNCTIONS
DEBUG_MSG("Function: %s\n", Name()); DEBUG_MSG("Function: %s\n", Name());
@ -667,10 +667,10 @@ void BuiltinFunc::Describe(ODesc* d) const
void builtin_error(const char* msg) void builtin_error(const char* msg)
{ {
builtin_error(msg, zeek::IntrusivePtr<Val>{}); builtin_error(msg, ValPtr{});
} }
void builtin_error(const char* msg, zeek::IntrusivePtr<Val> arg) void builtin_error(const char* msg, ValPtr arg)
{ {
builtin_error(msg, arg.get()); 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 // Gets a function's priority from its Scope's attributes. Errors if it sees any
// problems. // problems.
static int get_func_priority(const std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>& attrs) static int get_func_priority(const std::vector<zeek::detail::AttrPtr>& attrs)
{ {
int priority = 0; int priority = 0;
@ -881,7 +881,7 @@ static int get_func_priority(const std::vector<zeek::IntrusivePtr<zeek::detail::
return priority; return priority;
} }
function_ingredients::function_ingredients(zeek::IntrusivePtr<Scope> scope, zeek::IntrusivePtr<zeek::detail::Stmt> body) function_ingredients::function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body)
{ {
frame_size = scope->Length(); frame_size = scope->Length();
inits = scope->GetInits(); inits = scope->GetInits();

View file

@ -20,12 +20,18 @@
class Val; class Val;
class Frame; class Frame;
class Scope; class Scope;
using ScopePtr = zeek::IntrusivePtr<Scope>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek);
namespace zeek::detail {
using IDPtr = zeek::IntrusivePtr<ID>;
using StmtPtr = zeek::IntrusivePtr<Stmt>;
}
namespace caf { namespace caf {
template <class> class expected; template <class> class expected;
} }
@ -36,9 +42,12 @@ using vector = std::vector<data>;
using caf::expected; using caf::expected;
} }
class Func;
using FuncPtr = zeek::IntrusivePtr<Func>;
class Func : public BroObj { class Func : public BroObj {
public: public:
static inline const zeek::IntrusivePtr<Func> nil; static inline const FuncPtr nil;
enum Kind { BRO_FUNC, BUILTIN_FUNC }; enum Kind { BRO_FUNC, BUILTIN_FUNC };
@ -50,7 +59,7 @@ public:
zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); } zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); }
struct Body { struct Body {
zeek::IntrusivePtr<zeek::detail::Stmt> stmts; zeek::detail::StmtPtr stmts;
int priority; int priority;
bool operator<(const Body& other) const bool operator<(const Body& other) const
{ return priority > other.priority; } // reverse sort { return priority > other.priority; } // reverse sort
@ -68,7 +77,7 @@ public:
* @param parent the frame from which the function is being called. * @param parent the frame from which the function is being called.
* @return the return value of the function call. * @return the return value of the function call.
*/ */
virtual zeek::IntrusivePtr<Val> Invoke( virtual ValPtr Invoke(
zeek::Args* args, Frame* parent = nullptr) const = 0; zeek::Args* args, Frame* parent = nullptr) const = 0;
/** /**
@ -77,8 +86,8 @@ public:
template <class... Args> template <class... Args>
std::enable_if_t< std::enable_if_t<
std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>, std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>,
zeek::IntrusivePtr<Val>>, ValPtr>,
zeek::IntrusivePtr<Val>> ValPtr>
Invoke(Args&&... args) const Invoke(Args&&... args) const
{ {
auto zargs = zeek::Args{std::forward<Args>(args)...}; auto zargs = zeek::Args{std::forward<Args>(args)...};
@ -86,17 +95,17 @@ public:
} }
// Add a new event handler to an existing function (event). // Add a new event handler to an existing function (event).
virtual void AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body, virtual void AddBody(zeek::detail::StmtPtr new_body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::detail::IDPtr>& new_inits,
size_t new_frame_size, int priority = 0); size_t new_frame_size, int priority = 0);
virtual void SetScope(zeek::IntrusivePtr<Scope> newscope); virtual void SetScope(ScopePtr newscope);
virtual Scope* GetScope() const { return scope.get(); } virtual Scope* GetScope() const { return scope.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
virtual zeek::FuncType* FType() const { return type.get(); } virtual zeek::FuncType* FType() const { return type.get(); }
const zeek::IntrusivePtr<zeek::FuncType>& GetType() const const zeek::FuncTypePtr& GetType() const
{ return type; } { return type; }
Kind GetKind() const { return kind; } Kind GetKind() const { return kind; }
@ -107,12 +116,12 @@ public:
void Describe(ODesc* d) const override = 0; void Describe(ODesc* d) const override = 0;
virtual void DescribeDebug(ODesc* d, const zeek::Args* args) const; virtual void DescribeDebug(ODesc* d, const zeek::Args* args) const;
virtual zeek::IntrusivePtr<Func> DoClone(); virtual FuncPtr DoClone();
virtual TraversalCode Traverse(TraversalCallback* cb) const; virtual TraversalCode Traverse(TraversalCallback* cb) const;
uint32_t GetUniqueFuncID() const { return unique_id; } uint32_t GetUniqueFuncID() const { return unique_id; }
static const zeek::IntrusivePtr<Func>& GetFuncPtrByID(uint32_t id) static const FuncPtr& GetFuncPtrByID(uint32_t id)
{ return id >= unique_ids.size() ? Func::nil : unique_ids[id]; } { return id >= unique_ids.size() ? Func::nil : unique_ids[id]; }
protected: protected:
@ -122,29 +131,29 @@ protected:
void CopyStateInto(Func* other) const; void CopyStateInto(Func* other) const;
// Helper function for checking result of plugin hook. // Helper function for checking result of plugin hook.
void CheckPluginResult(bool handled, const zeek::IntrusivePtr<Val>& hook_result, void CheckPluginResult(bool handled, const ValPtr& hook_result,
zeek::FunctionFlavor flavor) const; zeek::FunctionFlavor flavor) const;
std::vector<Body> bodies; std::vector<Body> bodies;
zeek::IntrusivePtr<Scope> scope; ScopePtr scope;
Kind kind; Kind kind;
uint32_t unique_id; uint32_t unique_id;
zeek::IntrusivePtr<zeek::FuncType> type; zeek::FuncTypePtr type;
std::string name; std::string name;
static inline std::vector<zeek::IntrusivePtr<Func>> unique_ids; static inline std::vector<FuncPtr> unique_ids;
}; };
class BroFunc final : public Func { class BroFunc final : public Func {
public: public:
BroFunc(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::detail::Stmt> body, BroFunc(const zeek::detail::IDPtr& id, zeek::detail::StmtPtr body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& inits, const std::vector<zeek::detail::IDPtr>& inits,
size_t frame_size, int priority); size_t frame_size, int priority);
~BroFunc() override; ~BroFunc() override;
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> 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 * Adds adds a closure to the function. Closures are cloned and
@ -175,8 +184,8 @@ public:
*/ */
broker::expected<broker::data> SerializeClosure() const; broker::expected<broker::data> SerializeClosure() const;
void AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body, void AddBody(zeek::detail::StmtPtr new_body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::detail::IDPtr>& new_inits,
size_t new_frame_size, int priority) override; size_t new_frame_size, int priority) override;
/** Sets this function's outer_id list. */ /** Sets this function's outer_id list. */
@ -187,14 +196,14 @@ public:
protected: protected:
BroFunc() : Func(BRO_FUNC) {} BroFunc() : Func(BRO_FUNC) {}
zeek::IntrusivePtr<zeek::detail::Stmt> AddInits( zeek::detail::StmtPtr AddInits(
zeek::IntrusivePtr<zeek::detail::Stmt> body, zeek::detail::StmtPtr body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& inits); const std::vector<zeek::detail::IDPtr>& inits);
/** /**
* Clones this function along with its closures. * Clones this function along with its closures.
*/ */
zeek::IntrusivePtr<Func> DoClone() override; FuncPtr DoClone() override;
/** /**
* Performs a selective clone of *f* using the IDs that were * Performs a selective clone of *f* using the IDs that were
@ -222,7 +231,7 @@ public:
~BuiltinFunc() override; ~BuiltinFunc() override;
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> Invoke(zeek::Args* args, Frame* parent) const override; ValPtr Invoke(zeek::Args* args, Frame* parent) const override;
built_in_func TheFunc() const { return func; } built_in_func TheFunc() const { return func; }
void Describe(ODesc* d) const override; 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);
extern void builtin_error(const char* msg, zeek::IntrusivePtr<Val>); extern void builtin_error(const char* msg, ValPtr);
extern void builtin_error(const char* msg, BroObj* arg); extern void builtin_error(const char* msg, BroObj* arg);
extern void init_builtin_funcs(); extern void init_builtin_funcs();
extern void init_builtin_funcs_subdirs(); 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 // Gathers all of the information from a scope and a function body needed
// to build a function. // to build a function.
function_ingredients(zeek::IntrusivePtr<Scope> scope, zeek::IntrusivePtr<zeek::detail::Stmt> body); function_ingredients(ScopePtr scope, zeek::detail::StmtPtr body);
zeek::IntrusivePtr<zeek::detail::ID> id; zeek::detail::IDPtr id;
zeek::IntrusivePtr<zeek::detail::Stmt> body; zeek::detail::StmtPtr body;
std::vector<zeek::IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::detail::IDPtr> inits;
int frame_size; int frame_size;
int priority; int priority;
zeek::IntrusivePtr<Scope> scope; ScopePtr scope;
}; };
extern std::vector<CallInfo> call_stack; extern std::vector<CallInfo> call_stack;

View file

@ -1,3 +1,4 @@
// See the file "COPYING" in the main distribution directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
#include "zeek-config.h" #include "zeek-config.h"
@ -19,24 +20,24 @@
#include "zeekygen/ScriptInfo.h" #include "zeekygen/ScriptInfo.h"
#include "module_util.h" #include "module_util.h"
zeek::IntrusivePtr<zeek::RecordType> zeek::id::conn_id; zeek::RecordTypePtr zeek::id::conn_id;
zeek::IntrusivePtr<zeek::RecordType> zeek::id::endpoint; zeek::RecordTypePtr zeek::id::endpoint;
zeek::IntrusivePtr<zeek::RecordType> zeek::id::connection; zeek::RecordTypePtr zeek::id::connection;
zeek::IntrusivePtr<zeek::RecordType> zeek::id::fa_file; zeek::RecordTypePtr zeek::id::fa_file;
zeek::IntrusivePtr<zeek::RecordType> zeek::id::fa_metadata; zeek::RecordTypePtr zeek::id::fa_metadata;
zeek::IntrusivePtr<zeek::EnumType> zeek::id::transport_proto; zeek::EnumTypePtr zeek::id::transport_proto;
zeek::IntrusivePtr<zeek::TableType> zeek::id::string_set; zeek::TableTypePtr zeek::id::string_set;
zeek::IntrusivePtr<zeek::TableType> zeek::id::string_array; zeek::TableTypePtr zeek::id::string_array;
zeek::IntrusivePtr<zeek::TableType> zeek::id::count_set; zeek::TableTypePtr zeek::id::count_set;
zeek::IntrusivePtr<zeek::VectorType> zeek::id::string_vec; zeek::VectorTypePtr zeek::id::string_vec;
zeek::IntrusivePtr<zeek::VectorType> zeek::id::index_vec; zeek::VectorTypePtr zeek::id::index_vec;
const zeek::IntrusivePtr<zeek::detail::ID>& zeek::id::find(std::string_view name) const zeek::detail::IDPtr& zeek::id::find(std::string_view name)
{ {
return global_scope()->Find(name); return global_scope()->Find(name);
} }
const zeek::IntrusivePtr<zeek::Type>& 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); auto id = global_scope()->Find(name);
@ -47,7 +48,7 @@ const zeek::IntrusivePtr<zeek::Type>& zeek::id::find_type(std::string_view name)
return id->GetType(); return id->GetType();
} }
const zeek::IntrusivePtr<Val>& zeek::id::find_val(std::string_view name) const ValPtr& zeek::id::find_val(std::string_view name)
{ {
auto id = global_scope()->Find(name); auto id = global_scope()->Find(name);
@ -58,7 +59,7 @@ const zeek::IntrusivePtr<Val>& zeek::id::find_val(std::string_view name)
return id->GetVal(); return id->GetVal();
} }
const zeek::IntrusivePtr<Val>& zeek::id::find_const(std::string_view name) const ValPtr& zeek::id::find_const(std::string_view name)
{ {
auto id = global_scope()->Find(name); auto id = global_scope()->Find(name);
@ -73,7 +74,7 @@ const zeek::IntrusivePtr<Val>& zeek::id::find_const(std::string_view name)
return id->GetVal(); return id->GetVal();
} }
zeek::IntrusivePtr<Func> 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); const auto& v = zeek::id::find_val(name);
@ -130,7 +131,7 @@ std::string ID::ModuleName() const
return extract_module_name(name); return extract_module_name(name);
} }
void ID::SetType(zeek::IntrusivePtr<zeek::Type> t) void ID::SetType(zeek::TypePtr t)
{ {
type = std::move(t); type = std::move(t);
} }
@ -140,7 +141,7 @@ void ID::ClearVal()
val = nullptr; val = nullptr;
} }
void ID::SetVal(zeek::IntrusivePtr<Val> v) void ID::SetVal(ValPtr v)
{ {
val = std::move(v); val = std::move(v);
Modified(); Modified();
@ -169,7 +170,7 @@ void ID::SetVal(zeek::IntrusivePtr<Val> v)
} }
} }
void ID::SetVal(zeek::IntrusivePtr<Val> v, InitClass c) void ID::SetVal(ValPtr v, InitClass c)
{ {
if ( c == INIT_NONE || c == INIT_FULL ) if ( c == INIT_NONE || c == INIT_FULL )
{ {
@ -207,7 +208,7 @@ void ID::SetVal(zeek::IntrusivePtr<Val> v, InitClass c)
} }
} }
void ID::SetVal(zeek::IntrusivePtr<Expr> ev, InitClass c) void ID::SetVal(ExprPtr ev, InitClass c)
{ {
const auto& a = attrs->Find(c == INIT_EXTRA ? ATTR_ADD_FUNC : ATTR_DEL_FUNC); 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; return GetAttr(ATTR_REDEF) != nullptr;
} }
void ID::SetAttrs(zeek::IntrusivePtr<Attributes> a) void ID::SetAttrs(AttributesPtr a)
{ {
attrs = nullptr; attrs = nullptr;
AddAttrs(std::move(a)); AddAttrs(std::move(a));
@ -268,7 +269,7 @@ void ID::UpdateValAttrs()
} }
} }
const zeek::IntrusivePtr<Attr>& ID::GetAttr(AttrTag t) const const AttrPtr& ID::GetAttr(AttrTag t) const
{ {
return attrs ? attrs->Find(t) : Attr::nil; return attrs ? attrs->Find(t) : Attr::nil;
} }
@ -278,12 +279,12 @@ bool ID::IsDeprecated() const
return GetAttr(ATTR_DEPRECATED) != nullptr; return GetAttr(ATTR_DEPRECATED) != nullptr;
} }
void ID::MakeDeprecated(zeek::IntrusivePtr<Expr> deprecation) void ID::MakeDeprecated(ExprPtr deprecation)
{ {
if ( IsDeprecated() ) if ( IsDeprecated() )
return; return;
std::vector<zeek::IntrusivePtr<Attr>> attrv{zeek::make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))}; std::vector<AttrPtr> attrv{zeek::make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))};
AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal())); AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
} }
@ -308,7 +309,7 @@ std::string ID::GetDeprecationWarning() const
return fmt("deprecated (%s): %s", Name(), result.c_str()); return fmt("deprecated (%s): %s", Name(), result.c_str());
} }
void ID::AddAttrs(zeek::IntrusivePtr<Attributes> a) void ID::AddAttrs(AttributesPtr a)
{ {
if ( attrs ) if ( attrs )
attrs->AddAttrs(a); attrs->AddAttrs(a);
@ -334,12 +335,12 @@ void ID::SetOption()
// option implied redefinable // option implied redefinable
if ( ! IsRedefinable() ) if ( ! IsRedefinable() )
{ {
std::vector<zeek::IntrusivePtr<Attr>> attrv{zeek::make_intrusive<Attr>(ATTR_REDEF)}; std::vector<AttrPtr> attrv{zeek::make_intrusive<Attr>(ATTR_REDEF)};
AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal())); AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
} }
} }
void ID::EvalFunc(zeek::IntrusivePtr<Expr> ef, zeek::IntrusivePtr<Expr> ev) void ID::EvalFunc(ExprPtr ef, ExprPtr ev)
{ {
auto arg1 = zeek::make_intrusive<zeek::detail::ConstExpr>(val); auto arg1 = zeek::make_intrusive<zeek::detail::ConstExpr>(val);
auto args = zeek::make_intrusive<zeek::detail::ListExpr>(); auto args = zeek::make_intrusive<zeek::detail::ListExpr>();
@ -642,7 +643,7 @@ void ID::UpdateValID()
} }
#endif #endif
void ID::AddOptionHandler(zeek::IntrusivePtr<Func> callback, int priority) void ID::AddOptionHandler(FuncPtr callback, int priority)
{ {
option_handlers.emplace(priority, std::move(callback)); option_handlers.emplace(priority, std::move(callback));
} }

View file

@ -14,7 +14,10 @@
#include <vector> #include <vector>
class Val; class Val;
using ValPtr = zeek::IntrusivePtr<Val>;
class Func; class Func;
using FuncPtr = zeek::IntrusivePtr<Func>;
namespace zeek { class Type; } namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::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(VectorType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek);
using TypePtr = zeek::IntrusivePtr<zeek::Type>;
using RecordTypePtr = zeek::IntrusivePtr<zeek::RecordType>;
using TableTypePtr = zeek::IntrusivePtr<zeek::TableType>;
using VectorTypePtr = zeek::IntrusivePtr<zeek::VectorType>;
using EnumTypePtr = zeek::IntrusivePtr<zeek::EnumType>;
namespace zeek::detail { namespace zeek::detail {
class Attributes; class Attributes;
class Expr; class Expr;
using ExprPtr = zeek::IntrusivePtr<Expr>;
enum InitClass { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, }; enum InitClass { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, };
enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL }; enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
class ID;
using IDPtr = zeek::IntrusivePtr<ID>;
class ID final : public BroObj, public notifier::Modifiable { class ID final : public BroObj, public notifier::Modifiable {
public: public:
static inline const zeek::IntrusivePtr<ID> nil; static inline const IDPtr nil;
ID(const char* name, IDScope arg_scope, bool arg_is_export); ID(const char* name, IDScope arg_scope, bool arg_is_export);
@ -50,14 +63,14 @@ public:
std::string ModuleName() const; std::string ModuleName() const;
void SetType(zeek::IntrusivePtr<Type> t); void SetType(TypePtr t);
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
zeek::Type* Type() { return type.get(); } zeek::Type* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
const zeek::Type* Type() const { return type.get(); } const zeek::Type* Type() const { return type.get(); }
const zeek::IntrusivePtr<zeek::Type>& GetType() const const TypePtr& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
@ -74,10 +87,10 @@ public:
void MakeType() { is_type = true; } void MakeType() { is_type = true; }
void SetVal(zeek::IntrusivePtr<Val> v); void SetVal(ValPtr v);
void SetVal(zeek::IntrusivePtr<Val> v, InitClass c); void SetVal(ValPtr v, InitClass c);
void SetVal(zeek::IntrusivePtr<Expr> ev, InitClass c); void SetVal(ExprPtr ev, InitClass c);
bool HasVal() const { return val != nullptr; } bool HasVal() const { return val != nullptr; }
@ -86,7 +99,7 @@ public:
[[deprecated("Remove in v4.1. Use GetVal().")]] [[deprecated("Remove in v4.1. Use GetVal().")]]
const Val* ID_Val() const { return val.get(); } const Val* ID_Val() const { return val.get(); }
const zeek::IntrusivePtr<Val>& GetVal() const const ValPtr& GetVal() const
{ return val; } { return val; }
void ClearVal(); void ClearVal();
@ -105,22 +118,22 @@ public:
bool IsRedefinable() const; bool IsRedefinable() const;
void SetAttrs(zeek::IntrusivePtr<Attributes> attr); void SetAttrs(AttributesPtr attr);
void AddAttrs(zeek::IntrusivePtr<Attributes> attr); void AddAttrs(AttributesPtr attr);
void RemoveAttr(zeek::detail::AttrTag a); void RemoveAttr(AttrTag a);
void UpdateValAttrs(); void UpdateValAttrs();
const zeek::IntrusivePtr<Attributes>& GetAttrs() const const AttributesPtr& GetAttrs() const
{ return attrs; } { return attrs; }
[[deprecated("Remove in 4.1. Use GetAttrs().")]] [[deprecated("Remove in 4.1. Use GetAttrs().")]]
Attributes* Attrs() const { return attrs.get(); } Attributes* Attrs() const { return attrs.get(); }
const zeek::IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const; const AttrPtr& GetAttr(zeek::detail::AttrTag t) const;
bool IsDeprecated() const; bool IsDeprecated() const;
void MakeDeprecated(zeek::IntrusivePtr<Expr> deprecation); void MakeDeprecated(ExprPtr deprecation);
std::string GetDeprecationWarning() const; std::string GetDeprecationWarning() const;
@ -143,11 +156,11 @@ public:
bool HasOptionHandlers() const bool HasOptionHandlers() const
{ return !option_handlers.empty(); } { return !option_handlers.empty(); }
void AddOptionHandler(zeek::IntrusivePtr<Func> callback, int priority); void AddOptionHandler(FuncPtr callback, int priority);
std::vector<Func*> GetOptionHandlers() const; std::vector<Func*> GetOptionHandlers() const;
protected: protected:
void EvalFunc(zeek::IntrusivePtr<Expr> ef, zeek::IntrusivePtr<Expr> ev); void EvalFunc(ExprPtr ef, ExprPtr ev);
#ifdef DEBUG #ifdef DEBUG
void UpdateValID(); void UpdateValID();
@ -157,13 +170,13 @@ protected:
IDScope scope; IDScope scope;
bool is_export; bool is_export;
bool infer_return_type; bool infer_return_type;
zeek::IntrusivePtr<zeek::Type> type; TypePtr type;
bool is_const, is_enum_const, is_type, is_option; bool is_const, is_enum_const, is_type, is_option;
int offset; int offset;
zeek::IntrusivePtr<Val> val; ValPtr val;
zeek::IntrusivePtr<Attributes> attrs; AttributesPtr attrs;
// contains list of functions that are called when an option changes // contains list of functions that are called when an option changes
std::multimap<int, zeek::IntrusivePtr<Func>> option_handlers; std::multimap<int, FuncPtr> option_handlers;
}; };
@ -179,7 +192,7 @@ namespace zeek::id {
* @return The identifier, which may reference a nil object if no such * @return The identifier, which may reference a nil object if no such
* name exists. * name exists.
*/ */
const zeek::IntrusivePtr<zeek::detail::ID>& 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 * Lookup an ID by its name and return its type. A fatal occurs if the ID
@ -187,7 +200,7 @@ const zeek::IntrusivePtr<zeek::detail::ID>& find(std::string_view name);
* @param name The identifier name to lookup * @param name The identifier name to lookup
* @return The type of the identifier. * @return The type of the identifier.
*/ */
const zeek::IntrusivePtr<zeek::Type>& 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). * Lookup an ID by its name and return its type (as cast to @c T).
@ -205,7 +218,7 @@ zeek::IntrusivePtr<T> find_type(std::string_view name)
* @param name The identifier name to lookup * @param name The identifier name to lookup
* @return The current value of the identifier * @return The current value of the identifier
*/ */
const zeek::IntrusivePtr<Val>& 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). * Lookup an ID by its name and return its value (as cast to @c T).
@ -223,7 +236,7 @@ zeek::IntrusivePtr<T> find_val(std::string_view name)
* @param name The identifier name to lookup * @param name The identifier name to lookup
* @return The current value of the identifier * @return The current value of the identifier
*/ */
const zeek::IntrusivePtr<Val>& 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). * Lookup an ID by its name and return its value (as cast to @c T).
@ -241,19 +254,19 @@ zeek::IntrusivePtr<T> find_const(std::string_view name)
* @param name The identifier name to lookup * @param name The identifier name to lookup
* @return The current function value the identifier references. * @return The current function value the identifier references.
*/ */
zeek::IntrusivePtr<Func> find_func(std::string_view name); FuncPtr find_func(std::string_view name);
extern zeek::IntrusivePtr<zeek::RecordType> conn_id; extern RecordTypePtr conn_id;
extern zeek::IntrusivePtr<zeek::RecordType> endpoint; extern RecordTypePtr endpoint;
extern zeek::IntrusivePtr<zeek::RecordType> connection; extern RecordTypePtr connection;
extern zeek::IntrusivePtr<zeek::RecordType> fa_file; extern RecordTypePtr fa_file;
extern zeek::IntrusivePtr<zeek::RecordType> fa_metadata; extern RecordTypePtr fa_metadata;
extern zeek::IntrusivePtr<zeek::EnumType> transport_proto; extern EnumTypePtr transport_proto;
extern zeek::IntrusivePtr<zeek::TableType> string_set; extern TableTypePtr string_set;
extern zeek::IntrusivePtr<zeek::TableType> string_array; extern TableTypePtr string_array;
extern zeek::IntrusivePtr<zeek::TableType> count_set; extern TableTypePtr count_set;
extern zeek::IntrusivePtr<zeek::VectorType> string_vec; extern VectorTypePtr string_vec;
extern zeek::IntrusivePtr<zeek::VectorType> index_vec; extern VectorTypePtr index_vec;
namespace detail { namespace detail {

View file

@ -13,7 +13,7 @@
#include "BroString.h" #include "BroString.h"
#include "Reporter.h" #include "Reporter.h"
static zeek::IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len) static VectorValPtr BuildOptionsVal(const u_char* data, int len)
{ {
auto vv = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("ip6_options")); auto vv = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("ip6_options"));
@ -49,9 +49,9 @@ static zeek::IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len
return vv; return vv;
} }
zeek::IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(zeek::IntrusivePtr<VectorVal> chain) const RecordValPtr IPv6_Hdr::ToVal(VectorValPtr chain) const
{ {
zeek::IntrusivePtr<RecordVal> rv; RecordValPtr rv;
switch ( type ) { switch ( type ) {
case IPPROTO_IPV6: case IPPROTO_IPV6:
@ -298,7 +298,7 @@ zeek::IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(zeek::IntrusivePtr<VectorVal> chai
return rv; return rv;
} }
zeek::IntrusivePtr<RecordVal> IPv6_Hdr::ToVal() const RecordValPtr IPv6_Hdr::ToVal() const
{ return ToVal(nullptr); } { return ToVal(nullptr); }
RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const 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(); return ip4 ? IPAddr(ip4->ip_dst) : ip6_hdrs->DstAddr();
} }
zeek::IntrusivePtr<RecordVal> IP_Hdr::ToIPHdrVal() const RecordValPtr IP_Hdr::ToIPHdrVal() const
{ {
zeek::IntrusivePtr<RecordVal> rval; RecordValPtr rval;
if ( ip4 ) if ( ip4 )
{ {
@ -356,7 +356,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const
return ToIPHdrVal().release(); return ToIPHdrVal().release();
} }
zeek::IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal() const RecordValPtr IP_Hdr::ToPktHdrVal() const
{ {
static auto pkt_hdr_type = zeek::id::find_type<zeek::RecordType>("pkt_hdr"); static auto pkt_hdr_type = zeek::id::find_type<zeek::RecordType>("pkt_hdr");
return ToPktHdrVal(zeek::make_intrusive<RecordVal>(pkt_hdr_type), 0); return ToPktHdrVal(zeek::make_intrusive<RecordVal>(pkt_hdr_type), 0);
@ -367,7 +367,7 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const
return ToPktHdrVal().release(); return ToPktHdrVal().release();
} }
zeek::IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(zeek::IntrusivePtr<RecordVal> pkt_hdr, int sindex) const RecordValPtr IP_Hdr::ToPktHdrVal(RecordValPtr pkt_hdr, int sindex) const
{ {
static auto tcp_hdr_type = zeek::id::find_type<zeek::RecordType>("tcp_hdr"); static auto tcp_hdr_type = zeek::id::find_type<zeek::RecordType>("tcp_hdr");
static auto udp_hdr_type = zeek::id::find_type<zeek::RecordType>("udp_hdr"); static auto udp_hdr_type = zeek::id::find_type<zeek::RecordType>("udp_hdr");
@ -676,7 +676,7 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len)
} }
#endif #endif
zeek::IntrusivePtr<VectorVal> IPv6_Hdr_Chain::ToVal() const VectorValPtr IPv6_Hdr_Chain::ToVal() const
{ {
static auto ip6_ext_hdr_type = zeek::id::find_type<zeek::RecordType>("ip6_ext_hdr"); static auto ip6_ext_hdr_type = zeek::id::find_type<zeek::RecordType>("ip6_ext_hdr");
static auto ip6_hopopts_type = zeek::id::find_type<zeek::RecordType>("ip6_hopopts"); static auto ip6_hopopts_type = zeek::id::find_type<zeek::RecordType>("ip6_hopopts");

View file

@ -20,6 +20,9 @@ class IPAddr;
class RecordVal; class RecordVal;
class VectorVal; class VectorVal;
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
using VectorValPtr = zeek::IntrusivePtr<VectorVal>;
#ifdef ENABLE_MOBILE_IPV6 #ifdef ENABLE_MOBILE_IPV6
#ifndef IPPROTO_MOBILITY #ifndef IPPROTO_MOBILITY
@ -136,8 +139,8 @@ public:
/** /**
* Returns the script-layer record representation of the header. * Returns the script-layer record representation of the header.
*/ */
zeek::IntrusivePtr<RecordVal> ToVal(zeek::IntrusivePtr<VectorVal> chain) const; RecordValPtr ToVal(VectorValPtr chain) const;
zeek::IntrusivePtr<RecordVal> ToVal() const; RecordValPtr ToVal() const;
[[deprecated("Remove in v4.1. Use ToVal() instead.")]] [[deprecated("Remove in v4.1. Use ToVal() instead.")]]
RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const; RecordVal* BuildRecordVal(VectorVal* chain = nullptr) const;
@ -229,7 +232,7 @@ public:
* Returns a vector of ip6_ext_hdr RecordVals that includes script-layer * Returns a vector of ip6_ext_hdr RecordVals that includes script-layer
* representation of all extension headers in the chain. * representation of all extension headers in the chain.
*/ */
zeek::IntrusivePtr<VectorVal> ToVal() const; VectorValPtr ToVal() const;
[[deprecated("Remove in v4.1. Use ToVal() instead.")]] [[deprecated("Remove in v4.1. Use ToVal() instead.")]]
VectorVal* BuildVal() const; VectorVal* BuildVal() const;
@ -526,7 +529,7 @@ public:
/** /**
* Returns an ip_hdr or ip6_hdr_chain RecordVal. * Returns an ip_hdr or ip6_hdr_chain RecordVal.
*/ */
zeek::IntrusivePtr<RecordVal> ToIPHdrVal() const; RecordValPtr ToIPHdrVal() const;
[[deprecated("Remove in v4.1. Use ToIPHdrVal() instead.")]] [[deprecated("Remove in v4.1. Use ToIPHdrVal() instead.")]]
RecordVal* BuildIPHdrVal() const; RecordVal* BuildIPHdrVal() const;
@ -535,7 +538,7 @@ public:
* Returns a pkt_hdr RecordVal, which includes not only the IP header, but * Returns a pkt_hdr RecordVal, which includes not only the IP header, but
* also upper-layer (tcp/udp/icmp) headers. * also upper-layer (tcp/udp/icmp) headers.
*/ */
zeek::IntrusivePtr<RecordVal> ToPktHdrVal() const; RecordValPtr ToPktHdrVal() const;
[[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]]
RecordVal* BuildPktHdrVal() const; RecordVal* BuildPktHdrVal() const;
@ -544,7 +547,7 @@ public:
* Same as above, but simply add our values into the record at the * Same as above, but simply add our values into the record at the
* specified starting index. * specified starting index.
*/ */
zeek::IntrusivePtr<RecordVal> ToPktHdrVal(zeek::IntrusivePtr<RecordVal> pkt_hdr, int sindex) const; RecordValPtr ToPktHdrVal(RecordValPtr pkt_hdr, int sindex) const;
[[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]] [[deprecated("Remove in v4.1. Use ToPktHdrVal() instead.")]]
RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const; RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const;

View file

@ -40,7 +40,7 @@ OpaqueMgr* OpaqueMgr::mgr()
OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({zeek::NewRef{}, t}) OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({zeek::NewRef{}, t})
{} {}
OpaqueVal::OpaqueVal(zeek::IntrusivePtr<zeek::OpaqueType> t) : Val(std::move(t)) OpaqueVal::OpaqueVal(zeek::OpaqueTypePtr t) : Val(std::move(t))
{} {}
OpaqueVal::~OpaqueVal() OpaqueVal::~OpaqueVal()
@ -58,7 +58,7 @@ const std::string& OpaqueMgr::TypeID(const OpaqueVal* v) const
return x->first; return x->first;
} }
zeek::IntrusivePtr<OpaqueVal> OpaqueMgr::Instantiate(const std::string& id) const OpaqueValPtr OpaqueMgr::Instantiate(const std::string& id) const
{ {
auto x = _types.find(id); auto x = _types.find(id);
return x != _types.end() ? (*x->second)() : nullptr; return x != _types.end() ? (*x->second)() : nullptr;
@ -75,7 +75,7 @@ broker::expected<broker::data> OpaqueVal::Serialize() const
return {broker::vector{std::move(type), std::move(*d)}}; return {broker::vector{std::move(type), std::move(*d)}};
} }
zeek::IntrusivePtr<OpaqueVal> OpaqueVal::Unserialize(const broker::data& data) OpaqueValPtr OpaqueVal::Unserialize(const broker::data& data)
{ {
auto v = caf::get_if<broker::vector>(&data); auto v = caf::get_if<broker::vector>(&data);
@ -96,7 +96,7 @@ zeek::IntrusivePtr<OpaqueVal> OpaqueVal::Unserialize(const broker::data& data)
return val; return val;
} }
broker::expected<broker::data> OpaqueVal::SerializeType(const zeek::IntrusivePtr<zeek::Type>& t) broker::expected<broker::data> OpaqueVal::SerializeType(const zeek::TypePtr& t)
{ {
if ( t->InternalType() == zeek::TYPE_INTERNAL_ERROR ) if ( t->InternalType() == zeek::TYPE_INTERNAL_ERROR )
return broker::ec::invalid_data; return broker::ec::invalid_data;
@ -112,7 +112,7 @@ broker::expected<broker::data> OpaqueVal::SerializeType(const zeek::IntrusivePtr
return {broker::vector{false, static_cast<uint64_t>(t->Tag())}}; return {broker::vector{false, static_cast<uint64_t>(t->Tag())}};
} }
zeek::IntrusivePtr<zeek::Type> OpaqueVal::UnserializeType(const broker::data& data) zeek::TypePtr OpaqueVal::UnserializeType(const broker::data& data)
{ {
auto v = caf::get_if<broker::vector>(&data); auto v = caf::get_if<broker::vector>(&data);
if ( ! (v && v->size() == 2) ) if ( ! (v && v->size() == 2) )
@ -145,7 +145,7 @@ zeek::IntrusivePtr<zeek::Type> OpaqueVal::UnserializeType(const broker::data& da
return zeek::base_type(static_cast<zeek::TypeTag>(*tag)); return zeek::base_type(static_cast<zeek::TypeTag>(*tag));
} }
zeek::IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state) ValPtr OpaqueVal::DoClone(CloneState* state)
{ {
auto d = OpaqueVal::Serialize(); auto d = OpaqueVal::Serialize();
if ( ! d ) if ( ! d )
@ -169,7 +169,7 @@ bool HashVal::Init()
return valid; return valid;
} }
zeek::IntrusivePtr<StringVal> HashVal::Get() StringValPtr HashVal::Get()
{ {
if ( ! valid ) if ( ! valid )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
@ -200,13 +200,13 @@ bool HashVal::DoFeed(const void*, size_t)
return false; return false;
} }
zeek::IntrusivePtr<StringVal> HashVal::DoGet() StringValPtr HashVal::DoGet()
{ {
assert(! "missing implementation of DoGet()"); assert(! "missing implementation of DoGet()");
return val_mgr->EmptyString(); return val_mgr->EmptyString();
} }
HashVal::HashVal(zeek::IntrusivePtr<zeek::OpaqueType> t) : OpaqueVal(std::move(t)) HashVal::HashVal(zeek::OpaqueTypePtr t) : OpaqueVal(std::move(t))
{ {
valid = false; 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<Val>& v) void HashVal::digest_one(EVP_MD_CTX* h, const ValPtr& v)
{ {
digest_one(h, v.get()); digest_one(h, v.get());
} }
zeek::IntrusivePtr<Val> MD5Val::DoClone(CloneState* state) ValPtr MD5Val::DoClone(CloneState* state)
{ {
auto out = zeek::make_intrusive<MD5Val>(); auto out = zeek::make_intrusive<MD5Val>();
@ -275,7 +275,7 @@ bool MD5Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
zeek::IntrusivePtr<StringVal> MD5Val::DoGet() StringValPtr MD5Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
@ -364,7 +364,7 @@ SHA1Val::~SHA1Val()
EVP_MD_CTX_free(ctx); EVP_MD_CTX_free(ctx);
} }
zeek::IntrusivePtr<Val> SHA1Val::DoClone(CloneState* state) ValPtr SHA1Val::DoClone(CloneState* state)
{ {
auto out = zeek::make_intrusive<SHA1Val>(); auto out = zeek::make_intrusive<SHA1Val>();
@ -395,7 +395,7 @@ bool SHA1Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
zeek::IntrusivePtr<StringVal> SHA1Val::DoGet() StringValPtr SHA1Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
@ -487,7 +487,7 @@ SHA256Val::~SHA256Val()
EVP_MD_CTX_free(ctx); EVP_MD_CTX_free(ctx);
} }
zeek::IntrusivePtr<Val> SHA256Val::DoClone(CloneState* state) ValPtr SHA256Val::DoClone(CloneState* state)
{ {
auto out = zeek::make_intrusive<SHA256Val>(); auto out = zeek::make_intrusive<SHA256Val>();
@ -518,7 +518,7 @@ bool SHA256Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
zeek::IntrusivePtr<StringVal> SHA256Val::DoGet() StringValPtr SHA256Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
@ -711,7 +711,7 @@ BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf)
bloom_filter = bf; bloom_filter = bf;
} }
zeek::IntrusivePtr<Val> BloomFilterVal::DoClone(CloneState* state) ValPtr BloomFilterVal::DoClone(CloneState* state)
{ {
if ( bloom_filter ) if ( bloom_filter )
{ {
@ -723,7 +723,7 @@ zeek::IntrusivePtr<Val> BloomFilterVal::DoClone(CloneState* state)
return state->NewClone(this, zeek::make_intrusive<BloomFilterVal>()); return state->NewClone(this, zeek::make_intrusive<BloomFilterVal>());
} }
bool BloomFilterVal::Typify(zeek::IntrusivePtr<zeek::Type> arg_type) bool BloomFilterVal::Typify(zeek::TypePtr arg_type)
{ {
if ( type ) if ( type )
return false; return false;
@ -765,8 +765,8 @@ std::string BloomFilterVal::InternalState() const
return bloom_filter->InternalState(); return bloom_filter->InternalState();
} }
zeek::IntrusivePtr<BloomFilterVal> BloomFilterVal::Merge(const BloomFilterVal* x, BloomFilterValPtr BloomFilterVal::Merge(const BloomFilterVal* x,
const BloomFilterVal* y) const BloomFilterVal* y)
{ {
if ( x->Type() && // any one 0 is ok here if ( x->Type() && // any one 0 is ok here
y->Type() && y->Type() &&
@ -876,13 +876,13 @@ CardinalityVal::~CardinalityVal()
delete hash; delete hash;
} }
zeek::IntrusivePtr<Val> CardinalityVal::DoClone(CloneState* state) ValPtr CardinalityVal::DoClone(CloneState* state)
{ {
return state->NewClone(this, return state->NewClone(this,
zeek::make_intrusive<CardinalityVal>(new probabilistic::CardinalityCounter(*c))); zeek::make_intrusive<CardinalityVal>(new probabilistic::CardinalityCounter(*c)));
} }
bool CardinalityVal::Typify(zeek::IntrusivePtr<zeek::Type> arg_type) bool CardinalityVal::Typify(zeek::TypePtr arg_type)
{ {
if ( type ) if ( type )
return false; return false;
@ -957,7 +957,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr<paraglob::Paraglob> p)
this->internal_paraglob = std::move(p); this->internal_paraglob = std::move(p);
} }
zeek::IntrusivePtr<VectorVal> ParaglobVal::Get(StringVal* &pattern) VectorValPtr ParaglobVal::Get(StringVal* &pattern)
{ {
auto rval = zeek::make_intrusive<VectorVal>(zeek::id::string_vec); auto rval = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
std::string string_pattern (reinterpret_cast<const char*>(pattern->Bytes()), pattern->Len()); std::string string_pattern (reinterpret_cast<const char*>(pattern->Bytes()), pattern->Len());
@ -1018,7 +1018,7 @@ bool ParaglobVal::DoUnserialize(const broker::data& data)
return true; return true;
} }
zeek::IntrusivePtr<Val> ParaglobVal::DoClone(CloneState* state) ValPtr ParaglobVal::DoClone(CloneState* state)
{ {
try { try {
return zeek::make_intrusive<ParaglobVal> return zeek::make_intrusive<ParaglobVal>

View file

@ -13,7 +13,12 @@
#include <sys/types.h> // for u_char #include <sys/types.h> // for u_char
namespace broker { class data; } namespace broker { class data; }
class OpaqueVal; class OpaqueVal;
using OpaqueValPtr = zeek::IntrusivePtr<OpaqueVal>;
class BloomFilterVal;
using BloomFilterValPtr = zeek::IntrusivePtr<BloomFilterVal>;
/** /**
* Singleton that registers all available all available types of opaque * Singleton that registers all available all available types of opaque
@ -21,7 +26,7 @@ class OpaqueVal;
*/ */
class OpaqueMgr { class OpaqueMgr {
public: public:
using Factory = zeek::IntrusivePtr<OpaqueVal> (); using Factory = OpaqueValPtr ();
/** /**
* Return's a unique ID for the type of an opaque value. * Return's a unique ID for the type of an opaque value.
@ -45,7 +50,7 @@ public:
* is unknown, this will return null. * is unknown, this will return null.
* *
*/ */
zeek::IntrusivePtr<OpaqueVal> Instantiate(const std::string& id) const; OpaqueValPtr Instantiate(const std::string& id) const;
/** Returns the global manager singleton object. */ /** Returns the global manager singleton object. */
static OpaqueMgr* mgr(); static OpaqueMgr* mgr();
@ -72,7 +77,7 @@ private:
broker::expected<broker::data> DoSerialize() const override; \ broker::expected<broker::data> DoSerialize() const override; \
bool DoUnserialize(const broker::data& data) override; \ bool DoUnserialize(const broker::data& data) override; \
const char* OpaqueName() const override { return #T; } \ const char* OpaqueName() const override { return #T; } \
static zeek::IntrusivePtr<OpaqueVal> OpaqueInstantiate() { return zeek::make_intrusive<T>(); } static OpaqueValPtr OpaqueInstantiate() { return zeek::make_intrusive<T>(); }
#define __OPAQUE_MERGE(a, b) a ## b #define __OPAQUE_MERGE(a, b) a ## b
#define __OPAQUE_ID(x) __OPAQUE_MERGE(_opaque, x) #define __OPAQUE_ID(x) __OPAQUE_MERGE(_opaque, x)
@ -89,7 +94,7 @@ class OpaqueVal : public Val {
public: public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit OpaqueVal(zeek::OpaqueType* t); explicit OpaqueVal(zeek::OpaqueType* t);
explicit OpaqueVal(zeek::IntrusivePtr<zeek::OpaqueType> t); explicit OpaqueVal(zeek::OpaqueTypePtr t);
~OpaqueVal() override; ~OpaqueVal() override;
/** /**
@ -106,7 +111,7 @@ public:
* @param data Broker representation as returned by *Serialize()*. * @param data Broker representation as returned by *Serialize()*.
* @return unserialized instances with reference count at +1 * @return unserialized instances with reference count at +1
*/ */
static zeek::IntrusivePtr<OpaqueVal> Unserialize(const broker::data& data); static OpaqueValPtr Unserialize(const broker::data& data);
protected: protected:
friend class Val; friend class Val;
@ -142,19 +147,19 @@ protected:
* may also override this with a more efficient custom clone * may also override this with a more efficient custom clone
* implementation of their own. * implementation of their own.
*/ */
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
/** /**
* Helper function for derived class that need to record a type * Helper function for derived class that need to record a type
* during serialization. * during serialization.
*/ */
static broker::expected<broker::data> SerializeType(const zeek::IntrusivePtr<zeek::Type>& t); static broker::expected<broker::data> SerializeType(const zeek::TypePtr& t);
/** /**
* Helper function for derived class that need to restore a type * Helper function for derived class that need to restore a type
* during unserialization. Returns the type at reference count +1. * during unserialization. Returns the type at reference count +1.
*/ */
static zeek::IntrusivePtr<zeek::Type> UnserializeType(const broker::data& data); static zeek::TypePtr UnserializeType(const broker::data& data);
}; };
namespace probabilistic { namespace probabilistic {
@ -178,21 +183,21 @@ public:
bool IsValid() const; bool IsValid() const;
bool Init(); bool Init();
bool Feed(const void* data, size_t size); bool Feed(const void* data, size_t size);
zeek::IntrusivePtr<StringVal> Get(); StringValPtr Get();
protected: protected:
static void digest_one(EVP_MD_CTX* h, const Val* v); static void digest_one(EVP_MD_CTX* h, const Val* v);
static void digest_one(EVP_MD_CTX* h, const zeek::IntrusivePtr<Val>& v); static void digest_one(EVP_MD_CTX* h, const ValPtr& v);
HashVal() { valid = false; } HashVal() { valid = false; }
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit HashVal(zeek::OpaqueType* t); explicit HashVal(zeek::OpaqueType* t);
explicit HashVal(zeek::IntrusivePtr<zeek::OpaqueType> t); explicit HashVal(zeek::OpaqueTypePtr t);
virtual bool DoInit(); virtual bool DoInit();
virtual bool DoFeed(const void* data, size_t size); virtual bool DoFeed(const void* data, size_t size);
virtual zeek::IntrusivePtr<StringVal> DoGet(); virtual StringValPtr DoGet();
private: private:
// This flag exists because Get() can only be called once. // This flag exists because Get() can only be called once.
@ -221,14 +226,14 @@ public:
MD5Val(); MD5Val();
~MD5Val(); ~MD5Val();
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
protected: protected:
friend class Val; friend class Val;
bool DoInit() override; bool DoInit() override;
bool DoFeed(const void* data, size_t size) override; bool DoFeed(const void* data, size_t size) override;
zeek::IntrusivePtr<StringVal> DoGet() override; StringValPtr DoGet() override;
DECLARE_OPAQUE_VALUE(MD5Val) DECLARE_OPAQUE_VALUE(MD5Val)
private: private:
@ -244,14 +249,14 @@ public:
SHA1Val(); SHA1Val();
~SHA1Val(); ~SHA1Val();
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
protected: protected:
friend class Val; friend class Val;
bool DoInit() override; bool DoInit() override;
bool DoFeed(const void* data, size_t size) override; bool DoFeed(const void* data, size_t size) override;
zeek::IntrusivePtr<StringVal> DoGet() override; StringValPtr DoGet() override;
DECLARE_OPAQUE_VALUE(SHA1Val) DECLARE_OPAQUE_VALUE(SHA1Val)
private: private:
@ -267,14 +272,14 @@ public:
SHA256Val(); SHA256Val();
~SHA256Val(); ~SHA256Val();
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
protected: protected:
friend class Val; friend class Val;
bool DoInit() override; bool DoInit() override;
bool DoFeed(const void* data, size_t size) override; bool DoFeed(const void* data, size_t size) override;
zeek::IntrusivePtr<StringVal> DoGet() override; StringValPtr DoGet() override;
DECLARE_OPAQUE_VALUE(SHA256Val) DECLARE_OPAQUE_VALUE(SHA256Val)
private: private:
@ -302,12 +307,12 @@ public:
explicit BloomFilterVal(probabilistic::BloomFilter* bf); explicit BloomFilterVal(probabilistic::BloomFilter* bf);
~BloomFilterVal() override; ~BloomFilterVal() override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
const zeek::IntrusivePtr<zeek::Type>& Type() const const zeek::TypePtr& Type() const
{ return type; } { return type; }
bool Typify(zeek::IntrusivePtr<zeek::Type> type); bool Typify(zeek::TypePtr type);
void Add(const Val* val); void Add(const Val* val);
size_t Count(const Val* val) const; size_t Count(const Val* val) const;
@ -315,8 +320,8 @@ public:
bool Empty() const; bool Empty() const;
std::string InternalState() const; std::string InternalState() const;
static zeek::IntrusivePtr<BloomFilterVal> Merge(const BloomFilterVal* x, static BloomFilterValPtr Merge(const BloomFilterVal* x,
const BloomFilterVal* y); const BloomFilterVal* y);
protected: protected:
friend class Val; friend class Val;
@ -328,7 +333,7 @@ private:
BloomFilterVal(const BloomFilterVal&); BloomFilterVal(const BloomFilterVal&);
BloomFilterVal& operator=(const BloomFilterVal&); BloomFilterVal& operator=(const BloomFilterVal&);
zeek::IntrusivePtr<zeek::Type> type; zeek::TypePtr type;
CompositeHash* hash; CompositeHash* hash;
probabilistic::BloomFilter* bloom_filter; probabilistic::BloomFilter* bloom_filter;
}; };
@ -339,14 +344,14 @@ public:
explicit CardinalityVal(probabilistic::CardinalityCounter*); explicit CardinalityVal(probabilistic::CardinalityCounter*);
~CardinalityVal() override; ~CardinalityVal() override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
void Add(const Val* val); void Add(const Val* val);
const zeek::IntrusivePtr<zeek::Type>& Type() const const zeek::TypePtr& Type() const
{ return type; } { return type; }
bool Typify(zeek::IntrusivePtr<zeek::Type> type); bool Typify(zeek::TypePtr type);
probabilistic::CardinalityCounter* Get() { return c; }; probabilistic::CardinalityCounter* Get() { return c; };
@ -355,7 +360,7 @@ protected:
DECLARE_OPAQUE_VALUE(CardinalityVal) DECLARE_OPAQUE_VALUE(CardinalityVal)
private: private:
zeek::IntrusivePtr<zeek::Type> type; zeek::TypePtr type;
CompositeHash* hash; CompositeHash* hash;
probabilistic::CardinalityCounter* c; probabilistic::CardinalityCounter* c;
}; };
@ -363,8 +368,8 @@ private:
class ParaglobVal : public OpaqueVal { class ParaglobVal : public OpaqueVal {
public: public:
explicit ParaglobVal(std::unique_ptr<paraglob::Paraglob> p); explicit ParaglobVal(std::unique_ptr<paraglob::Paraglob> p);
zeek::IntrusivePtr<VectorVal> Get(StringVal* &pattern); VectorValPtr Get(StringVal* &pattern);
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
bool operator==(const ParaglobVal& other) const; bool operator==(const ParaglobVal& other) const;
protected: protected:

View file

@ -417,7 +417,7 @@ void Reporter::Weird(Connection* conn, const char* name, const char* addl)
"%s", name); "%s", name);
} }
void Reporter::Weird(zeek::IntrusivePtr<RecordVal> conn_id, zeek::IntrusivePtr<StringVal> uid, void Reporter::Weird(RecordValPtr conn_id, StringValPtr uid,
const char* name, const char* addl) const char* name, const char* addl)
{ {
UpdateWeirdStats(name); UpdateWeirdStats(name);

View file

@ -28,6 +28,9 @@ namespace zeek {
template <class T> class IntrusivePtr; template <class T> class IntrusivePtr;
} }
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
using StringValPtr = zeek::IntrusivePtr<StringVal>;
// One cannot raise this exception directly, go through the // One cannot raise this exception directly, go through the
// Reporter's methods instead. // Reporter's methods instead.
@ -99,7 +102,7 @@ public:
void Weird(const char* name, const char* addl = ""); // Raises net_weird(). 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(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(Connection* conn, const char* name, const char* addl = ""); // Raises conn_weird().
void Weird(zeek::IntrusivePtr<RecordVal> conn_id, zeek::IntrusivePtr<StringVal> uid, void Weird(RecordValPtr conn_id, StringValPtr uid,
const char* name, const char* addl = ""); // Raises expired_conn_weird(). 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(). void Weird(const IPAddr& orig, const IPAddr& resp, const char* name, const char* addl = ""); // Raises flow_weird().

View file

@ -15,8 +15,8 @@ typedef PList<Scope> scope_list;
static scope_list scopes; static scope_list scopes;
static Scope* top_scope; static Scope* top_scope;
Scope::Scope(zeek::IntrusivePtr<zeek::detail::ID> id, Scope::Scope(zeek::detail::IDPtr id,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> al) std::unique_ptr<std::vector<zeek::detail::AttrPtr>> al)
: scope_id(std::move(id)), attrs(std::move(al)) : scope_id(std::move(id)), attrs(std::move(al))
{ {
return_type = nullptr; return_type = nullptr;
@ -35,7 +35,7 @@ Scope::Scope(zeek::IntrusivePtr<zeek::detail::ID> id,
} }
} }
const zeek::IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) const const zeek::detail::IDPtr& Scope::Find(std::string_view name) const
{ {
auto entry = local.find(name); auto entry = local.find(name);
@ -45,7 +45,7 @@ const zeek::IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) c
return zeek::detail::ID::nil; return zeek::detail::ID::nil;
} }
zeek::IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name) zeek::detail::IDPtr Scope::Remove(std::string_view name)
{ {
auto entry = local.find(name); auto entry = local.find(name);
@ -59,12 +59,12 @@ zeek::IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name)
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<zeek::detail::ID> Scope::GenerateTemporary(const char* name) zeek::detail::IDPtr Scope::GenerateTemporary(const char* name)
{ {
return zeek::make_intrusive<zeek::detail::ID>(name, zeek::detail::SCOPE_FUNCTION, false); return zeek::make_intrusive<zeek::detail::ID>(name, zeek::detail::SCOPE_FUNCTION, false);
} }
std::vector<zeek::IntrusivePtr<zeek::detail::ID>> Scope::GetInits() std::vector<zeek::detail::IDPtr> Scope::GetInits()
{ {
auto rval = std::move(inits); auto rval = std::move(inits);
inits = {}; inits = {};
@ -119,7 +119,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
} }
const zeek::IntrusivePtr<zeek::detail::ID>& lookup_ID( const zeek::detail::IDPtr& lookup_ID(
const char* name, const char* curr_module, const char* name, const char* curr_module,
bool no_global, bool same_module_only, bool no_global, bool same_module_only,
bool check_export) bool check_export)
@ -154,7 +154,7 @@ const zeek::IntrusivePtr<zeek::detail::ID>& lookup_ID(
return zeek::detail::ID::nil; return zeek::detail::ID::nil;
} }
zeek::IntrusivePtr<zeek::detail::ID> install_ID( zeek::detail::IDPtr install_ID(
const char* name, const char* module_name, const char* name, const char* module_name,
bool is_global, bool is_export) bool is_global, bool is_export)
{ {
@ -191,14 +191,14 @@ void push_existing_scope(Scope* scope)
scopes.push_back(scope); scopes.push_back(scope);
} }
void push_scope(zeek::IntrusivePtr<zeek::detail::ID> id, void push_scope(zeek::detail::IDPtr id,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs) std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attrs)
{ {
top_scope = new Scope(std::move(id), std::move(attrs)); top_scope = new Scope(std::move(id), std::move(attrs));
scopes.push_back(top_scope); scopes.push_back(top_scope);
} }
zeek::IntrusivePtr<Scope> pop_scope() ScopePtr pop_scope()
{ {
if ( scopes.empty() ) if ( scopes.empty() )
reporter->InternalError("scope underflow"); reporter->InternalError("scope underflow");

View file

@ -13,18 +13,29 @@
#include "TraverseTypes.h" #include "TraverseTypes.h"
template <class T> class IntrusivePtr; template <class T> class IntrusivePtr;
class ListVal;
namespace zeek { class Type; } namespace zeek {
class Type;
using TypePtr = zeek::IntrusivePtr<zeek::Type>;
}
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
namespace zeek::detail {
class Attr;
using AttrPtr = zeek::IntrusivePtr<Attr>;
using IDPtr = zeek::IntrusivePtr<ID>;
}
class Scope;
using ScopePtr = zeek::IntrusivePtr<Scope>;
class Scope : public BroObj { class Scope : public BroObj {
public: public:
explicit Scope(zeek::IntrusivePtr<zeek::detail::ID> id, explicit Scope(zeek::detail::IDPtr id,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> al); std::unique_ptr<std::vector<zeek::detail::AttrPtr>> al);
const zeek::IntrusivePtr<zeek::detail::ID>& Find(std::string_view name) const; const zeek::detail::IDPtr& Find(std::string_view name) const;
template<typename N> template<typename N>
[[deprecated("Remove in v4.1. Use Find().")]] [[deprecated("Remove in v4.1. Use Find().")]]
@ -34,34 +45,34 @@ public:
template<typename N, typename I> template<typename N, typename I>
void Insert(N&& name, I&& id) { local[std::forward<N>(name)] = std::forward<I>(id); } void Insert(N&& name, I&& id) { local[std::forward<N>(name)] = std::forward<I>(id); }
zeek::IntrusivePtr<zeek::detail::ID> Remove(std::string_view name); zeek::detail::IDPtr Remove(std::string_view name);
[[deprecated("Remove in v4.1. Use GetID().")]] [[deprecated("Remove in v4.1. Use GetID().")]]
zeek::detail::ID* ScopeID() const { return scope_id.get(); } zeek::detail::ID* ScopeID() const { return scope_id.get(); }
const zeek::IntrusivePtr<zeek::detail::ID>& GetID() const const zeek::detail::IDPtr& GetID() const
{ return scope_id; } { return scope_id; }
const std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>>& Attrs() const const std::unique_ptr<std::vector<zeek::detail::AttrPtr>>& Attrs() const
{ return attrs; } { return attrs; }
[[deprecated("Remove in v4.1. Use GetReturnTrype().")]] [[deprecated("Remove in v4.1. Use GetReturnTrype().")]]
zeek::Type* ReturnType() const { return return_type.get(); } zeek::Type* ReturnType() const { return return_type.get(); }
const zeek::IntrusivePtr<zeek::Type>& GetReturnType() const const zeek::TypePtr& GetReturnType() const
{ return return_type; } { return return_type; }
size_t Length() const { return local.size(); } size_t Length() const { return local.size(); }
const auto& Vars() { return local; } const auto& Vars() { return local; }
zeek::IntrusivePtr<zeek::detail::ID> GenerateTemporary(const char* name); zeek::detail::IDPtr GenerateTemporary(const char* name);
// Returns the list of variables needing initialization, and // Returns the list of variables needing initialization, and
// removes it from this Scope. // removes it from this Scope.
std::vector<zeek::IntrusivePtr<zeek::detail::ID>> GetInits(); std::vector<zeek::detail::IDPtr> GetInits();
// Adds a variable to the list. // Adds a variable to the list.
void AddInit(zeek::IntrusivePtr<zeek::detail::ID> id) void AddInit(zeek::detail::IDPtr id)
{ inits.emplace_back(std::move(id)); } { inits.emplace_back(std::move(id)); }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -69,33 +80,33 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const; TraversalCode Traverse(TraversalCallback* cb) const;
protected: protected:
zeek::IntrusivePtr<zeek::detail::ID> scope_id; zeek::detail::IDPtr scope_id;
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs; std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attrs;
zeek::IntrusivePtr<zeek::Type> return_type; zeek::TypePtr return_type;
std::map<std::string, zeek::IntrusivePtr<zeek::detail::ID>, std::less<>> local; std::map<std::string, zeek::detail::IDPtr, std::less<>> local;
std::vector<zeek::IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::detail::IDPtr> inits;
}; };
extern bool in_debug; extern bool in_debug;
// If no_global is true, don't search in the default "global" namespace. // If no_global is true, don't search in the default "global" namespace.
extern const zeek::IntrusivePtr<zeek::detail::ID>& lookup_ID( extern const zeek::detail::IDPtr& lookup_ID(
const char* name, const char* module, const char* name, const char* module,
bool no_global = false, bool no_global = false,
bool same_module_only = false, bool same_module_only = false,
bool check_export = true); bool check_export = true);
extern zeek::IntrusivePtr<zeek::detail::ID> install_ID( extern zeek::detail::IDPtr install_ID(
const char* name, const char* module_name, const char* name, const char* module_name,
bool is_global, bool is_export); bool is_global, bool is_export);
extern void push_scope(zeek::IntrusivePtr<zeek::detail::ID> id, extern void push_scope(zeek::detail::IDPtr id,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs); std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attrs);
extern void push_existing_scope(Scope* scope); extern void push_existing_scope(Scope* scope);
// Returns the one popped off. // Returns the one popped off.
extern zeek::IntrusivePtr<Scope> pop_scope(); extern ScopePtr pop_scope();
extern Scope* current_scope(); extern Scope* current_scope();
extern Scope* global_scope(); extern Scope* global_scope();

View file

@ -703,7 +703,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr
conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel());
zeek::IntrusivePtr<Val> pkt_hdr_val; ValPtr pkt_hdr_val;
if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 ) if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 )
{ {

View file

@ -133,7 +133,7 @@ void Stmt::AccessStats(ODesc* d) const
} }
} }
ExprListStmt::ExprListStmt(BroStmtTag t, zeek::IntrusivePtr<ListExpr> arg_l) ExprListStmt::ExprListStmt(BroStmtTag t, ListExprPtr arg_l)
: Stmt(t), l(std::move(arg_l)) : Stmt(t), l(std::move(arg_l))
{ {
const expr_list& e = l->Exprs(); const expr_list& e = l->Exprs();
@ -149,7 +149,7 @@ ExprListStmt::ExprListStmt(BroStmtTag t, zeek::IntrusivePtr<ListExpr> arg_l)
ExprListStmt::~ExprListStmt() = default; ExprListStmt::~ExprListStmt() = default;
zeek::IntrusivePtr<Val> ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
last_access = network_time; last_access = network_time;
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -187,7 +187,7 @@ TraversalCode ExprListStmt::Traverse(TraversalCallback* cb) const
static BroFile* print_stdout = nullptr; static BroFile* print_stdout = nullptr;
static zeek::IntrusivePtr<EnumVal> 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); const auto& id = lookup_ID(name, module_name);
assert(id); assert(id);
@ -201,7 +201,7 @@ static zeek::IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, cons
return et->GetVal(index); return et->GetVal(index);
} }
static void print_log(const std::vector<zeek::IntrusivePtr<Val>>& vals) static void print_log(const std::vector<ValPtr>& vals)
{ {
static auto plval = lookup_enum_val("Log", "PRINTLOG"); static auto plval = lookup_enum_val("Log", "PRINTLOG");
static auto lpli = zeek::id::find_type<RecordType>("Log::PrintLogInfo"); static auto lpli = zeek::id::find_type<RecordType>("Log::PrintLogInfo");
@ -220,8 +220,8 @@ static void print_log(const std::vector<zeek::IntrusivePtr<Val>>& vals)
log_mgr->Write(plval.get(), record.get()); log_mgr->Write(plval.get(), record.get());
} }
zeek::IntrusivePtr<Val> PrintStmt::DoExec(std::vector<zeek::IntrusivePtr<Val>> vals, ValPtr PrintStmt::DoExec(std::vector<ValPtr> vals,
stmt_flow_type& /* flow */) const stmt_flow_type& /* flow */) const
{ {
RegisterAccess(); RegisterAccess();
@ -290,7 +290,7 @@ zeek::IntrusivePtr<Val> PrintStmt::DoExec(std::vector<zeek::IntrusivePtr<Val>> v
return nullptr; return nullptr;
} }
ExprStmt::ExprStmt(zeek::IntrusivePtr<Expr> 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() ) if ( e && e->IsPure() )
Warn("expression value ignored"); Warn("expression value ignored");
@ -298,7 +298,7 @@ ExprStmt::ExprStmt(zeek::IntrusivePtr<Expr> arg_e) : Stmt(STMT_EXPR), e(std::mov
SetLocationInfo(e->GetLocationInfo()); SetLocationInfo(e->GetLocationInfo());
} }
ExprStmt::ExprStmt(BroStmtTag t, zeek::IntrusivePtr<Expr> 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 ) if ( e )
SetLocationInfo(e->GetLocationInfo()); SetLocationInfo(e->GetLocationInfo());
@ -306,7 +306,7 @@ ExprStmt::ExprStmt(BroStmtTag t, zeek::IntrusivePtr<Expr> arg_e) : Stmt(t), e(st
ExprStmt::~ExprStmt() = default; ExprStmt::~ExprStmt() = default;
zeek::IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -319,7 +319,7 @@ zeek::IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<Val> 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; return nullptr;
} }
@ -365,9 +365,9 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IfStmt::IfStmt(zeek::IntrusivePtr<Expr> test, IfStmt::IfStmt(ExprPtr test,
zeek::IntrusivePtr<Stmt> arg_s1, StmtPtr arg_s1,
zeek::IntrusivePtr<Stmt> arg_s2) StmtPtr arg_s2)
: ExprStmt(STMT_IF, std::move(test)), : ExprStmt(STMT_IF, std::move(test)),
s1(std::move(arg_s1)), s2(std::move(arg_s2)) s1(std::move(arg_s1)), s2(std::move(arg_s2))
{ {
@ -381,7 +381,7 @@ IfStmt::IfStmt(zeek::IntrusivePtr<Expr> test,
IfStmt::~IfStmt() = default; IfStmt::~IfStmt() = default;
zeek::IntrusivePtr<Val> 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. // Treat 0 as false, but don't require 1 for true.
Stmt* do_stmt = v->IsZero() ? s2.get() : s1.get(); 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]); return get_last_stmt_tag(stmts->Stmts()[len - 1]);
} }
Case::Case(zeek::IntrusivePtr<ListExpr> arg_expr_cases, id_list* arg_type_cases, Case::Case(ListExprPtr arg_expr_cases, id_list* arg_type_cases,
zeek::IntrusivePtr<Stmt> arg_s) StmtPtr arg_s)
: expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases), : expr_cases(std::move(arg_expr_cases)), type_cases(arg_type_cases),
s(std::move(arg_s)) s(std::move(arg_s))
{ {
@ -591,7 +591,7 @@ void SwitchStmt::Init()
case_label_value_map.SetDeleteFunc(int_del_func); case_label_value_map.SetDeleteFunc(int_del_func);
} }
SwitchStmt::SwitchStmt(zeek::IntrusivePtr<Expr> index, case_list* arg_cases) SwitchStmt::SwitchStmt(ExprPtr index, case_list* arg_cases)
: ExprStmt(STMT_SWITCH, std::move(index)), : ExprStmt(STMT_SWITCH, std::move(index)),
cases(arg_cases), default_case_idx(-1) cases(arg_cases), default_case_idx(-1)
{ {
@ -797,9 +797,9 @@ std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const
return std::make_pair(label_idx, label_id); return std::make_pair(label_idx, label_id);
} }
zeek::IntrusivePtr<Val> 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<Val> rval; ValPtr rval;
auto m = FindCaseLabelMatch(v); auto m = FindCaseLabelMatch(v);
int matching_label_idx = m.first; int matching_label_idx = m.first;
@ -882,7 +882,7 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
AddStmt::AddStmt(zeek::IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_ADD, std::move(arg_e)) AddStmt::AddStmt(ExprPtr arg_e) : ExprStmt(STMT_ADD, std::move(arg_e))
{ {
if ( ! e->CanAdd() ) if ( ! e->CanAdd() )
Error("illegal add statement"); Error("illegal add statement");
@ -893,7 +893,7 @@ bool AddStmt::IsPure() const
return false; return false;
} }
zeek::IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr AddStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -915,7 +915,7 @@ TraversalCode AddStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
DelStmt::DelStmt(zeek::IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e)) DelStmt::DelStmt(ExprPtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e))
{ {
if ( e->IsError() ) if ( e->IsError() )
return; return;
@ -929,7 +929,7 @@ bool DelStmt::IsPure() const
return false; return false;
} }
zeek::IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr DelStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -950,12 +950,12 @@ TraversalCode DelStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
EventStmt::EventStmt(zeek::IntrusivePtr<EventExpr> arg_e) EventStmt::EventStmt(EventExprPtr arg_e)
: ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e)) : ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
{ {
} }
zeek::IntrusivePtr<Val> EventStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr EventStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
auto args = eval_list(f, event_expr->Args()); auto args = eval_list(f, event_expr->Args());
@ -981,8 +981,8 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
WhileStmt::WhileStmt(zeek::IntrusivePtr<Expr> arg_loop_condition, WhileStmt::WhileStmt(ExprPtr arg_loop_condition,
zeek::IntrusivePtr<Stmt> arg_body) StmtPtr arg_body)
: loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body)) : loop_condition(std::move(arg_loop_condition)), body(std::move(arg_body))
{ {
if ( ! loop_condition->IsError() && if ( ! loop_condition->IsError() &&
@ -1031,11 +1031,11 @@ TraversalCode WhileStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
zeek::IntrusivePtr<Val> rval; ValPtr rval;
for ( ; ; ) for ( ; ; )
{ {
@ -1060,7 +1060,7 @@ zeek::IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
return rval; return rval;
} }
ForStmt::ForStmt(id_list* arg_loop_vars, zeek::IntrusivePtr<Expr> loop_expr) ForStmt::ForStmt(id_list* arg_loop_vars, ExprPtr loop_expr)
: ExprStmt(STMT_FOR, std::move(loop_expr)) : ExprStmt(STMT_FOR, std::move(loop_expr))
{ {
loop_vars = arg_loop_vars; loop_vars = arg_loop_vars;
@ -1143,7 +1143,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, zeek::IntrusivePtr<Expr> loop_expr)
} }
ForStmt::ForStmt(id_list* arg_loop_vars, ForStmt::ForStmt(id_list* arg_loop_vars,
zeek::IntrusivePtr<Expr> loop_expr, zeek::IntrusivePtr<ID> val_var) ExprPtr loop_expr, IDPtr val_var)
: ForStmt(arg_loop_vars, std::move(loop_expr)) : ForStmt(arg_loop_vars, std::move(loop_expr))
{ {
value_var = std::move(val_var); value_var = std::move(val_var);
@ -1174,9 +1174,9 @@ ForStmt::~ForStmt()
delete loop_vars; delete loop_vars;
} }
zeek::IntrusivePtr<Val> 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<Val> ret; ValPtr ret;
if ( v->GetType()->Tag() == TYPE_TABLE ) if ( v->GetType()->Tag() == TYPE_TABLE )
{ {
@ -1332,7 +1332,7 @@ TraversalCode ForStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const ValPtr NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_LOOP; flow = FLOW_LOOP;
@ -1359,7 +1359,7 @@ TraversalCode NextStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const ValPtr BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_BREAK; flow = FLOW_BREAK;
@ -1386,7 +1386,7 @@ TraversalCode BreakStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const ValPtr FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_FALLTHROUGH; flow = FLOW_FALLTHROUGH;
@ -1413,7 +1413,7 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
ReturnStmt::ReturnStmt(zeek::IntrusivePtr<Expr> arg_e) ReturnStmt::ReturnStmt(ExprPtr arg_e)
: ExprStmt(STMT_RETURN, std::move(arg_e)) : ExprStmt(STMT_RETURN, std::move(arg_e))
{ {
Scope* s = current_scope(); Scope* s = current_scope();
@ -1457,7 +1457,7 @@ ReturnStmt::ReturnStmt(zeek::IntrusivePtr<Expr> arg_e)
} }
} }
zeek::IntrusivePtr<Val> ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_RETURN; flow = FLOW_RETURN;
@ -1496,7 +1496,7 @@ StmtList::~StmtList()
Unref(stmt); Unref(stmt);
} }
zeek::IntrusivePtr<Val> StmtList::Exec(Frame* f, stmt_flow_type& flow) const ValPtr StmtList::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1575,7 +1575,7 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const ValPtr EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1633,7 +1633,7 @@ void EventBodyList::Describe(ODesc* d) const
StmtList::Describe(d); StmtList::Describe(d);
} }
InitStmt::InitStmt(std::vector<zeek::IntrusivePtr<ID>> arg_inits) : Stmt(STMT_INIT) InitStmt::InitStmt(std::vector<IDPtr> arg_inits) : Stmt(STMT_INIT)
{ {
inits = std::move(arg_inits); inits = std::move(arg_inits);
@ -1641,7 +1641,7 @@ InitStmt::InitStmt(std::vector<zeek::IntrusivePtr<ID>> arg_inits) : Stmt(STMT_IN
SetLocationInfo(inits[0]->GetLocationInfo()); SetLocationInfo(inits[0]->GetLocationInfo());
} }
zeek::IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1650,7 +1650,7 @@ zeek::IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
const auto& t = aggr->GetType(); const auto& t = aggr->GetType();
zeek::IntrusivePtr<Val> v; ValPtr v;
switch ( t->Tag() ) { switch ( t->Tag() ) {
case TYPE_RECORD: case TYPE_RECORD:
@ -1706,7 +1706,7 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
zeek::IntrusivePtr<Val> NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const ValPtr NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1735,9 +1735,9 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
WhenStmt::WhenStmt(zeek::IntrusivePtr<Expr> arg_cond, WhenStmt::WhenStmt(ExprPtr arg_cond,
zeek::IntrusivePtr<Stmt> arg_s1, zeek::IntrusivePtr<Stmt> arg_s2, StmtPtr arg_s1, StmtPtr arg_s2,
zeek::IntrusivePtr<Expr> arg_timeout, bool arg_is_return) ExprPtr arg_timeout, bool arg_is_return)
: Stmt(STMT_WHEN), : Stmt(STMT_WHEN),
cond(std::move(arg_cond)), s1(std::move(arg_s1)), s2(std::move(arg_s2)), 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) timeout(std::move(arg_timeout)), is_return(arg_is_return)
@ -1761,7 +1761,7 @@ WhenStmt::WhenStmt(zeek::IntrusivePtr<Expr> arg_cond,
WhenStmt::~WhenStmt() = default; WhenStmt::~WhenStmt() = default;
zeek::IntrusivePtr<Val> WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const ValPtr WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;

View file

@ -23,13 +23,19 @@ class ForStmt;
class EventExpr; class EventExpr;
class ListExpr; class ListExpr;
using EventExprPtr = zeek::IntrusivePtr<EventExpr>;
using ListExprPtr = zeek::IntrusivePtr<ListExpr>;
class Stmt;
using StmtPtr = zeek::IntrusivePtr<Stmt>;
class Stmt : public BroObj { class Stmt : public BroObj {
public: public:
BroStmtTag Tag() const { return tag; } BroStmtTag Tag() const { return tag; }
~Stmt() override; ~Stmt() override;
virtual zeek::IntrusivePtr<Val> 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; } Stmt* Ref() { ::Ref(this); return this; }
@ -93,17 +99,17 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
ExprListStmt(BroStmtTag t, zeek::IntrusivePtr<ListExpr> arg_l); ExprListStmt(BroStmtTag t, ListExprPtr arg_l);
~ExprListStmt() override; ~ExprListStmt() override;
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
virtual zeek::IntrusivePtr<Val> DoExec(std::vector<zeek::IntrusivePtr<Val>> vals, virtual ValPtr DoExec(std::vector<ValPtr> vals,
stmt_flow_type& flow) const = 0; stmt_flow_type& flow) const = 0;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
zeek::IntrusivePtr<ListExpr> l; ListExprPtr l;
}; };
class PrintStmt final : public ExprListStmt { class PrintStmt final : public ExprListStmt {
@ -112,16 +118,16 @@ public:
explicit PrintStmt(L&& l) : ExprListStmt(STMT_PRINT, std::forward<L>(l)) { } explicit PrintStmt(L&& l) : ExprListStmt(STMT_PRINT, std::forward<L>(l)) { }
protected: protected:
zeek::IntrusivePtr<Val> DoExec(std::vector<zeek::IntrusivePtr<Val>> vals, ValPtr DoExec(std::vector<ValPtr> vals,
stmt_flow_type& flow) const override; stmt_flow_type& flow) const override;
}; };
class ExprStmt : public Stmt { class ExprStmt : public Stmt {
public: public:
explicit ExprStmt(zeek::IntrusivePtr<Expr> e); explicit ExprStmt(ExprPtr e);
~ExprStmt() override; ~ExprStmt() override;
zeek::IntrusivePtr<Val> 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(); } const Expr* StmtExpr() const { return e.get(); }
@ -130,18 +136,18 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
ExprStmt(BroStmtTag t, zeek::IntrusivePtr<Expr> e); ExprStmt(BroStmtTag t, ExprPtr e);
virtual zeek::IntrusivePtr<Val> 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; bool IsPure() const override;
zeek::IntrusivePtr<Expr> e; ExprPtr e;
}; };
class IfStmt final : public ExprStmt { class IfStmt final : public ExprStmt {
public: public:
IfStmt(zeek::IntrusivePtr<Expr> test, zeek::IntrusivePtr<Stmt> s1, zeek::IntrusivePtr<Stmt> s2); IfStmt(ExprPtr test, StmtPtr s1, StmtPtr s2);
~IfStmt() override; ~IfStmt() override;
const Stmt* TrueBranch() const { return s1.get(); } const Stmt* TrueBranch() const { return s1.get(); }
@ -152,16 +158,16 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Val> 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; bool IsPure() const override;
zeek::IntrusivePtr<Stmt> s1; StmtPtr s1;
zeek::IntrusivePtr<Stmt> s2; StmtPtr s2;
}; };
class Case final : public BroObj { class Case final : public BroObj {
public: public:
Case(zeek::IntrusivePtr<ListExpr> c, id_list* types, zeek::IntrusivePtr<Stmt> arg_s); Case(ListExprPtr c, id_list* types, StmtPtr arg_s);
~Case() override; ~Case() override;
const ListExpr* ExprCases() const { return expr_cases.get(); } const ListExpr* ExprCases() const { return expr_cases.get(); }
@ -178,16 +184,16 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const; TraversalCode Traverse(TraversalCallback* cb) const;
protected: protected:
zeek::IntrusivePtr<ListExpr> expr_cases; ListExprPtr expr_cases;
id_list* type_cases; id_list* type_cases;
zeek::IntrusivePtr<Stmt> s; StmtPtr s;
}; };
using case_list = PList<Case>; using case_list = PList<Case>;
class SwitchStmt final : public ExprStmt { class SwitchStmt final : public ExprStmt {
public: public:
SwitchStmt(zeek::IntrusivePtr<Expr> index, case_list* cases); SwitchStmt(ExprPtr index, case_list* cases);
~SwitchStmt() override; ~SwitchStmt() override;
const case_list* Cases() const { return cases; } const case_list* Cases() const { return cases; }
@ -197,7 +203,7 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Val> 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; bool IsPure() const override;
// Initialize composite hash and case label map. // Initialize composite hash and case label map.
@ -228,40 +234,40 @@ protected:
class AddStmt final : public ExprStmt { class AddStmt final : public ExprStmt {
public: public:
explicit AddStmt(zeek::IntrusivePtr<Expr> e); explicit AddStmt(ExprPtr e);
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> 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; TraversalCode Traverse(TraversalCallback* cb) const override;
}; };
class DelStmt final : public ExprStmt { class DelStmt final : public ExprStmt {
public: public:
explicit DelStmt(zeek::IntrusivePtr<Expr> e); explicit DelStmt(ExprPtr e);
bool IsPure() const override; bool IsPure() const override;
zeek::IntrusivePtr<Val> 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; TraversalCode Traverse(TraversalCallback* cb) const override;
}; };
class EventStmt final : public ExprStmt { class EventStmt final : public ExprStmt {
public: public:
explicit EventStmt(zeek::IntrusivePtr<EventExpr> e); explicit EventStmt(EventExprPtr e);
zeek::IntrusivePtr<Val> 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; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<EventExpr> event_expr; EventExprPtr event_expr;
}; };
class WhileStmt final : public Stmt { class WhileStmt final : public Stmt {
public: public:
WhileStmt(zeek::IntrusivePtr<Expr> loop_condition, zeek::IntrusivePtr<Stmt> body); WhileStmt(ExprPtr loop_condition, StmtPtr body);
~WhileStmt() override; ~WhileStmt() override;
bool IsPure() const override; bool IsPure() const override;
@ -271,20 +277,20 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
zeek::IntrusivePtr<Expr> loop_condition; ExprPtr loop_condition;
zeek::IntrusivePtr<Stmt> body; StmtPtr body;
}; };
class ForStmt final : public ExprStmt { class ForStmt final : public ExprStmt {
public: public:
ForStmt(id_list* loop_vars, zeek::IntrusivePtr<Expr> loop_expr); ForStmt(id_list* loop_vars, ExprPtr loop_expr);
// Special constructor for key value for loop. // Special constructor for key value for loop.
ForStmt(id_list* loop_vars, zeek::IntrusivePtr<Expr> loop_expr, zeek::IntrusivePtr<ID> val_var); ForStmt(id_list* loop_vars, ExprPtr loop_expr, IDPtr val_var);
~ForStmt() override; ~ForStmt() override;
void AddBody(zeek::IntrusivePtr<Stmt> 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 id_list* LoopVar() const { return loop_vars; }
const Expr* LoopExpr() const { return e.get(); } const Expr* LoopExpr() const { return e.get(); }
@ -297,20 +303,20 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Val> 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; id_list* loop_vars;
zeek::IntrusivePtr<Stmt> body; StmtPtr body;
// Stores the value variable being used for a key value for loop. // Stores the value variable being used for a key value for loop.
// Always set to nullptr unless special constructor is called. // Always set to nullptr unless special constructor is called.
zeek::IntrusivePtr<ID> value_var; IDPtr value_var;
}; };
class NextStmt final : public Stmt { class NextStmt final : public Stmt {
public: public:
NextStmt() : Stmt(STMT_NEXT) { } NextStmt() : Stmt(STMT_NEXT) { }
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -324,7 +330,7 @@ class BreakStmt final : public Stmt {
public: public:
BreakStmt() : Stmt(STMT_BREAK) { } BreakStmt() : Stmt(STMT_BREAK) { }
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -338,7 +344,7 @@ class FallthroughStmt final : public Stmt {
public: public:
FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { } FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { }
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -350,9 +356,9 @@ protected:
class ReturnStmt final : public ExprStmt { class ReturnStmt final : public ExprStmt {
public: public:
explicit ReturnStmt(zeek::IntrusivePtr<Expr> e); explicit ReturnStmt(ExprPtr e);
zeek::IntrusivePtr<Val> 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; void Describe(ODesc* d) const override;
}; };
@ -362,7 +368,7 @@ public:
StmtList(); StmtList();
~StmtList() override; ~StmtList() override;
zeek::IntrusivePtr<Val> 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; } const stmt_list& Stmts() const { return stmts; }
stmt_list& Stmts() { return stmts; } stmt_list& Stmts() { return stmts; }
@ -382,7 +388,7 @@ public:
EventBodyList() : StmtList() EventBodyList() : StmtList()
{ topmost = false; tag = STMT_EVENT_BODY_LIST; } { topmost = false; tag = STMT_EVENT_BODY_LIST; }
zeek::IntrusivePtr<Val> 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; void Describe(ODesc* d) const override;
@ -396,11 +402,11 @@ protected:
class InitStmt final : public Stmt { class InitStmt final : public Stmt {
public: public:
explicit InitStmt(std::vector<zeek::IntrusivePtr<ID>> arg_inits); explicit InitStmt(std::vector<IDPtr> arg_inits);
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
const std::vector<zeek::IntrusivePtr<ID>>& Inits() const const std::vector<IDPtr>& Inits() const
{ return inits; } { return inits; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -408,14 +414,14 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
std::vector<zeek::IntrusivePtr<ID>> inits; std::vector<IDPtr> inits;
}; };
class NullStmt final : public Stmt { class NullStmt final : public Stmt {
public: public:
NullStmt() : Stmt(STMT_NULL) { } NullStmt() : Stmt(STMT_NULL) { }
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -426,12 +432,12 @@ public:
class WhenStmt final : public Stmt { class WhenStmt final : public Stmt {
public: public:
// s2 is null if no timeout block given. // s2 is null if no timeout block given.
WhenStmt(zeek::IntrusivePtr<Expr> cond, WhenStmt(ExprPtr cond,
zeek::IntrusivePtr<Stmt> s1, zeek::IntrusivePtr<Stmt> s2, StmtPtr s1, StmtPtr s2,
zeek::IntrusivePtr<Expr> timeout, bool is_return); ExprPtr timeout, bool is_return);
~WhenStmt() override; ~WhenStmt() override;
zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; ValPtr Exec(Frame* f, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
const Expr* Cond() const { return cond.get(); } const Expr* Cond() const { return cond.get(); }
@ -444,10 +450,10 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
zeek::IntrusivePtr<Expr> cond; ExprPtr cond;
zeek::IntrusivePtr<Stmt> s1; StmtPtr s1;
zeek::IntrusivePtr<Stmt> s2; StmtPtr s2;
zeek::IntrusivePtr<Expr> timeout; ExprPtr timeout;
bool is_return; bool is_return;
}; };

View file

@ -2,9 +2,8 @@
#include "Tag.h" #include "Tag.h"
#include "Val.h" #include "Val.h"
#include "IntrusivePtr.h"
Tag::Tag(const zeek::IntrusivePtr<zeek::EnumType>& 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); 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({zeek::NewRef{}, etype}, arg_type, arg_subtype)
{ } { }
Tag::Tag(zeek::IntrusivePtr<EnumVal> arg_val) Tag::Tag(EnumValPtr arg_val)
{ {
assert(arg_val); assert(arg_val);
@ -73,7 +72,7 @@ Tag& Tag::operator=(const Tag&& other) noexcept
return *this; return *this;
} }
const zeek::IntrusivePtr<EnumVal>& Tag::AsVal(const zeek::IntrusivePtr<zeek::EnumType>& etype) const const EnumValPtr& Tag::AsVal(const zeek::EnumTypePtr& etype) const
{ {
if ( ! val ) if ( ! val )
{ {

View file

@ -11,7 +11,12 @@
#include "util.h" #include "util.h"
class EnumVal; class EnumVal;
using EnumValPtr = zeek::IntrusivePtr<EnumVal>;
ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek); ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek);
namespace zeek {
using EnumTypePtr = zeek::IntrusivePtr<zeek::EnumType>;
}
/** /**
* Class to identify an analyzer type. * Class to identify an analyzer type.
@ -116,7 +121,7 @@ protected:
* *
* @param etype the script-layer enum type associated with the tag. * @param etype the script-layer enum type associated with the tag.
*/ */
const zeek::IntrusivePtr<EnumVal>& AsVal(const zeek::IntrusivePtr<zeek::EnumType>& etype) const; const EnumValPtr& AsVal(const zeek::EnumTypePtr& etype) const;
[[deprecated("Remove in v4.1. Use AsVal() instead.")]] [[deprecated("Remove in v4.1. Use AsVal() instead.")]]
EnumVal* AsEnumVal(zeek::EnumType* etype) const; EnumVal* AsEnumVal(zeek::EnumType* etype) const;
@ -132,7 +137,7 @@ protected:
* @param subtype The sub type, which is left to an analyzer for * @param subtype The sub type, which is left to an analyzer for
* interpretation. By default it's set to zero. * interpretation. By default it's set to zero.
*/ */
Tag(const zeek::IntrusivePtr<zeek::EnumType>& 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.")]] [[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr& instead.")]]
Tag(zeek::EnumType* etype, type_t type, subtype_t subtype = 0); 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. * @param val An enum value of script type \c Analyzer::Tag.
*/ */
explicit Tag(zeek::IntrusivePtr<EnumVal> val); explicit Tag(EnumValPtr val);
[[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr instead.")]]
explicit Tag(EnumVal* val); explicit Tag(EnumVal* val);
@ -150,5 +155,5 @@ protected:
private: private:
type_t type; // Main type. type_t type; // Main type.
subtype_t subtype; // Subtype. subtype_t subtype; // Subtype.
mutable zeek::IntrusivePtr<EnumVal> val; // Script-layer value. mutable EnumValPtr val; // Script-layer value.
}; };

View file

@ -151,7 +151,7 @@ Trigger::Trigger(zeek::detail::Expr* arg_cond, zeek::detail::Stmt* arg_body,
arg_frame->SetDelayed(); arg_frame->SetDelayed();
} }
zeek::IntrusivePtr<Val> timeout_val; ValPtr timeout_val;
if ( arg_timeout ) if ( arg_timeout )
{ {
@ -264,7 +264,7 @@ bool Trigger::Eval()
f->SetTrigger({zeek::NewRef{}, this}); f->SetTrigger({zeek::NewRef{}, this});
zeek::IntrusivePtr<Val> v; ValPtr v;
try try
{ {
@ -348,8 +348,8 @@ void Trigger::Timeout()
if ( timeout_stmts ) if ( timeout_stmts )
{ {
stmt_flow_type flow; stmt_flow_type flow;
zeek::IntrusivePtr<Frame> f{zeek::AdoptRef{}, frame->Clone()}; FramePtr f{zeek::AdoptRef{}, frame->Clone()};
zeek::IntrusivePtr<Val> v; ValPtr v;
try try
{ {

View file

@ -8,6 +8,7 @@
#include "Notifier.h" #include "Notifier.h"
#include "iosource/IOSource.h" #include "iosource/IOSource.h"
#include "util.h" #include "util.h"
#include "IntrusivePtr.h"
class Frame; class Frame;
class Val; class Val;
@ -115,6 +116,8 @@ private:
ValCache cache; ValCache cache;
}; };
using TriggerPtr = zeek::IntrusivePtr<Trigger>;
class Manager final : public iosource::IOSource { class Manager final : public iosource::IOSource {
public: public:

View file

@ -16,7 +16,7 @@ EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t)
} }
} }
zeek::IntrusivePtr<RecordVal> EncapsulatingConn::ToVal() const RecordValPtr EncapsulatingConn::ToVal() const
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::Tunnel::EncapsulatingConn); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::Tunnel::EncapsulatingConn);

View file

@ -6,7 +6,6 @@
#include <vector> #include <vector>
#include "IntrusivePtr.h"
#include "NetVar.h" #include "NetVar.h"
#include "IPAddr.h" #include "IPAddr.h"
#include "ID.h" #include "ID.h"
@ -81,7 +80,7 @@ public:
/** /**
* Returns record value of type "EncapsulatingConn" representing the tunnel. * Returns record value of type "EncapsulatingConn" representing the tunnel.
*/ */
zeek::IntrusivePtr<RecordVal> ToVal() const; RecordValPtr ToVal() const;
[[deprecated("Remove in v4.1. Use ToVal() instead.")]] [[deprecated("Remove in v4.1. Use ToVal() instead.")]]
RecordVal* GetRecordVal() const RecordVal* GetRecordVal() const
@ -196,7 +195,7 @@ public:
* Get the value of type "EncapsulatingConnVector" represented by the * Get the value of type "EncapsulatingConnVector" represented by the
* entire encapsulation chain. * entire encapsulation chain.
*/ */
zeek::IntrusivePtr<VectorVal> ToVal() const VectorValPtr ToVal() const
{ {
auto vv = zeek::make_intrusive<VectorVal>( auto vv = zeek::make_intrusive<VectorVal>(
zeek::id::find_type<zeek::VectorType>("EncapsulatingConnVector")); zeek::id::find_type<zeek::VectorType>("EncapsulatingConnVector"));

View file

@ -71,7 +71,7 @@ Type::Type(zeek::TypeTag t, bool arg_base_type)
{ {
} }
zeek::IntrusivePtr<Type> Type::ShallowClone() TypePtr Type::ShallowClone()
{ {
switch ( tag ) { switch ( tag ) {
case TYPE_VOID: case TYPE_VOID:
@ -111,7 +111,7 @@ int Type::MatchesIndex(zeek::detail::ListExpr* const index) const
return DOES_NOT_MATCH_INDEX; return DOES_NOT_MATCH_INDEX;
} }
const zeek::IntrusivePtr<Type>& Type::Yield() const const TypePtr& Type::Yield() const
{ {
return Type::nil; return Type::nil;
} }
@ -163,7 +163,7 @@ bool TypeList::AllMatch(const Type* t, bool is_init) const
return true; return true;
} }
void TypeList::Append(zeek::IntrusivePtr<Type> t) void TypeList::Append(TypePtr t)
{ {
if ( pure_type && ! same_type(t, pure_type) ) if ( pure_type && ! same_type(t, pure_type) )
reporter->InternalError("pure type-list violation"); reporter->InternalError("pure type-list violation");
@ -172,7 +172,7 @@ void TypeList::Append(zeek::IntrusivePtr<Type> t)
types.emplace_back(std::move(t)); types.emplace_back(std::move(t));
} }
void TypeList::AppendEvenIfNotPure(zeek::IntrusivePtr<Type> t) void TypeList::AppendEvenIfNotPure(TypePtr t)
{ {
if ( pure_type && ! same_type(t, pure_type) ) if ( pure_type && ! same_type(t, pure_type) )
pure_type = nullptr; pure_type = nullptr;
@ -317,7 +317,7 @@ bool IndexType::IsSubNetIndex() const
return false; return false;
} }
TableType::TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield) TableType::TableType(TypeListPtr ind, TypePtr yield)
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield)) : IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
{ {
if ( ! indices ) if ( ! indices )
@ -344,7 +344,7 @@ TableType::TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type>
} }
} }
zeek::IntrusivePtr<Type> TableType::ShallowClone() TypePtr TableType::ShallowClone()
{ {
return zeek::make_intrusive<TableType>(indices, yield_type); return zeek::make_intrusive<TableType>(indices, yield_type);
} }
@ -355,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const
return indices->GetTypes().empty(); return indices->GetTypes().empty();
} }
SetType::SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> arg_elements) SetType::SetType(TypeListPtr ind, zeek::detail::ListExprPtr arg_elements)
: TableType(std::move(ind), nullptr), elements(std::move(arg_elements)) : TableType(std::move(ind), nullptr), elements(std::move(arg_elements))
{ {
if ( elements ) if ( elements )
@ -378,7 +378,7 @@ SetType::SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::deta
else if ( tl.size() == 1 ) else if ( tl.size() == 1 )
{ {
zeek::IntrusivePtr<Type> ft{zeek::NewRef{}, flatten_type(tl[0].get())}; TypePtr ft{zeek::NewRef{}, flatten_type(tl[0].get())};
indices = zeek::make_intrusive<TypeList>(ft); indices = zeek::make_intrusive<TypeList>(ft);
indices->Append(std::move(ft)); indices->Append(std::move(ft));
} }
@ -403,15 +403,15 @@ SetType::SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::deta
} }
} }
zeek::IntrusivePtr<Type> SetType::ShallowClone() TypePtr SetType::ShallowClone()
{ {
return zeek::make_intrusive<SetType>(indices, elements); return zeek::make_intrusive<SetType>(indices, elements);
} }
SetType::~SetType() = default; SetType::~SetType() = default;
FuncType::FuncType(zeek::IntrusivePtr<RecordType> arg_args, FuncType::FuncType(RecordTypePtr arg_args,
zeek::IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor) TypePtr arg_yield, FunctionFlavor arg_flavor)
: Type(TYPE_FUNC), args(std::move(arg_args)), : Type(TYPE_FUNC), args(std::move(arg_args)),
arg_types(zeek::make_intrusive<TypeList>()), yield(std::move(arg_yield)) arg_types(zeek::make_intrusive<TypeList>()), yield(std::move(arg_yield))
{ {
@ -441,7 +441,7 @@ FuncType::FuncType(zeek::IntrusivePtr<RecordType> arg_args,
prototypes.emplace_back(Prototype{false, args, std::move(offsets)}); prototypes.emplace_back(Prototype{false, args, std::move(offsets)});
} }
zeek::IntrusivePtr<Type> FuncType::ShallowClone() TypePtr FuncType::ShallowClone()
{ {
auto f = zeek::make_intrusive<FuncType>(); auto f = zeek::make_intrusive<FuncType>();
f->args = args; 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 bool FuncType::CheckArgs(const type_list* args, bool is_init) const
{ {
std::vector<zeek::IntrusivePtr<Type>> as; std::vector<TypePtr> as;
as.reserve(args->length()); as.reserve(args->length());
for ( auto a : *args ) for ( auto a : *args )
@ -490,7 +490,7 @@ bool FuncType::CheckArgs(const type_list* args, bool is_init) const
return CheckArgs(as, is_init); return CheckArgs(as, is_init);
} }
bool FuncType::CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& args, bool FuncType::CheckArgs(const std::vector<TypePtr>& args,
bool is_init) const bool is_init) const
{ {
const auto& my_args = arg_types->GetTypes(); const auto& my_args = arg_types->GetTypes();
@ -609,8 +609,7 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
return {}; return {};
} }
TypeDecl::TypeDecl(const char* i, zeek::IntrusivePtr<Type> t, TypeDecl::TypeDecl(const char* i, TypePtr t, zeek::detail::AttributesPtr arg_attrs)
zeek::IntrusivePtr<zeek::detail::Attributes> arg_attrs)
: type(std::move(t)), : type(std::move(t)),
attrs(std::move(arg_attrs)), attrs(std::move(arg_attrs)),
id(i) 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 // in this case the clone is actually not so shallow, since
// it gets modified by everyone. // it gets modified by everyone.
zeek::IntrusivePtr<Type> RecordType::ShallowClone() TypePtr RecordType::ShallowClone()
{ {
auto pass = new type_decl_list(); auto pass = new type_decl_list();
for ( const auto& type : *types ) for ( const auto& type : *types )
@ -682,7 +681,7 @@ bool RecordType::HasField(const char* field) const
return FieldOffset(field) >= 0; return FieldOffset(field) >= 0;
} }
zeek::IntrusivePtr<Val> RecordType::FieldDefault(int field) const ValPtr RecordType::FieldDefault(int field) const
{ {
const TypeDecl* td = FieldDecl(field); const TypeDecl* td = FieldDecl(field);
@ -794,7 +793,7 @@ static string container_type_name(const Type* ft)
return s; return s;
} }
zeek::IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv) const TableValPtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const
{ {
static auto record_field = zeek::id::find_type<RecordType>("record_field"); static auto record_field = zeek::id::find_type<RecordType>("record_field");
static auto record_field_table = zeek::id::find_type<TableType>("record_field_table"); static auto record_field_table = zeek::id::find_type<TableType>("record_field_table");
@ -804,7 +803,7 @@ zeek::IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv)
{ {
const auto& ft = GetFieldType(i); const auto& ft = GetFieldType(i);
const TypeDecl* fd = FieldDecl(i); const TypeDecl* fd = FieldDecl(i);
zeek::IntrusivePtr<Val> fv; ValPtr fv;
if ( rv ) if ( rv )
fv = rv->GetField(i); fv = rv->GetField(i);
@ -1028,7 +1027,7 @@ void SubNetType::Describe(ODesc* d) const
d->Add(int(Tag())); d->Add(int(Tag()));
} }
FileType::FileType(zeek::IntrusivePtr<Type> yield_type) FileType::FileType(TypePtr yield_type)
: Type(TYPE_FILE), yield(std::move(yield_type)) : Type(TYPE_FILE), yield(std::move(yield_type))
{ {
} }
@ -1083,7 +1082,7 @@ EnumType::EnumType(const EnumType* e)
SetName(e->GetName()); SetName(e->GetName());
} }
zeek::IntrusivePtr<Type> EnumType::ShallowClone() TypePtr EnumType::ShallowClone()
{ {
if ( counter == 0 ) if ( counter == 0 )
return zeek::make_intrusive<EnumType>(GetName()); return zeek::make_intrusive<EnumType>(GetName());
@ -1213,7 +1212,7 @@ EnumType::enum_name_list EnumType::Names() const
return n; return n;
} }
const zeek::IntrusivePtr<EnumVal>& EnumType::GetVal(bro_int_t i) const EnumValPtr& EnumType::GetVal(bro_int_t i)
{ {
auto it = vals.find(i); auto it = vals.find(i);
@ -1303,19 +1302,19 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
} }
} }
VectorType::VectorType(zeek::IntrusivePtr<Type> element_type) VectorType::VectorType(TypePtr element_type)
: Type(TYPE_VECTOR), yield_type(std::move(element_type)) : Type(TYPE_VECTOR), yield_type(std::move(element_type))
{ {
} }
zeek::IntrusivePtr<Type> VectorType::ShallowClone() TypePtr VectorType::ShallowClone()
{ {
return zeek::make_intrusive<VectorType>(yield_type); return zeek::make_intrusive<VectorType>(yield_type);
} }
VectorType::~VectorType() = default; VectorType::~VectorType() = default;
const zeek::IntrusivePtr<Type>& VectorType::Yield() const const TypePtr& VectorType::Yield() const
{ {
// Work around the fact that we use void internally to mark a vector // 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 // 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<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1, TypePtr merge_types(const TypePtr& arg_t1,
const zeek::IntrusivePtr<Type>& arg_t2) const TypePtr& arg_t2)
{ {
auto t1 = arg_t1.get(); auto t1 = arg_t1.get();
auto t2 = arg_t2.get(); auto t2 = arg_t2.get();
@ -1758,7 +1757,7 @@ zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1,
const auto& tl1 = it1->GetIndexTypes(); const auto& tl1 = it1->GetIndexTypes();
const auto& tl2 = it2->GetIndexTypes(); const auto& tl2 = it2->GetIndexTypes();
zeek::IntrusivePtr<TypeList> tl3; TypeListPtr tl3;
if ( tl1.size() != tl2.size() ) if ( tl1.size() != tl2.size() )
{ {
@ -1779,7 +1778,7 @@ zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1,
const auto& y1 = t1->Yield(); const auto& y1 = t1->Yield();
const auto& y2 = t2->Yield(); const auto& y2 = t2->Yield();
zeek::IntrusivePtr<Type> y3; TypePtr y3;
if ( y1 || y2 ) if ( y1 || y2 )
{ {
@ -1924,7 +1923,7 @@ zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1,
} }
} }
zeek::IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements) TypePtr merge_type_list(zeek::detail::ListExpr* elements)
{ {
TypeList* tl_type = elements->GetType()->AsTypeList(); TypeList* tl_type = elements->GetType()->AsTypeList();
const auto& tl = tl_type->GetTypes(); const auto& tl = tl_type->GetTypes();
@ -1969,7 +1968,7 @@ static Type* reduce_type(Type* t)
return t; return t;
} }
zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init) TypePtr init_type(zeek::detail::Expr* init)
{ {
if ( init->Tag() != zeek::detail::EXPR_LIST ) if ( init->Tag() != zeek::detail::EXPR_LIST )
{ {
@ -2016,7 +2015,7 @@ zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
for ( int i = 1; t && i < el.length(); ++i ) for ( int i = 1; t && i < el.length(); ++i )
{ {
auto el_t = el[i]->InitType(); auto el_t = el[i]->InitType();
zeek::IntrusivePtr<Type> ti; TypePtr ti;
if ( el_t ) if ( el_t )
ti = {zeek::NewRef{}, reduce_type(el_t.get())}; ti = {zeek::NewRef{}, reduce_type(el_t.get())};
@ -2068,9 +2067,9 @@ bool is_atomic_type(const Type& t)
} }
} }
const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag) const TypePtr& base_type(zeek::TypeTag tag)
{ {
static zeek::IntrusivePtr<Type> base_types[NUM_TYPES]; static TypePtr base_types[NUM_TYPES];
// We could check here that "tag" actually corresponds to a basic type. // We could check here that "tag" actually corresponds to a basic type.
if ( ! base_types[tag] ) if ( ! base_types[tag] )

View file

@ -18,10 +18,18 @@ class Val;
class EnumVal; class EnumVal;
class TableVal; class TableVal;
using ValPtr = zeek::IntrusivePtr<Val>;
using EnumValPtr = zeek::IntrusivePtr<EnumVal>;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
namespace zeek::detail {
using ListExprPtr = zeek::IntrusivePtr<ListExpr>;
}
namespace zeek { namespace zeek {
// BRO types. // BRO types.
@ -139,6 +147,20 @@ class EnumType;
class VectorType; class VectorType;
class TypeType; class TypeType;
class OpaqueType; class OpaqueType;
class FileType;
using TypePtr = zeek::IntrusivePtr<Type>;
using TypeListPtr = zeek::IntrusivePtr<TypeList>;
using TableTypePtr = zeek::IntrusivePtr<TableType>;
using SetTypePtr = zeek::IntrusivePtr<SetType>;
using RecordTypePtr = zeek::IntrusivePtr<RecordType>;
using SubNetTypePtr = zeek::IntrusivePtr<SubNetType>;
using FuncTypePtr = zeek::IntrusivePtr<FuncType>;
using EnumTypePtr = zeek::IntrusivePtr<EnumType>;
using VectorTypePtr = zeek::IntrusivePtr<VectorType>;
using TypeTypePtr = zeek::IntrusivePtr<TypeType>;
using OpaqueTypePtr = zeek::IntrusivePtr<OpaqueType>;
using FileTypePtr = zeek::IntrusivePtr<FileType>;
constexpr int DOES_NOT_MATCH_INDEX = 0; constexpr int DOES_NOT_MATCH_INDEX = 0;
constexpr int MATCHES_INDEX_SCALAR = 1; constexpr int MATCHES_INDEX_SCALAR = 1;
@ -146,7 +168,7 @@ constexpr int MATCHES_INDEX_VECTOR = 2;
class Type : public BroObj { class Type : public BroObj {
public: public:
static inline const zeek::IntrusivePtr<Type> nil; static inline const TypePtr nil;
explicit Type(zeek::TypeTag tag, bool base_type = false); explicit Type(zeek::TypeTag tag, bool base_type = false);
@ -158,7 +180,7 @@ public:
// Clone operations will mostly be implemented in the derived classes; // Clone operations will mostly be implemented in the derived classes;
// in addition cloning will be limited to classes that can be reached by // in addition cloning will be limited to classes that can be reached by
// the script-level. // the script-level.
virtual zeek::IntrusivePtr<Type> ShallowClone(); virtual TypePtr ShallowClone();
TypeTag Tag() const { return tag; } TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; } InternalTypeTag InternalType() const { return internal_tag; }
@ -178,7 +200,7 @@ public:
// Returns the type yielded by this type. For example, if // Returns the type yielded by this type. For example, if
// this type is a table[string] of port, then returns the "port" // this type is a table[string] of port, then returns the "port"
// type. Returns nil if this is not an index type. // type. Returns nil if this is not an index type.
virtual const zeek::IntrusivePtr<Type>& Yield() const; virtual const TypePtr& Yield() const;
[[deprecated("Remove in v4.1. Use Yield() instead.")]] [[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual Type* YieldType() virtual Type* YieldType()
@ -362,7 +384,7 @@ private:
class TypeList final : public Type { class TypeList final : public Type {
public: public:
explicit TypeList(zeek::IntrusivePtr<Type> arg_pure_type = nullptr) explicit TypeList(TypePtr arg_pure_type = nullptr)
: Type(TYPE_LIST), pure_type(std::move(arg_pure_type)) : Type(TYPE_LIST), pure_type(std::move(arg_pure_type))
{ {
} }
@ -373,14 +395,14 @@ public:
const type_list* Types() const const type_list* Types() const
{ return &types_list; } { return &types_list; }
const std::vector<zeek::IntrusivePtr<Type>>& GetTypes() const const std::vector<TypePtr>& GetTypes() const
{ return types; } { return types; }
bool IsPure() const { return pure_type != nullptr; } bool IsPure() const { return pure_type != nullptr; }
// Returns the underlying pure type, or nil if the list // Returns the underlying pure type, or nil if the list
// is not pure or is empty. // is not pure or is empty.
const zeek::IntrusivePtr<Type>& GetPureType() const const TypePtr& GetPureType() const
{ return pure_type; } { return pure_type; }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]] [[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 // is_init is true, then the matching is done in the context
// of an initialization. // of an initialization.
bool AllMatch(const Type* t, bool is_init) const; bool AllMatch(const Type* t, bool is_init) const;
bool AllMatch(const zeek::IntrusivePtr<Type>& t, bool is_init) const bool AllMatch(const TypePtr& t, bool is_init) const
{ return AllMatch(t.get(), is_init); } { return AllMatch(t.get(), is_init); }
void Append(zeek::IntrusivePtr<Type> t); void Append(TypePtr t);
void AppendEvenIfNotPure(zeek::IntrusivePtr<Type> t); void AppendEvenIfNotPure(TypePtr t);
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
zeek::IntrusivePtr<Type> pure_type; TypePtr pure_type;
std::vector<zeek::IntrusivePtr<Type>> types; std::vector<TypePtr> types;
// Remove in v4.1. This is used by Types(), which is deprecated. // Remove in v4.1. This is used by Types(), which is deprecated.
type_list types_list; type_list types_list;
@ -415,7 +437,7 @@ public:
int MatchesIndex(zeek::detail::ListExpr* index) const override; int MatchesIndex(zeek::detail::ListExpr* index) const override;
const zeek::IntrusivePtr<TypeList>& GetIndices() const const TypeListPtr& GetIndices() const
{ return indices; } { return indices; }
[[deprecated("Remove in v4.1. Use GetIndices().")]] [[deprecated("Remove in v4.1. Use GetIndices().")]]
@ -425,10 +447,10 @@ public:
const type_list* IndexTypes() const const type_list* IndexTypes() const
{ return indices->Types(); } { return indices->Types(); }
const std::vector<zeek::IntrusivePtr<Type>>& GetIndexTypes() const const std::vector<TypePtr>& GetIndexTypes() const
{ return indices->GetTypes(); } { return indices->GetTypes(); }
const zeek::IntrusivePtr<Type>& Yield() const override const TypePtr& Yield() const override
{ return yield_type; } { return yield_type; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -438,8 +460,8 @@ public:
bool IsSubNetIndex() const; bool IsSubNetIndex() const;
protected: protected:
IndexType(TypeTag t, zeek::IntrusivePtr<TypeList> arg_indices, IndexType(TypeTag t, TypeListPtr arg_indices,
zeek::IntrusivePtr<Type> arg_yield_type) TypePtr arg_yield_type)
: Type(t), indices(std::move(arg_indices)), : Type(t), indices(std::move(arg_indices)),
yield_type(std::move(arg_yield_type)) yield_type(std::move(arg_yield_type))
{ {
@ -447,15 +469,15 @@ protected:
~IndexType() override = default; ~IndexType() override = default;
zeek::IntrusivePtr<TypeList> indices; TypeListPtr indices;
zeek::IntrusivePtr<Type> yield_type; TypePtr yield_type;
}; };
class TableType : public IndexType { class TableType : public IndexType {
public: public:
TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield); TableType(TypeListPtr ind, TypePtr yield);
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
// Returns true if this table type is "unspecified", which is // Returns true if this table type is "unspecified", which is
// what one gets using an empty "set()" or "table()" constructor. // what one gets using an empty "set()" or "table()" constructor.
@ -464,24 +486,24 @@ public:
class SetType final : public TableType { class SetType final : public TableType {
public: public:
SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> arg_elements); SetType(TypeListPtr ind, zeek::detail::ListExprPtr arg_elements);
~SetType() override; ~SetType() override;
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
[[deprecated("Remove in v4.1. Use Elements() isntead.")]] [[deprecated("Remove in v4.1. Use Elements() isntead.")]]
zeek::detail::ListExpr* SetElements() const { return elements.get(); } zeek::detail::ListExpr* SetElements() const { return elements.get(); }
const zeek::IntrusivePtr<zeek::detail::ListExpr>& Elements() const const zeek::detail::ListExprPtr& Elements() const
{ return elements; } { return elements; }
protected: protected:
zeek::IntrusivePtr<zeek::detail::ListExpr> elements; zeek::detail::ListExprPtr elements;
}; };
class FuncType final : public Type { class FuncType final : public Type {
public: public:
static inline const zeek::IntrusivePtr<FuncType> nil; static inline const FuncTypePtr nil;
/** /**
* Prototype is only currently used for events and hooks which declare * Prototype is only currently used for events and hooks which declare
@ -490,27 +512,27 @@ public:
*/ */
struct Prototype { struct Prototype {
bool deprecated; bool deprecated;
zeek::IntrusivePtr<RecordType> args; RecordTypePtr args;
std::map<int, int> offsets; std::map<int, int> offsets;
}; };
FuncType(zeek::IntrusivePtr<RecordType> args, zeek::IntrusivePtr<Type> yield, FuncType(RecordTypePtr args, TypePtr yield,
FunctionFlavor f); FunctionFlavor f);
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
~FuncType() override; ~FuncType() override;
[[deprecated("Remove in v4.1. Use Params().")]] [[deprecated("Remove in v4.1. Use Params().")]]
RecordType* Args() const { return args.get(); } RecordType* Args() const { return args.get(); }
const zeek::IntrusivePtr<RecordType>& Params() const const RecordTypePtr& Params() const
{ return args; } { return args; }
const zeek::IntrusivePtr<Type>& Yield() const override const TypePtr& Yield() const override
{ return yield; } { return yield; }
void SetYieldType(zeek::IntrusivePtr<Type> arg_yield) { yield = std::move(arg_yield); } void SetYieldType(TypePtr arg_yield) { yield = std::move(arg_yield); }
FunctionFlavor Flavor() const { return flavor; } FunctionFlavor Flavor() const { return flavor; }
std::string FlavorString() const; std::string FlavorString() const;
@ -520,13 +542,13 @@ public:
int MatchesIndex(zeek::detail::ListExpr* index) const override; int MatchesIndex(zeek::detail::ListExpr* index) const override;
bool CheckArgs(const type_list* args, bool is_init = false) const; bool CheckArgs(const type_list* args, bool is_init = false) const;
bool CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& args, bool CheckArgs(const std::vector<TypePtr>& args,
bool is_init = false) const; bool is_init = false) const;
[[deprecated("Remove in v4.1. Use ParamList().")]] [[deprecated("Remove in v4.1. Use ParamList().")]]
TypeList* ArgTypes() const { return arg_types.get(); } TypeList* ArgTypes() const { return arg_types.get(); }
const zeek::IntrusivePtr<TypeList>& ParamList() const const TypeListPtr& ParamList() const
{ return arg_types; } { return arg_types; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -549,22 +571,22 @@ public:
{ return prototypes; } { return prototypes; }
protected: protected:
friend zeek::IntrusivePtr<FuncType> zeek::make_intrusive<FuncType>(); friend FuncTypePtr zeek::make_intrusive<FuncType>();
FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
zeek::IntrusivePtr<RecordType> args; RecordTypePtr args;
zeek::IntrusivePtr<TypeList> arg_types; TypeListPtr arg_types;
zeek::IntrusivePtr<Type> yield; TypePtr yield;
FunctionFlavor flavor; FunctionFlavor flavor;
std::vector<Prototype> prototypes; std::vector<Prototype> prototypes;
}; };
class TypeType final : public Type { class TypeType final : public Type {
public: public:
explicit TypeType(zeek::IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {} explicit TypeType(TypePtr t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<TypeType>(type); } TypePtr ShallowClone() override { return zeek::make_intrusive<TypeType>(type); }
const zeek::IntrusivePtr<Type>& GetType() const const TypePtr& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
@ -577,24 +599,23 @@ public:
const zeek::Type* Type() const { return type.get(); } const zeek::Type* Type() const { return type.get(); }
protected: protected:
zeek::IntrusivePtr<zeek::Type> type; TypePtr type;
}; };
class TypeDecl final { class TypeDecl final {
public: public:
TypeDecl() = default; TypeDecl() = default;
TypeDecl(const char* i, zeek::IntrusivePtr<Type> t, TypeDecl(const char* i, TypePtr t, zeek::detail::AttributesPtr attrs = nullptr);
zeek::IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
TypeDecl(const TypeDecl& other); TypeDecl(const TypeDecl& other);
~TypeDecl(); ~TypeDecl();
const zeek::IntrusivePtr<zeek::detail::Attr>& 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; } { return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; }
void DescribeReST(ODesc* d, bool roles_only = false) const; void DescribeReST(ODesc* d, bool roles_only = false) const;
zeek::IntrusivePtr<Type> type; TypePtr type;
zeek::IntrusivePtr<zeek::detail::Attributes> attrs; zeek::detail::AttributesPtr attrs;
const char* id = nullptr; const char* id = nullptr;
}; };
@ -603,7 +624,7 @@ using type_decl_list = PList<TypeDecl>;
class RecordType final : public Type { class RecordType final : public Type {
public: public:
explicit RecordType(type_decl_list* types); explicit RecordType(type_decl_list* types);
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
~RecordType() override; ~RecordType() override;
@ -624,7 +645,7 @@ public:
* Looks up a field by name and returns its type. No check for invalid * Looks up a field by name and returns its type. No check for invalid
* field name is performed. * field name is performed.
*/ */
const zeek::IntrusivePtr<Type>& GetFieldType(const char* field_name) const const TypePtr& GetFieldType(const char* field_name) const
{ return GetFieldType(FieldOffset(field_name)); } { return GetFieldType(FieldOffset(field_name)); }
/** /**
@ -639,7 +660,7 @@ public:
* Looks up a field by its index and returns its type. No check for * Looks up a field by its index and returns its type. No check for
* invalid field offset is performed. * invalid field offset is performed.
*/ */
const zeek::IntrusivePtr<Type>& GetFieldType(int field_index) const const TypePtr& GetFieldType(int field_index) const
{ return (*types)[field_index]->type; } { return (*types)[field_index]->type; }
/** /**
@ -650,7 +671,7 @@ public:
zeek::IntrusivePtr<T> GetFieldType(int field_index) const zeek::IntrusivePtr<T> GetFieldType(int field_index) const
{ return zeek::cast_intrusive<T>((*types)[field_index]->type); } { return zeek::cast_intrusive<T>((*types)[field_index]->type); }
zeek::IntrusivePtr<Val> FieldDefault(int field) const; ValPtr FieldDefault(int field) const;
// A field's offset is its position in the type_decl_list, // A field's offset is its position in the type_decl_list,
// starting at 0. Returns negative if the field doesn't exist. // 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 * @param rv an optional record value, if given the values of
* all fields will be provided in the returned table. * all fields will be provided in the returned table.
*/ */
zeek::IntrusivePtr<TableVal> 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. // Returns null if all is ok, otherwise a pointer to an error message.
const char* AddFields(const type_decl_list& types, const char* AddFields(const type_decl_list& types,
@ -712,23 +733,23 @@ public:
class FileType final : public Type { class FileType final : public Type {
public: public:
explicit FileType(zeek::IntrusivePtr<Type> yield_type); explicit FileType(TypePtr yield_type);
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<FileType>(yield); } TypePtr ShallowClone() override { return zeek::make_intrusive<FileType>(yield); }
~FileType() override; ~FileType() override;
const zeek::IntrusivePtr<Type>& Yield() const override const TypePtr& Yield() const override
{ return yield; } { return yield; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
protected: protected:
zeek::IntrusivePtr<Type> yield; TypePtr yield;
}; };
class OpaqueType final : public Type { class OpaqueType final : public Type {
public: public:
explicit OpaqueType(const std::string& name); explicit OpaqueType(const std::string& name);
zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<OpaqueType>(name); } TypePtr ShallowClone() override { return zeek::make_intrusive<OpaqueType>(name); }
~OpaqueType() override { }; ~OpaqueType() override { };
const std::string& Name() const { return name; } const std::string& Name() const { return name; }
@ -748,7 +769,7 @@ public:
explicit EnumType(const EnumType* e); explicit EnumType(const EnumType* e);
explicit EnumType(const std::string& arg_name); explicit EnumType(const std::string& arg_name);
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
~EnumType() override; ~EnumType() override;
// The value of this name is next internal counter value, starting // 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; void DescribeReST(ODesc* d, bool roles_only = false) const override;
const zeek::IntrusivePtr<EnumVal>& GetVal(bro_int_t i); const EnumValPtr& GetVal(bro_int_t i);
protected: protected:
void AddNameInternal(const std::string& module_name, void AddNameInternal(const std::string& module_name,
@ -783,7 +804,7 @@ protected:
typedef std::map<std::string, bro_int_t> NameMap; typedef std::map<std::string, bro_int_t> NameMap;
NameMap names; NameMap names;
using ValMap = std::unordered_map<bro_int_t, zeek::IntrusivePtr<EnumVal>>; using ValMap = std::unordered_map<bro_int_t, EnumValPtr>;
ValMap vals; ValMap vals;
// The counter is initialized to 0 and incremented on every implicit // The counter is initialized to 0 and incremented on every implicit
@ -797,11 +818,11 @@ protected:
class VectorType final : public Type { class VectorType final : public Type {
public: public:
explicit VectorType(zeek::IntrusivePtr<Type> t); explicit VectorType(TypePtr t);
zeek::IntrusivePtr<Type> ShallowClone() override; TypePtr ShallowClone() override;
~VectorType() override; ~VectorType() override;
const zeek::IntrusivePtr<Type>& Yield() const override; const TypePtr& Yield() const override;
int MatchesIndex(zeek::detail::ListExpr* index) 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; void DescribeReST(ODesc* d, bool roles_only = false) const override;
protected: protected:
zeek::IntrusivePtr<Type> yield_type; TypePtr yield_type;
}; };
// True if the two types are equivalent. If is_init is true then the test is // 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. // true then for record types the field names have to match, too.
extern bool same_type(const Type& t1, const Type& t2, extern bool same_type(const Type& t1, const Type& t2,
bool is_init=false, bool match_record_field_names=true); bool is_init=false, bool match_record_field_names=true);
inline bool same_type(const zeek::IntrusivePtr<Type>& t1, const zeek::IntrusivePtr<Type>& t2, inline bool same_type(const TypePtr& t1, const TypePtr& t2,
bool is_init=false, bool match_record_field_names=true) bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); } { return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const Type* t1, const Type* t2, inline bool same_type(const Type* t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true) bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); } { return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const zeek::IntrusivePtr<Type>& t1, const Type* t2, inline bool same_type(const TypePtr& t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true) bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); } { return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const Type* t1, const zeek::IntrusivePtr<Type>& t2, inline bool same_type(const Type* t1, const TypePtr& t2,
bool is_init=false, bool match_record_field_names=true) bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); } { 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 // Given two types, returns the "merge", in which promotable types
// are promoted to the maximum of the two. Returns nil (and generates // are promoted to the maximum of the two. Returns nil (and generates
// an error message) if the types are incompatible. // an error message) if the types are incompatible.
zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& t1, TypePtr merge_types(const TypePtr& t1, const TypePtr& t2);
const zeek::IntrusivePtr<Type>& t2);
// Given a list of expressions, returns a (ref'd) type reflecting // Given a list of expressions, returns a (ref'd) type reflecting
// a merged type consistent across all of them, or nil if this // a merged type consistent across all of them, or nil if this
// cannot be done. // cannot be done.
zeek::IntrusivePtr<Type> 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. // Given an expression, infer its type when used for an initialization.
zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init); TypePtr init_type(zeek::detail::Expr* init);
// Returns true if argument is an atomic type. // Returns true if argument is an atomic type.
bool is_atomic_type(const Type& t); bool is_atomic_type(const Type& t);
inline bool is_atomic_type(const Type* t) inline bool is_atomic_type(const Type* t)
{ return is_atomic_type(*t); } { return is_atomic_type(*t); }
inline bool is_atomic_type(const zeek::IntrusivePtr<Type>& t) inline bool is_atomic_type(const TypePtr& t)
{ return is_atomic_type(*t); } { return is_atomic_type(*t); }
// True if the given type tag corresponds to type that can be assigned to. // 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)); } inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); }
// Returns the basic (non-parameterized) type with the given type. // Returns the basic (non-parameterized) type with the given type.
const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag); const TypePtr& base_type(zeek::TypeTag tag);
// Returns the basic error type. // Returns the basic error type.
inline const zeek::IntrusivePtr<Type>& error_type() { return base_type(TYPE_ERROR); } inline const TypePtr& error_type() { return base_type(TYPE_ERROR); }
} // namespace zeek } // namespace zeek
@ -938,16 +958,16 @@ inline const zeek::IntrusivePtr<Type>& error_type() { return base_type(TYP
inline zeek::Type* base_type_no_ref(zeek::TypeTag tag) inline zeek::Type* base_type_no_ref(zeek::TypeTag tag)
{ return zeek::base_type(tag).get(); } { return zeek::base_type(tag).get(); }
extern zeek::IntrusivePtr<zeek::OpaqueType> md5_type; extern zeek::OpaqueTypePtr md5_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> sha1_type; extern zeek::OpaqueTypePtr sha1_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> sha256_type; extern zeek::OpaqueTypePtr sha256_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> entropy_type; extern zeek::OpaqueTypePtr entropy_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> cardinality_type; extern zeek::OpaqueTypePtr cardinality_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> topk_type; extern zeek::OpaqueTypePtr topk_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> bloomfilter_type; extern zeek::OpaqueTypePtr bloomfilter_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> x509_opaque_type; extern zeek::OpaqueTypePtr x509_opaque_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type; extern zeek::OpaqueTypePtr ocsp_resp_opaque_type;
extern zeek::IntrusivePtr<zeek::OpaqueType> paraglob_type; extern zeek::OpaqueTypePtr paraglob_type;
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
using TypeList [[deprecated("Remove in v4.1. Use zeek::TypeList instead.")]] = zeek::TypeList; using TypeList [[deprecated("Remove in v4.1. Use zeek::TypeList instead.")]] = zeek::TypeList;

View file

@ -45,13 +45,13 @@ using namespace std;
Val::Val(Func* f) : Val({zeek::NewRef{}, f}) Val::Val(Func* f) : Val({zeek::NewRef{}, f})
{} {}
Val::Val(zeek::IntrusivePtr<Func> f) Val::Val(FuncPtr f)
: val(f.release()), type(val.func_val->GetType()) : val(f.release()), type(val.func_val->GetType())
{} {}
static const zeek::IntrusivePtr<zeek::FileType>& GetStringFileType() noexcept static const zeek::FileTypePtr& GetStringFileType() noexcept
{ {
static zeek::IntrusivePtr<zeek::FileType> string_file_type static auto string_file_type
= zeek::make_intrusive<zeek::FileType>(zeek::base_type(zeek::TYPE_STRING)); = zeek::make_intrusive<zeek::FileType>(zeek::base_type(zeek::TYPE_STRING));
return string_file_type; return string_file_type;
@ -60,7 +60,7 @@ static const zeek::IntrusivePtr<zeek::FileType>& GetStringFileType() noexcept
Val::Val(BroFile* f) : Val({zeek::AdoptRef{}, f}) Val::Val(BroFile* f) : Val({zeek::AdoptRef{}, f})
{} {}
Val::Val(zeek::IntrusivePtr<BroFile> f) Val::Val(BroFilePtr f)
: val(f.release()), type(GetStringFileType()) : val(f.release()), type(GetStringFileType())
{ {
assert(val.file_val->GetType()->Tag() == zeek::TYPE_STRING); assert(val.file_val->GetType()->Tag() == zeek::TYPE_STRING);
@ -82,19 +82,19 @@ Val::~Val()
#endif #endif
} }
zeek::IntrusivePtr<Val> Val::CloneState::NewClone(Val* src, zeek::IntrusivePtr<Val> dst) ValPtr Val::CloneState::NewClone(Val* src, ValPtr dst)
{ {
clones.insert(std::make_pair(src, dst.get())); clones.insert(std::make_pair(src, dst.get()));
return dst; return dst;
} }
zeek::IntrusivePtr<Val> Val::Clone() ValPtr Val::Clone()
{ {
Val::CloneState state; Val::CloneState state;
return Clone(&state); return Clone(&state);
} }
zeek::IntrusivePtr<Val> Val::Clone(CloneState* state) ValPtr Val::Clone(CloneState* state)
{ {
auto i = state->clones.find(this); auto i = state->clones.find(this);
@ -109,7 +109,7 @@ zeek::IntrusivePtr<Val> Val::Clone(CloneState* state)
return c; return c;
} }
zeek::IntrusivePtr<Val> Val::DoClone(CloneState* state) ValPtr Val::DoClone(CloneState* state)
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case zeek::TYPE_INTERNAL_INT: case zeek::TYPE_INTERNAL_INT:
@ -153,7 +153,7 @@ zeek::IntrusivePtr<Val> Val::DoClone(CloneState* state)
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<Func> Val::AsFuncPtr() const FuncPtr Val::AsFuncPtr() const
{ {
CHECK_TAG(type->Tag(), zeek::TYPE_FUNC, "Val::Func", zeek::type_name) CHECK_TAG(type->Tag(), zeek::TYPE_FUNC, "Val::Func", zeek::type_name)
return {zeek::NewRef{}, val.func_val}; return {zeek::NewRef{}, val.func_val};
@ -256,7 +256,7 @@ double Val::CoerceToDouble() const
return 0.0; return 0.0;
} }
zeek::IntrusivePtr<Val> Val::SizeVal() const ValPtr Val::SizeVal() const
{ {
switch ( type->InternalType() ) { switch ( type->InternalType() ) {
case zeek::TYPE_INTERNAL_INT: case zeek::TYPE_INTERNAL_INT:
@ -419,7 +419,7 @@ bool Val::WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type,
return false; return false;
} }
zeek::IntrusivePtr<TableVal> Val::GetRecordFields() TableValPtr Val::GetRecordFields()
{ {
static auto record_field_table = zeek::id::find_type<zeek::TableType>("record_field_table"); static auto record_field_table = zeek::id::find_type<zeek::TableType>("record_field_table");
auto t = GetType().get(); auto t = GetType().get();
@ -656,7 +656,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val*
} }
} }
zeek::IntrusivePtr<StringVal> Val::ToJSON(bool only_loggable, RE_Matcher* re) StringValPtr Val::ToJSON(bool only_loggable, RE_Matcher* re)
{ {
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
threading::formatter::JSON::NullDoubleWriter writer(buffer); threading::formatter::JSON::NullDoubleWriter writer(buffer);
@ -739,7 +739,7 @@ void IntervalVal::ValDescribe(ODesc* d) const
} }
} }
zeek::IntrusivePtr<Val> PortVal::SizeVal() const ValPtr PortVal::SizeVal() const
{ {
return val_mgr->Int(val.uint_val); return val_mgr->Int(val.uint_val);
} }
@ -820,7 +820,7 @@ void PortVal::ValDescribe(ODesc* d) const
d->Add(Protocol()); d->Add(Protocol());
} }
zeek::IntrusivePtr<Val> PortVal::DoClone(CloneState* state) ValPtr PortVal::DoClone(CloneState* state)
{ {
// Immutable. // Immutable.
return {zeek::NewRef{}, this}; return {zeek::NewRef{}, this};
@ -857,7 +857,7 @@ unsigned int AddrVal::MemoryAllocation() const
return padded_sizeof(*this) + val.addr_val->MemoryAllocation(); return padded_sizeof(*this) + val.addr_val->MemoryAllocation();
} }
zeek::IntrusivePtr<Val> AddrVal::SizeVal() const ValPtr AddrVal::SizeVal() const
{ {
if ( val.addr_val->GetFamily() == IPv4 ) if ( val.addr_val->GetFamily() == IPv4 )
return val_mgr->Count(32); return val_mgr->Count(32);
@ -865,7 +865,7 @@ zeek::IntrusivePtr<Val> AddrVal::SizeVal() const
return val_mgr->Count(128); return val_mgr->Count(128);
} }
zeek::IntrusivePtr<Val> AddrVal::DoClone(CloneState* state) ValPtr AddrVal::DoClone(CloneState* state)
{ {
// Immutable. // Immutable.
return {zeek::NewRef{}, this}; return {zeek::NewRef{}, this};
@ -917,7 +917,7 @@ unsigned int SubNetVal::MemoryAllocation() const
return padded_sizeof(*this) + val.subnet_val->MemoryAllocation(); return padded_sizeof(*this) + val.subnet_val->MemoryAllocation();
} }
zeek::IntrusivePtr<Val> SubNetVal::SizeVal() const ValPtr SubNetVal::SizeVal() const
{ {
int retained = 128 - val.subnet_val->LengthIPv6(); int retained = 128 - val.subnet_val->LengthIPv6();
return zeek::make_intrusive<DoubleVal>(pow(2.0, double(retained))); return zeek::make_intrusive<DoubleVal>(pow(2.0, double(retained)));
@ -962,7 +962,7 @@ bool SubNetVal::Contains(const IPAddr& addr) const
return val.subnet_val->Contains(addr); return val.subnet_val->Contains(addr);
} }
zeek::IntrusivePtr<Val> SubNetVal::DoClone(CloneState* state) ValPtr SubNetVal::DoClone(CloneState* state)
{ {
// Immutable. // Immutable.
return {zeek::NewRef{}, this}; return {zeek::NewRef{}, this};
@ -986,7 +986,7 @@ StringVal::StringVal(const string& s) : StringVal(s.length(), s.data())
{ {
} }
zeek::IntrusivePtr<Val> StringVal::SizeVal() const ValPtr StringVal::SizeVal() const
{ {
return val_mgr->Count(val.string_val->Len()); 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(); return padded_sizeof(*this) + val.string_val->MemoryAllocation();
} }
zeek::IntrusivePtr<StringVal> StringVal::Replace( StringValPtr StringVal::Replace(
RE_Matcher* re, const BroString& repl, bool do_all) RE_Matcher* re, const BroString& repl, bool do_all)
{ {
const u_char* s = Bytes(); const u_char* s = Bytes();
@ -1118,7 +1118,7 @@ zeek::IntrusivePtr<StringVal> StringVal::Replace(
return zeek::make_intrusive<StringVal>(new BroString(true, result, r - result)); return zeek::make_intrusive<StringVal>(new BroString(true, result, r - result));
} }
zeek::IntrusivePtr<Val> StringVal::DoClone(CloneState* state) ValPtr StringVal::DoClone(CloneState* state)
{ {
// We could likely treat this type as immutable and return a reference // 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 // 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(); return padded_sizeof(*this) + val.re_val->MemoryAllocation();
} }
zeek::IntrusivePtr<Val> PatternVal::DoClone(CloneState* state) ValPtr PatternVal::DoClone(CloneState* state)
{ {
// We could likely treat this type as immutable and return a reference // 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 // instead of creating a new copy, but we first need to be careful and
@ -1197,7 +1197,7 @@ ListVal::~ListVal()
{ {
} }
zeek::IntrusivePtr<Val> ListVal::SizeVal() const ValPtr ListVal::SizeVal() const
{ {
return val_mgr->Count(vals.size()); return val_mgr->Count(vals.size());
} }
@ -1217,7 +1217,7 @@ RE_Matcher* ListVal::BuildRE() const
return re; return re;
} }
void ListVal::Append(zeek::IntrusivePtr<Val> v) void ListVal::Append(ValPtr v)
{ {
if ( type->AsTypeList()->IsPure() ) if ( type->AsTypeList()->IsPure() )
{ {
@ -1235,7 +1235,7 @@ void ListVal::Append(Val* v)
Append({zeek::AdoptRef{}, v}); Append({zeek::AdoptRef{}, v});
} }
zeek::IntrusivePtr<TableVal> ListVal::ToSetVal() const TableValPtr ListVal::ToSetVal() const
{ {
if ( tag == zeek::TYPE_ANY ) if ( tag == zeek::TYPE_ANY )
Internal("conversion of heterogeneous list to set"); Internal("conversion of heterogeneous list to set");
@ -1282,7 +1282,7 @@ void ListVal::Describe(ODesc* d) const
} }
} }
zeek::IntrusivePtr<Val> ListVal::DoClone(CloneState* state) ValPtr ListVal::DoClone(CloneState* state)
{ {
auto lv = zeek::make_intrusive<ListVal>(tag); auto lv = zeek::make_intrusive<ListVal>(tag);
lv->vals.reserve(vals.size()); lv->vals.reserve(vals.size());
@ -1336,7 +1336,7 @@ static void table_entry_val_delete_func(void* val)
delete tv; delete tv;
} }
static void find_nested_record_types(const zeek::IntrusivePtr<zeek::Type>& t, std::set<zeek::RecordType*>* found) static void find_nested_record_types(const zeek::TypePtr& t, std::set<zeek::RecordType*>* found)
{ {
if ( ! t ) if ( ! t )
return; return;
@ -1376,7 +1376,7 @@ static void find_nested_record_types(const zeek::IntrusivePtr<zeek::Type>& t, st
} }
} }
TableVal::TableVal(zeek::IntrusivePtr<zeek::TableType> t, zeek::IntrusivePtr<zeek::detail::Attributes> a) : Val(t) TableVal::TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr a) : Val(t)
{ {
Init(std::move(t)); Init(std::move(t));
SetAttrs(std::move(a)); SetAttrs(std::move(a));
@ -1396,7 +1396,7 @@ TableVal::TableVal(zeek::IntrusivePtr<zeek::TableType> t, zeek::IntrusivePtr<zee
} }
} }
void TableVal::Init(zeek::IntrusivePtr<zeek::TableType> t) void TableVal::Init(zeek::TableTypePtr t)
{ {
table_type = std::move(t); table_type = std::move(t);
expire_func = nullptr; expire_func = nullptr;
@ -1459,7 +1459,7 @@ int TableVal::RecursiveSize() const
return n; return n;
} }
void TableVal::SetAttrs(zeek::IntrusivePtr<zeek::detail::Attributes> a) void TableVal::SetAttrs(zeek::detail::AttributesPtr a)
{ {
attrs = std::move(a); attrs = std::move(a);
@ -1507,7 +1507,7 @@ void TableVal::CheckExpireAttr(zeek::detail::AttrTag at)
} }
} }
bool TableVal::Assign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val) bool TableVal::Assign(ValPtr index, ValPtr new_val)
{ {
auto k = MakeHashKey(*index); 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}); return Assign({zeek::NewRef{}, index}, {zeek::AdoptRef{}, new_val});
} }
bool TableVal::Assign(zeek::IntrusivePtr<Val> index, std::unique_ptr<HashKey> k, bool TableVal::Assign(ValPtr index, std::unique_ptr<HashKey> k,
zeek::IntrusivePtr<Val> new_val) ValPtr new_val)
{ {
bool is_set = table_type->IsSet(); 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<HashKey>{k}, {zeek::AdoptRef{}, new_val}); return Assign({zeek::NewRef{}, index}, std::unique_ptr<HashKey>{k}, {zeek::AdoptRef{}, new_val});
} }
zeek::IntrusivePtr<Val> TableVal::SizeVal() const ValPtr TableVal::SizeVal() const
{ {
return val_mgr->Count(Size()); return val_mgr->Count(Size());
} }
@ -1668,7 +1668,7 @@ bool TableVal::RemoveFrom(Val* val) const
return true; return true;
} }
zeek::IntrusivePtr<TableVal> TableVal::Intersection(const TableVal& tv) const TableValPtr TableVal::Intersection(const TableVal& tv) const
{ {
auto result = zeek::make_intrusive<TableVal>(table_type); auto result = zeek::make_intrusive<TableVal>(table_type);
@ -1753,7 +1753,7 @@ bool TableVal::IsSubsetOf(const TableVal& tv) const
return true; return true;
} }
bool TableVal::ExpandAndInit(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val) bool TableVal::ExpandAndInit(ValPtr index, ValPtr new_val)
{ {
const auto& index_type = index->GetType(); const auto& index_type = index->GetType();
@ -1805,7 +1805,7 @@ bool TableVal::ExpandAndInit(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<V
} }
zeek::IntrusivePtr<Val> TableVal::Default(const zeek::IntrusivePtr<Val>& index) ValPtr TableVal::Default(const ValPtr& index)
{ {
const auto& def_attr = GetAttr(zeek::detail::ATTR_DEFAULT); const auto& def_attr = GetAttr(zeek::detail::ATTR_DEFAULT);
@ -1870,7 +1870,7 @@ zeek::IntrusivePtr<Val> TableVal::Default(const zeek::IntrusivePtr<Val>& index)
else else
vl.emplace_back(index); vl.emplace_back(index);
zeek::IntrusivePtr<Val> result; ValPtr result;
try try
{ {
@ -1889,7 +1889,7 @@ zeek::IntrusivePtr<Val> TableVal::Default(const zeek::IntrusivePtr<Val>& index)
return result; return result;
} }
const zeek::IntrusivePtr<Val>& TableVal::Find(const zeek::IntrusivePtr<Val>& index) const ValPtr& TableVal::Find(const ValPtr& index)
{ {
if ( subnets ) if ( subnets )
{ {
@ -1934,7 +1934,7 @@ const zeek::IntrusivePtr<Val>& TableVal::Find(const zeek::IntrusivePtr<Val>& ind
return Val::nil; return Val::nil;
} }
zeek::IntrusivePtr<Val> TableVal::FindOrDefault(const zeek::IntrusivePtr<Val>& index) ValPtr TableVal::FindOrDefault(const ValPtr& index)
{ {
if ( auto rval = Find(index) ) if ( auto rval = Find(index) )
return rval; return rval;
@ -1944,9 +1944,9 @@ zeek::IntrusivePtr<Val> TableVal::FindOrDefault(const zeek::IntrusivePtr<Val>& i
Val* TableVal::Lookup(Val* index, bool use_default_val) Val* TableVal::Lookup(Val* index, bool use_default_val)
{ {
static zeek::IntrusivePtr<Val> last_default; static ValPtr last_default;
last_default = nullptr; last_default = nullptr;
zeek::IntrusivePtr<Val> idx{zeek::NewRef{}, index}; ValPtr idx{zeek::NewRef{}, index};
if ( const auto& rval = Find(idx) ) if ( const auto& rval = Find(idx) )
return rval.get(); return rval.get();
@ -1958,7 +1958,7 @@ Val* TableVal::Lookup(Val* index, bool use_default_val)
return last_default.get(); return last_default.get();
} }
zeek::IntrusivePtr<VectorVal> TableVal::LookupSubnets(const SubNetVal* search) VectorValPtr TableVal::LookupSubnets(const SubNetVal* search)
{ {
if ( ! subnets ) if ( ! subnets )
reporter->InternalError("LookupSubnets called on wrong table type"); reporter->InternalError("LookupSubnets called on wrong table type");
@ -1972,7 +1972,7 @@ zeek::IntrusivePtr<VectorVal> TableVal::LookupSubnets(const SubNetVal* search)
return result; return result;
} }
zeek::IntrusivePtr<TableVal> TableVal::LookupSubnetValues(const SubNetVal* search) TableValPtr TableVal::LookupSubnetValues(const SubNetVal* search)
{ {
if ( ! subnets ) if ( ! subnets )
reporter->InternalError("LookupSubnetValues called on wrong table type"); reporter->InternalError("LookupSubnetValues called on wrong table type");
@ -2024,13 +2024,13 @@ bool TableVal::UpdateTimestamp(Val* index)
return true; return true;
} }
zeek::IntrusivePtr<ListVal> TableVal::RecreateIndex(const HashKey& k) const ListValPtr TableVal::RecreateIndex(const HashKey& k) const
{ {
return table_hash->RecoverVals(k); return table_hash->RecoverVals(k);
} }
void TableVal::CallChangeFunc(const Val* index, void TableVal::CallChangeFunc(const Val* index,
const zeek::IntrusivePtr<Val>& old_value, const ValPtr& old_value,
OnChangeType tpe) OnChangeType tpe)
{ {
if ( ! change_func || ! index || in_change_func ) if ( ! change_func || ! index || in_change_func )
@ -2092,11 +2092,11 @@ void TableVal::CallChangeFunc(const Val* index,
in_change_func = false; in_change_func = false;
} }
zeek::IntrusivePtr<Val> TableVal::Remove(const Val& index) ValPtr TableVal::Remove(const Val& index)
{ {
auto k = MakeHashKey(index); auto k = MakeHashKey(index);
TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k.get()) : nullptr; TableEntryVal* v = k ? AsNonConstTable()->RemoveEntry(k.get()) : nullptr;
zeek::IntrusivePtr<Val> va; ValPtr va;
if ( v ) if ( v )
va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this}; va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this};
@ -2114,10 +2114,10 @@ zeek::IntrusivePtr<Val> TableVal::Remove(const Val& index)
return va; return va;
} }
zeek::IntrusivePtr<Val> TableVal::Remove(const HashKey& k) ValPtr TableVal::Remove(const HashKey& k)
{ {
TableEntryVal* v = AsNonConstTable()->RemoveEntry(k); TableEntryVal* v = AsNonConstTable()->RemoveEntry(k);
zeek::IntrusivePtr<Val> va; ValPtr va;
if ( v ) if ( v )
va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this}; va = v->GetVal() ? v->GetVal() : zeek::IntrusivePtr{zeek::NewRef{}, this};
@ -2143,7 +2143,7 @@ zeek::IntrusivePtr<Val> TableVal::Remove(const HashKey& k)
return va; return va;
} }
zeek::IntrusivePtr<ListVal> TableVal::ToListVal(zeek::TypeTag t) const ListValPtr TableVal::ToListVal(zeek::TypeTag t) const
{ {
auto l = zeek::make_intrusive<ListVal>(t); auto l = zeek::make_intrusive<ListVal>(t);
@ -2177,7 +2177,7 @@ ListVal* TableVal::ConvertToList(zeek::TypeTag t) const
return ToListVal().release(); return ToListVal().release();
} }
zeek::IntrusivePtr<ListVal> TableVal::ToPureListVal() const ListValPtr TableVal::ToPureListVal() const
{ {
const auto& tl = table_type->GetIndices()->GetTypes(); const auto& tl = table_type->GetIndices()->GetTypes();
if ( tl.size() != 1 ) if ( tl.size() != 1 )
@ -2194,7 +2194,7 @@ ListVal* TableVal::ConvertToPureList() const
return ToPureListVal().release(); return ToPureListVal().release();
} }
const zeek::IntrusivePtr<zeek::detail::Attr>& 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; 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<Val> new_val) bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, ValPtr new_val)
{ {
Val* ind_k_v = lv->Idx(k).get(); Val* ind_k_v = lv->Idx(k).get();
auto ind_k = ind_k_v->GetType()->IsSet() ? auto ind_k = ind_k_v->GetType()->IsSet() ?
ind_k_v->AsTableVal()->ToListVal() : ind_k_v->AsTableVal()->ToListVal() :
zeek::IntrusivePtr<ListVal>{zeek::NewRef{}, ind_k_v->AsListVal()}; ListValPtr{zeek::NewRef{}, ind_k_v->AsListVal()};
for ( int i = 0; i < ind_k->Length(); ++i ) for ( int i = 0; i < ind_k->Length(); ++i )
{ {
@ -2314,7 +2314,7 @@ bool TableVal::ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr<Val>
return true; return true;
} }
bool TableVal::CheckAndAssign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val) bool TableVal::CheckAndAssign(ValPtr index, ValPtr new_val)
{ {
Val* v = nullptr; Val* v = nullptr;
if ( subnets ) if ( subnets )
@ -2397,7 +2397,7 @@ void TableVal::DoExpire(double t)
else if ( v->ExpireAccessTime() + timeout < t ) else if ( v->ExpireAccessTime() + timeout < t )
{ {
zeek::IntrusivePtr<ListVal> idx = nullptr; ListValPtr idx = nullptr;
if ( expire_func ) if ( expire_func )
{ {
@ -2491,7 +2491,7 @@ double TableVal::GetExpireTime()
return -1; return -1;
} }
double TableVal::CallExpireFunc(zeek::IntrusivePtr<ListVal> idx) double TableVal::CallExpireFunc(ListValPtr idx)
{ {
if ( ! expire_func ) if ( ! expire_func )
return 0; return 0;
@ -2554,7 +2554,7 @@ double TableVal::CallExpireFunc(zeek::IntrusivePtr<ListVal> idx)
return secs; return secs;
} }
zeek::IntrusivePtr<Val> TableVal::DoClone(CloneState* state) ValPtr TableVal::DoClone(CloneState* state)
{ {
auto tv = zeek::make_intrusive<TableVal>(table_type); auto tv = zeek::make_intrusive<TableVal>(table_type);
state->NewClone(this, tv); state->NewClone(this, tv);
@ -2691,12 +2691,12 @@ RecordVal::RecordVal(zeek::RecordType* t, bool init_fields)
: RecordVal({zeek::NewRef{}, t}, init_fields) : RecordVal({zeek::NewRef{}, t}, init_fields)
{} {}
RecordVal::RecordVal(zeek::IntrusivePtr<zeek::RecordType> t, bool init_fields) : Val(std::move(t)) RecordVal::RecordVal(zeek::RecordTypePtr t, bool init_fields) : Val(std::move(t))
{ {
origin = nullptr; origin = nullptr;
auto rt = GetType()->AsRecordType(); auto rt = GetType()->AsRecordType();
int n = rt->NumFields(); int n = rt->NumFields();
auto vl = val.record_val = new std::vector<zeek::IntrusivePtr<Val>>; auto vl = val.record_val = new std::vector<ValPtr>;
vl->reserve(n); vl->reserve(n);
if ( is_parsing ) if ( is_parsing )
@ -2733,7 +2733,7 @@ RecordVal::RecordVal(zeek::IntrusivePtr<zeek::RecordType> t, bool init_fields) :
else if ( tag == zeek::TYPE_TABLE ) else if ( tag == zeek::TYPE_TABLE )
def = zeek::make_intrusive<TableVal>(zeek::IntrusivePtr{zeek::NewRef{}, type->AsTableType()}, def = zeek::make_intrusive<TableVal>(zeek::IntrusivePtr{zeek::NewRef{}, type->AsTableType()},
zeek::IntrusivePtr{zeek::NewRef{}, a}); zeek::IntrusivePtr{zeek::NewRef{}, a});
else if ( tag == zeek::TYPE_VECTOR ) else if ( tag == zeek::TYPE_VECTOR )
def = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<zeek::VectorType>(type)); def = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<zeek::VectorType>(type));
@ -2748,12 +2748,12 @@ RecordVal::~RecordVal()
delete AsNonConstRecord(); delete AsNonConstRecord();
} }
zeek::IntrusivePtr<Val> RecordVal::SizeVal() const ValPtr RecordVal::SizeVal() const
{ {
return val_mgr->Count(GetType()->AsRecordType()->NumFields()); return val_mgr->Count(GetType()->AsRecordType()->NumFields());
} }
void RecordVal::Assign(int field, zeek::IntrusivePtr<Val> new_val) void RecordVal::Assign(int field, ValPtr new_val)
{ {
(*AsNonConstRecord())[field] = std::move(new_val); (*AsNonConstRecord())[field] = std::move(new_val);
Modified(); Modified();
@ -2764,7 +2764,7 @@ void RecordVal::Assign(int field, Val* new_val)
Assign(field, {zeek::AdoptRef{}, new_val}); Assign(field, {zeek::AdoptRef{}, new_val});
} }
zeek::IntrusivePtr<Val> RecordVal::GetFieldOrDefault(int field) const ValPtr RecordVal::GetFieldOrDefault(int field) const
{ {
const auto& val = (*AsRecord())[field]; const auto& val = (*AsRecord())[field];
@ -2804,7 +2804,7 @@ void RecordVal::DoneParsing()
parse_time_records.clear(); parse_time_records.clear();
} }
const zeek::IntrusivePtr<Val>& RecordVal::GetField(const char* field) const const ValPtr& RecordVal::GetField(const char* field) const
{ {
int idx = GetType()->AsRecordType()->FieldOffset(field); int idx = GetType()->AsRecordType()->FieldOffset(field);
@ -2814,7 +2814,7 @@ const zeek::IntrusivePtr<Val>& RecordVal::GetField(const char* field) const
return GetField(idx); return GetField(idx);
} }
zeek::IntrusivePtr<Val> RecordVal::GetFieldOrDefault(const char* field) const ValPtr RecordVal::GetFieldOrDefault(const char* field) const
{ {
int idx = GetType()->AsRecordType()->FieldOffset(field); int idx = GetType()->AsRecordType()->FieldOffset(field);
@ -2824,10 +2824,9 @@ zeek::IntrusivePtr<Val> RecordVal::GetFieldOrDefault(const char* field) const
return GetFieldOrDefault(idx); return GetFieldOrDefault(idx);
} }
zeek::IntrusivePtr<RecordVal> RecordVal::CoerceTo( RecordValPtr RecordVal::CoerceTo(zeek::RecordTypePtr t,
zeek::IntrusivePtr<zeek::RecordType> t, RecordValPtr aggr,
zeek::IntrusivePtr<RecordVal> aggr, bool allow_orphaning) const
bool allow_orphaning) const
{ {
if ( ! record_promotion_compatible(t.get(), GetType()->AsRecordType()) ) if ( ! record_promotion_compatible(t.get(), GetType()->AsRecordType()) )
return nullptr; return nullptr;
@ -2889,8 +2888,7 @@ zeek::IntrusivePtr<RecordVal> RecordVal::CoerceTo(
return aggr; return aggr;
} }
zeek::IntrusivePtr<RecordVal> RecordVal::CoerceTo(zeek::IntrusivePtr<zeek::RecordType> t, RecordValPtr RecordVal::CoerceTo(zeek::RecordTypePtr t, bool allow_orphaning)
bool allow_orphaning)
{ {
if ( same_type(GetType(), t) ) if ( same_type(GetType(), t) )
return {zeek::NewRef{}, this}; return {zeek::NewRef{}, this};
@ -2898,7 +2896,7 @@ zeek::IntrusivePtr<RecordVal> RecordVal::CoerceTo(zeek::IntrusivePtr<zeek::Recor
return CoerceTo(std::move(t), nullptr, allow_orphaning); return CoerceTo(std::move(t), nullptr, allow_orphaning);
} }
zeek::IntrusivePtr<TableVal> RecordVal::GetRecordFieldsVal() const TableValPtr RecordVal::GetRecordFieldsVal() const
{ {
return GetType()->AsRecordType()->GetRecordFieldsVal(this); return GetType()->AsRecordType()->GetRecordFieldsVal(this);
} }
@ -2970,7 +2968,7 @@ void RecordVal::DescribeReST(ODesc* d) const
d->Add("}"); d->Add("}");
} }
zeek::IntrusivePtr<Val> RecordVal::DoClone(CloneState* state) ValPtr RecordVal::DoClone(CloneState* state)
{ {
// We set origin to 0 here. Origin only seems to be used for exactly one // 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 // purpose - to find the connection record that is associated with a
@ -3001,12 +2999,12 @@ unsigned int RecordVal::MemoryAllocation() const
size += v->MemoryAllocation(); size += v->MemoryAllocation();
} }
size += pad_size(vl.capacity() * sizeof(zeek::IntrusivePtr<Val>)); size += pad_size(vl.capacity() * sizeof(ValPtr));
size += padded_sizeof(vl); size += padded_sizeof(vl);
return size + padded_sizeof(*this); return size + padded_sizeof(*this);
} }
zeek::IntrusivePtr<Val> EnumVal::SizeVal() const ValPtr EnumVal::SizeVal() const
{ {
return val_mgr->Int(val.int_val); return val_mgr->Int(val.int_val);
} }
@ -3021,7 +3019,7 @@ void EnumVal::ValDescribe(ODesc* d) const
d->Add(ename); d->Add(ename);
} }
zeek::IntrusivePtr<Val> EnumVal::DoClone(CloneState* state) ValPtr EnumVal::DoClone(CloneState* state)
{ {
// Immutable. // Immutable.
return {zeek::NewRef{}, this}; return {zeek::NewRef{}, this};
@ -3030,9 +3028,9 @@ zeek::IntrusivePtr<Val> EnumVal::DoClone(CloneState* state)
VectorVal::VectorVal(zeek::VectorType* t) : VectorVal({zeek::NewRef{}, t}) VectorVal::VectorVal(zeek::VectorType* t) : VectorVal({zeek::NewRef{}, t})
{ } { }
VectorVal::VectorVal(zeek::IntrusivePtr<zeek::VectorType> t) : Val(std::move(t)) VectorVal::VectorVal(zeek::VectorTypePtr t) : Val(std::move(t))
{ {
val.vector_val = new vector<zeek::IntrusivePtr<Val>>(); val.vector_val = new vector<ValPtr>();
} }
VectorVal::~VectorVal() VectorVal::~VectorVal()
@ -3040,12 +3038,12 @@ VectorVal::~VectorVal()
delete val.vector_val; delete val.vector_val;
} }
zeek::IntrusivePtr<Val> VectorVal::SizeVal() const ValPtr VectorVal::SizeVal() const
{ {
return val_mgr->Count(uint32_t(val.vector_val->size())); return val_mgr->Count(uint32_t(val.vector_val->size()));
} }
bool VectorVal::Assign(unsigned int index, zeek::IntrusivePtr<Val> element) bool VectorVal::Assign(unsigned int index, ValPtr element)
{ {
if ( element && if ( element &&
! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) )
@ -3061,7 +3059,7 @@ bool VectorVal::Assign(unsigned int index, zeek::IntrusivePtr<Val> element)
} }
bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
zeek::IntrusivePtr<Val> element) ValPtr element)
{ {
ResizeAtLeast(index + how_many); ResizeAtLeast(index + how_many);
@ -3072,7 +3070,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many,
return true; return true;
} }
bool VectorVal::Insert(unsigned int index, zeek::IntrusivePtr<Val> element) bool VectorVal::Insert(unsigned int index, ValPtr element)
{ {
if ( element && if ( element &&
! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) ) ! same_type(element->GetType(), GetType()->AsVectorType()->Yield(), false) )
@ -3080,7 +3078,7 @@ bool VectorVal::Insert(unsigned int index, zeek::IntrusivePtr<Val> element)
return false; return false;
} }
vector<zeek::IntrusivePtr<Val>>::iterator it; vector<ValPtr>::iterator it;
if ( index < val.vector_val->size() ) if ( index < val.vector_val->size() )
it = std::next(val.vector_val->begin(), index); it = std::next(val.vector_val->begin(), index);
@ -3129,7 +3127,7 @@ bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const
return true; return true;
} }
const zeek::IntrusivePtr<Val>& VectorVal::At(unsigned int index) const const ValPtr& VectorVal::At(unsigned int index) const
{ {
if ( index >= val.vector_val->size() ) if ( index >= val.vector_val->size() )
return Val::nil; return Val::nil;
@ -3154,7 +3152,7 @@ unsigned int VectorVal::ResizeAtLeast(unsigned int new_num_elements)
return Resize(new_num_elements); return Resize(new_num_elements);
} }
zeek::IntrusivePtr<Val> VectorVal::DoClone(CloneState* state) ValPtr VectorVal::DoClone(CloneState* state)
{ {
auto vv = zeek::make_intrusive<VectorVal>(GetType<zeek::VectorType>()); auto vv = zeek::make_intrusive<VectorVal>(GetType<zeek::VectorType>());
vv->val.vector_val->reserve(val.vector_val->size()); vv->val.vector_val->reserve(val.vector_val->size());
@ -3188,10 +3186,10 @@ void VectorVal::ValDescribe(ODesc* d) const
d->Add("]"); d->Add("]");
} }
zeek::IntrusivePtr<Val> check_and_promote(zeek::IntrusivePtr<Val> v, ValPtr check_and_promote(ValPtr v,
const zeek::Type* t, const zeek::Type* t,
bool is_init, bool is_init,
const Location* expr_location) const Location* expr_location)
{ {
if ( ! v ) if ( ! v )
return nullptr; return nullptr;
@ -3248,7 +3246,7 @@ zeek::IntrusivePtr<Val> check_and_promote(zeek::IntrusivePtr<Val> v,
// Already has the right internal type. // Already has the right internal type.
return v; return v;
zeek::IntrusivePtr<Val> promoted_v; ValPtr promoted_v;
switch ( it ) { switch ( it ) {
case zeek::TYPE_INTERNAL_INT: 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<zeek::IntrusivePtr<Val>>& vals, void describe_vals(const std::vector<ValPtr>& vals,
ODesc* d, size_t offset) ODesc* d, size_t offset)
{ {
if ( ! d->IsReadable() ) if ( ! d->IsReadable() )
@ -3393,7 +3391,7 @@ void delete_vals(val_list* vals)
} }
} }
zeek::IntrusivePtr<Val> 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 // Note: when changing this function, adapt all three of
// cast_value_to_type()/can_cast_value_to_type()/can_cast_value_to_type(). // 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; return false;
} }
zeek::IntrusivePtr<Val> Val::MakeBool(bool b) ValPtr Val::MakeBool(bool b)
{ {
return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(bro_int_t(b), zeek::TYPE_BOOL)}; return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(bro_int_t(b), zeek::TYPE_BOOL)};
} }
zeek::IntrusivePtr<Val> Val::MakeInt(bro_int_t i) ValPtr Val::MakeInt(bro_int_t i)
{ {
return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(i, zeek::TYPE_INT)}; return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(i, zeek::TYPE_INT)};
} }
zeek::IntrusivePtr<Val> Val::MakeCount(bro_uint_t u) ValPtr Val::MakeCount(bro_uint_t u)
{ {
return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(u, zeek::TYPE_COUNT)}; return zeek::IntrusivePtr{zeek::AdoptRef{}, new Val(u, zeek::TYPE_COUNT)};
} }
@ -3506,7 +3504,7 @@ StringVal* ValManager::GetEmptyString() const
return empty_string->Ref()->AsStringVal(); return empty_string->Ref()->AsStringVal();
} }
const zeek::IntrusivePtr<PortVal>& 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 ) 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(); return Port(port_num, port_type)->Ref()->AsPortVal();
} }
const zeek::IntrusivePtr<PortVal>& ValManager::Port(uint32_t port_num) const const PortValPtr& ValManager::Port(uint32_t port_num) const
{ {
auto mask = port_num & PORT_SPACE_MASK; auto mask = port_num & PORT_SPACE_MASK;
port_num &= ~PORT_SPACE_MASK; port_num &= ~PORT_SPACE_MASK;

265
src/Val.h
View file

@ -34,6 +34,9 @@ class Func;
class BroFile; class BroFile;
class PrefixTable; class PrefixTable;
using BroFilePtr = zeek::IntrusivePtr<BroFile>;
using FuncPtr = zeek::IntrusivePtr<Func>;
class Val; class Val;
class PortVal; class PortVal;
class AddrVal; class AddrVal;
@ -49,6 +52,16 @@ class OpaqueVal;
class VectorVal; class VectorVal;
class TableEntryVal; class TableEntryVal;
using AddrValPtr = zeek::IntrusivePtr<AddrVal>;
using EnumValPtr = zeek::IntrusivePtr<EnumVal>;
using ListValPtr = zeek::IntrusivePtr<ListVal>;
using PortValPtr = zeek::IntrusivePtr<PortVal>;
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
using StringValPtr = zeek::IntrusivePtr<StringVal>;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
using ValPtr = zeek::IntrusivePtr<Val>;
using VectorValPtr = zeek::IntrusivePtr<VectorVal>;
class IPAddr; class IPAddr;
class IPPrefix; class IPPrefix;
@ -77,8 +90,8 @@ union BroValUnion {
BroFile* file_val; BroFile* file_val;
RE_Matcher* re_val; RE_Matcher* re_val;
PDict<TableEntryVal>* table_val; PDict<TableEntryVal>* table_val;
std::vector<zeek::IntrusivePtr<Val>>* record_val; std::vector<ValPtr>* record_val;
std::vector<zeek::IntrusivePtr<Val>>* vector_val; std::vector<ValPtr>* vector_val;
BroValUnion() = default; BroValUnion() = default;
@ -115,7 +128,7 @@ union BroValUnion {
class Val : public BroObj { class Val : public BroObj {
public: public:
static inline const zeek::IntrusivePtr<Val> nil; static inline const ValPtr nil;
[[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]] [[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]]
Val(double d, zeek::TypeTag t) Val(double d, zeek::TypeTag t)
@ -124,16 +137,16 @@ public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit Val(Func* f); explicit Val(Func* f);
explicit Val(zeek::IntrusivePtr<Func> f); explicit Val(FuncPtr f);
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit Val(BroFile* f); explicit Val(BroFile* f);
// Note, the file will be closed after this Val is destructed if there's // Note, the file will be closed after this Val is destructed if there's
// no other remaining references. // no other remaining references.
explicit Val(zeek::IntrusivePtr<BroFile> f); explicit Val(BroFilePtr f);
// Extra arg to differentiate from protected version. // Extra arg to differentiate from protected version.
Val(zeek::IntrusivePtr<zeek::Type> t, bool type_type) Val(zeek::TypePtr t, bool type_type)
: type(zeek::make_intrusive<zeek::TypeType>(std::move(t))) : type(zeek::make_intrusive<zeek::TypeType>(std::move(t)))
{} {}
@ -148,7 +161,7 @@ public:
~Val() override; ~Val() override;
Val* Ref() { ::Ref(this); return this; } Val* Ref() { ::Ref(this); return this; }
zeek::IntrusivePtr<Val> Clone(); ValPtr Clone();
bool IsZero() const; bool IsZero() const;
bool IsOne() const; bool IsOne() const;
@ -163,7 +176,7 @@ public:
// Returns a new Val with the "size" of this Val. What constitutes // Returns a new Val with the "size" of this Val. What constitutes
// size depends on the Val's type. // size depends on the Val's type.
virtual zeek::IntrusivePtr<Val> SizeVal() const; virtual ValPtr SizeVal() const;
// Bytes in total value object. // Bytes in total value object.
virtual unsigned int MemoryAllocation() const; virtual unsigned int MemoryAllocation() const;
@ -182,7 +195,7 @@ public:
[[deprecated("Remove in v4.1. Use GetType().")]] [[deprecated("Remove in v4.1. Use GetType().")]]
const zeek::Type* Type() const { return type.get(); } const zeek::Type* Type() const { return type.get(); }
const zeek::IntrusivePtr<zeek::Type>& GetType() const const zeek::TypePtr& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
@ -215,10 +228,10 @@ public:
CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString)
CONST_ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc) CONST_ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
CONST_ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable) CONST_ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable)
CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, record_val, AsRecord) CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsRecord)
CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector) CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<ValPtr>*, vector_val, AsVector)
const IPPrefix& AsSubNet() const const IPPrefix& AsSubNet() const
{ {
@ -252,9 +265,9 @@ public:
ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc) ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector) ACCESSOR(zeek::TYPE_VECTOR, std::vector<ValPtr>*, vector_val, AsVector)
zeek::IntrusivePtr<Func> AsFuncPtr() const; FuncPtr AsFuncPtr() const;
const IPPrefix& AsSubNet() const IPPrefix& AsSubNet()
{ {
@ -328,9 +341,9 @@ public:
static bool WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, const Val* val); static bool WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, const Val* val);
zeek::IntrusivePtr<TableVal> GetRecordFields(); TableValPtr GetRecordFields();
zeek::IntrusivePtr<StringVal> ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr); StringValPtr ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
protected: protected:
@ -344,9 +357,9 @@ protected:
virtual void ValDescribe(ODesc* d) const; virtual void ValDescribe(ODesc* d) const;
virtual void ValDescribeReST(ODesc* d) const; virtual void ValDescribeReST(ODesc* d) const;
static zeek::IntrusivePtr<Val> MakeBool(bool b); static ValPtr MakeBool(bool b);
static zeek::IntrusivePtr<Val> MakeInt(bro_int_t i); static ValPtr MakeInt(bro_int_t i);
static zeek::IntrusivePtr<Val> MakeCount(bro_uint_t u); static ValPtr MakeCount(bro_uint_t u);
template<typename V> template<typename V>
Val(V&& v, zeek::TypeTag t) noexcept Val(V&& v, zeek::TypeTag t) noexcept
@ -354,32 +367,32 @@ protected:
{} {}
template<typename V> template<typename V>
Val(V&& v, zeek::IntrusivePtr<zeek::Type> t) noexcept Val(V&& v, zeek::TypePtr t) noexcept
: val(std::forward<V>(v)), type(std::move(t)) : val(std::forward<V>(v)), type(std::move(t))
{} {}
explicit Val(zeek::IntrusivePtr<zeek::Type> t) noexcept explicit Val(zeek::TypePtr t) noexcept
: type(std::move(t)) : type(std::move(t))
{} {}
ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable) ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable)
ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, record_val, AsNonConstRecord) ACCESSOR(zeek::TYPE_RECORD, std::vector<ValPtr>*, record_val, AsNonConstRecord)
// For internal use by the Val::Clone() methods. // For internal use by the Val::Clone() methods.
struct CloneState { struct CloneState {
// Caches a cloned value for later reuse during the same // Caches a cloned value for later reuse during the same
// cloning operation. For recursive types, call this *before* // cloning operation. For recursive types, call this *before*
// descending down. // descending down.
zeek::IntrusivePtr<Val> NewClone(Val* src, zeek::IntrusivePtr<Val> dst); ValPtr NewClone(Val* src, ValPtr dst);
std::unordered_map<Val*, Val*> clones; std::unordered_map<Val*, Val*> clones;
}; };
zeek::IntrusivePtr<Val> Clone(CloneState* state); ValPtr Clone(CloneState* state);
virtual zeek::IntrusivePtr<Val> DoClone(CloneState* state); virtual ValPtr DoClone(CloneState* state);
BroValUnion val; BroValUnion val;
zeek::IntrusivePtr<zeek::Type> type; zeek::TypePtr type;
#ifdef DEBUG #ifdef DEBUG
// For debugging, we keep the name of the ID to which a Val is bound. // For debugging, we keep the name of the ID to which a Val is bound.
@ -405,21 +418,21 @@ public:
inline Val* GetTrue() const inline Val* GetTrue() const
{ return b_true->Ref(); } { return b_true->Ref(); }
inline const zeek::IntrusivePtr<Val>& True() const inline const ValPtr& True() const
{ return b_true; } { return b_true; }
[[deprecated("Remove in v4.1. Use val_mgr->False() instead.")]] [[deprecated("Remove in v4.1. Use val_mgr->False() instead.")]]
inline Val* GetFalse() const inline Val* GetFalse() const
{ return b_false->Ref(); } { return b_false->Ref(); }
inline const zeek::IntrusivePtr<Val>& False() const inline const ValPtr& False() const
{ return b_false; } { return b_false; }
[[deprecated("Remove in v4.1. Use val_mgr->Bool() instead.")]] [[deprecated("Remove in v4.1. Use val_mgr->Bool() instead.")]]
inline Val* GetBool(bool b) const inline Val* GetBool(bool b) const
{ return b ? b_true->Ref() : b_false->Ref(); } { return b ? b_true->Ref() : b_false->Ref(); }
inline const zeek::IntrusivePtr<Val>& Bool(bool b) const inline const ValPtr& Bool(bool b) const
{ return b ? b_true : b_false; } { return b ? b_true : b_false; }
[[deprecated("Remove in v4.1. Use val_mgr->Int() instead.")]] [[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(); Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref();
} }
inline zeek::IntrusivePtr<Val> Int(int64_t i) const inline ValPtr Int(int64_t i) const
{ {
return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ? return i < PREALLOCATED_INT_LOWEST || i > PREALLOCATED_INT_HIGHEST ?
Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST]; Val::MakeInt(i) : ints[i - PREALLOCATED_INT_LOWEST];
@ -441,7 +454,7 @@ public:
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i).release() : counts[i]->Ref(); return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i).release() : counts[i]->Ref();
} }
inline zeek::IntrusivePtr<Val> Count(uint64_t i) const inline ValPtr Count(uint64_t i) const
{ {
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i]; return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i];
} }
@ -449,7 +462,7 @@ public:
[[deprecated("Remove in v4.1. Use val_mgr->EmptyString() instead.")]] [[deprecated("Remove in v4.1. Use val_mgr->EmptyString() instead.")]]
StringVal* GetEmptyString() const; StringVal* GetEmptyString() const;
inline const zeek::IntrusivePtr<StringVal>& EmptyString() const inline const StringValPtr& EmptyString() const
{ return empty_string; } { return empty_string; }
// Port number given in host order. // Port number given in host order.
@ -457,23 +470,23 @@ public:
PortVal* GetPort(uint32_t port_num, TransportProto port_type) const; PortVal* GetPort(uint32_t port_num, TransportProto port_type) const;
// Port number given in host order. // Port number given in host order.
const zeek::IntrusivePtr<PortVal>& 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. // Host-order port number already masked with port space protocol mask.
[[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]] [[deprecated("Remove in v4.1. Use val_mgr->Port() instead.")]]
PortVal* GetPort(uint32_t port_num) const; PortVal* GetPort(uint32_t port_num) const;
// Host-order port number already masked with port space protocol mask. // Host-order port number already masked with port space protocol mask.
const zeek::IntrusivePtr<PortVal>& Port(uint32_t port_num) const; const PortValPtr& Port(uint32_t port_num) const;
private: private:
std::array<std::array<zeek::IntrusivePtr<PortVal>, 65536>, NUM_PORT_SPACES> ports; std::array<std::array<PortValPtr, 65536>, NUM_PORT_SPACES> ports;
std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_COUNTS> counts; std::array<ValPtr, PREALLOCATED_COUNTS> counts;
std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_INTS> ints; std::array<ValPtr, PREALLOCATED_INTS> ints;
zeek::IntrusivePtr<StringVal> empty_string; StringValPtr empty_string;
zeek::IntrusivePtr<Val> b_true; ValPtr b_true;
zeek::IntrusivePtr<Val> b_false; ValPtr b_false;
}; };
extern ValManager* val_mgr; extern ValManager* val_mgr;
@ -511,7 +524,7 @@ public:
class PortVal final : public Val { class PortVal final : public Val {
public: public:
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
// Returns the port number in host order (not including the mask). // Returns the port number in host order (not including the mask).
uint32_t Port() const; uint32_t Port() const;
@ -542,7 +555,7 @@ protected:
PortVal(uint32_t p); PortVal(uint32_t p);
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
class AddrVal final : public Val { class AddrVal final : public Val {
@ -551,7 +564,7 @@ public:
explicit AddrVal(const std::string& text); explicit AddrVal(const std::string& text);
~AddrVal() override; ~AddrVal() override;
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
// Constructor for address already in network order. // Constructor for address already in network order.
explicit AddrVal(uint32_t addr); // IPv4. explicit AddrVal(uint32_t addr); // IPv4.
@ -561,7 +574,7 @@ public:
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
class SubNetVal final : public Val { class SubNetVal final : public Val {
@ -574,7 +587,7 @@ public:
explicit SubNetVal(const IPPrefix& prefix); explicit SubNetVal(const IPPrefix& prefix);
~SubNetVal() override; ~SubNetVal() override;
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
const IPAddr& Prefix() const; const IPAddr& Prefix() const;
int Width() const; int Width() const;
@ -586,7 +599,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
class StringVal final : public Val { class StringVal final : public Val {
@ -596,7 +609,7 @@ public:
explicit StringVal(const std::string& s); explicit StringVal(const std::string& s);
StringVal(int length, const char* s); StringVal(int length, const char* s);
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
int Len(); int Len();
const u_char* Bytes(); const u_char* Bytes();
@ -612,7 +625,7 @@ public:
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
zeek::IntrusivePtr<StringVal> Replace(RE_Matcher* re, const BroString& repl, StringValPtr Replace(RE_Matcher* re, const BroString& repl,
bool do_all); bool do_all);
[[deprecated("Remove in v4.1. Use Replace().")]] [[deprecated("Remove in v4.1. Use Replace().")]]
@ -621,7 +634,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
class PatternVal final : public Val { class PatternVal final : public Val {
@ -637,7 +650,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
// ListVals are mainly used to index tables that have more than one // ListVals are mainly used to index tables that have more than one
@ -650,11 +663,11 @@ public:
zeek::TypeTag BaseTag() const { return tag; } zeek::TypeTag BaseTag() const { return tag; }
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
int Length() const { return vals.size(); } int Length() const { return vals.size(); }
const zeek::IntrusivePtr<Val>& 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")]] [[deprecated("Remove in v4.1. Use Idx() instead")]]
Val* Index(const int n) { return vals[n].get(); } Val* Index(const int n) { return vals[n].get(); }
@ -675,27 +688,27 @@ public:
* Appends a value to the list. * Appends a value to the list.
* @param v the value to append. * @param v the value to append.
*/ */
void Append(zeek::IntrusivePtr<Val> v); void Append(ValPtr v);
[[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]] [[deprecated("Remove in v4.1. Use Append(IntrusivePtr) instead.")]]
void Append(Val* v); void Append(Val* v);
// Returns a Set representation of the list (which must be homogeneous). // Returns a Set representation of the list (which must be homogeneous).
zeek::IntrusivePtr<TableVal> ToSetVal() const; TableValPtr ToSetVal() const;
[[deprecated("Remove in v4.1. Use ToSetVal() instead.")]] [[deprecated("Remove in v4.1. Use ToSetVal() instead.")]]
TableVal* ConvertToSet() const; TableVal* ConvertToSet() const;
const std::vector<zeek::IntrusivePtr<Val>>& Vals() const { return vals; } const std::vector<ValPtr>& Vals() const { return vals; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
std::vector<zeek::IntrusivePtr<Val>> vals; std::vector<ValPtr> vals;
zeek::TypeTag tag; zeek::TypeTag tag;
}; };
@ -703,7 +716,7 @@ extern double bro_start_network_time;
class TableEntryVal { class TableEntryVal {
public: public:
explicit TableEntryVal(zeek::IntrusivePtr<Val> v) explicit TableEntryVal(ValPtr v)
: val(std::move(v)) : val(std::move(v))
{ {
expire_access_time = expire_access_time =
@ -715,7 +728,7 @@ public:
[[deprecated("Remove in v4.1. Use GetVal().")]] [[deprecated("Remove in v4.1. Use GetVal().")]]
Val* Value() { return val.get(); } Val* Value() { return val.get(); }
const zeek::IntrusivePtr<Val>& GetVal() const const ValPtr& GetVal() const
{ return val; } { return val; }
// Returns/sets time of last expiration relevant access to this value. // Returns/sets time of last expiration relevant access to this value.
@ -727,7 +740,7 @@ public:
protected: protected:
friend class TableVal; friend class TableVal;
zeek::IntrusivePtr<Val> val; ValPtr val;
// The next entry stores seconds since Bro's start. We use ints here // 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 // 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 { class TableVal final : public Val, public notifier::Modifiable {
public: public:
explicit TableVal(zeek::IntrusivePtr<zeek::TableType> t, zeek::IntrusivePtr<zeek::detail::Attributes> attrs = nullptr); explicit TableVal(zeek::TableTypePtr t, zeek::detail::AttributesPtr attrs = nullptr);
[[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]]
explicit TableVal(zeek::TableType* t, zeek::detail::Attributes* attrs = nullptr) explicit TableVal(zeek::TableType* t, zeek::detail::Attributes* attrs = nullptr)
@ -771,7 +784,7 @@ public:
* must be nullptr. * must be nullptr.
* @return True if the assignment type-checked. * @return True if the assignment type-checked.
*/ */
bool Assign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val); bool Assign(ValPtr index, ValPtr new_val);
/** /**
* Assigns a value at an associated index in the table (or in the * Assigns a value at an associated index in the table (or in the
@ -783,8 +796,8 @@ public:
* must be nullptr. * must be nullptr.
* @return True if the assignment type-checked. * @return True if the assignment type-checked.
*/ */
bool Assign(zeek::IntrusivePtr<Val> index, std::unique_ptr<HashKey> k, bool Assign(ValPtr index, std::unique_ptr<HashKey> k,
zeek::IntrusivePtr<Val> new_val); ValPtr new_val);
// Returns true if the assignment typechecked, false if not. The // Returns true if the assignment typechecked, false if not. The
// methods take ownership of new_val, but not of the index. If we're // 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.")]] [[deprecated("Remove in v4.1. Use IntrusivePtr overload instead.")]]
bool Assign(Val* index, HashKey* k, Val* new_val); bool Assign(Val* index, HashKey* k, Val* new_val);
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
// Add the entire contents of the table to the given value, // Add the entire contents of the table to the given value,
// which must also be a TableVal. // which must also be a TableVal.
@ -825,7 +838,7 @@ public:
* @param v The intersecting table. * @param v The intersecting table.
* @return The intersection of this table and the given one. * @return The intersection of this table and the given one.
*/ */
zeek::IntrusivePtr<TableVal> Intersection(const TableVal& v) const; TableValPtr Intersection(const TableVal& v) const;
[[deprecated("Remove in v4.1. Use Intersection() instead.")]] [[deprecated("Remove in v4.1. Use Intersection() instead.")]]
TableVal* Intersect(const TableVal* v) const TableVal* Intersect(const TableVal* v) const
@ -851,7 +864,7 @@ public:
// Expands any lists in the index into multiple initializations. // Expands any lists in the index into multiple initializations.
// Returns true if the initializations typecheck, false if not. // Returns true if the initializations typecheck, false if not.
bool ExpandAndInit(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val); bool ExpandAndInit(ValPtr index, ValPtr new_val);
/** /**
* Finds an index in the table and returns its associated value. * 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 * non-existent index (nullptr), but otherwise has no meaning in relation
* to the set's contents. * to the set's contents.
*/ */
const zeek::IntrusivePtr<Val>& Find(const zeek::IntrusivePtr<Val>& index); const ValPtr& Find(const ValPtr& index);
/** /**
* Finds an index in the table and returns its associated value or else * 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 * exist, instead returns the &default value. If there's no &default
* attribute, then nullptr is still returned for non-existent index. * attribute, then nullptr is still returned for non-existent index.
*/ */
zeek::IntrusivePtr<Val> FindOrDefault(const zeek::IntrusivePtr<Val>& index); ValPtr FindOrDefault(const ValPtr& index);
// Returns the element's value if it exists in the table, // Returns the element's value if it exists in the table,
// nil otherwise. Note, "index" is not const because we // 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 // For a table[subnet]/set[subnet], return all subnets that cover
// the given subnet. // the given subnet.
// Causes an internal error if called for any other kind of table. // Causes an internal error if called for any other kind of table.
zeek::IntrusivePtr<VectorVal> LookupSubnets(const SubNetVal* s); VectorValPtr LookupSubnets(const SubNetVal* s);
// For a set[subnet]/table[subnet], return a new table that only contains // For a set[subnet]/table[subnet], return a new table that only contains
// entries that cover the given subnet. // entries that cover the given subnet.
// Causes an internal error if called for any other kind of table. // Causes an internal error if called for any other kind of table.
zeek::IntrusivePtr<TableVal> LookupSubnetValues(const SubNetVal* s); TableValPtr LookupSubnetValues(const SubNetVal* s);
// Sets the timestamp for the given index to network time. // Sets the timestamp for the given index to network time.
// Returns false if index does not exist. // Returns false if index does not exist.
@ -897,7 +910,7 @@ public:
/** /**
* @return The index corresponding to the given HashKey. * @return The index corresponding to the given HashKey.
*/ */
zeek::IntrusivePtr<ListVal> RecreateIndex(const HashKey& k) const; ListValPtr RecreateIndex(const HashKey& k) const;
[[deprecated("Remove in v4.1. Use RecreateIndex().")]] [[deprecated("Remove in v4.1. Use RecreateIndex().")]]
ListVal* RecoverIndex(const HashKey* k) const ListVal* RecoverIndex(const HashKey* k) const
@ -911,14 +924,14 @@ public:
* value is returned to differentiate it from non-existent index (nullptr), * value is returned to differentiate it from non-existent index (nullptr),
* but otherwise has no meaning in relation to the set's contents. * but otherwise has no meaning in relation to the set's contents.
*/ */
zeek::IntrusivePtr<Val> Remove(const Val& index); ValPtr Remove(const Val& index);
/** /**
* Same as Remove(const Val&), but uses a precomputed hash key. * Same as Remove(const Val&), but uses a precomputed hash key.
* @param k The hash key to lookup. * @param k The hash key to lookup.
* @return Same as Remove(const Val&). * @return Same as Remove(const Val&).
*/ */
zeek::IntrusivePtr<Val> Remove(const HashKey& k); ValPtr Remove(const HashKey& k);
[[deprecated("Remove in v4.1. Use Remove().")]] [[deprecated("Remove in v4.1. Use Remove().")]]
Val* Delete(const Val* index) Val* Delete(const Val* index)
@ -929,25 +942,25 @@ public:
{ return Remove(*k).release(); } { return Remove(*k).release(); }
// Returns a ListVal representation of the table (which must be a set). // Returns a ListVal representation of the table (which must be a set).
zeek::IntrusivePtr<ListVal> 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 // Returns a ListVal representation of the table (which must be a set
// with non-composite index type). // with non-composite index type).
zeek::IntrusivePtr<ListVal> ToPureListVal() const; ListValPtr ToPureListVal() const;
[[deprecated("Remove in v4.1. Use ToListVal() instead.")]] [[deprecated("Remove in v4.1. Use ToListVal() instead.")]]
ListVal* ConvertToList(zeek::TypeTag t=zeek::TYPE_ANY) const; ListVal* ConvertToList(zeek::TypeTag t=zeek::TYPE_ANY) const;
[[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]] [[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]]
ListVal* ConvertToPureList() const; // must be single index type ListVal* ConvertToPureList() const; // must be single index type
void SetAttrs(zeek::IntrusivePtr<zeek::detail::Attributes> attrs); void SetAttrs(zeek::detail::AttributesPtr attrs);
const zeek::IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const; const zeek::detail::AttrPtr& GetAttr(zeek::detail::AttrTag t) const;
[[deprecated("Remove in v4.1. Use GetAttrs().")]] [[deprecated("Remove in v4.1. Use GetAttrs().")]]
zeek::detail::Attributes* Attrs() { return attrs.get(); } zeek::detail::Attributes* Attrs() { return attrs.get(); }
const zeek::IntrusivePtr<zeek::detail::Attributes>& GetAttrs() const const zeek::detail::AttributesPtr& GetAttrs() const
{ return attrs; } { return attrs; }
// Returns the size of the table. // Returns the size of the table.
@ -1003,22 +1016,22 @@ public:
static void DoneParsing(); static void DoneParsing();
protected: protected:
void Init(zeek::IntrusivePtr<zeek::TableType> t); void Init(zeek::TableTypePtr t);
using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<TableVal>>>; using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<TableValPtr>>;
using ParseTimeTableState = std::vector<std::pair<zeek::IntrusivePtr<Val>, zeek::IntrusivePtr<Val>>>; using ParseTimeTableState = std::vector<std::pair<ValPtr, ValPtr>>;
using ParseTimeTableStates = std::unordered_map<TableVal*, ParseTimeTableState>; using ParseTimeTableStates = std::unordered_map<TableVal*, ParseTimeTableState>;
ParseTimeTableState DumpTableState(); ParseTimeTableState DumpTableState();
void RebuildTable(ParseTimeTableState ptts); void RebuildTable(ParseTimeTableState ptts);
void CheckExpireAttr(zeek::detail::AttrTag at); void CheckExpireAttr(zeek::detail::AttrTag at);
bool ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr<Val> new_val); bool ExpandCompoundAndInit(ListVal* lv, int k, ValPtr new_val);
bool CheckAndAssign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val); bool CheckAndAssign(ValPtr index, ValPtr new_val);
// Calculates default value for index. Returns nullptr if none. // Calculates default value for index. Returns nullptr if none.
zeek::IntrusivePtr<Val> Default(const zeek::IntrusivePtr<Val>& index); ValPtr Default(const ValPtr& index);
// Returns true if item expiration is enabled. // Returns true if item expiration is enabled.
bool ExpirationEnabled() { return expire_time != nullptr; } bool ExpirationEnabled() { return expire_time != nullptr; }
@ -1029,27 +1042,27 @@ protected:
double GetExpireTime(); double GetExpireTime();
// Calls &expire_func and returns its return interval; // Calls &expire_func and returns its return interval;
double CallExpireFunc(zeek::IntrusivePtr<ListVal> idx); double CallExpireFunc(ListValPtr idx);
// Enum for the different kinds of changes an &on_change handler can see // Enum for the different kinds of changes an &on_change handler can see
enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED }; enum OnChangeType { ELEMENT_NEW, ELEMENT_CHANGED, ELEMENT_REMOVED, ELEMENT_EXPIRED };
// Calls &change_func. Does not take ownership of values. (Refs if needed). // Calls &change_func. Does not take ownership of values. (Refs if needed).
void CallChangeFunc(const Val* index, const zeek::IntrusivePtr<Val>& old_value, void CallChangeFunc(const Val* index, const ValPtr& old_value,
OnChangeType tpe); OnChangeType tpe);
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
zeek::IntrusivePtr<zeek::TableType> table_type; zeek::TableTypePtr table_type;
CompositeHash* table_hash; CompositeHash* table_hash;
zeek::IntrusivePtr<zeek::detail::Attributes> attrs; zeek::detail::AttributesPtr attrs;
zeek::IntrusivePtr<zeek::detail::Expr> expire_time; zeek::detail::ExprPtr expire_time;
zeek::IntrusivePtr<zeek::detail::Expr> expire_func; zeek::detail::ExprPtr expire_func;
TableValTimer* timer; TableValTimer* timer;
IterCookie* expire_cookie; IterCookie* expire_cookie;
PrefixTable* subnets; PrefixTable* subnets;
zeek::IntrusivePtr<Val> def_val; ValPtr def_val;
zeek::IntrusivePtr<zeek::detail::Expr> change_func; zeek::detail::ExprPtr change_func;
// prevent recursion of change functions // prevent recursion of change functions
bool in_change_func = false; bool in_change_func = false;
@ -1061,18 +1074,18 @@ class RecordVal final : public Val, public notifier::Modifiable {
public: public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit RecordVal(zeek::RecordType* t, bool init_fields = true); explicit RecordVal(zeek::RecordType* t, bool init_fields = true);
explicit RecordVal(zeek::IntrusivePtr<zeek::RecordType> t, bool init_fields = true); explicit RecordVal(zeek::RecordTypePtr t, bool init_fields = true);
~RecordVal() override; ~RecordVal() override;
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
/** /**
* Assign a value to a record field. * Assign a value to a record field.
* @param field The field index to assign. * @param field The field index to assign.
* @param new_val The value to assign. * @param new_val The value to assign.
*/ */
void Assign(int field, zeek::IntrusivePtr<Val> new_val); void Assign(int field, ValPtr new_val);
/** /**
* Assign a value of type @c T to a record field, as constructed from * 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); void Assign(int field, Val* new_val);
// Note: the following nullptr method can also go upon removing the above. // Note: the following nullptr method can also go upon removing the above.
void Assign(int field, std::nullptr_t) void Assign(int field, std::nullptr_t)
{ Assign(field, zeek::IntrusivePtr<Val>{}); } { Assign(field, ValPtr{}); }
[[deprecated("Remove in v4.1. Use GetField().")]] [[deprecated("Remove in v4.1. Use GetField().")]]
Val* Lookup(int field) const // Does not Ref() value. Val* Lookup(int field) const // Does not Ref() value.
@ -1100,7 +1113,7 @@ public:
* @param field The field index to retrieve. * @param field The field index to retrieve.
* @return The value at the given field index. * @return The value at the given field index.
*/ */
const zeek::IntrusivePtr<Val>& GetField(int field) const const ValPtr& GetField(int field) const
{ return (*AsRecord())[field]; } { return (*AsRecord())[field]; }
/** /**
@ -1120,7 +1133,7 @@ public:
* @return The value at the given field index or the default value if * @return The value at the given field index or the default value if
* the field hasn't been assigned yet. * the field hasn't been assigned yet.
*/ */
zeek::IntrusivePtr<Val> GetFieldOrDefault(int field) const; ValPtr GetFieldOrDefault(int field) const;
[[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]] [[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]]
Val* LookupWithDefault(int field) const Val* LookupWithDefault(int field) const
@ -1132,7 +1145,7 @@ public:
* @return The value of the given field. If no such field name exists, * @return The value of the given field. If no such field name exists,
* a fatal error occurs. * a fatal error occurs.
*/ */
const zeek::IntrusivePtr<Val>& 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. * 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, * if the field hasn't been assigned yet. If no such field name exists,
* a fatal error occurs. * a fatal error occurs.
*/ */
zeek::IntrusivePtr<Val> GetFieldOrDefault(const char* field) const; ValPtr GetFieldOrDefault(const char* field) const;
/** /**
* Returns the value of a given field name or its default value * 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. * Returns a "record_field_table" value for introspection purposes.
*/ */
zeek::IntrusivePtr<TableVal> GetRecordFieldsVal() const; TableValPtr GetRecordFieldsVal() const;
// This is an experiment to associate a BroObj within the // This is an experiment to associate a BroObj within the
// event engine to a record value in bro script. // 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 // The *allow_orphaning* parameter allows for a record to be demoted
// down to a record type that contains less fields. // down to a record type that contains less fields.
zeek::IntrusivePtr<RecordVal> CoerceTo( RecordValPtr CoerceTo(zeek::RecordTypePtr other,
zeek::IntrusivePtr<zeek::RecordType> other, RecordValPtr aggr,
zeek::IntrusivePtr<RecordVal> aggr, bool allow_orphaning = false) const;
bool allow_orphaning = false) const; RecordValPtr CoerceTo(zeek::RecordTypePtr other,
zeek::IntrusivePtr<RecordVal> CoerceTo( bool allow_orphaning = false);
zeek::IntrusivePtr<zeek::RecordType> other,
bool allow_orphaning = false);
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
void DescribeReST(ODesc* d) const override; void DescribeReST(ODesc* d) const override;
@ -1222,17 +1233,17 @@ public:
static void DoneParsing(); static void DoneParsing();
protected: protected:
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
BroObj* origin; BroObj* origin;
using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<RecordVal>>>; using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<RecordValPtr>>;
static RecordTypeValMap parse_time_records; static RecordTypeValMap parse_time_records;
}; };
class EnumVal final : public Val { class EnumVal final : public Val {
public: public:
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
protected: protected:
friend class Val; friend class Val;
@ -1241,11 +1252,11 @@ protected:
template<class T, class... Ts> template<class T, class... Ts>
friend zeek::IntrusivePtr<T> zeek::make_intrusive(Ts&&... args); friend zeek::IntrusivePtr<T> zeek::make_intrusive(Ts&&... args);
EnumVal(zeek::IntrusivePtr<zeek::EnumType> 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; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
@ -1253,10 +1264,10 @@ class VectorVal final : public Val, public notifier::Modifiable {
public: public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit VectorVal(zeek::VectorType* t); explicit VectorVal(zeek::VectorType* t);
explicit VectorVal(zeek::IntrusivePtr<zeek::VectorType> t); explicit VectorVal(zeek::VectorTypePtr t);
~VectorVal() override; ~VectorVal() override;
zeek::IntrusivePtr<Val> SizeVal() const override; ValPtr SizeVal() const override;
/** /**
* Assigns an element to a given vector index. * Assigns an element to a given vector index.
@ -1265,7 +1276,7 @@ public:
* @return True if the element was successfully assigned, or false if * @return True if the element was successfully assigned, or false if
* the element was the wrong type. * the element was the wrong type.
*/ */
bool Assign(unsigned int index, zeek::IntrusivePtr<Val> element); bool Assign(unsigned int index, ValPtr element);
// Note: does NOT Ref() the element! Remember to do so unless // Note: does NOT Ref() the element! Remember to do so unless
// the element was just created and thus has refcount 1. // the element was just created and thus has refcount 1.
@ -1274,7 +1285,7 @@ public:
{ return Assign(index, {zeek::AdoptRef{}, element}); } { return Assign(index, {zeek::AdoptRef{}, element}); }
// Note: the following nullptr method can also go upon removing the above. // Note: the following nullptr method can also go upon removing the above.
void Assign(unsigned int index, std::nullptr_t) void Assign(unsigned int index, std::nullptr_t)
{ Assign(index, zeek::IntrusivePtr<Val>{}); } { Assign(index, ValPtr{}); }
[[deprecated("Remove in v4.1. Assign using integer index and IntrusivePtr element.")]] [[deprecated("Remove in v4.1. Assign using integer index and IntrusivePtr element.")]]
bool Assign(Val* index, Val* element) bool Assign(Val* index, Val* element)
@ -1291,7 +1302,7 @@ public:
* the element was the wrong type. * the element was the wrong type.
*/ */
bool AssignRepeat(unsigned int index, unsigned int how_many, bool AssignRepeat(unsigned int index, unsigned int how_many,
zeek::IntrusivePtr<Val> element); ValPtr element);
[[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]]
bool AssignRepeat(unsigned int index, unsigned int how_many, Val* element) 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 * @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). * does not exist (it's greater than or equal to vector's current size).
*/ */
const zeek::IntrusivePtr<Val>& At(unsigned int index) const; const ValPtr& At(unsigned int index) const;
[[deprecated("Remove in v4.1. Use At().")]] [[deprecated("Remove in v4.1. Use At().")]]
Val* Lookup(unsigned int index) const Val* Lookup(unsigned int index) const
@ -1339,7 +1350,7 @@ public:
* @return True if the element was inserted or false if the element was * @return True if the element was inserted or false if the element was
* the wrong type. * the wrong type.
*/ */
bool Insert(unsigned int index, zeek::IntrusivePtr<Val> element); bool Insert(unsigned int index, ValPtr element);
[[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Insert an IntrusivePtr instead.")]]
bool Insert(unsigned int index, Val* element) bool Insert(unsigned int index, Val* element)
@ -1350,33 +1361,33 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
zeek::IntrusivePtr<Val> DoClone(CloneState* state) override; ValPtr DoClone(CloneState* state) override;
}; };
// Checks the given value for consistency with the given type. If an // Checks the given value for consistency with the given type. If an
// exact match, returns it. If promotable, returns the promoted version. // 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 // 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. // true, then the checking is done in the context of an initialization.
extern zeek::IntrusivePtr<Val> check_and_promote( extern ValPtr check_and_promote(
zeek::IntrusivePtr<Val> v, const zeek::Type* t, bool is_init, ValPtr v, const zeek::Type* t, bool is_init,
const Location* expr_location = nullptr); const Location* expr_location = nullptr);
extern bool same_val(const Val* v1, const Val* v2); extern bool same_val(const Val* v1, const Val* v2);
extern bool same_atomic_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 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 val_list* vals, ODesc* d, int offset=0);
extern void describe_vals(const std::vector<zeek::IntrusivePtr<Val>>& vals, extern void describe_vals(const std::vector<ValPtr>& vals,
ODesc* d, size_t offset = 0); ODesc* d, size_t offset = 0);
extern void delete_vals(val_list* vals); extern void delete_vals(val_list* vals);
// True if the given Val* has a vector type. // 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(Val* v) { return v->GetType()->Tag() == zeek::TYPE_VECTOR; }
inline bool is_vector(const zeek::IntrusivePtr<Val>& 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. // Returns v casted to type T if the type supports that. Returns null if not.
// //
// Note: This implements the script-level cast operator. // Note: This implements the script-level cast operator.
extern zeek::IntrusivePtr<Val> 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 // Returns true if v can be casted to type T. If so, check_and_cast() will
// succeed as well. // succeed as well.

View file

@ -19,9 +19,9 @@
using namespace zeek::detail; using namespace zeek::detail;
static zeek::IntrusivePtr<Val> init_val(zeek::detail::Expr* init, static ValPtr init_val(zeek::detail::Expr* init,
const zeek::Type* t, const zeek::Type* t,
zeek::IntrusivePtr<Val> aggr) ValPtr aggr)
{ {
try try
{ {
@ -33,9 +33,9 @@ static zeek::IntrusivePtr<Val> init_val(zeek::detail::Expr* init,
} }
} }
static bool add_prototype(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::Type* t, static bool add_prototype(const zeek::detail::IDPtr& id, zeek::Type* t,
std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>* attrs, std::vector<AttrPtr>* attrs,
const zeek::IntrusivePtr<zeek::detail::Expr>& init) const zeek::detail::ExprPtr& init)
{ {
if ( ! zeek::IsFunc(id->GetType()->Tag()) ) if ( ! zeek::IsFunc(id->GetType()->Tag()) )
return false; return false;
@ -111,10 +111,10 @@ static bool add_prototype(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::
return true; return true;
} }
static void make_var(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::Type> t, static void make_var(const zeek::detail::IDPtr& id, zeek::TypePtr t,
zeek::detail::InitClass c, zeek::detail::InitClass c,
zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::ExprPtr init,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<AttrPtr>> attr,
decl_type dt, decl_type dt,
bool do_init) bool do_init)
{ {
@ -244,7 +244,7 @@ static void make_var(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::Intru
else if ( dt != VAR_REDEF || init || ! attr ) else if ( dt != VAR_REDEF || init || ! attr )
{ {
zeek::IntrusivePtr<Val> aggr; ValPtr aggr;
if ( t->Tag() == zeek::TYPE_RECORD ) if ( t->Tag() == zeek::TYPE_RECORD )
{ {
@ -264,7 +264,7 @@ static void make_var(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::Intru
else if ( t->Tag() == zeek::TYPE_VECTOR ) else if ( t->Tag() == zeek::TYPE_VECTOR )
aggr = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<zeek::VectorType>(t)); aggr = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<zeek::VectorType>(t));
zeek::IntrusivePtr<Val> v; ValPtr v;
if ( init ) if ( init )
{ {
@ -306,24 +306,27 @@ static void make_var(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::Intru
// For events, add a function value (without any body) here so that // For events, add a function value (without any body) here so that
// we can later access the ID even if no implementations have been // we can later access the ID even if no implementations have been
// defined. // defined.
std::vector<zeek::IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::detail::IDPtr> inits;
auto f = zeek::make_intrusive<BroFunc>(id, nullptr, inits, 0, 0); auto f = zeek::make_intrusive<BroFunc>(id, nullptr, inits, 0, 0);
id->SetVal(zeek::make_intrusive<Val>(std::move(f))); id->SetVal(zeek::make_intrusive<Val>(std::move(f)));
} }
} }
void add_global(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::Type> t, void add_global(
zeek::detail::InitClass c, zeek::IntrusivePtr<zeek::detail::Expr> init, const zeek::detail::IDPtr& id,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr, zeek::TypePtr t,
decl_type dt) zeek::detail::InitClass c, zeek::detail::ExprPtr init,
std::unique_ptr<std::vector<AttrPtr>> attr,
decl_type dt)
{ {
make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true); make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true);
} }
zeek::IntrusivePtr<zeek::detail::Stmt> add_local(zeek::IntrusivePtr<zeek::detail::ID> id, zeek::IntrusivePtr<zeek::Type> t, zeek::detail::StmtPtr add_local(
zeek::detail::InitClass c, zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::IDPtr id, zeek::TypePtr t,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr, zeek::detail::InitClass c, zeek::detail::ExprPtr init,
decl_type dt) std::unique_ptr<std::vector<AttrPtr>> attr,
decl_type dt)
{ {
make_var(id, std::move(t), c, init, std::move(attr), dt, false); make_var(id, std::move(t), c, init, std::move(attr), dt, false);
@ -352,10 +355,10 @@ zeek::IntrusivePtr<zeek::detail::Stmt> add_local(zeek::IntrusivePtr<zeek::detail
} }
} }
extern zeek::IntrusivePtr<zeek::detail::Expr> add_and_assign_local( extern zeek::detail::ExprPtr add_and_assign_local(
zeek::IntrusivePtr<zeek::detail::ID> id, zeek::detail::IDPtr id,
zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::ExprPtr init,
zeek::IntrusivePtr<Val> val) ValPtr val)
{ {
make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false); make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false);
auto name_expr = zeek::make_intrusive<zeek::detail::NameExpr>(std::move(id)); auto name_expr = zeek::make_intrusive<zeek::detail::NameExpr>(std::move(id));
@ -363,12 +366,12 @@ extern zeek::IntrusivePtr<zeek::detail::Expr> add_and_assign_local(
std::move(name_expr), std::move(init), false, std::move(val)); std::move(name_expr), std::move(init), false, std::move(val));
} }
void add_type(zeek::detail::ID* id, zeek::IntrusivePtr<zeek::Type> t, void add_type(zeek::detail::ID* id, zeek::TypePtr t,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr) std::unique_ptr<std::vector<AttrPtr>> attr)
{ {
std::string new_type_name = id->Name(); std::string new_type_name = id->Name();
std::string old_type_name = t->GetName(); std::string old_type_name = t->GetName();
zeek::IntrusivePtr<zeek::Type> tnew; zeek::TypePtr tnew;
if ( (t->Tag() == zeek::TYPE_RECORD || t->Tag() == zeek::TYPE_ENUM) && if ( (t->Tag() == zeek::TYPE_RECORD || t->Tag() == zeek::TYPE_ENUM) &&
old_type_name.empty() ) old_type_name.empty() )
@ -406,10 +409,10 @@ static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv
if ( ! recv_i->attrs ) if ( ! recv_i->attrs )
{ {
std::vector<zeek::IntrusivePtr<zeek::detail::Attr>> a{def}; std::vector<AttrPtr> a{def};
recv_i->attrs = zeek::make_intrusive<zeek::detail::Attributes>(std::move(a), recv_i->attrs = zeek::make_intrusive<zeek::detail::Attributes>(std::move(a),
recv_i->type, recv_i->type,
true, false); true, false);
} }
else if ( ! recv_i->attrs->Find(zeek::detail::ATTR_DEFAULT) ) 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<zeek::IntrusivePtr<zeek::detail::Attr>>* al, static zeek::detail::Attr* find_attr(const std::vector<AttrPtr>* al,
zeek::detail::AttrTag tag) zeek::detail::AttrTag tag)
{ {
if ( ! al ) if ( ! al )
@ -465,10 +468,10 @@ static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::Fu
return true; return true;
} }
void begin_func(zeek::IntrusivePtr<zeek::detail::ID> id, const char* module_name, void begin_func(zeek::detail::IDPtr id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef, zeek::FunctionFlavor flavor, bool is_redef,
zeek::IntrusivePtr<zeek::FuncType> t, zeek::FuncTypePtr t,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs) std::unique_ptr<std::vector<AttrPtr>> attrs)
{ {
if ( flavor == zeek::FUNC_FLAVOR_EVENT ) if ( flavor == zeek::FUNC_FLAVOR_EVENT )
{ {
@ -639,7 +642,7 @@ TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr)
return TC_CONTINUE; return TC_CONTINUE;
} }
void end_func(zeek::IntrusivePtr<zeek::detail::Stmt> body) void end_func(zeek::detail::StmtPtr body)
{ {
auto ingredients = std::make_unique<function_ingredients>(pop_scope(), std::move(body)); auto ingredients = std::make_unique<function_ingredients>(pop_scope(), std::move(body));

View file

@ -16,37 +16,41 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
namespace zeek::detail {
using StmtPtr = zeek::IntrusivePtr<zeek::detail::Stmt>;
}
typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type; typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type;
extern void add_global(const zeek::IntrusivePtr<zeek::detail::ID>& id, extern void add_global(const zeek::detail::IDPtr& id,
zeek::IntrusivePtr<zeek::Type> t, zeek::TypePtr t,
zeek::detail::InitClass c, zeek::detail::InitClass c,
zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::ExprPtr init,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attr,
decl_type dt); decl_type dt);
extern zeek::IntrusivePtr<zeek::detail::Stmt> add_local( extern zeek::detail::StmtPtr add_local(
zeek::IntrusivePtr<zeek::detail::ID> id, zeek::detail::IDPtr id,
zeek::IntrusivePtr<zeek::Type> t, zeek::TypePtr t,
zeek::detail::InitClass c, zeek::detail::InitClass c,
zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::ExprPtr init,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attr,
decl_type dt); decl_type dt);
extern zeek::IntrusivePtr<zeek::detail::Expr> add_and_assign_local( extern zeek::detail::ExprPtr add_and_assign_local(
zeek::IntrusivePtr<zeek::detail::ID> id, zeek::detail::IDPtr id,
zeek::IntrusivePtr<zeek::detail::Expr> init, zeek::detail::ExprPtr init,
zeek::IntrusivePtr<Val> val = nullptr); ValPtr val = nullptr);
extern void add_type(zeek::detail::ID* id, zeek::IntrusivePtr<zeek::Type> t, extern void add_type(zeek::detail::ID* id, zeek::TypePtr t,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr); std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attr);
extern void begin_func(zeek::IntrusivePtr<zeek::detail::ID> id, const char* module_name, extern void begin_func(zeek::detail::IDPtr id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef, zeek::FunctionFlavor flavor, bool is_redef,
zeek::IntrusivePtr<zeek::FuncType> t, zeek::FuncTypePtr t,
std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs = nullptr); std::unique_ptr<std::vector<zeek::detail::AttrPtr>> attrs = nullptr);
extern void end_func(zeek::IntrusivePtr<zeek::detail::Stmt> body); extern void end_func(zeek::detail::StmtPtr body);
// Gather all IDs referenced inside a body that aren't part of a given scope. // 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); extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body);

View file

@ -710,7 +710,7 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len)
if ( ! protocol_violation ) if ( ! protocol_violation )
return; return;
zeek::IntrusivePtr<StringVal> r; StringValPtr r;
if ( data && len ) if ( data && len )
{ {
@ -794,7 +794,7 @@ RecordVal* Analyzer::BuildConnVal()
return conn->ConnVal()->Ref()->AsRecordVal(); return conn->ConnVal()->Ref()->AsRecordVal();
} }
const zeek::IntrusivePtr<RecordVal>& Analyzer::ConnVal() const RecordValPtr& Analyzer::ConnVal()
{ {
return conn->ConnVal(); return conn->ConnVal();
} }
@ -926,12 +926,12 @@ void TransportLayerAnalyzer::Done()
} }
void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */, void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */,
zeek::IntrusivePtr<BroFile> /* f */) BroFilePtr /* f */)
{ {
reporter->Error("analyzer type does not support writing to a contents file"); reporter->Error("analyzer type does not support writing to a contents file");
} }
zeek::IntrusivePtr<BroFile> 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"); reporter->Error("analyzer type does not support writing to a contents file");
return nullptr; return nullptr;

View file

@ -17,6 +17,8 @@
#include "../IntrusivePtr.h" #include "../IntrusivePtr.h"
class BroFile; class BroFile;
using BroFilePtr = zeek::IntrusivePtr<BroFile>;
class Rule; class Rule;
class Connection; class Connection;
class IP_Hdr; class IP_Hdr;
@ -35,6 +37,8 @@ using analyzer_list = std::list<Analyzer*>;
typedef uint32_t ID; typedef uint32_t ID;
typedef void (Analyzer::*analyzer_timer_func)(double t); typedef void (Analyzer::*analyzer_timer_func)(double t);
using RecordValPtr = zeek::IntrusivePtr<RecordVal>;
/** /**
* Class to receive processed output from an anlyzer. * Class to receive processed output from an anlyzer.
*/ */
@ -556,7 +560,7 @@ public:
* Convenience function that forwards directly to * Convenience function that forwards directly to
* Connection::ConnVal(). * Connection::ConnVal().
*/ */
const zeek::IntrusivePtr<RecordVal>& ConnVal(); const RecordValPtr& ConnVal();
/** /**
* Convenience function that forwards directly to the corresponding * Convenience function that forwards directly to the corresponding
@ -604,7 +608,7 @@ public:
template <class... Args> template <class... Args>
std::enable_if_t< std::enable_if_t<
std::is_convertible_v< std::is_convertible_v<
std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, ValPtr>>
EnqueueConnEvent(EventHandlerPtr h, Args&&... args) EnqueueConnEvent(EventHandlerPtr h, Args&&... args)
{ return EnqueueConnEvent(h, zeek::Args{std::forward<Args>(args)...}); } { return EnqueueConnEvent(h, zeek::Args{std::forward<Args>(args)...}); }
@ -911,7 +915,7 @@ public:
* @param f The file to record to. * @param f The file to record to.
* *
*/ */
virtual void SetContentsFile(unsigned int direction, zeek::IntrusivePtr<BroFile> f); virtual void SetContentsFile(unsigned int direction, BroFilePtr f);
/** /**
* Returns an associated contents file, if any. This must only be * 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 * @param direction One of the CONTENTS_* constants indicating which
* direction the query is for. * direction the query is for.
*/ */
virtual zeek::IntrusivePtr<BroFile> GetContentsFile(unsigned int direction) const; virtual BroFilePtr GetContentsFile(unsigned int direction) const;
/** /**
* Associates a PIA with this analyzer. A PIA takes the * Associates a PIA with this analyzer. A PIA takes the

View file

@ -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, void Manager::ScheduleAnalyzer(const IPAddr& orig, const IPAddr& resp, PortVal* resp_p,
Val* analyzer, double timeout) Val* analyzer, double timeout)
{ {
zeek::IntrusivePtr<EnumVal> ev{zeek::NewRef{}, analyzer->AsEnumVal()}; EnumValPtr ev{zeek::NewRef{}, analyzer->AsEnumVal()};
return ScheduleAnalyzer(orig, resp, resp_p->Port(), resp_p->PortType(), return ScheduleAnalyzer(orig, resp, resp_p->Port(), resp_p->PortType(),
Tag(std::move(ev)), timeout); Tag(std::move(ev)), timeout);
} }

View file

@ -16,7 +16,7 @@ analyzer::Tag& analyzer::Tag::operator=(const analyzer::Tag& other)
return *this; return *this;
} }
const zeek::IntrusivePtr<EnumVal>& analyzer::Tag::AsVal() const const EnumValPtr& analyzer::Tag::AsVal() const
{ {
return ::Tag::AsVal(analyzer_mgr->GetTagType()); return ::Tag::AsVal(analyzer_mgr->GetTagType());
} }
@ -26,7 +26,7 @@ EnumVal* analyzer::Tag::AsEnumVal() const
return AsVal().get(); return AsVal().get();
} }
analyzer::Tag::Tag(zeek::IntrusivePtr<EnumVal> val) analyzer::Tag::Tag(EnumValPtr val)
: ::Tag(std::move(val)) : ::Tag(std::move(val))
{ } { }

View file

@ -89,7 +89,7 @@ public:
* *
* @param etype the script-layer enum type associated with the tag. * @param etype the script-layer enum type associated with the tag.
*/ */
const zeek::IntrusivePtr<EnumVal>& AsVal() const; const EnumValPtr& AsVal() const;
[[deprecated("Remove in v4.1. Use AsVal() instead.")]] [[deprecated("Remove in v4.1. Use AsVal() instead.")]]
EnumVal* AsEnumVal() const; EnumVal* AsEnumVal() const;
@ -118,7 +118,7 @@ protected:
* *
* @param val An enum value of script type \c Analyzer::Tag. * @param val An enum value of script type \c Analyzer::Tag.
*/ */
explicit Tag(zeek::IntrusivePtr<EnumVal> val); explicit Tag(EnumValPtr val);
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead")]]
explicit Tag(EnumVal* val); explicit Tag(EnumVal* val);

View file

@ -226,7 +226,7 @@ void ARP_Analyzer::RREvent(EventHandlerPtr e,
AddrVal* ARP_Analyzer::ConstructAddrVal(const void* addr) AddrVal* ARP_Analyzer::ConstructAddrVal(const void* addr)
{ return ToAddrVal(addr).release(); } { return ToAddrVal(addr).release(); }
zeek::IntrusivePtr<AddrVal> ARP_Analyzer::ToAddrVal(const void* addr) AddrValPtr ARP_Analyzer::ToAddrVal(const void* addr)
{ {
// ### For now, we only handle IPv4 addresses. // ### For now, we only handle IPv4 addresses.
return zeek::make_intrusive<AddrVal>(*(const uint32_t*) addr); return zeek::make_intrusive<AddrVal>(*(const uint32_t*) addr);
@ -235,7 +235,7 @@ zeek::IntrusivePtr<AddrVal> ARP_Analyzer::ToAddrVal(const void* addr)
StringVal* ARP_Analyzer::EthAddrToStr(const u_char* addr) StringVal* ARP_Analyzer::EthAddrToStr(const u_char* addr)
{ return ToEthAddrStr(addr).release(); } { return ToEthAddrStr(addr).release(); }
zeek::IntrusivePtr<StringVal> ARP_Analyzer::ToEthAddrStr(const u_char* addr) StringValPtr ARP_Analyzer::ToEthAddrStr(const u_char* addr)
{ {
char buf[1024]; char buf[1024];
snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x", snprintf(buf, sizeof(buf), "%02x:%02x:%02x:%02x:%02x:%02x",

View file

@ -51,8 +51,8 @@ protected:
[[deprecated("Remove in v4.1. Use ToEthAddrStr().")]] [[deprecated("Remove in v4.1. Use ToEthAddrStr().")]]
StringVal* EthAddrToStr(const u_char* addr); StringVal* EthAddrToStr(const u_char* addr);
zeek::IntrusivePtr<AddrVal> ToAddrVal(const void* addr); AddrValPtr ToAddrVal(const void* addr);
zeek::IntrusivePtr<StringVal> ToEthAddrStr(const u_char* addr); StringValPtr ToEthAddrStr(const u_char* addr);
void BadARP(const struct arp_pkthdr* hdr, const char* string); void BadARP(const struct arp_pkthdr* hdr, const char* string);
void Corrupted(const char* string); void Corrupted(const char* string);
}; };

View file

@ -3,12 +3,12 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t); ValPtr asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t);
zeek::IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t); ValPtr asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t);
zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid); StringValPtr asn1_oid_to_val(const ASN1Encoding* oid);
zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid); StringValPtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid);
zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s); StringValPtr asn1_octet_string_to_val(const ASN1Encoding* s);
zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1OctetString* s); StringValPtr asn1_octet_string_to_val(const ASN1OctetString* s);
%} %}
############################## ASN.1 Encodings ############################## ASN.1 Encodings
@ -102,12 +102,12 @@ function binary_to_int64(bs: bytestring): int64
%code{ %code{
zeek::IntrusivePtr<Val> 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); return asn1_integer_to_val(i->encoding(), t);
} }
zeek::IntrusivePtr<Val> 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()); auto v = binary_to_int64(i->content());
@ -125,12 +125,12 @@ zeek::IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag
} }
} }
zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid) StringValPtr asn1_oid_to_val(const ASN1ObjectIdentifier* oid)
{ {
return asn1_oid_to_val(oid->encoding()); return asn1_oid_to_val(oid->encoding());
} }
zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid) StringValPtr asn1_oid_to_val(const ASN1Encoding* oid)
{ {
vector<uint64> oid_components; vector<uint64> oid_components;
vector<vector<uint8> > subidentifiers; vector<vector<uint8> > subidentifiers;
@ -194,12 +194,12 @@ zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid)
return zeek::make_intrusive<StringVal>(rval); return zeek::make_intrusive<StringVal>(rval);
} }
zeek::IntrusivePtr<StringVal> 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()); return asn1_octet_string_to_val(s->encoding());
} }
zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s) StringValPtr asn1_octet_string_to_val(const ASN1Encoding* s)
{ {
bytestring const& bs = s->content(); bytestring const& bs = s->content();
return zeek::make_intrusive<StringVal>(bs.length(), reinterpret_cast<const char*>(bs.data())); return zeek::make_intrusive<StringVal>(bs.length(), reinterpret_cast<const char*>(bs.data()));

View file

@ -15,11 +15,11 @@
using namespace analyzer::bittorrent; using namespace analyzer::bittorrent;
static zeek::IntrusivePtr<zeek::TableType> bt_tracker_headers; static zeek::TableTypePtr bt_tracker_headers;
static zeek::IntrusivePtr<zeek::RecordType> bittorrent_peer; static zeek::RecordTypePtr bittorrent_peer;
static zeek::IntrusivePtr<zeek::TableType> bittorrent_peer_set; static zeek::TableTypePtr bittorrent_peer_set;
static zeek::IntrusivePtr<zeek::RecordType> bittorrent_benc_value; static zeek::RecordTypePtr bittorrent_benc_value;
static zeek::IntrusivePtr<zeek::TableType> bittorrent_benc_dir; static zeek::TableTypePtr bittorrent_benc_dir;
BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c)
: tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c) : tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c)

View file

@ -83,7 +83,7 @@ refine connection DCE_RPC_Conn += {
%{ %{
if ( dce_rpc_bind_ack ) if ( dce_rpc_bind_ack )
{ {
zeek::IntrusivePtr<StringVal> sec_addr; StringValPtr sec_addr;
// Remove the null from the end of the string if it's there. // Remove the null from the end of the string if it's there.
if ( ${bind.sec_addr}.length() > 0 && if ( ${bind.sec_addr}.length() > 0 &&

View file

@ -1,8 +1,8 @@
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
%member{ %member{
zeek::IntrusivePtr<RecordVal> options; RecordValPtr options;
zeek::IntrusivePtr<VectorVal> all_options; VectorValPtr all_options;
%} %}
%init{ %init{

View file

@ -627,7 +627,7 @@ refine flow DHCP_Flow += {
%{ %{
auto client_id = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::ClientID); auto client_id = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::ClientID);
client_id->Assign(0, val_mgr->Count(${v.client_id.hwtype})); client_id->Assign(0, val_mgr->Count(${v.client_id.hwtype}));
zeek::IntrusivePtr<StringVal> sv; StringValPtr sv;
if ( ${v.client_id.hwtype} == 0 ) if ( ${v.client_id.hwtype} == 0 )
sv = zeek::make_intrusive<StringVal>(${v.client_id.hwaddr}.length(), sv = zeek::make_intrusive<StringVal>(${v.client_id.hwaddr}.length(),

View file

@ -1260,7 +1260,7 @@ bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg,
return true; return true;
} }
static zeek::IntrusivePtr<StringVal> static StringValPtr
extract_char_string(analyzer::Analyzer* analyzer, extract_char_string(analyzer::Analyzer* analyzer,
const u_char*& data, int& len, int& rdlen) 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<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
zeek::IntrusivePtr<StringVal> char_string; StringValPtr char_string;
while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) )
char_strings->Assign(char_strings->Size(), std::move(char_string)); 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<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
zeek::IntrusivePtr<StringVal> char_string; StringValPtr char_string;
while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) ) while ( (char_string = extract_char_string(analyzer, data, len, rdlength)) )
char_strings->Assign(char_strings->Size(), std::move(char_string)); 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; skip_event = 0;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal() RecordValPtr DNS_MsgInfo::BuildHdrVal()
{ {
static auto dns_msg = zeek::id::find_type<zeek::RecordType>("dns_msg"); static auto dns_msg = zeek::id::find_type<zeek::RecordType>("dns_msg");
auto r = zeek::make_intrusive<RecordVal>(dns_msg); auto r = zeek::make_intrusive<RecordVal>(dns_msg);
@ -1468,7 +1468,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal()
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildAnswerVal() RecordValPtr DNS_MsgInfo::BuildAnswerVal()
{ {
static auto dns_answer = zeek::id::find_type<zeek::RecordType>("dns_answer"); static auto dns_answer = zeek::id::find_type<zeek::RecordType>("dns_answer");
auto r = zeek::make_intrusive<RecordVal>(dns_answer); auto r = zeek::make_intrusive<RecordVal>(dns_answer);
@ -1482,7 +1482,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildAnswerVal()
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val() RecordValPtr DNS_MsgInfo::BuildEDNS_Val()
{ {
// We have to treat the additional record type in EDNS differently // We have to treat the additional record type in EDNS differently
// than a regular resource record. // than a regular resource record.
@ -1518,7 +1518,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val()
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> 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<zeek::RecordType>("dns_tsig_additional"); static auto dns_tsig_additional = zeek::id::find_type<zeek::RecordType>("dns_tsig_additional");
auto r = zeek::make_intrusive<RecordVal>(dns_tsig_additional); auto r = zeek::make_intrusive<RecordVal>(dns_tsig_additional);
@ -1538,7 +1538,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) RecordValPtr DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig)
{ {
static auto dns_rrsig_rr = zeek::id::find_type<zeek::RecordType>("dns_rrsig_rr"); static auto dns_rrsig_rr = zeek::id::find_type<zeek::RecordType>("dns_rrsig_rr");
auto r = zeek::make_intrusive<RecordVal>(dns_rrsig_rr); auto r = zeek::make_intrusive<RecordVal>(dns_rrsig_rr);
@ -1559,7 +1559,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) RecordValPtr DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey)
{ {
static auto dns_dnskey_rr = zeek::id::find_type<zeek::RecordType>("dns_dnskey_rr"); static auto dns_dnskey_rr = zeek::id::find_type<zeek::RecordType>("dns_dnskey_rr");
auto r = zeek::make_intrusive<RecordVal>(dns_dnskey_rr); auto r = zeek::make_intrusive<RecordVal>(dns_dnskey_rr);
@ -1575,7 +1575,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) RecordValPtr DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3)
{ {
static auto dns_nsec3_rr = zeek::id::find_type<zeek::RecordType>("dns_nsec3_rr"); static auto dns_nsec3_rr = zeek::id::find_type<zeek::RecordType>("dns_nsec3_rr");
auto r = zeek::make_intrusive<RecordVal>(dns_nsec3_rr); auto r = zeek::make_intrusive<RecordVal>(dns_nsec3_rr);
@ -1595,7 +1595,7 @@ zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) RecordValPtr DNS_MsgInfo::BuildDS_Val(DS_DATA* ds)
{ {
static auto dns_ds_rr = zeek::id::find_type<zeek::RecordType>("dns_ds_rr"); static auto dns_ds_rr = zeek::id::find_type<zeek::RecordType>("dns_ds_rr");
auto r = zeek::make_intrusive<RecordVal>(dns_ds_rr); auto r = zeek::make_intrusive<RecordVal>(dns_ds_rr);

View file

@ -165,7 +165,7 @@ struct NSEC3_DATA {
BroString* nsec_salt; BroString* nsec_salt;
unsigned short nsec_hlen; unsigned short nsec_hlen;
BroString* nsec_hash; BroString* nsec_hash;
zeek::IntrusivePtr<VectorVal> bitmaps; VectorValPtr bitmaps;
}; };
struct DS_DATA { struct DS_DATA {
@ -179,14 +179,14 @@ class DNS_MsgInfo {
public: public:
DNS_MsgInfo(DNS_RawMsgHdr* hdr, int is_query); DNS_MsgInfo(DNS_RawMsgHdr* hdr, int is_query);
zeek::IntrusivePtr<RecordVal> BuildHdrVal(); RecordValPtr BuildHdrVal();
zeek::IntrusivePtr<RecordVal> BuildAnswerVal(); RecordValPtr BuildAnswerVal();
zeek::IntrusivePtr<RecordVal> BuildEDNS_Val(); RecordValPtr BuildEDNS_Val();
zeek::IntrusivePtr<RecordVal> BuildTSIG_Val(struct TSIG_DATA*); RecordValPtr BuildTSIG_Val(struct TSIG_DATA*);
zeek::IntrusivePtr<RecordVal> BuildRRSIG_Val(struct RRSIG_DATA*); RecordValPtr BuildRRSIG_Val(struct RRSIG_DATA*);
zeek::IntrusivePtr<RecordVal> BuildDNSKEY_Val(struct DNSKEY_DATA*); RecordValPtr BuildDNSKEY_Val(struct DNSKEY_DATA*);
zeek::IntrusivePtr<RecordVal> BuildNSEC3_Val(struct NSEC3_DATA*); RecordValPtr BuildNSEC3_Val(struct NSEC3_DATA*);
zeek::IntrusivePtr<RecordVal> BuildDS_Val(struct DS_DATA*); RecordValPtr BuildDS_Val(struct DS_DATA*);
int id; int id;
int opcode; ///< query type, see DNS_Opcode int opcode; ///< query type, see DNS_Opcode
@ -203,7 +203,7 @@ public:
int arcount; ///< number of additional RRs int arcount; ///< number of additional RRs
int is_query; ///< whether it came from the session initiator int is_query; ///< whether it came from the session initiator
zeek::IntrusivePtr<StringVal> query_name; StringValPtr query_name;
RR_Type atype; RR_Type atype;
int aclass; ///< normally = 1, inet int aclass; ///< normally = 1, inet
uint32_t ttl; uint32_t ttl;

View file

@ -4,7 +4,7 @@ type ftp_port: record;
%%{ %%{
#include "Reporter.h" #include "Reporter.h"
static zeek::IntrusivePtr<Val> parse_port(const char* line) static ValPtr parse_port(const char* line)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port);
@ -47,7 +47,7 @@ static zeek::IntrusivePtr<Val> parse_port(const char* line)
return r; return r;
} }
static zeek::IntrusivePtr<Val> parse_eftp(const char* line) static ValPtr parse_eftp(const char* line)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port);

View file

@ -4,7 +4,7 @@
%} %}
%code{ %code{
zeek::IntrusivePtr<RecordVal> BuildGTPv1Hdr(const GTPv1_Header* pdu) RecordValPtr BuildGTPv1Hdr(const GTPv1_Header* pdu)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtpv1_hdr); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtpv1_hdr);
@ -28,12 +28,12 @@ zeek::IntrusivePtr<RecordVal> BuildGTPv1Hdr(const GTPv1_Header* pdu)
return rv; return rv;
} }
static zeek::IntrusivePtr<Val> BuildIMSI(const InformationElement* ie) static ValPtr BuildIMSI(const InformationElement* ie)
{ {
return val_mgr->Count(ie->imsi()->value()); return val_mgr->Count(ie->imsi()->value());
} }
static zeek::IntrusivePtr<Val> BuildRAI(const InformationElement* ie) static ValPtr BuildRAI(const InformationElement* ie)
{ {
auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_rai); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_rai);
ev->Assign(0, val_mgr->Count(ie->rai()->mcc())); ev->Assign(0, val_mgr->Count(ie->rai()->mcc()));
@ -43,47 +43,47 @@ static zeek::IntrusivePtr<Val> BuildRAI(const InformationElement* ie)
return ev; return ev;
} }
static zeek::IntrusivePtr<Val> BuildRecovery(const InformationElement* ie) static ValPtr BuildRecovery(const InformationElement* ie)
{ {
return val_mgr->Count(ie->recovery()->restart_counter()); return val_mgr->Count(ie->recovery()->restart_counter());
} }
static zeek::IntrusivePtr<Val> BuildSelectionMode(const InformationElement* ie) static ValPtr BuildSelectionMode(const InformationElement* ie)
{ {
return val_mgr->Count(ie->selection_mode()->mode()); return val_mgr->Count(ie->selection_mode()->mode());
} }
static zeek::IntrusivePtr<Val> BuildTEID1(const InformationElement* ie) static ValPtr BuildTEID1(const InformationElement* ie)
{ {
return val_mgr->Count(ie->teid1()->value()); return val_mgr->Count(ie->teid1()->value());
} }
static zeek::IntrusivePtr<Val> BuildTEID_ControlPlane(const InformationElement* ie) static ValPtr BuildTEID_ControlPlane(const InformationElement* ie)
{ {
return val_mgr->Count(ie->teidcp()->value()); return val_mgr->Count(ie->teidcp()->value());
} }
static zeek::IntrusivePtr<Val> BuildNSAPI(const InformationElement* ie) static ValPtr BuildNSAPI(const InformationElement* ie)
{ {
return val_mgr->Count(ie->nsapi()->nsapi()); return val_mgr->Count(ie->nsapi()->nsapi());
} }
static zeek::IntrusivePtr<Val> BuildChargingCharacteristics(const InformationElement* ie) static ValPtr BuildChargingCharacteristics(const InformationElement* ie)
{ {
return val_mgr->Count(ie->charging_characteristics()->value()); return val_mgr->Count(ie->charging_characteristics()->value());
} }
static zeek::IntrusivePtr<Val> BuildTraceReference(const InformationElement* ie) static ValPtr BuildTraceReference(const InformationElement* ie)
{ {
return val_mgr->Count(ie->trace_reference()->value()); return val_mgr->Count(ie->trace_reference()->value());
} }
static zeek::IntrusivePtr<Val> BuildTraceType(const InformationElement* ie) static ValPtr BuildTraceType(const InformationElement* ie)
{ {
return val_mgr->Count(ie->trace_type()->value()); return val_mgr->Count(ie->trace_type()->value());
} }
zeek::IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie) ValPtr BuildEndUserAddr(const InformationElement* ie)
{ {
auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_end_user_addr); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_end_user_addr);
ev->Assign(0, val_mgr->Count(ie->end_user_addr()->pdp_type_org())); ev->Assign(0, val_mgr->Count(ie->end_user_addr()->pdp_type_org()));
@ -114,21 +114,21 @@ zeek::IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie)
return ev; return ev;
} }
zeek::IntrusivePtr<Val> BuildAccessPointName(const InformationElement* ie) ValPtr BuildAccessPointName(const InformationElement* ie)
{ {
BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(), BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(),
ie->ap_name()->value().length(), false); ie->ap_name()->value().length(), false);
return zeek::make_intrusive<StringVal>(bs); return zeek::make_intrusive<StringVal>(bs);
} }
zeek::IntrusivePtr<Val> BuildProtoConfigOptions(const InformationElement* ie) ValPtr BuildProtoConfigOptions(const InformationElement* ie)
{ {
const u_char* d = (const u_char*) ie->proto_config_opts()->value().data(); const u_char* d = (const u_char*) ie->proto_config_opts()->value().data();
int len = ie->proto_config_opts()->value().length(); int len = ie->proto_config_opts()->value().length();
return zeek::make_intrusive<StringVal>(new BroString(d, len, false)); return zeek::make_intrusive<StringVal>(new BroString(d, len, false));
} }
zeek::IntrusivePtr<Val> BuildGSN_Addr(const InformationElement* ie) ValPtr BuildGSN_Addr(const InformationElement* ie)
{ {
auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_gsn_addr); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_gsn_addr);
@ -147,14 +147,14 @@ zeek::IntrusivePtr<Val> BuildGSN_Addr(const InformationElement* ie)
return ev; return ev;
} }
zeek::IntrusivePtr<Val> BuildMSISDN(const InformationElement* ie) ValPtr BuildMSISDN(const InformationElement* ie)
{ {
const u_char* d = (const u_char*) ie->msisdn()->value().data(); const u_char* d = (const u_char*) ie->msisdn()->value().data();
int len = ie->msisdn()->value().length(); int len = ie->msisdn()->value().length();
return zeek::make_intrusive<StringVal>(new BroString(d, len, false)); return zeek::make_intrusive<StringVal>(new BroString(d, len, false));
} }
zeek::IntrusivePtr<Val> BuildQoS_Profile(const InformationElement* ie) ValPtr BuildQoS_Profile(const InformationElement* ie)
{ {
auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_qos_profile); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_qos_profile);
@ -167,28 +167,28 @@ zeek::IntrusivePtr<Val> BuildQoS_Profile(const InformationElement* ie)
return ev; return ev;
} }
zeek::IntrusivePtr<Val> BuildTrafficFlowTemplate(const InformationElement* ie) ValPtr BuildTrafficFlowTemplate(const InformationElement* ie)
{ {
const uint8* d = ie->traffic_flow_template()->value().data(); const uint8* d = ie->traffic_flow_template()->value().data();
int len = ie->traffic_flow_template()->value().length(); int len = ie->traffic_flow_template()->value().length();
return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
zeek::IntrusivePtr<Val> BuildTriggerID(const InformationElement* ie) ValPtr BuildTriggerID(const InformationElement* ie)
{ {
const uint8* d = ie->trigger_id()->value().data(); const uint8* d = ie->trigger_id()->value().data();
int len = ie->trigger_id()->value().length(); int len = ie->trigger_id()->value().length();
return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
zeek::IntrusivePtr<Val> BuildOMC_ID(const InformationElement* ie) ValPtr BuildOMC_ID(const InformationElement* ie)
{ {
const uint8* d = ie->omc_id()->value().data(); const uint8* d = ie->omc_id()->value().data();
int len = ie->omc_id()->value().length(); int len = ie->omc_id()->value().length();
return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
zeek::IntrusivePtr<Val> BuildPrivateExt(const InformationElement* ie) ValPtr BuildPrivateExt(const InformationElement* ie)
{ {
auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_private_extension); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_private_extension);
@ -201,22 +201,22 @@ zeek::IntrusivePtr<Val> BuildPrivateExt(const InformationElement* ie)
return ev; return ev;
} }
static zeek::IntrusivePtr<Val> BuildCause(const InformationElement* ie) static ValPtr BuildCause(const InformationElement* ie)
{ {
return val_mgr->Count(ie->cause()->value()); return val_mgr->Count(ie->cause()->value());
} }
static zeek::IntrusivePtr<Val> BuildReorderReq(const InformationElement* ie) static ValPtr BuildReorderReq(const InformationElement* ie)
{ {
return val_mgr->Bool(ie->reorder_req()->req()); return val_mgr->Bool(ie->reorder_req()->req());
} }
static zeek::IntrusivePtr<Val> BuildChargingID(const InformationElement* ie) static ValPtr BuildChargingID(const InformationElement* ie)
{ {
return val_mgr->Count(ie->charging_id()->value());; return val_mgr->Count(ie->charging_id()->value());;
} }
zeek::IntrusivePtr<Val> BuildChargingGatewayAddr(const InformationElement* ie) ValPtr BuildChargingGatewayAddr(const InformationElement* ie)
{ {
const uint8* d = ie->charging_gateway_addr()->value().data(); const uint8* d = ie->charging_gateway_addr()->value().data();
int len = ie->charging_gateway_addr()->value().length(); int len = ie->charging_gateway_addr()->value().length();
@ -228,7 +228,7 @@ zeek::IntrusivePtr<Val> BuildChargingGatewayAddr(const InformationElement* ie)
return nullptr; return nullptr;
} }
static zeek::IntrusivePtr<Val> BuildTeardownInd(const InformationElement* ie) static ValPtr BuildTeardownInd(const InformationElement* ie)
{ {
return val_mgr->Bool(ie->teardown_ind()->ind()); return val_mgr->Bool(ie->teardown_ind()->ind());
} }

View file

@ -613,7 +613,7 @@ HTTP_Message::~HTTP_Message()
delete [] entity_data_buffer; delete [] entity_data_buffer;
} }
zeek::IntrusivePtr<RecordVal> 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<zeek::RecordType>("http_message_stat"); static auto http_message_stat = zeek::id::find_type<zeek::RecordType>("http_message_stat");
auto stat = zeek::make_intrusive<RecordVal>(http_message_stat); auto stat = zeek::make_intrusive<RecordVal>(http_message_stat);
@ -1355,7 +1355,7 @@ void HTTP_Analyzer::HTTP_Event(const char* category, const char* detail)
HTTP_Event(category, zeek::make_intrusive<StringVal>(detail)); HTTP_Event(category, zeek::make_intrusive<StringVal>(detail));
} }
void HTTP_Analyzer::HTTP_Event(const char* category, zeek::IntrusivePtr<StringVal> detail) void HTTP_Analyzer::HTTP_Event(const char* category, StringValPtr detail)
{ {
if ( http_event ) if ( http_event )
// DEBUG_MSG("%.6f http_event\n", network_time); // DEBUG_MSG("%.6f http_event\n", network_time);
@ -1365,8 +1365,8 @@ void HTTP_Analyzer::HTTP_Event(const char* category, zeek::IntrusivePtr<StringVa
std::move(detail)); std::move(detail));
} }
zeek::IntrusivePtr<StringVal> StringValPtr
HTTP_Analyzer::TruncateURI(const zeek::IntrusivePtr<StringVal>& uri) HTTP_Analyzer::TruncateURI(const StringValPtr& uri)
{ {
const BroString* str = uri->AsString(); const BroString* str = uri->AsString();

View file

@ -145,7 +145,7 @@ protected:
HTTP_Entity* current_entity; HTTP_Entity* current_entity;
zeek::IntrusivePtr<RecordVal> BuildMessageStat(bool interrupted, const char* msg); RecordValPtr BuildMessageStat(bool interrupted, const char* msg);
}; };
class HTTP_Analyzer final : public tcp::TCP_ApplicationAnalyzer { class HTTP_Analyzer final : public tcp::TCP_ApplicationAnalyzer {
@ -156,7 +156,7 @@ public:
void HTTP_EntityData(bool is_orig, BroString* entity_data); void HTTP_EntityData(bool is_orig, BroString* entity_data);
void HTTP_MessageDone(bool is_orig, HTTP_Message* message); void HTTP_MessageDone(bool is_orig, HTTP_Message* message);
void HTTP_Event(const char* category, const char* detail); void HTTP_Event(const char* category, const char* detail);
void HTTP_Event(const char* category, zeek::IntrusivePtr<StringVal> detail); void HTTP_Event(const char* category, StringValPtr detail);
void SkipEntityData(bool is_orig); void SkipEntityData(bool is_orig);
@ -237,7 +237,7 @@ protected:
int HTTP_ReplyCode(const char* code_str); int HTTP_ReplyCode(const char* code_str);
int ExpectReplyMessageBody(); int ExpectReplyMessageBody();
zeek::IntrusivePtr<StringVal> TruncateURI(const zeek::IntrusivePtr<StringVal>& uri); StringValPtr TruncateURI(const StringValPtr& uri);
int request_state, reply_state; int request_state, reply_state;
int num_requests, num_replies; int num_requests, num_replies;
@ -257,19 +257,19 @@ protected:
// in a reply. // in a reply.
std::string upgrade_protocol; std::string upgrade_protocol;
zeek::IntrusivePtr<StringVal> request_method; StringValPtr request_method;
// request_URI is in the original form (may contain '%<hex><hex>' // request_URI is in the original form (may contain '%<hex><hex>'
// sequences). // sequences).
zeek::IntrusivePtr<StringVal> request_URI; StringValPtr request_URI;
// unescaped_URI does not contain escaped sequences. // unescaped_URI does not contain escaped sequences.
zeek::IntrusivePtr<StringVal> unescaped_URI; StringValPtr unescaped_URI;
std::queue<zeek::IntrusivePtr<StringVal>> unanswered_requests; std::queue<StringValPtr> unanswered_requests;
int reply_code; int reply_code;
zeek::IntrusivePtr<StringVal> reply_reason_phrase; StringValPtr reply_reason_phrase;
tcp::ContentLine_Analyzer* content_line_orig; tcp::ContentLine_Analyzer* content_line_orig;
tcp::ContentLine_Analyzer* content_line_resp; tcp::ContentLine_Analyzer* content_line_resp;

View file

@ -219,7 +219,7 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen,
} }
} }
zeek::IntrusivePtr<RecordVal> RecordValPtr
ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len, ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len,
int icmpv6, const IP_Hdr* ip_hdr) int icmpv6, const IP_Hdr* ip_hdr)
{ {
@ -305,7 +305,7 @@ TransportProto ICMP_Analyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t*
return proto; return proto;
} }
zeek::IntrusivePtr<RecordVal> 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_data((const struct ip*) data, false);
const IP_Hdr* ip_hdr = &ip_hdr_data; const IP_Hdr* ip_hdr = &ip_hdr_data;
@ -372,7 +372,7 @@ zeek::IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP4Context(int len, const
return iprec; return iprec;
} }
zeek::IntrusivePtr<RecordVal> 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; int DF = 0, MF = 0, bad_hdr_len = 0;
TransportProto proto = TRANSPORT_UNKNOWN; TransportProto proto = TRANSPORT_UNKNOWN;
@ -469,7 +469,7 @@ void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val)
Analyzer::UpdateConnVal(conn_val); Analyzer::UpdateConnVal(conn_val);
} }
void ICMP_Analyzer::UpdateEndpointVal(const zeek::IntrusivePtr<Val>& endp_arg, bool is_orig) void ICMP_Analyzer::UpdateEndpointVal(const ValPtr& endp_arg, bool is_orig)
{ {
Conn()->EnableStatusUpdateTimer(); Conn()->EnableStatusUpdateTimer();
@ -722,7 +722,7 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp,
); );
} }
zeek::IntrusivePtr<VectorVal> 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<zeek::RecordType>("icmp6_nd_option"); static auto icmp6_nd_option_type = zeek::id::find_type<zeek::RecordType>("icmp6_nd_option");
static auto icmp6_nd_prefix_info_type = zeek::id::find_type<zeek::RecordType>("icmp6_nd_prefix_info"); static auto icmp6_nd_prefix_info_type = zeek::id::find_type<zeek::RecordType>("icmp6_nd_prefix_info");

View file

@ -7,6 +7,7 @@
#include "net_util.h" #include "net_util.h"
class VectorVal; class VectorVal;
using VectorValPtr = zeek::IntrusivePtr<VectorVal>;
namespace analyzer { namespace icmp { namespace analyzer { namespace icmp {
@ -51,13 +52,13 @@ protected:
void Describe(ODesc* d) const; void Describe(ODesc* d) const;
zeek::IntrusivePtr<RecordVal> BuildICMPVal(const struct icmp* icmpp, int len, RecordValPtr BuildICMPVal(const struct icmp* icmpp, int len,
int icmpv6, const IP_Hdr* ip_hdr); int icmpv6, const IP_Hdr* ip_hdr);
void NextICMP4(double t, const struct icmp* icmpp, int len, int caplen, void NextICMP4(double t, const struct icmp* icmpp, int len, int caplen,
const u_char*& data, const IP_Hdr* ip_hdr ); const u_char*& data, const IP_Hdr* ip_hdr );
zeek::IntrusivePtr<RecordVal> 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, void Context4(double t, const struct icmp* icmpp, int len, int caplen,
const u_char*& data, const IP_Hdr* ip_hdr); 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, void NextICMP6(double t, const struct icmp* icmpp, int len, int caplen,
const u_char*& data, const IP_Hdr* ip_hdr ); const u_char*& data, const IP_Hdr* ip_hdr );
zeek::IntrusivePtr<RecordVal> 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, void Context6(double t, const struct icmp* icmpp, int len, int caplen,
const u_char*& data, const IP_Hdr* ip_hdr); const u_char*& data, const IP_Hdr* ip_hdr);
// RFC 4861 Neighbor Discover message options // RFC 4861 Neighbor Discover message options
zeek::IntrusivePtr<VectorVal> BuildNDOptionsVal(int caplen, const u_char* data); VectorValPtr BuildNDOptionsVal(int caplen, const u_char* data);
zeek::IntrusivePtr<RecordVal> icmp_conn_val; RecordValPtr icmp_conn_val;
int type; int type;
int code; int code;
int request_len, reply_len; int request_len, reply_len;
@ -84,7 +85,7 @@ protected:
RuleMatcherState matcher_state; RuleMatcherState matcher_state;
private: private:
void UpdateEndpointVal(const zeek::IntrusivePtr<Val>& endp, bool is_orig); void UpdateEndpointVal(const ValPtr& endp, bool is_orig);
}; };
// Returns the counterpart type to the given type (e.g., the counterpart // Returns the counterpart type to the given type (e.g., the counterpart

View file

@ -87,9 +87,9 @@ void KRB_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
} }
} }
zeek::IntrusivePtr<StringVal> KRB_Analyzer::GetAuthenticationInfo(const BroString* principal, StringValPtr KRB_Analyzer::GetAuthenticationInfo(const BroString* principal,
const BroString* ciphertext, const BroString* ciphertext,
const bro_uint_t enctype) const bro_uint_t enctype)
{ {
#ifdef USE_KRB5 #ifdef USE_KRB5
if ( !krb_available ) if ( !krb_available )

View file

@ -25,9 +25,9 @@ public:
static analyzer::Analyzer* Instantiate(Connection* conn) static analyzer::Analyzer* Instantiate(Connection* conn)
{ return new KRB_Analyzer(conn); } { return new KRB_Analyzer(conn); }
zeek::IntrusivePtr<StringVal> GetAuthenticationInfo(const BroString* principal, StringValPtr GetAuthenticationInfo(const BroString* principal,
const BroString* ciphertext, const BroString* ciphertext,
const bro_uint_t enctype); const bro_uint_t enctype);
protected: protected:

View file

@ -21,9 +21,9 @@ public:
// Overriden from tcp::TCP_ApplicationAnalyzer. // Overriden from tcp::TCP_ApplicationAnalyzer.
void EndpointEOF(bool is_orig) override; void EndpointEOF(bool is_orig) override;
zeek::IntrusivePtr<StringVal> GetAuthenticationInfo(const BroString* principal, StringValPtr GetAuthenticationInfo(const BroString* principal,
const BroString* ciphertext, const BroString* ciphertext,
const bro_uint_t enctype) const bro_uint_t enctype)
{ return val_mgr->EmptyString(); } { return val_mgr->EmptyString(); }
static analyzer::Analyzer* Instantiate(Connection* conn) static analyzer::Analyzer* Instantiate(Connection* conn)

View file

@ -1,12 +1,12 @@
%header{ %header{
zeek::IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts); RecordValPtr proc_krb_kdc_options(const KRB_KDC_Options* opts);
zeek::IntrusivePtr<RecordVal> 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);
bool proc_error_arguments(RecordVal* rv, const std::vector<KRB_ERROR_Arg*>* args, int64 error_code); bool proc_error_arguments(RecordVal* rv, const std::vector<KRB_ERROR_Arg*>* args, int64 error_code);
%} %}
%code{ %code{
zeek::IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts) RecordValPtr proc_krb_kdc_options(const KRB_KDC_Options* opts)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Options); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Options);
@ -27,7 +27,7 @@ zeek::IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts)
return rv; return rv;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::KRB::KDC_Request); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Request);
@ -201,7 +201,7 @@ refine connection KRB_Conn += {
%{ %{
bro_analyzer()->ProtocolConfirmation(); bro_analyzer()->ProtocolConfirmation();
auto msg_type = binary_to_int64(${msg.msg_type.data.content}); auto msg_type = binary_to_int64(${msg.msg_type.data.content});
auto make_arg = [this, msg]() -> zeek::IntrusivePtr<RecordVal> auto make_arg = [this, msg]() -> RecordValPtr
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Response); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Response);

View file

@ -2,20 +2,20 @@
%include ../asn1/asn1.pac %include ../asn1/asn1.pac
%header{ %header{
zeek::IntrusivePtr<Val> GetTimeFromAsn1(const KRB_Time* atime, int64 usecs); ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs);
zeek::IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs); ValPtr GetTimeFromAsn1(StringVal* atime, int64 usecs);
%} %}
%code{ %code{
zeek::IntrusivePtr<Val> GetTimeFromAsn1(const KRB_Time* atime, int64 usecs) ValPtr GetTimeFromAsn1(const KRB_Time* atime, int64 usecs)
{ {
auto atime_bytestring = to_stringval(atime->time()); auto atime_bytestring = to_stringval(atime->time());
auto result = GetTimeFromAsn1(atime_bytestring.get(), usecs); auto result = GetTimeFromAsn1(atime_bytestring.get(), usecs);
return result; return result;
} }
zeek::IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs) ValPtr GetTimeFromAsn1(StringVal* atime, int64 usecs)
{ {
time_t lResult = 0; time_t lResult = 0;

View file

@ -7,11 +7,11 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<VectorVal> 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{ %code{
zeek::IntrusivePtr<VectorVal> 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<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Type_Value_Vector")); auto vv = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Type_Value_Vector"));

View file

@ -1,19 +1,19 @@
# Fundamental KRB types # Fundamental KRB types
%header{ %header{
zeek::IntrusivePtr<Val> GetStringFromPrincipalName(const KRB_Principal_Name* pname); ValPtr GetStringFromPrincipalName(const KRB_Principal_Name* pname);
zeek::IntrusivePtr<VectorVal> proc_cipher_list(const Array* list); VectorValPtr proc_cipher_list(const Array* list);
zeek::IntrusivePtr<VectorVal> 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);
zeek::IntrusivePtr<RecordVal> proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr); RecordValPtr proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr);
zeek::IntrusivePtr<VectorVal> proc_tickets(const KRB_Ticket_Sequence* list); VectorValPtr proc_tickets(const KRB_Ticket_Sequence* list);
zeek::IntrusivePtr<RecordVal> proc_ticket(const KRB_Ticket* ticket); RecordValPtr proc_ticket(const KRB_Ticket* ticket);
%} %}
%code{ %code{
zeek::IntrusivePtr<Val> GetStringFromPrincipalName(const KRB_Principal_Name* pname) ValPtr GetStringFromPrincipalName(const KRB_Principal_Name* pname)
{ {
if ( pname->data()->size() == 1 ) if ( pname->data()->size() == 1 )
return to_stringval(pname->data()[0][0]->encoding()->content()); return to_stringval(pname->data()[0][0]->encoding()->content());
@ -25,7 +25,7 @@ zeek::IntrusivePtr<Val> GetStringFromPrincipalName(const KRB_Principal_Name* pna
return zeek::make_intrusive<StringVal>("unknown"); return zeek::make_intrusive<StringVal>("unknown");
} }
zeek::IntrusivePtr<VectorVal> proc_cipher_list(const Array* list) VectorValPtr proc_cipher_list(const Array* list)
{ {
auto ciphers = zeek::make_intrusive<VectorVal>(zeek::id::index_vec); auto ciphers = zeek::make_intrusive<VectorVal>(zeek::id::index_vec);
for ( uint i = 0; i < list->data()->size(); ++i ) for ( uint i = 0; i < list->data()->size(); ++i )
@ -33,7 +33,7 @@ zeek::IntrusivePtr<VectorVal> proc_cipher_list(const Array* list)
return ciphers; return ciphers;
} }
zeek::IntrusivePtr<VectorVal> 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<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Host_Address_Vector")); auto addrs = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Host_Address_Vector"));
@ -45,7 +45,7 @@ zeek::IntrusivePtr<VectorVal> proc_host_address_list(const BroAnalyzer a, const
return addrs; return addrs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::KRB::Host_Address); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::Host_Address);
const auto& addr_bytes = addr->address()->data()->content(); const auto& addr_bytes = addr->address()->data()->content();
@ -92,7 +92,7 @@ zeek::IntrusivePtr<RecordVal> proc_host_address(const BroAnalyzer a, const KRB_H
return rv; return rv;
} }
zeek::IntrusivePtr<VectorVal> proc_tickets(const KRB_Ticket_Sequence* list) VectorValPtr proc_tickets(const KRB_Ticket_Sequence* list)
{ {
auto tickets = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Ticket_Vector")); auto tickets = zeek::make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("KRB::Ticket_Vector"));
@ -105,7 +105,7 @@ zeek::IntrusivePtr<VectorVal> proc_tickets(const KRB_Ticket_Sequence* list)
return tickets; return tickets;
} }
zeek::IntrusivePtr<RecordVal> proc_ticket(const KRB_Ticket* ticket) RecordValPtr proc_ticket(const KRB_Ticket* ticket)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::Ticket); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::Ticket);

View file

@ -45,13 +45,13 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn)
if ( ! re_skip_authentication ) if ( ! re_skip_authentication )
{ {
zeek::IntrusivePtr<ListVal> skip_authentication = zeek::id::find_val("skip_authentication")->AsTableVal()->ToPureListVal(); ListValPtr skip_authentication = zeek::id::find_val("skip_authentication")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> direct_login_prompts = zeek::id::find_val("direct_login_prompts")->AsTableVal()->ToPureListVal(); ListValPtr direct_login_prompts = zeek::id::find_val("direct_login_prompts")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> login_prompts = zeek::id::find_val("login_prompts")->AsTableVal()->ToPureListVal(); ListValPtr login_prompts = zeek::id::find_val("login_prompts")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> login_non_failure_msgs = zeek::id::find_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal(); ListValPtr login_non_failure_msgs = zeek::id::find_val("login_non_failure_msgs")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> login_failure_msgs = zeek::id::find_val("login_failure_msgs")->AsTableVal()->ToPureListVal(); ListValPtr login_failure_msgs = zeek::id::find_val("login_failure_msgs")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> login_success_msgs = zeek::id::find_val("login_success_msgs")->AsTableVal()->ToPureListVal(); ListValPtr login_success_msgs = zeek::id::find_val("login_success_msgs")->AsTableVal()->ToPureListVal();
zeek::IntrusivePtr<ListVal> login_timeouts = zeek::id::find_val("login_timeouts")->AsTableVal()->ToPureListVal(); ListValPtr login_timeouts = zeek::id::find_val("login_timeouts")->AsTableVal()->ToPureListVal();
#ifdef USE_PERFTOOLS_DEBUG #ifdef USE_PERFTOOLS_DEBUG
HeapLeakChecker::Disabler disabler; HeapLeakChecker::Disabler disabler;

View file

@ -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) StringVal* new_string_val(const data_chunk_t buf)
{ return to_string_val(buf).release(); } { return to_string_val(buf).release(); }
zeek::IntrusivePtr<StringVal> to_string_val(int length, const char* data) StringValPtr to_string_val(int length, const char* data)
{ {
return zeek::make_intrusive<StringVal>(length, data); return zeek::make_intrusive<StringVal>(length, data);
} }
zeek::IntrusivePtr<StringVal> 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<StringVal>(end_of_data - data, data); return zeek::make_intrusive<StringVal>(end_of_data - data, data);
} }
zeek::IntrusivePtr<StringVal> 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); return to_string_val(buf.length, buf.data);
} }
@ -1301,7 +1301,7 @@ void MIME_Entity::DebugPrintHeaders()
RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h) RecordVal* MIME_Message::BuildHeaderVal(MIME_Header* h)
{ return ToHeaderVal(h).release(); } { return ToHeaderVal(h).release(); }
zeek::IntrusivePtr<RecordVal> MIME_Message::ToHeaderVal(MIME_Header* h) RecordValPtr MIME_Message::ToHeaderVal(MIME_Header* h)
{ {
static auto mime_header_rec = zeek::id::find_type<zeek::RecordType>("mime_header_rec"); static auto mime_header_rec = zeek::id::find_type<zeek::RecordType>("mime_header_rec");
auto header_record = zeek::make_intrusive<RecordVal>(mime_header_rec); auto header_record = zeek::make_intrusive<RecordVal>(mime_header_rec);
@ -1316,7 +1316,7 @@ zeek::IntrusivePtr<RecordVal> MIME_Message::ToHeaderVal(MIME_Header* h)
TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist) TableVal* MIME_Message::BuildHeaderTable(MIME_HeaderList& hlist)
{ return ToHeaderTable(hlist).release(); } { return ToHeaderTable(hlist).release(); }
zeek::IntrusivePtr<TableVal> MIME_Message::ToHeaderTable(MIME_HeaderList& hlist) TableValPtr MIME_Message::ToHeaderTable(MIME_HeaderList& hlist)
{ {
static auto mime_header_list = zeek::id::find_type<zeek::TableType>("mime_header_list"); static auto mime_header_list = zeek::id::find_type<zeek::TableType>("mime_header_list");
auto t = zeek::make_intrusive<TableVal>(mime_header_list); auto t = zeek::make_intrusive<TableVal>(mime_header_list);

View file

@ -14,6 +14,9 @@ class TableVal;
class StringVal; class StringVal;
class Base64Converter; class Base64Converter;
using TableValPtr = zeek::IntrusivePtr<TableVal>;
using StringValPtr = zeek::IntrusivePtr<StringVal>;
namespace analyzer { namespace mime { namespace analyzer { namespace mime {
// MIME: Multipurpose Internet Mail Extensions // MIME: Multipurpose Internet Mail Extensions
@ -102,8 +105,8 @@ public:
StringVal* ContentType() const { return content_type_str.get(); } StringVal* ContentType() const { return content_type_str.get(); }
[[deprecated("Remove in v4.1. Use GetContentSubType().")]] [[deprecated("Remove in v4.1. Use GetContentSubType().")]]
StringVal* ContentSubType() const { return content_subtype_str.get(); } StringVal* ContentSubType() const { return content_subtype_str.get(); }
const zeek::IntrusivePtr<StringVal>& GetContentType() const { return content_type_str; } const StringValPtr& GetContentType() const { return content_type_str; }
const zeek::IntrusivePtr<StringVal>& GetContentSubType() const { return content_subtype_str; } const StringValPtr& GetContentSubType() const { return content_subtype_str; }
int ContentTransferEncoding() const { return content_encoding; } int ContentTransferEncoding() const { return content_encoding; }
protected: protected:
@ -159,8 +162,8 @@ protected:
int current_field_type; int current_field_type;
int need_to_parse_parameters; int need_to_parse_parameters;
zeek::IntrusivePtr<StringVal> content_type_str; StringValPtr content_type_str;
zeek::IntrusivePtr<StringVal> content_subtype_str; StringValPtr content_subtype_str;
BroString* content_encoding_str; BroString* content_encoding_str;
BroString* multipart_boundary; BroString* multipart_boundary;
@ -235,8 +238,8 @@ protected:
[[deprecated("Remove in v4.1. Use ToHeaderTable().")]] [[deprecated("Remove in v4.1. Use ToHeaderTable().")]]
TableVal* BuildHeaderTable(MIME_HeaderList& hlist); TableVal* BuildHeaderTable(MIME_HeaderList& hlist);
zeek::IntrusivePtr<RecordVal> ToHeaderVal(MIME_Header* h); RecordValPtr ToHeaderVal(MIME_Header* h);
zeek::IntrusivePtr<TableVal> ToHeaderTable(MIME_HeaderList& hlist); TableValPtr ToHeaderTable(MIME_HeaderList& hlist);
}; };
class MIME_Mail final : public MIME_Message { 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); extern StringVal* new_string_val(const char* data, const char* end_of_data);
[[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]] [[deprecated("Remove in v4.1. Use analyzer::mime::to_string_val().")]]
extern StringVal* new_string_val(const data_chunk_t buf); extern StringVal* new_string_val(const data_chunk_t buf);
extern zeek::IntrusivePtr<StringVal> to_string_val(int length, const char* data); extern StringValPtr to_string_val(int length, const char* data);
extern zeek::IntrusivePtr<StringVal> to_string_val(const char* data, const char* end_of_data); extern StringValPtr to_string_val(const char* data, const char* end_of_data);
extern zeek::IntrusivePtr<StringVal> to_string_val(const data_chunk_t buf); extern StringValPtr to_string_val(const data_chunk_t buf);
extern int fputs(data_chunk_t b, FILE* fp); extern int fputs(data_chunk_t b, FILE* fp);
extern bool istrequal(data_chunk_t s, const char* t); extern bool istrequal(data_chunk_t s, const char* t);
extern bool is_lws(char ch); extern bool is_lws(char ch);

View file

@ -8,13 +8,13 @@
# #
%header{ %header{
zeek::IntrusivePtr<VectorVal> bytestring_to_coils(const bytestring& coils, uint quantity); VectorValPtr bytestring_to_coils(const bytestring& coils, uint quantity);
zeek::IntrusivePtr<RecordVal> HeaderToVal(ModbusTCP_TransportHeader* header); RecordValPtr HeaderToVal(ModbusTCP_TransportHeader* header);
zeek::IntrusivePtr<VectorVal> create_vector_of_count(); VectorValPtr create_vector_of_count();
%} %}
%code{ %code{
zeek::IntrusivePtr<VectorVal> bytestring_to_coils(const bytestring& coils, uint quantity) VectorValPtr bytestring_to_coils(const bytestring& coils, uint quantity)
{ {
auto modbus_coils = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::ModbusCoils); auto modbus_coils = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::ModbusCoils);
@ -27,7 +27,7 @@
return modbus_coils; return modbus_coils;
} }
zeek::IntrusivePtr<RecordVal> HeaderToVal(ModbusTCP_TransportHeader* header) RecordValPtr HeaderToVal(ModbusTCP_TransportHeader* header)
{ {
auto modbus_header = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ModbusHeaders); auto modbus_header = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ModbusHeaders);
modbus_header->Assign(0, val_mgr->Count(header->tid())); modbus_header->Assign(0, val_mgr->Count(header->tid()));
@ -37,7 +37,7 @@
return modbus_header; return modbus_header;
} }
zeek::IntrusivePtr<VectorVal> create_vector_of_count() VectorValPtr create_vector_of_count()
{ {
auto vt = zeek::make_intrusive<zeek::VectorType>(zeek::base_type(zeek::TYPE_COUNT)); auto vt = zeek::make_intrusive<zeek::VectorType>(zeek::base_type(zeek::TYPE_COUNT));
auto vv = zeek::make_intrusive<VectorVal>(std::move(vt)); auto vv = zeek::make_intrusive<VectorVal>(std::move(vt));

View file

@ -1,12 +1,12 @@
%header{ %header{
zeek::IntrusivePtr<Val> filetime2brotime(uint64_t ts); ValPtr filetime2brotime(uint64_t ts);
zeek::IntrusivePtr<RecordVal> build_version_record(NTLM_Version* val); RecordValPtr build_version_record(NTLM_Version* val);
zeek::IntrusivePtr<RecordVal> build_negotiate_flag_record(NTLM_Negotiate_Flags* val); RecordValPtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val);
%} %}
%code{ %code{
// This is replicated from the SMB analyzer. :( // This is replicated from the SMB analyzer. :(
zeek::IntrusivePtr<Val> filetime2brotime(uint64_t ts) ValPtr filetime2brotime(uint64_t ts)
{ {
double secs = (ts / 10000000.0); double secs = (ts / 10000000.0);
@ -17,7 +17,7 @@
return bro_ts; return bro_ts;
} }
zeek::IntrusivePtr<RecordVal> build_version_record(NTLM_Version* val) RecordValPtr build_version_record(NTLM_Version* val)
{ {
auto result = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTLM::Version); auto result = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTLM::Version);
result->Assign(0, val_mgr->Count(${val.major_version})); result->Assign(0, val_mgr->Count(${val.major_version}));
@ -28,7 +28,7 @@
return result; return result;
} }
zeek::IntrusivePtr<RecordVal> build_negotiate_flag_record(NTLM_Negotiate_Flags* val) RecordValPtr build_negotiate_flag_record(NTLM_Negotiate_Flags* val)
{ {
auto flags = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTLM::NegotiateFlags); auto flags = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTLM::NegotiateFlags);
flags->Assign(0, val_mgr->Bool(${val.negotiate_56})); flags->Assign(0, val_mgr->Bool(${val.negotiate_56}));

View file

@ -8,23 +8,23 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<Val> proc_ntp_short(const NTP_Short_Time* t); ValPtr proc_ntp_short(const NTP_Short_Time* t);
zeek::IntrusivePtr<Val> proc_ntp_timestamp(const NTP_Time* t); ValPtr proc_ntp_timestamp(const NTP_Time* t);
zeek::IntrusivePtr<RecordVal> BuildNTPStdMsg(NTP_std_msg* nsm); RecordValPtr BuildNTPStdMsg(NTP_std_msg* nsm);
zeek::IntrusivePtr<RecordVal> BuildNTPControlMsg(NTP_control_msg* ncm); RecordValPtr BuildNTPControlMsg(NTP_control_msg* ncm);
zeek::IntrusivePtr<RecordVal> BuildNTPMode7Msg(NTP_mode7_msg* m7); RecordValPtr BuildNTPMode7Msg(NTP_mode7_msg* m7);
%} %}
%code{ %code{
zeek::IntrusivePtr<Val> proc_ntp_short(const NTP_Short_Time* t) ValPtr proc_ntp_short(const NTP_Short_Time* t)
{ {
if ( t->seconds() == 0 && t->fractions() == 0 ) if ( t->seconds() == 0 && t->fractions() == 0 )
return zeek::make_intrusive<IntervalVal>(0.0); return zeek::make_intrusive<IntervalVal>(0.0);
return zeek::make_intrusive<IntervalVal>(t->seconds() + t->fractions()*FRAC_16); return zeek::make_intrusive<IntervalVal>(t->seconds() + t->fractions()*FRAC_16);
} }
zeek::IntrusivePtr<Val> proc_ntp_timestamp(const NTP_Time* t) ValPtr proc_ntp_timestamp(const NTP_Time* t)
{ {
if ( t->seconds() == 0 && t->fractions() == 0) if ( t->seconds() == 0 && t->fractions() == 0)
return zeek::make_intrusive<TimeVal>(0.0); return zeek::make_intrusive<TimeVal>(0.0);
@ -32,7 +32,7 @@
} }
// This builds the standard msg record // This builds the standard msg record
zeek::IntrusivePtr<RecordVal> BuildNTPStdMsg(NTP_std_msg* nsm) RecordValPtr BuildNTPStdMsg(NTP_std_msg* nsm)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::StandardMessage); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::StandardMessage);
@ -85,7 +85,7 @@
} }
// This builds the control msg record // This builds the control msg record
zeek::IntrusivePtr<RecordVal> BuildNTPControlMsg(NTP_control_msg* ncm) RecordValPtr BuildNTPControlMsg(NTP_control_msg* ncm)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::ControlMessage); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::ControlMessage);
@ -110,7 +110,7 @@
} }
// This builds the mode7 msg record // This builds the mode7 msg record
zeek::IntrusivePtr<RecordVal> BuildNTPMode7Msg(NTP_mode7_msg* m7) RecordValPtr BuildNTPMode7Msg(NTP_mode7_msg* m7)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::Mode7Message); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NTP::Mode7Message);

View file

@ -22,7 +22,7 @@ refine flow RADIUS_Flow += {
// Do we already have a vector of attributes for this type? // Do we already have a vector of attributes for this type?
auto current = attributes->FindOrDefault(index); auto current = attributes->FindOrDefault(index);
zeek::IntrusivePtr<Val> val = to_stringval(${msg.attributes[i].value}); ValPtr val = to_stringval(${msg.attributes[i].value});
if ( current ) if ( current )
{ {

View file

@ -22,7 +22,7 @@ bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
uint32_t proc = c->Proc(); uint32_t proc = c->Proc();
// The call arguments, depends on the call type obviously ... // The call arguments, depends on the call type obviously ...
zeek::IntrusivePtr<RecordVal> callarg; RecordValPtr callarg;
switch ( proc ) { switch ( proc ) {
case BifEnum::MOUNT3::PROC_NULL: 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) double last_time, int reply_len)
{ {
EventHandlerPtr event = nullptr; EventHandlerPtr event = nullptr;
zeek::IntrusivePtr<Val> reply; ValPtr reply;
BifEnum::MOUNT3::status_t mount_status = BifEnum::MOUNT3::MNT3_OK; BifEnum::MOUNT3::status_t mount_status = BifEnum::MOUNT3::MNT3_OK;
bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS );
@ -203,14 +203,14 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c,
return vl; return vl;
} }
zeek::IntrusivePtr<EnumVal> 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); 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); auto rval = zeek::BifType::Enum::MOUNT3::auth_flavor_t->GetVal(t);
return rval; return rval;
} }
zeek::IntrusivePtr<StringVal> MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) StringValPtr MOUNT_Interp::mount3_fh(const u_char*& buf, int& n)
{ {
int fh_n; int fh_n;
const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64);
@ -221,7 +221,7 @@ zeek::IntrusivePtr<StringVal> MOUNT_Interp::mount3_fh(const u_char*& buf, int& n
return zeek::make_intrusive<StringVal>(new BroString(fh, fh_n, false)); return zeek::make_intrusive<StringVal>(new BroString(fh, fh_n, false));
} }
zeek::IntrusivePtr<StringVal> MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) StringValPtr MOUNT_Interp::mount3_filename(const u_char*& buf, int& n)
{ {
int name_len; int name_len;
const u_char* name = extract_XDR_opaque(buf, n, name_len); const u_char* name = extract_XDR_opaque(buf, n, name_len);
@ -232,15 +232,15 @@ zeek::IntrusivePtr<StringVal> MOUNT_Interp::mount3_filename(const u_char*& buf,
return zeek::make_intrusive<StringVal>(new BroString(name, name_len, false)); return zeek::make_intrusive<StringVal>(new BroString(name, name_len, false));
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::MOUNT3::dirmntargs_t); auto dirmntargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::MOUNT3::dirmntargs_t);
dirmntargs->Assign(0, mount3_filename(buf, n)); dirmntargs->Assign(0, mount3_filename(buf, n));
return dirmntargs; return dirmntargs;
} }
zeek::IntrusivePtr<RecordVal> MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n, RecordValPtr MOUNT_Interp::mount3_mnt_reply(const u_char*& buf, int& n,
BifEnum::MOUNT3::status_t status) BifEnum::MOUNT3::status_t status)
{ {
auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::MOUNT3::mnt_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::MOUNT3::mnt_reply_t);

View file

@ -29,12 +29,12 @@ protected:
// to 0. However, the methods might still return an allocated Val * ! // 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 // So, you might want to Unref() the Val if buf is 0. Method names
// are based on the type names of RFC 1813. // are based on the type names of RFC 1813.
zeek::IntrusivePtr<EnumVal> mount3_auth_flavor(const u_char*& buf, int& n); EnumValPtr mount3_auth_flavor(const u_char*& buf, int& n);
zeek::IntrusivePtr<StringVal> mount3_fh(const u_char*& buf, int& n); StringValPtr mount3_fh(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> mount3_dirmntargs(const u_char*&buf, int &n); RecordValPtr mount3_dirmntargs(const u_char*&buf, int &n);
zeek::IntrusivePtr<StringVal> mount3_filename(const u_char*& buf, int& n); StringValPtr mount3_filename(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> 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 { class MOUNT_Analyzer : public RPC_Analyzer {

View file

@ -22,7 +22,7 @@ bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n)
uint32_t proc = c->Proc(); uint32_t proc = c->Proc();
// The call arguments, depends on the call type obviously ... // The call arguments, depends on the call type obviously ...
zeek::IntrusivePtr<Val> callarg; ValPtr callarg;
switch ( proc ) { switch ( proc ) {
case BifEnum::NFS3::PROC_NULL: 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) double last_time, int reply_len)
{ {
EventHandlerPtr event = nullptr; EventHandlerPtr event = nullptr;
zeek::IntrusivePtr<Val> reply; ValPtr reply;
BifEnum::NFS3::status_t nfs_status = BifEnum::NFS3::NFS3ERR_OK; BifEnum::NFS3::status_t nfs_status = BifEnum::NFS3::NFS3ERR_OK;
bool rpc_success = ( rpc_status == BifEnum::RPC_SUCCESS ); 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; return true;
} }
zeek::IntrusivePtr<StringVal> 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; int data_n;
@ -336,7 +336,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_
return vl; return vl;
} }
zeek::IntrusivePtr<StringVal> NFS_Interp::nfs3_fh(const u_char*& buf, int& n) StringValPtr NFS_Interp::nfs3_fh(const u_char*& buf, int& n)
{ {
int fh_n; int fh_n;
const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64); const u_char* fh = extract_XDR_opaque(buf, n, fh_n, 64);
@ -348,7 +348,7 @@ zeek::IntrusivePtr<StringVal> NFS_Interp::nfs3_fh(const u_char*& buf, int& n)
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::sattr_t); auto attrs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::sattr_t);
@ -379,7 +379,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_sattr(const u_char*& buf, int& n)
return attrs; return attrs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::sattr_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::sattr_reply_t);
@ -397,7 +397,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_sattr_reply(const u_char*& buf, i
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::fattr_t); auto attrs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::fattr_t);
@ -419,21 +419,21 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_fattr(const u_char*& buf, int& n)
return attrs; return attrs;
} }
zeek::IntrusivePtr<EnumVal> 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); 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); auto rval = zeek::BifType::Enum::NFS3::time_how_t->GetVal(t);
return rval; return rval;
} }
zeek::IntrusivePtr<EnumVal> 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); 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); auto rval = zeek::BifType::Enum::NFS3::file_type_t->GetVal(t);
return rval; return rval;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::wcc_attr_t); auto attrs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::wcc_attr_t);
@ -444,7 +444,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_wcc_attr(const u_char*& buf, int&
return attrs; return attrs;
} }
zeek::IntrusivePtr<StringVal> NFS_Interp::nfs3_filename(const u_char*& buf, int& n) StringValPtr NFS_Interp::nfs3_filename(const u_char*& buf, int& n)
{ {
int name_len; int name_len;
const u_char* name = extract_XDR_opaque(buf, n, name_len); const u_char* name = extract_XDR_opaque(buf, n, name_len);
@ -455,7 +455,7 @@ zeek::IntrusivePtr<StringVal> NFS_Interp::nfs3_filename(const u_char*& buf, int&
return zeek::make_intrusive<StringVal>(new BroString(name, name_len, false)); return zeek::make_intrusive<StringVal>(new BroString(name, name_len, false));
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::diropargs_t); auto diropargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::diropargs_t);
@ -465,7 +465,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_diropargs(const u_char*& buf, int
return diropargs; return diropargs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::symlinkdata_t); auto symlinkdata = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::symlinkdata_t);
@ -475,7 +475,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_symlinkdata(const u_char*& buf, i
return symlinkdata; return symlinkdata;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::renameopargs_t); auto renameopargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::renameopargs_t);
@ -487,7 +487,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_renameopargs(const u_char*& buf,
return renameopargs; return renameopargs;
} }
zeek::IntrusivePtr<RecordVal> 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); int have_attrs = extract_XDR_uint32(buf, n);
@ -497,7 +497,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_post_op_attr(const u_char*& buf,
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<StringVal> 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); int have_fh = extract_XDR_uint32(buf, n);
@ -507,7 +507,7 @@ zeek::IntrusivePtr<StringVal> NFS_Interp::nfs3_post_op_fh(const u_char*& buf, in
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<RecordVal> 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); int have_attrs = extract_XDR_uint32(buf, n);
@ -516,14 +516,14 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_pre_op_attr(const u_char*& buf, i
return nullptr; return nullptr;
} }
zeek::IntrusivePtr<EnumVal> 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); 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); auto rval = zeek::BifType::Enum::NFS3::stable_how_t->GetVal(stable);
return rval; return rval;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::lookup_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::lookup_reply_t);
@ -542,7 +542,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_lookup_reply(const u_char*& buf,
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::readargs_t); auto readargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::readargs_t);
@ -553,7 +553,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_readargs(const u_char*& buf, int&
return readargs; return readargs;
} }
zeek::IntrusivePtr<RecordVal> 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) bro_uint_t offset)
{ {
auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::read_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::read_reply_t);
@ -576,7 +576,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_read_reply(const u_char*& buf, in
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::readlink_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::readlink_reply_t);
@ -593,7 +593,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_readlink_reply(const u_char*& buf
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::link_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::link_reply_t);
@ -609,7 +609,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_link_reply(const u_char*& buf, in
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::symlinkargs_t); auto symlinkargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::symlinkargs_t);
@ -619,7 +619,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_symlinkargs(const u_char*& buf, i
return symlinkargs; return symlinkargs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::sattrargs_t); auto sattrargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::sattrargs_t);
@ -629,7 +629,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_sattrargs(const u_char*& buf, int
return sattrargs; return sattrargs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::linkargs_t); auto linkargs = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::linkargs_t);
@ -639,7 +639,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_linkargs(const u_char*& buf, int&
return linkargs; return linkargs;
} }
zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n) RecordValPtr NFS_Interp::nfs3_writeargs(const u_char*& buf, int& n)
{ {
uint32_t bytes; uint32_t bytes;
uint64_t offset; uint64_t offset;
@ -657,7 +657,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_writeargs(const u_char*& buf, int
return writeargs; return writeargs;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::write_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::write_reply_t);
@ -682,7 +682,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_write_reply(const u_char*& buf, i
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::newobj_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::newobj_reply_t);
@ -706,7 +706,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_newobj_reply(const u_char*& buf,
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::delobj_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::delobj_reply_t);
@ -717,7 +717,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_delobj_reply(const u_char*& buf,
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::renameobj_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::renameobj_reply_t);
@ -730,7 +730,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_renameobj_reply(const u_char*& bu
return rep; return rep;
} }
zeek::IntrusivePtr<RecordVal> 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<RecordVal>(zeek::BifType::Record::NFS3::readdirargs_t); auto args = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::readdirargs_t);
@ -746,7 +746,7 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_readdirargs(bool isplus, const u_
return args; return args;
} }
zeek::IntrusivePtr<RecordVal> 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) int&n, BifEnum::NFS3::status_t status)
{ {
auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::readdir_reply_t); auto rep = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::NFS3::readdir_reply_t);
@ -791,27 +791,27 @@ zeek::IntrusivePtr<RecordVal> NFS_Interp::nfs3_readdir_reply(bool isplus, const
return rep; return rep;
} }
zeek::IntrusivePtr<Val> 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)); return val_mgr->Count(extract_XDR_uint32(buf, n));
} }
zeek::IntrusivePtr<Val> 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)); return val_mgr->Count(extract_XDR_uint64(buf, n));
} }
zeek::IntrusivePtr<Val> NFS_Interp::ExtractTime(const u_char*& buf, int& n) ValPtr NFS_Interp::ExtractTime(const u_char*& buf, int& n)
{ {
return zeek::make_intrusive<TimeVal>(extract_XDR_time(buf, n)); return zeek::make_intrusive<TimeVal>(extract_XDR_time(buf, n));
} }
zeek::IntrusivePtr<Val> NFS_Interp::ExtractInterval(const u_char*& buf, int& n) ValPtr NFS_Interp::ExtractInterval(const u_char*& buf, int& n)
{ {
return zeek::make_intrusive<IntervalVal>(double(extract_XDR_uint32(buf, n)), 1.0); return zeek::make_intrusive<IntervalVal>(double(extract_XDR_uint32(buf, n)), 1.0);
} }
zeek::IntrusivePtr<Val> 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)); return val_mgr->Bool(extract_XDR_uint32(buf, n));
} }

View file

@ -30,53 +30,53 @@ protected:
// to 0. However, the methods might still return an allocated Val * ! // 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 // So, you might want to Unref() the Val if buf is 0. Method names
// are based on the type names of RFC 1813. // are based on the type names of RFC 1813.
zeek::IntrusivePtr<StringVal> nfs3_fh(const u_char*& buf, int& n); StringValPtr nfs3_fh(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_fattr(const u_char*& buf, int& n); RecordValPtr nfs3_fattr(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_sattr(const u_char*& buf, int& n); RecordValPtr nfs3_sattr(const u_char*& buf, int& n);
zeek::IntrusivePtr<EnumVal> nfs3_ftype(const u_char*& buf, int& n); EnumValPtr nfs3_ftype(const u_char*& buf, int& n);
zeek::IntrusivePtr<EnumVal> nfs3_time_how(const u_char*& buf, int& n); EnumValPtr nfs3_time_how(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_wcc_attr(const u_char*& buf, int& n); RecordValPtr nfs3_wcc_attr(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_diropargs(const u_char*&buf, int &n); RecordValPtr nfs3_diropargs(const u_char*&buf, int &n);
zeek::IntrusivePtr<RecordVal> nfs3_symlinkdata(const u_char*& buf, int& n); RecordValPtr nfs3_symlinkdata(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_renameopargs(const u_char*&buf, int &n); RecordValPtr nfs3_renameopargs(const u_char*&buf, int &n);
zeek::IntrusivePtr<StringVal> nfs3_filename(const u_char*& buf, int& n); StringValPtr nfs3_filename(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_linkargs(const u_char*& buf, int& n); RecordValPtr nfs3_linkargs(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_symlinkargs(const u_char*& buf, int& n); RecordValPtr nfs3_symlinkargs(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_sattrargs(const u_char*& buf, int& n); RecordValPtr nfs3_sattrargs(const u_char*& buf, int& n);
zeek::IntrusivePtr<StringVal> nfs3_nfspath(const u_char*& buf, int& n) StringValPtr nfs3_nfspath(const u_char*& buf, int& n)
{ {
return nfs3_filename(buf,n); return nfs3_filename(buf,n);
} }
zeek::IntrusivePtr<RecordVal> nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr RecordValPtr nfs3_post_op_attr(const u_char*&buf, int &n); // Return 0 or an fattr
zeek::IntrusivePtr<RecordVal> nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr RecordValPtr nfs3_pre_op_attr(const u_char*&buf, int &n); // Return 0 or an wcc_attr
zeek::IntrusivePtr<RecordVal> nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); RecordValPtr nfs3_sattr_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status);
zeek::IntrusivePtr<RecordVal> nfs3_lookup_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);
zeek::IntrusivePtr<RecordVal> nfs3_readargs(const u_char*& buf, int& n); RecordValPtr nfs3_readargs(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset); RecordValPtr nfs3_read_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status, bro_uint_t offset);
zeek::IntrusivePtr<RecordVal> nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); RecordValPtr nfs3_readlink_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status);
zeek::IntrusivePtr<RecordVal> nfs3_link_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);
zeek::IntrusivePtr<RecordVal> nfs3_writeargs(const u_char*& buf, int& n); RecordValPtr nfs3_writeargs(const u_char*& buf, int& n);
zeek::IntrusivePtr<EnumVal> nfs3_stable_how(const u_char*& buf, int& n); EnumValPtr nfs3_stable_how(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status); RecordValPtr nfs3_write_reply(const u_char*& buf, int& n, BifEnum::NFS3::status_t status);
zeek::IntrusivePtr<RecordVal> nfs3_newobj_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);
zeek::IntrusivePtr<RecordVal> nfs3_delobj_reply(const u_char*& buf, int& n); RecordValPtr nfs3_delobj_reply(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_renameobj_reply(const u_char*& buf, int& n); RecordValPtr nfs3_renameobj_reply(const u_char*& buf, int& n);
zeek::IntrusivePtr<StringVal> nfs3_post_op_fh(const u_char*& buf, int& n); StringValPtr nfs3_post_op_fh(const u_char*& buf, int& n);
zeek::IntrusivePtr<RecordVal> nfs3_readdirargs(bool isplus, const u_char*& buf, int&n); RecordValPtr nfs3_readdirargs(bool isplus, const u_char*& buf, int&n);
zeek::IntrusivePtr<RecordVal> nfs3_readdir_reply(bool isplus, const u_char*& buf, int&n, BifEnum::NFS3::status_t status); 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 // 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: // in bro.init returns NULL or the data as string val:
// * offset is the offset of the read/write call // * offset is the offset of the read/write call
// * size is the amount of bytes read (or requested to be written), // * size is the amount of bytes read (or requested to be written),
zeek::IntrusivePtr<StringVal> 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<Val> ExtractUint32(const u_char*& buf, int& n); ValPtr ExtractUint32(const u_char*& buf, int& n);
zeek::IntrusivePtr<Val> ExtractUint64(const u_char*& buf, int& n); ValPtr ExtractUint64(const u_char*& buf, int& n);
zeek::IntrusivePtr<Val> ExtractTime(const u_char*& buf, int& n); ValPtr ExtractTime(const u_char*& buf, int& n);
zeek::IntrusivePtr<Val> ExtractInterval(const u_char*& buf, int& n); ValPtr ExtractInterval(const u_char*& buf, int& n);
zeek::IntrusivePtr<Val> ExtractBool(const u_char*& buf, int& n); ValPtr ExtractBool(const u_char*& buf, int& n);
}; };
class NFS_Analyzer : public RPC_Analyzer { class NFS_Analyzer : public RPC_Analyzer {

View file

@ -79,7 +79,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu
int reply_len) int reply_len)
{ {
EventHandlerPtr event; EventHandlerPtr event;
zeek::IntrusivePtr<Val> reply; ValPtr reply;
int success = (status == BifEnum::RPC_SUCCESS); int success = (status == BifEnum::RPC_SUCCESS);
switch ( c->Proc() ) { switch ( c->Proc() ) {
@ -189,7 +189,7 @@ bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status statu
return true; return true;
} }
zeek::IntrusivePtr<Val> 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<zeek::RecordType>("pm_mapping"); static auto pm_mapping = zeek::id::find_type<zeek::RecordType>("pm_mapping");
auto mapping = zeek::make_intrusive<RecordVal>(pm_mapping); auto mapping = zeek::make_intrusive<RecordVal>(pm_mapping);
@ -207,7 +207,7 @@ zeek::IntrusivePtr<Val> PortmapperInterp::ExtractMapping(const u_char*& buf, int
return mapping; return mapping;
} }
zeek::IntrusivePtr<Val> 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<zeek::RecordType>("pm_port_request"); static auto pm_port_request = zeek::id::find_type<zeek::RecordType>("pm_port_request");
auto pr = zeek::make_intrusive<RecordVal>(pm_port_request); auto pr = zeek::make_intrusive<RecordVal>(pm_port_request);
@ -225,7 +225,7 @@ zeek::IntrusivePtr<Val> PortmapperInterp::ExtractPortRequest(const u_char*& buf,
return pr; return pr;
} }
zeek::IntrusivePtr<Val> 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<zeek::RecordType>("pm_callit_request"); static auto pm_callit_request = zeek::id::find_type<zeek::RecordType>("pm_callit_request");
auto c = zeek::make_intrusive<RecordVal>(pm_callit_request); auto c = zeek::make_intrusive<RecordVal>(pm_callit_request);
@ -262,7 +262,7 @@ uint32_t PortmapperInterp::CheckPort(uint32_t port)
return port; return port;
} }
void PortmapperInterp::Event(EventHandlerPtr f, zeek::IntrusivePtr<Val> request, BifEnum::rpc_status status, zeek::IntrusivePtr<Val> reply) void PortmapperInterp::Event(EventHandlerPtr f, ValPtr request, BifEnum::rpc_status status, ValPtr reply)
{ {
if ( ! f ) if ( ! f )
return; return;

View file

@ -17,11 +17,11 @@ protected:
double last_time, int reply_len) override; double last_time, int reply_len) override;
uint32_t CheckPort(uint32_t port); uint32_t CheckPort(uint32_t port);
void Event(EventHandlerPtr f, zeek::IntrusivePtr<Val> request, BifEnum::rpc_status status, zeek::IntrusivePtr<Val> reply); void Event(EventHandlerPtr f, ValPtr request, BifEnum::rpc_status status, ValPtr reply);
zeek::IntrusivePtr<Val> ExtractMapping(const u_char*& buf, int& len); ValPtr ExtractMapping(const u_char*& buf, int& len);
zeek::IntrusivePtr<Val> ExtractPortRequest(const u_char*& buf, int& len); ValPtr ExtractPortRequest(const u_char*& buf, int& len);
zeek::IntrusivePtr<Val> ExtractCallItRequest(const u_char*& buf, int& len); ValPtr ExtractCallItRequest(const u_char*& buf, int& len);
}; };
class Portmapper_Analyzer : public RPC_Analyzer { class Portmapper_Analyzer : public RPC_Analyzer {

View file

@ -52,9 +52,9 @@ public:
double last_time, int rpc_len); double last_time, int rpc_len);
~RPC_CallInfo(); ~RPC_CallInfo();
void AddVal(zeek::IntrusivePtr<Val> arg_v) { v = std::move(arg_v); } void AddVal(ValPtr arg_v) { v = std::move(arg_v); }
const zeek::IntrusivePtr<Val>& RequestVal() const { return v; } const ValPtr& RequestVal() const { return v; }
zeek::IntrusivePtr<Val> TakeRequestVal() { auto rv = std::move(v); return rv; } ValPtr TakeRequestVal() { auto rv = std::move(v); return rv; }
bool CompareRexmit(const u_char* buf, int n) const; bool CompareRexmit(const u_char* buf, int n) const;
@ -95,7 +95,7 @@ protected:
int header_len; // size of data before the arguments int header_len; // size of data before the arguments
bool valid_call; // whether call was well-formed bool valid_call; // whether call was well-formed
zeek::IntrusivePtr<Val> v; // single (perhaps compound) value corresponding to call ValPtr v; // single (perhaps compound) value corresponding to call
}; };
class RPC_Interpreter { class RPC_Interpreter {

View file

@ -3,7 +3,7 @@ refine flow SIP_Flow += {
%member{ %member{
int content_length; int content_length;
bool build_headers; bool build_headers;
std::vector<zeek::IntrusivePtr<Val>> headers; std::vector<ValPtr> headers;
%} %}
%init{ %init{
@ -104,7 +104,7 @@ refine flow SIP_Flow += {
%{ %{
static auto mime_header_rec = zeek::id::find_type<zeek::RecordType>("mime_header_rec"); static auto mime_header_rec = zeek::id::find_type<zeek::RecordType>("mime_header_rec");
RecordVal* header_record = new RecordVal(mime_header_rec); RecordVal* header_record = new RecordVal(mime_header_rec);
zeek::IntrusivePtr<StringVal> name_val; StringValPtr name_val;
if ( name.length() > 0 ) if ( name.length() > 0 )
{ {

View file

@ -3,7 +3,7 @@
%} %}
%code{ %code{
zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::uint8s_to_stringval(std::vector<uint8_t>* data) StringValPtr binpac::SMB::SMB_Conn::uint8s_to_stringval(std::vector<uint8_t>* data)
{ {
int length = data->size(); int length = data->size();
auto buf = std::make_unique<uint8[]>(length); auto buf = std::make_unique<uint8[]>(length);
@ -15,7 +15,7 @@ zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::uint8s_to_stringval(std::ve
return utf16_to_utf8_val(bro_analyzer()->Conn(), bs); return utf16_to_utf8_val(bro_analyzer()->Conn(), bs);
} }
zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::extract_string(SMB_string* s) StringValPtr binpac::SMB::SMB_Conn::extract_string(SMB_string* s)
{ {
if ( s->unicode() == false ) if ( s->unicode() == false )
{ {
@ -37,12 +37,12 @@ zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::extract_string(SMB_string*
return uint8s_to_stringval(s->u()->s()); return uint8s_to_stringval(s->u()->s());
} }
zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::smb_string2stringval(SMB_string* s) StringValPtr binpac::SMB::SMB_Conn::smb_string2stringval(SMB_string* s)
{ {
return extract_string(s); return extract_string(s);
} }
zeek::IntrusivePtr<StringVal> 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()); return uint8s_to_stringval(s->s());
} }
@ -50,10 +50,10 @@ zeek::IntrusivePtr<StringVal> binpac::SMB::SMB_Conn::smb2_string2stringval(SMB2_
refine connection SMB_Conn += { refine connection SMB_Conn += {
%member{ %member{
zeek::IntrusivePtr<StringVal> uint8s_to_stringval(std::vector<uint8_t>* data); StringValPtr uint8s_to_stringval(std::vector<uint8_t>* data);
zeek::IntrusivePtr<StringVal> extract_string(SMB_string* s); StringValPtr extract_string(SMB_string* s);
zeek::IntrusivePtr<StringVal> smb_string2stringval(SMB_string* s); StringValPtr smb_string2stringval(SMB_string* s);
zeek::IntrusivePtr<StringVal> smb2_string2stringval(SMB2_string* s); StringValPtr smb2_string2stringval(SMB2_string* s);
SMB_unicode_string* me; SMB_unicode_string* me;
%} %}

View file

@ -1,13 +1,13 @@
%header{ %header{
zeek::IntrusivePtr<Val> filetime2brotime(uint64_t ts); ValPtr filetime2brotime(uint64_t ts);
zeek::IntrusivePtr<Val> 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);
zeek::IntrusivePtr<RecordVal> SMB_BuildMACTimes(uint64_t modify, uint64_t access, RecordValPtr SMB_BuildMACTimes(uint64_t modify, uint64_t access,
uint64_t create, uint64_t change); uint64_t create, uint64_t change);
%} %}
%code{ %code{
zeek::IntrusivePtr<Val> filetime2brotime(uint64_t ts) ValPtr filetime2brotime(uint64_t ts)
{ {
// Bro can't support times back to the 1600's // Bro can't support times back to the 1600's
// so we subtract a lot of seconds. // so we subtract a lot of seconds.
@ -15,7 +15,7 @@ zeek::IntrusivePtr<Val> filetime2brotime(uint64_t ts)
return zeek::make_intrusive<TimeVal>(secs); return zeek::make_intrusive<TimeVal>(secs);
} }
zeek::IntrusivePtr<Val> 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; tm lTime;
lTime.tm_sec = ${t.two_seconds} * 2; lTime.tm_sec = ${t.two_seconds} * 2;
@ -29,7 +29,7 @@ zeek::IntrusivePtr<Val> time_from_lanman(SMB_time* t, SMB_date* d, uint16_t tz)
return zeek::make_intrusive<TimeVal>(lResult + tz); return zeek::make_intrusive<TimeVal>(lResult + tz);
} }
zeek::IntrusivePtr<RecordVal> SMB_BuildMACTimes(uint64_t modify, uint64_t access, RecordValPtr SMB_BuildMACTimes(uint64_t modify, uint64_t access,
uint64_t create, uint64_t change) uint64_t create, uint64_t change)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB::MACTimes); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB::MACTimes);

View file

@ -17,7 +17,7 @@ refine connection SMB_Conn += {
auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(), auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(),
(const char*)${val.parameters}.data()); (const char*)${val.parameters}.data());
zeek::IntrusivePtr<StringVal> payload_str; StringValPtr payload_str;
SMB1_transaction_data* payload = nullptr; SMB1_transaction_data* payload = nullptr;
if ( ${val.data_count} > 0 ) if ( ${val.data_count} > 0 )

View file

@ -5,7 +5,7 @@ enum Trans_subcommands {
}; };
%code{ %code{
zeek::IntrusivePtr<StringVal> 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() ) { switch ( payload->trans_type() ) {
case SMB_PIPE: case SMB_PIPE:
@ -26,7 +26,7 @@ refine connection SMB_Conn += {
%member{ %member{
map<uint16, bool> is_file_a_pipe; map<uint16, bool> is_file_a_pipe;
static zeek::IntrusivePtr<StringVal> 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 function get_is_file_a_pipe(id: uint16): bool
@ -55,7 +55,7 @@ refine connection SMB_Conn += {
auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(), auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(),
(const char*)${val.parameters}.data()); (const char*)${val.parameters}.data());
zeek::IntrusivePtr<StringVal> payload_str; StringValPtr payload_str;
if ( ${val.data_count} > 0 ) if ( ${val.data_count} > 0 )
payload_str = transaction_data_to_val(${val.data}); payload_str = transaction_data_to_val(${val.data});
@ -80,7 +80,7 @@ refine connection SMB_Conn += {
auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(), auto parameters = zeek::make_intrusive<StringVal>(${val.parameters}.length(),
(const char*)${val.parameters}.data()); (const char*)${val.parameters}.data());
zeek::IntrusivePtr<StringVal> payload_str; StringValPtr payload_str;
if ( ${val.data_count} > 0 ) if ( ${val.data_count} > 0 )
payload_str = transaction_data_to_val(${val.data[0]}); payload_str = transaction_data_to_val(${val.data[0]});

View file

@ -3,11 +3,11 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<RecordVal> SMBHeaderVal(SMB_Header* hdr); RecordValPtr SMBHeaderVal(SMB_Header* hdr);
%} %}
%code{ %code{
zeek::IntrusivePtr<RecordVal> SMBHeaderVal(SMB_Header* hdr) RecordValPtr SMBHeaderVal(SMB_Header* hdr)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB1::Header); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB1::Header);

View file

@ -2,14 +2,14 @@
# http://msdn.microsoft.com/en-us/library/cc246497(v=PROT.13).aspx # http://msdn.microsoft.com/en-us/library/cc246497(v=PROT.13).aspx
%header{ %header{
zeek::IntrusivePtr<RecordVal> BuildSMB2HeaderVal(SMB2_Header* hdr); RecordValPtr BuildSMB2HeaderVal(SMB2_Header* hdr);
zeek::IntrusivePtr<RecordVal> BuildSMB2GUID(SMB2_guid* file_id); RecordValPtr BuildSMB2GUID(SMB2_guid* file_id);
zeek::IntrusivePtr<RecordVal> smb2_file_attrs_to_bro(SMB2_file_attributes* val); RecordValPtr smb2_file_attrs_to_bro(SMB2_file_attributes* val);
zeek::IntrusivePtr<RecordVal> BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv); RecordValPtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv);
%} %}
%code{ %code{
zeek::IntrusivePtr<RecordVal> BuildSMB2HeaderVal(SMB2_Header* hdr) RecordValPtr BuildSMB2HeaderVal(SMB2_Header* hdr)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::Header); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::Header);
r->Assign(0, val_mgr->Count(${hdr.credit_charge})); r->Assign(0, val_mgr->Count(${hdr.credit_charge}));
@ -25,7 +25,7 @@ zeek::IntrusivePtr<RecordVal> BuildSMB2HeaderVal(SMB2_Header* hdr)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> BuildSMB2GUID(SMB2_guid* file_id) RecordValPtr BuildSMB2GUID(SMB2_guid* file_id)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::GUID); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::GUID);
r->Assign(0, val_mgr->Count(${file_id.persistent})); r->Assign(0, val_mgr->Count(${file_id.persistent}));
@ -33,7 +33,7 @@ zeek::IntrusivePtr<RecordVal> BuildSMB2GUID(SMB2_guid* file_id)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> smb2_file_attrs_to_bro(SMB2_file_attributes* val) RecordValPtr smb2_file_attrs_to_bro(SMB2_file_attributes* val)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::FileAttrs); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::FileAttrs);
r->Assign(0, val_mgr->Bool(${val.read_only})); r->Assign(0, val_mgr->Bool(${val.read_only}));
@ -54,7 +54,7 @@ zeek::IntrusivePtr<RecordVal> smb2_file_attrs_to_bro(SMB2_file_attributes* val)
return r; return r;
} }
zeek::IntrusivePtr<RecordVal> BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) RecordValPtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv)
{ {
auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::NegotiateContextValue); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SMB2::NegotiateContextValue);

View file

@ -8,26 +8,26 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<AddrVal> network_address_to_val(const ASN1Encoding* na); AddrValPtr network_address_to_val(const ASN1Encoding* na);
zeek::IntrusivePtr<AddrVal> network_address_to_val(const NetworkAddress* na); AddrValPtr network_address_to_val(const NetworkAddress* na);
zeek::IntrusivePtr<Val> asn1_obj_to_val(const ASN1Encoding* obj); ValPtr asn1_obj_to_val(const ASN1Encoding* obj);
zeek::IntrusivePtr<RecordVal> build_hdr(const Header* header); RecordValPtr build_hdr(const Header* header);
zeek::IntrusivePtr<RecordVal> build_hdrV3(const Header* header); RecordValPtr build_hdrV3(const Header* header);
zeek::IntrusivePtr<VectorVal> build_bindings(const VarBindList* vbl); VectorValPtr build_bindings(const VarBindList* vbl);
zeek::IntrusivePtr<RecordVal> build_pdu(const CommonPDU* pdu); RecordValPtr build_pdu(const CommonPDU* pdu);
zeek::IntrusivePtr<RecordVal> build_trap_pdu(const TrapPDU* pdu); RecordValPtr build_trap_pdu(const TrapPDU* pdu);
zeek::IntrusivePtr<RecordVal> build_bulk_pdu(const GetBulkRequestPDU* pdu); RecordValPtr build_bulk_pdu(const GetBulkRequestPDU* pdu);
%} %}
%code{ %code{
zeek::IntrusivePtr<AddrVal> network_address_to_val(const NetworkAddress* na) AddrValPtr network_address_to_val(const NetworkAddress* na)
{ {
return network_address_to_val(na->encoding()); return network_address_to_val(na->encoding());
} }
zeek::IntrusivePtr<AddrVal> network_address_to_val(const ASN1Encoding* na) AddrValPtr network_address_to_val(const ASN1Encoding* na)
{ {
bytestring const& bs = na->content(); bytestring const& bs = na->content();
@ -42,9 +42,9 @@ zeek::IntrusivePtr<AddrVal> network_address_to_val(const ASN1Encoding* na)
return zeek::make_intrusive<AddrVal>(ntohl(network_order)); return zeek::make_intrusive<AddrVal>(ntohl(network_order));
} }
zeek::IntrusivePtr<Val> asn1_obj_to_val(const ASN1Encoding* obj) ValPtr asn1_obj_to_val(const ASN1Encoding* obj)
{ {
zeek::IntrusivePtr<RecordVal> rval = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::ObjectValue); RecordValPtr rval = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::ObjectValue);
uint8 tag = obj->meta()->tag(); uint8 tag = obj->meta()->tag();
rval->Assign(0, val_mgr->Count(tag)); rval->Assign(0, val_mgr->Count(tag));
@ -85,12 +85,12 @@ zeek::IntrusivePtr<Val> asn1_obj_to_val(const ASN1Encoding* obj)
return rval; return rval;
} }
zeek::IntrusivePtr<Val> 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); return asn1_integer_to_val(tt->asn1_integer(), zeek::TYPE_COUNT);
} }
zeek::IntrusivePtr<RecordVal> build_hdr(const Header* header) RecordValPtr build_hdr(const Header* header)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::Header); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::Header);
rv->Assign(0, val_mgr->Count(header->version())); rv->Assign(0, val_mgr->Count(header->version()));
@ -122,7 +122,7 @@ zeek::IntrusivePtr<RecordVal> build_hdr(const Header* header)
return rv; return rv;
} }
zeek::IntrusivePtr<RecordVal> build_hdrV3(const Header* header) RecordValPtr build_hdrV3(const Header* header)
{ {
auto v3 = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::HeaderV3); auto v3 = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::HeaderV3);
const v3Header* v3hdr = header->v3(); const v3Header* v3hdr = header->v3();
@ -151,7 +151,7 @@ zeek::IntrusivePtr<RecordVal> build_hdrV3(const Header* header)
return v3; return v3;
} }
zeek::IntrusivePtr<VectorVal> build_bindings(const VarBindList* vbl) VectorValPtr build_bindings(const VarBindList* vbl)
{ {
auto vv = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::SNMP::Bindings); auto vv = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::SNMP::Bindings);
@ -167,7 +167,7 @@ zeek::IntrusivePtr<VectorVal> build_bindings(const VarBindList* vbl)
return vv; return vv;
} }
zeek::IntrusivePtr<RecordVal> build_pdu(const CommonPDU* pdu) RecordValPtr build_pdu(const CommonPDU* pdu)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::PDU); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::PDU);
rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT));
@ -177,7 +177,7 @@ zeek::IntrusivePtr<RecordVal> build_pdu(const CommonPDU* pdu)
return rv; return rv;
} }
zeek::IntrusivePtr<RecordVal> build_trap_pdu(const TrapPDU* pdu) RecordValPtr build_trap_pdu(const TrapPDU* pdu)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::TrapPDU); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::TrapPDU);
rv->Assign(0, asn1_oid_to_val(pdu->enterprise())); rv->Assign(0, asn1_oid_to_val(pdu->enterprise()));
@ -189,7 +189,7 @@ zeek::IntrusivePtr<RecordVal> build_trap_pdu(const TrapPDU* pdu)
return rv; return rv;
} }
zeek::IntrusivePtr<RecordVal> build_bulk_pdu(const GetBulkRequestPDU* pdu) RecordValPtr build_bulk_pdu(const GetBulkRequestPDU* pdu)
{ {
auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::BulkPDU); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::SNMP::BulkPDU);
rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT)); rv->Assign(0, asn1_integer_to_val(pdu->request_id(), zeek::TYPE_INT));

View file

@ -1,10 +1,10 @@
%header{ %header{
zeek::IntrusivePtr<StringVal> array_to_string(vector<uint8> *a); StringValPtr array_to_string(vector<uint8> *a);
%} %}
%code{ %code{
zeek::IntrusivePtr<StringVal> array_to_string(vector<uint8> *a) StringValPtr array_to_string(vector<uint8> *a)
{ {
int len = a->size(); int len = a->size();
auto tmp = std::make_unique<char[]>(len); auto tmp = std::make_unique<char[]>(len);

View file

@ -5,12 +5,12 @@
%} %}
%header{ %header{
zeek::IntrusivePtr<VectorVal> name_list_to_vector(const bytestring& nl); VectorValPtr name_list_to_vector(const bytestring& nl);
%} %}
%code{ %code{
// Copied from IRC_Analyzer::SplitWords // Copied from IRC_Analyzer::SplitWords
zeek::IntrusivePtr<VectorVal> name_list_to_vector(const bytestring& nl) VectorValPtr name_list_to_vector(const bytestring& nl)
{ {
auto vv = zeek::make_intrusive<VectorVal>(zeek::id::string_vec); auto vv = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);

Some files were not shown because too many files have changed in this diff Show more