Move IntrusivePtr and utility methods to the zeek namespace

This commit is contained in:
Tim Wojtulewicz 2020-06-24 16:40:00 -04:00
parent 4668378d91
commit 9364e6a5b7
255 changed files with 3761 additions and 3730 deletions

@ -1 +1 @@
Subproject commit 9c10bb74bb62aa7fb10efc079f1b2e5926e9798c Subproject commit 10a4c007351ab7d16e5cbef0006a5ad9002ea3de

View file

@ -358,9 +358,9 @@ AnonymizeIPAddr_A50::Node* AnonymizeIPAddr_A50::find_node(ipaddr32_t a)
return nullptr; return nullptr;
} }
static IntrusivePtr<TableVal> anon_preserve_orig_addr; static zeek::IntrusivePtr<TableVal> anon_preserve_orig_addr;
static IntrusivePtr<TableVal> anon_preserve_resp_addr; static zeek::IntrusivePtr<TableVal> anon_preserve_resp_addr;
static IntrusivePtr<TableVal> anon_preserve_other_addr; static zeek::IntrusivePtr<TableVal> anon_preserve_other_addr;
void zeek::detail::init_ip_addr_anonymizers() void zeek::detail::init_ip_addr_anonymizers()
{ {
@ -373,23 +373,23 @@ void zeek::detail::init_ip_addr_anonymizers()
auto id = global_scope()->Find("preserve_orig_addr"); auto id = global_scope()->Find("preserve_orig_addr");
if ( id ) if ( id )
anon_preserve_orig_addr = cast_intrusive<TableVal>(id->GetVal()); anon_preserve_orig_addr = zeek::cast_intrusive<TableVal>(id->GetVal());
id = global_scope()->Find("preserve_resp_addr"); id = global_scope()->Find("preserve_resp_addr");
if ( id ) if ( id )
anon_preserve_resp_addr = cast_intrusive<TableVal>(id->GetVal()); anon_preserve_resp_addr = zeek::cast_intrusive<TableVal>(id->GetVal());
id = global_scope()->Find("preserve_other_addr"); id = global_scope()->Find("preserve_other_addr");
if ( id ) if ( id )
anon_preserve_other_addr = cast_intrusive<TableVal>(id->GetVal()); anon_preserve_other_addr = zeek::cast_intrusive<TableVal>(id->GetVal());
} }
ipaddr32_t zeek::detail::anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl) ipaddr32_t zeek::detail::anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
{ {
TableVal* preserve_addr = nullptr; TableVal* preserve_addr = nullptr;
auto addr = make_intrusive<AddrVal>(ip); auto addr = zeek::make_intrusive<AddrVal>(ip);
int method = -1; int method = -1;
@ -445,8 +445,8 @@ void zeek::detail::log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output
{ {
if ( anonymization_mapping ) if ( anonymization_mapping )
mgr.Enqueue(anonymization_mapping, mgr.Enqueue(anonymization_mapping,
make_intrusive<AddrVal>(input), zeek::make_intrusive<AddrVal>(input),
make_intrusive<AddrVal>(output) zeek::make_intrusive<AddrVal>(output)
); );
} }

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, IntrusivePtr<Expr> e) Attr::Attr(AttrTag t, zeek::IntrusivePtr<Expr> e)
: expr(std::move(e)) : expr(std::move(e))
{ {
tag = t; tag = t;
@ -37,7 +37,7 @@ Attr::Attr(AttrTag t)
{ {
} }
void Attr::SetAttrExpr(IntrusivePtr<zeek::detail::Expr> e) void Attr::SetAttrExpr(zeek::IntrusivePtr<zeek::detail::Expr> 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, IntrusivePtr<Type> t, bool arg_in_record, bool is_global) Attributes::Attributes(attr_list* a, zeek::IntrusivePtr<Type> 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());
@ -150,19 +150,19 @@ Attributes::Attributes(attr_list* a, IntrusivePtr<Type> t, bool arg_in_record, b
// the necessary checking gets done. // the necessary checking gets done.
for ( const auto& attr : *a ) for ( const auto& attr : *a )
AddAttr({NewRef{}, attr}); AddAttr({zeek::NewRef{}, attr});
delete a; delete a;
} }
Attributes::Attributes(IntrusivePtr<Type> t, Attributes::Attributes(zeek::IntrusivePtr<Type> t,
bool arg_in_record, bool is_global) bool arg_in_record, bool is_global)
: Attributes(std::vector<IntrusivePtr<Attr>>{}, 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<IntrusivePtr<Attr>> a, Attributes::Attributes(std::vector<zeek::IntrusivePtr<Attr>> a,
IntrusivePtr<Type> t, zeek::IntrusivePtr<Type> t,
bool arg_in_record, bool is_global) bool arg_in_record, bool is_global)
: type(std::move(t)) : type(std::move(t))
{ {
@ -181,7 +181,7 @@ Attributes::Attributes(std::vector<IntrusivePtr<Attr>> a,
AddAttr(std::move(attr)); AddAttr(std::move(attr));
} }
void Attributes::AddAttr(IntrusivePtr<Attr> attr) void Attributes::AddAttr(zeek::IntrusivePtr<Attr> attr)
{ {
// We overwrite old attributes by deleting them first. // We overwrite old attributes by deleting them first.
RemoveAttr(attr->Tag()); RemoveAttr(attr->Tag());
@ -197,7 +197,7 @@ void Attributes::AddAttr(IntrusivePtr<Attr> attr)
if ( (attr->Tag() == ATTR_ADD_FUNC || attr->Tag() == ATTR_DEL_FUNC) && if ( (attr->Tag() == ATTR_ADD_FUNC || attr->Tag() == ATTR_DEL_FUNC) &&
! Find(ATTR_REDEF) ) ! Find(ATTR_REDEF) )
{ {
auto a = make_intrusive<Attr>(ATTR_REDEF); auto a = zeek::make_intrusive<Attr>(ATTR_REDEF);
attrs_list.push_back(a.get()); attrs_list.push_back(a.get());
attrs.emplace_back(std::move(a)); attrs.emplace_back(std::move(a));
} }
@ -206,13 +206,13 @@ void Attributes::AddAttr(IntrusivePtr<Attr> attr)
if ( ! global_var && attr->Tag() == ATTR_DEFAULT && if ( ! global_var && attr->Tag() == ATTR_DEFAULT &&
! Find(ATTR_OPTIONAL) ) ! Find(ATTR_OPTIONAL) )
{ {
auto a = make_intrusive<Attr>(ATTR_OPTIONAL); auto a = zeek::make_intrusive<Attr>(ATTR_OPTIONAL);
attrs_list.push_back(a.get()); attrs_list.push_back(a.get());
attrs.emplace_back(std::move(a)); attrs.emplace_back(std::move(a));
} }
} }
void Attributes::AddAttrs(const IntrusivePtr<Attributes>& a) void Attributes::AddAttrs(const zeek::IntrusivePtr<Attributes>& a)
{ {
for ( const auto& attr : a->GetAttrs() ) for ( const auto& attr : a->GetAttrs() )
AddAttr(attr); AddAttr(attr);
@ -235,7 +235,7 @@ Attr* Attributes::FindAttr(AttrTag t) const
return nullptr; return nullptr;
} }
const IntrusivePtr<Attr>& Attributes::Find(AttrTag t) const const zeek::IntrusivePtr<Attr>& 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

@ -40,9 +40,9 @@ enum AttrTag {
class Attr final : public BroObj { class Attr final : public BroObj {
public: public:
static inline const IntrusivePtr<zeek::detail::Attr> nil; static inline const zeek::IntrusivePtr<zeek::detail::Attr> nil;
Attr(AttrTag t, IntrusivePtr<zeek::detail::Expr> e); Attr(AttrTag t, zeek::IntrusivePtr<zeek::detail::Expr> e);
explicit Attr(AttrTag t); explicit Attr(AttrTag t);
~Attr() override = default; ~Attr() override = default;
@ -52,10 +52,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 IntrusivePtr<zeek::detail::Expr>& GetExpr() const const zeek::IntrusivePtr<zeek::detail::Expr>& GetExpr() const
{ return expr; } { return expr; }
void SetAttrExpr(IntrusivePtr<zeek::detail::Expr> e); void SetAttrExpr(zeek::IntrusivePtr<zeek::detail::Expr> 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 +78,24 @@ protected:
void AddTag(ODesc* d) const; void AddTag(ODesc* d) const;
AttrTag tag; AttrTag tag;
IntrusivePtr<Expr> expr; zeek::IntrusivePtr<Expr> 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, IntrusivePtr<Type> t, bool in_record, bool is_global); Attributes(attr_list* a, zeek::IntrusivePtr<Type> t, bool in_record, bool is_global);
Attributes(std::vector<IntrusivePtr<Attr>> a, IntrusivePtr<Type> t, Attributes(std::vector<zeek::IntrusivePtr<Attr>> a, zeek::IntrusivePtr<Type> t,
bool in_record, bool is_global); bool in_record, bool is_global);
Attributes(IntrusivePtr<Type> t, bool in_record, bool is_global); Attributes(zeek::IntrusivePtr<Type> t, bool in_record, bool is_global);
~Attributes() override = default; ~Attributes() override = default;
void AddAttr(IntrusivePtr<Attr> a); void AddAttr(zeek::IntrusivePtr<Attr> a);
void AddAttrs(const IntrusivePtr<Attributes>& a); void AddAttrs(const zeek::IntrusivePtr<Attributes>& 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 +103,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 IntrusivePtr<Attr>& Find(AttrTag t) const; const zeek::IntrusivePtr<Attr>& Find(AttrTag t) const;
void RemoveAttr(AttrTag t); void RemoveAttr(AttrTag t);
@ -114,7 +114,7 @@ public:
const attr_list* Attrs() const const attr_list* Attrs() const
{ return &attrs_list; } { return &attrs_list; }
const std::vector<IntrusivePtr<Attr>>& GetAttrs() const const std::vector<zeek::IntrusivePtr<Attr>>& GetAttrs() const
{ return attrs; } { return attrs; }
bool operator==(const Attributes& other) const; bool operator==(const Attributes& other) const;
@ -122,8 +122,8 @@ public:
protected: protected:
void CheckAttr(Attr* attr); void CheckAttr(Attr* attr);
IntrusivePtr<Type> type; zeek::IntrusivePtr<Type> type;
std::vector<IntrusivePtr<Attr>> attrs; std::vector<zeek::IntrusivePtr<Attr>> 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

@ -7,5 +7,5 @@ BifReturnVal::BifReturnVal(std::nullptr_t) noexcept
{} {}
BifReturnVal::BifReturnVal(Val* v) noexcept BifReturnVal::BifReturnVal(Val* v) noexcept
: rval(AdoptRef{}, v) : rval(zeek::AdoptRef{}, v)
{} {}

View file

@ -15,8 +15,8 @@ class BifReturnVal {
public: public:
template <typename T> template <typename T>
BifReturnVal(IntrusivePtr<T> v) noexcept BifReturnVal(zeek::IntrusivePtr<T> v) noexcept
: rval(AdoptRef{}, v.release()) : rval(zeek::AdoptRef{}, v.release())
{ } { }
BifReturnVal(std::nullptr_t) noexcept; BifReturnVal(std::nullptr_t) noexcept;
@ -24,5 +24,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;
IntrusivePtr<Val> rval; zeek::IntrusivePtr<Val> rval;
}; };

View file

@ -340,13 +340,13 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const
VectorVal* BroString:: VecToPolicy(Vec* vec) VectorVal* BroString:: VecToPolicy(Vec* vec)
{ {
auto result = make_intrusive<VectorVal>(zeek::id::string_vec); auto result = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
for ( unsigned int i = 0; i < vec->size(); ++i ) for ( unsigned int i = 0; i < vec->size(); ++i )
{ {
BroString* string = (*vec)[i]; BroString* string = (*vec)[i];
auto val = make_intrusive<StringVal>(string->Len(), auto val = zeek::make_intrusive<StringVal>(string->Len(),
(const char*) string->Bytes()); (const char*) string->Bytes());
result->Assign(i+1, std::move(val)); result->Assign(i+1, std::move(val));
} }

View file

@ -15,7 +15,7 @@
#include "Func.h" #include "Func.h"
#include "IPAddr.h" #include "IPAddr.h"
CompositeHash::CompositeHash(IntrusivePtr<zeek::TypeList> composite_type) CompositeHash::CompositeHash(zeek::IntrusivePtr<zeek::TypeList> composite_type)
: type(std::move(composite_type)) : type(std::move(composite_type))
{ {
singleton_tag = zeek::TYPE_INTERNAL_ERROR; singleton_tag = zeek::TYPE_INTERNAL_ERROR;
@ -209,7 +209,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
auto tbl = tv->AsTable(); auto tbl = tv->AsTable();
auto it = tbl->InitForIteration(); auto it = tbl->InitForIteration();
auto lv = make_intrusive<ListVal>(zeek::TYPE_ANY); auto lv = zeek::make_intrusive<ListVal>(zeek::TYPE_ANY);
struct HashKeyComparer { struct HashKeyComparer {
bool operator()(const HashKey* a, const HashKey* b) const bool operator()(const HashKey* a, const HashKey* b) const
@ -351,7 +351,7 @@ std::unique_ptr<HashKey> CompositeHash::MakeHashKey(const Val& argv, bool type_c
// re-introduce const on the recursive call, it should // re-introduce const on the recursive call, it should
// be okay; the only thing is that the ListVal unref's it. // be okay; the only thing is that the ListVal unref's it.
Val* ncv = (Val*) v; Val* ncv = (Val*) v;
lv.Append({NewRef{}, ncv}); lv.Append({zeek::NewRef{}, ncv});
return MakeHashKey(lv, type_check); return MakeHashKey(lv, type_check);
} }
@ -709,16 +709,16 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const
return offset; return offset;
} }
IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const zeek::IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
{ {
auto l = 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();
const char* kp = (const char*) k.Key(); const char* kp = (const char*) k.Key();
const char* const k_end = kp + k.Size(); const char* const k_end = kp + k.Size();
for ( const auto& type : tl ) for ( const auto& type : tl )
{ {
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> 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));
@ -730,9 +730,10 @@ IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
return l; return l;
} }
const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0, const char* CompositeHash::RecoverOneVal(
const char* const k_end, zeek::Type* t, const HashKey& k, const char* kp0,
IntrusivePtr<Val>* pval, bool optional) const const char* const k_end, zeek::Type* t,
zeek::IntrusivePtr<Val>* 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 )
@ -803,11 +804,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
if ( tag == zeek::TYPE_INTERVAL ) if ( tag == zeek::TYPE_INTERVAL )
*pval = make_intrusive<IntervalVal>(*kp, 1.0); *pval = zeek::make_intrusive<IntervalVal>(*kp, 1.0);
else if ( tag == zeek::TYPE_TIME ) else if ( tag == zeek::TYPE_TIME )
*pval = make_intrusive<TimeVal>(*kp); *pval = zeek::make_intrusive<TimeVal>(*kp);
else else
*pval = make_intrusive<DoubleVal>(*kp); *pval = zeek::make_intrusive<DoubleVal>(*kp);
} }
break; break;
@ -820,7 +821,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
switch ( tag ) { switch ( tag ) {
case zeek::TYPE_ADDR: case zeek::TYPE_ADDR:
*pval = make_intrusive<AddrVal>(addr); *pval = zeek::make_intrusive<AddrVal>(addr);
break; break;
default: default:
@ -835,7 +836,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
{ {
const uint32_t* const kp = AlignType<uint32_t>(kp0); const uint32_t* const kp = AlignType<uint32_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+5); kp1 = reinterpret_cast<const char*>(kp+5);
*pval = make_intrusive<SubNetVal>(kp, kp[4]); *pval = zeek::make_intrusive<SubNetVal>(kp, kp[4]);
} }
break; break;
@ -853,7 +854,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
if ( ! f ) if ( ! f )
reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp); reporter->InternalError("failed to look up unique function id %" PRIu32 " in CompositeHash::RecoverOneVal()", *kp);
*pval = make_intrusive<Val>(f); *pval = zeek::make_intrusive<Val>(f);
const auto& pvt = (*pval)->GetType(); const auto& pvt = (*pval)->GetType();
if ( ! pvt ) if ( ! pvt )
@ -893,7 +894,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
reporter->InternalError("failed compiling table/set key pattern: %s", reporter->InternalError("failed compiling table/set key pattern: %s",
re->PatternText()); re->PatternText());
*pval = make_intrusive<PatternVal>(re); *pval = zeek::make_intrusive<PatternVal>(re);
} }
break; break;
@ -903,11 +904,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
zeek::RecordType* rt = t->AsRecordType(); zeek::RecordType* rt = t->AsRecordType();
int num_fields = rt->NumFields(); int num_fields = rt->NumFields();
std::vector<IntrusivePtr<Val>> values; std::vector<zeek::IntrusivePtr<Val>> values;
int i; int i;
for ( i = 0; i < num_fields; ++i ) for ( i = 0; i < num_fields; ++i )
{ {
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> 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));
@ -930,7 +931,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
ASSERT(int(values.size()) == num_fields); ASSERT(int(values.size()) == num_fields);
auto rv = make_intrusive<RecordVal>(IntrusivePtr{NewRef{}, rt}); auto rv = zeek::make_intrusive<RecordVal>(zeek::IntrusivePtr{zeek::NewRef{}, rt});
for ( int i = 0; i < num_fields; ++i ) for ( int i = 0; i < num_fields; ++i )
rv->Assign(i, std::move(values[i])); rv->Assign(i, std::move(values[i]));
@ -947,18 +948,18 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
n = *kp; n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
zeek::TableType* tt = t->AsTableType(); zeek::TableType* tt = t->AsTableType();
auto tv = make_intrusive<TableVal>(IntrusivePtr{NewRef{}, tt}); auto tv = zeek::make_intrusive<TableVal>(zeek::IntrusivePtr{zeek::NewRef{}, tt});
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
{ {
IntrusivePtr<Val> key; zeek::IntrusivePtr<Val> 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
{ {
IntrusivePtr<Val> value; zeek::IntrusivePtr<Val> 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));
@ -976,7 +977,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
n = *kp; n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
zeek::VectorType* vt = t->AsVectorType(); zeek::VectorType* vt = t->AsVectorType();
auto vv = make_intrusive<VectorVal>(IntrusivePtr{NewRef{}, vt}); auto vv = zeek::make_intrusive<VectorVal>(zeek::IntrusivePtr{zeek::NewRef{}, vt});
for ( unsigned int i = 0; i < n; ++i ) for ( unsigned int i = 0; i < n; ++i )
{ {
@ -986,7 +987,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
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);
IntrusivePtr<Val> value; zeek::IntrusivePtr<Val> 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,
@ -1006,11 +1007,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
n = *kp; n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
zeek::TypeList* tl = t->AsTypeList(); zeek::TypeList* tl = t->AsTypeList();
auto lv = make_intrusive<ListVal>(zeek::TYPE_ANY); auto lv = zeek::make_intrusive<ListVal>(zeek::TYPE_ANY);
for ( int i = 0; i < n; ++i ) for ( int i = 0; i < n; ++i )
{ {
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> 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));
@ -1046,7 +1047,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
kp1 = reinterpret_cast<const char*>(kp+1); kp1 = reinterpret_cast<const char*>(kp+1);
} }
*pval = make_intrusive<StringVal>(new BroString((const byte_vec) kp1, n, true)); *pval = zeek::make_intrusive<StringVal>(new BroString((const byte_vec) kp1, n, true));
kp1 += n; kp1 += n;
} }
break; break;

View file

@ -12,7 +12,7 @@ class HashKey;
class CompositeHash { class CompositeHash {
public: public:
explicit CompositeHash(IntrusivePtr<zeek::TypeList> composite_type); explicit CompositeHash(zeek::IntrusivePtr<zeek::TypeList> composite_type);
~CompositeHash(); ~CompositeHash();
// Compute the hash corresponding to the given index val, // Compute the hash corresponding to the given index val,
@ -24,10 +24,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.
IntrusivePtr<ListVal> RecoverVals(const HashKey& k) const; zeek::IntrusivePtr<ListVal> RecoverVals(const HashKey& k) const;
[[deprecated("Remove in v4.1. Pass in HashKey& instead.")]] [[deprecated("Remove in v4.1. Pass in HashKey& instead.")]]
IntrusivePtr<ListVal> RecoverVals(const HashKey* k) const zeek::IntrusivePtr<ListVal> 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); }
@ -38,15 +38,15 @@ protected:
// Computes the piece of the hash for Val*, returning the new kp. // Computes the piece of the hash for Val*, returning the new kp.
// Used as a helper for ComputeHash in the non-singleton case. // Used as a helper for ComputeHash in the non-singleton case.
char* SingleValHash(bool type_check, char* kp, zeek::Type* bt, Val* v, char* SingleValHash(bool type_check, char* kp, zeek::Type* bt, Val* v,
bool optional) const; bool optional) const;
// Recovers just one Val of possibly many; called from RecoverVals. // Recovers just one Val of possibly many; called from RecoverVals.
// Upon return, pval will point to the recovered Val of type t. // Upon return, pval will point to the recovered Val of type t.
// Returns and updated kp for the next Val. Calls reporter->InternalError() // Returns and updated kp for the next Val. Calls reporter->InternalError()
// 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 HashKey& k, const char* RecoverOneVal(
const char* kp, const char* const k_end, const HashKey& k, const char* kp, const char* const k_end,
zeek::Type* t, IntrusivePtr<Val>* pval, bool optional) const; zeek::Type* t, zeek::IntrusivePtr<Val>* 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 +89,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;
IntrusivePtr<zeek::TypeList> type; zeek::IntrusivePtr<zeek::TypeList> 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,21 +342,21 @@ RecordVal* Connection::BuildConnVal()
return ConnVal()->Ref()->AsRecordVal(); return ConnVal()->Ref()->AsRecordVal();
} }
const IntrusivePtr<RecordVal>& Connection::ConnVal() const zeek::IntrusivePtr<RecordVal>& Connection::ConnVal()
{ {
if ( ! conn_val ) if ( ! conn_val )
{ {
conn_val = make_intrusive<RecordVal>(zeek::id::connection); conn_val = zeek::make_intrusive<RecordVal>(zeek::id::connection);
TransportProto prot_type = ConnTransport(); TransportProto prot_type = ConnTransport();
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id); auto id_val = zeek::make_intrusive<RecordVal>(zeek::id::conn_id);
id_val->Assign(0, make_intrusive<AddrVal>(orig_addr)); id_val->Assign(0, zeek::make_intrusive<AddrVal>(orig_addr));
id_val->Assign(1, val_mgr->Port(ntohs(orig_port), prot_type)); id_val->Assign(1, val_mgr->Port(ntohs(orig_port), prot_type));
id_val->Assign(2, make_intrusive<AddrVal>(resp_addr)); id_val->Assign(2, zeek::make_intrusive<AddrVal>(resp_addr));
id_val->Assign(3, val_mgr->Port(ntohs(resp_port), prot_type)); id_val->Assign(3, val_mgr->Port(ntohs(resp_port), prot_type));
auto orig_endp = make_intrusive<RecordVal>(zeek::id::endpoint); auto orig_endp = zeek::make_intrusive<RecordVal>(zeek::id::endpoint);
orig_endp->Assign(0, val_mgr->Count(0)); orig_endp->Assign(0, val_mgr->Count(0));
orig_endp->Assign(1, val_mgr->Count(0)); orig_endp->Assign(1, val_mgr->Count(0));
orig_endp->Assign(4, val_mgr->Count(orig_flow_label)); orig_endp->Assign(4, val_mgr->Count(orig_flow_label));
@ -365,27 +365,27 @@ const IntrusivePtr<RecordVal>& Connection::ConnVal()
char null[l2_len]{}; char null[l2_len]{};
if ( memcmp(&orig_l2_addr, &null, l2_len) != 0 ) if ( memcmp(&orig_l2_addr, &null, l2_len) != 0 )
orig_endp->Assign(5, make_intrusive<StringVal>(fmt_mac(orig_l2_addr, l2_len))); orig_endp->Assign(5, zeek::make_intrusive<StringVal>(fmt_mac(orig_l2_addr, l2_len)));
auto resp_endp = make_intrusive<RecordVal>(zeek::id::endpoint); auto resp_endp = zeek::make_intrusive<RecordVal>(zeek::id::endpoint);
resp_endp->Assign(0, val_mgr->Count(0)); resp_endp->Assign(0, val_mgr->Count(0));
resp_endp->Assign(1, val_mgr->Count(0)); resp_endp->Assign(1, val_mgr->Count(0));
resp_endp->Assign(4, val_mgr->Count(resp_flow_label)); resp_endp->Assign(4, val_mgr->Count(resp_flow_label));
if ( memcmp(&resp_l2_addr, &null, l2_len) != 0 ) if ( memcmp(&resp_l2_addr, &null, l2_len) != 0 )
resp_endp->Assign(5, make_intrusive<StringVal>(fmt_mac(resp_l2_addr, l2_len))); resp_endp->Assign(5, zeek::make_intrusive<StringVal>(fmt_mac(resp_l2_addr, l2_len)));
conn_val->Assign(0, std::move(id_val)); conn_val->Assign(0, std::move(id_val));
conn_val->Assign(1, std::move(orig_endp)); conn_val->Assign(1, std::move(orig_endp));
conn_val->Assign(2, std::move(resp_endp)); conn_val->Assign(2, std::move(resp_endp));
// 3 and 4 are set below. // 3 and 4 are set below.
conn_val->Assign(5, make_intrusive<TableVal>(zeek::id::string_set)); // service conn_val->Assign(5, zeek::make_intrusive<TableVal>(zeek::id::string_set)); // service
conn_val->Assign(6, val_mgr->EmptyString()); // history conn_val->Assign(6, val_mgr->EmptyString()); // history
if ( ! uid ) if ( ! uid )
uid.Set(bits_per_uid); uid.Set(bits_per_uid);
conn_val->Assign(7, make_intrusive<StringVal>(uid.Base62("C").c_str())); conn_val->Assign(7, zeek::make_intrusive<StringVal>(uid.Base62("C").c_str()));
if ( encapsulation && encapsulation->Depth() > 0 ) if ( encapsulation && encapsulation->Depth() > 0 )
conn_val->Assign(8, encapsulation->ToVal()); conn_val->Assign(8, encapsulation->ToVal());
@ -401,9 +401,9 @@ const IntrusivePtr<RecordVal>& Connection::ConnVal()
if ( root_analyzer ) if ( root_analyzer )
root_analyzer->UpdateConnVal(conn_val.get()); root_analyzer->UpdateConnVal(conn_val.get());
conn_val->Assign(3, make_intrusive<TimeVal>(start_time)); // ### conn_val->Assign(3, zeek::make_intrusive<TimeVal>(start_time)); // ###
conn_val->Assign(4, make_intrusive<IntervalVal>(last_time - start_time)); conn_val->Assign(4, zeek::make_intrusive<IntervalVal>(last_time - start_time));
conn_val->Assign(6, make_intrusive<StringVal>(history.c_str())); conn_val->Assign(6, zeek::make_intrusive<StringVal>(history.c_str()));
conn_val->Assign(11, val_mgr->Bool(is_successful)); conn_val->Assign(11, val_mgr->Bool(is_successful));
conn_val->SetOrigin(this); conn_val->SetOrigin(this);
@ -433,7 +433,7 @@ void Connection::AppendAddl(const char* str)
const char* old = cv->GetField(6)->AsString()->CheckString(); const char* old = cv->GetField(6)->AsString()->CheckString();
const char* format = *old ? "%s %s" : "%s%s"; const char* format = *old ? "%s %s" : "%s%s";
cv->Assign(6, make_intrusive<StringVal>(fmt(format, old, str))); cv->Assign(6, zeek::make_intrusive<StringVal>(fmt(format, old, str)));
} }
// Returns true if the character at s separates a version number. // Returns true if the character at s separates a version number.
@ -470,7 +470,7 @@ void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, const ch
return; return;
if ( name ) if ( name )
EnqueueEvent(f, analyzer, make_intrusive<StringVal>(name), ConnVal()); EnqueueEvent(f, analyzer, zeek::make_intrusive<StringVal>(name), ConnVal());
else else
EnqueueEvent(f, analyzer, ConnVal()); EnqueueEvent(f, analyzer, ConnVal());
} }
@ -487,12 +487,12 @@ void Connection::Event(EventHandlerPtr f, analyzer::Analyzer* analyzer, Val* v1,
if ( v2 ) if ( v2 )
EnqueueEvent(f, analyzer, EnqueueEvent(f, analyzer,
ConnVal(), ConnVal(),
IntrusivePtr{AdoptRef{}, v1}, zeek::IntrusivePtr{zeek::AdoptRef{}, v1},
IntrusivePtr{AdoptRef{}, v2}); zeek::IntrusivePtr{zeek::AdoptRef{}, v2});
else else
EnqueueEvent(f, analyzer, EnqueueEvent(f, analyzer,
ConnVal(), ConnVal(),
IntrusivePtr{AdoptRef{}, v1}); zeek::IntrusivePtr{zeek::AdoptRef{}, v1});
} }
void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list vl) void Connection::ConnectionEvent(EventHandlerPtr f, analyzer::Analyzer* a, val_list vl)

View file

@ -169,7 +169,7 @@ public:
/** /**
* Returns the associated "connection" record. * Returns the associated "connection" record.
*/ */
const IntrusivePtr<RecordVal>& ConnVal(); const zeek::IntrusivePtr<RecordVal>& ConnVal();
void AppendAddl(const char* str); void AppendAddl(const char* str);
@ -235,7 +235,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...>>, IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>>
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 +355,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;
IntrusivePtr<RecordVal> conn_val; zeek::IntrusivePtr<RecordVal> 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();
} }
IntrusivePtr<ListVal> Addrs(); zeek::IntrusivePtr<ListVal> Addrs();
IntrusivePtr<TableVal> AddrsSet(); // addresses returned as a set zeek::IntrusivePtr<TableVal> AddrsSet(); // addresses returned as a set
IntrusivePtr<StringVal> Host(); zeek::IntrusivePtr<StringVal> 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;
IntrusivePtr<StringVal> host_val; zeek::IntrusivePtr<StringVal> host_val;
int num_addrs; int num_addrs;
IPAddr* addrs; IPAddr* addrs;
IntrusivePtr<ListVal> addrs_val; zeek::IntrusivePtr<ListVal> addrs_val;
double creation_time; double creation_time;
int map_type; int map_type;
@ -173,13 +173,13 @@ void DNS_Mgr_mapping_delete_func(void* v)
delete (DNS_Mapping*) v; delete (DNS_Mapping*) v;
} }
static IntrusivePtr<TableVal> empty_addr_set() static zeek::IntrusivePtr<TableVal> empty_addr_set()
{ {
auto addr_t = zeek::base_type(zeek::TYPE_ADDR); auto addr_t = zeek::base_type(zeek::TYPE_ADDR);
auto set_index = make_intrusive<zeek::TypeList>(addr_t); auto set_index = zeek::make_intrusive<zeek::TypeList>(addr_t);
set_index->Append(std::move(addr_t)); set_index->Append(std::move(addr_t));
auto s = make_intrusive<zeek::SetType>(std::move(set_index), nullptr); auto s = zeek::make_intrusive<zeek::SetType>(std::move(set_index), nullptr);
return make_intrusive<TableVal>(std::move(s)); return zeek::make_intrusive<TableVal>(std::move(s));
} }
DNS_Mapping::DNS_Mapping(const char* host, struct hostent* h, uint32_t ttl) DNS_Mapping::DNS_Mapping(const char* host, struct hostent* h, uint32_t ttl)
@ -276,23 +276,23 @@ DNS_Mapping::~DNS_Mapping()
delete [] addrs; delete [] addrs;
} }
IntrusivePtr<ListVal> DNS_Mapping::Addrs() zeek::IntrusivePtr<ListVal> DNS_Mapping::Addrs()
{ {
if ( failed ) if ( failed )
return nullptr; return nullptr;
if ( ! addrs_val ) if ( ! addrs_val )
{ {
addrs_val = make_intrusive<ListVal>(zeek::TYPE_ADDR); addrs_val = zeek::make_intrusive<ListVal>(zeek::TYPE_ADDR);
for ( int i = 0; i < num_addrs; ++i ) for ( int i = 0; i < num_addrs; ++i )
addrs_val->Append(make_intrusive<AddrVal>(addrs[i])); addrs_val->Append(zeek::make_intrusive<AddrVal>(addrs[i]));
} }
return addrs_val; return addrs_val;
} }
IntrusivePtr<TableVal> DNS_Mapping::AddrsSet() { zeek::IntrusivePtr<TableVal> DNS_Mapping::AddrsSet() {
auto l = Addrs(); auto l = Addrs();
if ( ! l ) if ( ! l )
@ -301,13 +301,13 @@ IntrusivePtr<TableVal> DNS_Mapping::AddrsSet() {
return l->ToSetVal(); return l->ToSetVal();
} }
IntrusivePtr<StringVal> DNS_Mapping::Host() zeek::IntrusivePtr<StringVal> DNS_Mapping::Host()
{ {
if ( failed || num_names == 0 || ! names[0] ) if ( failed || num_names == 0 || ! names[0] )
return nullptr; return nullptr;
if ( ! host_val ) if ( ! host_val )
host_val = make_intrusive<StringVal>(names[0]); host_val = zeek::make_intrusive<StringVal>(names[0]);
return host_val; return host_val;
} }
@ -461,12 +461,12 @@ void DNS_Mgr::InitPostScript()
LoadCache(fopen(cache_name, "r")); LoadCache(fopen(cache_name, "r"));
} }
static IntrusivePtr<TableVal> fake_name_lookup_result(const char* name) static zeek::IntrusivePtr<TableVal> 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);
auto hv = make_intrusive<ListVal>(zeek::TYPE_ADDR); auto hv = zeek::make_intrusive<ListVal>(zeek::TYPE_ADDR);
hv->Append(make_intrusive<AddrVal>(reinterpret_cast<const uint32_t*>(&hash))); hv->Append(zeek::make_intrusive<AddrVal>(reinterpret_cast<const uint32_t*>(&hash)));
return hv->ToSetVal(); return hv->ToSetVal();
} }
@ -485,7 +485,7 @@ static const char* fake_addr_lookup_result(const IPAddr& addr)
return tmp; return tmp;
} }
IntrusivePtr<TableVal> DNS_Mgr::LookupHost(const char* name) zeek::IntrusivePtr<TableVal> 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 @@ IntrusivePtr<TableVal> DNS_Mgr::LookupHost(const char* name)
} }
} }
IntrusivePtr<Val> DNS_Mgr::LookupAddr(const IPAddr& addr) zeek::IntrusivePtr<Val> DNS_Mgr::LookupAddr(const IPAddr& addr)
{ {
InitSource(); InitSource();
@ -559,7 +559,7 @@ IntrusivePtr<Val> DNS_Mgr::LookupAddr(const IPAddr& addr)
{ {
string s(addr); string s(addr);
reporter->Warning("can't resolve IP address: %s", s.c_str()); reporter->Warning("can't resolve IP address: %s", s.c_str());
return make_intrusive<StringVal>(s.c_str()); return zeek::make_intrusive<StringVal>(s.c_str());
} }
} }
} }
@ -568,7 +568,7 @@ IntrusivePtr<Val> DNS_Mgr::LookupAddr(const IPAddr& addr)
switch ( mode ) { switch ( mode ) {
case DNS_PRIME: case DNS_PRIME:
requests.push_back(new DNS_Mgr_Request(addr)); requests.push_back(new DNS_Mgr_Request(addr));
return make_intrusive<StringVal>("<none>"); return zeek::make_intrusive<StringVal>("<none>");
case DNS_FORCE: case DNS_FORCE:
reporter->FatalError("can't find DNS entry for %s in cache", reporter->FatalError("can't find DNS entry for %s in cache",
@ -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,
IntrusivePtr<ListVal> l1, IntrusivePtr<ListVal> l2) zeek::IntrusivePtr<ListVal> l1, zeek::IntrusivePtr<ListVal> l2)
{ {
if ( ! e ) if ( ! e )
return; return;
@ -714,17 +714,17 @@ 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));
} }
IntrusivePtr<Val> DNS_Mgr::BuildMappingVal(DNS_Mapping* dm) zeek::IntrusivePtr<Val> DNS_Mgr::BuildMappingVal(DNS_Mapping* dm)
{ {
auto r = make_intrusive<RecordVal>(dm_rec); auto r = zeek::make_intrusive<RecordVal>(dm_rec);
r->Assign(0, make_intrusive<TimeVal>(dm->CreationTime())); r->Assign(0, zeek::make_intrusive<TimeVal>(dm->CreationTime()));
r->Assign(1, make_intrusive<StringVal>(dm->ReqHost() ? dm->ReqHost() : "")); r->Assign(1, zeek::make_intrusive<StringVal>(dm->ReqHost() ? dm->ReqHost() : ""));
r->Assign(2, make_intrusive<AddrVal>(dm->ReqAddr())); r->Assign(2, zeek::make_intrusive<AddrVal>(dm->ReqAddr()));
r->Assign(3, val_mgr->Bool(dm->Valid())); r->Assign(3, val_mgr->Bool(dm->Valid()));
auto h = dm->Host(); auto h = dm->Host();
r->Assign(4, h ? std::move(h) : make_intrusive<StringVal>("<none>")); r->Assign(4, h ? std::move(h) : zeek::make_intrusive<StringVal>("<none>"));
r->Assign(5, dm->AddrsSet()); r->Assign(5, dm->AddrsSet());
return r; return r;
@ -870,9 +870,9 @@ 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));
} }
IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2) zeek::IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2)
{ {
auto delta = make_intrusive<ListVal>(zeek::TYPE_ADDR); auto delta = zeek::make_intrusive<ListVal>(zeek::TYPE_ADDR);
for ( int i = 0; i < al1->Length(); ++i ) for ( int i = 0; i < al1->Length(); ++i )
{ {
@ -980,7 +980,7 @@ const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr)
return d->names ? d->names[0] : "<\?\?\?>"; return d->names ? d->names[0] : "<\?\?\?>";
} }
IntrusivePtr<TableVal> DNS_Mgr::LookupNameInCache(const string& name) zeek::IntrusivePtr<TableVal> 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,
IntrusivePtr<TableVal> result) zeek::IntrusivePtr<TableVal> result)
{ {
callback->Resolved(result.get()); callback->Resolved(result.get());
delete callback; delete callback;

View file

@ -50,9 +50,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.
IntrusivePtr<TableVal> LookupHost(const char* host); zeek::IntrusivePtr<TableVal> LookupHost(const char* host);
IntrusivePtr<Val> LookupAddr(const IPAddr& addr); zeek::IntrusivePtr<Val> 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 +62,7 @@ public:
bool Save(); bool Save();
const char* LookupAddrInCache(const IPAddr& addr); const char* LookupAddrInCache(const IPAddr& addr);
IntrusivePtr<TableVal> LookupNameInCache(const std::string& name); zeek::IntrusivePtr<TableVal> 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 +100,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,
IntrusivePtr<ListVal> l1, IntrusivePtr<ListVal> l2); zeek::IntrusivePtr<ListVal> l1, zeek::IntrusivePtr<ListVal> 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);
IntrusivePtr<Val> BuildMappingVal(DNS_Mapping* dm); zeek::IntrusivePtr<Val> 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);
IntrusivePtr<ListVal> AddrListDelta(ListVal* al1, ListVal* al2); zeek::IntrusivePtr<ListVal> 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 +151,7 @@ protected:
bool did_init; bool did_init;
IntrusivePtr<zeek::RecordType> dm_rec; zeek::IntrusivePtr<zeek::RecordType> dm_rec;
typedef std::list<LookupCallback*> CallbackList; typedef std::list<LookupCallback*> CallbackList;

View file

@ -13,7 +13,6 @@
#include "Scope.h" #include "Scope.h"
#include "Frame.h" #include "Frame.h"
#include "Func.h" #include "Func.h"
#include "IntrusivePtr.h"
#include "Val.h" #include "Val.h"
#include "Stmt.h" #include "Stmt.h"
#include "Timer.h" #include "Timer.h"

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;
IntrusivePtr<Val> dbg_eval_expr(const char* expr) zeek::IntrusivePtr<Val> 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 @@ 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.
IntrusivePtr<Val> result; zeek::IntrusivePtr<Val> result;
if ( yyparse() ) if ( yyparse() )
{ {
if ( g_curr_debug_error ) if ( g_curr_debug_error )

View file

@ -11,7 +11,10 @@
#include <map> #include <map>
#include <string> #include <string>
namespace zeek {
template <class T> class IntrusivePtr; template <class T> class IntrusivePtr;
}
class Val; class Val;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
@ -162,7 +165,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.
IntrusivePtr<Val> dbg_eval_expr(const char* expr); zeek::IntrusivePtr<Val> 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

@ -15,7 +15,6 @@
#include "Desc.h" #include "Desc.h"
#include "DbgBreakpoint.h" #include "DbgBreakpoint.h"
#include "ID.h" #include "ID.h"
#include "IntrusivePtr.h"
#include "Frame.h" #include "Frame.h"
#include "Func.h" #include "Func.h"
#include "Stmt.h" #include "Stmt.h"

View file

@ -93,7 +93,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
zeek::Args args{ zeek::Args args{
ip->ToPktHdrVal(), ip->ToPktHdrVal(),
{AdoptRef{}, BuildData(data, th_len, len, caplen)}, {zeek::AdoptRef{}, BuildData(data, th_len, len, caplen)},
}; };
try try
@ -117,7 +117,7 @@ bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
zeek::Args args{ zeek::Args args{
ip->ToPktHdrVal(), ip->ToPktHdrVal(),
{AdoptRef{}, BuildData(data, uh_len, len, caplen)}, {zeek::AdoptRef{}, BuildData(data, uh_len, len, caplen)},
}; };
try try

View file

@ -22,10 +22,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);
IntrusivePtr<Func> check_ip; zeek::IntrusivePtr<Func> check_ip;
IntrusivePtr<Func> check_tcp; zeek::IntrusivePtr<Func> check_tcp;
IntrusivePtr<Func> check_udp; zeek::IntrusivePtr<Func> check_udp;
IntrusivePtr<Func> check_icmp; zeek::IntrusivePtr<Func> 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...>>, IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>>
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 IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_export) const zeek::IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_export)
{ {
if ( type ) if ( type )
return type; return type;
@ -44,11 +44,11 @@ const IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_export)
return type; return type;
} }
void EventHandler::SetFunc(IntrusivePtr<Func> f) void EventHandler::SetFunc(zeek::IntrusivePtr<Func> f)
{ local = std::move(f); } { local = std::move(f); }
void EventHandler::SetLocalHandler(Func* f) void EventHandler::SetLocalHandler(Func* f)
{ SetFunc({NewRef{}, f}); } { SetFunc({zeek::NewRef{}, f}); }
void EventHandler::Call(zeek::Args* vl, bool no_remote) void EventHandler::Call(zeek::Args* vl, bool no_remote)
{ {
@ -118,7 +118,7 @@ void EventHandler::NewEvent(zeek::Args* vl)
const auto& args = GetType()->Params(); const auto& args = GetType()->Params();
static auto call_argument_vector = zeek::id::find_type<zeek::VectorType>("call_argument_vector"); static auto call_argument_vector = zeek::id::find_type<zeek::VectorType>("call_argument_vector");
auto vargs = make_intrusive<VectorVal>(call_argument_vector); auto vargs = zeek::make_intrusive<VectorVal>(call_argument_vector);
for ( int i = 0; i < args->NumFields(); i++ ) for ( int i = 0; i < args->NumFields(); i++ )
{ {
@ -127,13 +127,13 @@ void EventHandler::NewEvent(zeek::Args* vl)
auto fdefault = args->FieldDefault(i); auto fdefault = args->FieldDefault(i);
static auto call_argument = zeek::id::find_type<zeek::RecordType>("call_argument"); static auto call_argument = zeek::id::find_type<zeek::RecordType>("call_argument");
auto rec = make_intrusive<RecordVal>(call_argument); auto rec = zeek::make_intrusive<RecordVal>(call_argument);
rec->Assign(0, make_intrusive<StringVal>(fname)); rec->Assign(0, zeek::make_intrusive<StringVal>(fname));
ODesc d; ODesc d;
d.SetShort(); d.SetShort();
ftype->Describe(&d); ftype->Describe(&d);
rec->Assign(1, make_intrusive<StringVal>(d.Description())); rec->Assign(1, zeek::make_intrusive<StringVal>(d.Description()));
if ( fdefault ) if ( fdefault )
rec->Assign(2, std::move(fdefault)); rec->Assign(2, std::move(fdefault));
@ -145,7 +145,7 @@ void EventHandler::NewEvent(zeek::Args* vl)
} }
Event* ev = new Event(new_event, { Event* ev = new Event(new_event, {
make_intrusive<StringVal>(name), zeek::make_intrusive<StringVal>(name),
std::move(vargs), std::move(vargs),
}); });
mgr.Dispatch(ev); mgr.Dispatch(ev);

View file

@ -17,19 +17,19 @@ public:
const char* Name() { return name.data(); } const char* Name() { return name.data(); }
const IntrusivePtr<Func>& GetFunc() const zeek::IntrusivePtr<Func>& 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 IntrusivePtr<zeek::FuncType>& GetType(bool check_export = true); const zeek::IntrusivePtr<zeek::FuncType>& 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(IntrusivePtr<Func> f); void SetFunc(zeek::IntrusivePtr<Func> 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 +68,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;
IntrusivePtr<Func> local; zeek::IntrusivePtr<Func> local;
IntrusivePtr<zeek::FuncType> type; zeek::IntrusivePtr<zeek::FuncType> 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

@ -78,12 +78,12 @@ 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 IntrusivePtr<zeek::Type>& GetType() const const zeek::IntrusivePtr<zeek::Type>& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
IntrusivePtr<T> GetType() const zeek::IntrusivePtr<T> GetType() const
{ return cast_intrusive<T>(type); } { return zeek::cast_intrusive<T>(type); }
BroExprTag Tag() const { return tag; } BroExprTag Tag() const { return tag; }
@ -91,7 +91,7 @@ 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 IntrusivePtr<Val> Eval(Frame* f) const = 0; virtual zeek::IntrusivePtr<Val> 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
@ -101,11 +101,11 @@ public:
const; const;
// Assign to the given value, if appropriate. // Assign to the given value, if appropriate.
virtual void Assign(Frame* f, IntrusivePtr<Val> v); virtual void Assign(Frame* f, zeek::IntrusivePtr<Val> 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 IntrusivePtr<zeek::Type> InitType() const; virtual zeek::IntrusivePtr<zeek::Type> 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 +118,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 IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const; virtual zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> 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 +154,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 IntrusivePtr<Expr> MakeLvalue(); virtual zeek::IntrusivePtr<Expr> 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 +223,7 @@ protected:
// Puts the expression in canonical form. // Puts the expression in canonical form.
virtual void Canonicize(); virtual void Canonicize();
void SetType(IntrusivePtr<zeek::Type> t); void SetType(zeek::IntrusivePtr<zeek::Type> 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 +235,19 @@ protected:
[[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const; [[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const;
BroExprTag tag; BroExprTag tag;
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> type;
bool paren; bool paren;
}; };
class NameExpr final : public Expr { class NameExpr final : public Expr {
public: public:
explicit NameExpr(IntrusivePtr<ID> id, bool const_init = false); explicit NameExpr(zeek::IntrusivePtr<ID> id, bool const_init = false);
ID* Id() const { return id.get(); } ID* Id() const { return id.get(); }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
void Assign(Frame* f, IntrusivePtr<Val> v) override; void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override;
IntrusivePtr<Expr> MakeLvalue() override; zeek::IntrusivePtr<Expr> MakeLvalue() override;
bool IsPure() const override; bool IsPure() const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -255,23 +255,23 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<ID> id; zeek::IntrusivePtr<ID> id;
bool in_const_init; bool in_const_init;
}; };
class ConstExpr final : public Expr { class ConstExpr final : public Expr {
public: public:
explicit ConstExpr(IntrusivePtr<Val> val); explicit ConstExpr(zeek::IntrusivePtr<Val> val);
Val* Value() const { return val.get(); } Val* Value() const { return val.get(); }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<Val> val; zeek::IntrusivePtr<Val> val;
}; };
class UnaryExpr : public Expr { class UnaryExpr : public Expr {
@ -281,21 +281,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.
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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, IntrusivePtr<Expr> arg_op); UnaryExpr(BroExprTag arg_tag, zeek::IntrusivePtr<Expr> 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 IntrusivePtr<Val> Fold(Val* v) const; virtual zeek::IntrusivePtr<Val> Fold(Val* v) const;
IntrusivePtr<Expr> op; zeek::IntrusivePtr<Expr> op;
}; };
class BinaryExpr : public Expr { class BinaryExpr : public Expr {
@ -308,13 +308,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.
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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,
IntrusivePtr<Expr> arg_op1, IntrusivePtr<Expr> arg_op2) zeek::IntrusivePtr<Expr> arg_op1, zeek::IntrusivePtr<Expr> 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 +324,20 @@ protected:
} }
// Returns the expression folded using the given constants. // Returns the expression folded using the given constants.
virtual IntrusivePtr<Val> Fold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const;
// Same for when the constants are strings. // Same for when the constants are strings.
virtual IntrusivePtr<Val> StringFold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> StringFold(Val* v1, Val* v2) const;
// Same for when the constants are patterns. // Same for when the constants are patterns.
virtual IntrusivePtr<Val> PatternFold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> PatternFold(Val* v1, Val* v2) const;
// Same for when the constants are sets. // Same for when the constants are sets.
virtual IntrusivePtr<Val> SetFold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> 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 IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const;
virtual IntrusivePtr<Val> SubNetFold(Val* v1, Val* v2) const; virtual zeek::IntrusivePtr<Val> SubNetFold(Val* v1, Val* v2) const;
bool BothConst() const { return op1->IsConst() && op2->IsConst(); } bool BothConst() const { return op1->IsConst() && op2->IsConst(); }
@ -353,148 +353,148 @@ protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<Expr> op1; zeek::IntrusivePtr<Expr> op1;
IntrusivePtr<Expr> op2; zeek::IntrusivePtr<Expr> op2;
}; };
class CloneExpr final : public UnaryExpr { class CloneExpr final : public UnaryExpr {
public: public:
explicit CloneExpr(IntrusivePtr<Expr> op); explicit CloneExpr(zeek::IntrusivePtr<Expr> op);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class IncrExpr final : public UnaryExpr { class IncrExpr final : public UnaryExpr {
public: public:
IncrExpr(BroExprTag tag, IntrusivePtr<Expr> op); IncrExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
IntrusivePtr<Val> DoSingleEval(Frame* f, Val* v) const; zeek::IntrusivePtr<Val> 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(IntrusivePtr<Expr> op); explicit ComplementExpr(zeek::IntrusivePtr<Expr> op);
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class NotExpr final : public UnaryExpr { class NotExpr final : public UnaryExpr {
public: public:
explicit NotExpr(IntrusivePtr<Expr> op); explicit NotExpr(zeek::IntrusivePtr<Expr> op);
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class PosExpr final : public UnaryExpr { class PosExpr final : public UnaryExpr {
public: public:
explicit PosExpr(IntrusivePtr<Expr> op); explicit PosExpr(zeek::IntrusivePtr<Expr> op);
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class NegExpr final : public UnaryExpr { class NegExpr final : public UnaryExpr {
public: public:
explicit NegExpr(IntrusivePtr<Expr> op); explicit NegExpr(zeek::IntrusivePtr<Expr> op);
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class SizeExpr final : public UnaryExpr { class SizeExpr final : public UnaryExpr {
public: public:
explicit SizeExpr(IntrusivePtr<Expr> op); explicit SizeExpr(zeek::IntrusivePtr<Expr> op);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class AddExpr final : public BinaryExpr { class AddExpr final : public BinaryExpr {
public: public:
AddExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); AddExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
void Canonicize() override; void Canonicize() override;
}; };
class AddToExpr final : public BinaryExpr { class AddToExpr final : public BinaryExpr {
public: public:
AddToExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); AddToExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
}; };
class RemoveFromExpr final : public BinaryExpr { class RemoveFromExpr final : public BinaryExpr {
public: public:
RemoveFromExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); RemoveFromExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
}; };
class SubExpr final : public BinaryExpr { class SubExpr final : public BinaryExpr {
public: public:
SubExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); SubExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
}; };
class TimesExpr final : public BinaryExpr { class TimesExpr final : public BinaryExpr {
public: public:
TimesExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); TimesExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
void Canonicize() override; void Canonicize() override;
}; };
class DivideExpr final : public BinaryExpr { class DivideExpr final : public BinaryExpr {
public: public:
DivideExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); DivideExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
protected: protected:
IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const override; zeek::IntrusivePtr<Val> AddrFold(Val* v1, Val* v2) const override;
}; };
class ModExpr final : public BinaryExpr { class ModExpr final : public BinaryExpr {
public: public:
ModExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); ModExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
}; };
class BoolExpr final : public BinaryExpr { class BoolExpr final : public BinaryExpr {
public: public:
BoolExpr(BroExprTag tag, IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); BoolExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
IntrusivePtr<Val> DoSingleEval(Frame* f, IntrusivePtr<Val> v1, Expr* op2) const; zeek::IntrusivePtr<Val> DoSingleEval(Frame* f, zeek::IntrusivePtr<Val> v1, Expr* op2) const;
}; };
class BitExpr final : public BinaryExpr { class BitExpr final : public BinaryExpr {
public: public:
BitExpr(BroExprTag tag, IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); BitExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
}; };
class EqExpr final : public BinaryExpr { class EqExpr final : public BinaryExpr {
public: public:
EqExpr(BroExprTag tag, IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); EqExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
void Canonicize() override; void Canonicize() override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override;
}; };
class RelExpr final : public BinaryExpr { class RelExpr final : public BinaryExpr {
public: public:
RelExpr(BroExprTag tag, IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); RelExpr(BroExprTag tag, zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
void Canonicize() override; void Canonicize() override;
}; };
class CondExpr final : public Expr { class CondExpr final : public Expr {
public: public:
CondExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2, IntrusivePtr<Expr> op3); CondExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2, zeek::IntrusivePtr<Expr> 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(); }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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 +502,53 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<Expr> op1; zeek::IntrusivePtr<Expr> op1;
IntrusivePtr<Expr> op2; zeek::IntrusivePtr<Expr> op2;
IntrusivePtr<Expr> op3; zeek::IntrusivePtr<Expr> op3;
}; };
class RefExpr final : public UnaryExpr { class RefExpr final : public UnaryExpr {
public: public:
explicit RefExpr(IntrusivePtr<Expr> op); explicit RefExpr(zeek::IntrusivePtr<Expr> op);
void Assign(Frame* f, IntrusivePtr<Val> v) override; void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override;
IntrusivePtr<Expr> MakeLvalue() override; zeek::IntrusivePtr<Expr> 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(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2, bool is_init, AssignExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2, bool is_init,
IntrusivePtr<Val> val = nullptr, zeek::IntrusivePtr<Val> val = nullptr,
const IntrusivePtr<Attributes>& attrs = nullptr); const zeek::IntrusivePtr<Attributes>& attrs = nullptr);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<zeek::Type> InitType() const override; zeek::IntrusivePtr<zeek::Type> InitType() const override;
bool IsRecordElement(TypeDecl* td) const override; bool IsRecordElement(TypeDecl* td) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
bool IsPure() const override; bool IsPure() const override;
protected: protected:
bool TypeCheck(const IntrusivePtr<Attributes>& attrs = nullptr); bool TypeCheck(const zeek::IntrusivePtr<Attributes>& attrs = nullptr);
bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2);
bool is_init; bool is_init;
IntrusivePtr<Val> val; // optional zeek::IntrusivePtr<Val> val; // optional
}; };
class IndexSliceAssignExpr final : public AssignExpr { class IndexSliceAssignExpr final : public AssignExpr {
public: public:
IndexSliceAssignExpr(IntrusivePtr<Expr> op1, IndexSliceAssignExpr(zeek::IntrusivePtr<Expr> op1,
IntrusivePtr<Expr> op2, bool is_init); zeek::IntrusivePtr<Expr> op2, bool is_init);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
}; };
class IndexExpr final : public BinaryExpr { class IndexExpr final : public BinaryExpr {
public: public:
IndexExpr(IntrusivePtr<Expr> op1, IndexExpr(zeek::IntrusivePtr<Expr> op1,
IntrusivePtr<ListExpr> op2, bool is_slice = false); zeek::IntrusivePtr<ListExpr> op2, bool is_slice = false);
bool CanAdd() const override; bool CanAdd() const override;
bool CanDel() const override; bool CanDel() const override;
@ -556,19 +556,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, IntrusivePtr<Val> v) override; void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override;
IntrusivePtr<Expr> MakeLvalue() override; zeek::IntrusivePtr<Expr> 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.
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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:
IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -577,7 +577,7 @@ protected:
class FieldExpr final : public UnaryExpr { class FieldExpr final : public UnaryExpr {
public: public:
FieldExpr(IntrusivePtr<Expr> op, const char* field_name); FieldExpr(zeek::IntrusivePtr<Expr> op, const char* field_name);
~FieldExpr() override; ~FieldExpr() override;
int Field() const { return field; } int Field() const { return field; }
@ -585,13 +585,13 @@ public:
bool CanDel() const override; bool CanDel() const override;
void Assign(Frame* f, IntrusivePtr<Val> v) override; void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override;
void Delete(Frame* f) override; void Delete(Frame* f) override;
IntrusivePtr<Expr> MakeLvalue() override; zeek::IntrusivePtr<Expr> MakeLvalue() override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -604,13 +604,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(IntrusivePtr<Expr> op, const char* field_name); HasFieldExpr(zeek::IntrusivePtr<Expr> 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:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -620,76 +620,76 @@ protected:
class RecordConstructorExpr final : public UnaryExpr { class RecordConstructorExpr final : public UnaryExpr {
public: public:
explicit RecordConstructorExpr(IntrusivePtr<ListExpr> constructor_list); explicit RecordConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list);
~RecordConstructorExpr() override; ~RecordConstructorExpr() override;
protected: protected:
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> 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(IntrusivePtr<ListExpr> constructor_list, TableConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs, std::unique_ptr<std::vector<zeek::IntrusivePtr<Attr>>> attrs,
IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::IntrusivePtr<zeek::Type> 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 IntrusivePtr<Attributes>& GetAttrs() const const zeek::IntrusivePtr<Attributes>& GetAttrs() const
{ return attrs; } { return attrs; }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
protected: protected:
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<Attributes> attrs; zeek::IntrusivePtr<Attributes> attrs;
}; };
class SetConstructorExpr final : public UnaryExpr { class SetConstructorExpr final : public UnaryExpr {
public: public:
SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list, SetConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs, std::unique_ptr<std::vector<zeek::IntrusivePtr<Attr>>> attrs,
IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::IntrusivePtr<zeek::Type> 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 IntrusivePtr<Attributes>& GetAttrs() const const zeek::IntrusivePtr<Attributes>& GetAttrs() const
{ return attrs; } { return attrs; }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
protected: protected:
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<Attributes> attrs; zeek::IntrusivePtr<Attributes> attrs;
}; };
class VectorConstructorExpr final : public UnaryExpr { class VectorConstructorExpr final : public UnaryExpr {
public: public:
explicit VectorConstructorExpr(IntrusivePtr<ListExpr> constructor_list, explicit VectorConstructorExpr(zeek::IntrusivePtr<ListExpr> constructor_list,
IntrusivePtr<zeek::Type> arg_type = nullptr); zeek::IntrusivePtr<zeek::Type> arg_type = nullptr);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
protected: protected:
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> 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, IntrusivePtr<Expr> value); FieldAssignExpr(const char* field_name, zeek::IntrusivePtr<Expr> value);
const char* FieldName() const { return field_name.c_str(); } const char* FieldName() const { return field_name.c_str(); }
@ -704,21 +704,21 @@ protected:
class ArithCoerceExpr final : public UnaryExpr { class ArithCoerceExpr final : public UnaryExpr {
public: public:
ArithCoerceExpr(IntrusivePtr<Expr> op, zeek::TypeTag t); ArithCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::TypeTag t);
protected: protected:
IntrusivePtr<Val> FoldSingleVal(Val* v, InternalTypeTag t) const; zeek::IntrusivePtr<Val> FoldSingleVal(Val* v, InternalTypeTag t) const;
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class RecordCoerceExpr final : public UnaryExpr { class RecordCoerceExpr final : public UnaryExpr {
public: public:
RecordCoerceExpr(IntrusivePtr<Expr> op, IntrusivePtr<RecordType> r); RecordCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<RecordType> r);
~RecordCoerceExpr() override; ~RecordCoerceExpr() override;
protected: protected:
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> 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 +728,20 @@ protected:
class TableCoerceExpr final : public UnaryExpr { class TableCoerceExpr final : public UnaryExpr {
public: public:
TableCoerceExpr(IntrusivePtr<Expr> op, IntrusivePtr<TableType> r); TableCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<TableType> r);
~TableCoerceExpr() override; ~TableCoerceExpr() override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class VectorCoerceExpr final : public UnaryExpr { class VectorCoerceExpr final : public UnaryExpr {
public: public:
VectorCoerceExpr(IntrusivePtr<Expr> op, IntrusivePtr<VectorType> v); VectorCoerceExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<VectorType> v);
~VectorCoerceExpr() override; ~VectorCoerceExpr() override;
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
}; };
class ScheduleTimer final : public Timer { class ScheduleTimer final : public Timer {
@ -758,11 +758,11 @@ protected:
class ScheduleExpr final : public Expr { class ScheduleExpr final : public Expr {
public: public:
ScheduleExpr(IntrusivePtr<Expr> when, IntrusivePtr<EventExpr> event); ScheduleExpr(zeek::IntrusivePtr<Expr> when, zeek::IntrusivePtr<EventExpr> event);
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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 +772,22 @@ public:
protected: protected:
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
IntrusivePtr<Expr> when; zeek::IntrusivePtr<Expr> when;
IntrusivePtr<EventExpr> event; zeek::IntrusivePtr<EventExpr> event;
}; };
class InExpr final : public BinaryExpr { class InExpr final : public BinaryExpr {
public: public:
InExpr(IntrusivePtr<Expr> op1, IntrusivePtr<Expr> op2); InExpr(zeek::IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> op2);
protected: protected:
IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override; zeek::IntrusivePtr<Val> Fold(Val* v1, Val* v2) const override;
}; };
class CallExpr final : public Expr { class CallExpr final : public Expr {
public: public:
CallExpr(IntrusivePtr<Expr> func, IntrusivePtr<ListExpr> args, CallExpr(zeek::IntrusivePtr<Expr> func, zeek::IntrusivePtr<ListExpr> args,
bool in_hook = false); bool in_hook = false);
Expr* Func() const { return func.get(); } Expr* Func() const { return func.get(); }
@ -795,15 +795,15 @@ public:
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<Expr> func; zeek::IntrusivePtr<Expr> func;
IntrusivePtr<ListExpr> args; zeek::IntrusivePtr<ListExpr> args;
}; };
@ -817,7 +817,7 @@ public:
LambdaExpr(std::unique_ptr<function_ingredients> ingredients, LambdaExpr(std::unique_ptr<function_ingredients> ingredients,
id_list outer_ids); id_list outer_ids);
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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 +834,13 @@ private:
class EventExpr final : public Expr { class EventExpr final : public Expr {
public: public:
EventExpr(const char* name, IntrusivePtr<ListExpr> args); EventExpr(const char* name, zeek::IntrusivePtr<ListExpr> 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; }
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
@ -849,16 +849,16 @@ protected:
std::string name; std::string name;
EventHandlerPtr handler; EventHandlerPtr handler;
IntrusivePtr<ListExpr> args; zeek::IntrusivePtr<ListExpr> args;
}; };
class ListExpr : public Expr { class ListExpr : public Expr {
public: public:
ListExpr(); ListExpr();
explicit ListExpr(IntrusivePtr<Expr> e); explicit ListExpr(zeek::IntrusivePtr<Expr> e);
~ListExpr() override; ~ListExpr() override;
void Append(IntrusivePtr<Expr> e); void Append(zeek::IntrusivePtr<Expr> 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 +866,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;
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> Eval(Frame* f) const override;
IntrusivePtr<zeek::Type> InitType() const override; zeek::IntrusivePtr<zeek::Type> InitType() const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override; zeek::IntrusivePtr<Val> InitVal(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Expr> MakeLvalue() override; zeek::IntrusivePtr<Expr> MakeLvalue() override;
void Assign(Frame* f, IntrusivePtr<Val> v) override; void Assign(Frame* f, zeek::IntrusivePtr<Val> v) override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Val> AddSetInit(const zeek::Type* t, IntrusivePtr<Val> aggr) const; zeek::IntrusivePtr<Val> AddSetInit(const zeek::Type* t, zeek::IntrusivePtr<Val> aggr) const;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
@ -886,28 +886,28 @@ protected:
class RecordAssignExpr final : public ListExpr { class RecordAssignExpr final : public ListExpr {
public: public:
RecordAssignExpr(const IntrusivePtr<Expr>& record, const IntrusivePtr<Expr>& init_list, bool is_init); RecordAssignExpr(const zeek::IntrusivePtr<Expr>& record, const zeek::IntrusivePtr<Expr>& init_list, bool is_init);
}; };
class CastExpr final : public UnaryExpr { class CastExpr final : public UnaryExpr {
public: public:
CastExpr(IntrusivePtr<Expr> op, IntrusivePtr<zeek::Type> t); CastExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<zeek::Type> t);
protected: protected:
IntrusivePtr<Val> Eval(Frame* f) const override; zeek::IntrusivePtr<Val> 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(IntrusivePtr<Expr> op, IntrusivePtr<zeek::Type> t); IsExpr(zeek::IntrusivePtr<Expr> op, zeek::IntrusivePtr<zeek::Type> t);
protected: protected:
IntrusivePtr<Val> Fold(Val* v) const override; zeek::IntrusivePtr<Val> Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override; void ExprDescribe(ODesc* d) const override;
private: private:
IntrusivePtr<zeek::Type> t; zeek::IntrusivePtr<zeek::Type> t;
}; };
inline Val* Expr::ExprVal() const inline Val* Expr::ExprVal() const
@ -918,8 +918,9 @@ inline Val* Expr::ExprVal() const
} }
// Decides whether to return an AssignExpr or a RecordAssignExpr. // Decides whether to return an AssignExpr or a RecordAssignExpr.
IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1, zeek::IntrusivePtr<Expr> get_assign_expr(
IntrusivePtr<Expr> op2, bool is_init); zeek::IntrusivePtr<Expr> op1,
zeek::IntrusivePtr<Expr> 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
@ -936,7 +937,7 @@ IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1,
* Returns nullptr if the expression cannot match or a promoted * Returns nullptr if the expression cannot match or a promoted
* expression. * expression.
*/ */
extern IntrusivePtr<Expr> check_and_promote_expr(Expr* e, Type* t); extern zeek::IntrusivePtr<Expr> 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);
@ -944,7 +945,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<IntrusivePtr<Val>>> eval_list(Frame* f, const ListExpr* l); std::optional<std::vector<zeek::IntrusivePtr<Val>>> 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
@ -953,7 +954,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 IntrusivePtr<Expr>& e) { return is_vector(e.get()); } inline bool is_vector(const zeek::IntrusivePtr<Expr>& e) { return is_vector(e.get()); }
} }

View file

@ -328,8 +328,8 @@ void BroFile::RaiseOpenEvent()
if ( ! ::file_opened ) if ( ! ::file_opened )
return; return;
IntrusivePtr<BroFile> bf{NewRef{}, this}; zeek::IntrusivePtr<BroFile> bf{zeek::NewRef{}, this};
Event* event = new ::Event(::file_opened, {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,11 +346,11 @@ double BroFile::Size()
return s.st_size; return s.st_size;
} }
IntrusivePtr<BroFile> BroFile::Get(const char* name) zeek::IntrusivePtr<BroFile> 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 )
return {NewRef{}, el.second}; return {zeek::NewRef{}, el.second};
return make_intrusive<BroFile>(name, "w"); return zeek::make_intrusive<BroFile>(name, "w");
} }

View file

@ -45,7 +45,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 IntrusivePtr<zeek::Type>& GetType() const const zeek::IntrusivePtr<zeek::Type>& 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 +72,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 IntrusivePtr<BroFile> Get(const char* name); static zeek::IntrusivePtr<BroFile> 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 +106,7 @@ protected:
void RaiseOpenEvent(); void RaiseOpenEvent();
FILE* f; FILE* f;
IntrusivePtr<zeek::Type> t; zeek::IntrusivePtr<zeek::Type> t;
char* name; char* name;
char* access; char* access;
zeek::detail::Attributes* attrs; zeek::detail::Attributes* attrs;

View file

@ -63,9 +63,9 @@ void Frame::AddFunctionWithClosureRef(BroFunc* func)
} }
void Frame::SetElement(int n, Val* v) void Frame::SetElement(int n, Val* v)
{ SetElement(n, {AdoptRef{}, v}); } { SetElement(n, {zeek::AdoptRef{}, v}); }
void Frame::SetElement(int n, IntrusivePtr<Val> v) void Frame::SetElement(int n, zeek::IntrusivePtr<Val> v)
{ {
ClearElement(n); ClearElement(n);
frame[n] = {std::move(v), false}; frame[n] = {std::move(v), false};
@ -74,10 +74,10 @@ void Frame::SetElement(int n, IntrusivePtr<Val> v)
void Frame::SetElementWeak(int n, Val* v) void Frame::SetElementWeak(int n, Val* v)
{ {
ClearElement(n); ClearElement(n);
frame[n] = {{AdoptRef{}, v}, true}; frame[n] = {{zeek::AdoptRef{}, v}, true};
} }
void Frame::SetElement(const zeek::detail::ID* id, IntrusivePtr<Val> v) void Frame::SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr<Val> v)
{ {
if ( closure ) if ( closure )
{ {
@ -106,7 +106,7 @@ void Frame::SetElement(const zeek::detail::ID* id, IntrusivePtr<Val> v)
SetElement(id->Offset(), std::move(v)); SetElement(id->Offset(), std::move(v));
} }
const IntrusivePtr<Val>& Frame::GetElementByID(const zeek::detail::ID* id) const const zeek::IntrusivePtr<Val>& Frame::GetElementByID(const zeek::detail::ID* id) const
{ {
if ( closure ) if ( closure )
{ {
@ -173,7 +173,7 @@ Frame* Frame::Clone() const
return other; return other;
} }
static bool val_is_func(const IntrusivePtr<Val>& v, BroFunc* func) static bool val_is_func(const zeek::IntrusivePtr<Val>& v, BroFunc* func)
{ {
if ( v->GetType()->Tag() != zeek::TYPE_FUNC ) if ( v->GetType()->Tag() != zeek::TYPE_FUNC )
return false; return false;
@ -348,14 +348,14 @@ broker::expected<broker::data> Frame::Serialize(const Frame* target, const id_li
return {std::move(rval)}; return {std::move(rval)};
} }
std::pair<bool, IntrusivePtr<Frame>> Frame::Unserialize(const broker::vector& data) std::pair<bool, zeek::IntrusivePtr<Frame>> 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;
IntrusivePtr<Frame> closure; zeek::IntrusivePtr<Frame> closure;
auto where = data.begin(); auto where = data.begin();
@ -437,7 +437,7 @@ std::pair<bool, IntrusivePtr<Frame>> Frame::Unserialize(const broker::vector& da
int frame_size = body.size(); int frame_size = body.size();
// We'll associate this frame with a function later. // We'll associate this frame with a function later.
auto rf = make_intrusive<Frame>(frame_size, nullptr, nullptr); auto rf = zeek::make_intrusive<Frame>(frame_size, nullptr, nullptr);
rf->offset_map = std::make_unique<OffsetMap>(std::move(offset_map)); rf->offset_map = std::make_unique<OffsetMap>(std::move(offset_map));
// Frame takes ownership of unref'ing elements in outer_ids // Frame takes ownership of unref'ing elements in outer_ids
@ -505,7 +505,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(IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger) void Frame::SetTrigger(zeek::IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger)
{ {
trigger = std::move(arg_trigger); trigger = std::move(arg_trigger);
} }

View file

@ -43,7 +43,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 IntrusivePtr<Val>& GetElement(int n) const const zeek::IntrusivePtr<Val>& 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 +54,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, IntrusivePtr<Val> v); void SetElement(int n, zeek::IntrusivePtr<Val> 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 +66,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, IntrusivePtr<Val> v); void SetElement(const zeek::detail::ID* id, zeek::IntrusivePtr<Val> v);
void SetElement(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<Val> v) void SetElement(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<Val> v)
{ SetElement(id.get(), std::move(v)); } { SetElement(id.get(), std::move(v)); }
/** /**
@ -77,7 +77,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 IntrusivePtr<Val>& GetElementByID(const IntrusivePtr<zeek::detail::ID>& id) const const zeek::IntrusivePtr<Val>& GetElementByID(const zeek::IntrusivePtr<zeek::detail::ID>& 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 +195,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, IntrusivePtr<Frame>> Unserialize(const broker::vector& data); static std::pair<bool, zeek::IntrusivePtr<Frame>> 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 +216,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(IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger); void SetTrigger(zeek::IntrusivePtr<zeek::detail::trigger::Trigger> 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 +241,13 @@ private:
using OffsetMap = std::unordered_map<std::string, int>; using OffsetMap = std::unordered_map<std::string, int>;
struct Element { struct Element {
IntrusivePtr<Val> val; zeek::IntrusivePtr<Val> 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 IntrusivePtr<Val>& GetElementByID(const zeek::detail::ID* id) const; const zeek::IntrusivePtr<Val>& 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 +322,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;
IntrusivePtr<zeek::detail::trigger::Trigger> trigger; zeek::IntrusivePtr<zeek::detail::trigger::Trigger> 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

@ -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"
@ -59,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, IntrusivePtr<Val>> empty_hook_result(false, nullptr); static const std::pair<bool, zeek::IntrusivePtr<Val>> empty_hook_result(false, nullptr);
std::string render_call_stack() std::string render_call_stack()
{ {
@ -110,34 +111,34 @@ std::string render_call_stack()
Func::Func() Func::Func()
{ {
unique_id = unique_ids.size(); unique_id = unique_ids.size();
unique_ids.push_back({NewRef{}, this}); unique_ids.push_back({zeek::NewRef{}, this});
} }
Func::Func(Kind arg_kind) : kind(arg_kind) Func::Func(Kind arg_kind) : kind(arg_kind)
{ {
unique_id = unique_ids.size(); unique_id = unique_ids.size();
unique_ids.push_back({NewRef{}, this}); unique_ids.push_back({zeek::NewRef{}, this});
} }
Func::~Func() = default; Func::~Func() = default;
void Func::AddBody(IntrusivePtr<zeek::detail::Stmt> /* new_body */, void Func::AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> /* new_body */,
const std::vector<IntrusivePtr<zeek::detail::ID>>& /* new_inits */, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& /* 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(IntrusivePtr<Scope> newscope) void Func::SetScope(zeek::IntrusivePtr<Scope> newscope)
{ {
scope = std::move(newscope); scope = std::move(newscope);
} }
IntrusivePtr<Func> Func::DoClone() zeek::IntrusivePtr<Func> 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.
return {NewRef{}, this}; return {zeek::NewRef{}, this};
} }
void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const void Func::DescribeDebug(ODesc* d, const zeek::Args* args) const
@ -215,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 IntrusivePtr<Val>& hook_result, void Func::CheckPluginResult(bool handled, const zeek::IntrusivePtr<Val>& 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
@ -268,8 +269,8 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr<Val>& hook_result,
} }
} }
BroFunc::BroFunc(const IntrusivePtr<zeek::detail::ID>& arg_id, IntrusivePtr<zeek::detail::Stmt> arg_body, BroFunc::BroFunc(const zeek::IntrusivePtr<zeek::detail::ID>& arg_id, zeek::IntrusivePtr<zeek::detail::Stmt> arg_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& aggr_inits, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& aggr_inits,
size_t arg_frame_size, int priority) size_t arg_frame_size, int priority)
: Func(BRO_FUNC) : Func(BRO_FUNC)
{ {
@ -304,7 +305,7 @@ Val* Func::Call(val_list* args, Frame* parent) const
return Invoke(&zargs, parent).release(); return Invoke(&zargs, parent).release();
}; };
IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const zeek::IntrusivePtr<Val> 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());
@ -330,7 +331,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
return Flavor() == zeek::FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr; return Flavor() == zeek::FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr;
} }
auto f = make_intrusive<Frame>(frame_size, this, args); auto f = zeek::make_intrusive<Frame>(frame_size, this, args);
if ( closure ) if ( closure )
f->CaptureClosure(closure, outer_ids); f->CaptureClosure(closure, outer_ids);
@ -338,7 +339,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
// Hand down any trigger. // Hand down any trigger.
if ( parent ) if ( parent )
{ {
f->SetTrigger({NewRef{}, parent->GetTrigger()}); f->SetTrigger({zeek::NewRef{}, parent->GetTrigger()});
f->SetCall(parent->GetCall()); f->SetCall(parent->GetCall());
} }
@ -356,7 +357,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
} }
stmt_flow_type flow = FLOW_NEXT; stmt_flow_type flow = FLOW_NEXT;
IntrusivePtr<Val> result; zeek::IntrusivePtr<Val> result;
for ( const auto& body : bodies ) for ( const auto& body : bodies )
{ {
@ -449,8 +450,8 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
return result; return result;
} }
void BroFunc::AddBody(IntrusivePtr<zeek::detail::Stmt> new_body, void BroFunc::AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& 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 )
@ -540,11 +541,11 @@ bool BroFunc::UpdateClosure(const broker::vector& data)
} }
IntrusivePtr<Func> BroFunc::DoClone() zeek::IntrusivePtr<Func> 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.
auto other = IntrusivePtr{AdoptRef{}, new BroFunc()}; auto other = zeek::IntrusivePtr{zeek::AdoptRef{}, new BroFunc()};
CopyStateInto(other.get()); CopyStateInto(other.get());
@ -574,13 +575,14 @@ void BroFunc::Describe(ODesc* d) const
} }
} }
IntrusivePtr<zeek::detail::Stmt> BroFunc::AddInits(IntrusivePtr<zeek::detail::Stmt> body, zeek::IntrusivePtr<zeek::detail::Stmt> BroFunc::AddInits(
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits) zeek::IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& inits)
{ {
if ( inits.empty() ) if ( inits.empty() )
return body; return body;
auto stmt_series = make_intrusive<zeek::detail::StmtList>(); auto stmt_series = zeek::make_intrusive<zeek::detail::StmtList>();
stmt_series->Stmts().push_back(new zeek::detail::InitStmt(inits)); stmt_series->Stmts().push_back(new zeek::detail::InitStmt(inits));
stmt_series->Stmts().push_back(body.release()); stmt_series->Stmts().push_back(body.release());
@ -588,7 +590,7 @@ IntrusivePtr<zeek::detail::Stmt> BroFunc::AddInits(IntrusivePtr<zeek::detail::St
} }
BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
bool arg_is_pure) bool arg_is_pure)
: Func(BUILTIN_FUNC) : Func(BUILTIN_FUNC)
{ {
func = arg_func; func = arg_func;
@ -602,7 +604,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
reporter->InternalError("built-in function %s multiply defined", Name()); reporter->InternalError("built-in function %s multiply defined", Name());
type = id->GetType<zeek::FuncType>(); type = id->GetType<zeek::FuncType>();
id->SetVal(make_intrusive<Val>(IntrusivePtr{NewRef{}, this})); id->SetVal(zeek::make_intrusive<Val>(zeek::IntrusivePtr{zeek::NewRef{}, this}));
} }
BuiltinFunc::~BuiltinFunc() BuiltinFunc::~BuiltinFunc()
@ -614,7 +616,7 @@ bool BuiltinFunc::IsPure() const
return is_pure; return is_pure;
} }
IntrusivePtr<Val> BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const zeek::IntrusivePtr<Val> 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());
@ -665,10 +667,10 @@ void BuiltinFunc::Describe(ODesc* d) const
void builtin_error(const char* msg) void builtin_error(const char* msg)
{ {
builtin_error(msg, IntrusivePtr<Val>{}); builtin_error(msg, zeek::IntrusivePtr<Val>{});
} }
void builtin_error(const char* msg, IntrusivePtr<Val> arg) void builtin_error(const char* msg, zeek::IntrusivePtr<Val> arg)
{ {
builtin_error(msg, arg.get()); builtin_error(msg, arg.get());
} }
@ -844,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<IntrusivePtr<zeek::detail::Attr>>& attrs) static int get_func_priority(const std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>& attrs)
{ {
int priority = 0; int priority = 0;
@ -879,7 +881,7 @@ static int get_func_priority(const std::vector<IntrusivePtr<zeek::detail::Attr>>
return priority; return priority;
} }
function_ingredients::function_ingredients(IntrusivePtr<Scope> scope, IntrusivePtr<zeek::detail::Stmt> body) function_ingredients::function_ingredients(zeek::IntrusivePtr<Scope> scope, zeek::IntrusivePtr<zeek::detail::Stmt> body)
{ {
frame_size = scope->Length(); frame_size = scope->Length();
inits = scope->GetInits(); inits = scope->GetInits();

View file

@ -38,7 +38,7 @@ using caf::expected;
class Func : public BroObj { class Func : public BroObj {
public: public:
static inline const IntrusivePtr<Func> nil; static inline const zeek::IntrusivePtr<Func> nil;
enum Kind { BRO_FUNC, BUILTIN_FUNC }; enum Kind { BRO_FUNC, BUILTIN_FUNC };
@ -50,7 +50,7 @@ public:
zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); } zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); }
struct Body { struct Body {
IntrusivePtr<zeek::detail::Stmt> stmts; zeek::IntrusivePtr<zeek::detail::Stmt> 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,8 +68,8 @@ 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 IntrusivePtr<Val> Invoke(zeek::Args* args, virtual zeek::IntrusivePtr<Val> Invoke(
Frame* parent = nullptr) const = 0; zeek::Args* args, Frame* parent = nullptr) const = 0;
/** /**
* A version of Invoke() taking a variable number of individual arguments. * A version of Invoke() taking a variable number of individual arguments.
@ -77,8 +77,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...>>,
IntrusivePtr<Val>>, zeek::IntrusivePtr<Val>>,
IntrusivePtr<Val>> zeek::IntrusivePtr<Val>>
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 +86,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(IntrusivePtr<zeek::detail::Stmt> new_body, virtual void AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& new_inits,
size_t new_frame_size, int priority = 0); size_t new_frame_size, int priority = 0);
virtual void SetScope(IntrusivePtr<Scope> newscope); virtual void SetScope(zeek::IntrusivePtr<Scope> 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 IntrusivePtr<zeek::FuncType>& GetType() const const zeek::IntrusivePtr<zeek::FuncType>& GetType() const
{ return type; } { return type; }
Kind GetKind() const { return kind; } Kind GetKind() const { return kind; }
@ -107,12 +107,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 IntrusivePtr<Func> DoClone(); virtual zeek::IntrusivePtr<Func> 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 IntrusivePtr<Func>& GetFuncPtrByID(uint32_t id) static const zeek::IntrusivePtr<Func>& 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 +122,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 IntrusivePtr<Val>& hook_result, void CheckPluginResult(bool handled, const zeek::IntrusivePtr<Val>& hook_result,
zeek::FunctionFlavor flavor) const; zeek::FunctionFlavor flavor) const;
std::vector<Body> bodies; std::vector<Body> bodies;
IntrusivePtr<Scope> scope; zeek::IntrusivePtr<Scope> scope;
Kind kind; Kind kind;
uint32_t unique_id; uint32_t unique_id;
IntrusivePtr<zeek::FuncType> type; zeek::IntrusivePtr<zeek::FuncType> type;
std::string name; std::string name;
static inline std::vector<IntrusivePtr<Func>> unique_ids; static inline std::vector<zeek::IntrusivePtr<Func>> unique_ids;
}; };
class BroFunc final : public Func { class BroFunc final : public Func {
public: public:
BroFunc(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::detail::Stmt> body, BroFunc(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& 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;
IntrusivePtr<Val> Invoke(zeek::Args* args, Frame* parent) const override; zeek::IntrusivePtr<Val> 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 +175,8 @@ public:
*/ */
broker::expected<broker::data> SerializeClosure() const; broker::expected<broker::data> SerializeClosure() const;
void AddBody(IntrusivePtr<zeek::detail::Stmt> new_body, void AddBody(zeek::IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits, const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& 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 +187,14 @@ public:
protected: protected:
BroFunc() : Func(BRO_FUNC) {} BroFunc() : Func(BRO_FUNC) {}
IntrusivePtr<zeek::detail::Stmt> AddInits( zeek::IntrusivePtr<zeek::detail::Stmt> AddInits(
IntrusivePtr<zeek::detail::Stmt> body, zeek::IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits); const std::vector<zeek::IntrusivePtr<zeek::detail::ID>>& inits);
/** /**
* Clones this function along with its closures. * Clones this function along with its closures.
*/ */
IntrusivePtr<Func> DoClone() override; zeek::IntrusivePtr<Func> 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 +222,7 @@ public:
~BuiltinFunc() override; ~BuiltinFunc() override;
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Invoke(zeek::Args* args, Frame* parent) const override; zeek::IntrusivePtr<Val> 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 +236,7 @@ protected:
extern void builtin_error(const char* msg); extern void builtin_error(const char* msg);
extern void builtin_error(const char* msg, IntrusivePtr<Val>); extern void builtin_error(const char* msg, zeek::IntrusivePtr<Val>);
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 +255,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(IntrusivePtr<Scope> scope, IntrusivePtr<zeek::detail::Stmt> body); function_ingredients(zeek::IntrusivePtr<Scope> scope, zeek::IntrusivePtr<zeek::detail::Stmt> body);
IntrusivePtr<zeek::detail::ID> id; zeek::IntrusivePtr<zeek::detail::ID> id;
IntrusivePtr<zeek::detail::Stmt> body; zeek::IntrusivePtr<zeek::detail::Stmt> body;
std::vector<IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::IntrusivePtr<zeek::detail::ID>> inits;
int frame_size; int frame_size;
int priority; int priority;
IntrusivePtr<Scope> scope; zeek::IntrusivePtr<Scope> scope;
}; };
extern std::vector<CallInfo> call_stack; extern std::vector<CallInfo> call_stack;

View file

@ -19,24 +19,24 @@
#include "zeekygen/ScriptInfo.h" #include "zeekygen/ScriptInfo.h"
#include "module_util.h" #include "module_util.h"
IntrusivePtr<zeek::RecordType> zeek::id::conn_id; zeek::IntrusivePtr<zeek::RecordType> zeek::id::conn_id;
IntrusivePtr<zeek::RecordType> zeek::id::endpoint; zeek::IntrusivePtr<zeek::RecordType> zeek::id::endpoint;
IntrusivePtr<zeek::RecordType> zeek::id::connection; zeek::IntrusivePtr<zeek::RecordType> zeek::id::connection;
IntrusivePtr<zeek::RecordType> zeek::id::fa_file; zeek::IntrusivePtr<zeek::RecordType> zeek::id::fa_file;
IntrusivePtr<zeek::RecordType> zeek::id::fa_metadata; zeek::IntrusivePtr<zeek::RecordType> zeek::id::fa_metadata;
IntrusivePtr<zeek::EnumType> zeek::id::transport_proto; zeek::IntrusivePtr<zeek::EnumType> zeek::id::transport_proto;
IntrusivePtr<zeek::TableType> zeek::id::string_set; zeek::IntrusivePtr<zeek::TableType> zeek::id::string_set;
IntrusivePtr<zeek::TableType> zeek::id::string_array; zeek::IntrusivePtr<zeek::TableType> zeek::id::string_array;
IntrusivePtr<zeek::TableType> zeek::id::count_set; zeek::IntrusivePtr<zeek::TableType> zeek::id::count_set;
IntrusivePtr<zeek::VectorType> zeek::id::string_vec; zeek::IntrusivePtr<zeek::VectorType> zeek::id::string_vec;
IntrusivePtr<zeek::VectorType> zeek::id::index_vec; zeek::IntrusivePtr<zeek::VectorType> zeek::id::index_vec;
const IntrusivePtr<zeek::detail::ID>& zeek::id::find(std::string_view name) const zeek::IntrusivePtr<zeek::detail::ID>& zeek::id::find(std::string_view name)
{ {
return global_scope()->Find(name); return global_scope()->Find(name);
} }
const IntrusivePtr<zeek::Type>& zeek::id::find_type(std::string_view name) const zeek::IntrusivePtr<zeek::Type>& zeek::id::find_type(std::string_view name)
{ {
auto id = global_scope()->Find(name); auto id = global_scope()->Find(name);
@ -47,7 +47,7 @@ const IntrusivePtr<zeek::Type>& zeek::id::find_type(std::string_view name)
return id->GetType(); return id->GetType();
} }
const IntrusivePtr<Val>& zeek::id::find_val(std::string_view name) const zeek::IntrusivePtr<Val>& zeek::id::find_val(std::string_view name)
{ {
auto id = global_scope()->Find(name); auto id = global_scope()->Find(name);
@ -58,7 +58,7 @@ const IntrusivePtr<Val>& zeek::id::find_val(std::string_view name)
return id->GetVal(); return id->GetVal();
} }
const IntrusivePtr<Val>& zeek::id::find_const(std::string_view name) const zeek::IntrusivePtr<Val>& zeek::id::find_const(std::string_view name)
{ {
auto id = global_scope()->Find(name); auto id = global_scope()->Find(name);
@ -73,7 +73,7 @@ const IntrusivePtr<Val>& zeek::id::find_const(std::string_view name)
return id->GetVal(); return id->GetVal();
} }
IntrusivePtr<Func> zeek::id::find_func(std::string_view name) zeek::IntrusivePtr<Func> 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 +130,7 @@ std::string ID::ModuleName() const
return extract_module_name(name); return extract_module_name(name);
} }
void ID::SetType(IntrusivePtr<zeek::Type> t) void ID::SetType(zeek::IntrusivePtr<zeek::Type> t)
{ {
type = std::move(t); type = std::move(t);
} }
@ -140,7 +140,7 @@ void ID::ClearVal()
val = nullptr; val = nullptr;
} }
void ID::SetVal(IntrusivePtr<Val> v) void ID::SetVal(zeek::IntrusivePtr<Val> v)
{ {
val = std::move(v); val = std::move(v);
Modified(); Modified();
@ -169,7 +169,7 @@ void ID::SetVal(IntrusivePtr<Val> v)
} }
} }
void ID::SetVal(IntrusivePtr<Val> v, InitClass c) void ID::SetVal(zeek::IntrusivePtr<Val> v, InitClass c)
{ {
if ( c == INIT_NONE || c == INIT_FULL ) if ( c == INIT_NONE || c == INIT_FULL )
{ {
@ -207,7 +207,7 @@ void ID::SetVal(IntrusivePtr<Val> v, InitClass c)
} }
} }
void ID::SetVal(IntrusivePtr<Expr> ev, InitClass c) void ID::SetVal(zeek::IntrusivePtr<Expr> 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 +222,7 @@ bool ID::IsRedefinable() const
return GetAttr(ATTR_REDEF) != nullptr; return GetAttr(ATTR_REDEF) != nullptr;
} }
void ID::SetAttrs(IntrusivePtr<Attributes> a) void ID::SetAttrs(zeek::IntrusivePtr<Attributes> a)
{ {
attrs = nullptr; attrs = nullptr;
AddAttrs(std::move(a)); AddAttrs(std::move(a));
@ -260,15 +260,15 @@ void ID::UpdateValAttrs()
TypeDecl* fd = rt->FieldDecl(i); TypeDecl* fd = rt->FieldDecl(i);
if ( ! fd->attrs ) if ( ! fd->attrs )
fd->attrs = make_intrusive<Attributes>(rt->GetFieldType(i), true, IsGlobal()); fd->attrs = zeek::make_intrusive<Attributes>(rt->GetFieldType(i), true, IsGlobal());
fd->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG)); fd->attrs->AddAttr(zeek::make_intrusive<Attr>(ATTR_LOG));
} }
} }
} }
} }
const IntrusivePtr<Attr>& ID::GetAttr(AttrTag t) const const zeek::IntrusivePtr<Attr>& ID::GetAttr(AttrTag t) const
{ {
return attrs ? attrs->Find(t) : Attr::nil; return attrs ? attrs->Find(t) : Attr::nil;
} }
@ -278,13 +278,13 @@ bool ID::IsDeprecated() const
return GetAttr(ATTR_DEPRECATED) != nullptr; return GetAttr(ATTR_DEPRECATED) != nullptr;
} }
void ID::MakeDeprecated(IntrusivePtr<Expr> deprecation) void ID::MakeDeprecated(zeek::IntrusivePtr<Expr> deprecation)
{ {
if ( IsDeprecated() ) if ( IsDeprecated() )
return; return;
std::vector<IntrusivePtr<Attr>> attrv{make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))}; std::vector<zeek::IntrusivePtr<Attr>> attrv{zeek::make_intrusive<Attr>(ATTR_DEPRECATED, std::move(deprecation))};
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal())); AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
} }
std::string ID::GetDeprecationWarning() const std::string ID::GetDeprecationWarning() const
@ -308,7 +308,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(IntrusivePtr<Attributes> a) void ID::AddAttrs(zeek::IntrusivePtr<Attributes> a)
{ {
if ( attrs ) if ( attrs )
attrs->AddAttrs(a); attrs->AddAttrs(a);
@ -334,18 +334,18 @@ void ID::SetOption()
// option implied redefinable // option implied redefinable
if ( ! IsRedefinable() ) if ( ! IsRedefinable() )
{ {
std::vector<IntrusivePtr<Attr>> attrv{make_intrusive<Attr>(ATTR_REDEF)}; std::vector<zeek::IntrusivePtr<Attr>> attrv{zeek::make_intrusive<Attr>(ATTR_REDEF)};
AddAttrs(make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal())); AddAttrs(zeek::make_intrusive<Attributes>(std::move(attrv), GetType(), false, IsGlobal()));
} }
} }
void ID::EvalFunc(IntrusivePtr<Expr> ef, IntrusivePtr<Expr> ev) void ID::EvalFunc(zeek::IntrusivePtr<Expr> ef, zeek::IntrusivePtr<Expr> ev)
{ {
auto arg1 = make_intrusive<zeek::detail::ConstExpr>(val); auto arg1 = zeek::make_intrusive<zeek::detail::ConstExpr>(val);
auto args = make_intrusive<zeek::detail::ListExpr>(); auto args = zeek::make_intrusive<zeek::detail::ListExpr>();
args->Append(std::move(arg1)); args->Append(std::move(arg1));
args->Append(std::move(ev)); args->Append(std::move(ev));
auto ce = make_intrusive<CallExpr>(std::move(ef), std::move(args)); auto ce = zeek::make_intrusive<CallExpr>(std::move(ef), std::move(args));
SetVal(ce->Eval(nullptr)); SetVal(ce->Eval(nullptr));
} }
@ -642,7 +642,7 @@ void ID::UpdateValID()
} }
#endif #endif
void ID::AddOptionHandler(IntrusivePtr<Func> callback, int priority) void ID::AddOptionHandler(zeek::IntrusivePtr<Func> callback, int priority)
{ {
option_handlers.emplace(priority, std::move(callback)); option_handlers.emplace(priority, std::move(callback));
} }

View file

@ -34,7 +34,7 @@ enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
class ID final : public BroObj, public notifier::Modifiable { class ID final : public BroObj, public notifier::Modifiable {
public: public:
static inline const IntrusivePtr<ID> nil; static inline const zeek::IntrusivePtr<ID> nil;
ID(const char* name, IDScope arg_scope, bool arg_is_export); ID(const char* name, IDScope arg_scope, bool arg_is_export);
@ -50,19 +50,19 @@ public:
std::string ModuleName() const; std::string ModuleName() const;
void SetType(IntrusivePtr<Type> t); void SetType(zeek::IntrusivePtr<Type> 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 IntrusivePtr<zeek::Type>& GetType() const const zeek::IntrusivePtr<zeek::Type>& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
IntrusivePtr<T> GetType() const zeek::IntrusivePtr<T> GetType() const
{ return cast_intrusive<T>(type); } { return zeek::cast_intrusive<T>(type); }
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]] [[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
zeek::Type* AsType() { return is_type ? GetType().get() : nullptr; } zeek::Type* AsType() { return is_type ? GetType().get() : nullptr; }
@ -74,10 +74,10 @@ public:
void MakeType() { is_type = true; } void MakeType() { is_type = true; }
void SetVal(IntrusivePtr<Val> v); void SetVal(zeek::IntrusivePtr<Val> v);
void SetVal(IntrusivePtr<Val> v, InitClass c); void SetVal(zeek::IntrusivePtr<Val> v, InitClass c);
void SetVal(IntrusivePtr<Expr> ev, InitClass c); void SetVal(zeek::IntrusivePtr<Expr> ev, InitClass c);
bool HasVal() const { return val != nullptr; } bool HasVal() const { return val != nullptr; }
@ -86,7 +86,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 IntrusivePtr<Val>& GetVal() const const zeek::IntrusivePtr<Val>& GetVal() const
{ return val; } { return val; }
void ClearVal(); void ClearVal();
@ -105,22 +105,22 @@ public:
bool IsRedefinable() const; bool IsRedefinable() const;
void SetAttrs(IntrusivePtr<Attributes> attr); void SetAttrs(zeek::IntrusivePtr<Attributes> attr);
void AddAttrs(IntrusivePtr<Attributes> attr); void AddAttrs(zeek::IntrusivePtr<Attributes> attr);
void RemoveAttr(zeek::detail::AttrTag a); void RemoveAttr(zeek::detail::AttrTag a);
void UpdateValAttrs(); void UpdateValAttrs();
const IntrusivePtr<Attributes>& GetAttrs() const const zeek::IntrusivePtr<Attributes>& 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 IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const; const zeek::IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const;
bool IsDeprecated() const; bool IsDeprecated() const;
void MakeDeprecated(IntrusivePtr<Expr> deprecation); void MakeDeprecated(zeek::IntrusivePtr<Expr> deprecation);
std::string GetDeprecationWarning() const; std::string GetDeprecationWarning() const;
@ -143,11 +143,11 @@ public:
bool HasOptionHandlers() const bool HasOptionHandlers() const
{ return !option_handlers.empty(); } { return !option_handlers.empty(); }
void AddOptionHandler(IntrusivePtr<Func> callback, int priority); void AddOptionHandler(zeek::IntrusivePtr<Func> callback, int priority);
std::vector<Func*> GetOptionHandlers() const; std::vector<Func*> GetOptionHandlers() const;
protected: protected:
void EvalFunc(IntrusivePtr<Expr> ef, IntrusivePtr<Expr> ev); void EvalFunc(zeek::IntrusivePtr<Expr> ef, zeek::IntrusivePtr<Expr> ev);
#ifdef DEBUG #ifdef DEBUG
void UpdateValID(); void UpdateValID();
@ -157,13 +157,13 @@ protected:
IDScope scope; IDScope scope;
bool is_export; bool is_export;
bool infer_return_type; bool infer_return_type;
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> 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;
IntrusivePtr<Val> val; zeek::IntrusivePtr<Val> val;
IntrusivePtr<Attributes> attrs; zeek::IntrusivePtr<Attributes> 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, IntrusivePtr<Func>> option_handlers; std::multimap<int, zeek::IntrusivePtr<Func>> option_handlers;
}; };
@ -179,7 +179,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 IntrusivePtr<zeek::detail::ID>& find(std::string_view name); const zeek::IntrusivePtr<zeek::detail::ID>& 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 +187,7 @@ const 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 IntrusivePtr<zeek::Type>& find_type(std::string_view name); const zeek::IntrusivePtr<zeek::Type>& 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).
@ -196,8 +196,8 @@ const IntrusivePtr<zeek::Type>& find_type(std::string_view name);
* @return The type of the identifier. * @return The type of the identifier.
*/ */
template<class T> template<class T>
IntrusivePtr<T> find_type(std::string_view name) zeek::IntrusivePtr<T> find_type(std::string_view name)
{ return cast_intrusive<T>(find_type(name)); } { return zeek::cast_intrusive<T>(find_type(name)); }
/** /**
* Lookup an ID by its name and return its value. A fatal occurs if the ID * Lookup an ID by its name and return its value. A fatal occurs if the ID
@ -205,7 +205,7 @@ 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 IntrusivePtr<Val>& find_val(std::string_view name); const zeek::IntrusivePtr<Val>& 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).
@ -214,8 +214,8 @@ const IntrusivePtr<Val>& find_val(std::string_view name);
* @return The current value of the identifier. * @return The current value of the identifier.
*/ */
template<class T> template<class T>
IntrusivePtr<T> find_val(std::string_view name) zeek::IntrusivePtr<T> find_val(std::string_view name)
{ return cast_intrusive<T>(find_val(name)); } { return zeek::cast_intrusive<T>(find_val(name)); }
/** /**
* Lookup an ID by its name and return its value. A fatal occurs if the ID * Lookup an ID by its name and return its value. A fatal occurs if the ID
@ -223,7 +223,7 @@ 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 IntrusivePtr<Val>& find_const(std::string_view name); const zeek::IntrusivePtr<Val>& 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).
@ -232,8 +232,8 @@ const IntrusivePtr<Val>& find_const(std::string_view name);
* @return The current value of the identifier. * @return The current value of the identifier.
*/ */
template<class T> template<class T>
IntrusivePtr<T> find_const(std::string_view name) zeek::IntrusivePtr<T> find_const(std::string_view name)
{ return cast_intrusive<T>(find_const(name)); } { return zeek::cast_intrusive<T>(find_const(name)); }
/** /**
* Lookup an ID by its name and return the function it references. * Lookup an ID by its name and return the function it references.
@ -241,19 +241,19 @@ 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.
*/ */
IntrusivePtr<Func> find_func(std::string_view name); zeek::IntrusivePtr<Func> find_func(std::string_view name);
extern IntrusivePtr<zeek::RecordType> conn_id; extern zeek::IntrusivePtr<zeek::RecordType> conn_id;
extern IntrusivePtr<zeek::RecordType> endpoint; extern zeek::IntrusivePtr<zeek::RecordType> endpoint;
extern IntrusivePtr<zeek::RecordType> connection; extern zeek::IntrusivePtr<zeek::RecordType> connection;
extern IntrusivePtr<zeek::RecordType> fa_file; extern zeek::IntrusivePtr<zeek::RecordType> fa_file;
extern IntrusivePtr<zeek::RecordType> fa_metadata; extern zeek::IntrusivePtr<zeek::RecordType> fa_metadata;
extern IntrusivePtr<zeek::EnumType> transport_proto; extern zeek::IntrusivePtr<zeek::EnumType> transport_proto;
extern IntrusivePtr<zeek::TableType> string_set; extern zeek::IntrusivePtr<zeek::TableType> string_set;
extern IntrusivePtr<zeek::TableType> string_array; extern zeek::IntrusivePtr<zeek::TableType> string_array;
extern IntrusivePtr<zeek::TableType> count_set; extern zeek::IntrusivePtr<zeek::TableType> count_set;
extern IntrusivePtr<zeek::VectorType> string_vec; extern zeek::IntrusivePtr<zeek::VectorType> string_vec;
extern IntrusivePtr<zeek::VectorType> index_vec; extern zeek::IntrusivePtr<zeek::VectorType> index_vec;
namespace detail { namespace detail {

View file

@ -13,15 +13,15 @@
#include "BroString.h" #include "BroString.h"
#include "Reporter.h" #include "Reporter.h"
static IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len) static zeek::IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len)
{ {
auto vv = 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"));
while ( len > 0 ) while ( len > 0 )
{ {
static auto ip6_option_type = zeek::id::find_type<zeek::RecordType>("ip6_option"); static auto ip6_option_type = zeek::id::find_type<zeek::RecordType>("ip6_option");
const struct ip6_opt* opt = (const struct ip6_opt*) data; const struct ip6_opt* opt = (const struct ip6_opt*) data;
auto rv = make_intrusive<RecordVal>(ip6_option_type); auto rv = zeek::make_intrusive<RecordVal>(ip6_option_type);
rv->Assign(0, val_mgr->Count(opt->ip6o_type)); rv->Assign(0, val_mgr->Count(opt->ip6o_type));
if ( opt->ip6o_type == 0 ) if ( opt->ip6o_type == 0 )
@ -37,7 +37,7 @@ static IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len)
// PadN or other option // PadN or other option
uint16_t off = 2 * sizeof(uint8_t); uint16_t off = 2 * sizeof(uint8_t);
rv->Assign(1, val_mgr->Count(opt->ip6o_len)); rv->Assign(1, val_mgr->Count(opt->ip6o_len));
rv->Assign(2, make_intrusive<StringVal>( rv->Assign(2, zeek::make_intrusive<StringVal>(
new BroString(data + off, opt->ip6o_len, true))); new BroString(data + off, opt->ip6o_len, true)));
data += opt->ip6o_len + off; data += opt->ip6o_len + off;
len -= opt->ip6o_len + off; len -= opt->ip6o_len + off;
@ -49,25 +49,25 @@ static IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len)
return vv; return vv;
} }
IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const zeek::IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(zeek::IntrusivePtr<VectorVal> chain) const
{ {
IntrusivePtr<RecordVal> rv; zeek::IntrusivePtr<RecordVal> rv;
switch ( type ) { switch ( type ) {
case IPPROTO_IPV6: case IPPROTO_IPV6:
{ {
static auto ip6_hdr_type = zeek::id::find_type<zeek::RecordType>("ip6_hdr"); static auto ip6_hdr_type = zeek::id::find_type<zeek::RecordType>("ip6_hdr");
rv = make_intrusive<RecordVal>(ip6_hdr_type); rv = zeek::make_intrusive<RecordVal>(ip6_hdr_type);
const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data; const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data;
rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20)); rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20));
rv->Assign(1, val_mgr->Count(ntohl(ip6->ip6_flow) & 0x000fffff)); rv->Assign(1, val_mgr->Count(ntohl(ip6->ip6_flow) & 0x000fffff));
rv->Assign(2, val_mgr->Count(ntohs(ip6->ip6_plen))); rv->Assign(2, val_mgr->Count(ntohs(ip6->ip6_plen)));
rv->Assign(3, val_mgr->Count(ip6->ip6_nxt)); rv->Assign(3, val_mgr->Count(ip6->ip6_nxt));
rv->Assign(4, val_mgr->Count(ip6->ip6_hlim)); rv->Assign(4, val_mgr->Count(ip6->ip6_hlim));
rv->Assign(5, make_intrusive<AddrVal>(IPAddr(ip6->ip6_src))); rv->Assign(5, zeek::make_intrusive<AddrVal>(IPAddr(ip6->ip6_src)));
rv->Assign(6, make_intrusive<AddrVal>(IPAddr(ip6->ip6_dst))); rv->Assign(6, zeek::make_intrusive<AddrVal>(IPAddr(ip6->ip6_dst)));
if ( ! chain ) if ( ! chain )
chain = make_intrusive<VectorVal>( chain = zeek::make_intrusive<VectorVal>(
zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain")); zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain"));
rv->Assign(7, std::move(chain)); rv->Assign(7, std::move(chain));
} }
@ -76,7 +76,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_HOPOPTS: case IPPROTO_HOPOPTS:
{ {
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");
rv = make_intrusive<RecordVal>(ip6_hopopts_type); rv = zeek::make_intrusive<RecordVal>(ip6_hopopts_type);
const struct ip6_hbh* hbh = (const struct ip6_hbh*)data; const struct ip6_hbh* hbh = (const struct ip6_hbh*)data;
rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt)); rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt));
rv->Assign(1, val_mgr->Count(hbh->ip6h_len)); rv->Assign(1, val_mgr->Count(hbh->ip6h_len));
@ -89,7 +89,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_DSTOPTS: case IPPROTO_DSTOPTS:
{ {
static auto ip6_dstopts_type = zeek::id::find_type<zeek::RecordType>("ip6_dstopts"); static auto ip6_dstopts_type = zeek::id::find_type<zeek::RecordType>("ip6_dstopts");
rv = make_intrusive<RecordVal>(ip6_dstopts_type); rv = zeek::make_intrusive<RecordVal>(ip6_dstopts_type);
const struct ip6_dest* dst = (const struct ip6_dest*)data; const struct ip6_dest* dst = (const struct ip6_dest*)data;
rv->Assign(0, val_mgr->Count(dst->ip6d_nxt)); rv->Assign(0, val_mgr->Count(dst->ip6d_nxt));
rv->Assign(1, val_mgr->Count(dst->ip6d_len)); rv->Assign(1, val_mgr->Count(dst->ip6d_len));
@ -101,21 +101,21 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ROUTING: case IPPROTO_ROUTING:
{ {
static auto ip6_routing_type = zeek::id::find_type<zeek::RecordType>("ip6_routing"); static auto ip6_routing_type = zeek::id::find_type<zeek::RecordType>("ip6_routing");
rv = make_intrusive<RecordVal>(ip6_routing_type); rv = zeek::make_intrusive<RecordVal>(ip6_routing_type);
const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data; const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data;
rv->Assign(0, val_mgr->Count(rt->ip6r_nxt)); rv->Assign(0, val_mgr->Count(rt->ip6r_nxt));
rv->Assign(1, val_mgr->Count(rt->ip6r_len)); rv->Assign(1, val_mgr->Count(rt->ip6r_len));
rv->Assign(2, val_mgr->Count(rt->ip6r_type)); rv->Assign(2, val_mgr->Count(rt->ip6r_type));
rv->Assign(3, val_mgr->Count(rt->ip6r_segleft)); rv->Assign(3, val_mgr->Count(rt->ip6r_segleft));
uint16_t off = 4 * sizeof(uint8_t); uint16_t off = 4 * sizeof(uint8_t);
rv->Assign(4, make_intrusive<StringVal>(new BroString(data + off, Length() - off, true))); rv->Assign(4, zeek::make_intrusive<StringVal>(new BroString(data + off, Length() - off, true)));
} }
break; break;
case IPPROTO_FRAGMENT: case IPPROTO_FRAGMENT:
{ {
static auto ip6_fragment_type = zeek::id::find_type<zeek::RecordType>("ip6_fragment"); static auto ip6_fragment_type = zeek::id::find_type<zeek::RecordType>("ip6_fragment");
rv = make_intrusive<RecordVal>(ip6_fragment_type); rv = zeek::make_intrusive<RecordVal>(ip6_fragment_type);
const struct ip6_frag* frag = (const struct ip6_frag*)data; const struct ip6_frag* frag = (const struct ip6_frag*)data;
rv->Assign(0, val_mgr->Count(frag->ip6f_nxt)); rv->Assign(0, val_mgr->Count(frag->ip6f_nxt));
rv->Assign(1, val_mgr->Count(frag->ip6f_reserved)); rv->Assign(1, val_mgr->Count(frag->ip6f_reserved));
@ -129,7 +129,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_AH: case IPPROTO_AH:
{ {
static auto ip6_ah_type = zeek::id::find_type<zeek::RecordType>("ip6_ah"); static auto ip6_ah_type = zeek::id::find_type<zeek::RecordType>("ip6_ah");
rv = make_intrusive<RecordVal>(ip6_ah_type); rv = zeek::make_intrusive<RecordVal>(ip6_ah_type);
rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt)); rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt));
rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len)); rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len));
rv->Assign(2, val_mgr->Count(ntohs(((uint16_t*)data)[1]))); rv->Assign(2, val_mgr->Count(ntohs(((uint16_t*)data)[1])));
@ -141,7 +141,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
// Payload Len was non-zero for this header. // Payload Len was non-zero for this header.
rv->Assign(4, val_mgr->Count(ntohl(((uint32_t*)data)[2]))); rv->Assign(4, val_mgr->Count(ntohl(((uint32_t*)data)[2])));
uint16_t off = 3 * sizeof(uint32_t); uint16_t off = 3 * sizeof(uint32_t);
rv->Assign(5, make_intrusive<StringVal>(new BroString(data + off, Length() - off, true))); rv->Assign(5, zeek::make_intrusive<StringVal>(new BroString(data + off, Length() - off, true)));
} }
} }
break; break;
@ -149,7 +149,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ESP: case IPPROTO_ESP:
{ {
static auto ip6_esp_type = zeek::id::find_type<zeek::RecordType>("ip6_esp"); static auto ip6_esp_type = zeek::id::find_type<zeek::RecordType>("ip6_esp");
rv = make_intrusive<RecordVal>(ip6_esp_type); rv = zeek::make_intrusive<RecordVal>(ip6_esp_type);
const uint32_t* esp = (const uint32_t*)data; const uint32_t* esp = (const uint32_t*)data;
rv->Assign(0, val_mgr->Count(ntohl(esp[0]))); rv->Assign(0, val_mgr->Count(ntohl(esp[0])));
rv->Assign(1, val_mgr->Count(ntohl(esp[1]))); rv->Assign(1, val_mgr->Count(ntohl(esp[1])));
@ -160,7 +160,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_MOBILITY: case IPPROTO_MOBILITY:
{ {
static auto ip6_mob_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_hdr"); static auto ip6_mob_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_hdr");
rv = make_intrusive<RecordVal>(ip6_mob_type); rv = zeek::make_intrusive<RecordVal>(ip6_mob_type);
const struct ip6_mobility* mob = (const struct ip6_mobility*) data; const struct ip6_mobility* mob = (const struct ip6_mobility*) data;
rv->Assign(0, val_mgr->Count(mob->ip6mob_payload)); rv->Assign(0, val_mgr->Count(mob->ip6mob_payload));
rv->Assign(1, val_mgr->Count(mob->ip6mob_len)); rv->Assign(1, val_mgr->Count(mob->ip6mob_len));
@ -169,7 +169,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum))); rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum)));
static auto ip6_mob_msg_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_msg"); static auto ip6_mob_msg_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_msg");
auto msg = make_intrusive<RecordVal>(ip6_mob_msg_type); auto msg = zeek::make_intrusive<RecordVal>(ip6_mob_msg_type);
msg->Assign(0, val_mgr->Count(mob->ip6mob_type)); msg->Assign(0, val_mgr->Count(mob->ip6mob_type));
uint16_t off = sizeof(ip6_mobility); uint16_t off = sizeof(ip6_mobility);
@ -187,7 +187,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
switch ( mob->ip6mob_type ) { switch ( mob->ip6mob_type ) {
case 0: case 0:
{ {
auto m = make_intrusive<RecordVal>(ip6_mob_brr_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mob_brr_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
off += sizeof(uint16_t); off += sizeof(uint16_t);
m->Assign(1, BuildOptionsVal(data + off, Length() - off)); m->Assign(1, BuildOptionsVal(data + off, Length() - off));
@ -197,7 +197,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 1: case 1:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_hoti_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_hoti_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))));
off += sizeof(uint16_t) + sizeof(uint64_t); off += sizeof(uint16_t) + sizeof(uint64_t);
@ -208,7 +208,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 2: case 2:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_coti_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_coti_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))));
off += sizeof(uint16_t) + sizeof(uint64_t); off += sizeof(uint16_t) + sizeof(uint64_t);
@ -219,7 +219,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 3: case 3:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_hot_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_hot_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))));
m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t))))));
@ -231,7 +231,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 4: case 4:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_cot_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_cot_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(1, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t))))));
m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t)))))); m->Assign(2, val_mgr->Count(ntohll(*((uint64_t*)(msg_data + sizeof(uint16_t) + sizeof(uint64_t))))));
@ -243,7 +243,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 5: case 5:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_bu_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_bu_type);
m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data)))); m->Assign(0, val_mgr->Count(ntohs(*((uint16_t*)msg_data))));
m->Assign(1, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x8000)); m->Assign(1, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x8000));
m->Assign(2, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x4000)); m->Assign(2, val_mgr->Bool(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))) & 0x4000));
@ -258,7 +258,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 6: case 6:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_back_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_back_type);
m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data)));
m->Assign(1, val_mgr->Bool(*((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80)); m->Assign(1, val_mgr->Bool(*((uint8_t*)(msg_data + sizeof(uint8_t))) & 0x80));
m->Assign(2, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t)))))); m->Assign(2, val_mgr->Count(ntohs(*((uint16_t*)(msg_data + sizeof(uint16_t))))));
@ -271,10 +271,10 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case 7: case 7:
{ {
auto m = make_intrusive<RecordVal>(ip6_mobility_be_type); auto m = zeek::make_intrusive<RecordVal>(ip6_mobility_be_type);
m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data))); m->Assign(0, val_mgr->Count(*((uint8_t*)msg_data)));
const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t)); const in6_addr* hoa = (const in6_addr*)(msg_data + sizeof(uint16_t));
m->Assign(1, make_intrusive<AddrVal>(IPAddr(*hoa))); m->Assign(1, zeek::make_intrusive<AddrVal>(IPAddr(*hoa)));
off += sizeof(uint16_t) + sizeof(in6_addr); off += sizeof(uint16_t) + sizeof(in6_addr);
m->Assign(2, BuildOptionsVal(data + off, Length() - off)); m->Assign(2, BuildOptionsVal(data + off, Length() - off));
msg->Assign(8, std::move(m)); msg->Assign(8, std::move(m));
@ -298,12 +298,12 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
return rv; return rv;
} }
IntrusivePtr<RecordVal> IPv6_Hdr::ToVal() const zeek::IntrusivePtr<RecordVal> IPv6_Hdr::ToVal() const
{ return ToVal(nullptr); } { return ToVal(nullptr); }
RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const
{ {
return ToVal({AdoptRef{}, chain}).release(); return ToVal({zeek::AdoptRef{}, chain}).release();
} }
IPAddr IP_Hdr::IPHeaderSrcAddr() const IPAddr IP_Hdr::IPHeaderSrcAddr() const
@ -326,22 +326,22 @@ IPAddr IP_Hdr::DstAddr() const
return ip4 ? IPAddr(ip4->ip_dst) : ip6_hdrs->DstAddr(); return ip4 ? IPAddr(ip4->ip_dst) : ip6_hdrs->DstAddr();
} }
IntrusivePtr<RecordVal> IP_Hdr::ToIPHdrVal() const zeek::IntrusivePtr<RecordVal> IP_Hdr::ToIPHdrVal() const
{ {
IntrusivePtr<RecordVal> rval; zeek::IntrusivePtr<RecordVal> rval;
if ( ip4 ) if ( ip4 )
{ {
static auto ip4_hdr_type = zeek::id::find_type<zeek::RecordType>("ip4_hdr"); static auto ip4_hdr_type = zeek::id::find_type<zeek::RecordType>("ip4_hdr");
rval = make_intrusive<RecordVal>(ip4_hdr_type); rval = zeek::make_intrusive<RecordVal>(ip4_hdr_type);
rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4)); rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4));
rval->Assign(1, val_mgr->Count(ip4->ip_tos)); rval->Assign(1, val_mgr->Count(ip4->ip_tos));
rval->Assign(2, val_mgr->Count(ntohs(ip4->ip_len))); rval->Assign(2, val_mgr->Count(ntohs(ip4->ip_len)));
rval->Assign(3, val_mgr->Count(ntohs(ip4->ip_id))); rval->Assign(3, val_mgr->Count(ntohs(ip4->ip_id)));
rval->Assign(4, val_mgr->Count(ip4->ip_ttl)); rval->Assign(4, val_mgr->Count(ip4->ip_ttl));
rval->Assign(5, val_mgr->Count(ip4->ip_p)); rval->Assign(5, val_mgr->Count(ip4->ip_p));
rval->Assign(6, make_intrusive<AddrVal>(ip4->ip_src.s_addr)); rval->Assign(6, zeek::make_intrusive<AddrVal>(ip4->ip_src.s_addr));
rval->Assign(7, make_intrusive<AddrVal>(ip4->ip_dst.s_addr)); rval->Assign(7, zeek::make_intrusive<AddrVal>(ip4->ip_dst.s_addr));
} }
else else
{ {
@ -356,10 +356,10 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const
return ToIPHdrVal().release(); return ToIPHdrVal().release();
} }
IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal() const zeek::IntrusivePtr<RecordVal> 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(make_intrusive<RecordVal>(pkt_hdr_type), 0); return ToPktHdrVal(zeek::make_intrusive<RecordVal>(pkt_hdr_type), 0);
} }
RecordVal* IP_Hdr::BuildPktHdrVal() const RecordVal* IP_Hdr::BuildPktHdrVal() const
@ -367,7 +367,7 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const
return ToPktHdrVal().release(); return ToPktHdrVal().release();
} }
IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int sindex) const zeek::IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(zeek::IntrusivePtr<RecordVal> 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");
@ -386,7 +386,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int
case IPPROTO_TCP: case IPPROTO_TCP:
{ {
const struct tcphdr* tp = (const struct tcphdr*) data; const struct tcphdr* tp = (const struct tcphdr*) data;
auto tcp_hdr = make_intrusive<RecordVal>(tcp_hdr_type); auto tcp_hdr = zeek::make_intrusive<RecordVal>(tcp_hdr_type);
int tcp_hdr_len = tp->th_off * 4; int tcp_hdr_len = tp->th_off * 4;
int data_len = PayloadLen() - tcp_hdr_len; int data_len = PayloadLen() - tcp_hdr_len;
@ -408,7 +408,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int
case IPPROTO_UDP: case IPPROTO_UDP:
{ {
const struct udphdr* up = (const struct udphdr*) data; const struct udphdr* up = (const struct udphdr*) data;
auto udp_hdr = make_intrusive<RecordVal>(udp_hdr_type); auto udp_hdr = zeek::make_intrusive<RecordVal>(udp_hdr_type);
udp_hdr->Assign(0, val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP)); udp_hdr->Assign(0, val_mgr->Port(ntohs(up->uh_sport), TRANSPORT_UDP));
udp_hdr->Assign(1, val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP)); udp_hdr->Assign(1, val_mgr->Port(ntohs(up->uh_dport), TRANSPORT_UDP));
@ -421,7 +421,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int
case IPPROTO_ICMP: case IPPROTO_ICMP:
{ {
const struct icmp* icmpp = (const struct icmp *) data; const struct icmp* icmpp = (const struct icmp *) data;
auto icmp_hdr = make_intrusive<RecordVal>(icmp_hdr_type); auto icmp_hdr = zeek::make_intrusive<RecordVal>(icmp_hdr_type);
icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp_type)); icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp_type));
@ -432,7 +432,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int
case IPPROTO_ICMPV6: case IPPROTO_ICMPV6:
{ {
const struct icmp6_hdr* icmpp = (const struct icmp6_hdr*) data; const struct icmp6_hdr* icmpp = (const struct icmp6_hdr*) data;
auto icmp_hdr = make_intrusive<RecordVal>(icmp_hdr_type); auto icmp_hdr = zeek::make_intrusive<RecordVal>(icmp_hdr_type);
icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp6_type)); icmp_hdr->Assign(0, val_mgr->Count(icmpp->icmp6_type));
@ -452,7 +452,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int
RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const RecordVal* IP_Hdr::BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const
{ {
return ToPktHdrVal({AdoptRef{}, pkt_hdr}, sindex).release(); return ToPktHdrVal({zeek::AdoptRef{}, pkt_hdr}, sindex).release();
} }
static inline bool isIPv6ExtHeader(uint8_t type) static inline bool isIPv6ExtHeader(uint8_t type)
@ -676,7 +676,7 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len)
} }
#endif #endif
IntrusivePtr<VectorVal> IPv6_Hdr_Chain::ToVal() const zeek::IntrusivePtr<VectorVal> 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");
@ -686,12 +686,12 @@ IntrusivePtr<VectorVal> IPv6_Hdr_Chain::ToVal() const
static auto ip6_ah_type = zeek::id::find_type<zeek::RecordType>("ip6_ah"); static auto ip6_ah_type = zeek::id::find_type<zeek::RecordType>("ip6_ah");
static auto ip6_esp_type = zeek::id::find_type<zeek::RecordType>("ip6_esp"); static auto ip6_esp_type = zeek::id::find_type<zeek::RecordType>("ip6_esp");
static auto ip6_ext_hdr_chain_type = zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain"); static auto ip6_ext_hdr_chain_type = zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain");
auto rval = make_intrusive<VectorVal>(ip6_ext_hdr_chain_type); auto rval = zeek::make_intrusive<VectorVal>(ip6_ext_hdr_chain_type);
for ( size_t i = 1; i < chain.size(); ++i ) for ( size_t i = 1; i < chain.size(); ++i )
{ {
auto v = chain[i]->ToVal(); auto v = chain[i]->ToVal();
auto ext_hdr = make_intrusive<RecordVal>(ip6_ext_hdr_type); auto ext_hdr = zeek::make_intrusive<RecordVal>(ip6_ext_hdr_type);
uint8_t type = chain[i]->Type(); uint8_t type = chain[i]->Type();
ext_hdr->Assign(0, val_mgr->Count(type)); ext_hdr->Assign(0, val_mgr->Count(type));

View file

@ -136,8 +136,8 @@ public:
/** /**
* Returns the script-layer record representation of the header. * Returns the script-layer record representation of the header.
*/ */
IntrusivePtr<RecordVal> ToVal(IntrusivePtr<VectorVal> chain) const; zeek::IntrusivePtr<RecordVal> ToVal(zeek::IntrusivePtr<VectorVal> chain) const;
IntrusivePtr<RecordVal> ToVal() const; zeek::IntrusivePtr<RecordVal> 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 +229,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.
*/ */
IntrusivePtr<VectorVal> ToVal() const; zeek::IntrusivePtr<VectorVal> 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 +526,7 @@ public:
/** /**
* Returns an ip_hdr or ip6_hdr_chain RecordVal. * Returns an ip_hdr or ip6_hdr_chain RecordVal.
*/ */
IntrusivePtr<RecordVal> ToIPHdrVal() const; zeek::IntrusivePtr<RecordVal> 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 +535,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.
*/ */
IntrusivePtr<RecordVal> ToPktHdrVal() const; zeek::IntrusivePtr<RecordVal> 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 +544,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.
*/ */
IntrusivePtr<RecordVal> ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int sindex) const; zeek::IntrusivePtr<RecordVal> ToPktHdrVal(zeek::IntrusivePtr<RecordVal> 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

@ -5,6 +5,8 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
namespace zeek {
/** /**
* A tag class for the #IntrusivePtr constructor which means: adopt * A tag class for the #IntrusivePtr constructor which means: adopt
* the reference from the caller. * the reference from the caller.
@ -97,7 +99,7 @@ public:
} }
IntrusivePtr(const IntrusivePtr& other) noexcept IntrusivePtr(const IntrusivePtr& other) noexcept
: IntrusivePtr(NewRef{}, other.get()) : IntrusivePtr(zeek::NewRef{}, other.get())
{ {
} }
@ -181,7 +183,7 @@ template <class T, class... Ts>
IntrusivePtr<T> make_intrusive(Ts&&... args) IntrusivePtr<T> make_intrusive(Ts&&... args)
{ {
// Assumes that objects start with a reference count of 1! // Assumes that objects start with a reference count of 1!
return {AdoptRef{}, new T(std::forward<Ts>(args)...)}; return {zeek::AdoptRef{}, new T(std::forward<Ts>(args)...)};
} }
/** /**
@ -193,16 +195,18 @@ IntrusivePtr<T> make_intrusive(Ts&&... args)
template <class T, class U> template <class T, class U>
IntrusivePtr<T> cast_intrusive(IntrusivePtr<U> p) noexcept IntrusivePtr<T> cast_intrusive(IntrusivePtr<U> p) noexcept
{ {
return {AdoptRef{}, static_cast<T*>(p.release())}; return {zeek::AdoptRef{}, static_cast<T*>(p.release())};
} }
}
// -- comparison to nullptr ---------------------------------------------------- // -- comparison to nullptr ----------------------------------------------------
/** /**
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator==(const IntrusivePtr<T>& x, std::nullptr_t) { bool operator==(const zeek::IntrusivePtr<T>& x, std::nullptr_t) {
return !x; return !x;
} }
@ -210,7 +214,7 @@ bool operator==(const IntrusivePtr<T>& x, std::nullptr_t) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator==(std::nullptr_t, const IntrusivePtr<T>& x) { bool operator==(std::nullptr_t, const zeek::IntrusivePtr<T>& x) {
return !x; return !x;
} }
@ -218,7 +222,7 @@ bool operator==(std::nullptr_t, const IntrusivePtr<T>& x) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator!=(const IntrusivePtr<T>& x, std::nullptr_t) { bool operator!=(const zeek::IntrusivePtr<T>& x, std::nullptr_t) {
return static_cast<bool>(x); return static_cast<bool>(x);
} }
@ -226,7 +230,7 @@ bool operator!=(const IntrusivePtr<T>& x, std::nullptr_t) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator!=(std::nullptr_t, const IntrusivePtr<T>& x) { bool operator!=(std::nullptr_t, const zeek::IntrusivePtr<T>& x) {
return static_cast<bool>(x); return static_cast<bool>(x);
} }
@ -236,7 +240,7 @@ bool operator!=(std::nullptr_t, const IntrusivePtr<T>& x) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator==(const IntrusivePtr<T>& x, const T* y) { bool operator==(const zeek::IntrusivePtr<T>& x, const T* y) {
return x.get() == y; return x.get() == y;
} }
@ -244,7 +248,7 @@ bool operator==(const IntrusivePtr<T>& x, const T* y) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator==(const T* x, const IntrusivePtr<T>& y) { bool operator==(const T* x, const zeek::IntrusivePtr<T>& y) {
return x == y.get(); return x == y.get();
} }
@ -252,7 +256,7 @@ bool operator==(const T* x, const IntrusivePtr<T>& y) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator!=(const IntrusivePtr<T>& x, const T* y) { bool operator!=(const zeek::IntrusivePtr<T>& x, const T* y) {
return x.get() != y; return x.get() != y;
} }
@ -260,7 +264,7 @@ bool operator!=(const IntrusivePtr<T>& x, const T* y) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T> template <class T>
bool operator!=(const T* x, const IntrusivePtr<T>& y) { bool operator!=(const T* x, const zeek::IntrusivePtr<T>& y) {
return x != y.get(); return x != y.get();
} }
@ -273,7 +277,7 @@ bool operator!=(const T* x, const IntrusivePtr<T>& y) {
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T, class U> template <class T, class U>
auto operator==(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y) auto operator==(const zeek::IntrusivePtr<T>& x, const zeek::IntrusivePtr<U>& y)
-> decltype(x.get() == y.get()) -> decltype(x.get() == y.get())
{ {
return x.get() == y.get(); return x.get() == y.get();
@ -283,9 +287,8 @@ auto operator==(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y)
* @relates IntrusivePtr * @relates IntrusivePtr
*/ */
template <class T, class U> template <class T, class U>
auto operator!=(const IntrusivePtr<T>& x, const IntrusivePtr<U>& y) auto operator!=(const zeek::IntrusivePtr<T>& x, const zeek::IntrusivePtr<U>& y)
-> decltype(x.get() != y.get()) -> decltype(x.get() != y.get())
{ {
return x.get() != y.get(); return x.get() != y.get();
} }

View file

@ -194,7 +194,7 @@ void net_init(const std::optional<std::string>& interface,
writefile, pkt_dumper->ErrorMsg()); writefile, pkt_dumper->ErrorMsg());
if ( const auto& id = global_scope()->Find("trace_output_file") ) if ( const auto& id = global_scope()->Find("trace_output_file") )
id->SetVal(make_intrusive<StringVal>(writefile)); id->SetVal(zeek::make_intrusive<StringVal>(writefile));
else else
reporter->Error("trace_output_file not defined in bro.init"); reporter->Error("trace_output_file not defined in bro.init");
} }

View file

@ -37,10 +37,10 @@ OpaqueMgr* OpaqueMgr::mgr()
return &mgr; return &mgr;
} }
OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({NewRef{}, t}) OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({zeek::NewRef{}, t})
{} {}
OpaqueVal::OpaqueVal(IntrusivePtr<zeek::OpaqueType> t) : Val(std::move(t)) OpaqueVal::OpaqueVal(zeek::IntrusivePtr<zeek::OpaqueType> 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;
} }
IntrusivePtr<OpaqueVal> OpaqueMgr::Instantiate(const std::string& id) const zeek::IntrusivePtr<OpaqueVal> 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)}};
} }
IntrusivePtr<OpaqueVal> OpaqueVal::Unserialize(const broker::data& data) zeek::IntrusivePtr<OpaqueVal> 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 @@ IntrusivePtr<OpaqueVal> OpaqueVal::Unserialize(const broker::data& data)
return val; return val;
} }
broker::expected<broker::data> OpaqueVal::SerializeType(const IntrusivePtr<zeek::Type>& t) broker::expected<broker::data> OpaqueVal::SerializeType(const zeek::IntrusivePtr<zeek::Type>& 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 IntrusivePtr<zeek:
return {broker::vector{false, static_cast<uint64_t>(t->Tag())}}; return {broker::vector{false, static_cast<uint64_t>(t->Tag())}};
} }
IntrusivePtr<zeek::Type> OpaqueVal::UnserializeType(const broker::data& data) zeek::IntrusivePtr<zeek::Type> 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 @@ IntrusivePtr<zeek::Type> OpaqueVal::UnserializeType(const broker::data& data)
return zeek::base_type(static_cast<zeek::TypeTag>(*tag)); return zeek::base_type(static_cast<zeek::TypeTag>(*tag));
} }
IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state) zeek::IntrusivePtr<Val> 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;
} }
IntrusivePtr<StringVal> HashVal::Get() zeek::IntrusivePtr<StringVal> HashVal::Get()
{ {
if ( ! valid ) if ( ! valid )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
@ -200,18 +200,18 @@ bool HashVal::DoFeed(const void*, size_t)
return false; return false;
} }
IntrusivePtr<StringVal> HashVal::DoGet() zeek::IntrusivePtr<StringVal> HashVal::DoGet()
{ {
assert(! "missing implementation of DoGet()"); assert(! "missing implementation of DoGet()");
return val_mgr->EmptyString(); return val_mgr->EmptyString();
} }
HashVal::HashVal(IntrusivePtr<zeek::OpaqueType> t) : OpaqueVal(std::move(t)) HashVal::HashVal(zeek::IntrusivePtr<zeek::OpaqueType> t) : OpaqueVal(std::move(t))
{ {
valid = false; valid = false;
} }
HashVal::HashVal(zeek::OpaqueType* t) : HashVal({NewRef{}, t}) HashVal::HashVal(zeek::OpaqueType* t) : HashVal({zeek::NewRef{}, t})
{} {}
MD5Val::MD5Val() : HashVal(md5_type) MD5Val::MD5Val() : HashVal(md5_type)
@ -239,14 +239,14 @@ void HashVal::digest_one(EVP_MD_CTX* h, const Val* v)
} }
} }
void HashVal::digest_one(EVP_MD_CTX* h, const IntrusivePtr<Val>& v) void HashVal::digest_one(EVP_MD_CTX* h, const zeek::IntrusivePtr<Val>& v)
{ {
digest_one(h, v.get()); digest_one(h, v.get());
} }
IntrusivePtr<Val> MD5Val::DoClone(CloneState* state) zeek::IntrusivePtr<Val> MD5Val::DoClone(CloneState* state)
{ {
auto out = make_intrusive<MD5Val>(); auto out = zeek::make_intrusive<MD5Val>();
if ( IsValid() ) if ( IsValid() )
{ {
@ -275,14 +275,14 @@ bool MD5Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
IntrusivePtr<StringVal> MD5Val::DoGet() zeek::IntrusivePtr<StringVal> MD5Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
u_char digest[MD5_DIGEST_LENGTH]; u_char digest[MD5_DIGEST_LENGTH];
hash_final(ctx, digest); hash_final(ctx, digest);
return make_intrusive<StringVal>(md5_digest_print(digest)); return zeek::make_intrusive<StringVal>(md5_digest_print(digest));
} }
IMPLEMENT_OPAQUE_VALUE(MD5Val) IMPLEMENT_OPAQUE_VALUE(MD5Val)
@ -364,9 +364,9 @@ SHA1Val::~SHA1Val()
EVP_MD_CTX_free(ctx); EVP_MD_CTX_free(ctx);
} }
IntrusivePtr<Val> SHA1Val::DoClone(CloneState* state) zeek::IntrusivePtr<Val> SHA1Val::DoClone(CloneState* state)
{ {
auto out = make_intrusive<SHA1Val>(); auto out = zeek::make_intrusive<SHA1Val>();
if ( IsValid() ) if ( IsValid() )
{ {
@ -395,14 +395,14 @@ bool SHA1Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
IntrusivePtr<StringVal> SHA1Val::DoGet() zeek::IntrusivePtr<StringVal> SHA1Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
u_char digest[SHA_DIGEST_LENGTH]; u_char digest[SHA_DIGEST_LENGTH];
hash_final(ctx, digest); hash_final(ctx, digest);
return make_intrusive<StringVal>(sha1_digest_print(digest)); return zeek::make_intrusive<StringVal>(sha1_digest_print(digest));
} }
IMPLEMENT_OPAQUE_VALUE(SHA1Val) IMPLEMENT_OPAQUE_VALUE(SHA1Val)
@ -487,9 +487,9 @@ SHA256Val::~SHA256Val()
EVP_MD_CTX_free(ctx); EVP_MD_CTX_free(ctx);
} }
IntrusivePtr<Val> SHA256Val::DoClone(CloneState* state) zeek::IntrusivePtr<Val> SHA256Val::DoClone(CloneState* state)
{ {
auto out = make_intrusive<SHA256Val>(); auto out = zeek::make_intrusive<SHA256Val>();
if ( IsValid() ) if ( IsValid() )
{ {
@ -518,14 +518,14 @@ bool SHA256Val::DoFeed(const void* data, size_t size)
return true; return true;
} }
IntrusivePtr<StringVal> SHA256Val::DoGet() zeek::IntrusivePtr<StringVal> SHA256Val::DoGet()
{ {
if ( ! IsValid() ) if ( ! IsValid() )
return val_mgr->EmptyString(); return val_mgr->EmptyString();
u_char digest[SHA256_DIGEST_LENGTH]; u_char digest[SHA256_DIGEST_LENGTH];
hash_final(ctx, digest); hash_final(ctx, digest);
return make_intrusive<StringVal>(sha256_digest_print(digest)); return zeek::make_intrusive<StringVal>(sha256_digest_print(digest));
} }
IMPLEMENT_OPAQUE_VALUE(SHA256Val) IMPLEMENT_OPAQUE_VALUE(SHA256Val)
@ -711,26 +711,26 @@ BloomFilterVal::BloomFilterVal(probabilistic::BloomFilter* bf)
bloom_filter = bf; bloom_filter = bf;
} }
IntrusivePtr<Val> BloomFilterVal::DoClone(CloneState* state) zeek::IntrusivePtr<Val> BloomFilterVal::DoClone(CloneState* state)
{ {
if ( bloom_filter ) if ( bloom_filter )
{ {
auto bf = make_intrusive<BloomFilterVal>(bloom_filter->Clone()); auto bf = zeek::make_intrusive<BloomFilterVal>(bloom_filter->Clone());
bf->Typify(type); bf->Typify(type);
return state->NewClone(this, std::move(bf)); return state->NewClone(this, std::move(bf));
} }
return state->NewClone(this, make_intrusive<BloomFilterVal>()); return state->NewClone(this, zeek::make_intrusive<BloomFilterVal>());
} }
bool BloomFilterVal::Typify(IntrusivePtr<zeek::Type> arg_type) bool BloomFilterVal::Typify(zeek::IntrusivePtr<zeek::Type> arg_type)
{ {
if ( type ) if ( type )
return false; return false;
type = std::move(arg_type); type = std::move(arg_type);
auto tl = make_intrusive<zeek::TypeList>(type); auto tl = zeek::make_intrusive<zeek::TypeList>(type);
tl->Append(type); tl->Append(type);
hash = new CompositeHash(std::move(tl)); hash = new CompositeHash(std::move(tl));
@ -765,7 +765,7 @@ std::string BloomFilterVal::InternalState() const
return bloom_filter->InternalState(); return bloom_filter->InternalState();
} }
IntrusivePtr<BloomFilterVal> BloomFilterVal::Merge(const BloomFilterVal* x, zeek::IntrusivePtr<BloomFilterVal> 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
@ -791,7 +791,7 @@ IntrusivePtr<BloomFilterVal> BloomFilterVal::Merge(const BloomFilterVal* x,
return nullptr; return nullptr;
} }
auto merged = make_intrusive<BloomFilterVal>(copy); auto merged = zeek::make_intrusive<BloomFilterVal>(copy);
if ( x->Type() && ! merged->Typify(x->Type()) ) if ( x->Type() && ! merged->Typify(x->Type()) )
{ {
@ -876,20 +876,20 @@ CardinalityVal::~CardinalityVal()
delete hash; delete hash;
} }
IntrusivePtr<Val> CardinalityVal::DoClone(CloneState* state) zeek::IntrusivePtr<Val> CardinalityVal::DoClone(CloneState* state)
{ {
return state->NewClone(this, return state->NewClone(this,
make_intrusive<CardinalityVal>(new probabilistic::CardinalityCounter(*c))); zeek::make_intrusive<CardinalityVal>(new probabilistic::CardinalityCounter(*c)));
} }
bool CardinalityVal::Typify(IntrusivePtr<zeek::Type> arg_type) bool CardinalityVal::Typify(zeek::IntrusivePtr<zeek::Type> arg_type)
{ {
if ( type ) if ( type )
return false; return false;
type = std::move(arg_type); type = std::move(arg_type);
auto tl = make_intrusive<zeek::TypeList>(type); auto tl = zeek::make_intrusive<zeek::TypeList>(type);
tl->Append(type); tl->Append(type);
hash = new CompositeHash(std::move(tl)); hash = new CompositeHash(std::move(tl));
@ -957,14 +957,14 @@ ParaglobVal::ParaglobVal(std::unique_ptr<paraglob::Paraglob> p)
this->internal_paraglob = std::move(p); this->internal_paraglob = std::move(p);
} }
IntrusivePtr<VectorVal> ParaglobVal::Get(StringVal* &pattern) zeek::IntrusivePtr<VectorVal> ParaglobVal::Get(StringVal* &pattern)
{ {
auto rval = 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());
std::vector<std::string> matches = this->internal_paraglob->get(string_pattern); std::vector<std::string> matches = this->internal_paraglob->get(string_pattern);
for (unsigned int i = 0; i < matches.size(); i++) for (unsigned int i = 0; i < matches.size(); i++)
rval->Assign(i, make_intrusive<StringVal>(matches.at(i))); rval->Assign(i, zeek::make_intrusive<StringVal>(matches.at(i)));
return rval; return rval;
} }
@ -1018,10 +1018,10 @@ bool ParaglobVal::DoUnserialize(const broker::data& data)
return true; return true;
} }
IntrusivePtr<Val> ParaglobVal::DoClone(CloneState* state) zeek::IntrusivePtr<Val> ParaglobVal::DoClone(CloneState* state)
{ {
try { try {
return make_intrusive<ParaglobVal> return zeek::make_intrusive<ParaglobVal>
(std::make_unique<paraglob::Paraglob>(this->internal_paraglob->serialize())); (std::make_unique<paraglob::Paraglob>(this->internal_paraglob->serialize()));
} }
catch (const paraglob::underflow_error& e) catch (const paraglob::underflow_error& e)

View file

@ -21,7 +21,7 @@ class OpaqueVal;
*/ */
class OpaqueMgr { class OpaqueMgr {
public: public:
using Factory = IntrusivePtr<OpaqueVal> (); using Factory = zeek::IntrusivePtr<OpaqueVal> ();
/** /**
* 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 +45,7 @@ public:
* is unknown, this will return null. * is unknown, this will return null.
* *
*/ */
IntrusivePtr<OpaqueVal> Instantiate(const std::string& id) const; zeek::IntrusivePtr<OpaqueVal> Instantiate(const std::string& id) const;
/** Returns the global manager singleton object. */ /** Returns the global manager singleton object. */
static OpaqueMgr* mgr(); static OpaqueMgr* mgr();
@ -68,11 +68,11 @@ private:
/** Macro to insert into an OpaqueVal-derived class's declaration. */ /** Macro to insert into an OpaqueVal-derived class's declaration. */
#define DECLARE_OPAQUE_VALUE(T) \ #define DECLARE_OPAQUE_VALUE(T) \
friend class OpaqueMgr::Register<T>; \ friend class OpaqueMgr::Register<T>; \
friend IntrusivePtr<T> make_intrusive<T>(); \ friend zeek::IntrusivePtr<T> zeek::make_intrusive<T>(); \
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 IntrusivePtr<OpaqueVal> OpaqueInstantiate() { return make_intrusive<T>(); } static zeek::IntrusivePtr<OpaqueVal> 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 +89,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(IntrusivePtr<zeek::OpaqueType> t); explicit OpaqueVal(zeek::IntrusivePtr<zeek::OpaqueType> t);
~OpaqueVal() override; ~OpaqueVal() override;
/** /**
@ -106,7 +106,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 IntrusivePtr<OpaqueVal> Unserialize(const broker::data& data); static zeek::IntrusivePtr<OpaqueVal> Unserialize(const broker::data& data);
protected: protected:
friend class Val; friend class Val;
@ -142,19 +142,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.
*/ */
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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 IntrusivePtr<zeek::Type>& t); static broker::expected<broker::data> SerializeType(const zeek::IntrusivePtr<zeek::Type>& 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 IntrusivePtr<zeek::Type> UnserializeType(const broker::data& data); static zeek::IntrusivePtr<zeek::Type> UnserializeType(const broker::data& data);
}; };
namespace probabilistic { namespace probabilistic {
@ -178,21 +178,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);
IntrusivePtr<StringVal> Get(); zeek::IntrusivePtr<StringVal> 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 IntrusivePtr<Val>& v); static void digest_one(EVP_MD_CTX* h, const zeek::IntrusivePtr<Val>& 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(IntrusivePtr<zeek::OpaqueType> t); explicit HashVal(zeek::IntrusivePtr<zeek::OpaqueType> 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 IntrusivePtr<StringVal> DoGet(); virtual zeek::IntrusivePtr<StringVal> 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 +221,14 @@ public:
MD5Val(); MD5Val();
~MD5Val(); ~MD5Val();
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<StringVal> DoGet() override; zeek::IntrusivePtr<StringVal> DoGet() override;
DECLARE_OPAQUE_VALUE(MD5Val) DECLARE_OPAQUE_VALUE(MD5Val)
private: private:
@ -244,14 +244,14 @@ public:
SHA1Val(); SHA1Val();
~SHA1Val(); ~SHA1Val();
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<StringVal> DoGet() override; zeek::IntrusivePtr<StringVal> DoGet() override;
DECLARE_OPAQUE_VALUE(SHA1Val) DECLARE_OPAQUE_VALUE(SHA1Val)
private: private:
@ -267,14 +267,14 @@ public:
SHA256Val(); SHA256Val();
~SHA256Val(); ~SHA256Val();
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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;
IntrusivePtr<StringVal> DoGet() override; zeek::IntrusivePtr<StringVal> DoGet() override;
DECLARE_OPAQUE_VALUE(SHA256Val) DECLARE_OPAQUE_VALUE(SHA256Val)
private: private:
@ -302,12 +302,12 @@ public:
explicit BloomFilterVal(probabilistic::BloomFilter* bf); explicit BloomFilterVal(probabilistic::BloomFilter* bf);
~BloomFilterVal() override; ~BloomFilterVal() override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
const IntrusivePtr<zeek::Type>& Type() const const zeek::IntrusivePtr<zeek::Type>& Type() const
{ return type; } { return type; }
bool Typify(IntrusivePtr<zeek::Type> type); bool Typify(zeek::IntrusivePtr<zeek::Type> 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,7 +315,7 @@ public:
bool Empty() const; bool Empty() const;
std::string InternalState() const; std::string InternalState() const;
static IntrusivePtr<BloomFilterVal> Merge(const BloomFilterVal* x, static zeek::IntrusivePtr<BloomFilterVal> Merge(const BloomFilterVal* x,
const BloomFilterVal* y); const BloomFilterVal* y);
protected: protected:
@ -328,7 +328,7 @@ private:
BloomFilterVal(const BloomFilterVal&); BloomFilterVal(const BloomFilterVal&);
BloomFilterVal& operator=(const BloomFilterVal&); BloomFilterVal& operator=(const BloomFilterVal&);
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> type;
CompositeHash* hash; CompositeHash* hash;
probabilistic::BloomFilter* bloom_filter; probabilistic::BloomFilter* bloom_filter;
}; };
@ -339,14 +339,14 @@ public:
explicit CardinalityVal(probabilistic::CardinalityCounter*); explicit CardinalityVal(probabilistic::CardinalityCounter*);
~CardinalityVal() override; ~CardinalityVal() override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
void Add(const Val* val); void Add(const Val* val);
const IntrusivePtr<zeek::Type>& Type() const const zeek::IntrusivePtr<zeek::Type>& Type() const
{ return type; } { return type; }
bool Typify(IntrusivePtr<zeek::Type> type); bool Typify(zeek::IntrusivePtr<zeek::Type> type);
probabilistic::CardinalityCounter* Get() { return c; }; probabilistic::CardinalityCounter* Get() { return c; };
@ -355,7 +355,7 @@ protected:
DECLARE_OPAQUE_VALUE(CardinalityVal) DECLARE_OPAQUE_VALUE(CardinalityVal)
private: private:
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> type;
CompositeHash* hash; CompositeHash* hash;
probabilistic::CardinalityCounter* c; probabilistic::CardinalityCounter* c;
}; };
@ -363,8 +363,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);
IntrusivePtr<VectorVal> Get(StringVal* &pattern); zeek::IntrusivePtr<VectorVal> Get(StringVal* &pattern);
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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(IntrusivePtr<RecordVal> conn_id, IntrusivePtr<StringVal> uid, void Reporter::Weird(zeek::IntrusivePtr<RecordVal> conn_id, zeek::IntrusivePtr<StringVal> uid,
const char* name, const char* addl) const char* name, const char* addl)
{ {
UpdateWeirdStats(name); UpdateWeirdStats(name);
@ -558,19 +558,19 @@ void Reporter::DoLog(const char* prefix, EventHandlerPtr event, FILE* out,
vl.reserve(vl_size); vl.reserve(vl_size);
if ( time ) if ( time )
vl.emplace_back(make_intrusive<TimeVal>(network_time ? network_time : current_time())); vl.emplace_back(zeek::make_intrusive<TimeVal>(network_time ? network_time : current_time()));
vl.emplace_back(make_intrusive<StringVal>(buffer)); vl.emplace_back(zeek::make_intrusive<StringVal>(buffer));
if ( location ) if ( location )
vl.emplace_back(make_intrusive<StringVal>(loc_str.c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(loc_str.c_str()));
if ( conn ) if ( conn )
vl.emplace_back(conn->ConnVal()); vl.emplace_back(conn->ConnVal());
if ( addl ) if ( addl )
for ( auto v : *addl ) for ( auto v : *addl )
vl.emplace_back(AdoptRef{}, v); vl.emplace_back(zeek::AdoptRef{}, v);
if ( conn ) if ( conn )
conn->EnqueueEvent(event, nullptr, std::move(vl)); conn->EnqueueEvent(event, nullptr, std::move(vl));

View file

@ -24,7 +24,9 @@ class EventHandlerPtr;
class RecordVal; class RecordVal;
class StringVal; class StringVal;
namespace zeek {
template <class T> class IntrusivePtr; template <class T> class IntrusivePtr;
}
// 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.
@ -97,7 +99,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(IntrusivePtr<RecordVal> conn_id, IntrusivePtr<StringVal> uid, void Weird(zeek::IntrusivePtr<RecordVal> conn_id, zeek::IntrusivePtr<StringVal> 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

@ -22,9 +22,9 @@ void RuleActionEvent::DoAction(const Rule* parent, RuleEndpointState* state,
{ {
if ( signature_match ) if ( signature_match )
mgr.Enqueue(signature_match, mgr.Enqueue(signature_match,
IntrusivePtr{AdoptRef{}, rule_matcher->BuildRuleStateValue(parent, state)}, zeek::IntrusivePtr{zeek::AdoptRef{}, rule_matcher->BuildRuleStateValue(parent, state)},
make_intrusive<StringVal>(msg), zeek::make_intrusive<StringVal>(msg),
data ? make_intrusive<StringVal>(len, (const char*)data) : val_mgr->EmptyString() data ? zeek::make_intrusive<StringVal>(len, (const char*)data) : val_mgr->EmptyString()
); );
} }

View file

@ -170,10 +170,10 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state,
// Call function with a signature_state value as argument. // Call function with a signature_state value as argument.
zeek::Args args; zeek::Args args;
args.reserve(2); args.reserve(2);
args.emplace_back(AdoptRef{}, rule_matcher->BuildRuleStateValue(rule, state)); args.emplace_back(zeek::AdoptRef{}, rule_matcher->BuildRuleStateValue(rule, state));
if ( data ) if ( data )
args.emplace_back(make_intrusive<StringVal>(len, (const char*) data)); args.emplace_back(zeek::make_intrusive<StringVal>(len, (const char*) data));
else else
args.emplace_back(val_mgr->EmptyString()); args.emplace_back(val_mgr->EmptyString());

View file

@ -83,7 +83,7 @@ Val* RuleMatcher::BuildRuleStateValue(const Rule* rule,
{ {
static auto signature_state = zeek::id::find_type<zeek::RecordType>("signature_state"); static auto signature_state = zeek::id::find_type<zeek::RecordType>("signature_state");
RecordVal* val = new RecordVal(signature_state); RecordVal* val = new RecordVal(signature_state);
val->Assign(0, make_intrusive<StringVal>(rule->ID())); val->Assign(0, zeek::make_intrusive<StringVal>(rule->ID()));
val->Assign(1, state->GetAnalyzer()->ConnVal()); val->Assign(1, state->GetAnalyzer()->ConnVal());
val->Assign(2, val_mgr->Bool(state->is_orig)); val->Assign(2, val_mgr->Bool(state->is_orig));
val->Assign(3, val_mgr->Count(state->payload_size)); val->Assign(3, val_mgr->Count(state->payload_size));

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(IntrusivePtr<zeek::detail::ID> id, Scope::Scope(zeek::IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> al) std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> 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(IntrusivePtr<zeek::detail::ID> id,
} }
} }
const IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) const const zeek::IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) const
{ {
auto entry = local.find(name); auto entry = local.find(name);
@ -45,7 +45,7 @@ const IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) const
return zeek::detail::ID::nil; return zeek::detail::ID::nil;
} }
IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name) zeek::IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name)
{ {
auto entry = local.find(name); auto entry = local.find(name);
@ -59,12 +59,12 @@ IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name)
return nullptr; return nullptr;
} }
IntrusivePtr<zeek::detail::ID> Scope::GenerateTemporary(const char* name) zeek::IntrusivePtr<zeek::detail::ID> Scope::GenerateTemporary(const char* name)
{ {
return 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<IntrusivePtr<zeek::detail::ID>> Scope::GetInits() std::vector<zeek::IntrusivePtr<zeek::detail::ID>> Scope::GetInits()
{ {
auto rval = std::move(inits); auto rval = std::move(inits);
inits = {}; inits = {};
@ -119,9 +119,10 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
} }
const IntrusivePtr<zeek::detail::ID>& lookup_ID(const char* name, const char* curr_module, const zeek::IntrusivePtr<zeek::detail::ID>& lookup_ID(
bool no_global, bool same_module_only, const char* name, const char* curr_module,
bool check_export) bool no_global, bool same_module_only,
bool check_export)
{ {
std::string fullname = make_full_var_name(curr_module, name); std::string fullname = make_full_var_name(curr_module, name);
@ -153,8 +154,9 @@ const IntrusivePtr<zeek::detail::ID>& lookup_ID(const char* name, const char* cu
return zeek::detail::ID::nil; return zeek::detail::ID::nil;
} }
IntrusivePtr<zeek::detail::ID> install_ID(const char* name, const char* module_name, zeek::IntrusivePtr<zeek::detail::ID> install_ID(
bool is_global, bool is_export) const char* name, const char* module_name,
bool is_global, bool is_export)
{ {
if ( scopes.empty() && ! is_global ) if ( scopes.empty() && ! is_global )
reporter->InternalError("local identifier in global scope"); reporter->InternalError("local identifier in global scope");
@ -171,7 +173,7 @@ IntrusivePtr<zeek::detail::ID> install_ID(const char* name, const char* module_n
std::string full_name = make_full_var_name(module_name, name); std::string full_name = make_full_var_name(module_name, name);
auto id = make_intrusive<zeek::detail::ID>(full_name.data(), scope, is_export); auto id = zeek::make_intrusive<zeek::detail::ID>(full_name.data(), scope, is_export);
if ( zeek::detail::SCOPE_FUNCTION != scope ) if ( zeek::detail::SCOPE_FUNCTION != scope )
global_scope()->Insert(std::move(full_name), id); global_scope()->Insert(std::move(full_name), id);
@ -189,14 +191,14 @@ void push_existing_scope(Scope* scope)
scopes.push_back(scope); scopes.push_back(scope);
} }
void push_scope(IntrusivePtr<zeek::detail::ID> id, void push_scope(zeek::IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs) std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> 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);
} }
IntrusivePtr<Scope> pop_scope() zeek::IntrusivePtr<Scope> pop_scope()
{ {
if ( scopes.empty() ) if ( scopes.empty() )
reporter->InternalError("scope underflow"); reporter->InternalError("scope underflow");
@ -206,7 +208,7 @@ IntrusivePtr<Scope> pop_scope()
top_scope = scopes.empty() ? nullptr : scopes.back(); top_scope = scopes.empty() ? nullptr : scopes.back();
return {AdoptRef{}, old_top}; return {zeek::AdoptRef{}, old_top};
} }
Scope* current_scope() Scope* current_scope()

View file

@ -21,10 +21,10 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
class Scope : public BroObj { class Scope : public BroObj {
public: public:
explicit Scope(IntrusivePtr<zeek::detail::ID> id, explicit Scope(zeek::IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> al); std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> al);
const IntrusivePtr<zeek::detail::ID>& Find(std::string_view name) const; const zeek::IntrusivePtr<zeek::detail::ID>& 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 +34,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); }
IntrusivePtr<zeek::detail::ID> Remove(std::string_view name); zeek::IntrusivePtr<zeek::detail::ID> 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 IntrusivePtr<zeek::detail::ID>& GetID() const const zeek::IntrusivePtr<zeek::detail::ID>& GetID() const
{ return scope_id; } { return scope_id; }
const std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>>& Attrs() const const std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>>& 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 IntrusivePtr<zeek::Type>& GetReturnType() const const zeek::IntrusivePtr<zeek::Type>& 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; }
IntrusivePtr<zeek::detail::ID> GenerateTemporary(const char* name); zeek::IntrusivePtr<zeek::detail::ID> 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<IntrusivePtr<zeek::detail::ID>> GetInits(); std::vector<zeek::IntrusivePtr<zeek::detail::ID>> GetInits();
// Adds a variable to the list. // Adds a variable to the list.
void AddInit(IntrusivePtr<zeek::detail::ID> id) void AddInit(zeek::IntrusivePtr<zeek::detail::ID> 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,31 +69,33 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const; TraversalCode Traverse(TraversalCallback* cb) const;
protected: protected:
IntrusivePtr<zeek::detail::ID> scope_id; zeek::IntrusivePtr<zeek::detail::ID> scope_id;
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs; std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs;
IntrusivePtr<zeek::Type> return_type; zeek::IntrusivePtr<zeek::Type> return_type;
std::map<std::string, IntrusivePtr<zeek::detail::ID>, std::less<>> local; std::map<std::string, zeek::IntrusivePtr<zeek::detail::ID>, std::less<>> local;
std::vector<IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::IntrusivePtr<zeek::detail::ID>> 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 IntrusivePtr<zeek::detail::ID>& lookup_ID(const char* name, const char* module, extern const zeek::IntrusivePtr<zeek::detail::ID>& lookup_ID(
bool no_global = false, const char* name, const char* module,
bool same_module_only = false, bool no_global = false,
bool check_export = true); bool same_module_only = false,
bool check_export = true);
extern IntrusivePtr<zeek::detail::ID> install_ID(const char* name, const char* module_name, extern zeek::IntrusivePtr<zeek::detail::ID> install_ID(
bool is_global, bool is_export); const char* name, const char* module_name,
bool is_global, bool is_export);
extern void push_scope(IntrusivePtr<zeek::detail::ID> id, extern void push_scope(zeek::IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs); std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> 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 IntrusivePtr<Scope> pop_scope(); extern zeek::IntrusivePtr<Scope> 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());
IntrusivePtr<Val> pkt_hdr_val; zeek::IntrusivePtr<Val> pkt_hdr_val;
if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 ) if ( ipv6_ext_headers && ip_hdr->NumHeaders() > 1 )
{ {

View file

@ -63,7 +63,7 @@ VectorVal* BroSubstring::VecToPolicy(Vec* vec)
static auto sw_align_vec_type = zeek::id::find_type<zeek::VectorType>("sw_align_vec"); static auto sw_align_vec_type = zeek::id::find_type<zeek::VectorType>("sw_align_vec");
static auto sw_substring_vec_type = zeek::id::find_type<zeek::VectorType>("sw_substring_vec"); static auto sw_substring_vec_type = zeek::id::find_type<zeek::VectorType>("sw_substring_vec");
auto result = make_intrusive<VectorVal>(sw_substring_vec_type); auto result = zeek::make_intrusive<VectorVal>(sw_substring_vec_type);
if ( vec ) if ( vec )
{ {
@ -71,17 +71,17 @@ VectorVal* BroSubstring::VecToPolicy(Vec* vec)
{ {
BroSubstring* bst = (*vec)[i]; BroSubstring* bst = (*vec)[i];
auto st_val = make_intrusive<RecordVal>(sw_substring_type); auto st_val = zeek::make_intrusive<RecordVal>(sw_substring_type);
st_val->Assign(0, make_intrusive<StringVal>(new BroString(*bst))); st_val->Assign(0, zeek::make_intrusive<StringVal>(new BroString(*bst)));
auto aligns = make_intrusive<VectorVal>(sw_align_vec_type); auto aligns = zeek::make_intrusive<VectorVal>(sw_align_vec_type);
for ( unsigned int j = 0; j < bst->GetNumAlignments(); ++j ) for ( unsigned int j = 0; j < bst->GetNumAlignments(); ++j )
{ {
const BSSAlign& align = (bst->GetAlignments())[j]; const BSSAlign& align = (bst->GetAlignments())[j];
auto align_val = make_intrusive<RecordVal>(sw_align_type); auto align_val = zeek::make_intrusive<RecordVal>(sw_align_type);
align_val->Assign(0, make_intrusive<StringVal>(new BroString(*align.string))); align_val->Assign(0, zeek::make_intrusive<StringVal>(new BroString(*align.string)));
align_val->Assign(1, val_mgr->Count(align.index)); align_val->Assign(1, val_mgr->Count(align.index));
aligns->Assign(j + 1, std::move(align_val)); aligns->Assign(j + 1, std::move(align_val));

View file

@ -313,9 +313,9 @@ void ProfileLogger::Log()
if ( profiling_update ) if ( profiling_update )
{ {
mgr.Dispatch(new Event(profiling_update, { mgr.Dispatch(new Event(profiling_update, {
make_intrusive<Val>(IntrusivePtr{NewRef{}, file}), zeek::make_intrusive<Val>(zeek::IntrusivePtr{zeek::NewRef{}, file}),
val_mgr->Bool(expensive), val_mgr->Bool(expensive),
})); }));
} }
} }
@ -344,7 +344,7 @@ SampleLogger::SampleLogger()
if ( ! load_sample_info ) if ( ! load_sample_info )
load_sample_info = zeek::id::find_type("load_sample_info")->AsTableType(); load_sample_info = zeek::id::find_type("load_sample_info")->AsTableType();
load_samples = new TableVal({NewRef{}, load_sample_info}); load_samples = new TableVal({zeek::NewRef{}, load_sample_info});
} }
SampleLogger::~SampleLogger() SampleLogger::~SampleLogger()
@ -354,13 +354,13 @@ SampleLogger::~SampleLogger()
void SampleLogger::FunctionSeen(const Func* func) void SampleLogger::FunctionSeen(const Func* func)
{ {
auto idx = make_intrusive<StringVal>(func->Name()); auto idx = zeek::make_intrusive<StringVal>(func->Name());
load_samples->Assign(std::move(idx), nullptr); load_samples->Assign(std::move(idx), nullptr);
} }
void SampleLogger::LocationSeen(const Location* loc) void SampleLogger::LocationSeen(const Location* loc)
{ {
auto idx = make_intrusive<StringVal>(loc->filename); auto idx = zeek::make_intrusive<StringVal>(loc->filename);
load_samples->Assign(std::move(idx), nullptr); load_samples->Assign(std::move(idx), nullptr);
} }
@ -370,9 +370,9 @@ void SampleLogger::SegmentProfile(const char* /* name */,
{ {
if ( load_sample ) if ( load_sample )
mgr.Enqueue(load_sample, mgr.Enqueue(load_sample,
IntrusivePtr{NewRef{}, load_samples}, zeek::IntrusivePtr{zeek::NewRef{}, load_samples},
make_intrusive<IntervalVal>(dtime, Seconds), zeek::make_intrusive<IntervalVal>(dtime, Seconds),
val_mgr->Int(dmem) val_mgr->Int(dmem)
); );
} }

View file

@ -133,7 +133,7 @@ void Stmt::AccessStats(ODesc* d) const
} }
} }
ExprListStmt::ExprListStmt(BroStmtTag t, IntrusivePtr<ListExpr> arg_l) ExprListStmt::ExprListStmt(BroStmtTag t, zeek::IntrusivePtr<ListExpr> 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, IntrusivePtr<ListExpr> arg_l)
ExprListStmt::~ExprListStmt() = default; ExprListStmt::~ExprListStmt() = default;
IntrusivePtr<Val> ExprListStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> 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 IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char* name) static zeek::IntrusivePtr<EnumVal> 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,26 +201,26 @@ static IntrusivePtr<EnumVal> lookup_enum_val(const char* module_name, const char
return et->GetVal(index); return et->GetVal(index);
} }
static void print_log(const std::vector<IntrusivePtr<Val>>& vals) static void print_log(const std::vector<zeek::IntrusivePtr<Val>>& 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");
auto record = make_intrusive<RecordVal>(lpli); auto record = zeek::make_intrusive<RecordVal>(lpli);
auto vec = make_intrusive<VectorVal>(zeek::id::string_vec); auto vec = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
for ( const auto& val : vals ) for ( const auto& val : vals )
{ {
ODesc d(DESC_READABLE); ODesc d(DESC_READABLE);
val->Describe(&d); val->Describe(&d);
vec->Assign(vec->Size(), make_intrusive<StringVal>(d.Description())); vec->Assign(vec->Size(), zeek::make_intrusive<StringVal>(d.Description()));
} }
record->Assign(0, make_intrusive<TimeVal>(network_time)); record->Assign(0, zeek::make_intrusive<TimeVal>(network_time));
record->Assign(1, std::move(vec)); record->Assign(1, std::move(vec));
log_mgr->Write(plval.get(), record.get()); log_mgr->Write(plval.get(), record.get());
} }
IntrusivePtr<Val> PrintStmt::DoExec(std::vector<IntrusivePtr<Val>> vals, zeek::IntrusivePtr<Val> PrintStmt::DoExec(std::vector<zeek::IntrusivePtr<Val>> vals,
stmt_flow_type& /* flow */) const stmt_flow_type& /* flow */) const
{ {
RegisterAccess(); RegisterAccess();
@ -290,7 +290,7 @@ IntrusivePtr<Val> PrintStmt::DoExec(std::vector<IntrusivePtr<Val>> vals,
return nullptr; return nullptr;
} }
ExprStmt::ExprStmt(IntrusivePtr<Expr> arg_e) : Stmt(STMT_EXPR), e(std::move(arg_e)) ExprStmt::ExprStmt(zeek::IntrusivePtr<Expr> 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(IntrusivePtr<Expr> arg_e) : Stmt(STMT_EXPR), e(std::move(arg_
SetLocationInfo(e->GetLocationInfo()); SetLocationInfo(e->GetLocationInfo());
} }
ExprStmt::ExprStmt(BroStmtTag t, IntrusivePtr<Expr> arg_e) : Stmt(t), e(std::move(arg_e)) ExprStmt::ExprStmt(BroStmtTag t, zeek::IntrusivePtr<Expr> 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, IntrusivePtr<Expr> arg_e) : Stmt(t), e(std::mov
ExprStmt::~ExprStmt() = default; ExprStmt::~ExprStmt() = default;
IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -319,7 +319,7 @@ IntrusivePtr<Val> ExprStmt::Exec(Frame* f, stmt_flow_type& flow) const
return nullptr; return nullptr;
} }
IntrusivePtr<Val> ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const zeek::IntrusivePtr<Val> ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& /* flow */) const
{ {
return nullptr; return nullptr;
} }
@ -365,8 +365,9 @@ TraversalCode ExprStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IfStmt::IfStmt(IntrusivePtr<Expr> test, IfStmt::IfStmt(zeek::IntrusivePtr<Expr> test,
IntrusivePtr<Stmt> arg_s1, IntrusivePtr<Stmt> arg_s2) zeek::IntrusivePtr<Stmt> arg_s1,
zeek::IntrusivePtr<Stmt> 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))
{ {
@ -380,7 +381,7 @@ IfStmt::IfStmt(IntrusivePtr<Expr> test,
IfStmt::~IfStmt() = default; IfStmt::~IfStmt() = default;
IntrusivePtr<Val> IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> 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();
@ -465,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(IntrusivePtr<ListExpr> arg_expr_cases, id_list* arg_type_cases, Case::Case(zeek::IntrusivePtr<ListExpr> arg_expr_cases, id_list* arg_type_cases,
IntrusivePtr<Stmt> arg_s) zeek::IntrusivePtr<Stmt> 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))
{ {
@ -583,14 +584,14 @@ static void int_del_func(void* v)
void SwitchStmt::Init() void SwitchStmt::Init()
{ {
auto t = make_intrusive<TypeList>(); auto t = zeek::make_intrusive<TypeList>();
t->Append(e->GetType()); t->Append(e->GetType());
comp_hash = new CompositeHash(std::move(t)); comp_hash = new CompositeHash(std::move(t));
case_label_value_map.SetDeleteFunc(int_del_func); case_label_value_map.SetDeleteFunc(int_del_func);
} }
SwitchStmt::SwitchStmt(IntrusivePtr<Expr> index, case_list* arg_cases) SwitchStmt::SwitchStmt(zeek::IntrusivePtr<Expr> 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)
{ {
@ -796,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);
} }
IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{ {
IntrusivePtr<Val> rval; zeek::IntrusivePtr<Val> rval;
auto m = FindCaseLabelMatch(v); auto m = FindCaseLabelMatch(v);
int matching_label_idx = m.first; int matching_label_idx = m.first;
@ -881,7 +882,7 @@ TraversalCode SwitchStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
AddStmt::AddStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_ADD, std::move(arg_e)) AddStmt::AddStmt(zeek::IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_ADD, std::move(arg_e))
{ {
if ( ! e->CanAdd() ) if ( ! e->CanAdd() )
Error("illegal add statement"); Error("illegal add statement");
@ -892,7 +893,7 @@ bool AddStmt::IsPure() const
return false; return false;
} }
IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> AddStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -914,7 +915,7 @@ TraversalCode AddStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
DelStmt::DelStmt(IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e)) DelStmt::DelStmt(zeek::IntrusivePtr<Expr> arg_e) : ExprStmt(STMT_DELETE, std::move(arg_e))
{ {
if ( e->IsError() ) if ( e->IsError() )
return; return;
@ -928,7 +929,7 @@ bool DelStmt::IsPure() const
return false; return false;
} }
IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> DelStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -949,12 +950,12 @@ TraversalCode DelStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
EventStmt::EventStmt(IntrusivePtr<EventExpr> arg_e) EventStmt::EventStmt(zeek::IntrusivePtr<EventExpr> arg_e)
: ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e)) : ExprStmt(STMT_EVENT, arg_e), event_expr(std::move(arg_e))
{ {
} }
IntrusivePtr<Val> EventStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> 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());
@ -980,8 +981,8 @@ TraversalCode EventStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
WhileStmt::WhileStmt(IntrusivePtr<Expr> arg_loop_condition, WhileStmt::WhileStmt(zeek::IntrusivePtr<Expr> arg_loop_condition,
IntrusivePtr<Stmt> arg_body) zeek::IntrusivePtr<Stmt> 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() &&
@ -1030,11 +1031,11 @@ TraversalCode WhileStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
IntrusivePtr<Val> rval; zeek::IntrusivePtr<Val> rval;
for ( ; ; ) for ( ; ; )
{ {
@ -1059,7 +1060,7 @@ IntrusivePtr<Val> WhileStmt::Exec(Frame* f, stmt_flow_type& flow) const
return rval; return rval;
} }
ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr) ForStmt::ForStmt(id_list* arg_loop_vars, zeek::IntrusivePtr<Expr> 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;
@ -1089,7 +1090,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
else else
{ {
add_local({NewRef{}, lv}, ind_type, INIT_NONE, add_local({zeek::NewRef{}, lv}, ind_type, INIT_NONE,
nullptr, nullptr, VAR_REGULAR); nullptr, nullptr, VAR_REGULAR);
} }
} }
@ -1106,7 +1107,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
const auto& t = (*loop_vars)[0]->GetType(); const auto& t = (*loop_vars)[0]->GetType();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT), add_local({zeek::NewRef{}, (*loop_vars)[0]}, base_type(TYPE_COUNT),
INIT_NONE, nullptr, nullptr, VAR_REGULAR); INIT_NONE, nullptr, nullptr, VAR_REGULAR);
else if ( ! IsIntegral(t->Tag()) ) else if ( ! IsIntegral(t->Tag()) )
@ -1127,7 +1128,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
const auto& t = (*loop_vars)[0]->GetType(); const auto& t = (*loop_vars)[0]->GetType();
if ( ! t ) if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, add_local({zeek::NewRef{}, (*loop_vars)[0]},
base_type(TYPE_STRING), base_type(TYPE_STRING),
INIT_NONE, nullptr, nullptr, VAR_REGULAR); INIT_NONE, nullptr, nullptr, VAR_REGULAR);
@ -1142,7 +1143,7 @@ ForStmt::ForStmt(id_list* arg_loop_vars, IntrusivePtr<Expr> loop_expr)
} }
ForStmt::ForStmt(id_list* arg_loop_vars, ForStmt::ForStmt(id_list* arg_loop_vars,
IntrusivePtr<Expr> loop_expr, IntrusivePtr<ID> val_var) zeek::IntrusivePtr<Expr> loop_expr, zeek::IntrusivePtr<ID> 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);
@ -1173,9 +1174,9 @@ ForStmt::~ForStmt()
delete loop_vars; delete loop_vars;
} }
IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
{ {
IntrusivePtr<Val> ret; zeek::IntrusivePtr<Val> ret;
if ( v->GetType()->Tag() == TYPE_TABLE ) if ( v->GetType()->Tag() == TYPE_TABLE )
{ {
@ -1247,7 +1248,7 @@ IntrusivePtr<Val> ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const
for ( int i = 0; i < sval->Len(); ++i ) for ( int i = 0; i < sval->Len(); ++i )
{ {
auto sv = make_intrusive<StringVal>(1, (const char*) sval->Bytes() + i); auto sv = zeek::make_intrusive<StringVal>(1, (const char*) sval->Bytes() + i);
f->SetElement((*loop_vars)[0], std::move(sv)); f->SetElement((*loop_vars)[0], std::move(sv));
flow = FLOW_NEXT; flow = FLOW_NEXT;
ret = body->Exec(f, flow); ret = body->Exec(f, flow);
@ -1331,7 +1332,7 @@ TraversalCode ForStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_LOOP; flow = FLOW_LOOP;
@ -1358,7 +1359,7 @@ TraversalCode NextStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_BREAK; flow = FLOW_BREAK;
@ -1385,7 +1386,7 @@ TraversalCode BreakStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_FALLTHROUGH; flow = FLOW_FALLTHROUGH;
@ -1412,7 +1413,7 @@ TraversalCode FallthroughStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
ReturnStmt::ReturnStmt(IntrusivePtr<Expr> arg_e) ReturnStmt::ReturnStmt(zeek::IntrusivePtr<Expr> arg_e)
: ExprStmt(STMT_RETURN, std::move(arg_e)) : ExprStmt(STMT_RETURN, std::move(arg_e))
{ {
Scope* s = current_scope(); Scope* s = current_scope();
@ -1456,7 +1457,7 @@ ReturnStmt::ReturnStmt(IntrusivePtr<Expr> arg_e)
} }
} }
IntrusivePtr<Val> ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> ReturnStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_RETURN; flow = FLOW_RETURN;
@ -1495,7 +1496,7 @@ StmtList::~StmtList()
Unref(stmt); Unref(stmt);
} }
IntrusivePtr<Val> StmtList::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> StmtList::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1574,7 +1575,7 @@ TraversalCode StmtList::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> EventBodyList::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1632,7 +1633,7 @@ void EventBodyList::Describe(ODesc* d) const
StmtList::Describe(d); StmtList::Describe(d);
} }
InitStmt::InitStmt(std::vector<IntrusivePtr<ID>> arg_inits) : Stmt(STMT_INIT) InitStmt::InitStmt(std::vector<zeek::IntrusivePtr<ID>> arg_inits) : Stmt(STMT_INIT)
{ {
inits = std::move(arg_inits); inits = std::move(arg_inits);
@ -1640,7 +1641,7 @@ InitStmt::InitStmt(std::vector<IntrusivePtr<ID>> arg_inits) : Stmt(STMT_INIT)
SetLocationInfo(inits[0]->GetLocationInfo()); SetLocationInfo(inits[0]->GetLocationInfo());
} }
IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1649,18 +1650,18 @@ IntrusivePtr<Val> InitStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
const auto& t = aggr->GetType(); const auto& t = aggr->GetType();
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> v;
switch ( t->Tag() ) { switch ( t->Tag() ) {
case TYPE_RECORD: case TYPE_RECORD:
v = make_intrusive<RecordVal>(cast_intrusive<RecordType>(t)); v = zeek::make_intrusive<RecordVal>(zeek::cast_intrusive<RecordType>(t));
break; break;
case TYPE_VECTOR: case TYPE_VECTOR:
v = make_intrusive<VectorVal>(cast_intrusive<VectorType>(t)); v = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<VectorType>(t));
break; break;
case TYPE_TABLE: case TYPE_TABLE:
v = make_intrusive<TableVal>(cast_intrusive<TableType>(t), v = zeek::make_intrusive<TableVal>(zeek::cast_intrusive<TableType>(t),
aggr->GetAttrs()); aggr->GetAttrs());
break; break;
default: default:
break; break;
@ -1705,7 +1706,7 @@ TraversalCode InitStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
IntrusivePtr<Val> NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;
@ -1734,9 +1735,9 @@ TraversalCode NullStmt::Traverse(TraversalCallback* cb) const
HANDLE_TC_STMT_POST(tc); HANDLE_TC_STMT_POST(tc);
} }
WhenStmt::WhenStmt(IntrusivePtr<Expr> arg_cond, WhenStmt::WhenStmt(zeek::IntrusivePtr<Expr> arg_cond,
IntrusivePtr<Stmt> arg_s1, IntrusivePtr<Stmt> arg_s2, zeek::IntrusivePtr<Stmt> arg_s1, zeek::IntrusivePtr<Stmt> arg_s2,
IntrusivePtr<Expr> arg_timeout, bool arg_is_return) zeek::IntrusivePtr<Expr> 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)
@ -1760,7 +1761,7 @@ WhenStmt::WhenStmt(IntrusivePtr<Expr> arg_cond,
WhenStmt::~WhenStmt() = default; WhenStmt::~WhenStmt() = default;
IntrusivePtr<Val> WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const zeek::IntrusivePtr<Val> WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const
{ {
RegisterAccess(); RegisterAccess();
flow = FLOW_NEXT; flow = FLOW_NEXT;

View file

@ -29,7 +29,7 @@ public:
~Stmt() override; ~Stmt() override;
virtual IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const = 0; virtual zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const = 0;
Stmt* Ref() { ::Ref(this); return this; } Stmt* Ref() { ::Ref(this); return this; }
@ -93,17 +93,17 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
ExprListStmt(BroStmtTag t, IntrusivePtr<ListExpr> arg_l); ExprListStmt(BroStmtTag t, zeek::IntrusivePtr<ListExpr> arg_l);
~ExprListStmt() override; ~ExprListStmt() override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
virtual IntrusivePtr<Val> DoExec(std::vector<IntrusivePtr<Val>> vals, virtual zeek::IntrusivePtr<Val> DoExec(std::vector<zeek::IntrusivePtr<Val>> 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;
IntrusivePtr<ListExpr> l; zeek::IntrusivePtr<ListExpr> l;
}; };
class PrintStmt final : public ExprListStmt { class PrintStmt final : public ExprListStmt {
@ -112,16 +112,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:
IntrusivePtr<Val> DoExec(std::vector<IntrusivePtr<Val>> vals, zeek::IntrusivePtr<Val> DoExec(std::vector<zeek::IntrusivePtr<Val>> 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(IntrusivePtr<Expr> e); explicit ExprStmt(zeek::IntrusivePtr<Expr> e);
~ExprStmt() override; ~ExprStmt() override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +130,18 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
ExprStmt(BroStmtTag t, IntrusivePtr<Expr> e); ExprStmt(BroStmtTag t, zeek::IntrusivePtr<Expr> e);
virtual IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const; virtual zeek::IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const;
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Expr> e; zeek::IntrusivePtr<Expr> e;
}; };
class IfStmt final : public ExprStmt { class IfStmt final : public ExprStmt {
public: public:
IfStmt(IntrusivePtr<Expr> test, IntrusivePtr<Stmt> s1, IntrusivePtr<Stmt> s2); IfStmt(zeek::IntrusivePtr<Expr> test, zeek::IntrusivePtr<Stmt> s1, zeek::IntrusivePtr<Stmt> s2);
~IfStmt() override; ~IfStmt() override;
const Stmt* TrueBranch() const { return s1.get(); } const Stmt* TrueBranch() const { return s1.get(); }
@ -152,16 +152,16 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Stmt> s1; zeek::IntrusivePtr<Stmt> s1;
IntrusivePtr<Stmt> s2; zeek::IntrusivePtr<Stmt> s2;
}; };
class Case final : public BroObj { class Case final : public BroObj {
public: public:
Case(IntrusivePtr<ListExpr> c, id_list* types, IntrusivePtr<Stmt> arg_s); Case(zeek::IntrusivePtr<ListExpr> c, id_list* types, zeek::IntrusivePtr<Stmt> arg_s);
~Case() override; ~Case() override;
const ListExpr* ExprCases() const { return expr_cases.get(); } const ListExpr* ExprCases() const { return expr_cases.get(); }
@ -178,16 +178,16 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const; TraversalCode Traverse(TraversalCallback* cb) const;
protected: protected:
IntrusivePtr<ListExpr> expr_cases; zeek::IntrusivePtr<ListExpr> expr_cases;
id_list* type_cases; id_list* type_cases;
IntrusivePtr<Stmt> s; zeek::IntrusivePtr<Stmt> s;
}; };
using case_list = PList<Case>; using case_list = PList<Case>;
class SwitchStmt final : public ExprStmt { class SwitchStmt final : public ExprStmt {
public: public:
SwitchStmt(IntrusivePtr<Expr> index, case_list* cases); SwitchStmt(zeek::IntrusivePtr<Expr> index, case_list* cases);
~SwitchStmt() override; ~SwitchStmt() override;
const case_list* Cases() const { return cases; } const case_list* Cases() const { return cases; }
@ -197,7 +197,7 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +228,40 @@ protected:
class AddStmt final : public ExprStmt { class AddStmt final : public ExprStmt {
public: public:
explicit AddStmt(IntrusivePtr<Expr> e); explicit AddStmt(zeek::IntrusivePtr<Expr> e);
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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(IntrusivePtr<Expr> e); explicit DelStmt(zeek::IntrusivePtr<Expr> e);
bool IsPure() const override; bool IsPure() const override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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(IntrusivePtr<EventExpr> e); explicit EventStmt(zeek::IntrusivePtr<EventExpr> e);
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<EventExpr> event_expr; zeek::IntrusivePtr<EventExpr> event_expr;
}; };
class WhileStmt final : public Stmt { class WhileStmt final : public Stmt {
public: public:
WhileStmt(IntrusivePtr<Expr> loop_condition, IntrusivePtr<Stmt> body); WhileStmt(zeek::IntrusivePtr<Expr> loop_condition, zeek::IntrusivePtr<Stmt> body);
~WhileStmt() override; ~WhileStmt() override;
bool IsPure() const override; bool IsPure() const override;
@ -271,20 +271,20 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
IntrusivePtr<Expr> loop_condition; zeek::IntrusivePtr<Expr> loop_condition;
IntrusivePtr<Stmt> body; zeek::IntrusivePtr<Stmt> body;
}; };
class ForStmt final : public ExprStmt { class ForStmt final : public ExprStmt {
public: public:
ForStmt(id_list* loop_vars, IntrusivePtr<Expr> loop_expr); ForStmt(id_list* loop_vars, zeek::IntrusivePtr<Expr> loop_expr);
// Special constructor for key value for loop. // Special constructor for key value for loop.
ForStmt(id_list* loop_vars, IntrusivePtr<Expr> loop_expr, IntrusivePtr<ID> val_var); ForStmt(id_list* loop_vars, zeek::IntrusivePtr<Expr> loop_expr, zeek::IntrusivePtr<ID> val_var);
~ForStmt() override; ~ForStmt() override;
void AddBody(IntrusivePtr<Stmt> arg_body) { body = std::move(arg_body); } void AddBody(zeek::IntrusivePtr<Stmt> 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 +297,20 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override;
id_list* loop_vars; id_list* loop_vars;
IntrusivePtr<Stmt> body; zeek::IntrusivePtr<Stmt> 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.
IntrusivePtr<ID> value_var; zeek::IntrusivePtr<ID> value_var;
}; };
class NextStmt final : public Stmt { class NextStmt final : public Stmt {
public: public:
NextStmt() : Stmt(STMT_NEXT) { } NextStmt() : Stmt(STMT_NEXT) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +324,7 @@ class BreakStmt final : public Stmt {
public: public:
BreakStmt() : Stmt(STMT_BREAK) { } BreakStmt() : Stmt(STMT_BREAK) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +338,7 @@ class FallthroughStmt final : public Stmt {
public: public:
FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { } FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +350,9 @@ protected:
class ReturnStmt final : public ExprStmt { class ReturnStmt final : public ExprStmt {
public: public:
explicit ReturnStmt(IntrusivePtr<Expr> e); explicit ReturnStmt(zeek::IntrusivePtr<Expr> e);
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
}; };
@ -362,7 +362,7 @@ public:
StmtList(); StmtList();
~StmtList() override; ~StmtList() override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +382,7 @@ public:
EventBodyList() : StmtList() EventBodyList() : StmtList()
{ topmost = false; tag = STMT_EVENT_BODY_LIST; } { topmost = false; tag = STMT_EVENT_BODY_LIST; }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -396,11 +396,11 @@ protected:
class InitStmt final : public Stmt { class InitStmt final : public Stmt {
public: public:
explicit InitStmt(std::vector<IntrusivePtr<ID>> arg_inits); explicit InitStmt(std::vector<zeek::IntrusivePtr<ID>> arg_inits);
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override;
const std::vector<IntrusivePtr<ID>>& Inits() const const std::vector<zeek::IntrusivePtr<ID>>& Inits() const
{ return inits; } { return inits; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -408,14 +408,14 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
std::vector<IntrusivePtr<ID>> inits; std::vector<zeek::IntrusivePtr<ID>> inits;
}; };
class NullStmt final : public Stmt { class NullStmt final : public Stmt {
public: public:
NullStmt() : Stmt(STMT_NULL) { } NullStmt() : Stmt(STMT_NULL) { }
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +426,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(IntrusivePtr<Expr> cond, WhenStmt(zeek::IntrusivePtr<Expr> cond,
IntrusivePtr<Stmt> s1, IntrusivePtr<Stmt> s2, zeek::IntrusivePtr<Stmt> s1, zeek::IntrusivePtr<Stmt> s2,
IntrusivePtr<Expr> timeout, bool is_return); zeek::IntrusivePtr<Expr> timeout, bool is_return);
~WhenStmt() override; ~WhenStmt() override;
IntrusivePtr<Val> Exec(Frame* f, stmt_flow_type& flow) const override; zeek::IntrusivePtr<Val> 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 +444,10 @@ public:
TraversalCode Traverse(TraversalCallback* cb) const override; TraversalCode Traverse(TraversalCallback* cb) const override;
protected: protected:
IntrusivePtr<Expr> cond; zeek::IntrusivePtr<Expr> cond;
IntrusivePtr<Stmt> s1; zeek::IntrusivePtr<Stmt> s1;
IntrusivePtr<Stmt> s2; zeek::IntrusivePtr<Stmt> s2;
IntrusivePtr<Expr> timeout; zeek::IntrusivePtr<Expr> timeout;
bool is_return; bool is_return;
}; };

View file

@ -4,7 +4,7 @@
#include "Val.h" #include "Val.h"
#include "IntrusivePtr.h" #include "IntrusivePtr.h"
Tag::Tag(const IntrusivePtr<zeek::EnumType>& etype, type_t arg_type, subtype_t arg_subtype) Tag::Tag(const zeek::IntrusivePtr<zeek::EnumType>& etype, type_t arg_type, subtype_t arg_subtype)
{ {
assert(arg_type > 0); assert(arg_type > 0);
@ -15,10 +15,10 @@ Tag::Tag(const IntrusivePtr<zeek::EnumType>& etype, type_t arg_type, subtype_t a
} }
Tag::Tag(zeek::EnumType* etype, type_t arg_type, subtype_t arg_subtype) Tag::Tag(zeek::EnumType* etype, type_t arg_type, subtype_t arg_subtype)
: Tag({NewRef{}, etype}, arg_type, arg_subtype) : Tag({zeek::NewRef{}, etype}, arg_type, arg_subtype)
{ } { }
Tag::Tag(IntrusivePtr<EnumVal> arg_val) Tag::Tag(zeek::IntrusivePtr<EnumVal> arg_val)
{ {
assert(arg_val); assert(arg_val);
@ -30,7 +30,7 @@ Tag::Tag(IntrusivePtr<EnumVal> arg_val)
} }
Tag::Tag(EnumVal* arg_val) Tag::Tag(EnumVal* arg_val)
: Tag({NewRef{}, arg_val}) : Tag({zeek::NewRef{}, arg_val})
{ } { }
Tag::Tag(const Tag& other) Tag::Tag(const Tag& other)
@ -73,7 +73,7 @@ Tag& Tag::operator=(const Tag&& other) noexcept
return *this; return *this;
} }
const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<zeek::EnumType>& etype) const const zeek::IntrusivePtr<EnumVal>& Tag::AsVal(const zeek::IntrusivePtr<zeek::EnumType>& etype) const
{ {
if ( ! val ) if ( ! val )
{ {
@ -86,7 +86,7 @@ const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<zeek::EnumType>& etyp
EnumVal* Tag::AsEnumVal(zeek::EnumType* etype) const EnumVal* Tag::AsEnumVal(zeek::EnumType* etype) const
{ {
return AsVal({NewRef{}, etype}).get(); return AsVal({zeek::NewRef{}, etype}).get();
} }
std::string Tag::AsString() const std::string Tag::AsString() const

View file

@ -116,7 +116,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 IntrusivePtr<EnumVal>& AsVal(const IntrusivePtr<zeek::EnumType>& etype) const; const zeek::IntrusivePtr<EnumVal>& AsVal(const zeek::IntrusivePtr<zeek::EnumType>& 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,9 +132,9 @@ 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 IntrusivePtr<zeek::EnumType>& etype, type_t type, subtype_t subtype = 0); Tag(const zeek::IntrusivePtr<zeek::EnumType>& etype, type_t type, subtype_t subtype = 0);
[[deprecated("Remove in v4.1. Construct from 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,13 +142,13 @@ 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(IntrusivePtr<EnumVal> val); explicit Tag(zeek::IntrusivePtr<EnumVal> val);
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from zeek::IntrusivePtr instead.")]]
explicit Tag(EnumVal* val); explicit Tag(EnumVal* val);
private: private:
type_t type; // Main type. type_t type; // Main type.
subtype_t subtype; // Subtype. subtype_t subtype; // Subtype.
mutable IntrusivePtr<EnumVal> val; // Script-layer value. mutable zeek::IntrusivePtr<EnumVal> 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();
} }
IntrusivePtr<Val> timeout_val; zeek::IntrusivePtr<Val> timeout_val;
if ( arg_timeout ) if ( arg_timeout )
{ {
@ -262,9 +262,9 @@ bool Trigger::Eval()
return false; return false;
} }
f->SetTrigger({NewRef{}, this}); f->SetTrigger({zeek::NewRef{}, this});
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> v;
try try
{ {
@ -348,8 +348,8 @@ void Trigger::Timeout()
if ( timeout_stmts ) if ( timeout_stmts )
{ {
stmt_flow_type flow; stmt_flow_type flow;
IntrusivePtr<Frame> f{AdoptRef{}, frame->Clone()}; zeek::IntrusivePtr<Frame> f{zeek::AdoptRef{}, frame->Clone()};
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> v;
try try
{ {

View file

@ -16,19 +16,19 @@ EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t)
} }
} }
IntrusivePtr<RecordVal> EncapsulatingConn::ToVal() const zeek::IntrusivePtr<RecordVal> EncapsulatingConn::ToVal() const
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::Tunnel::EncapsulatingConn); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::Tunnel::EncapsulatingConn);
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id); auto id_val = zeek::make_intrusive<RecordVal>(zeek::id::conn_id);
id_val->Assign(0, make_intrusive<AddrVal>(src_addr)); id_val->Assign(0, zeek::make_intrusive<AddrVal>(src_addr));
id_val->Assign(1, val_mgr->Port(ntohs(src_port), proto)); id_val->Assign(1, val_mgr->Port(ntohs(src_port), proto));
id_val->Assign(2, make_intrusive<AddrVal>(dst_addr)); id_val->Assign(2, zeek::make_intrusive<AddrVal>(dst_addr));
id_val->Assign(3, val_mgr->Port(ntohs(dst_port), proto)); id_val->Assign(3, val_mgr->Port(ntohs(dst_port), proto));
rv->Assign(0, std::move(id_val)); rv->Assign(0, std::move(id_val));
rv->Assign(1, zeek::BifType::Enum::Tunnel::Type->GetVal(type)); rv->Assign(1, zeek::BifType::Enum::Tunnel::Type->GetVal(type));
rv->Assign(2, make_intrusive<StringVal>(uid.Base62("C").c_str())); rv->Assign(2, zeek::make_intrusive<StringVal>(uid.Base62("C").c_str()));
return rv; return rv;
} }

View file

@ -81,7 +81,7 @@ public:
/** /**
* Returns record value of type "EncapsulatingConn" representing the tunnel. * Returns record value of type "EncapsulatingConn" representing the tunnel.
*/ */
IntrusivePtr<RecordVal> ToVal() const; zeek::IntrusivePtr<RecordVal> 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,9 +196,9 @@ 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.
*/ */
IntrusivePtr<VectorVal> ToVal() const zeek::IntrusivePtr<VectorVal> ToVal() const
{ {
auto vv = make_intrusive<VectorVal>( auto vv = zeek::make_intrusive<VectorVal>(
zeek::id::find_type<zeek::VectorType>("EncapsulatingConnVector")); zeek::id::find_type<zeek::VectorType>("EncapsulatingConnVector"));
if ( conns ) if ( conns )

View file

@ -71,7 +71,7 @@ Type::Type(zeek::TypeTag t, bool arg_base_type)
{ {
} }
IntrusivePtr<Type> Type::ShallowClone() zeek::IntrusivePtr<Type> Type::ShallowClone()
{ {
switch ( tag ) { switch ( tag ) {
case TYPE_VOID: case TYPE_VOID:
@ -89,7 +89,7 @@ IntrusivePtr<Type> Type::ShallowClone()
case TYPE_ADDR: case TYPE_ADDR:
case TYPE_SUBNET: case TYPE_SUBNET:
case TYPE_ANY: case TYPE_ANY:
return make_intrusive<Type>(tag, base_type); return zeek::make_intrusive<Type>(tag, base_type);
default: default:
reporter->InternalError("cloning illegal base Type"); reporter->InternalError("cloning illegal base Type");
@ -111,7 +111,7 @@ int Type::MatchesIndex(zeek::detail::ListExpr* const index) const
return DOES_NOT_MATCH_INDEX; return DOES_NOT_MATCH_INDEX;
} }
const IntrusivePtr<Type>& Type::Yield() const const zeek::IntrusivePtr<Type>& 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(IntrusivePtr<Type> t) void TypeList::Append(zeek::IntrusivePtr<Type> 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(IntrusivePtr<Type> t)
types.emplace_back(std::move(t)); types.emplace_back(std::move(t));
} }
void TypeList::AppendEvenIfNotPure(IntrusivePtr<Type> t) void TypeList::AppendEvenIfNotPure(zeek::IntrusivePtr<Type> 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(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield) TableType::TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield)
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield)) : IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
{ {
if ( ! indices ) if ( ! indices )
@ -344,9 +344,9 @@ TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield)
} }
} }
IntrusivePtr<Type> TableType::ShallowClone() zeek::IntrusivePtr<Type> TableType::ShallowClone()
{ {
return make_intrusive<TableType>(indices, yield_type); return zeek::make_intrusive<TableType>(indices, yield_type);
} }
bool TableType::IsUnspecifiedTable() const bool TableType::IsUnspecifiedTable() const
@ -355,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const
return indices->GetTypes().empty(); return indices->GetTypes().empty();
} }
SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements) SetType::SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> 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,8 +378,8 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr
else if ( tl.size() == 1 ) else if ( tl.size() == 1 )
{ {
IntrusivePtr<Type> ft{NewRef{}, flatten_type(tl[0].get())}; zeek::IntrusivePtr<Type> ft{zeek::NewRef{}, flatten_type(tl[0].get())};
indices = make_intrusive<TypeList>(ft); indices = zeek::make_intrusive<TypeList>(ft);
indices->Append(std::move(ft)); indices->Append(std::move(ft));
} }
@ -396,24 +396,24 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr
return; return;
} }
indices = make_intrusive<TypeList>(t); indices = zeek::make_intrusive<TypeList>(t);
indices->Append(std::move(t)); indices->Append(std::move(t));
} }
} }
} }
} }
IntrusivePtr<Type> SetType::ShallowClone() zeek::IntrusivePtr<Type> SetType::ShallowClone()
{ {
return make_intrusive<SetType>(indices, elements); return zeek::make_intrusive<SetType>(indices, elements);
} }
SetType::~SetType() = default; SetType::~SetType() = default;
FuncType::FuncType(IntrusivePtr<RecordType> arg_args, FuncType::FuncType(zeek::IntrusivePtr<RecordType> arg_args,
IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor) zeek::IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor)
: Type(TYPE_FUNC), args(std::move(arg_args)), : Type(TYPE_FUNC), args(std::move(arg_args)),
arg_types(make_intrusive<TypeList>()), yield(std::move(arg_yield)) arg_types(zeek::make_intrusive<TypeList>()), yield(std::move(arg_yield))
{ {
flavor = arg_flavor; flavor = arg_flavor;
@ -441,9 +441,9 @@ FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
prototypes.emplace_back(Prototype{false, args, std::move(offsets)}); prototypes.emplace_back(Prototype{false, args, std::move(offsets)});
} }
IntrusivePtr<Type> FuncType::ShallowClone() zeek::IntrusivePtr<Type> FuncType::ShallowClone()
{ {
auto f = make_intrusive<FuncType>(); auto f = zeek::make_intrusive<FuncType>();
f->args = args; f->args = args;
f->arg_types = arg_types; f->arg_types = arg_types;
f->yield = yield; f->yield = yield;
@ -481,16 +481,16 @@ 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<IntrusivePtr<Type>> as; std::vector<zeek::IntrusivePtr<Type>> as;
as.reserve(args->length()); as.reserve(args->length());
for ( auto a : *args ) for ( auto a : *args )
as.emplace_back(NewRef{}, a); as.emplace_back(zeek::NewRef{}, a);
return CheckArgs(as, is_init); return CheckArgs(as, is_init);
} }
bool FuncType::CheckArgs(const std::vector<IntrusivePtr<Type>>& args, bool FuncType::CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& 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,8 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
return {}; return {};
} }
TypeDecl::TypeDecl(const char* i, IntrusivePtr<Type> t, TypeDecl::TypeDecl(const char* i, zeek::IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> 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,12 +658,12 @@ 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.
IntrusivePtr<Type> RecordType::ShallowClone() zeek::IntrusivePtr<Type> RecordType::ShallowClone()
{ {
auto pass = new type_decl_list(); auto pass = new type_decl_list();
for ( const auto& type : *types ) for ( const auto& type : *types )
pass->push_back(new TypeDecl(*type)); pass->push_back(new TypeDecl(*type));
return make_intrusive<RecordType>(pass); return zeek::make_intrusive<RecordType>(pass);
} }
RecordType::~RecordType() RecordType::~RecordType()
@ -682,7 +682,7 @@ bool RecordType::HasField(const char* field) const
return FieldOffset(field) >= 0; return FieldOffset(field) >= 0;
} }
IntrusivePtr<Val> RecordType::FieldDefault(int field) const zeek::IntrusivePtr<Val> RecordType::FieldDefault(int field) const
{ {
const TypeDecl* td = FieldDecl(field); const TypeDecl* td = FieldDecl(field);
@ -794,31 +794,31 @@ static string container_type_name(const Type* ft)
return s; return s;
} }
IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv) const zeek::IntrusivePtr<TableVal> 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");
auto rval = make_intrusive<TableVal>(record_field_table); auto rval = zeek::make_intrusive<TableVal>(record_field_table);
for ( int i = 0; i < NumFields(); ++i ) for ( int i = 0; i < NumFields(); ++i )
{ {
const auto& ft = GetFieldType(i); const auto& ft = GetFieldType(i);
const TypeDecl* fd = FieldDecl(i); const TypeDecl* fd = FieldDecl(i);
IntrusivePtr<Val> fv; zeek::IntrusivePtr<Val> fv;
if ( rv ) if ( rv )
fv = rv->GetField(i); fv = rv->GetField(i);
bool logged = (fd->attrs && fd->GetAttr(zeek::detail::ATTR_LOG) != nullptr); bool logged = (fd->attrs && fd->GetAttr(zeek::detail::ATTR_LOG) != nullptr);
auto nr = make_intrusive<RecordVal>(record_field); auto nr = zeek::make_intrusive<RecordVal>(record_field);
string s = container_type_name(ft.get()); string s = container_type_name(ft.get());
nr->Assign(0, make_intrusive<StringVal>(s)); nr->Assign(0, zeek::make_intrusive<StringVal>(s));
nr->Assign(1, val_mgr->Bool(logged)); nr->Assign(1, val_mgr->Bool(logged));
nr->Assign(2, std::move(fv)); nr->Assign(2, std::move(fv));
nr->Assign(3, FieldDefault(i)); nr->Assign(3, FieldDefault(i));
auto field_name = make_intrusive<StringVal>(FieldName(i)); auto field_name = zeek::make_intrusive<StringVal>(FieldName(i));
rval->Assign(std::move(field_name), std::move(nr)); rval->Assign(std::move(field_name), std::move(nr));
} }
@ -845,9 +845,9 @@ const char* RecordType::AddFields(const type_decl_list& others,
if ( add_log_attr ) if ( add_log_attr )
{ {
if ( ! td->attrs ) if ( ! td->attrs )
td->attrs = make_intrusive<zeek::detail::Attributes>(td->type, true, false); td->attrs = zeek::make_intrusive<zeek::detail::Attributes>(td->type, true, false);
td->attrs->AddAttr(make_intrusive<zeek::detail::Attr>(zeek::detail::ATTR_LOG)); td->attrs->AddAttr(zeek::make_intrusive<zeek::detail::Attr>(zeek::detail::ATTR_LOG));
} }
types->push_back(td); types->push_back(td);
@ -1028,7 +1028,7 @@ void SubNetType::Describe(ODesc* d) const
d->Add(int(Tag())); d->Add(int(Tag()));
} }
FileType::FileType(IntrusivePtr<Type> yield_type) FileType::FileType(zeek::IntrusivePtr<Type> yield_type)
: Type(TYPE_FILE), yield(std::move(yield_type)) : Type(TYPE_FILE), yield(std::move(yield_type))
{ {
} }
@ -1083,12 +1083,12 @@ EnumType::EnumType(const EnumType* e)
SetName(e->GetName()); SetName(e->GetName());
} }
IntrusivePtr<Type> EnumType::ShallowClone() zeek::IntrusivePtr<Type> EnumType::ShallowClone()
{ {
if ( counter == 0 ) if ( counter == 0 )
return make_intrusive<EnumType>(GetName()); return zeek::make_intrusive<EnumType>(GetName());
return make_intrusive<EnumType>(this); return zeek::make_intrusive<EnumType>(this);
} }
EnumType::~EnumType() = default; EnumType::~EnumType() = default;
@ -1137,11 +1137,11 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
if ( ! id ) if ( ! id )
{ {
id = install_ID(name, module_name.c_str(), true, is_export); id = install_ID(name, module_name.c_str(), true, is_export);
id->SetType({NewRef{}, this}); id->SetType({zeek::NewRef{}, this});
id->SetEnumConst(); id->SetEnumConst();
if ( deprecation ) if ( deprecation )
id->MakeDeprecated({NewRef{}, deprecation}); id->MakeDeprecated({zeek::NewRef{}, deprecation});
zeekygen_mgr->Identifier(std::move(id)); zeekygen_mgr->Identifier(std::move(id));
} }
@ -1164,7 +1164,7 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
AddNameInternal(module_name, name, val, is_export); AddNameInternal(module_name, name, val, is_export);
if ( vals.find(val) == vals.end() ) if ( vals.find(val) == vals.end() )
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val); vals[val] = zeek::make_intrusive<EnumVal>(zeek::IntrusivePtr{zeek::NewRef{}, this}, val);
set<Type*> types = Type::GetAliases(GetName()); set<Type*> types = Type::GetAliases(GetName());
set<Type*>::const_iterator it; set<Type*>::const_iterator it;
@ -1213,13 +1213,13 @@ EnumType::enum_name_list EnumType::Names() const
return n; return n;
} }
const IntrusivePtr<EnumVal>& EnumType::GetVal(bro_int_t i) const zeek::IntrusivePtr<EnumVal>& EnumType::GetVal(bro_int_t i)
{ {
auto it = vals.find(i); auto it = vals.find(i);
if ( it == vals.end() ) if ( it == vals.end() )
{ {
auto ev = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, i); auto ev = zeek::make_intrusive<EnumVal>(zeek::IntrusivePtr{zeek::NewRef{}, this}, i);
return vals.emplace(i, std::move(ev)).first->second; return vals.emplace(i, std::move(ev)).first->second;
} }
@ -1303,19 +1303,19 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
} }
} }
VectorType::VectorType(IntrusivePtr<Type> element_type) VectorType::VectorType(zeek::IntrusivePtr<Type> element_type)
: Type(TYPE_VECTOR), yield_type(std::move(element_type)) : Type(TYPE_VECTOR), yield_type(std::move(element_type))
{ {
} }
IntrusivePtr<Type> VectorType::ShallowClone() zeek::IntrusivePtr<Type> VectorType::ShallowClone()
{ {
return make_intrusive<VectorType>(yield_type); return zeek::make_intrusive<VectorType>(yield_type);
} }
VectorType::~VectorType() = default; VectorType::~VectorType() = default;
const IntrusivePtr<Type>& VectorType::Yield() const const zeek::IntrusivePtr<Type>& 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 +1684,8 @@ TypeTag max_type(TypeTag t1, TypeTag t2)
} }
} }
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1, zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& arg_t1,
const IntrusivePtr<Type>& arg_t2) const zeek::IntrusivePtr<Type>& arg_t2)
{ {
auto t1 = arg_t1.get(); auto t1 = arg_t1.get();
auto t2 = arg_t2.get(); auto t2 = arg_t2.get();
@ -1758,7 +1758,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const auto& tl1 = it1->GetIndexTypes(); const auto& tl1 = it1->GetIndexTypes();
const auto& tl2 = it2->GetIndexTypes(); const auto& tl2 = it2->GetIndexTypes();
IntrusivePtr<TypeList> tl3; zeek::IntrusivePtr<TypeList> tl3;
if ( tl1.size() != tl2.size() ) if ( tl1.size() != tl2.size() )
{ {
@ -1766,7 +1766,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr; return nullptr;
} }
tl3 = make_intrusive<TypeList>(); tl3 = zeek::make_intrusive<TypeList>();
for ( auto i = 0u; i < tl1.size(); ++i ) for ( auto i = 0u; i < tl1.size(); ++i )
{ {
@ -1779,7 +1779,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const auto& y1 = t1->Yield(); const auto& y1 = t1->Yield();
const auto& y2 = t2->Yield(); const auto& y2 = t2->Yield();
IntrusivePtr<Type> y3; zeek::IntrusivePtr<Type> y3;
if ( y1 || y2 ) if ( y1 || y2 )
{ {
@ -1795,9 +1795,9 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
} }
if ( t1->IsSet() ) if ( t1->IsSet() )
return make_intrusive<SetType>(std::move(tl3), nullptr); return zeek::make_intrusive<SetType>(std::move(tl3), nullptr);
else else
return make_intrusive<TableType>(std::move(tl3), std::move(y3)); return zeek::make_intrusive<TableType>(std::move(tl3), std::move(y3));
} }
case TYPE_FUNC: case TYPE_FUNC:
@ -1810,12 +1810,12 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const FuncType* ft1 = (const FuncType*) t1; const FuncType* ft1 = (const FuncType*) t1;
const FuncType* ft2 = (const FuncType*) t1; const FuncType* ft2 = (const FuncType*) t1;
auto args = cast_intrusive<RecordType>(merge_types(ft1->Params(), auto args = zeek::cast_intrusive<RecordType>(merge_types(ft1->Params(),
ft2->Params())); ft2->Params()));
auto yield = t1->Yield() ? auto yield = t1->Yield() ?
merge_types(t1->Yield(), t2->Yield()) : nullptr; merge_types(t1->Yield(), t2->Yield()) : nullptr;
return make_intrusive<FuncType>(std::move(args), std::move(yield), return zeek::make_intrusive<FuncType>(std::move(args), std::move(yield),
ft1->Flavor()); ft1->Flavor());
} }
@ -1845,7 +1845,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
tdl3->push_back(new TypeDecl(copy_string(td1->id), std::move(tdl3_i))); tdl3->push_back(new TypeDecl(copy_string(td1->id), std::move(tdl3_i)));
} }
return make_intrusive<RecordType>(tdl3); return zeek::make_intrusive<RecordType>(tdl3);
} }
case TYPE_LIST: case TYPE_LIST:
@ -1888,7 +1888,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr; return nullptr;
} }
auto tl3 = make_intrusive<TypeList>(); auto tl3 = zeek::make_intrusive<TypeList>();
for ( auto i = 0u; i < l1.size(); ++i ) for ( auto i = 0u; i < l1.size(); ++i )
tl3->Append(merge_types(l1[i], l2[i])); tl3->Append(merge_types(l1[i], l2[i]));
@ -1903,7 +1903,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr; return nullptr;
} }
return make_intrusive<VectorType>(merge_types(t1->Yield(), t2->Yield())); return zeek::make_intrusive<VectorType>(merge_types(t1->Yield(), t2->Yield()));
case TYPE_FILE: case TYPE_FILE:
if ( ! same_type(t1->Yield(), t2->Yield()) ) if ( ! same_type(t1->Yield(), t2->Yield()) )
@ -1912,7 +1912,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
return nullptr; return nullptr;
} }
return make_intrusive<FileType>(merge_types(t1->Yield(), t2->Yield())); return zeek::make_intrusive<FileType>(merge_types(t1->Yield(), t2->Yield()));
case TYPE_UNION: case TYPE_UNION:
reporter->InternalError("union type in merge_types()"); reporter->InternalError("union type in merge_types()");
@ -1924,7 +1924,7 @@ IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
} }
} }
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements) zeek::IntrusivePtr<Type> 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 +1969,7 @@ static Type* reduce_type(Type* t)
return t; return t;
} }
IntrusivePtr<Type> init_type(zeek::detail::Expr* init) zeek::IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
{ {
if ( init->Tag() != zeek::detail::EXPR_LIST ) if ( init->Tag() != zeek::detail::EXPR_LIST )
{ {
@ -2008,7 +2008,7 @@ IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
auto t = e0->InitType(); auto t = e0->InitType();
if ( t ) if ( t )
t = {NewRef{}, reduce_type(t.get())}; t = {zeek::NewRef{}, reduce_type(t.get())};
if ( ! t ) if ( ! t )
return nullptr; return nullptr;
@ -2016,10 +2016,10 @@ 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();
IntrusivePtr<Type> ti; zeek::IntrusivePtr<Type> ti;
if ( el_t ) if ( el_t )
ti = {NewRef{}, reduce_type(el_t.get())}; ti = {zeek::NewRef{}, reduce_type(el_t.get())};
if ( ! ti ) if ( ! ti )
return nullptr; return nullptr;
@ -2044,12 +2044,12 @@ IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
// it one, as that's what's required for creating a set type. // it one, as that's what's required for creating a set type.
if ( t->Tag() != TYPE_LIST ) if ( t->Tag() != TYPE_LIST )
{ {
auto tl = make_intrusive<TypeList>(t); auto tl = zeek::make_intrusive<TypeList>(t);
tl->Append(std::move(t)); tl->Append(std::move(t));
t = std::move(tl); t = std::move(tl);
} }
return make_intrusive<SetType>(cast_intrusive<TypeList>(std::move(t)), return zeek::make_intrusive<SetType>(zeek::cast_intrusive<TypeList>(std::move(t)),
nullptr); nullptr);
} }
@ -2068,14 +2068,14 @@ bool is_atomic_type(const Type& t)
} }
} }
const IntrusivePtr<Type>& base_type(zeek::TypeTag tag) const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag)
{ {
static IntrusivePtr<Type> base_types[NUM_TYPES]; static zeek::IntrusivePtr<Type> 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] )
{ {
base_types[tag] = make_intrusive<Type>(tag, true); base_types[tag] = zeek::make_intrusive<Type>(tag, true);
// Give the base types a pseudo-location for easier identification. // Give the base types a pseudo-location for easier identification.
Location l(type_name(tag), 0, 0, 0, 0); Location l(type_name(tag), 0, 0, 0, 0);
base_types[tag]->SetLocationInfo(&l); base_types[tag]->SetLocationInfo(&l);

View file

@ -14,6 +14,7 @@
#include <list> #include <list>
#include <optional> #include <optional>
class Val;
class EnumVal; class EnumVal;
class TableVal; class TableVal;
@ -127,6 +128,7 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept
return TYPE_INTERNAL_VOID; return TYPE_INTERNAL_VOID;
} }
class Type;
class TypeList; class TypeList;
class TableType; class TableType;
class SetType; class SetType;
@ -144,7 +146,7 @@ constexpr int MATCHES_INDEX_VECTOR = 2;
class Type : public BroObj { class Type : public BroObj {
public: public:
static inline const IntrusivePtr<Type> nil; static inline const zeek::IntrusivePtr<Type> nil;
explicit Type(zeek::TypeTag tag, bool base_type = false); explicit Type(zeek::TypeTag tag, bool base_type = false);
@ -156,7 +158,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 IntrusivePtr<Type> ShallowClone(); virtual zeek::IntrusivePtr<Type> ShallowClone();
TypeTag Tag() const { return tag; } TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; } InternalTypeTag InternalType() const { return internal_tag; }
@ -176,7 +178,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 IntrusivePtr<Type>& Yield() const; virtual const zeek::IntrusivePtr<Type>& Yield() const;
[[deprecated("Remove in v4.1. Use Yield() instead.")]] [[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual Type* YieldType() virtual Type* YieldType()
@ -360,7 +362,7 @@ private:
class TypeList final : public Type { class TypeList final : public Type {
public: public:
explicit TypeList(IntrusivePtr<Type> arg_pure_type = nullptr) explicit TypeList(zeek::IntrusivePtr<Type> arg_pure_type = nullptr)
: Type(TYPE_LIST), pure_type(std::move(arg_pure_type)) : Type(TYPE_LIST), pure_type(std::move(arg_pure_type))
{ {
} }
@ -371,14 +373,14 @@ public:
const type_list* Types() const const type_list* Types() const
{ return &types_list; } { return &types_list; }
const std::vector<IntrusivePtr<Type>>& GetTypes() const const std::vector<zeek::IntrusivePtr<Type>>& 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 IntrusivePtr<Type>& GetPureType() const const zeek::IntrusivePtr<Type>& GetPureType() const
{ return pure_type; } { return pure_type; }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]] [[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
@ -390,19 +392,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 IntrusivePtr<Type>& t, bool is_init) const bool AllMatch(const zeek::IntrusivePtr<Type>& t, bool is_init) const
{ return AllMatch(t.get(), is_init); } { return AllMatch(t.get(), is_init); }
void Append(IntrusivePtr<Type> t); void Append(zeek::IntrusivePtr<Type> t);
void AppendEvenIfNotPure(IntrusivePtr<Type> t); void AppendEvenIfNotPure(zeek::IntrusivePtr<Type> 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:
IntrusivePtr<Type> pure_type; zeek::IntrusivePtr<Type> pure_type;
std::vector<IntrusivePtr<Type>> types; std::vector<zeek::IntrusivePtr<Type>> 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;
@ -413,7 +415,7 @@ public:
int MatchesIndex(zeek::detail::ListExpr* index) const override; int MatchesIndex(zeek::detail::ListExpr* index) const override;
const IntrusivePtr<TypeList>& GetIndices() const const zeek::IntrusivePtr<TypeList>& GetIndices() const
{ return indices; } { return indices; }
[[deprecated("Remove in v4.1. Use GetIndices().")]] [[deprecated("Remove in v4.1. Use GetIndices().")]]
@ -423,10 +425,10 @@ public:
const type_list* IndexTypes() const const type_list* IndexTypes() const
{ return indices->Types(); } { return indices->Types(); }
const std::vector<IntrusivePtr<Type>>& GetIndexTypes() const const std::vector<zeek::IntrusivePtr<Type>>& GetIndexTypes() const
{ return indices->GetTypes(); } { return indices->GetTypes(); }
const IntrusivePtr<Type>& Yield() const override const zeek::IntrusivePtr<Type>& Yield() const override
{ return yield_type; } { return yield_type; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -436,8 +438,8 @@ public:
bool IsSubNetIndex() const; bool IsSubNetIndex() const;
protected: protected:
IndexType(TypeTag t, IntrusivePtr<TypeList> arg_indices, IndexType(TypeTag t, zeek::IntrusivePtr<TypeList> arg_indices,
IntrusivePtr<Type> arg_yield_type) zeek::IntrusivePtr<Type> 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))
{ {
@ -445,15 +447,15 @@ protected:
~IndexType() override = default; ~IndexType() override = default;
IntrusivePtr<TypeList> indices; zeek::IntrusivePtr<TypeList> indices;
IntrusivePtr<Type> yield_type; zeek::IntrusivePtr<Type> yield_type;
}; };
class TableType : public IndexType { class TableType : public IndexType {
public: public:
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield); TableType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<Type> yield);
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> 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.
@ -462,24 +464,24 @@ public:
class SetType final : public TableType { class SetType final : public TableType {
public: public:
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements); SetType(zeek::IntrusivePtr<TypeList> ind, zeek::IntrusivePtr<zeek::detail::ListExpr> arg_elements);
~SetType() override; ~SetType() override;
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> 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 IntrusivePtr<zeek::detail::ListExpr>& Elements() const const zeek::IntrusivePtr<zeek::detail::ListExpr>& Elements() const
{ return elements; } { return elements; }
protected: protected:
IntrusivePtr<zeek::detail::ListExpr> elements; zeek::IntrusivePtr<zeek::detail::ListExpr> elements;
}; };
class FuncType final : public Type { class FuncType final : public Type {
public: public:
static inline const IntrusivePtr<FuncType> nil; static inline const zeek::IntrusivePtr<FuncType> nil;
/** /**
* Prototype is only currently used for events and hooks which declare * Prototype is only currently used for events and hooks which declare
@ -488,27 +490,27 @@ public:
*/ */
struct Prototype { struct Prototype {
bool deprecated; bool deprecated;
IntrusivePtr<RecordType> args; zeek::IntrusivePtr<RecordType> args;
std::map<int, int> offsets; std::map<int, int> offsets;
}; };
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<Type> yield, FuncType(zeek::IntrusivePtr<RecordType> args, zeek::IntrusivePtr<Type> yield,
FunctionFlavor f); FunctionFlavor f);
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> 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 IntrusivePtr<RecordType>& Params() const const zeek::IntrusivePtr<RecordType>& Params() const
{ return args; } { return args; }
const IntrusivePtr<Type>& Yield() const override const zeek::IntrusivePtr<Type>& Yield() const override
{ return yield; } { return yield; }
void SetYieldType(IntrusivePtr<Type> arg_yield) { yield = std::move(arg_yield); } void SetYieldType(zeek::IntrusivePtr<Type> 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;
@ -518,13 +520,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<IntrusivePtr<Type>>& args, bool CheckArgs(const std::vector<zeek::IntrusivePtr<Type>>& 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 IntrusivePtr<TypeList>& ParamList() const const zeek::IntrusivePtr<TypeList>& ParamList() const
{ return arg_types; } { return arg_types; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
@ -547,27 +549,27 @@ public:
{ return prototypes; } { return prototypes; }
protected: protected:
friend IntrusivePtr<FuncType> make_intrusive<FuncType>(); friend zeek::IntrusivePtr<FuncType> zeek::make_intrusive<FuncType>();
FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; } FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
IntrusivePtr<RecordType> args; zeek::IntrusivePtr<RecordType> args;
IntrusivePtr<TypeList> arg_types; zeek::IntrusivePtr<TypeList> arg_types;
IntrusivePtr<Type> yield; zeek::IntrusivePtr<Type> 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(IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {} explicit TypeType(zeek::IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<TypeType>(type); } zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<TypeType>(type); }
const IntrusivePtr<Type>& GetType() const const zeek::IntrusivePtr<Type>& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
IntrusivePtr<T> GetType() const zeek::IntrusivePtr<T> GetType() const
{ return cast_intrusive<T>(type); } { return zeek::cast_intrusive<T>(type); }
[[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(); }
@ -575,24 +577,24 @@ public:
const zeek::Type* Type() const { return type.get(); } const zeek::Type* Type() const { return type.get(); }
protected: protected:
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> type;
}; };
class TypeDecl final { class TypeDecl final {
public: public:
TypeDecl() = default; TypeDecl() = default;
TypeDecl(const char* i, IntrusivePtr<Type> t, TypeDecl(const char* i, zeek::IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> attrs = nullptr); zeek::IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
TypeDecl(const TypeDecl& other); TypeDecl(const TypeDecl& other);
~TypeDecl(); ~TypeDecl();
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag a) const const zeek::IntrusivePtr<zeek::detail::Attr>& 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;
IntrusivePtr<Type> type; zeek::IntrusivePtr<Type> type;
IntrusivePtr<zeek::detail::Attributes> attrs; zeek::IntrusivePtr<zeek::detail::Attributes> attrs;
const char* id = nullptr; const char* id = nullptr;
}; };
@ -601,7 +603,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);
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> ShallowClone() override;
~RecordType() override; ~RecordType() override;
@ -622,7 +624,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 IntrusivePtr<Type>& GetFieldType(const char* field_name) const const zeek::IntrusivePtr<Type>& GetFieldType(const char* field_name) const
{ return GetFieldType(FieldOffset(field_name)); } { return GetFieldType(FieldOffset(field_name)); }
/** /**
@ -630,14 +632,14 @@ public:
* No check for invalid field name is performed. * No check for invalid field name is performed.
*/ */
template <class T> template <class T>
IntrusivePtr<T> GetFieldType(const char* field_name) const zeek::IntrusivePtr<T> GetFieldType(const char* field_name) const
{ return cast_intrusive<T>(GetFieldType(field_name)); } { return zeek::cast_intrusive<T>(GetFieldType(field_name)); }
/** /**
* 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 IntrusivePtr<Type>& GetFieldType(int field_index) const const zeek::IntrusivePtr<Type>& GetFieldType(int field_index) const
{ return (*types)[field_index]->type; } { return (*types)[field_index]->type; }
/** /**
@ -645,10 +647,10 @@ public:
* No check for invalid field offset is performed. * No check for invalid field offset is performed.
*/ */
template <class T> template <class T>
IntrusivePtr<T> GetFieldType(int field_index) const zeek::IntrusivePtr<T> GetFieldType(int field_index) const
{ return cast_intrusive<T>((*types)[field_index]->type); } { return zeek::cast_intrusive<T>((*types)[field_index]->type); }
IntrusivePtr<Val> FieldDefault(int field) const; zeek::IntrusivePtr<Val> 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.
@ -670,7 +672,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.
*/ */
IntrusivePtr<TableVal> GetRecordFieldsVal(const RecordVal* rv = nullptr) const; zeek::IntrusivePtr<TableVal> 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,
@ -710,23 +712,23 @@ public:
class FileType final : public Type { class FileType final : public Type {
public: public:
explicit FileType(IntrusivePtr<Type> yield_type); explicit FileType(zeek::IntrusivePtr<Type> yield_type);
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<FileType>(yield); } zeek::IntrusivePtr<Type> ShallowClone() override { return zeek::make_intrusive<FileType>(yield); }
~FileType() override; ~FileType() override;
const IntrusivePtr<Type>& Yield() const override const zeek::IntrusivePtr<Type>& Yield() const override
{ return yield; } { return yield; }
void Describe(ODesc* d) const override; void Describe(ODesc* d) const override;
protected: protected:
IntrusivePtr<Type> yield; zeek::IntrusivePtr<Type> 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);
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<OpaqueType>(name); } zeek::IntrusivePtr<Type> 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; }
@ -746,7 +748,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);
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> 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
@ -768,7 +770,7 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override;
const IntrusivePtr<EnumVal>& GetVal(bro_int_t i); const zeek::IntrusivePtr<EnumVal>& GetVal(bro_int_t i);
protected: protected:
void AddNameInternal(const std::string& module_name, void AddNameInternal(const std::string& module_name,
@ -781,7 +783,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, IntrusivePtr<EnumVal>>; using ValMap = std::unordered_map<bro_int_t, zeek::IntrusivePtr<EnumVal>>;
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
@ -795,11 +797,11 @@ protected:
class VectorType final : public Type { class VectorType final : public Type {
public: public:
explicit VectorType(IntrusivePtr<Type> t); explicit VectorType(zeek::IntrusivePtr<Type> t);
IntrusivePtr<Type> ShallowClone() override; zeek::IntrusivePtr<Type> ShallowClone() override;
~VectorType() override; ~VectorType() override;
const IntrusivePtr<Type>& Yield() const override; const zeek::IntrusivePtr<Type>& Yield() const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override; int MatchesIndex(zeek::detail::ListExpr* index) const override;
@ -811,7 +813,7 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override;
protected: protected:
IntrusivePtr<Type> yield_type; zeek::IntrusivePtr<Type> 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
@ -819,16 +821,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 IntrusivePtr<Type>& t1, const IntrusivePtr<Type>& t2, inline bool same_type(const zeek::IntrusivePtr<Type>& t1, const zeek::IntrusivePtr<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 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 IntrusivePtr<Type>& t1, const Type* t2, inline bool same_type(const zeek::IntrusivePtr<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 Type* t1, const IntrusivePtr<Type>& t2, inline bool same_type(const Type* t1, const zeek::IntrusivePtr<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); }
@ -851,22 +853,22 @@ 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.
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& t1, zeek::IntrusivePtr<Type> merge_types(const zeek::IntrusivePtr<Type>& t1,
const IntrusivePtr<Type>& 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.
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements); zeek::IntrusivePtr<Type> 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.
IntrusivePtr<Type> init_type(zeek::detail::Expr* init); zeek::IntrusivePtr<Type> 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 IntrusivePtr<Type>& t) inline bool is_atomic_type(const zeek::IntrusivePtr<Type>& 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.
@ -923,10 +925,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 IntrusivePtr<zeek::Type>& base_type(zeek::TypeTag tag); const zeek::IntrusivePtr<Type>& base_type(zeek::TypeTag tag);
// Returns the basic error type. // Returns the basic error type.
inline const IntrusivePtr<zeek::Type>& error_type() { return base_type(TYPE_ERROR); } inline const zeek::IntrusivePtr<Type>& error_type() { return base_type(TYPE_ERROR); }
} // namespace zeek } // namespace zeek
@ -936,16 +938,16 @@ inline const IntrusivePtr<zeek::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 IntrusivePtr<zeek::OpaqueType> md5_type; extern zeek::IntrusivePtr<zeek::OpaqueType> md5_type;
extern IntrusivePtr<zeek::OpaqueType> sha1_type; extern zeek::IntrusivePtr<zeek::OpaqueType> sha1_type;
extern IntrusivePtr<zeek::OpaqueType> sha256_type; extern zeek::IntrusivePtr<zeek::OpaqueType> sha256_type;
extern IntrusivePtr<zeek::OpaqueType> entropy_type; extern zeek::IntrusivePtr<zeek::OpaqueType> entropy_type;
extern IntrusivePtr<zeek::OpaqueType> cardinality_type; extern zeek::IntrusivePtr<zeek::OpaqueType> cardinality_type;
extern IntrusivePtr<zeek::OpaqueType> topk_type; extern zeek::IntrusivePtr<zeek::OpaqueType> topk_type;
extern IntrusivePtr<zeek::OpaqueType> bloomfilter_type; extern zeek::IntrusivePtr<zeek::OpaqueType> bloomfilter_type;
extern IntrusivePtr<zeek::OpaqueType> x509_opaque_type; extern zeek::IntrusivePtr<zeek::OpaqueType> x509_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type; extern zeek::IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> paraglob_type; extern zeek::IntrusivePtr<zeek::OpaqueType> 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;

File diff suppressed because it is too large Load diff

300
src/Val.h
View file

@ -28,17 +28,16 @@
template<typename T> class PDict; template<typename T> class PDict;
class IterCookie; class IterCookie;
class Val;
class BroString; class BroString;
class BroFunc; class BroFunc;
class Func; class Func;
class BroFile; class BroFile;
class PrefixTable; class PrefixTable;
class Val;
class PortVal; class PortVal;
class AddrVal; class AddrVal;
class SubNetVal; class SubNetVal;
class IntervalVal; class IntervalVal;
class PatternVal; class PatternVal;
class TableVal; class TableVal;
@ -47,16 +46,14 @@ class ListVal;
class StringVal; class StringVal;
class EnumVal; class EnumVal;
class OpaqueVal; class OpaqueVal;
class VectorVal;
class TableEntryVal;
class IPAddr; class IPAddr;
class IPPrefix; class IPPrefix;
class StateAccess; class StateAccess;
class VectorVal;
class TableEntryVal;
class RE_Matcher; class RE_Matcher;
union BroValUnion { union BroValUnion {
@ -80,8 +77,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<IntrusivePtr<Val>>* record_val; std::vector<zeek::IntrusivePtr<Val>>* record_val;
std::vector<IntrusivePtr<Val>>* vector_val; std::vector<zeek::IntrusivePtr<Val>>* vector_val;
BroValUnion() = default; BroValUnion() = default;
@ -118,7 +115,7 @@ union BroValUnion {
class Val : public BroObj { class Val : public BroObj {
public: public:
static inline const IntrusivePtr<Val> nil; static inline const zeek::IntrusivePtr<Val> 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)
@ -127,21 +124,21 @@ 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(IntrusivePtr<Func> f); explicit Val(zeek::IntrusivePtr<Func> 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(IntrusivePtr<BroFile> f); explicit Val(zeek::IntrusivePtr<BroFile> f);
// Extra arg to differentiate from protected version. // Extra arg to differentiate from protected version.
Val(IntrusivePtr<zeek::Type> t, bool type_type) Val(zeek::IntrusivePtr<zeek::Type> t, bool type_type)
: type(make_intrusive<zeek::TypeType>(std::move(t))) : type(zeek::make_intrusive<zeek::TypeType>(std::move(t)))
{} {}
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
Val(zeek::Type* t, bool type_type) : Val({NewRef{}, t}, type_type) Val(zeek::Type* t, bool type_type) : Val({zeek::NewRef{}, t}, type_type)
{} {}
Val() Val()
@ -151,7 +148,7 @@ public:
~Val() override; ~Val() override;
Val* Ref() { ::Ref(this); return this; } Val* Ref() { ::Ref(this); return this; }
IntrusivePtr<Val> Clone(); zeek::IntrusivePtr<Val> Clone();
bool IsZero() const; bool IsZero() const;
bool IsOne() const; bool IsOne() const;
@ -166,7 +163,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 IntrusivePtr<Val> SizeVal() const; virtual zeek::IntrusivePtr<Val> SizeVal() const;
// Bytes in total value object. // Bytes in total value object.
virtual unsigned int MemoryAllocation() const; virtual unsigned int MemoryAllocation() const;
@ -185,12 +182,12 @@ 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 IntrusivePtr<zeek::Type>& GetType() const const zeek::IntrusivePtr<zeek::Type>& GetType() const
{ return type; } { return type; }
template <class T> template <class T>
IntrusivePtr<T> GetType() const zeek::IntrusivePtr<T> GetType() const
{ return cast_intrusive<T>(type); } { return zeek::cast_intrusive<T>(type); }
#define CONST_ACCESSOR(tag, ctype, accessor, name) \ #define CONST_ACCESSOR(tag, ctype, accessor, name) \
const ctype name() const \ const ctype name() const \
@ -218,10 +215,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<IntrusivePtr<Val>>*, record_val, AsRecord) CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, 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<IntrusivePtr<Val>>*, vector_val, AsVector) CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector)
const IPPrefix& AsSubNet() const const IPPrefix& AsSubNet() const
{ {
@ -255,9 +252,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<IntrusivePtr<Val>>*, vector_val, AsVector) ACCESSOR(zeek::TYPE_VECTOR, std::vector<zeek::IntrusivePtr<Val>>*, vector_val, AsVector)
IntrusivePtr<Func> AsFuncPtr() const; zeek::IntrusivePtr<Func> AsFuncPtr() const;
const IPPrefix& AsSubNet() const IPPrefix& AsSubNet()
{ {
@ -331,9 +328,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);
IntrusivePtr<TableVal> GetRecordFields(); zeek::IntrusivePtr<TableVal> GetRecordFields();
IntrusivePtr<StringVal> ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr); zeek::IntrusivePtr<StringVal> ToJSON(bool only_loggable=false, RE_Matcher* re=nullptr);
protected: protected:
@ -347,9 +344,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 IntrusivePtr<Val> MakeBool(bool b); static zeek::IntrusivePtr<Val> MakeBool(bool b);
static IntrusivePtr<Val> MakeInt(bro_int_t i); static zeek::IntrusivePtr<Val> MakeInt(bro_int_t i);
static IntrusivePtr<Val> MakeCount(bro_uint_t u); static zeek::IntrusivePtr<Val> 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
@ -357,32 +354,32 @@ protected:
{} {}
template<typename V> template<typename V>
Val(V&& v, IntrusivePtr<zeek::Type> t) noexcept Val(V&& v, zeek::IntrusivePtr<zeek::Type> t) noexcept
: val(std::forward<V>(v)), type(std::move(t)) : val(std::forward<V>(v)), type(std::move(t))
{} {}
explicit Val(IntrusivePtr<zeek::Type> t) noexcept explicit Val(zeek::IntrusivePtr<zeek::Type> 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<IntrusivePtr<Val>>*, record_val, AsNonConstRecord) ACCESSOR(zeek::TYPE_RECORD, std::vector<zeek::IntrusivePtr<Val>>*, 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.
IntrusivePtr<Val> NewClone(Val* src, IntrusivePtr<Val> dst); zeek::IntrusivePtr<Val> NewClone(Val* src, zeek::IntrusivePtr<Val> dst);
std::unordered_map<Val*, Val*> clones; std::unordered_map<Val*, Val*> clones;
}; };
IntrusivePtr<Val> Clone(CloneState* state); zeek::IntrusivePtr<Val> Clone(CloneState* state);
virtual IntrusivePtr<Val> DoClone(CloneState* state); virtual zeek::IntrusivePtr<Val> DoClone(CloneState* state);
BroValUnion val; BroValUnion val;
IntrusivePtr<zeek::Type> type; zeek::IntrusivePtr<zeek::Type> 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.
@ -408,21 +405,21 @@ public:
inline Val* GetTrue() const inline Val* GetTrue() const
{ return b_true->Ref(); } { return b_true->Ref(); }
inline const IntrusivePtr<Val>& True() const inline const zeek::IntrusivePtr<Val>& 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 IntrusivePtr<Val>& False() const inline const zeek::IntrusivePtr<Val>& 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 IntrusivePtr<Val>& Bool(bool b) const inline const zeek::IntrusivePtr<Val>& 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.")]]
@ -432,7 +429,7 @@ public:
Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref(); Val::MakeInt(i).release() : ints[i - PREALLOCATED_INT_LOWEST]->Ref();
} }
inline IntrusivePtr<Val> Int(int64_t i) const inline zeek::IntrusivePtr<Val> 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];
@ -444,7 +441,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 IntrusivePtr<Val> Count(uint64_t i) const inline zeek::IntrusivePtr<Val> Count(uint64_t i) const
{ {
return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i]; return i >= PREALLOCATED_COUNTS ? Val::MakeCount(i) : counts[i];
} }
@ -452,7 +449,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 IntrusivePtr<StringVal>& EmptyString() const inline const zeek::IntrusivePtr<StringVal>& EmptyString() const
{ return empty_string; } { return empty_string; }
// Port number given in host order. // Port number given in host order.
@ -460,23 +457,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 IntrusivePtr<PortVal>& Port(uint32_t port_num, TransportProto port_type) const; const zeek::IntrusivePtr<PortVal>& 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 IntrusivePtr<PortVal>& Port(uint32_t port_num) const; const zeek::IntrusivePtr<PortVal>& Port(uint32_t port_num) const;
private: private:
std::array<std::array<IntrusivePtr<PortVal>, 65536>, NUM_PORT_SPACES> ports; std::array<std::array<zeek::IntrusivePtr<PortVal>, 65536>, NUM_PORT_SPACES> ports;
std::array<IntrusivePtr<Val>, PREALLOCATED_COUNTS> counts; std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_COUNTS> counts;
std::array<IntrusivePtr<Val>, PREALLOCATED_INTS> ints; std::array<zeek::IntrusivePtr<Val>, PREALLOCATED_INTS> ints;
IntrusivePtr<StringVal> empty_string; zeek::IntrusivePtr<StringVal> empty_string;
IntrusivePtr<Val> b_true; zeek::IntrusivePtr<Val> b_true;
IntrusivePtr<Val> b_false; zeek::IntrusivePtr<Val> b_false;
}; };
extern ValManager* val_mgr; extern ValManager* val_mgr;
@ -514,7 +511,7 @@ public:
class PortVal final : public Val { class PortVal final : public Val {
public: public:
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> 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;
@ -545,7 +542,7 @@ protected:
PortVal(uint32_t p); PortVal(uint32_t p);
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
}; };
class AddrVal final : public Val { class AddrVal final : public Val {
@ -554,7 +551,7 @@ public:
explicit AddrVal(const std::string& text); explicit AddrVal(const std::string& text);
~AddrVal() override; ~AddrVal() override;
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> 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.
@ -564,7 +561,7 @@ public:
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
protected: protected:
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
}; };
class SubNetVal final : public Val { class SubNetVal final : public Val {
@ -577,7 +574,7 @@ public:
explicit SubNetVal(const IPPrefix& prefix); explicit SubNetVal(const IPPrefix& prefix);
~SubNetVal() override; ~SubNetVal() override;
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> SizeVal() const override;
const IPAddr& Prefix() const; const IPAddr& Prefix() const;
int Width() const; int Width() const;
@ -589,7 +586,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
}; };
class StringVal final : public Val { class StringVal final : public Val {
@ -599,7 +596,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);
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> SizeVal() const override;
int Len(); int Len();
const u_char* Bytes(); const u_char* Bytes();
@ -615,8 +612,8 @@ public:
unsigned int MemoryAllocation() const override; unsigned int MemoryAllocation() const override;
IntrusivePtr<StringVal> Replace(RE_Matcher* re, const BroString& repl, zeek::IntrusivePtr<StringVal> 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().")]]
Val* Substitute(RE_Matcher* re, StringVal* repl, bool do_all) Val* Substitute(RE_Matcher* re, StringVal* repl, bool do_all)
@ -624,7 +621,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
}; };
class PatternVal final : public Val { class PatternVal final : public Val {
@ -640,7 +637,7 @@ public:
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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
@ -653,11 +650,11 @@ public:
zeek::TypeTag BaseTag() const { return tag; } zeek::TypeTag BaseTag() const { return tag; }
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> SizeVal() const override;
int Length() const { return vals.size(); } int Length() const { return vals.size(); }
const IntrusivePtr<Val>& Idx(size_t i) const { return vals[i]; } const zeek::IntrusivePtr<Val>& 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(); }
@ -678,27 +675,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(IntrusivePtr<Val> v); void Append(zeek::IntrusivePtr<Val> 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).
IntrusivePtr<TableVal> ToSetVal() const; zeek::IntrusivePtr<TableVal> 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<IntrusivePtr<Val>>& Vals() const { return vals; } const std::vector<zeek::IntrusivePtr<Val>>& 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:
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
std::vector<IntrusivePtr<Val>> vals; std::vector<zeek::IntrusivePtr<Val>> vals;
zeek::TypeTag tag; zeek::TypeTag tag;
}; };
@ -706,7 +703,7 @@ extern double bro_start_network_time;
class TableEntryVal { class TableEntryVal {
public: public:
explicit TableEntryVal(IntrusivePtr<Val> v) explicit TableEntryVal(zeek::IntrusivePtr<Val> v)
: val(std::move(v)) : val(std::move(v))
{ {
expire_access_time = expire_access_time =
@ -718,7 +715,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 IntrusivePtr<Val>& GetVal() const const zeek::IntrusivePtr<Val>& 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.
@ -730,7 +727,8 @@ public:
protected: protected:
friend class TableVal; friend class TableVal;
IntrusivePtr<Val> val; zeek::IntrusivePtr<Val> 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
// anyway. // anyway.
@ -756,11 +754,11 @@ class Frame;
class TableVal final : public Val, public notifier::Modifiable { class TableVal final : public Val, public notifier::Modifiable {
public: public:
explicit TableVal(IntrusivePtr<zeek::TableType> t, IntrusivePtr<zeek::detail::Attributes> attrs = nullptr); explicit TableVal(zeek::IntrusivePtr<zeek::TableType> t, zeek::IntrusivePtr<zeek::detail::Attributes> 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)
: TableVal({NewRef{}, t}, {NewRef{}, attrs}) : TableVal({zeek::NewRef{}, t}, {zeek::NewRef{}, attrs})
{} {}
~TableVal() override; ~TableVal() override;
@ -773,7 +771,7 @@ public:
* must be nullptr. * must be nullptr.
* @return True if the assignment type-checked. * @return True if the assignment type-checked.
*/ */
bool Assign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val); bool Assign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> 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
@ -785,8 +783,8 @@ public:
* must be nullptr. * must be nullptr.
* @return True if the assignment type-checked. * @return True if the assignment type-checked.
*/ */
bool Assign(IntrusivePtr<Val> index, std::unique_ptr<HashKey> k, bool Assign(zeek::IntrusivePtr<Val> index, std::unique_ptr<HashKey> k,
IntrusivePtr<Val> new_val); zeek::IntrusivePtr<Val> 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
@ -799,7 +797,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);
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> 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.
@ -827,7 +825,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.
*/ */
IntrusivePtr<TableVal> Intersection(const TableVal& v) const; zeek::IntrusivePtr<TableVal> 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
@ -853,7 +851,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(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val); bool ExpandAndInit(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val);
/** /**
* Finds an index in the table and returns its associated value. * Finds an index in the table and returns its associated value.
@ -864,7 +862,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 IntrusivePtr<Val>& Find(const IntrusivePtr<Val>& index); const zeek::IntrusivePtr<Val>& Find(const zeek::IntrusivePtr<Val>& 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
@ -874,7 +872,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.
*/ */
IntrusivePtr<Val> FindOrDefault(const IntrusivePtr<Val>& index); zeek::IntrusivePtr<Val> FindOrDefault(const zeek::IntrusivePtr<Val>& 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
@ -885,12 +883,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.
IntrusivePtr<VectorVal> LookupSubnets(const SubNetVal* s); zeek::IntrusivePtr<VectorVal> 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.
IntrusivePtr<TableVal> LookupSubnetValues(const SubNetVal* s); zeek::IntrusivePtr<TableVal> 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.
@ -899,7 +897,7 @@ public:
/** /**
* @return The index corresponding to the given HashKey. * @return The index corresponding to the given HashKey.
*/ */
IntrusivePtr<ListVal> RecreateIndex(const HashKey& k) const; zeek::IntrusivePtr<ListVal> 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
@ -913,14 +911,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.
*/ */
IntrusivePtr<Val> Remove(const Val& index); zeek::IntrusivePtr<Val> 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&).
*/ */
IntrusivePtr<Val> Remove(const HashKey& k); zeek::IntrusivePtr<Val> 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)
@ -931,25 +929,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).
IntrusivePtr<ListVal> ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const; zeek::IntrusivePtr<ListVal> 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).
IntrusivePtr<ListVal> ToPureListVal() const; zeek::IntrusivePtr<ListVal> 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(IntrusivePtr<zeek::detail::Attributes> attrs); void SetAttrs(zeek::IntrusivePtr<zeek::detail::Attributes> attrs);
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::AttrTag t) const; const zeek::IntrusivePtr<zeek::detail::Attr>& 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 IntrusivePtr<zeek::detail::Attributes>& GetAttrs() const const zeek::IntrusivePtr<zeek::detail::Attributes>& GetAttrs() const
{ return attrs; } { return attrs; }
// Returns the size of the table. // Returns the size of the table.
@ -1005,22 +1003,22 @@ public:
static void DoneParsing(); static void DoneParsing();
protected: protected:
void Init(IntrusivePtr<zeek::TableType> t); void Init(zeek::IntrusivePtr<zeek::TableType> t);
using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<IntrusivePtr<TableVal>>>; using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<TableVal>>>;
using ParseTimeTableState = std::vector<std::pair<IntrusivePtr<Val>, IntrusivePtr<Val>>>; using ParseTimeTableState = std::vector<std::pair<zeek::IntrusivePtr<Val>, zeek::IntrusivePtr<Val>>>;
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, IntrusivePtr<Val> new_val); bool ExpandCompoundAndInit(ListVal* lv, int k, zeek::IntrusivePtr<Val> new_val);
bool CheckAndAssign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val); bool CheckAndAssign(zeek::IntrusivePtr<Val> index, zeek::IntrusivePtr<Val> new_val);
// Calculates default value for index. Returns nullptr if none. // Calculates default value for index. Returns nullptr if none.
IntrusivePtr<Val> Default(const IntrusivePtr<Val>& index); zeek::IntrusivePtr<Val> Default(const zeek::IntrusivePtr<Val>& 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; }
@ -1031,27 +1029,27 @@ protected:
double GetExpireTime(); double GetExpireTime();
// Calls &expire_func and returns its return interval; // Calls &expire_func and returns its return interval;
double CallExpireFunc(IntrusivePtr<ListVal> idx); double CallExpireFunc(zeek::IntrusivePtr<ListVal> 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 IntrusivePtr<Val>& old_value, void CallChangeFunc(const Val* index, const zeek::IntrusivePtr<Val>& old_value,
OnChangeType tpe); OnChangeType tpe);
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
IntrusivePtr<zeek::TableType> table_type; zeek::IntrusivePtr<zeek::TableType> table_type;
CompositeHash* table_hash; CompositeHash* table_hash;
IntrusivePtr<zeek::detail::Attributes> attrs; zeek::IntrusivePtr<zeek::detail::Attributes> attrs;
IntrusivePtr<zeek::detail::Expr> expire_time; zeek::IntrusivePtr<zeek::detail::Expr> expire_time;
IntrusivePtr<zeek::detail::Expr> expire_func; zeek::IntrusivePtr<zeek::detail::Expr> expire_func;
TableValTimer* timer; TableValTimer* timer;
IterCookie* expire_cookie; IterCookie* expire_cookie;
PrefixTable* subnets; PrefixTable* subnets;
IntrusivePtr<Val> def_val; zeek::IntrusivePtr<Val> def_val;
IntrusivePtr<zeek::detail::Expr> change_func; zeek::IntrusivePtr<zeek::detail::Expr> change_func;
// prevent recursion of change functions // prevent recursion of change functions
bool in_change_func = false; bool in_change_func = false;
@ -1063,18 +1061,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(IntrusivePtr<zeek::RecordType> t, bool init_fields = true); explicit RecordVal(zeek::IntrusivePtr<zeek::RecordType> t, bool init_fields = true);
~RecordVal() override; ~RecordVal() override;
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> 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, IntrusivePtr<Val> new_val); void Assign(int field, zeek::IntrusivePtr<Val> 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
@ -1085,13 +1083,13 @@ public:
*/ */
template <class T, class... Ts> template <class T, class... Ts>
void Assign(int field, Ts&&... args) void Assign(int field, Ts&&... args)
{ Assign(field, make_intrusive<T>(std::forward<Ts>(args)...)); } { Assign(field, zeek::make_intrusive<T>(std::forward<Ts>(args)...)); }
[[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]]
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, IntrusivePtr<Val>{}); } { Assign(field, zeek::IntrusivePtr<Val>{}); }
[[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.
@ -1102,7 +1100,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 IntrusivePtr<Val>& GetField(int field) const const zeek::IntrusivePtr<Val>& GetField(int field) const
{ return (*AsRecord())[field]; } { return (*AsRecord())[field]; }
/** /**
@ -1111,8 +1109,8 @@ public:
* @return The value at the given field index cast to type @c T. * @return The value at the given field index cast to type @c T.
*/ */
template <class T> template <class T>
IntrusivePtr<T> GetField(int field) const zeek::IntrusivePtr<T> GetField(int field) const
{ return cast_intrusive<T>(GetField(field)); } { return zeek::cast_intrusive<T>(GetField(field)); }
/** /**
* Returns the value of a given field index if it's previously been * Returns the value of a given field index if it's previously been
@ -1122,7 +1120,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.
*/ */
IntrusivePtr<Val> GetFieldOrDefault(int field) const; zeek::IntrusivePtr<Val> 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
@ -1134,7 +1132,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 IntrusivePtr<Val>& GetField(const char* field) const; const zeek::IntrusivePtr<Val>& 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.
@ -1143,8 +1141,8 @@ public:
* field name exists, a fatal error occurs. * field name exists, a fatal error occurs.
*/ */
template <class T> template <class T>
IntrusivePtr<T> GetField(const char* field) const zeek::IntrusivePtr<T> GetField(const char* field) const
{ return cast_intrusive<T>(GetField(field)); } { return zeek::cast_intrusive<T>(GetField(field)); }
/** /**
* Returns the value of a given field name if it's previously been * Returns the value of a given field name if it's previously been
@ -1155,7 +1153,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.
*/ */
IntrusivePtr<Val> GetFieldOrDefault(const char* field) const; zeek::IntrusivePtr<Val> 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
@ -1165,8 +1163,8 @@ public:
* type @c T. If no such field name exists, a fatal error occurs. * type @c T. If no such field name exists, a fatal error occurs.
*/ */
template <class T> template <class T>
IntrusivePtr<T> GetFieldOrDefault(const char* field) const zeek::IntrusivePtr<T> GetFieldOrDefault(const char* field) const
{ return cast_intrusive<T>(GetField(field)); } { return zeek::cast_intrusive<T>(GetField(field)); }
/** /**
* Looks up the value of a field by field name. If the field doesn't * Looks up the value of a field by field name. If the field doesn't
@ -1185,7 +1183,7 @@ public:
/** /**
* Returns a "record_field_table" value for introspection purposes. * Returns a "record_field_table" value for introspection purposes.
*/ */
IntrusivePtr<TableVal> GetRecordFieldsVal() const; zeek::IntrusivePtr<TableVal> 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.
@ -1203,11 +1201,13 @@ 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.
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<zeek::RecordType> other, zeek::IntrusivePtr<RecordVal> CoerceTo(
IntrusivePtr<RecordVal> aggr, zeek::IntrusivePtr<zeek::RecordType> other,
bool allow_orphaning = false) const; zeek::IntrusivePtr<RecordVal> aggr,
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<zeek::RecordType> other, bool allow_orphaning = false) const;
bool allow_orphaning = false); zeek::IntrusivePtr<RecordVal> CoerceTo(
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,30 +1222,30 @@ public:
static void DoneParsing(); static void DoneParsing();
protected: protected:
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
BroObj* origin; BroObj* origin;
using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<IntrusivePtr<RecordVal>>>; using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<zeek::IntrusivePtr<RecordVal>>>;
static RecordTypeValMap parse_time_records; static RecordTypeValMap parse_time_records;
}; };
class EnumVal final : public Val { class EnumVal final : public Val {
public: public:
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> SizeVal() const override;
protected: protected:
friend class Val; friend class Val;
friend class zeek::EnumType; friend class zeek::EnumType;
template<class T, class... Ts> template<class T, class... Ts>
friend IntrusivePtr<T> make_intrusive(Ts&&... args); friend zeek::IntrusivePtr<T> zeek::make_intrusive(Ts&&... args);
EnumVal(IntrusivePtr<zeek::EnumType> t, int i) : Val(bro_int_t(i), std::move(t)) EnumVal(zeek::IntrusivePtr<zeek::EnumType> t, int i) : Val(bro_int_t(i), std::move(t))
{} {}
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> DoClone(CloneState* state) override;
}; };
@ -1253,10 +1253,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(IntrusivePtr<zeek::VectorType> t); explicit VectorVal(zeek::IntrusivePtr<zeek::VectorType> t);
~VectorVal() override; ~VectorVal() override;
IntrusivePtr<Val> SizeVal() const override; zeek::IntrusivePtr<Val> SizeVal() const override;
/** /**
* Assigns an element to a given vector index. * Assigns an element to a given vector index.
@ -1265,22 +1265,22 @@ 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, IntrusivePtr<Val> element); bool Assign(unsigned int index, zeek::IntrusivePtr<Val> 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.
[[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]] [[deprecated("Remove in v4.1. Assign an IntrusivePtr instead.")]]
bool Assign(unsigned int index, Val* element) bool Assign(unsigned int index, Val* element)
{ return Assign(index, {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, IntrusivePtr<Val>{}); } { Assign(index, zeek::IntrusivePtr<Val>{}); }
[[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)
{ {
return Assign(index->AsListVal()->Idx(0)->CoerceToUnsigned(), return Assign(index->AsListVal()->Idx(0)->CoerceToUnsigned(),
{AdoptRef{}, element}); {zeek::AdoptRef{}, element});
} }
/** /**
@ -1291,11 +1291,11 @@ 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,
IntrusivePtr<Val> element); zeek::IntrusivePtr<Val> 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)
{ return AssignRepeat(index, how_many, {NewRef{}, element}); } { return AssignRepeat(index, how_many, {zeek::NewRef{}, element}); }
// Add this value to the given value (if appropriate). // Add this value to the given value (if appropriate).
// Returns true if succcessful. // Returns true if succcessful.
@ -1307,7 +1307,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 IntrusivePtr<Val>& At(unsigned int index) const; const zeek::IntrusivePtr<Val>& 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,44 +1339,44 @@ 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, IntrusivePtr<Val> element); bool Insert(unsigned int index, zeek::IntrusivePtr<Val> 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)
{ return Insert(index, {AdoptRef{}, element}); } { return Insert(index, {zeek::AdoptRef{}, element}); }
// Removes an element at a specific position. // Removes an element at a specific position.
bool Remove(unsigned int index); bool Remove(unsigned int index);
protected: protected:
void ValDescribe(ODesc* d) const override; void ValDescribe(ODesc* d) const override;
IntrusivePtr<Val> DoClone(CloneState* state) override; zeek::IntrusivePtr<Val> 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 IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v, extern zeek::IntrusivePtr<Val> check_and_promote(
const zeek::Type* t, bool is_init, zeek::IntrusivePtr<Val> 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<IntrusivePtr<Val>>& vals, extern void describe_vals(const std::vector<zeek::IntrusivePtr<Val>>& 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 IntrusivePtr<Val>& v) { return is_vector(v.get()); } inline bool is_vector(const zeek::IntrusivePtr<Val>& 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 IntrusivePtr<Val> cast_value_to_type(Val* v, zeek::Type* t); extern zeek::IntrusivePtr<Val> 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,8 +19,9 @@
using namespace zeek::detail; using namespace zeek::detail;
static IntrusivePtr<Val> init_val(zeek::detail::Expr* init, const zeek::Type* t, static zeek::IntrusivePtr<Val> init_val(zeek::detail::Expr* init,
IntrusivePtr<Val> aggr) const zeek::Type* t,
zeek::IntrusivePtr<Val> aggr)
{ {
try try
{ {
@ -32,9 +33,9 @@ static IntrusivePtr<Val> init_val(zeek::detail::Expr* init, const zeek::Type* t,
} }
} }
static bool add_prototype(const IntrusivePtr<zeek::detail::ID>& id, zeek::Type* t, static bool add_prototype(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::Type* t,
std::vector<IntrusivePtr<zeek::detail::Attr>>* attrs, std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>* attrs,
const IntrusivePtr<zeek::detail::Expr>& init) const zeek::IntrusivePtr<zeek::detail::Expr>& init)
{ {
if ( ! zeek::IsFunc(id->GetType()->Tag()) ) if ( ! zeek::IsFunc(id->GetType()->Tag()) )
return false; return false;
@ -110,10 +111,10 @@ static bool add_prototype(const IntrusivePtr<zeek::detail::ID>& id, zeek::Type*
return true; return true;
} }
static void make_var(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::Type> t, static void make_var(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::Type> t,
zeek::detail::InitClass c, zeek::detail::InitClass c,
IntrusivePtr<zeek::detail::Expr> init, zeek::IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt, decl_type dt,
bool do_init) bool do_init)
{ {
@ -202,7 +203,7 @@ static void make_var(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek
id->SetType(t); id->SetType(t);
if ( attr ) if ( attr )
id->AddAttrs(make_intrusive<zeek::detail::Attributes>(std::move(*attr), t, false, id->IsGlobal())); id->AddAttrs(zeek::make_intrusive<zeek::detail::Attributes>(std::move(*attr), t, false, id->IsGlobal()));
if ( init ) if ( init )
{ {
@ -243,26 +244,27 @@ static void make_var(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek
else if ( dt != VAR_REDEF || init || ! attr ) else if ( dt != VAR_REDEF || init || ! attr )
{ {
IntrusivePtr<Val> aggr; zeek::IntrusivePtr<Val> aggr;
if ( t->Tag() == zeek::TYPE_RECORD ) if ( t->Tag() == zeek::TYPE_RECORD )
{ {
aggr = make_intrusive<RecordVal>(cast_intrusive<zeek::RecordType>(t)); aggr = zeek::make_intrusive<RecordVal>(zeek::cast_intrusive<zeek::RecordType>(t));
if ( init && t ) if ( init && t )
// Have an initialization and type is not deduced. // Have an initialization and type is not deduced.
init = make_intrusive<zeek::detail::RecordCoerceExpr>(std::move(init), init = zeek::make_intrusive<zeek::detail::RecordCoerceExpr>(
IntrusivePtr{NewRef{}, t->AsRecordType()}); std::move(init),
zeek::IntrusivePtr{zeek::NewRef{}, t->AsRecordType()});
} }
else if ( t->Tag() == zeek::TYPE_TABLE ) else if ( t->Tag() == zeek::TYPE_TABLE )
aggr = make_intrusive<TableVal>(cast_intrusive<zeek::TableType>(t), aggr = zeek::make_intrusive<TableVal>(zeek::cast_intrusive<zeek::TableType>(t),
id->GetAttrs()); id->GetAttrs());
else if ( t->Tag() == zeek::TYPE_VECTOR ) else if ( t->Tag() == zeek::TYPE_VECTOR )
aggr = make_intrusive<VectorVal>(cast_intrusive<zeek::VectorType>(t)); aggr = zeek::make_intrusive<VectorVal>(zeek::cast_intrusive<zeek::VectorType>(t));
IntrusivePtr<Val> v; zeek::IntrusivePtr<Val> v;
if ( init ) if ( init )
{ {
@ -304,23 +306,23 @@ static void make_var(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek
// 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<IntrusivePtr<zeek::detail::ID>> inits; std::vector<zeek::IntrusivePtr<zeek::detail::ID>> inits;
auto f = make_intrusive<BroFunc>(id, nullptr, inits, 0, 0); auto f = zeek::make_intrusive<BroFunc>(id, nullptr, inits, 0, 0);
id->SetVal(make_intrusive<Val>(std::move(f))); id->SetVal(zeek::make_intrusive<Val>(std::move(f)));
} }
} }
void add_global(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::Type> t, void add_global(const zeek::IntrusivePtr<zeek::detail::ID>& id, zeek::IntrusivePtr<zeek::Type> t,
zeek::detail::InitClass c, IntrusivePtr<zeek::detail::Expr> init, zeek::detail::InitClass c, zeek::IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt) 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);
} }
IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id, IntrusivePtr<zeek::Type> t, zeek::IntrusivePtr<zeek::detail::Stmt> add_local(zeek::IntrusivePtr<zeek::detail::ID> id, zeek::IntrusivePtr<zeek::Type> t,
zeek::detail::InitClass c, IntrusivePtr<zeek::detail::Expr> init, zeek::detail::InitClass c, zeek::IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt) 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);
@ -334,11 +336,11 @@ IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id, In
const Location location = init->GetLocationInfo() ? const Location location = init->GetLocationInfo() ?
*init->GetLocationInfo() : no_location; *init->GetLocationInfo() : no_location;
auto name_expr = make_intrusive<zeek::detail::NameExpr>(id, dt == VAR_CONST); auto name_expr = zeek::make_intrusive<zeek::detail::NameExpr>(id, dt == VAR_CONST);
auto assign_expr = make_intrusive<zeek::detail::AssignExpr>(std::move(name_expr), auto assign_expr = zeek::make_intrusive<zeek::detail::AssignExpr>(std::move(name_expr),
std::move(init), 0, std::move(init), 0,
nullptr, id->GetAttrs()); nullptr, id->GetAttrs());
auto stmt = make_intrusive<zeek::detail::ExprStmt>(std::move(assign_expr)); auto stmt = zeek::make_intrusive<zeek::detail::ExprStmt>(std::move(assign_expr));
stmt->SetLocationInfo(&location); stmt->SetLocationInfo(&location);
return stmt; return stmt;
} }
@ -346,26 +348,27 @@ IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id, In
else else
{ {
current_scope()->AddInit(std::move(id)); current_scope()->AddInit(std::move(id));
return make_intrusive<zeek::detail::NullStmt>(); return zeek::make_intrusive<zeek::detail::NullStmt>();
} }
} }
extern IntrusivePtr<zeek::detail::Expr> add_and_assign_local(IntrusivePtr<zeek::detail::ID> id, extern zeek::IntrusivePtr<zeek::detail::Expr> add_and_assign_local(
IntrusivePtr<zeek::detail::Expr> init, zeek::IntrusivePtr<zeek::detail::ID> id,
IntrusivePtr<Val> val) zeek::IntrusivePtr<zeek::detail::Expr> init,
zeek::IntrusivePtr<Val> 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 = make_intrusive<zeek::detail::NameExpr>(std::move(id)); auto name_expr = zeek::make_intrusive<zeek::detail::NameExpr>(std::move(id));
return make_intrusive<zeek::detail::AssignExpr>(std::move(name_expr), std::move(init), return zeek::make_intrusive<zeek::detail::AssignExpr>(
false, std::move(val)); std::move(name_expr), std::move(init), false, std::move(val));
} }
void add_type(zeek::detail::ID* id, IntrusivePtr<zeek::Type> t, void add_type(zeek::detail::ID* id, zeek::IntrusivePtr<zeek::Type> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr) std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> 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();
IntrusivePtr<zeek::Type> tnew; zeek::IntrusivePtr<zeek::Type> 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() )
@ -386,7 +389,7 @@ void add_type(zeek::detail::ID* id, IntrusivePtr<zeek::Type> t,
id->MakeType(); id->MakeType();
if ( attr ) if ( attr )
id->SetAttrs(make_intrusive<zeek::detail::Attributes>(std::move(*attr), tnew, false, false)); id->SetAttrs(zeek::make_intrusive<zeek::detail::Attributes>(std::move(*attr), tnew, false, false));
} }
static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv) static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv)
@ -403,8 +406,8 @@ static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv
if ( ! recv_i->attrs ) if ( ! recv_i->attrs )
{ {
std::vector<IntrusivePtr<zeek::detail::Attr>> a{def}; std::vector<zeek::IntrusivePtr<zeek::detail::Attr>> a{def};
recv_i->attrs = 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);
} }
@ -414,7 +417,7 @@ static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv
} }
} }
static zeek::detail::Attr* find_attr(const std::vector<IntrusivePtr<zeek::detail::Attr>>* al, static zeek::detail::Attr* find_attr(const std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>* al,
zeek::detail::AttrTag tag) zeek::detail::AttrTag tag)
{ {
if ( ! al ) if ( ! al )
@ -462,10 +465,10 @@ static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::Fu
return true; return true;
} }
void begin_func(IntrusivePtr<zeek::detail::ID> id, const char* module_name, void begin_func(zeek::IntrusivePtr<zeek::detail::ID> id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef, zeek::FunctionFlavor flavor, bool is_redef,
IntrusivePtr<zeek::FuncType> t, zeek::IntrusivePtr<zeek::FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs) std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs)
{ {
if ( flavor == zeek::FUNC_FLAVOR_EVENT ) if ( flavor == zeek::FUNC_FLAVOR_EVENT )
{ {
@ -636,7 +639,7 @@ TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr)
return TC_CONTINUE; return TC_CONTINUE;
} }
void end_func(IntrusivePtr<zeek::detail::Stmt> body) void end_func(zeek::IntrusivePtr<zeek::detail::Stmt> 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));
@ -648,14 +651,14 @@ void end_func(IntrusivePtr<zeek::detail::Stmt> body)
ingredients->priority); ingredients->priority);
else else
{ {
auto f = make_intrusive<BroFunc>( auto f = zeek::make_intrusive<BroFunc>(
ingredients->id, ingredients->id,
ingredients->body, ingredients->body,
ingredients->inits, ingredients->inits,
ingredients->frame_size, ingredients->frame_size,
ingredients->priority); ingredients->priority);
ingredients->id->SetVal(make_intrusive<Val>(std::move(f))); ingredients->id->SetVal(zeek::make_intrusive<Val>(std::move(f)));
ingredients->id->SetConst(); ingredients->id->SetConst();
} }

View file

@ -18,33 +18,35 @@ ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
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 IntrusivePtr<zeek::detail::ID>& id, extern void add_global(const zeek::IntrusivePtr<zeek::detail::ID>& id,
IntrusivePtr<zeek::Type> t, zeek::IntrusivePtr<zeek::Type> t,
zeek::detail::InitClass c, zeek::detail::InitClass c,
IntrusivePtr<zeek::detail::Expr> init, zeek::IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr, std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt); decl_type dt);
extern IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id, extern zeek::IntrusivePtr<zeek::detail::Stmt> add_local(
IntrusivePtr<zeek::Type> t, zeek::IntrusivePtr<zeek::detail::ID> id,
zeek::detail::InitClass c, zeek::IntrusivePtr<zeek::Type> t,
IntrusivePtr<zeek::detail::Expr> init, zeek::detail::InitClass c,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr, zeek::IntrusivePtr<zeek::detail::Expr> init,
decl_type dt); std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt);
extern IntrusivePtr<zeek::detail::Expr> add_and_assign_local(IntrusivePtr<zeek::detail::ID> id, extern zeek::IntrusivePtr<zeek::detail::Expr> add_and_assign_local(
IntrusivePtr<zeek::detail::Expr> init, zeek::IntrusivePtr<zeek::detail::ID> id,
IntrusivePtr<Val> val = nullptr); zeek::IntrusivePtr<zeek::detail::Expr> init,
zeek::IntrusivePtr<Val> val = nullptr);
extern void add_type(zeek::detail::ID* id, IntrusivePtr<zeek::Type> t, extern void add_type(zeek::detail::ID* id, zeek::IntrusivePtr<zeek::Type> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr); std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attr);
extern void begin_func(IntrusivePtr<zeek::detail::ID> id, const char* module_name, extern void begin_func(zeek::IntrusivePtr<zeek::detail::ID> id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef, zeek::FunctionFlavor flavor, bool is_redef,
IntrusivePtr<zeek::FuncType> t, zeek::IntrusivePtr<zeek::FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs = nullptr); std::unique_ptr<std::vector<zeek::IntrusivePtr<zeek::detail::Attr>>> attrs = nullptr);
extern void end_func(IntrusivePtr<zeek::detail::Stmt> body); extern void end_func(zeek::IntrusivePtr<zeek::detail::Stmt> 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

@ -1,5 +1,4 @@
#include "ZeekArgs.h" #include "ZeekArgs.h"
#include "IntrusivePtr.h"
#include "Val.h" #include "Val.h"
zeek::Args zeek::val_list_to_args(const val_list& vl) zeek::Args zeek::val_list_to_args(const val_list& vl)
@ -8,8 +7,7 @@ zeek::Args zeek::val_list_to_args(const val_list& vl)
rval.reserve(vl.length()); rval.reserve(vl.length());
for ( auto& v : vl ) for ( auto& v : vl )
rval.emplace_back(AdoptRef{}, v); rval.emplace_back(zeek::AdoptRef{}, v);
return rval; return rval;
} }

View file

@ -2,16 +2,15 @@
#pragma once #pragma once
#include <vector>
#include "BroList.h" #include "BroList.h"
#include <vector>
class Val; class Val;
template <class T> class IntrusivePtr;
namespace zeek { namespace zeek {
using Args = std::vector<IntrusivePtr<Val>>; template <class T> class IntrusivePtr;
using Args = std::vector<zeek::IntrusivePtr<Val>>;
/** /**
* Converts a legacy-style argument list for use in modern Zeek function * Converts a legacy-style argument list for use in modern Zeek function

View file

@ -710,18 +710,18 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len)
if ( ! protocol_violation ) if ( ! protocol_violation )
return; return;
IntrusivePtr<StringVal> r; zeek::IntrusivePtr<StringVal> r;
if ( data && len ) if ( data && len )
{ {
const char *tmp = copy_string(reason); const char *tmp = copy_string(reason);
r = make_intrusive<StringVal>(fmt("%s [%s%s]", tmp, r = zeek::make_intrusive<StringVal>(fmt("%s [%s%s]", tmp,
fmt_bytes(data, min(40, len)), fmt_bytes(data, min(40, len)),
len > 40 ? "..." : "")); len > 40 ? "..." : ""));
delete [] tmp; delete [] tmp;
} }
else else
r = make_intrusive<StringVal>(reason); r = zeek::make_intrusive<StringVal>(reason);
const auto& tval = tag.AsVal(); const auto& tval = tag.AsVal();
mgr.Enqueue(protocol_violation, ConnVal(), tval, val_mgr->Count(id), std::move(r)); mgr.Enqueue(protocol_violation, ConnVal(), tval, val_mgr->Count(id), std::move(r));
@ -794,7 +794,7 @@ RecordVal* Analyzer::BuildConnVal()
return conn->ConnVal()->Ref()->AsRecordVal(); return conn->ConnVal()->Ref()->AsRecordVal();
} }
const IntrusivePtr<RecordVal>& Analyzer::ConnVal() const zeek::IntrusivePtr<RecordVal>& Analyzer::ConnVal()
{ {
return conn->ConnVal(); return conn->ConnVal();
} }
@ -806,8 +806,8 @@ void Analyzer::Event(EventHandlerPtr f, const char* name)
void Analyzer::Event(EventHandlerPtr f, Val* v1, Val* v2) void Analyzer::Event(EventHandlerPtr f, Val* v1, Val* v2)
{ {
IntrusivePtr val1{AdoptRef{}, v1}; zeek::IntrusivePtr val1{zeek::AdoptRef{}, v1};
IntrusivePtr val2{AdoptRef{}, v2}; zeek::IntrusivePtr val2{zeek::AdoptRef{}, v2};
if ( f ) if ( f )
conn->EnqueueEvent(f, this, conn->ConnVal(), std::move(val1), std::move(val2)); conn->EnqueueEvent(f, this, conn->ConnVal(), std::move(val1), std::move(val2));
@ -926,12 +926,12 @@ void TransportLayerAnalyzer::Done()
} }
void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */, void TransportLayerAnalyzer::SetContentsFile(unsigned int /* direction */,
IntrusivePtr<BroFile> /* f */) zeek::IntrusivePtr<BroFile> /* 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");
} }
IntrusivePtr<BroFile> TransportLayerAnalyzer::GetContentsFile(unsigned int /* direction */) const zeek::IntrusivePtr<BroFile> 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;
@ -942,7 +942,7 @@ void TransportLayerAnalyzer::PacketContents(const u_char* data, int len)
if ( packet_contents && len > 0 ) if ( packet_contents && len > 0 )
{ {
BroString* cbs = new BroString(data, len, true); BroString* cbs = new BroString(data, len, true);
auto contents = make_intrusive<StringVal>(cbs); auto contents = zeek::make_intrusive<StringVal>(cbs);
EnqueueConnEvent(packet_contents, ConnVal(), std::move(contents)); EnqueueConnEvent(packet_contents, ConnVal(), std::move(contents));
} }
} }

View file

@ -556,7 +556,7 @@ public:
* Convenience function that forwards directly to * Convenience function that forwards directly to
* Connection::ConnVal(). * Connection::ConnVal().
*/ */
const IntrusivePtr<RecordVal>& ConnVal(); const zeek::IntrusivePtr<RecordVal>& ConnVal();
/** /**
* Convenience function that forwards directly to the corresponding * Convenience function that forwards directly to the corresponding
@ -604,7 +604,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...>>, IntrusivePtr<Val>>> std::tuple_element_t<0, std::tuple<Args...>>, zeek::IntrusivePtr<Val>>>
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 +911,7 @@ public:
* @param f The file to record to. * @param f The file to record to.
* *
*/ */
virtual void SetContentsFile(unsigned int direction, IntrusivePtr<BroFile> f); virtual void SetContentsFile(unsigned int direction, zeek::IntrusivePtr<BroFile> 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 +921,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 IntrusivePtr<BroFile> GetContentsFile(unsigned int direction) const; virtual zeek::IntrusivePtr<BroFile> 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

@ -463,7 +463,7 @@ bool Manager::BuildInitialAnalyzerTree(Connection* conn)
if ( resp_port == 22 || resp_port == 23 || resp_port == 513 ) if ( resp_port == 22 || resp_port == 23 || resp_port == 513 )
{ {
static auto stp_skip_src = zeek::id::find_val<TableVal>("stp_skip_src"); static auto stp_skip_src = zeek::id::find_val<TableVal>("stp_skip_src");
auto src = make_intrusive<AddrVal>(conn->OrigAddr()); auto src = zeek::make_intrusive<AddrVal>(conn->OrigAddr());
if ( ! stp_skip_src->FindOrDefault(src) ) if ( ! stp_skip_src->FindOrDefault(src) )
tcp->AddChildAnalyzer(new stepping_stone::SteppingStone_Analyzer(conn), false); tcp->AddChildAnalyzer(new stepping_stone::SteppingStone_Analyzer(conn), false);
@ -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)
{ {
IntrusivePtr<EnumVal> ev{NewRef{}, analyzer->AsEnumVal()}; zeek::IntrusivePtr<EnumVal> 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 IntrusivePtr<EnumVal>& analyzer::Tag::AsVal() const const zeek::IntrusivePtr<EnumVal>& analyzer::Tag::AsVal() const
{ {
return ::Tag::AsVal(analyzer_mgr->GetTagType()); return ::Tag::AsVal(analyzer_mgr->GetTagType());
} }
@ -26,10 +26,10 @@ EnumVal* analyzer::Tag::AsEnumVal() const
return AsVal().get(); return AsVal().get();
} }
analyzer::Tag::Tag(IntrusivePtr<EnumVal> val) analyzer::Tag::Tag(zeek::IntrusivePtr<EnumVal> val)
: ::Tag(std::move(val)) : ::Tag(std::move(val))
{ } { }
analyzer::Tag::Tag(EnumVal* val) analyzer::Tag::Tag(EnumVal* val)
: ::Tag({NewRef{}, val}) : ::Tag({zeek::NewRef{}, 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 IntrusivePtr<EnumVal>& AsVal() const; const zeek::IntrusivePtr<EnumVal>& 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(IntrusivePtr<EnumVal> val); explicit Tag(zeek::IntrusivePtr<EnumVal> 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

@ -41,8 +41,8 @@ function Analyzer::__schedule_analyzer%(orig: addr, resp: addr, resp_p: port,
function __name%(atype: Analyzer::Tag%) : string function __name%(atype: Analyzer::Tag%) : string
%{ %{
const auto& n = analyzer_mgr->GetComponentName(IntrusivePtr{NewRef{}, atype->AsEnumVal()}); const auto& n = analyzer_mgr->GetComponentName(zeek::IntrusivePtr{zeek::NewRef{}, atype->AsEnumVal()});
return make_intrusive<StringVal>(n); return zeek::make_intrusive<StringVal>(n);
%} %}
function __tag%(name: string%) : Analyzer::Tag function __tag%(name: string%) : Analyzer::Tag

View file

@ -196,7 +196,7 @@ void ARP_Analyzer::BadARP(const struct arp_pkthdr* hdr, const char* msg)
ToEthAddrStr((const u_char*) ar_sha(hdr)), ToEthAddrStr((const u_char*) ar_sha(hdr)),
ToAddrVal(ar_tpa(hdr)), ToAddrVal(ar_tpa(hdr)),
ToEthAddrStr((const u_char*) ar_tha(hdr)), ToEthAddrStr((const u_char*) ar_tha(hdr)),
make_intrusive<StringVal>(msg) zeek::make_intrusive<StringVal>(msg)
); );
} }
@ -226,19 +226,19 @@ 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(); }
IntrusivePtr<AddrVal> ARP_Analyzer::ToAddrVal(const void* addr) zeek::IntrusivePtr<AddrVal> ARP_Analyzer::ToAddrVal(const void* addr)
{ {
// ### For now, we only handle IPv4 addresses. // ### For now, we only handle IPv4 addresses.
return make_intrusive<AddrVal>(*(const uint32_t*) addr); return zeek::make_intrusive<AddrVal>(*(const uint32_t*) 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(); }
IntrusivePtr<StringVal> ARP_Analyzer::ToEthAddrStr(const u_char* addr) zeek::IntrusivePtr<StringVal> 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",
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
return make_intrusive<StringVal>(buf); return zeek::make_intrusive<StringVal>(buf);
} }

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);
IntrusivePtr<AddrVal> ToAddrVal(const void* addr); zeek::IntrusivePtr<AddrVal> ToAddrVal(const void* addr);
IntrusivePtr<StringVal> ToEthAddrStr(const u_char* addr); zeek::IntrusivePtr<StringVal> 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{
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t); zeek::IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t);
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t); zeek::IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t);
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid); zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid);
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid); zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid);
IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s); zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s);
IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1OctetString* s); zeek::IntrusivePtr<StringVal> 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{
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t) zeek::IntrusivePtr<Val> 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);
} }
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t) zeek::IntrusivePtr<Val> 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 @@ IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t)
} }
} }
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid) zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid)
{ {
return asn1_oid_to_val(oid->encoding()); return asn1_oid_to_val(oid->encoding());
} }
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid) zeek::IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid)
{ {
vector<uint64> oid_components; vector<uint64> oid_components;
vector<vector<uint8> > subidentifiers; vector<vector<uint8> > subidentifiers;
@ -191,17 +191,17 @@ IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid)
} }
} }
return make_intrusive<StringVal>(rval); return zeek::make_intrusive<StringVal>(rval);
} }
IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1OctetString* s) zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1OctetString* s)
{ {
return asn1_octet_string_to_val(s->encoding()); return asn1_octet_string_to_val(s->encoding());
} }
IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s) zeek::IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s)
{ {
bytestring const& bs = s->content(); bytestring const& bs = s->content();
return 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

@ -122,6 +122,6 @@ void BitTorrent_Analyzer::DeliverWeird(const char* msg, bool orig)
EnqueueConnEvent(bittorrent_peer_weird, EnqueueConnEvent(bittorrent_peer_weird,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(msg) zeek::make_intrusive<StringVal>(msg)
); );
} }

View file

@ -15,11 +15,11 @@
using namespace analyzer::bittorrent; using namespace analyzer::bittorrent;
static IntrusivePtr<zeek::TableType> bt_tracker_headers; static zeek::IntrusivePtr<zeek::TableType> bt_tracker_headers;
static IntrusivePtr<zeek::RecordType> bittorrent_peer; static zeek::IntrusivePtr<zeek::RecordType> bittorrent_peer;
static IntrusivePtr<zeek::TableType> bittorrent_peer_set; static zeek::IntrusivePtr<zeek::TableType> bittorrent_peer_set;
static IntrusivePtr<zeek::RecordType> bittorrent_benc_value; static zeek::IntrusivePtr<zeek::RecordType> bittorrent_benc_value;
static IntrusivePtr<zeek::TableType> bittorrent_benc_dir; static zeek::IntrusivePtr<zeek::TableType> 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)
@ -248,7 +248,7 @@ void BitTorrentTracker_Analyzer::DeliverWeird(const char* msg, bool orig)
EnqueueConnEvent(bt_tracker_weird, EnqueueConnEvent(bt_tracker_weird,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(msg) zeek::make_intrusive<StringVal>(msg)
); );
} }
@ -347,9 +347,9 @@ void BitTorrentTracker_Analyzer::EmitRequest(void)
if ( bt_tracker_request ) if ( bt_tracker_request )
EnqueueConnEvent(bt_tracker_request, EnqueueConnEvent(bt_tracker_request,
ConnVal(), ConnVal(),
IntrusivePtr{AdoptRef{}, req_val_uri}, zeek::IntrusivePtr{zeek::AdoptRef{}, req_val_uri},
IntrusivePtr{AdoptRef{}, req_val_headers} zeek::IntrusivePtr{zeek::AdoptRef{}, req_val_headers}
); );
req_val_uri = nullptr; req_val_uri = nullptr;
@ -400,10 +400,11 @@ bool BitTorrentTracker_Analyzer::ParseResponse(char* line)
if ( res_status != 200 ) if ( res_status != 200 )
{ {
if ( bt_tracker_response_not_ok ) if ( bt_tracker_response_not_ok )
EnqueueConnEvent(bt_tracker_response_not_ok, EnqueueConnEvent(
bt_tracker_response_not_ok,
ConnVal(), ConnVal(),
val_mgr->Count(res_status), val_mgr->Count(res_status),
IntrusivePtr{AdoptRef{}, res_val_headers} zeek::IntrusivePtr{zeek::AdoptRef{}, res_val_headers}
); );
res_val_headers = nullptr; res_val_headers = nullptr;
res_buf_pos = res_buf + res_buf_len; res_buf_pos = res_buf + res_buf_len;
@ -477,17 +478,17 @@ void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name,
uint32_t ad = extract_uint32((u_char*) value); uint32_t ad = extract_uint32((u_char*) value);
uint16_t pt = ntohs((value[4] << 8) | value[5]); uint16_t pt = ntohs((value[4] << 8) | value[5]);
auto peer = make_intrusive<RecordVal>(bittorrent_peer); auto peer = zeek::make_intrusive<RecordVal>(bittorrent_peer);
peer->Assign(0, make_intrusive<AddrVal>(ad)); peer->Assign(0, zeek::make_intrusive<AddrVal>(ad));
peer->Assign(1, val_mgr->Port(pt, TRANSPORT_TCP)); peer->Assign(1, val_mgr->Port(pt, TRANSPORT_TCP));
res_val_peers->Assign(std::move(peer), nullptr); res_val_peers->Assign(std::move(peer), nullptr);
} }
} }
else else
{ {
auto name_ = make_intrusive<StringVal>(name_len, name); auto name_ = zeek::make_intrusive<StringVal>(name_len, name);
auto benc_value = make_intrusive<RecordVal>(bittorrent_benc_value); auto benc_value = zeek::make_intrusive<RecordVal>(bittorrent_benc_value);
benc_value->Assign(type, make_intrusive<StringVal>(value_len, value)); benc_value->Assign(type, zeek::make_intrusive<StringVal>(value_len, value));
res_val_benc->Assign(std::move(name_), std::move(benc_value)); res_val_benc->Assign(std::move(name_), std::move(benc_value));
} }
} }
@ -495,8 +496,8 @@ void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name,
void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name, void BitTorrentTracker_Analyzer::ResponseBenc(int name_len, char* name,
enum btt_benc_types type, bro_int_t value) enum btt_benc_types type, bro_int_t value)
{ {
auto benc_value = make_intrusive<RecordVal>(bittorrent_benc_value); auto benc_value = zeek::make_intrusive<RecordVal>(bittorrent_benc_value);
auto name_ = make_intrusive<StringVal>(name_len, name); auto name_ = zeek::make_intrusive<StringVal>(name_len, name);
benc_value->Assign(type, val_mgr->Int(value)); benc_value->Assign(type, val_mgr->Int(value));
res_val_benc->Assign(std::move(name_), std::move(benc_value)); res_val_benc->Assign(std::move(name_), std::move(benc_value));
@ -782,11 +783,11 @@ void BitTorrentTracker_Analyzer::EmitResponse(void)
if ( bt_tracker_response ) if ( bt_tracker_response )
EnqueueConnEvent(bt_tracker_response, EnqueueConnEvent(bt_tracker_response,
ConnVal(), ConnVal(),
val_mgr->Count(res_status), val_mgr->Count(res_status),
IntrusivePtr{AdoptRef{}, res_val_headers}, zeek::IntrusivePtr{zeek::AdoptRef{}, res_val_headers},
IntrusivePtr{AdoptRef{}, res_val_peers}, zeek::IntrusivePtr{zeek::AdoptRef{}, res_val_peers},
IntrusivePtr{AdoptRef{}, res_val_benc} zeek::IntrusivePtr{zeek::AdoptRef{}, res_val_benc}
); );
res_val_headers = nullptr; res_val_headers = nullptr;

View file

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

View file

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

View file

@ -83,14 +83,14 @@ refine connection DCE_RPC_Conn += {
%{ %{
if ( dce_rpc_bind_ack ) if ( dce_rpc_bind_ack )
{ {
IntrusivePtr<StringVal> sec_addr; zeek::IntrusivePtr<StringVal> 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 &&
*(${bind.sec_addr}.begin() + ${bind.sec_addr}.length()) == 0 ) *(${bind.sec_addr}.begin() + ${bind.sec_addr}.length()) == 0 )
sec_addr = make_intrusive<StringVal>(${bind.sec_addr}.length()-1, (const char*) ${bind.sec_addr}.begin()); sec_addr = zeek::make_intrusive<StringVal>(${bind.sec_addr}.length()-1, (const char*) ${bind.sec_addr}.begin());
else else
sec_addr = make_intrusive<StringVal>(${bind.sec_addr}.length(), (const char*) ${bind.sec_addr}.begin()); sec_addr = zeek::make_intrusive<StringVal>(${bind.sec_addr}.length(), (const char*) ${bind.sec_addr}.begin());
zeek::BifEvent::enqueue_dce_rpc_bind_ack(bro_analyzer(), zeek::BifEvent::enqueue_dce_rpc_bind_ack(bro_analyzer(),
bro_analyzer()->Conn(), bro_analyzer()->Conn(),
@ -175,4 +175,3 @@ refine typeattr DCE_RPC_Request += &let {
refine typeattr DCE_RPC_Response += &let { refine typeattr DCE_RPC_Response += &let {
proc = $context.connection.process_dce_rpc_response(this); proc = $context.connection.process_dce_rpc_response(this);
}; };

View file

@ -1,8 +1,8 @@
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
%member{ %member{
IntrusivePtr<RecordVal> options; zeek::IntrusivePtr<RecordVal> options;
IntrusivePtr<VectorVal> all_options; zeek::IntrusivePtr<VectorVal> all_options;
%} %}
%init{ %init{
@ -19,8 +19,8 @@ refine flow DHCP_Flow += {
%{ %{
if ( ! options ) if ( ! options )
{ {
options = make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::Options); options = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::Options);
all_options = make_intrusive<VectorVal>(zeek::id::index_vec); all_options = zeek::make_intrusive<VectorVal>(zeek::id::index_vec);
options->Assign(0, all_options); options->Assign(0, all_options);
} }
@ -53,17 +53,17 @@ refine flow DHCP_Flow += {
std::string mac_str = fmt_mac(${msg.chaddr}.data(), ${msg.chaddr}.length()); std::string mac_str = fmt_mac(${msg.chaddr}.data(), ${msg.chaddr}.length());
double secs = static_cast<double>(${msg.secs}); double secs = static_cast<double>(${msg.secs});
auto dhcp_msg_val = make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::Msg); auto dhcp_msg_val = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::Msg);
dhcp_msg_val->Assign(0, val_mgr->Count(${msg.op})); dhcp_msg_val->Assign(0, val_mgr->Count(${msg.op}));
dhcp_msg_val->Assign(1, val_mgr->Count(${msg.type})); dhcp_msg_val->Assign(1, val_mgr->Count(${msg.type}));
dhcp_msg_val->Assign(2, val_mgr->Count(${msg.xid})); dhcp_msg_val->Assign(2, val_mgr->Count(${msg.xid}));
dhcp_msg_val->Assign(3, make_intrusive<IntervalVal>(secs)); dhcp_msg_val->Assign(3, zeek::make_intrusive<IntervalVal>(secs));
dhcp_msg_val->Assign(4, val_mgr->Count(${msg.flags})); dhcp_msg_val->Assign(4, val_mgr->Count(${msg.flags}));
dhcp_msg_val->Assign(5, make_intrusive<AddrVal>(htonl(${msg.ciaddr}))); dhcp_msg_val->Assign(5, zeek::make_intrusive<AddrVal>(htonl(${msg.ciaddr})));
dhcp_msg_val->Assign(6, make_intrusive<AddrVal>(htonl(${msg.yiaddr}))); dhcp_msg_val->Assign(6, zeek::make_intrusive<AddrVal>(htonl(${msg.yiaddr})));
dhcp_msg_val->Assign(7, make_intrusive<AddrVal>(htonl(${msg.siaddr}))); dhcp_msg_val->Assign(7, zeek::make_intrusive<AddrVal>(htonl(${msg.siaddr})));
dhcp_msg_val->Assign(8, make_intrusive<AddrVal>(htonl(${msg.giaddr}))); dhcp_msg_val->Assign(8, zeek::make_intrusive<AddrVal>(htonl(${msg.giaddr})));
dhcp_msg_val->Assign(9, make_intrusive<StringVal>(mac_str)); dhcp_msg_val->Assign(9, zeek::make_intrusive<StringVal>(mac_str));
int last_non_null = 0; int last_non_null = 0;
@ -74,7 +74,7 @@ refine flow DHCP_Flow += {
} }
if ( last_non_null > 0 ) if ( last_non_null > 0 )
dhcp_msg_val->Assign(10, make_intrusive<StringVal>(last_non_null + 1, dhcp_msg_val->Assign(10, zeek::make_intrusive<StringVal>(last_non_null + 1,
reinterpret_cast<const char*>(${msg.sname}.begin()))); reinterpret_cast<const char*>(${msg.sname}.begin())));
last_non_null = 0; last_non_null = 0;
@ -86,7 +86,7 @@ refine flow DHCP_Flow += {
} }
if ( last_non_null > 0 ) if ( last_non_null > 0 )
dhcp_msg_val->Assign(11, make_intrusive<StringVal>(last_non_null + 1, dhcp_msg_val->Assign(11, zeek::make_intrusive<StringVal>(last_non_null + 1,
reinterpret_cast<const char*>(${msg.file_n}.begin()))); reinterpret_cast<const char*>(${msg.file_n}.begin())));
init_options(); init_options();

View file

@ -11,7 +11,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_subnet_option(v: OptionValue): bool function process_subnet_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(1, make_intrusive<AddrVal>(htonl(${v.subnet}))); ${context.flow}->options->Assign(1, zeek::make_intrusive<AddrVal>(htonl(${v.subnet})));
return true; return true;
%} %}
}; };
@ -57,14 +57,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_router_option(v: OptionValue): bool function process_router_option(v: OptionValue): bool
%{ %{
auto router_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto router_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_routers = ${v.router_list}->size(); int num_routers = ${v.router_list}->size();
vector<uint32>* rlist = ${v.router_list}; vector<uint32>* rlist = ${v.router_list};
for ( int i = 0; i < num_routers; ++i ) for ( int i = 0; i < num_routers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
router_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); router_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(2, std::move(router_list)); ${context.flow}->options->Assign(2, std::move(router_list));
@ -91,14 +91,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_timeserver_option(v: OptionValue): bool function process_timeserver_option(v: OptionValue): bool
%{ %{
auto timeserver_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto timeserver_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_servers = ${v.timeserver_list}->size(); int num_servers = ${v.timeserver_list}->size();
vector<uint32>* rlist = ${v.timeserver_list}; vector<uint32>* rlist = ${v.timeserver_list};
for ( int i = 0; i < num_servers; ++i ) for ( int i = 0; i < num_servers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
timeserver_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); timeserver_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(26, std::move(timeserver_list)); ${context.flow}->options->Assign(26, std::move(timeserver_list));
@ -125,14 +125,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_nameserver_option(v: OptionValue): bool function process_nameserver_option(v: OptionValue): bool
%{ %{
auto nameserver_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto nameserver_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_servers = ${v.nameserver_list}->size(); int num_servers = ${v.nameserver_list}->size();
vector<uint32>* rlist = ${v.nameserver_list}; vector<uint32>* rlist = ${v.nameserver_list};
for ( int i = 0; i < num_servers; ++i ) for ( int i = 0; i < num_servers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
nameserver_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); nameserver_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(27, std::move(nameserver_list)); ${context.flow}->options->Assign(27, std::move(nameserver_list));
@ -159,14 +159,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_dns_server_option(v: OptionValue): bool function process_dns_server_option(v: OptionValue): bool
%{ %{
auto server_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto server_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_servers = ${v.dns_server_list}->size(); int num_servers = ${v.dns_server_list}->size();
vector<uint32>* rlist = ${v.dns_server_list}; vector<uint32>* rlist = ${v.dns_server_list};
for ( int i = 0; i < num_servers; ++i ) for ( int i = 0; i < num_servers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
server_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); server_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(3, std::move(server_list)); ${context.flow}->options->Assign(3, std::move(server_list));
@ -192,7 +192,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_host_name_option(v: OptionValue): bool function process_host_name_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(4, make_intrusive<StringVal>(${v.host_name}.length(), ${context.flow}->options->Assign(4, zeek::make_intrusive<StringVal>(${v.host_name}.length(),
reinterpret_cast<const char*>(${v.host_name}.begin()))); reinterpret_cast<const char*>(${v.host_name}.begin())));
return true; return true;
@ -225,7 +225,7 @@ refine flow DHCP_Flow += {
last_non_null = i; last_non_null = i;
} }
${context.flow}->options->Assign(5, make_intrusive<StringVal>(last_non_null == 0 ? 0 : last_non_null + 1, ${context.flow}->options->Assign(5, zeek::make_intrusive<StringVal>(last_non_null == 0 ? 0 : last_non_null + 1,
reinterpret_cast<const char*>(${v.domain_name}.begin()))); reinterpret_cast<const char*>(${v.domain_name}.begin())));
return true; return true;
@ -274,7 +274,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_broadcast_address_option(v: OptionValue): bool function process_broadcast_address_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(7, make_intrusive<AddrVal>(htonl(${v.broadcast_address}))); ${context.flow}->options->Assign(7, zeek::make_intrusive<AddrVal>(htonl(${v.broadcast_address})));
return true; return true;
%} %}
@ -298,14 +298,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_ntpserver_option(v: OptionValue): bool function process_ntpserver_option(v: OptionValue): bool
%{ %{
auto ntpserver_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto ntpserver_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_servers = ${v.ntpserver_list}->size(); int num_servers = ${v.ntpserver_list}->size();
vector<uint32>* rlist = ${v.ntpserver_list}; vector<uint32>* rlist = ${v.ntpserver_list};
for ( int i = 0; i < num_servers; ++i ) for ( int i = 0; i < num_servers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
ntpserver_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); ntpserver_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(28, std::move(ntpserver_list)); ${context.flow}->options->Assign(28, std::move(ntpserver_list));
@ -331,7 +331,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_vendor_specific_option(v: OptionValue): bool function process_vendor_specific_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(8, make_intrusive<StringVal>(${v.vendor_specific}.length(), ${context.flow}->options->Assign(8, zeek::make_intrusive<StringVal>(${v.vendor_specific}.length(),
reinterpret_cast<const char*>(${v.vendor_specific}.begin()))); reinterpret_cast<const char*>(${v.vendor_specific}.begin())));
return true; return true;
@ -356,14 +356,14 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_nbns_option(v: OptionValue): bool function process_nbns_option(v: OptionValue): bool
%{ %{
auto server_list = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs); auto server_list = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::Addrs);
int num_servers = ${v.nbns}->size(); int num_servers = ${v.nbns}->size();
vector<uint32>* rlist = ${v.nbns}; vector<uint32>* rlist = ${v.nbns};
for ( int i = 0; i < num_servers; ++i ) for ( int i = 0; i < num_servers; ++i )
{ {
uint32 raddr = (*rlist)[i]; uint32 raddr = (*rlist)[i];
server_list->Assign(i, make_intrusive<AddrVal>(htonl(raddr))); server_list->Assign(i, zeek::make_intrusive<AddrVal>(htonl(raddr)));
} }
${context.flow}->options->Assign(9, std::move(server_list)); ${context.flow}->options->Assign(9, std::move(server_list));
@ -389,7 +389,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_addr_request_option(v: OptionValue): bool function process_addr_request_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(10, make_intrusive<AddrVal>(htonl(${v.addr_request}))); ${context.flow}->options->Assign(10, zeek::make_intrusive<AddrVal>(htonl(${v.addr_request})));
return true; return true;
%} %}
@ -414,7 +414,7 @@ refine flow DHCP_Flow += {
function process_lease_option(v: OptionValue): bool function process_lease_option(v: OptionValue): bool
%{ %{
double lease = static_cast<double>(${v.lease}); double lease = static_cast<double>(${v.lease});
${context.flow}->options->Assign(11, make_intrusive<IntervalVal>(lease)); ${context.flow}->options->Assign(11, zeek::make_intrusive<IntervalVal>(lease));
return true; return true;
%} %}
@ -438,7 +438,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_serv_id_option(v: OptionValue): bool function process_serv_id_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(12, make_intrusive<AddrVal>(htonl(${v.serv_addr}))); ${context.flow}->options->Assign(12, zeek::make_intrusive<AddrVal>(htonl(${v.serv_addr})));
return true; return true;
%} %}
@ -462,7 +462,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_par_req_list_option(v: OptionValue): bool function process_par_req_list_option(v: OptionValue): bool
%{ %{
auto params = make_intrusive<VectorVal>(zeek::id::index_vec); auto params = zeek::make_intrusive<VectorVal>(zeek::id::index_vec);
int num_parms = ${v.par_req_list}->size(); int num_parms = ${v.par_req_list}->size();
vector<uint8>* plist = ${v.par_req_list}; vector<uint8>* plist = ${v.par_req_list};
@ -496,7 +496,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_message_option(v: OptionValue): bool function process_message_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(14, make_intrusive<StringVal>(${v.message}.length(), ${context.flow}->options->Assign(14, zeek::make_intrusive<StringVal>(${v.message}.length(),
reinterpret_cast<const char*>(${v.message}.begin()))); reinterpret_cast<const char*>(${v.message}.begin())));
return true; return true;
@ -546,7 +546,7 @@ refine flow DHCP_Flow += {
function process_renewal_time_option(v: OptionValue): bool function process_renewal_time_option(v: OptionValue): bool
%{ %{
double renewal_time = static_cast<double>(${v.renewal_time}); double renewal_time = static_cast<double>(${v.renewal_time});
${context.flow}->options->Assign(16, make_intrusive<IntervalVal>(renewal_time)); ${context.flow}->options->Assign(16, zeek::make_intrusive<IntervalVal>(renewal_time));
return true; return true;
%} %}
@ -571,7 +571,7 @@ refine flow DHCP_Flow += {
function process_rebinding_time_option(v: OptionValue): bool function process_rebinding_time_option(v: OptionValue): bool
%{ %{
double rebinding_time = static_cast<double>(${v.rebinding_time}); double rebinding_time = static_cast<double>(${v.rebinding_time});
${context.flow}->options->Assign(17, make_intrusive<IntervalVal>(rebinding_time)); ${context.flow}->options->Assign(17, zeek::make_intrusive<IntervalVal>(rebinding_time));
return true; return true;
%} %}
@ -595,7 +595,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_vendor_class_option(v: OptionValue): bool function process_vendor_class_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(18, make_intrusive<StringVal>(${v.vendor_class}.length(), ${context.flow}->options->Assign(18, zeek::make_intrusive<StringVal>(${v.vendor_class}.length(),
reinterpret_cast<const char*>(${v.vendor_class}.begin()))); reinterpret_cast<const char*>(${v.vendor_class}.begin())));
return true; return true;
@ -625,16 +625,16 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_client_id_option(v: OptionValue): bool function process_client_id_option(v: OptionValue): bool
%{ %{
auto client_id = 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}));
IntrusivePtr<StringVal> sv; zeek::IntrusivePtr<StringVal> sv;
if ( ${v.client_id.hwtype} == 0 ) if ( ${v.client_id.hwtype} == 0 )
sv = make_intrusive<StringVal>(${v.client_id.hwaddr}.length(), sv = zeek::make_intrusive<StringVal>(${v.client_id.hwaddr}.length(),
(const char*)${v.client_id.hwaddr}.begin()); (const char*)${v.client_id.hwaddr}.begin());
else else
sv = make_intrusive<StringVal>(fmt_mac(${v.client_id.hwaddr}.begin(), sv = zeek::make_intrusive<StringVal>(fmt_mac(${v.client_id.hwaddr}.begin(),
${v.client_id.hwaddr}.length())); ${v.client_id.hwaddr}.length()));
client_id->Assign(1, std::move(sv)); client_id->Assign(1, std::move(sv));
@ -662,7 +662,7 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_user_class_option(v: OptionValue): bool function process_user_class_option(v: OptionValue): bool
%{ %{
${context.flow}->options->Assign(20, make_intrusive<StringVal>(${v.user_class}.length(), ${context.flow}->options->Assign(20, zeek::make_intrusive<StringVal>(${v.user_class}.length(),
reinterpret_cast<const char*>(${v.user_class}.begin()))); reinterpret_cast<const char*>(${v.user_class}.begin())));
return true; return true;
@ -694,12 +694,12 @@ refine casetype OptionValue += {
refine flow DHCP_Flow += { refine flow DHCP_Flow += {
function process_client_fqdn_option(v: OptionValue): bool function process_client_fqdn_option(v: OptionValue): bool
%{ %{
auto client_fqdn = make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::ClientFQDN); auto client_fqdn = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::ClientFQDN);
client_fqdn->Assign(0, val_mgr->Count(${v.client_fqdn.flags})); client_fqdn->Assign(0, val_mgr->Count(${v.client_fqdn.flags}));
client_fqdn->Assign(1, val_mgr->Count(${v.client_fqdn.rcode1})); client_fqdn->Assign(1, val_mgr->Count(${v.client_fqdn.rcode1}));
client_fqdn->Assign(2, val_mgr->Count(${v.client_fqdn.rcode2})); client_fqdn->Assign(2, val_mgr->Count(${v.client_fqdn.rcode2}));
const char* domain_name = reinterpret_cast<const char*>(${v.client_fqdn.domain_name}.begin()); const char* domain_name = reinterpret_cast<const char*>(${v.client_fqdn.domain_name}.begin());
client_fqdn->Assign(3, make_intrusive<StringVal>(${v.client_fqdn.domain_name}.length(), domain_name)); client_fqdn->Assign(3, zeek::make_intrusive<StringVal>(${v.client_fqdn.domain_name}.length(), domain_name));
${context.flow}->options->Assign(21, std::move(client_fqdn)); ${context.flow}->options->Assign(21, std::move(client_fqdn));
@ -752,14 +752,14 @@ refine flow DHCP_Flow += {
function process_relay_agent_inf_option(v: OptionValue): bool function process_relay_agent_inf_option(v: OptionValue): bool
%{ %{
auto relay_agent_sub_opt = make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::SubOpts); auto relay_agent_sub_opt = zeek::make_intrusive<VectorVal>(zeek::BifType::Vector::DHCP::SubOpts);
uint16 i = 0; uint16 i = 0;
for ( auto ptrsubopt = ${v.relay_agent_inf}->begin(); for ( auto ptrsubopt = ${v.relay_agent_inf}->begin();
ptrsubopt != ${v.relay_agent_inf}->end(); ++ptrsubopt ) ptrsubopt != ${v.relay_agent_inf}->end(); ++ptrsubopt )
{ {
auto r = make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::SubOpt); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::DHCP::SubOpt);
r->Assign(0, val_mgr->Count((*ptrsubopt)->code())); r->Assign(0, val_mgr->Count((*ptrsubopt)->code()));
r->Assign(1, to_stringval((*ptrsubopt)->value())); r->Assign(1, to_stringval((*ptrsubopt)->value()));
@ -818,7 +818,7 @@ refine flow DHCP_Flow += {
if ( string_len == 0 ) if ( string_len == 0 )
{ {
${context.flow}->options->Assign(24, make_intrusive<StringVal>(0, "")); ${context.flow}->options->Assign(24, zeek::make_intrusive<StringVal>(0, ""));
return true; return true;
} }
@ -830,7 +830,7 @@ refine flow DHCP_Flow += {
if ( has_newline ) if ( has_newline )
--string_len; --string_len;
${context.flow}->options->Assign(24, make_intrusive<StringVal>(string_len, ${context.flow}->options->Assign(24, zeek::make_intrusive<StringVal>(string_len,
reinterpret_cast<const char*>(${v.auto_proxy_config}.begin()))); reinterpret_cast<const char*>(${v.auto_proxy_config}.begin())));
return true; return true;
@ -840,5 +840,3 @@ refine flow DHCP_Flow += {
refine typeattr Option += &let { refine typeattr Option += &let {
proc_auto_proxy_config_option = $context.flow.process_auto_proxy_config_option(info.value) &if(code==AUTO_PROXY_CONFIG_OPTION); proc_auto_proxy_config_option = $context.flow.process_auto_proxy_config_option(info.value) &if(code==AUTO_PROXY_CONFIG_OPTION);
}; };

View file

@ -91,7 +91,7 @@ void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query)
{ // We did an answer, so can potentially skip auth/addl. { // We did an answer, so can potentially skip auth/addl.
static auto dns_skip_auth = zeek::id::find_val<TableVal>("dns_skip_auth"); static auto dns_skip_auth = zeek::id::find_val<TableVal>("dns_skip_auth");
static auto dns_skip_addl = zeek::id::find_val<TableVal>("dns_skip_addl"); static auto dns_skip_addl = zeek::id::find_val<TableVal>("dns_skip_addl");
auto server = make_intrusive<AddrVal>(analyzer->Conn()->RespAddr()); auto server = zeek::make_intrusive<AddrVal>(analyzer->Conn()->RespAddr());
skip_auth = skip_auth || msg.nscount == 0 || skip_auth = skip_auth || msg.nscount == 0 ||
dns_skip_auth->FindOrDefault(server); dns_skip_auth->FindOrDefault(server);
@ -238,7 +238,7 @@ bool DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg,
// Note that the exact meaning of some of these fields will be // Note that the exact meaning of some of these fields will be
// re-interpreted by other, more adventurous RR types. // re-interpreted by other, more adventurous RR types.
msg->query_name = make_intrusive<StringVal>(new BroString(name, name_end - name, true)); msg->query_name = zeek::make_intrusive<StringVal>(new BroString(name, name_end - name, true));
msg->atype = RR_Type(ExtractShort(data, len)); msg->atype = RR_Type(ExtractShort(data, len));
msg->aclass = ExtractShort(data, len); msg->aclass = ExtractShort(data, len);
msg->ttl = ExtractLong(data, len); msg->ttl = ExtractLong(data, len);
@ -562,7 +562,7 @@ bool DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<StringVal>(new BroString(name, name_end - name, true)) zeek::make_intrusive<StringVal>(new BroString(name, name_end - name, true))
); );
return true; return true;
@ -603,14 +603,14 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
if ( dns_SOA_reply && ! msg->skip_event ) if ( dns_SOA_reply && ! msg->skip_event )
{ {
static auto dns_soa = zeek::id::find_type<zeek::RecordType>("dns_soa"); static auto dns_soa = zeek::id::find_type<zeek::RecordType>("dns_soa");
auto r = make_intrusive<RecordVal>(dns_soa); auto r = zeek::make_intrusive<RecordVal>(dns_soa);
r->Assign(0, make_intrusive<StringVal>(new BroString(mname, mname_end - mname, true))); r->Assign(0, zeek::make_intrusive<StringVal>(new BroString(mname, mname_end - mname, true)));
r->Assign(1, make_intrusive<StringVal>(new BroString(rname, rname_end - rname, true))); r->Assign(1, zeek::make_intrusive<StringVal>(new BroString(rname, rname_end - rname, true)));
r->Assign(2, val_mgr->Count(serial)); r->Assign(2, val_mgr->Count(serial));
r->Assign(3, make_intrusive<IntervalVal>(double(refresh), Seconds)); r->Assign(3, zeek::make_intrusive<IntervalVal>(double(refresh), Seconds));
r->Assign(4, make_intrusive<IntervalVal>(double(retry), Seconds)); r->Assign(4, zeek::make_intrusive<IntervalVal>(double(retry), Seconds));
r->Assign(5, make_intrusive<IntervalVal>(double(expire), Seconds)); r->Assign(5, zeek::make_intrusive<IntervalVal>(double(expire), Seconds));
r->Assign(6, make_intrusive<IntervalVal>(double(minimum), Seconds)); r->Assign(6, zeek::make_intrusive<IntervalVal>(double(minimum), Seconds));
analyzer->EnqueueConnEvent(dns_SOA_reply, analyzer->EnqueueConnEvent(dns_SOA_reply,
analyzer->ConnVal(), analyzer->ConnVal(),
@ -646,7 +646,7 @@ bool DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<StringVal>(new BroString(name, name_end - name, true)), zeek::make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
val_mgr->Count(preference) val_mgr->Count(preference)
); );
@ -687,7 +687,7 @@ bool DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<StringVal>(new BroString(name, name_end - name, true)), zeek::make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
val_mgr->Count(priority), val_mgr->Count(priority),
val_mgr->Count(weight), val_mgr->Count(weight),
val_mgr->Count(port) val_mgr->Count(port)
@ -1009,7 +1009,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
int typebitmaps_len = rdlength - (data - data_start); int typebitmaps_len = rdlength - (data - data_start);
auto char_strings = make_intrusive<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
while ( typebitmaps_len > 0 && len > 0 ) while ( typebitmaps_len > 0 && len > 0 )
{ {
@ -1024,7 +1024,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
} }
BroString* bitmap = ExtractStream(data, len, bmlen); BroString* bitmap = ExtractStream(data, len, bmlen);
char_strings->Assign(char_strings->Size(), make_intrusive<StringVal>(bitmap)); char_strings->Assign(char_strings->Size(), zeek::make_intrusive<StringVal>(bitmap));
typebitmaps_len = typebitmaps_len - (2 + bmlen); typebitmaps_len = typebitmaps_len - (2 + bmlen);
} }
@ -1033,7 +1033,7 @@ bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<StringVal>(new BroString(name, name_end - name, true)), zeek::make_intrusive<StringVal>(new BroString(name, name_end - name, true)),
std::move(char_strings) std::move(char_strings)
); );
@ -1084,7 +1084,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg,
int typebitmaps_len = rdlength - (data - data_start); int typebitmaps_len = rdlength - (data - data_start);
auto char_strings = make_intrusive<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
while ( typebitmaps_len > 0 && len > 0 ) while ( typebitmaps_len > 0 && len > 0 )
{ {
@ -1099,7 +1099,7 @@ bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg,
} }
BroString* bitmap = ExtractStream(data, len, bmlen); BroString* bitmap = ExtractStream(data, len, bmlen);
char_strings->Assign(char_strings->Size(), make_intrusive<StringVal>(bitmap)); char_strings->Assign(char_strings->Size(), zeek::make_intrusive<StringVal>(bitmap));
typebitmaps_len = typebitmaps_len - (2 + bmlen); typebitmaps_len = typebitmaps_len - (2 + bmlen);
} }
@ -1200,7 +1200,7 @@ bool DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<AddrVal>(htonl(addr)) zeek::make_intrusive<AddrVal>(htonl(addr))
); );
return true; return true;
@ -1236,7 +1236,7 @@ bool DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
make_intrusive<AddrVal>(addr) zeek::make_intrusive<AddrVal>(addr)
); );
return true; return true;
@ -1260,7 +1260,7 @@ bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg,
return true; return true;
} }
static IntrusivePtr<StringVal> static zeek::IntrusivePtr<StringVal>
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)
{ {
@ -1279,7 +1279,7 @@ extract_char_string(analyzer::Analyzer* analyzer,
return nullptr; return nullptr;
} }
auto rval = make_intrusive<StringVal>(str_size, reinterpret_cast<const char*>(data)); auto rval = zeek::make_intrusive<StringVal>(str_size, reinterpret_cast<const char*>(data));
rdlen -= str_size; rdlen -= str_size;
len -= str_size; len -= str_size;
@ -1299,8 +1299,8 @@ bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg,
return true; return true;
} }
auto char_strings = make_intrusive<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
IntrusivePtr<StringVal> char_string; zeek::IntrusivePtr<StringVal> 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));
@ -1327,8 +1327,8 @@ bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg,
return true; return true;
} }
auto char_strings = make_intrusive<VectorVal>(zeek::id::string_vec); auto char_strings = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
IntrusivePtr<StringVal> char_string; zeek::IntrusivePtr<StringVal> 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));
@ -1380,8 +1380,8 @@ bool DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg,
msg->BuildHdrVal(), msg->BuildHdrVal(),
msg->BuildAnswerVal(), msg->BuildAnswerVal(),
val_mgr->Count(flags), val_mgr->Count(flags),
make_intrusive<StringVal>(tag), zeek::make_intrusive<StringVal>(tag),
make_intrusive<StringVal>(value) zeek::make_intrusive<StringVal>(value)
); );
else else
{ {
@ -1407,10 +1407,10 @@ void DNS_Interpreter::SendReplyOrRejectEvent(DNS_MsgInfo* msg,
analyzer->EnqueueConnEvent(event, analyzer->EnqueueConnEvent(event,
analyzer->ConnVal(), analyzer->ConnVal(),
msg->BuildHdrVal(), msg->BuildHdrVal(),
make_intrusive<StringVal>(question_name), zeek::make_intrusive<StringVal>(question_name),
val_mgr->Count(qtype), val_mgr->Count(qtype),
val_mgr->Count(qclass), val_mgr->Count(qclass),
make_intrusive<StringVal>(original_name) zeek::make_intrusive<StringVal>(original_name)
); );
} }
@ -1446,10 +1446,10 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query)
skip_event = 0; skip_event = 0;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal() zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_msg); auto r = zeek::make_intrusive<RecordVal>(dns_msg);
r->Assign(0, val_mgr->Count(id)); r->Assign(0, val_mgr->Count(id));
r->Assign(1, val_mgr->Count(opcode)); r->Assign(1, val_mgr->Count(opcode));
@ -1468,26 +1468,26 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal()
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildAnswerVal() zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_answer); auto r = zeek::make_intrusive<RecordVal>(dns_answer);
r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(0, val_mgr->Count(int(answer_type)));
r->Assign(1, query_name); r->Assign(1, query_name);
r->Assign(2, val_mgr->Count(atype)); r->Assign(2, val_mgr->Count(atype));
r->Assign(3, val_mgr->Count(aclass)); r->Assign(3, val_mgr->Count(aclass));
r->Assign(4, make_intrusive<IntervalVal>(double(ttl), Seconds)); r->Assign(4, zeek::make_intrusive<IntervalVal>(double(ttl), Seconds));
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val() zeek::IntrusivePtr<RecordVal> 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.
static auto dns_edns_additional = zeek::id::find_type<zeek::RecordType>("dns_edns_additional"); static auto dns_edns_additional = zeek::id::find_type<zeek::RecordType>("dns_edns_additional");
auto r = make_intrusive<RecordVal>(dns_edns_additional); auto r = zeek::make_intrusive<RecordVal>(dns_edns_additional);
r->Assign(0, val_mgr->Count(int(answer_type))); r->Assign(0, val_mgr->Count(int(answer_type)));
r->Assign(1, query_name); r->Assign(1, query_name);
@ -1512,25 +1512,25 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val()
r->Assign(4, val_mgr->Count(return_error)); r->Assign(4, val_mgr->Count(return_error));
r->Assign(5, val_mgr->Count(version)); r->Assign(5, val_mgr->Count(version));
r->Assign(6, val_mgr->Count(z)); r->Assign(6, val_mgr->Count(z));
r->Assign(7, make_intrusive<IntervalVal>(double(ttl), Seconds)); r->Assign(7, zeek::make_intrusive<IntervalVal>(double(ttl), Seconds));
r->Assign(8, val_mgr->Count(is_query)); r->Assign(8, val_mgr->Count(is_query));
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_tsig_additional); auto r = zeek::make_intrusive<RecordVal>(dns_tsig_additional);
double rtime = tsig->time_s + tsig->time_ms / 1000.0; double rtime = tsig->time_s + tsig->time_ms / 1000.0;
// r->Assign(0, val_mgr->Count(int(answer_type))); // r->Assign(0, val_mgr->Count(int(answer_type)));
r->Assign(0, query_name); r->Assign(0, query_name);
r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(1, val_mgr->Count(int(answer_type)));
r->Assign(2, make_intrusive<StringVal>(tsig->alg_name)); r->Assign(2, zeek::make_intrusive<StringVal>(tsig->alg_name));
r->Assign(3, make_intrusive<StringVal>(tsig->sig)); r->Assign(3, zeek::make_intrusive<StringVal>(tsig->sig));
r->Assign(4, make_intrusive<TimeVal>(rtime)); r->Assign(4, zeek::make_intrusive<TimeVal>(rtime));
r->Assign(5, make_intrusive<TimeVal>(double(tsig->fudge))); r->Assign(5, zeek::make_intrusive<TimeVal>(double(tsig->fudge)));
r->Assign(6, val_mgr->Count(tsig->orig_id)); r->Assign(6, val_mgr->Count(tsig->orig_id));
r->Assign(7, val_mgr->Count(tsig->rr_error)); r->Assign(7, val_mgr->Count(tsig->rr_error));
r->Assign(8, val_mgr->Count(is_query)); r->Assign(8, val_mgr->Count(is_query));
@ -1538,47 +1538,47 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig)
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_rrsig_rr); auto r = zeek::make_intrusive<RecordVal>(dns_rrsig_rr);
r->Assign(0, query_name); r->Assign(0, query_name);
r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(1, val_mgr->Count(int(answer_type)));
r->Assign(2, val_mgr->Count(rrsig->type_covered)); r->Assign(2, val_mgr->Count(rrsig->type_covered));
r->Assign(3, val_mgr->Count(rrsig->algorithm)); r->Assign(3, val_mgr->Count(rrsig->algorithm));
r->Assign(4, val_mgr->Count(rrsig->labels)); r->Assign(4, val_mgr->Count(rrsig->labels));
r->Assign(5, make_intrusive<IntervalVal>(double(rrsig->orig_ttl), Seconds)); r->Assign(5, zeek::make_intrusive<IntervalVal>(double(rrsig->orig_ttl), Seconds));
r->Assign(6, make_intrusive<TimeVal>(double(rrsig->sig_exp))); r->Assign(6, zeek::make_intrusive<TimeVal>(double(rrsig->sig_exp)));
r->Assign(7, make_intrusive<TimeVal>(double(rrsig->sig_incep))); r->Assign(7, zeek::make_intrusive<TimeVal>(double(rrsig->sig_incep)));
r->Assign(8, val_mgr->Count(rrsig->key_tag)); r->Assign(8, val_mgr->Count(rrsig->key_tag));
r->Assign(9, make_intrusive<StringVal>(rrsig->signer_name)); r->Assign(9, zeek::make_intrusive<StringVal>(rrsig->signer_name));
r->Assign(10, make_intrusive<StringVal>(rrsig->signature)); r->Assign(10, zeek::make_intrusive<StringVal>(rrsig->signature));
r->Assign(11, val_mgr->Count(is_query)); r->Assign(11, val_mgr->Count(is_query));
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_dnskey_rr); auto r = zeek::make_intrusive<RecordVal>(dns_dnskey_rr);
r->Assign(0, query_name); r->Assign(0, query_name);
r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(1, val_mgr->Count(int(answer_type)));
r->Assign(2, val_mgr->Count(dnskey->dflags)); r->Assign(2, val_mgr->Count(dnskey->dflags));
r->Assign(3, val_mgr->Count(dnskey->dprotocol)); r->Assign(3, val_mgr->Count(dnskey->dprotocol));
r->Assign(4, val_mgr->Count(dnskey->dalgorithm)); r->Assign(4, val_mgr->Count(dnskey->dalgorithm));
r->Assign(5, make_intrusive<StringVal>(dnskey->public_key)); r->Assign(5, zeek::make_intrusive<StringVal>(dnskey->public_key));
r->Assign(6, val_mgr->Count(is_query)); r->Assign(6, val_mgr->Count(is_query));
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_nsec3_rr); auto r = zeek::make_intrusive<RecordVal>(dns_nsec3_rr);
r->Assign(0, query_name); r->Assign(0, query_name);
r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(1, val_mgr->Count(int(answer_type)));
@ -1586,26 +1586,26 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3)
r->Assign(3, val_mgr->Count(nsec3->nsec_hash_algo)); r->Assign(3, val_mgr->Count(nsec3->nsec_hash_algo));
r->Assign(4, val_mgr->Count(nsec3->nsec_iter)); r->Assign(4, val_mgr->Count(nsec3->nsec_iter));
r->Assign(5, val_mgr->Count(nsec3->nsec_salt_len)); r->Assign(5, val_mgr->Count(nsec3->nsec_salt_len));
r->Assign(6, make_intrusive<StringVal>(nsec3->nsec_salt)); r->Assign(6, zeek::make_intrusive<StringVal>(nsec3->nsec_salt));
r->Assign(7, val_mgr->Count(nsec3->nsec_hlen)); r->Assign(7, val_mgr->Count(nsec3->nsec_hlen));
r->Assign(8, make_intrusive<StringVal>(nsec3->nsec_hash)); r->Assign(8, zeek::make_intrusive<StringVal>(nsec3->nsec_hash));
r->Assign(9, std::move(nsec3->bitmaps)); r->Assign(9, std::move(nsec3->bitmaps));
r->Assign(10, val_mgr->Count(is_query)); r->Assign(10, val_mgr->Count(is_query));
return r; return r;
} }
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDS_Val(DS_DATA* ds) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(dns_ds_rr); auto r = zeek::make_intrusive<RecordVal>(dns_ds_rr);
r->Assign(0, query_name); r->Assign(0, query_name);
r->Assign(1, val_mgr->Count(int(answer_type))); r->Assign(1, val_mgr->Count(int(answer_type)));
r->Assign(2, val_mgr->Count(ds->key_tag)); r->Assign(2, val_mgr->Count(ds->key_tag));
r->Assign(3, val_mgr->Count(ds->algorithm)); r->Assign(3, val_mgr->Count(ds->algorithm));
r->Assign(4, val_mgr->Count(ds->digest_type)); r->Assign(4, val_mgr->Count(ds->digest_type));
r->Assign(5, make_intrusive<StringVal>(ds->digest_val)); r->Assign(5, zeek::make_intrusive<StringVal>(ds->digest_val));
r->Assign(6, val_mgr->Count(is_query)); r->Assign(6, val_mgr->Count(is_query));
return r; return r;

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;
IntrusivePtr<VectorVal> bitmaps; zeek::IntrusivePtr<VectorVal> 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);
IntrusivePtr<RecordVal> BuildHdrVal(); zeek::IntrusivePtr<RecordVal> BuildHdrVal();
IntrusivePtr<RecordVal> BuildAnswerVal(); zeek::IntrusivePtr<RecordVal> BuildAnswerVal();
IntrusivePtr<RecordVal> BuildEDNS_Val(); zeek::IntrusivePtr<RecordVal> BuildEDNS_Val();
IntrusivePtr<RecordVal> BuildTSIG_Val(struct TSIG_DATA*); zeek::IntrusivePtr<RecordVal> BuildTSIG_Val(struct TSIG_DATA*);
IntrusivePtr<RecordVal> BuildRRSIG_Val(struct RRSIG_DATA*); zeek::IntrusivePtr<RecordVal> BuildRRSIG_Val(struct RRSIG_DATA*);
IntrusivePtr<RecordVal> BuildDNSKEY_Val(struct DNSKEY_DATA*); zeek::IntrusivePtr<RecordVal> BuildDNSKEY_Val(struct DNSKEY_DATA*);
IntrusivePtr<RecordVal> BuildNSEC3_Val(struct NSEC3_DATA*); zeek::IntrusivePtr<RecordVal> BuildNSEC3_Val(struct NSEC3_DATA*);
IntrusivePtr<RecordVal> BuildDS_Val(struct DS_DATA*); zeek::IntrusivePtr<RecordVal> 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
IntrusivePtr<StringVal> query_name; zeek::IntrusivePtr<StringVal> 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

@ -79,10 +79,11 @@ void File_Analyzer::Identify()
: *(matches.begin()->second.begin()); : *(matches.begin()->second.begin());
if ( file_transferred ) if ( file_transferred )
EnqueueConnEvent(file_transferred, EnqueueConnEvent(
file_transferred,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(buffer_len, buffer), zeek::make_intrusive<StringVal>(buffer_len, buffer),
make_intrusive<StringVal>("<unknown>"), zeek::make_intrusive<StringVal>("<unknown>"),
make_intrusive<StringVal>(match) zeek::make_intrusive<StringVal>(match)
); );
} }

View file

@ -70,8 +70,8 @@ void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig
EnqueueConnEvent(finger_request, EnqueueConnEvent(finger_request,
ConnVal(), ConnVal(),
val_mgr->Bool(long_cnt), val_mgr->Bool(long_cnt),
make_intrusive<StringVal>(at - line, line), zeek::make_intrusive<StringVal>(at - line, line),
make_intrusive<StringVal>(end_of_line - host, host) zeek::make_intrusive<StringVal>(end_of_line - host, host)
); );
Conn()->Match(Rule::FINGER, (const u_char *) line, Conn()->Match(Rule::FINGER, (const u_char *) line,
@ -87,7 +87,7 @@ void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig
EnqueueConnEvent(finger_reply, EnqueueConnEvent(finger_reply,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(end_of_line - line, line) zeek::make_intrusive<StringVal>(end_of_line - line, line)
); );
} }
} }

View file

@ -98,8 +98,8 @@ void FTP_Analyzer::DeliverStream(int length, const u_char* data, bool orig)
vl = { vl = {
ConnVal(), ConnVal(),
IntrusivePtr{AdoptRef{}, cmd_str}, zeek::IntrusivePtr{zeek::AdoptRef{}, cmd_str},
make_intrusive<StringVal>(end_of_line - line, line), zeek::make_intrusive<StringVal>(end_of_line - line, line),
}; };
f = ftp_request; f = ftp_request;
@ -178,7 +178,7 @@ void FTP_Analyzer::DeliverStream(int length, const u_char* data, bool orig)
vl = { vl = {
ConnVal(), ConnVal(),
val_mgr->Count(reply_code), val_mgr->Count(reply_code),
make_intrusive<StringVal>(end_of_line - line, line), zeek::make_intrusive<StringVal>(end_of_line - line, line),
val_mgr->Bool(cont_resp) val_mgr->Bool(cont_resp)
}; };

View file

@ -4,9 +4,9 @@ type ftp_port: record;
%%{ %%{
#include "Reporter.h" #include "Reporter.h"
static IntrusivePtr<Val> parse_port(const char* line) static zeek::IntrusivePtr<Val> parse_port(const char* line)
{ {
auto r = make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port);
int bytes[6]; int bytes[6];
if ( line && sscanf(line, "%d,%d,%d,%d,%d,%d", if ( line && sscanf(line, "%d,%d,%d,%d,%d,%d",
@ -33,13 +33,13 @@ static IntrusivePtr<Val> parse_port(const char* line)
good = 0; good = 0;
} }
r->Assign(0, make_intrusive<AddrVal>(htonl(addr))); r->Assign(0, zeek::make_intrusive<AddrVal>(htonl(addr)));
r->Assign(1, val_mgr->Port(port, TRANSPORT_TCP)); r->Assign(1, val_mgr->Port(port, TRANSPORT_TCP));
r->Assign(2, val_mgr->Bool(good)); r->Assign(2, val_mgr->Bool(good));
} }
else else
{ {
r->Assign(0, make_intrusive<AddrVal>(uint32_t(0))); r->Assign(0, zeek::make_intrusive<AddrVal>(uint32_t(0)));
r->Assign(1, val_mgr->Port(0, TRANSPORT_TCP)); r->Assign(1, val_mgr->Port(0, TRANSPORT_TCP));
r->Assign(2, val_mgr->False()); r->Assign(2, val_mgr->False());
} }
@ -47,9 +47,9 @@ static IntrusivePtr<Val> parse_port(const char* line)
return r; return r;
} }
static IntrusivePtr<Val> parse_eftp(const char* line) static zeek::IntrusivePtr<Val> parse_eftp(const char* line)
{ {
auto r = make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port); auto r = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::ftp_port);
int net_proto = 0; // currently not used int net_proto = 0; // currently not used
IPAddr addr; // unspecified IPv6 address (all 128 bits zero) IPAddr addr; // unspecified IPv6 address (all 128 bits zero)
@ -109,7 +109,7 @@ static IntrusivePtr<Val> parse_eftp(const char* line)
} }
r->Assign(0, make_intrusive<AddrVal>(addr)); r->Assign(0, zeek::make_intrusive<AddrVal>(addr));
r->Assign(1, val_mgr->Port(port, TRANSPORT_TCP)); r->Assign(1, val_mgr->Port(port, TRANSPORT_TCP));
r->Assign(2, val_mgr->Bool(good)); r->Assign(2, val_mgr->Bool(good));
@ -206,10 +206,10 @@ function fmt_ftp_port%(a: addr, p: port%): string
{ {
uint32_t a = ntohl(addr[0]); uint32_t a = ntohl(addr[0]);
uint32_t pn = p->Port(); uint32_t pn = p->Port();
return make_intrusive<StringVal>(fmt("%d,%d,%d,%d,%d,%d", return zeek::make_intrusive<StringVal>(fmt("%d,%d,%d,%d,%d,%d",
a >> 24, (a >> 16) & 0xff, a >> 24, (a >> 16) & 0xff,
(a >> 8) & 0xff, a & 0xff, (a >> 8) & 0xff, a & 0xff,
pn >> 8, pn & 0xff)); pn >> 8, pn & 0xff));
} }
else else
{ {

View file

@ -73,7 +73,7 @@ void Gnutella_Analyzer::Done()
if ( ! p->msg_sent && p->msg_pos ) if ( ! p->msg_sent && p->msg_pos )
EnqueueConnEvent(gnutella_partial_binary_msg, EnqueueConnEvent(gnutella_partial_binary_msg,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(p->msg), zeek::make_intrusive<StringVal>(p->msg),
val_mgr->Bool((i == 0)), val_mgr->Bool((i == 0)),
val_mgr->Count(p->msg_pos) val_mgr->Count(p->msg_pos)
); );
@ -179,7 +179,7 @@ void Gnutella_Analyzer::DeliverLines(int len, const u_char* data, bool orig)
EnqueueConnEvent(gnutella_text_msg, EnqueueConnEvent(gnutella_text_msg,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(ms->headers.data()) zeek::make_intrusive<StringVal>(ms->headers.data())
); );
ms->headers = ""; ms->headers = "";
@ -221,7 +221,7 @@ void Gnutella_Analyzer::SendEvents(GnutellaMsgState* p, bool is_orig)
val_mgr->Count(p->msg_ttl), val_mgr->Count(p->msg_ttl),
val_mgr->Count(p->msg_hops), val_mgr->Count(p->msg_hops),
val_mgr->Count(p->msg_len), val_mgr->Count(p->msg_len),
make_intrusive<StringVal>(p->payload), zeek::make_intrusive<StringVal>(p->payload),
val_mgr->Count(p->payload_len), val_mgr->Count(p->payload_len),
val_mgr->Bool((p->payload_len < std::min(p->msg_len, (unsigned int)GNUTELLA_MAX_PAYLOAD))), val_mgr->Bool((p->payload_len < std::min(p->msg_len, (unsigned int)GNUTELLA_MAX_PAYLOAD))),
val_mgr->Bool((p->payload_left == 0)) val_mgr->Bool((p->payload_left == 0))

View file

@ -4,9 +4,9 @@
%} %}
%code{ %code{
IntrusivePtr<RecordVal> BuildGTPv1Hdr(const GTPv1_Header* pdu) zeek::IntrusivePtr<RecordVal> BuildGTPv1Hdr(const GTPv1_Header* pdu)
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::gtpv1_hdr); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtpv1_hdr);
rv->Assign(0, val_mgr->Count(pdu->version())); rv->Assign(0, val_mgr->Count(pdu->version()));
rv->Assign(1, val_mgr->Bool(pdu->pt_flag())); rv->Assign(1, val_mgr->Bool(pdu->pt_flag()));
@ -28,14 +28,14 @@ IntrusivePtr<RecordVal> BuildGTPv1Hdr(const GTPv1_Header* pdu)
return rv; return rv;
} }
static IntrusivePtr<Val> BuildIMSI(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildIMSI(const InformationElement* ie)
{ {
return val_mgr->Count(ie->imsi()->value()); return val_mgr->Count(ie->imsi()->value());
} }
static IntrusivePtr<Val> BuildRAI(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildRAI(const InformationElement* ie)
{ {
auto ev = 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()));
ev->Assign(1, val_mgr->Count(ie->rai()->mnc())); ev->Assign(1, val_mgr->Count(ie->rai()->mnc()));
ev->Assign(2, val_mgr->Count(ie->rai()->lac())); ev->Assign(2, val_mgr->Count(ie->rai()->lac()));
@ -43,49 +43,49 @@ static IntrusivePtr<Val> BuildRAI(const InformationElement* ie)
return ev; return ev;
} }
static IntrusivePtr<Val> BuildRecovery(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildRecovery(const InformationElement* ie)
{ {
return val_mgr->Count(ie->recovery()->restart_counter()); return val_mgr->Count(ie->recovery()->restart_counter());
} }
static IntrusivePtr<Val> BuildSelectionMode(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildSelectionMode(const InformationElement* ie)
{ {
return val_mgr->Count(ie->selection_mode()->mode()); return val_mgr->Count(ie->selection_mode()->mode());
} }
static IntrusivePtr<Val> BuildTEID1(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildTEID1(const InformationElement* ie)
{ {
return val_mgr->Count(ie->teid1()->value()); return val_mgr->Count(ie->teid1()->value());
} }
static IntrusivePtr<Val> BuildTEID_ControlPlane(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildTEID_ControlPlane(const InformationElement* ie)
{ {
return val_mgr->Count(ie->teidcp()->value()); return val_mgr->Count(ie->teidcp()->value());
} }
static IntrusivePtr<Val> BuildNSAPI(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildNSAPI(const InformationElement* ie)
{ {
return val_mgr->Count(ie->nsapi()->nsapi()); return val_mgr->Count(ie->nsapi()->nsapi());
} }
static IntrusivePtr<Val> BuildChargingCharacteristics(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildChargingCharacteristics(const InformationElement* ie)
{ {
return val_mgr->Count(ie->charging_characteristics()->value()); return val_mgr->Count(ie->charging_characteristics()->value());
} }
static IntrusivePtr<Val> BuildTraceReference(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildTraceReference(const InformationElement* ie)
{ {
return val_mgr->Count(ie->trace_reference()->value()); return val_mgr->Count(ie->trace_reference()->value());
} }
static IntrusivePtr<Val> BuildTraceType(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildTraceType(const InformationElement* ie)
{ {
return val_mgr->Count(ie->trace_type()->value()); return val_mgr->Count(ie->trace_type()->value());
} }
IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie) zeek::IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie)
{ {
auto ev = 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()));
ev->Assign(1, val_mgr->Count(ie->end_user_addr()->pdp_type_num())); ev->Assign(1, val_mgr->Count(ie->end_user_addr()->pdp_type_num()));
@ -97,15 +97,15 @@ IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie)
switch ( ie->end_user_addr()->pdp_type_num() ) { switch ( ie->end_user_addr()->pdp_type_num() ) {
case 0x21: case 0x21:
ev->Assign(2, make_intrusive<AddrVal>( ev->Assign(2, zeek::make_intrusive<AddrVal>(
IPAddr(IPv4, (const uint32*) d, IPAddr::Network))); IPAddr(IPv4, (const uint32*) d, IPAddr::Network)));
break; break;
case 0x57: case 0x57:
ev->Assign(2, make_intrusive<AddrVal>( ev->Assign(2, zeek::make_intrusive<AddrVal>(
IPAddr(IPv6, (const uint32*) d, IPAddr::Network))); IPAddr(IPv6, (const uint32*) d, IPAddr::Network)));
break; break;
default: default:
ev->Assign(3, make_intrusive<StringVal>( ev->Assign(3, zeek::make_intrusive<StringVal>(
new BroString((const u_char*) d, len, false))); new BroString((const u_char*) d, len, false)));
break; break;
} }
@ -114,121 +114,121 @@ IntrusivePtr<Val> BuildEndUserAddr(const InformationElement* ie)
return ev; return ev;
} }
IntrusivePtr<Val> BuildAccessPointName(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(bs); return zeek::make_intrusive<StringVal>(bs);
} }
IntrusivePtr<Val> BuildProtoConfigOptions(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(new BroString(d, len, false)); return zeek::make_intrusive<StringVal>(new BroString(d, len, false));
} }
IntrusivePtr<Val> BuildGSN_Addr(const InformationElement* ie) zeek::IntrusivePtr<Val> BuildGSN_Addr(const InformationElement* ie)
{ {
auto ev = make_intrusive<RecordVal>(zeek::BifType::Record::gtp_gsn_addr); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_gsn_addr);
int len = ie->gsn_addr()->value().length(); int len = ie->gsn_addr()->value().length();
const uint8* d = ie->gsn_addr()->value().data(); const uint8* d = ie->gsn_addr()->value().data();
if ( len == 4 ) if ( len == 4 )
ev->Assign(0, make_intrusive<AddrVal>( ev->Assign(0, zeek::make_intrusive<AddrVal>(
IPAddr(IPv4, (const uint32*) d, IPAddr::Network))); IPAddr(IPv4, (const uint32*) d, IPAddr::Network)));
else if ( len == 16 ) else if ( len == 16 )
ev->Assign(0, make_intrusive<AddrVal>( ev->Assign(0, zeek::make_intrusive<AddrVal>(
IPAddr(IPv6, (const uint32*) d, IPAddr::Network))); IPAddr(IPv6, (const uint32*) d, IPAddr::Network)));
else else
ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, false))); ev->Assign(1, zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)));
return ev; return ev;
} }
IntrusivePtr<Val> BuildMSISDN(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(new BroString(d, len, false)); return zeek::make_intrusive<StringVal>(new BroString(d, len, false));
} }
IntrusivePtr<Val> BuildQoS_Profile(const InformationElement* ie) zeek::IntrusivePtr<Val> BuildQoS_Profile(const InformationElement* ie)
{ {
auto ev = make_intrusive<RecordVal>(zeek::BifType::Record::gtp_qos_profile); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_qos_profile);
const u_char* d = (const u_char*) ie->qos_profile()->data().data(); const u_char* d = (const u_char*) ie->qos_profile()->data().data();
int len = ie->qos_profile()->data().length(); int len = ie->qos_profile()->data().length();
ev->Assign(0, val_mgr->Count(ie->qos_profile()->alloc_retention_priority())); ev->Assign(0, val_mgr->Count(ie->qos_profile()->alloc_retention_priority()));
ev->Assign(1, make_intrusive<StringVal>(new BroString(d, len, false))); ev->Assign(1, zeek::make_intrusive<StringVal>(new BroString(d, len, false)));
return ev; return ev;
} }
IntrusivePtr<Val> BuildTrafficFlowTemplate(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
IntrusivePtr<Val> BuildTriggerID(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
IntrusivePtr<Val> BuildOMC_ID(const InformationElement* ie) zeek::IntrusivePtr<Val> 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 make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)); return zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false));
} }
IntrusivePtr<Val> BuildPrivateExt(const InformationElement* ie) zeek::IntrusivePtr<Val> BuildPrivateExt(const InformationElement* ie)
{ {
auto ev = make_intrusive<RecordVal>(zeek::BifType::Record::gtp_private_extension); auto ev = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::gtp_private_extension);
const uint8* d = ie->private_ext()->value().data(); const uint8* d = ie->private_ext()->value().data();
int len = ie->private_ext()->value().length(); int len = ie->private_ext()->value().length();
ev->Assign(0, val_mgr->Count(ie->private_ext()->id())); ev->Assign(0, val_mgr->Count(ie->private_ext()->id()));
ev->Assign(1, make_intrusive<StringVal>(new BroString((const u_char*) d, len, false))); ev->Assign(1, zeek::make_intrusive<StringVal>(new BroString((const u_char*) d, len, false)));
return ev; return ev;
} }
static IntrusivePtr<Val> BuildCause(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildCause(const InformationElement* ie)
{ {
return val_mgr->Count(ie->cause()->value()); return val_mgr->Count(ie->cause()->value());
} }
static IntrusivePtr<Val> BuildReorderReq(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildReorderReq(const InformationElement* ie)
{ {
return val_mgr->Bool(ie->reorder_req()->req()); return val_mgr->Bool(ie->reorder_req()->req());
} }
static IntrusivePtr<Val> BuildChargingID(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildChargingID(const InformationElement* ie)
{ {
return val_mgr->Count(ie->charging_id()->value());; return val_mgr->Count(ie->charging_id()->value());;
} }
IntrusivePtr<Val> BuildChargingGatewayAddr(const InformationElement* ie) zeek::IntrusivePtr<Val> 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();
if ( len == 4 ) if ( len == 4 )
return make_intrusive<AddrVal>(IPAddr(IPv4, (const uint32*) d, IPAddr::Network)); return zeek::make_intrusive<AddrVal>(IPAddr(IPv4, (const uint32*) d, IPAddr::Network));
else if ( len == 16 ) else if ( len == 16 )
return make_intrusive<AddrVal>(IPAddr(IPv6, (const uint32*) d, IPAddr::Network)); return zeek::make_intrusive<AddrVal>(IPAddr(IPv6, (const uint32*) d, IPAddr::Network));
else else
return nullptr; return nullptr;
} }
static IntrusivePtr<Val> BuildTeardownInd(const InformationElement* ie) static zeek::IntrusivePtr<Val> BuildTeardownInd(const InformationElement* ie)
{ {
return val_mgr->Bool(ie->teardown_ind()->ind()); return val_mgr->Bool(ie->teardown_ind()->ind());
} }
@ -237,7 +237,7 @@ void CreatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu)
{ {
if ( ! ::gtpv1_create_pdp_ctx_request ) return; if ( ! ::gtpv1_create_pdp_ctx_request ) return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_create_pdp_ctx_request_elements); zeek::BifType::Record::gtp_create_pdp_ctx_request_elements);
const vector<InformationElement *> * v = pdu->create_pdp_ctx_request(); const vector<InformationElement *> * v = pdu->create_pdp_ctx_request();
@ -337,7 +337,7 @@ void CreatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu)
if ( ! ::gtpv1_create_pdp_ctx_response ) if ( ! ::gtpv1_create_pdp_ctx_response )
return; return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_create_pdp_ctx_response_elements); zeek::BifType::Record::gtp_create_pdp_ctx_response_elements);
const vector<InformationElement *> * v = pdu->create_pdp_ctx_response(); const vector<InformationElement *> * v = pdu->create_pdp_ctx_response();
@ -406,7 +406,7 @@ void UpdatePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu)
if ( ! ::gtpv1_update_pdp_ctx_request ) if ( ! ::gtpv1_update_pdp_ctx_request )
return; return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_update_pdp_ctx_request_elements); zeek::BifType::Record::gtp_update_pdp_ctx_request_elements);
const vector<InformationElement *> * v = pdu->update_pdp_ctx_request(); const vector<InformationElement *> * v = pdu->update_pdp_ctx_request();
@ -484,7 +484,7 @@ void UpdatePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu)
if ( ! ::gtpv1_update_pdp_ctx_response ) if ( ! ::gtpv1_update_pdp_ctx_response )
return; return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_update_pdp_ctx_response_elements); zeek::BifType::Record::gtp_update_pdp_ctx_response_elements);
const vector<InformationElement *> * v = pdu->update_pdp_ctx_response(); const vector<InformationElement *> * v = pdu->update_pdp_ctx_response();
@ -544,7 +544,7 @@ void DeletePDP_Request(const BroAnalyzer& a, const GTPv1_Header* pdu)
if ( ! ::gtpv1_delete_pdp_ctx_request ) if ( ! ::gtpv1_delete_pdp_ctx_request )
return; return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_delete_pdp_ctx_request_elements); zeek::BifType::Record::gtp_delete_pdp_ctx_request_elements);
const vector<InformationElement *> * v = pdu->delete_pdp_ctx_request(); const vector<InformationElement *> * v = pdu->delete_pdp_ctx_request();
@ -578,7 +578,7 @@ void DeletePDP_Response(const BroAnalyzer& a, const GTPv1_Header* pdu)
if ( ! ::gtpv1_delete_pdp_ctx_response ) if ( ! ::gtpv1_delete_pdp_ctx_response )
return; return;
auto rv = make_intrusive<RecordVal>( auto rv = zeek::make_intrusive<RecordVal>(
zeek::BifType::Record::gtp_delete_pdp_ctx_response_elements); zeek::BifType::Record::gtp_delete_pdp_ctx_response_elements);
const vector<InformationElement *> * v = pdu->delete_pdp_ctx_response(); const vector<InformationElement *> * v = pdu->delete_pdp_ctx_response();

View file

@ -613,14 +613,14 @@ HTTP_Message::~HTTP_Message()
delete [] entity_data_buffer; delete [] entity_data_buffer;
} }
IntrusivePtr<RecordVal> HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) zeek::IntrusivePtr<RecordVal> 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 = make_intrusive<RecordVal>(http_message_stat); auto stat = zeek::make_intrusive<RecordVal>(http_message_stat);
int field = 0; int field = 0;
stat->Assign(field++, make_intrusive<TimeVal>(start_time)); stat->Assign(field++, zeek::make_intrusive<TimeVal>(start_time));
stat->Assign(field++, val_mgr->Bool(interrupted)); stat->Assign(field++, val_mgr->Bool(interrupted));
stat->Assign(field++, make_intrusive<StringVal>(msg)); stat->Assign(field++, zeek::make_intrusive<StringVal>(msg));
stat->Assign(field++, val_mgr->Count(body_length)); stat->Assign(field++, val_mgr->Count(body_length));
stat->Assign(field++, val_mgr->Count(content_gap_length)); stat->Assign(field++, val_mgr->Count(content_gap_length));
stat->Assign(field++, val_mgr->Count(header_length)); stat->Assign(field++, val_mgr->Count(header_length));
@ -1153,11 +1153,11 @@ void HTTP_Analyzer::GenStats()
if ( http_stats ) if ( http_stats )
{ {
static auto http_stats_rec = zeek::id::find_type<zeek::RecordType>("http_stats_rec"); static auto http_stats_rec = zeek::id::find_type<zeek::RecordType>("http_stats_rec");
auto r = make_intrusive<RecordVal>(http_stats_rec); auto r = zeek::make_intrusive<RecordVal>(http_stats_rec);
r->Assign(0, val_mgr->Count(num_requests)); r->Assign(0, val_mgr->Count(num_requests));
r->Assign(1, val_mgr->Count(num_replies)); r->Assign(1, val_mgr->Count(num_replies));
r->Assign(2, make_intrusive<DoubleVal>(request_version.ToDouble())); r->Assign(2, zeek::make_intrusive<DoubleVal>(request_version.ToDouble()));
r->Assign(3, make_intrusive<DoubleVal>(reply_version.ToDouble())); r->Assign(3, zeek::make_intrusive<DoubleVal>(reply_version.ToDouble()));
// DEBUG_MSG("%.6f http_stats\n", network_time); // DEBUG_MSG("%.6f http_stats\n", network_time);
EnqueueConnEvent(http_stats, ConnVal(), std::move(r)); EnqueueConnEvent(http_stats, ConnVal(), std::move(r));
@ -1242,7 +1242,7 @@ int HTTP_Analyzer::HTTP_RequestLine(const char* line, const char* end_of_line)
return -1; return -1;
} }
request_method = make_intrusive<StringVal>(end_of_method - line, line); request_method = zeek::make_intrusive<StringVal>(end_of_method - line, line);
Conn()->Match(Rule::HTTP_REQUEST, Conn()->Match(Rule::HTTP_REQUEST,
(const u_char*) unescaped_URI->AsString()->Bytes(), (const u_char*) unescaped_URI->AsString()->Bytes(),
@ -1312,8 +1312,8 @@ bool HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line)
// NormalizeURI(line, end_of_uri); // NormalizeURI(line, end_of_uri);
request_URI = make_intrusive<StringVal>(end_of_uri - line, line); request_URI = zeek::make_intrusive<StringVal>(end_of_uri - line, line);
unescaped_URI = make_intrusive<StringVal>( unescaped_URI = zeek::make_intrusive<StringVal>(
unescape_URI((const u_char*) line, (const u_char*) end_of_uri, this)); unescape_URI((const u_char*) line, (const u_char*) end_of_uri, this));
return true; return true;
@ -1352,21 +1352,21 @@ void HTTP_Analyzer::SetVersion(HTTP_VersionNumber* version, HTTP_VersionNumber n
void HTTP_Analyzer::HTTP_Event(const char* category, const char* detail) void HTTP_Analyzer::HTTP_Event(const char* category, const char* detail)
{ {
HTTP_Event(category, make_intrusive<StringVal>(detail)); HTTP_Event(category, zeek::make_intrusive<StringVal>(detail));
} }
void HTTP_Analyzer::HTTP_Event(const char* category, IntrusivePtr<StringVal> detail) void HTTP_Analyzer::HTTP_Event(const char* category, zeek::IntrusivePtr<StringVal> detail)
{ {
if ( http_event ) if ( http_event )
// DEBUG_MSG("%.6f http_event\n", network_time); // DEBUG_MSG("%.6f http_event\n", network_time);
EnqueueConnEvent(http_event, EnqueueConnEvent(http_event,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(category), zeek::make_intrusive<StringVal>(category),
std::move(detail)); std::move(detail));
} }
IntrusivePtr<StringVal> zeek::IntrusivePtr<StringVal>
HTTP_Analyzer::TruncateURI(const IntrusivePtr<StringVal>& uri) HTTP_Analyzer::TruncateURI(const zeek::IntrusivePtr<StringVal>& uri)
{ {
const BroString* str = uri->AsString(); const BroString* str = uri->AsString();
@ -1375,7 +1375,7 @@ HTTP_Analyzer::TruncateURI(const IntrusivePtr<StringVal>& uri)
u_char* s = new u_char[truncate_http_URI + 4]; u_char* s = new u_char[truncate_http_URI + 4];
memcpy(s, str->Bytes(), truncate_http_URI); memcpy(s, str->Bytes(), truncate_http_URI);
memcpy(s + truncate_http_URI, "...", 4); memcpy(s + truncate_http_URI, "...", 4);
return make_intrusive<StringVal>(new BroString(true, s, truncate_http_URI+3)); return zeek::make_intrusive<StringVal>(new BroString(true, s, truncate_http_URI+3));
} }
else else
return uri; return uri;
@ -1398,7 +1398,7 @@ void HTTP_Analyzer::HTTP_Request()
request_method, request_method,
TruncateURI(request_URI), TruncateURI(request_URI),
TruncateURI(unescaped_URI), TruncateURI(unescaped_URI),
make_intrusive<StringVal>(fmt("%.1f", request_version.ToDouble())) zeek::make_intrusive<StringVal>(fmt("%.1f", request_version.ToDouble()))
); );
} }
@ -1407,11 +1407,11 @@ void HTTP_Analyzer::HTTP_Reply()
if ( http_reply ) if ( http_reply )
EnqueueConnEvent(http_reply, EnqueueConnEvent(http_reply,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(fmt("%.1f", reply_version.ToDouble())), zeek::make_intrusive<StringVal>(fmt("%.1f", reply_version.ToDouble())),
val_mgr->Count(reply_code), val_mgr->Count(reply_code),
reply_reason_phrase ? reply_reason_phrase ?
reply_reason_phrase : reply_reason_phrase :
make_intrusive<StringVal>("<empty>") zeek::make_intrusive<StringVal>("<empty>")
); );
else else
reply_reason_phrase = nullptr; reply_reason_phrase = nullptr;
@ -1473,7 +1473,7 @@ void HTTP_Analyzer::ReplyMade(bool interrupted, const char* msg)
if ( http_connection_upgrade ) if ( http_connection_upgrade )
EnqueueConnEvent(http_connection_upgrade, EnqueueConnEvent(http_connection_upgrade,
ConnVal(), ConnVal(),
make_intrusive<StringVal>(upgrade_protocol) zeek::make_intrusive<StringVal>(upgrade_protocol)
); );
} }
@ -1551,7 +1551,7 @@ int HTTP_Analyzer::HTTP_ReplyLine(const char* line, const char* end_of_line)
rest = skip_whitespace(rest, end_of_line); rest = skip_whitespace(rest, end_of_line);
reply_reason_phrase = reply_reason_phrase =
make_intrusive<StringVal>(end_of_line - rest, (const char *) rest); zeek::make_intrusive<StringVal>(end_of_line - rest, (const char *) rest);
return 1; return 1;
} }
@ -1655,7 +1655,7 @@ void HTTP_Analyzer::HTTP_EntityData(bool is_orig, BroString* entity_data)
ConnVal(), ConnVal(),
val_mgr->Bool(is_orig), val_mgr->Bool(is_orig),
val_mgr->Count(entity_data->Len()), val_mgr->Count(entity_data->Len()),
make_intrusive<StringVal>(entity_data) zeek::make_intrusive<StringVal>(entity_data)
); );
else else
delete entity_data; delete entity_data;

View file

@ -145,7 +145,7 @@ protected:
HTTP_Entity* current_entity; HTTP_Entity* current_entity;
IntrusivePtr<RecordVal> BuildMessageStat(bool interrupted, const char* msg); zeek::IntrusivePtr<RecordVal> 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, IntrusivePtr<StringVal> detail); void HTTP_Event(const char* category, zeek::IntrusivePtr<StringVal> 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();
IntrusivePtr<StringVal> TruncateURI(const IntrusivePtr<StringVal>& uri); zeek::IntrusivePtr<StringVal> TruncateURI(const zeek::IntrusivePtr<StringVal>& 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;
IntrusivePtr<StringVal> request_method; zeek::IntrusivePtr<StringVal> 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).
IntrusivePtr<StringVal> request_URI; zeek::IntrusivePtr<StringVal> request_URI;
// unescaped_URI does not contain escaped sequences. // unescaped_URI does not contain escaped sequences.
IntrusivePtr<StringVal> unescaped_URI; zeek::IntrusivePtr<StringVal> unescaped_URI;
std::queue<IntrusivePtr<StringVal>> unanswered_requests; std::queue<zeek::IntrusivePtr<StringVal>> unanswered_requests;
int reply_code; int reply_code;
IntrusivePtr<StringVal> reply_reason_phrase; zeek::IntrusivePtr<StringVal> 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

@ -52,5 +52,5 @@ function unescape_URI%(URI: string%): string
const u_char* line = URI->Bytes(); const u_char* line = URI->Bytes();
const u_char* const line_end = line + URI->Len(); const u_char* const line_end = line + URI->Len();
return make_intrusive<StringVal>(analyzer::http::unescape_URI(line, line_end, 0)); return zeek::make_intrusive<StringVal>(analyzer::http::unescape_URI(line, line_end, 0));
%} %}

View file

@ -214,22 +214,22 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen,
EnqueueConnEvent(icmp_sent_payload, EnqueueConnEvent(icmp_sent_payload,
ConnVal(), ConnVal(),
BuildICMPVal(icmpp, len, icmpv6, ip_hdr), BuildICMPVal(icmpp, len, icmpv6, ip_hdr),
make_intrusive<StringVal>(payload) zeek::make_intrusive<StringVal>(payload)
); );
} }
} }
IntrusivePtr<RecordVal> zeek::IntrusivePtr<RecordVal>
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)
{ {
if ( ! icmp_conn_val ) if ( ! icmp_conn_val )
{ {
static auto icmp_conn = zeek::id::find_type<zeek::RecordType>("icmp_conn"); static auto icmp_conn = zeek::id::find_type<zeek::RecordType>("icmp_conn");
icmp_conn_val = make_intrusive<RecordVal>(icmp_conn); icmp_conn_val = zeek::make_intrusive<RecordVal>(icmp_conn);
icmp_conn_val->Assign(0, make_intrusive<AddrVal>(Conn()->OrigAddr())); icmp_conn_val->Assign(0, zeek::make_intrusive<AddrVal>(Conn()->OrigAddr()));
icmp_conn_val->Assign(1, make_intrusive<AddrVal>(Conn()->RespAddr())); icmp_conn_val->Assign(1, zeek::make_intrusive<AddrVal>(Conn()->RespAddr()));
icmp_conn_val->Assign(2, val_mgr->Count(icmpp->icmp_type)); icmp_conn_val->Assign(2, val_mgr->Count(icmpp->icmp_type));
icmp_conn_val->Assign(3, val_mgr->Count(icmpp->icmp_code)); icmp_conn_val->Assign(3, val_mgr->Count(icmpp->icmp_code));
icmp_conn_val->Assign(4, val_mgr->Count(len)); icmp_conn_val->Assign(4, val_mgr->Count(len));
@ -305,7 +305,7 @@ TransportProto ICMP_Analyzer::GetContextProtocol(const IP_Hdr* ip_hdr, uint32_t*
return proto; return proto;
} }
IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP4Context(int len, const u_char*& data) zeek::IntrusivePtr<RecordVal> 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;
@ -352,12 +352,12 @@ IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP4Context(int len, const u_char
} }
static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context"); static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context");
auto iprec = make_intrusive<RecordVal>(icmp_context); auto iprec = zeek::make_intrusive<RecordVal>(icmp_context);
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id); auto id_val = zeek::make_intrusive<RecordVal>(zeek::id::conn_id);
id_val->Assign(0, make_intrusive<AddrVal>(src_addr)); id_val->Assign(0, zeek::make_intrusive<AddrVal>(src_addr));
id_val->Assign(1, val_mgr->Port(src_port, proto)); id_val->Assign(1, val_mgr->Port(src_port, proto));
id_val->Assign(2, make_intrusive<AddrVal>(dst_addr)); id_val->Assign(2, zeek::make_intrusive<AddrVal>(dst_addr));
id_val->Assign(3, val_mgr->Port(dst_port, proto)); id_val->Assign(3, val_mgr->Port(dst_port, proto));
iprec->Assign(0, std::move(id_val)); iprec->Assign(0, std::move(id_val));
@ -372,7 +372,7 @@ IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP4Context(int len, const u_char
return iprec; return iprec;
} }
IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) zeek::IntrusivePtr<RecordVal> 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;
@ -412,12 +412,12 @@ IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP6Context(int len, const u_char
} }
static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context"); static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context");
auto iprec = make_intrusive<RecordVal>(icmp_context); auto iprec = zeek::make_intrusive<RecordVal>(icmp_context);
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id); auto id_val = zeek::make_intrusive<RecordVal>(zeek::id::conn_id);
id_val->Assign(0, make_intrusive<AddrVal>(src_addr)); id_val->Assign(0, zeek::make_intrusive<AddrVal>(src_addr));
id_val->Assign(1, val_mgr->Port(src_port, proto)); id_val->Assign(1, val_mgr->Port(src_port, proto));
id_val->Assign(2, make_intrusive<AddrVal>(dst_addr)); id_val->Assign(2, zeek::make_intrusive<AddrVal>(dst_addr));
id_val->Assign(3, val_mgr->Port(dst_port, proto)); id_val->Assign(3, val_mgr->Port(dst_port, proto));
iprec->Assign(0, std::move(id_val)); iprec->Assign(0, std::move(id_val));
@ -469,7 +469,7 @@ void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val)
Analyzer::UpdateConnVal(conn_val); Analyzer::UpdateConnVal(conn_val);
} }
void ICMP_Analyzer::UpdateEndpointVal(const IntrusivePtr<Val>& endp_arg, bool is_orig) void ICMP_Analyzer::UpdateEndpointVal(const zeek::IntrusivePtr<Val>& endp_arg, bool is_orig)
{ {
Conn()->EnableStatusUpdateTimer(); Conn()->EnableStatusUpdateTimer();
@ -523,7 +523,7 @@ void ICMP_Analyzer::Echo(double t, const struct icmp* icmpp, int len,
BuildICMPVal(icmpp, len, ip_hdr->NextProto() != IPPROTO_ICMP, ip_hdr), BuildICMPVal(icmpp, len, ip_hdr->NextProto() != IPPROTO_ICMP, ip_hdr),
val_mgr->Count(iid), val_mgr->Count(iid),
val_mgr->Count(iseq), val_mgr->Count(iseq),
make_intrusive<StringVal>(payload) zeek::make_intrusive<StringVal>(payload)
); );
} }
@ -556,9 +556,9 @@ void ICMP_Analyzer::RouterAdvert(double t, const struct icmp* icmpp, int len,
val_mgr->Count((icmpp->icmp_wpa & 0x18)>>3), // Pref val_mgr->Count((icmpp->icmp_wpa & 0x18)>>3), // Pref
val_mgr->Bool(icmpp->icmp_wpa & 0x04), // Proxy val_mgr->Bool(icmpp->icmp_wpa & 0x04), // Proxy
val_mgr->Count(icmpp->icmp_wpa & 0x02), // Reserved val_mgr->Count(icmpp->icmp_wpa & 0x02), // Reserved
make_intrusive<IntervalVal>((double)ntohs(icmpp->icmp_lifetime), Seconds), zeek::make_intrusive<IntervalVal>((double)ntohs(icmpp->icmp_lifetime), Seconds),
make_intrusive<IntervalVal>((double)ntohl(reachable), Milliseconds), zeek::make_intrusive<IntervalVal>((double)ntohl(reachable), Milliseconds),
make_intrusive<IntervalVal>((double)ntohl(retrans), Milliseconds), zeek::make_intrusive<IntervalVal>((double)ntohl(retrans), Milliseconds),
BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)
); );
} }
@ -585,7 +585,7 @@ void ICMP_Analyzer::NeighborAdvert(double t, const struct icmp* icmpp, int len,
val_mgr->Bool(icmpp->icmp_num_addrs & 0x80), // Router val_mgr->Bool(icmpp->icmp_num_addrs & 0x80), // Router
val_mgr->Bool(icmpp->icmp_num_addrs & 0x40), // Solicited val_mgr->Bool(icmpp->icmp_num_addrs & 0x40), // Solicited
val_mgr->Bool(icmpp->icmp_num_addrs & 0x20), // Override val_mgr->Bool(icmpp->icmp_num_addrs & 0x20), // Override
make_intrusive<AddrVal>(tgtaddr), zeek::make_intrusive<AddrVal>(tgtaddr),
BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)
); );
} }
@ -609,7 +609,7 @@ void ICMP_Analyzer::NeighborSolicit(double t, const struct icmp* icmpp, int len,
EnqueueConnEvent(f, EnqueueConnEvent(f,
ConnVal(), ConnVal(),
BuildICMPVal(icmpp, len, 1, ip_hdr), BuildICMPVal(icmpp, len, 1, ip_hdr),
make_intrusive<AddrVal>(tgtaddr), zeek::make_intrusive<AddrVal>(tgtaddr),
BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)
); );
} }
@ -636,8 +636,8 @@ void ICMP_Analyzer::Redirect(double t, const struct icmp* icmpp, int len,
EnqueueConnEvent(f, EnqueueConnEvent(f,
ConnVal(), ConnVal(),
BuildICMPVal(icmpp, len, 1, ip_hdr), BuildICMPVal(icmpp, len, 1, ip_hdr),
make_intrusive<AddrVal>(tgtaddr), zeek::make_intrusive<AddrVal>(tgtaddr),
make_intrusive<AddrVal>(dstaddr), zeek::make_intrusive<AddrVal>(dstaddr),
BuildNDOptionsVal(caplen - opt_offset, data + opt_offset) BuildNDOptionsVal(caplen - opt_offset, data + opt_offset)
); );
} }
@ -722,12 +722,12 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp,
); );
} }
IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) zeek::IntrusivePtr<VectorVal> 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");
auto vv = make_intrusive<VectorVal>( auto vv = zeek::make_intrusive<VectorVal>(
zeek::id::find_type<zeek::VectorType>("icmp6_nd_options")); zeek::id::find_type<zeek::VectorType>("icmp6_nd_options"));
while ( caplen > 0 ) while ( caplen > 0 )
@ -748,7 +748,7 @@ IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha
break; break;
} }
auto rv = make_intrusive<RecordVal>(icmp6_nd_option_type); auto rv = zeek::make_intrusive<RecordVal>(icmp6_nd_option_type);
rv->Assign(0, val_mgr->Count(type)); rv->Assign(0, val_mgr->Count(type));
rv->Assign(1, val_mgr->Count(length)); rv->Assign(1, val_mgr->Count(length));
@ -769,7 +769,7 @@ IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha
if ( caplen >= length ) if ( caplen >= length )
{ {
BroString* link_addr = new BroString(data, length, false); BroString* link_addr = new BroString(data, length, false);
rv->Assign(2, make_intrusive<StringVal>(link_addr)); rv->Assign(2, zeek::make_intrusive<StringVal>(link_addr));
} }
else else
set_payload_field = true; set_payload_field = true;
@ -782,7 +782,7 @@ IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha
{ {
if ( caplen >= 30 ) if ( caplen >= 30 )
{ {
auto info = make_intrusive<RecordVal>(icmp6_nd_prefix_info_type); auto info = zeek::make_intrusive<RecordVal>(icmp6_nd_prefix_info_type);
uint8_t prefix_len = *((const uint8_t*)(data)); uint8_t prefix_len = *((const uint8_t*)(data));
bool L_flag = (*((const uint8_t*)(data + 1)) & 0x80) != 0; bool L_flag = (*((const uint8_t*)(data + 1)) & 0x80) != 0;
bool A_flag = (*((const uint8_t*)(data + 1)) & 0x40) != 0; bool A_flag = (*((const uint8_t*)(data + 1)) & 0x40) != 0;
@ -792,9 +792,9 @@ IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha
info->Assign(0, val_mgr->Count(prefix_len)); info->Assign(0, val_mgr->Count(prefix_len));
info->Assign(1, val_mgr->Bool(L_flag)); info->Assign(1, val_mgr->Bool(L_flag));
info->Assign(2, val_mgr->Bool(A_flag)); info->Assign(2, val_mgr->Bool(A_flag));
info->Assign(3, make_intrusive<IntervalVal>((double)ntohl(valid_life), Seconds)); info->Assign(3, zeek::make_intrusive<IntervalVal>((double)ntohl(valid_life), Seconds));
info->Assign(4, make_intrusive<IntervalVal>((double)ntohl(prefer_life), Seconds)); info->Assign(4, zeek::make_intrusive<IntervalVal>((double)ntohl(prefer_life), Seconds));
info->Assign(5, make_intrusive<AddrVal>(IPAddr(prefix))); info->Assign(5, zeek::make_intrusive<AddrVal>(IPAddr(prefix)));
rv->Assign(3, std::move(info)); rv->Assign(3, std::move(info));
} }
@ -839,7 +839,7 @@ IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha
if ( set_payload_field ) if ( set_payload_field )
{ {
BroString* payload = new BroString(data, std::min((int)length, caplen), false); BroString* payload = new BroString(data, std::min((int)length, caplen), false);
rv->Assign(6, make_intrusive<StringVal>(payload)); rv->Assign(6, zeek::make_intrusive<StringVal>(payload));
} }
data += length; data += length;

View file

@ -51,13 +51,13 @@ protected:
void Describe(ODesc* d) const; void Describe(ODesc* d) const;
IntrusivePtr<RecordVal> BuildICMPVal(const struct icmp* icmpp, int len, zeek::IntrusivePtr<RecordVal> 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 );
IntrusivePtr<RecordVal> ExtractICMP4Context(int len, const u_char*& data); zeek::IntrusivePtr<RecordVal> 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 +68,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 );
IntrusivePtr<RecordVal> ExtractICMP6Context(int len, const u_char*& data); zeek::IntrusivePtr<RecordVal> 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
IntrusivePtr<VectorVal> BuildNDOptionsVal(int caplen, const u_char* data); zeek::IntrusivePtr<VectorVal> BuildNDOptionsVal(int caplen, const u_char* data);
IntrusivePtr<RecordVal> icmp_conn_val; zeek::IntrusivePtr<RecordVal> icmp_conn_val;
int type; int type;
int code; int code;
int request_len, reply_len; int request_len, reply_len;
@ -84,7 +84,7 @@ protected:
RuleMatcherState matcher_state; RuleMatcherState matcher_state;
private: private:
void UpdateEndpointVal(const IntrusivePtr<Val>& endp, bool is_orig); void UpdateEndpointVal(const zeek::IntrusivePtr<Val>& 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

@ -149,7 +149,7 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig)
ConnVal(), ConnVal(),
val_mgr->Port(local_port, TRANSPORT_TCP), val_mgr->Port(local_port, TRANSPORT_TCP),
val_mgr->Port(remote_port, TRANSPORT_TCP), val_mgr->Port(remote_port, TRANSPORT_TCP),
make_intrusive<StringVal>(end_of_line - line, line) zeek::make_intrusive<StringVal>(end_of_line - line, line)
); );
} }
@ -182,8 +182,8 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig)
ConnVal(), ConnVal(),
val_mgr->Port(local_port, TRANSPORT_TCP), val_mgr->Port(local_port, TRANSPORT_TCP),
val_mgr->Port(remote_port, TRANSPORT_TCP), val_mgr->Port(remote_port, TRANSPORT_TCP),
make_intrusive<StringVal>(end_of_line - line, line), zeek::make_intrusive<StringVal>(end_of_line - line, line),
make_intrusive<StringVal>(sys_type_s) zeek::make_intrusive<StringVal>(sys_type_s)
); );
} }
} }

View file

@ -59,12 +59,12 @@ refine connection IMAP_Conn += {
if ( ! imap_capabilities ) if ( ! imap_capabilities )
return true; return true;
auto capv = make_intrusive<VectorVal>(zeek::id::string_vec); auto capv = zeek::make_intrusive<VectorVal>(zeek::id::string_vec);
for ( unsigned int i = 0; i< capabilities->size(); i++ ) for ( unsigned int i = 0; i< capabilities->size(); i++ )
{ {
const bytestring& capability = (*capabilities)[i]->cap(); const bytestring& capability = (*capabilities)[i]->cap();
capv->Assign(i, make_intrusive<StringVal>(capability.length(), (const char*)capability.data())); capv->Assign(i, zeek::make_intrusive<StringVal>(capability.length(), (const char*)capability.data()));
} }
zeek::BifEvent::enqueue_imap_capabilities(bro_analyzer(), bro_analyzer()->Conn(), std::move(capv)); zeek::BifEvent::enqueue_imap_capabilities(bro_analyzer(), bro_analyzer()->Conn(), std::move(capv));

View file

@ -273,21 +273,21 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
if ( parts.size() > 0 && parts[0][0] == ':' ) if ( parts.size() > 0 && parts[0][0] == ':' )
parts[0] = parts[0].substr(1); parts[0] = parts[0].substr(1);
auto set = make_intrusive<TableVal>(zeek::id::string_set); auto set = zeek::make_intrusive<TableVal>(zeek::id::string_set);
for ( unsigned int i = 0; i < parts.size(); ++i ) for ( unsigned int i = 0; i < parts.size(); ++i )
{ {
if ( parts[i][0] == '@' ) if ( parts[i][0] == '@' )
parts[i] = parts[i].substr(1); parts[i] = parts[i].substr(1);
auto idx = make_intrusive<StringVal>(parts[i].c_str()); auto idx = zeek::make_intrusive<StringVal>(parts[i].c_str());
set->Assign(std::move(idx), nullptr); set->Assign(std::move(idx), nullptr);
} }
EnqueueConnEvent(irc_names_info, EnqueueConnEvent(irc_names_info,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(type.c_str()), zeek::make_intrusive<StringVal>(type.c_str()),
make_intrusive<StringVal>(channel.c_str()), zeek::make_intrusive<StringVal>(channel.c_str()),
std::move(set) std::move(set)
); );
} }
@ -374,8 +374,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_global_users, EnqueueConnEvent(irc_global_users,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(eop - prefix, prefix), zeek::make_intrusive<StringVal>(eop - prefix, prefix),
make_intrusive<StringVal>(++msg) zeek::make_intrusive<StringVal>(++msg)
); );
break; break;
} }
@ -400,9 +400,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
vl.reserve(6); vl.reserve(6);
vl.emplace_back(ConnVal()); vl.emplace_back(ConnVal());
vl.emplace_back(val_mgr->Bool(orig)); vl.emplace_back(val_mgr->Bool(orig));
vl.emplace_back(make_intrusive<StringVal>(parts[0].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[0].c_str()));
vl.emplace_back(make_intrusive<StringVal>(parts[1].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[1].c_str()));
vl.emplace_back(make_intrusive<StringVal>(parts[2].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[2].c_str()));
parts.erase(parts.begin(), parts.begin() + 4); parts.erase(parts.begin(), parts.begin() + 4);
@ -413,7 +413,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
if ( real_name[0] == ':' ) if ( real_name[0] == ':' )
real_name = real_name.substr(1); real_name = real_name.substr(1);
vl.emplace_back(make_intrusive<StringVal>(real_name.c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(real_name.c_str()));
EnqueueConnEvent(irc_whois_user_line, std::move(vl)); EnqueueConnEvent(irc_whois_user_line, std::move(vl));
} }
@ -439,7 +439,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_whois_operator_line, EnqueueConnEvent(irc_whois_operator_line,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(parts[0].c_str()) zeek::make_intrusive<StringVal>(parts[0].c_str())
); );
} }
break; break;
@ -466,18 +466,18 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
if ( parts.size() > 0 && parts[0][0] == ':' ) if ( parts.size() > 0 && parts[0][0] == ':' )
parts[0] = parts[0].substr(1); parts[0] = parts[0].substr(1);
auto set = make_intrusive<TableVal>(zeek::id::string_set); auto set = zeek::make_intrusive<TableVal>(zeek::id::string_set);
for ( unsigned int i = 0; i < parts.size(); ++i ) for ( unsigned int i = 0; i < parts.size(); ++i )
{ {
auto idx = make_intrusive<StringVal>(parts[i].c_str()); auto idx = zeek::make_intrusive<StringVal>(parts[i].c_str());
set->Assign(std::move(idx), nullptr); set->Assign(std::move(idx), nullptr);
} }
EnqueueConnEvent(irc_whois_channel_line, EnqueueConnEvent(irc_whois_channel_line,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(nick.c_str()), zeek::make_intrusive<StringVal>(nick.c_str()),
std::move(set) std::move(set)
); );
} }
@ -508,8 +508,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_channel_topic, EnqueueConnEvent(irc_channel_topic,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(parts[1].c_str()), zeek::make_intrusive<StringVal>(parts[1].c_str()),
make_intrusive<StringVal>(t) zeek::make_intrusive<StringVal>(t)
); );
} }
else else
@ -542,15 +542,15 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_who_line, EnqueueConnEvent(irc_who_line,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(parts[0].c_str()), zeek::make_intrusive<StringVal>(parts[0].c_str()),
make_intrusive<StringVal>(parts[1].c_str()), zeek::make_intrusive<StringVal>(parts[1].c_str()),
make_intrusive<StringVal>(parts[2].c_str()), zeek::make_intrusive<StringVal>(parts[2].c_str()),
make_intrusive<StringVal>(parts[3].c_str()), zeek::make_intrusive<StringVal>(parts[3].c_str()),
make_intrusive<StringVal>(parts[4].c_str()), zeek::make_intrusive<StringVal>(parts[4].c_str()),
make_intrusive<StringVal>(parts[5].c_str()), zeek::make_intrusive<StringVal>(parts[5].c_str()),
make_intrusive<StringVal>(parts[6].c_str()), zeek::make_intrusive<StringVal>(parts[6].c_str()),
val_mgr->Int(atoi(parts[7].c_str())), val_mgr->Int(atoi(parts[7].c_str())),
make_intrusive<StringVal>(parts[8].c_str()) zeek::make_intrusive<StringVal>(parts[8].c_str())
); );
} }
break; break;
@ -589,9 +589,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_reply, EnqueueConnEvent(irc_reply,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
val_mgr->Count(code), val_mgr->Count(code),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
break; break;
} }
@ -660,11 +660,11 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_dcc_message, EnqueueConnEvent(irc_dcc_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(target.c_str()), zeek::make_intrusive<StringVal>(target.c_str()),
make_intrusive<StringVal>(parts[1].c_str()), zeek::make_intrusive<StringVal>(parts[1].c_str()),
make_intrusive<StringVal>(parts[2].c_str()), zeek::make_intrusive<StringVal>(parts[2].c_str()),
make_intrusive<AddrVal>(htonl(raw_ip)), zeek::make_intrusive<AddrVal>(htonl(raw_ip)),
val_mgr->Count(atoi(parts[4].c_str())), val_mgr->Count(atoi(parts[4].c_str())),
parts.size() >= 6 ? val_mgr->Count(atoi(parts[5].c_str())) : val_mgr->Count(0) parts.size() >= 6 ? val_mgr->Count(atoi(parts[5].c_str())) : val_mgr->Count(0)
); );
@ -676,9 +676,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_privmsg_message, EnqueueConnEvent(irc_privmsg_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(target.c_str()), zeek::make_intrusive<StringVal>(target.c_str()),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
} }
@ -701,9 +701,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_notice_message, EnqueueConnEvent(irc_notice_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(target.c_str()), zeek::make_intrusive<StringVal>(target.c_str()),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
@ -725,9 +725,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_squery_message, EnqueueConnEvent(irc_squery_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(target.c_str()), zeek::make_intrusive<StringVal>(target.c_str()),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
@ -741,15 +741,15 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
vl.emplace_back(val_mgr->Bool(orig)); vl.emplace_back(val_mgr->Bool(orig));
if ( parts.size() > 0 ) if ( parts.size() > 0 )
vl.emplace_back(make_intrusive<StringVal>(parts[0].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[0].c_str()));
else vl.emplace_back(val_mgr->EmptyString()); else vl.emplace_back(val_mgr->EmptyString());
if ( parts.size() > 1 ) if ( parts.size() > 1 )
vl.emplace_back(make_intrusive<StringVal>(parts[1].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[1].c_str()));
else vl.emplace_back(val_mgr->EmptyString()); else vl.emplace_back(val_mgr->EmptyString());
if ( parts.size() > 2 ) if ( parts.size() > 2 )
vl.emplace_back(make_intrusive<StringVal>(parts[2].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[2].c_str()));
else vl.emplace_back(val_mgr->EmptyString()); else vl.emplace_back(val_mgr->EmptyString());
string realname; string realname;
@ -761,7 +761,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
} }
const char* name = realname.c_str(); const char* name = realname.c_str();
vl.emplace_back(make_intrusive<StringVal>(*name == ':' ? name + 1 : name)); vl.emplace_back(zeek::make_intrusive<StringVal>(*name == ':' ? name + 1 : name));
EnqueueConnEvent(irc_user_message, std::move(vl)); EnqueueConnEvent(irc_user_message, std::move(vl));
} }
@ -774,8 +774,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_oper_message, EnqueueConnEvent(irc_oper_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(parts[0].c_str()), zeek::make_intrusive<StringVal>(parts[0].c_str()),
make_intrusive<StringVal>(parts[1].c_str()) zeek::make_intrusive<StringVal>(parts[1].c_str())
); );
else else
@ -796,9 +796,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
vl.reserve(6); vl.reserve(6);
vl.emplace_back(ConnVal()); vl.emplace_back(ConnVal());
vl.emplace_back(val_mgr->Bool(orig)); vl.emplace_back(val_mgr->Bool(orig));
vl.emplace_back(make_intrusive<StringVal>(prefix.c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(prefix.c_str()));
vl.emplace_back(make_intrusive<StringVal>(parts[0].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[0].c_str()));
vl.emplace_back(make_intrusive<StringVal>(parts[1].c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(parts[1].c_str()));
if ( parts.size() > 2 ) if ( parts.size() > 2 )
{ {
@ -809,7 +809,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
if ( comment[0] == ':' ) if ( comment[0] == ':' )
comment = comment.substr(1); comment = comment.substr(1);
vl.emplace_back(make_intrusive<StringVal>(comment.c_str())); vl.emplace_back(zeek::make_intrusive<StringVal>(comment.c_str()));
} }
else else
vl.emplace_back(val_mgr->EmptyString()); vl.emplace_back(val_mgr->EmptyString());
@ -838,7 +838,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
nickname = prefix.substr(0, pos); nickname = prefix.substr(0, pos);
} }
auto list = make_intrusive<TableVal>(irc_join_list); auto list = zeek::make_intrusive<TableVal>(irc_join_list);
vector<string> channels = SplitWords(parts[0], ','); vector<string> channels = SplitWords(parts[0], ',');
vector<string> passwords; vector<string> passwords;
@ -849,15 +849,15 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
string empty_string = ""; string empty_string = "";
for ( unsigned int i = 0; i < channels.size(); ++i ) for ( unsigned int i = 0; i < channels.size(); ++i )
{ {
auto info = make_intrusive<RecordVal>(irc_join_info); auto info = zeek::make_intrusive<RecordVal>(irc_join_info);
info->Assign(0, make_intrusive<StringVal>(nickname.c_str())); info->Assign(0, zeek::make_intrusive<StringVal>(nickname.c_str()));
info->Assign(1, make_intrusive<StringVal>(channels[i].c_str())); info->Assign(1, zeek::make_intrusive<StringVal>(channels[i].c_str()));
if ( i < passwords.size() ) if ( i < passwords.size() )
info->Assign(2, make_intrusive<StringVal>(passwords[i].c_str())); info->Assign(2, zeek::make_intrusive<StringVal>(passwords[i].c_str()));
else else
info->Assign(2, make_intrusive<StringVal>(empty_string.c_str())); info->Assign(2, zeek::make_intrusive<StringVal>(empty_string.c_str()));
// User mode. // User mode.
info->Assign(3, make_intrusive<StringVal>(empty_string.c_str())); info->Assign(3, zeek::make_intrusive<StringVal>(empty_string.c_str()));
list->Assign(std::move(info), nullptr); list->Assign(std::move(info), nullptr);
} }
@ -882,13 +882,13 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
parts[1] = parts[1].substr(1); parts[1] = parts[1].substr(1);
vector<string> users = SplitWords(parts[1], ','); vector<string> users = SplitWords(parts[1], ',');
auto list = make_intrusive<TableVal>(irc_join_list); auto list = zeek::make_intrusive<TableVal>(irc_join_list);
string empty_string = ""; string empty_string = "";
for ( unsigned int i = 0; i < users.size(); ++i ) for ( unsigned int i = 0; i < users.size(); ++i )
{ {
auto info = make_intrusive<RecordVal>(irc_join_info); auto info = zeek::make_intrusive<RecordVal>(irc_join_info);
string nick = users[i]; string nick = users[i];
string mode = "none"; string mode = "none";
@ -912,12 +912,12 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
mode = "voice"; mode = "voice";
} }
info->Assign(0, make_intrusive<StringVal>(nick.c_str())); info->Assign(0, zeek::make_intrusive<StringVal>(nick.c_str()));
info->Assign(1, make_intrusive<StringVal>(channel.c_str())); info->Assign(1, zeek::make_intrusive<StringVal>(channel.c_str()));
// Password: // Password:
info->Assign(2, make_intrusive<StringVal>(empty_string.c_str())); info->Assign(2, zeek::make_intrusive<StringVal>(empty_string.c_str()));
// User mode: // User mode:
info->Assign(3, make_intrusive<StringVal>(mode.c_str())); info->Assign(3, zeek::make_intrusive<StringVal>(mode.c_str()));
list->Assign(std::move(info), nullptr); list->Assign(std::move(info), nullptr);
} }
@ -952,20 +952,20 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
nick = nick.substr(0, pos); nick = nick.substr(0, pos);
vector<string> channelList = SplitWords(channels, ','); vector<string> channelList = SplitWords(channels, ',');
auto set = make_intrusive<TableVal>(zeek::id::string_set); auto set = zeek::make_intrusive<TableVal>(zeek::id::string_set);
for ( unsigned int i = 0; i < channelList.size(); ++i ) for ( unsigned int i = 0; i < channelList.size(); ++i )
{ {
auto idx = make_intrusive<StringVal>(channelList[i].c_str()); auto idx = zeek::make_intrusive<StringVal>(channelList[i].c_str());
set->Assign(std::move(idx), nullptr); set->Assign(std::move(idx), nullptr);
} }
EnqueueConnEvent(irc_part_message, EnqueueConnEvent(irc_part_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(nick.c_str()), zeek::make_intrusive<StringVal>(nick.c_str()),
std::move(set), std::move(set),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
@ -986,8 +986,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_quit_message, EnqueueConnEvent(irc_quit_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(nickname.c_str()), zeek::make_intrusive<StringVal>(nickname.c_str()),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
@ -1000,8 +1000,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_nick_message, EnqueueConnEvent(irc_nick_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(nick.c_str()) zeek::make_intrusive<StringVal>(nick.c_str())
); );
} }
@ -1026,7 +1026,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
parts.size() > 0 ? parts.size() > 0 ?
make_intrusive<StringVal>(parts[0].c_str()) : zeek::make_intrusive<StringVal>(parts[0].c_str()) :
val_mgr->EmptyString(), val_mgr->EmptyString(),
val_mgr->Bool(oper) val_mgr->Bool(oper)
); );
@ -1055,8 +1055,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_whois_message, EnqueueConnEvent(irc_whois_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(server.c_str()), zeek::make_intrusive<StringVal>(server.c_str()),
make_intrusive<StringVal>(users.c_str()) zeek::make_intrusive<StringVal>(users.c_str())
); );
} }
@ -1068,8 +1068,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_error_message, EnqueueConnEvent(irc_error_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
} }
@ -1084,9 +1084,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_invite_message, EnqueueConnEvent(irc_invite_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(parts[0].c_str()), zeek::make_intrusive<StringVal>(parts[0].c_str()),
make_intrusive<StringVal>(parts[1].c_str()) zeek::make_intrusive<StringVal>(parts[1].c_str())
); );
} }
else else
@ -1099,8 +1099,8 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_mode_message, EnqueueConnEvent(irc_mode_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
else else
@ -1112,7 +1112,7 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_password_message, EnqueueConnEvent(irc_password_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
} }
@ -1134,9 +1134,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_squit_message, EnqueueConnEvent(irc_squit_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(server.c_str()), zeek::make_intrusive<StringVal>(server.c_str()),
make_intrusive<StringVal>(message.c_str()) zeek::make_intrusive<StringVal>(message.c_str())
); );
} }
@ -1148,9 +1148,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_request, EnqueueConnEvent(irc_request,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(command.c_str()), zeek::make_intrusive<StringVal>(command.c_str()),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
} }
} }
@ -1162,9 +1162,9 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig)
EnqueueConnEvent(irc_message, EnqueueConnEvent(irc_message,
ConnVal(), ConnVal(),
val_mgr->Bool(orig), val_mgr->Bool(orig),
make_intrusive<StringVal>(prefix.c_str()), zeek::make_intrusive<StringVal>(prefix.c_str()),
make_intrusive<StringVal>(command.c_str()), zeek::make_intrusive<StringVal>(command.c_str()),
make_intrusive<StringVal>(params.c_str()) zeek::make_intrusive<StringVal>(params.c_str())
); );
} }
} }

View file

@ -87,9 +87,9 @@ void KRB_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
} }
} }
IntrusivePtr<StringVal> KRB_Analyzer::GetAuthenticationInfo(const BroString* principal, zeek::IntrusivePtr<StringVal> 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 )
@ -147,7 +147,7 @@ IntrusivePtr<StringVal> KRB_Analyzer::GetAuthenticationInfo(const BroString* pri
return nullptr; return nullptr;
} }
auto ret = make_intrusive<StringVal>(cp); auto ret = zeek::make_intrusive<StringVal>(cp);
krb5_free_unparsed_name(krb_context, cp); krb5_free_unparsed_name(krb_context, cp);
krb5_free_ticket(krb_context, tkt); krb5_free_ticket(krb_context, tkt);

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); }
IntrusivePtr<StringVal> GetAuthenticationInfo(const BroString* principal, zeek::IntrusivePtr<StringVal> 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;
IntrusivePtr<StringVal> GetAuthenticationInfo(const BroString* principal, zeek::IntrusivePtr<StringVal> 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,14 +1,14 @@
%header{ %header{
IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts); zeek::IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts);
IntrusivePtr<RecordVal> proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer); zeek::IntrusivePtr<RecordVal> 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{
IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts) zeek::IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts)
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Options); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Options);
rv->Assign(0, val_mgr->Bool(opts->forwardable())); rv->Assign(0, val_mgr->Bool(opts->forwardable()));
rv->Assign(1, val_mgr->Bool(opts->forwarded())); rv->Assign(1, val_mgr->Bool(opts->forwarded()));
@ -27,9 +27,9 @@ IntrusivePtr<RecordVal> proc_krb_kdc_options(const KRB_KDC_Options* opts)
return rv; return rv;
} }
IntrusivePtr<RecordVal> proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer) zeek::IntrusivePtr<RecordVal> proc_krb_kdc_req_arguments(KRB_KDC_REQ* msg, const BroAnalyzer bro_analyzer)
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Request); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Request);
rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), zeek::TYPE_COUNT)); rv->Assign(0, asn1_integer_to_val(msg->pvno()->data(), zeek::TYPE_COUNT));
rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), zeek::TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(msg->msg_type()->data(), zeek::TYPE_COUNT));
@ -201,9 +201,9 @@ 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]() -> IntrusivePtr<RecordVal> auto make_arg = [this, msg]() -> zeek::IntrusivePtr<RecordVal>
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Response); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::KDC_Response);
rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT)); rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT));
rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT));
@ -244,7 +244,7 @@ refine connection KRB_Conn += {
bro_analyzer()->ProtocolConfirmation(); bro_analyzer()->ProtocolConfirmation();
if ( krb_error ) if ( krb_error )
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::Error_Msg); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::Error_Msg);
proc_error_arguments(rv.get(), ${msg.args1}, 0); proc_error_arguments(rv.get(), ${msg.args1}, 0);
rv->Assign(4, asn1_integer_to_val(${msg.error_code}, zeek::TYPE_COUNT)); rv->Assign(4, asn1_integer_to_val(${msg.error_code}, zeek::TYPE_COUNT));
proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content})); proc_error_arguments(rv.get(), ${msg.args2}, binary_to_int64(${msg.error_code.encoding.content}));
@ -258,7 +258,7 @@ refine connection KRB_Conn += {
bro_analyzer()->ProtocolConfirmation(); bro_analyzer()->ProtocolConfirmation();
if ( krb_ap_request ) if ( krb_ap_request )
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::AP_Options); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::AP_Options);
rv->Assign(0, val_mgr->Bool(${msg.ap_options.use_session_key})); rv->Assign(0, val_mgr->Bool(${msg.ap_options.use_session_key}));
rv->Assign(1, val_mgr->Bool(${msg.ap_options.mutual_required})); rv->Assign(1, val_mgr->Bool(${msg.ap_options.mutual_required}));
@ -289,7 +289,7 @@ refine connection KRB_Conn += {
bro_analyzer()->ProtocolConfirmation(); bro_analyzer()->ProtocolConfirmation();
if ( krb_safe ) if ( krb_safe )
{ {
auto rv = make_intrusive<RecordVal>(zeek::BifType::Record::KRB::SAFE_Msg); auto rv = zeek::make_intrusive<RecordVal>(zeek::BifType::Record::KRB::SAFE_Msg);
rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT)); rv->Assign(0, asn1_integer_to_val(${msg.pvno.data}, zeek::TYPE_COUNT));
rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT)); rv->Assign(1, asn1_integer_to_val(${msg.msg_type.data}, zeek::TYPE_COUNT));

View file

@ -2,20 +2,20 @@
%include ../asn1/asn1.pac %include ../asn1/asn1.pac
%header{ %header{
IntrusivePtr<Val> GetTimeFromAsn1(const KRB_Time* atime, int64 usecs); zeek::IntrusivePtr<Val> GetTimeFromAsn1(const KRB_Time* atime, int64 usecs);
IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs); zeek::IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs);
%} %}
%code{ %code{
IntrusivePtr<Val> GetTimeFromAsn1(const KRB_Time* atime, int64 usecs) zeek::IntrusivePtr<Val> 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;
} }
IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs) zeek::IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs)
{ {
time_t lResult = 0; time_t lResult = 0;
@ -51,7 +51,7 @@ IntrusivePtr<Val> GetTimeFromAsn1(StringVal* atime, int64 usecs)
if ( !lResult ) if ( !lResult )
lResult = 0; lResult = 0;
return make_intrusive<TimeVal>(double(lResult + double(usecs/100000.0))); return zeek::make_intrusive<TimeVal>(double(lResult + double(usecs/100000.0)));
} }
%} %}

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