Merge remote-tracking branch 'origin/topic/timw/266-namespaces'

Merge adjustments:

- Preserved original `base_type_no_ref` argument type as ::TypeTag
- Removed superfluous #pragma guard around deprecated TableVal ctor
- Clarify NEWS regarding MetaHook{Pre,Post} deprecations
- Simplify some `::zeek::` qualifications to just `zeek::`
- Prefixed FORWARD_DECLARE_NAMESPACED macro with ZEEK_

* origin/topic/timw/266-namespaces:
  Disable some deprecation diagnostics for GCC
  Rename BroType to Type
  Update NEWS
  Review cleanup
  Move Type types to zeek namespace
  Move Flare/Pipe from the bro namespace to zeek::detail
  Move Attr to the zeek::detail namespace
  Move Trigger into the zeek::detail namespace
  Move ID to the zeek::detail namespace
  Move Anon.h into zeek::detail namespace
  Mark all of the aliased classes in plugin/Plugin.h deprecated, and fix all of the plugins that were using them
  Move all of the base plugin classes into the zeek::plugin namespace
  Expr: move all classes into zeek::detail
  Stmt: move Stmt classes into zeek::detail namespace
  Add utility macro for creating namespaced aliases for classes
This commit is contained in:
Jon Siwek 2020-06-11 23:12:02 -07:00
commit d4f3cad7d1
256 changed files with 4277 additions and 3501 deletions

28
CHANGES
View file

@ -1,4 +1,32 @@
3.2.0-dev.779 | 2020-06-11 23:17:46 -0700
* Rename BroType to zeek::Type (Tim Wojtulewicz, Corelight)
* Move Type types to zeek namespace (Tim Wojtulewicz, Corelight)
* Move Flare/Pipe from the bro namespace to zeek::detail (Tim Wojtulewicz, Corelight)
* Move Attr to the zeek::detail namespace (Tim Wojtulewicz, Corelight)
* Move Trigger into the zeek::detail namespace (Tim Wojtulewicz, Corelight)
* Move ID to the zeek::detail namespace (Tim Wojtulewicz, Corelight)
* Move Anon.h into zeek::detail namespace (Tim Wojtulewicz, Corelight)
* Mark all of the aliased classes in plugin/Plugin.h deprecated (Tim Wojtulewicz, Corelight)
And fix all of the plugins that were using them
* Move all of the base plugin classes into the zeek::plugin namespace (Tim Wojtulewicz, Corelight)
* Expr: move all classes into zeek::detail (Tim Wojtulewicz, Corelight)
* Stmt: move Stmt classes into zeek::detail namespace (Tim Wojtulewicz, Corelight)
* Add utility macro for creating namespaced aliases for classes (Tim Wojtulewicz, Corelight)
3.2.0-dev.763 | 2020-06-10 16:34:31 -0700
* Optimize Connection::RemovalEvent() for bare-mode usage (Jon Siwek, Corelight)

14
NEWS
View file

@ -107,6 +107,14 @@ Changed Functionality
- ``Attributes::Attrs()`` now returns ``const std::vector<IntrusivePtr<Attr>>&``
instead of ``attr_list*``
- Moved a large number of classes from the global namespace into either the
``zeek`` or ``zeek::detail`` namespace. See https://github.com/zeek/zeek/issues/266
for the rationale behind these changes. Most types that were moved and functions
that used them have been marked as deprecated and will generate compiler
warnings if used (a few exceptions will not generate compiler warnings,
but the Deprecated Functionality section below will mention those
ones specifically).
Removed Functionality
---------------------
@ -124,6 +132,12 @@ Deprecated Functionality
method to now use is called ``HookFunctionCall`` and uses ``IntrusivePtr``
arguments and return value.
- The ``plugin::Plugin::MetaHookPre()`` and ``MetaHookPost()`` methods are
deprecated. Note that compilers will not emit a deprecation warning, but
the replacement methods are named the same except use
``zeek::plugin::HookType`` arguments (the type is now from the "zeek"
namespace).
- The ``Func::Call(val_list*, ...)`` method is now deprecated. Use ``Invoke()``
instead which takes a ``zeek::Args`` (``std::vector<IntrusivePtr<Val>>``).
There's also a variadic template for ``Invoke()`` that forwards all arguments

View file

@ -1 +1 @@
3.2.0-dev.763
3.2.0-dev.779

@ -1 +1 @@
Subproject commit 7d474ff6ac0ff1870eef6159bef93a1bfed953df
Subproject commit 9c10bb74bb62aa7fb10efc079f1b2e5926e9798c

View file

@ -14,7 +14,9 @@
#include "ID.h"
#include "IPAddr.h"
AnonymizeIPAddr* ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr};
using namespace zeek::detail;
AnonymizeIPAddr* zeek::detail::ip_anonymizer[NUM_ADDR_ANONYMIZATION_METHODS] = {nullptr};
static uint32_t rand32()
{
@ -22,7 +24,7 @@ static uint32_t rand32()
}
// From tcpdpriv.
int bi_ffs(uint32_t value)
static int bi_ffs(uint32_t value)
{
int add = 0;
static uint8_t bvals[] = {
@ -360,7 +362,7 @@ static IntrusivePtr<TableVal> anon_preserve_orig_addr;
static IntrusivePtr<TableVal> anon_preserve_resp_addr;
static IntrusivePtr<TableVal> anon_preserve_other_addr;
void init_ip_addr_anonymizers()
void zeek::detail::init_ip_addr_anonymizers()
{
ip_anonymizer[KEEP_ORIG_ADDR] = nullptr;
ip_anonymizer[SEQUENTIALLY_NUMBERED] = new AnonymizeIPAddr_Seq();
@ -384,7 +386,7 @@ void init_ip_addr_anonymizers()
anon_preserve_other_addr = cast_intrusive<TableVal>(id->GetVal());
}
ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
ipaddr32_t zeek::detail::anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
{
TableVal* preserve_addr = nullptr;
auto addr = make_intrusive<AddrVal>(ip);
@ -439,7 +441,7 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl)
#include "NetVar.h"
#include "Event.h"
void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output)
void zeek::detail::log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output)
{
if ( anonymization_mapping )
mgr.Enqueue(anonymization_mapping,

View file

@ -14,6 +14,8 @@
#include <map>
#include <cstdint>
namespace zeek::detail {
// TODO: Anon.h may not be the right place to put these functions ...
enum ip_addr_anonymization_class_t {
@ -126,3 +128,5 @@ ipaddr32_t anonymize_ip(ipaddr32_t ip, enum ip_addr_anonymization_class_t cl);
#define LOG_ANONYMIZATION_MAPPING
void log_anonymization_mapping(ipaddr32_t input, ipaddr32_t output);
}

View file

@ -9,6 +9,8 @@
#include "IntrusivePtr.h"
#include "threading/SerialTypes.h"
namespace zeek::detail {
const char* attr_name(attr_tag t)
{
static const char* attr_names[int(NUM_ATTRS)] = {
@ -35,9 +37,20 @@ Attr::Attr(attr_tag t)
{
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Attr::Attr(::attr_tag t, IntrusivePtr<Expr> e) : Attr(static_cast<attr_tag>(t), e)
{
}
Attr::Attr(::attr_tag t) : Attr(static_cast<attr_tag>(t))
{
}
#pragma GCC diagnostic pop
Attr::~Attr() = default;
void Attr::SetAttrExpr(IntrusivePtr<Expr> e)
void Attr::SetAttrExpr(IntrusivePtr<zeek::detail::Expr> e)
{ expr = std::move(e); }
void Attr::Describe(ODesc* d) const
@ -136,7 +149,7 @@ void Attr::AddTag(ODesc* d) const
d->Add(attr_name(Tag()));
}
Attributes::Attributes(attr_list* a, IntrusivePtr<BroType> t, bool arg_in_record, bool is_global)
Attributes::Attributes(attr_list* a, IntrusivePtr<Type> t, bool arg_in_record, bool is_global)
{
attrs.reserve(a->length());
in_record = arg_in_record;
@ -154,14 +167,14 @@ Attributes::Attributes(attr_list* a, IntrusivePtr<BroType> t, bool arg_in_record
delete a;
}
Attributes::Attributes(IntrusivePtr<BroType> t,
Attributes::Attributes(IntrusivePtr<Type> t,
bool arg_in_record, bool is_global)
: Attributes(std::vector<IntrusivePtr<Attr>>{}, std::move(t),
arg_in_record, is_global)
{}
Attributes::Attributes(std::vector<IntrusivePtr<Attr>> a,
IntrusivePtr<BroType> t,
IntrusivePtr<Type> t,
bool arg_in_record, bool is_global)
: type(std::move(t))
{
@ -244,6 +257,19 @@ void Attributes::RemoveAttr(attr_tag t)
}
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Attr* Attributes::FindAttr(::attr_tag t) const
{
return FindAttr(static_cast<attr_tag>(t));
}
void Attributes::RemoveAttr(::attr_tag t)
{
RemoveAttr(static_cast<attr_tag>(t));
}
#pragma GCC diagnostic pop
void Attributes::Describe(ODesc* d) const
{
if ( attrs.empty() )
@ -663,3 +689,5 @@ bool Attributes::operator==(const Attributes& other) const
return true;
}
}

View file

@ -8,13 +8,13 @@
#include "BroList.h"
#include "IntrusivePtr.h"
class Expr;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
// Note that there are two kinds of attributes: the kind (here) which
// modify expressions or supply metadata on types, and the kind that
// are extra metadata on every variable instance.
typedef enum {
enum [[deprecated("Remove in v4.1. Use zeek::detail::attr_tag instead.")]] attr_tag {
ATTR_OPTIONAL,
ATTR_DEFAULT,
ATTR_REDEF,
@ -33,26 +33,60 @@ typedef enum {
ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry
ATTR_ON_CHANGE, // for table change tracking
ATTR_DEPRECATED,
#define NUM_ATTRS (int(ATTR_DEPRECATED) + 1)
} attr_tag;
NUM_ATTRS // this item should always be last
};
namespace zeek::detail {
enum attr_tag {
ATTR_OPTIONAL,
ATTR_DEFAULT,
ATTR_REDEF,
ATTR_ADD_FUNC,
ATTR_DEL_FUNC,
ATTR_EXPIRE_FUNC,
ATTR_EXPIRE_READ,
ATTR_EXPIRE_WRITE,
ATTR_EXPIRE_CREATE,
ATTR_RAW_OUTPUT,
ATTR_PRIORITY,
ATTR_GROUP,
ATTR_LOG,
ATTR_ERROR_HANDLER,
ATTR_TYPE_COLUMN, // for input framework
ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry
ATTR_ON_CHANGE, // for table change tracking
ATTR_DEPRECATED,
NUM_ATTRS // this item should always be last
};
class Attr final : public BroObj {
public:
static inline const IntrusivePtr<Attr> nil;
static inline const IntrusivePtr<zeek::detail::Attr> nil;
Attr(attr_tag t, IntrusivePtr<Expr> e);
Attr(attr_tag t, IntrusivePtr<zeek::detail::Expr> e);
explicit Attr(attr_tag t);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
Attr(::attr_tag t, IntrusivePtr<zeek::detail::Expr> e);
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
explicit Attr(::attr_tag t);
#pragma GCC diagnostic pop
~Attr() override;
attr_tag Tag() const { return tag; }
[[deprecated("Remove in v4.1. Use GetExpr().")]]
Expr* AttrExpr() const { return expr.get(); }
zeek::detail::Expr* AttrExpr() const { return expr.get(); }
const IntrusivePtr<Expr>& GetExpr() const
const IntrusivePtr<zeek::detail::Expr>& GetExpr() const
{ return expr; }
void SetAttrExpr(IntrusivePtr<Expr> e);
void SetAttrExpr(IntrusivePtr<zeek::detail::Expr> e);
void Describe(ODesc* d) const override;
void DescribeReST(ODesc* d, bool shorten = false) const;
@ -82,11 +116,11 @@ protected:
class Attributes final : public BroObj {
public:
[[deprecated("Remove in v4.1. Construct using IntrusivePtrs instead.")]]
Attributes(attr_list* a, IntrusivePtr<BroType> t, bool in_record, bool is_global);
Attributes(attr_list* a, IntrusivePtr<Type> t, bool in_record, bool is_global);
Attributes(std::vector<IntrusivePtr<Attr>> a, IntrusivePtr<BroType> t,
Attributes(std::vector<IntrusivePtr<Attr>> a, IntrusivePtr<Type> t,
bool in_record, bool is_global);
Attributes(IntrusivePtr<BroType> t, bool in_record, bool is_global);
Attributes(IntrusivePtr<Type> t, bool in_record, bool is_global);
void AddAttr(IntrusivePtr<Attr> a);
@ -102,6 +136,14 @@ public:
void RemoveAttr(attr_tag t);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
Attr* FindAttr(::attr_tag t) const;
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
void RemoveAttr(::attr_tag t);
#pragma GCC diagnostic pop
void Describe(ODesc* d) const override;
void DescribeReST(ODesc* d, bool shorten = false) const;
@ -113,8 +155,13 @@ public:
protected:
void CheckAttr(Attr* attr);
IntrusivePtr<BroType> type;
IntrusivePtr<Type> type;
std::vector<IntrusivePtr<Attr>> attrs;
bool in_record;
bool global_var;
};
}
using Attr [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attr;
using Attributes [[deprecated("Remove in v4.1. Use zeek::detail::Attr instead.")]] = zeek::detail::Attributes;

View file

@ -4,23 +4,24 @@
#include "List.h"
class Expr;
typedef PList<Expr> expr_list;
class ID;
typedef PList<ID> id_list;
class Val;
typedef PList<Val> val_list;
using val_list = PList<Val>;
class Stmt;
typedef PList<Stmt> stmt_list;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
using expr_list = PList<zeek::detail::Expr>;
class BroType;
typedef PList<BroType> type_list;
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
using id_list = PList<zeek::detail::ID>;
class Attr;
typedef PList<Attr> attr_list;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
using stmt_list = PList<zeek::detail::Stmt>;
namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
using type_list = PList<zeek::Type>;
ZEEK_FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail);
using attr_list = PList<zeek::detail::Attr>;
class Timer;
typedef PList<Timer, ListOrder::UNORDERED> timer_list;
using timer_list = PList<Timer, ListOrder::UNORDERED>;

View file

@ -26,7 +26,7 @@ Brofiler::~Brofiler()
Unref(s);
}
void Brofiler::AddStmt(Stmt* s)
void Brofiler::AddStmt(zeek::detail::Stmt* s)
{
if ( ignoring != 0 )
return;
@ -127,7 +127,7 @@ bool Brofiler::WriteStats()
return false;
}
for ( list<Stmt*>::const_iterator it = stmts.begin();
for ( list<zeek::detail::Stmt*>::const_iterator it = stmts.begin();
it != stmts.end(); ++it )
{
ODesc location_info;
@ -154,4 +154,3 @@ bool Brofiler::WriteStats()
fclose(f);
return true;
}

View file

@ -5,7 +5,8 @@
#include <list>
#include <string>
class Stmt;
#include "util.h"
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
/**
* A simple class for managing stats of Bro script coverage across Bro runs.
@ -39,13 +40,13 @@ public:
void IncIgnoreDepth() { ignoring++; }
void DecIgnoreDepth() { ignoring--; }
void AddStmt(Stmt* s);
void AddStmt(zeek::detail::Stmt* s);
private:
/**
* The current, global Brofiler instance creates this list at parse-time.
*/
std::list<Stmt*> stmts;
std::list<zeek::detail::Stmt*> stmts;
/**
* Indicates whether new statments will not be considered as part of

View file

@ -15,17 +15,17 @@
#include "Func.h"
#include "IPAddr.h"
CompositeHash::CompositeHash(IntrusivePtr<TypeList> composite_type)
CompositeHash::CompositeHash(IntrusivePtr<zeek::TypeList> composite_type)
: type(std::move(composite_type))
{
singleton_tag = TYPE_INTERNAL_ERROR;
singleton_tag = zeek::TYPE_INTERNAL_ERROR;
// If the only element is a record, don't treat it as a
// singleton, since it needs to be evaluated specially.
if ( type->Types().size() == 1 )
{
if ( type->Types()[0]->Tag() == TYPE_RECORD )
if ( type->Types()[0]->Tag() == zeek::TYPE_RECORD )
{
is_complex_type = true;
is_singleton = false;
@ -72,10 +72,10 @@ CompositeHash::~CompositeHash()
// Computes the piece of the hash for Val*, returning the new kp.
char* CompositeHash::SingleValHash(bool type_check, char* kp0,
BroType* bt, Val* v, bool optional) const
zeek::Type* bt, Val* v, bool optional) const
{
char* kp1 = nullptr;
InternalTypeTag t = bt->InternalType();
zeek::InternalTypeTag t = bt->InternalType();
if ( optional )
{
@ -90,13 +90,13 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
if ( type_check )
{
InternalTypeTag vt = v->GetType()->InternalType();
zeek::InternalTypeTag vt = v->GetType()->InternalType();
if ( vt != t )
return nullptr;
}
switch ( t ) {
case TYPE_INTERNAL_INT:
case zeek::TYPE_INTERNAL_INT:
{
bro_int_t* kp = AlignAndPadType<bro_int_t>(kp0);
*kp = v->ForceAsInt();
@ -104,7 +104,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_UNSIGNED:
case zeek::TYPE_INTERNAL_UNSIGNED:
{
bro_uint_t* kp = AlignAndPadType<bro_uint_t>(kp0);
*kp = v->ForceAsUInt();
@ -112,7 +112,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_ADDR:
case zeek::TYPE_INTERNAL_ADDR:
{
uint32_t* kp = AlignAndPadType<uint32_t>(kp0);
v->AsAddr().CopyIPv6(kp);
@ -120,7 +120,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_SUBNET:
case zeek::TYPE_INTERNAL_SUBNET:
{
uint32_t* kp = AlignAndPadType<uint32_t>(kp0);
v->AsSubNet().Prefix().CopyIPv6(kp);
@ -129,7 +129,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_DOUBLE:
case zeek::TYPE_INTERNAL_DOUBLE:
{
double* kp = AlignAndPadType<double>(kp0);
*kp = v->InternalDouble();
@ -137,11 +137,11 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_VOID:
case TYPE_INTERNAL_OTHER:
case zeek::TYPE_INTERNAL_VOID:
case zeek::TYPE_INTERNAL_OTHER:
{
switch ( v->GetType()->Tag() ) {
case TYPE_FUNC:
case zeek::TYPE_FUNC:
{
uint32_t* kp = AlignAndPadType<uint32_t>(kp0);
*kp = v->AsFunc()->GetUniqueFuncID();
@ -149,7 +149,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
break;
}
case TYPE_PATTERN:
case zeek::TYPE_PATTERN:
{
const char* texts[2] = {
v->AsPattern()->PatternText(),
@ -173,19 +173,19 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
break;
}
case TYPE_RECORD:
case zeek::TYPE_RECORD:
{
char* kp = kp0;
RecordVal* rv = v->AsRecordVal();
RecordType* rt = bt->AsRecordType();
zeek::RecordType* rt = bt->AsRecordType();
int num_fields = rt->NumFields();
for ( int i = 0; i < num_fields; ++i )
{
auto rv_i = rv->GetField(i).get();
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(ATTR_OPTIONAL));
zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL));
if ( ! (rv_i || optional) )
return nullptr;
@ -200,7 +200,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
break;
}
case TYPE_TABLE:
case zeek::TYPE_TABLE:
{
int* kp = AlignAndPadType<int>(kp0);
TableVal* tv = v->AsTableVal();
@ -209,7 +209,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
auto tbl = tv->AsTable();
auto it = tbl->InitForIteration();
auto lv = make_intrusive<ListVal>(TYPE_ANY);
auto lv = make_intrusive<ListVal>(zeek::TYPE_ANY);
struct HashKeyComparer {
bool operator()(const HashKey* a, const HashKey* b) const
@ -259,11 +259,11 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_VECTOR:
case zeek::TYPE_VECTOR:
{
unsigned int* kp = AlignAndPadType<unsigned int>(kp0);
VectorVal* vv = v->AsVectorVal();
VectorType* vt = v->GetType()->AsVectorType();
zeek::VectorType* vt = v->GetType()->AsVectorType();
*kp = vv->Size();
kp1 = reinterpret_cast<char*>(kp+1);
for ( unsigned int i = 0; i < vv->Size(); ++i )
@ -287,7 +287,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_LIST:
case zeek::TYPE_LIST:
{
int* kp = AlignAndPadType<int>(kp0);
ListVal* lv = v->AsListVal();
@ -310,10 +310,10 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
}
break; // case TYPE_INTERNAL_VOID/OTHER
break; // case zeek::TYPE_INTERNAL_VOID/OTHER
}
case TYPE_INTERNAL_STRING:
case zeek::TYPE_INTERNAL_STRING:
{
// Align to int for the length field.
int* kp = AlignAndPadType<int>(kp0);
@ -328,7 +328,7 @@ char* CompositeHash::SingleValHash(bool type_check, char* kp0,
}
break;
case TYPE_INTERNAL_ERROR:
case zeek::TYPE_INTERNAL_ERROR:
return nullptr;
}
@ -343,9 +343,9 @@ std::unique_ptr<HashKey> CompositeHash::MakeHashKey(const Val& argv, bool type_c
if ( is_singleton )
return ComputeSingletonHash(v, type_check);
if ( is_complex_type && v->GetType()->Tag() != TYPE_LIST )
if ( is_complex_type && v->GetType()->Tag() != zeek::TYPE_LIST )
{
ListVal lv(TYPE_ANY);
ListVal lv(zeek::TYPE_ANY);
// Cast away const to use ListVal - but since we
// re-introduce const on the recursive call, it should
@ -369,7 +369,7 @@ std::unique_ptr<HashKey> CompositeHash::MakeHashKey(const Val& argv, bool type_c
const auto& tl = type->Types();
if ( type_check && v->GetType()->Tag() != TYPE_LIST )
if ( type_check && v->GetType()->Tag() != zeek::TYPE_LIST )
return nullptr;
auto lv = v->AsListVal();
@ -390,7 +390,7 @@ std::unique_ptr<HashKey> CompositeHash::MakeHashKey(const Val& argv, bool type_c
std::unique_ptr<HashKey> CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const
{
if ( v->GetType()->Tag() == TYPE_LIST )
if ( v->GetType()->Tag() == zeek::TYPE_LIST )
{
auto lv = v->AsListVal();
@ -404,25 +404,25 @@ std::unique_ptr<HashKey> CompositeHash::ComputeSingletonHash(const Val* v, bool
return nullptr;
switch ( singleton_tag ) {
case TYPE_INTERNAL_INT:
case TYPE_INTERNAL_UNSIGNED:
case zeek::TYPE_INTERNAL_INT:
case zeek::TYPE_INTERNAL_UNSIGNED:
return std::make_unique<HashKey>(v->ForceAsInt());
case TYPE_INTERNAL_ADDR:
case zeek::TYPE_INTERNAL_ADDR:
return v->AsAddr().MakeHashKey();
case TYPE_INTERNAL_SUBNET:
case zeek::TYPE_INTERNAL_SUBNET:
return v->AsSubNet().MakeHashKey();
case TYPE_INTERNAL_DOUBLE:
case zeek::TYPE_INTERNAL_DOUBLE:
return std::make_unique<HashKey>(v->InternalDouble());
case TYPE_INTERNAL_VOID:
case TYPE_INTERNAL_OTHER:
if ( v->GetType()->Tag() == TYPE_FUNC )
case zeek::TYPE_INTERNAL_VOID:
case zeek::TYPE_INTERNAL_OTHER:
if ( v->GetType()->Tag() == zeek::TYPE_FUNC )
return std::make_unique<HashKey>(v->AsFunc()->GetUniqueFuncID());
if ( v->GetType()->Tag() == TYPE_PATTERN )
if ( v->GetType()->Tag() == zeek::TYPE_PATTERN )
{
const char* texts[2] = {
v->AsPattern()->PatternText(),
@ -438,10 +438,10 @@ std::unique_ptr<HashKey> CompositeHash::ComputeSingletonHash(const Val* v, bool
reporter->InternalError("bad index type in CompositeHash::ComputeSingletonHash");
return nullptr;
case TYPE_INTERNAL_STRING:
case zeek::TYPE_INTERNAL_STRING:
return std::make_unique<HashKey>(v->AsString());
case TYPE_INTERNAL_ERROR:
case zeek::TYPE_INTERNAL_ERROR:
return nullptr;
default:
@ -450,53 +450,53 @@ std::unique_ptr<HashKey> CompositeHash::ComputeSingletonHash(const Val* v, bool
}
}
int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
int CompositeHash::SingleTypeKeySize(zeek::Type* bt, const Val* v,
bool type_check, int sz, bool optional,
bool calc_static_size) const
{
InternalTypeTag t = bt->InternalType();
zeek::InternalTypeTag t = bt->InternalType();
if ( optional )
sz = SizeAlign(sz, sizeof(char));
if ( type_check && v )
{
InternalTypeTag vt = v->GetType()->InternalType();
zeek::InternalTypeTag vt = v->GetType()->InternalType();
if ( vt != t )
return 0;
}
switch ( t ) {
case TYPE_INTERNAL_INT:
case TYPE_INTERNAL_UNSIGNED:
case zeek::TYPE_INTERNAL_INT:
case zeek::TYPE_INTERNAL_UNSIGNED:
sz = SizeAlign(sz, sizeof(bro_int_t));
break;
case TYPE_INTERNAL_ADDR:
case zeek::TYPE_INTERNAL_ADDR:
sz = SizeAlign(sz, sizeof(uint32_t));
sz += sizeof(uint32_t) * 3; // to make a total of 4 words
break;
case TYPE_INTERNAL_SUBNET:
case zeek::TYPE_INTERNAL_SUBNET:
sz = SizeAlign(sz, sizeof(uint32_t));
sz += sizeof(uint32_t) * 4; // to make a total of 5 words
break;
case TYPE_INTERNAL_DOUBLE:
case zeek::TYPE_INTERNAL_DOUBLE:
sz = SizeAlign(sz, sizeof(double));
break;
case TYPE_INTERNAL_VOID:
case TYPE_INTERNAL_OTHER:
case zeek::TYPE_INTERNAL_VOID:
case zeek::TYPE_INTERNAL_OTHER:
{
switch ( bt->Tag() ) {
case TYPE_FUNC:
case zeek::TYPE_FUNC:
{
sz = SizeAlign(sz, sizeof(uint32_t));
break;
}
case TYPE_PATTERN:
case zeek::TYPE_PATTERN:
{
if ( ! v )
return (optional && ! calc_static_size) ? sz : 0;
@ -507,16 +507,16 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
break;
}
case TYPE_RECORD:
case zeek::TYPE_RECORD:
{
const RecordVal* rv = v ? v->AsRecordVal() : nullptr;
RecordType* rt = bt->AsRecordType();
zeek::RecordType* rt = bt->AsRecordType();
int num_fields = rt->NumFields();
for ( int i = 0; i < num_fields; ++i )
{
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(ATTR_OPTIONAL));
zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL));
sz = SingleTypeKeySize(rt->GetFieldType(i).get(),
rv ? rv->GetField(i).get() : nullptr,
@ -529,7 +529,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
break;
}
case TYPE_TABLE:
case zeek::TYPE_TABLE:
{
if ( ! v )
return (optional && ! calc_static_size) ? sz : 0;
@ -558,7 +558,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
break;
}
case TYPE_VECTOR:
case zeek::TYPE_VECTOR:
{
if ( ! v )
return (optional && ! calc_static_size) ? sz : 0;
@ -580,7 +580,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
break;
}
case TYPE_LIST:
case zeek::TYPE_LIST:
{
if ( ! v )
return (optional && ! calc_static_size) ? sz : 0;
@ -604,10 +604,10 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
}
}
break; // case TYPE_INTERNAL_VOID/OTHER
break; // case zeek::TYPE_INTERNAL_VOID/OTHER
}
case TYPE_INTERNAL_STRING:
case zeek::TYPE_INTERNAL_STRING:
if ( ! v )
return (optional && ! calc_static_size) ? sz : 0;
@ -616,7 +616,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v,
sz += v->AsString()->Len();
break;
case TYPE_INTERNAL_ERROR:
case zeek::TYPE_INTERNAL_ERROR:
return 0;
}
@ -629,7 +629,7 @@ int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_stati
if ( v )
{
if ( type_check && v->GetType()->Tag() != TYPE_LIST )
if ( type_check && v->GetType()->Tag() != zeek::TYPE_LIST )
return 0;
auto lv = v->AsListVal();
@ -711,7 +711,7 @@ int CompositeHash::SizeAlign(int offset, unsigned int size) const
IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
{
auto l = make_intrusive<ListVal>(TYPE_ANY);
auto l = make_intrusive<ListVal>(zeek::TYPE_ANY);
const auto& tl = type->Types();
const char* kp = (const char*) k.Key();
const char* const k_end = kp + k.Size();
@ -731,15 +731,15 @@ IntrusivePtr<ListVal> CompositeHash::RecoverVals(const HashKey& k) const
}
const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
const char* const k_end, BroType* t,
const char* const k_end, zeek::Type* t,
IntrusivePtr<Val>* pval, bool optional) const
{
// k->Size() == 0 for a single empty string.
if ( kp0 >= k_end && k.Size() > 0 )
reporter->InternalError("over-ran key in CompositeHash::RecoverVals");
TypeTag tag = t->Tag();
InternalTypeTag it = t->InternalType();
zeek::TypeTag tag = t->Tag();
zeek::InternalTypeTag it = t->InternalType();
const char* kp1 = nullptr;
if ( optional )
@ -755,16 +755,16 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
switch ( it ) {
case TYPE_INTERNAL_INT:
case zeek::TYPE_INTERNAL_INT:
{
const bro_int_t* const kp = AlignType<bro_int_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+1);
if ( tag == TYPE_ENUM )
if ( tag == zeek::TYPE_ENUM )
*pval = t->AsEnumType()->GetVal(*kp);
else if ( tag == TYPE_BOOL )
else if ( tag == zeek::TYPE_BOOL )
*pval = val_mgr->Bool(*kp);
else if ( tag == TYPE_INT )
else if ( tag == zeek::TYPE_INT )
*pval = val_mgr->Int(*kp);
else
{
@ -774,18 +774,18 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_UNSIGNED:
case zeek::TYPE_INTERNAL_UNSIGNED:
{
const bro_uint_t* const kp = AlignType<bro_uint_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+1);
switch ( tag ) {
case TYPE_COUNT:
case TYPE_COUNTER:
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
*pval = val_mgr->Count(*kp);
break;
case TYPE_PORT:
case zeek::TYPE_PORT:
*pval = val_mgr->Port(*kp);
break;
@ -797,21 +797,21 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_DOUBLE:
case zeek::TYPE_INTERNAL_DOUBLE:
{
const double* const kp = AlignType<double>(kp0);
kp1 = reinterpret_cast<const char*>(kp+1);
if ( tag == TYPE_INTERVAL )
if ( tag == zeek::TYPE_INTERVAL )
*pval = make_intrusive<IntervalVal>(*kp, 1.0);
else if ( tag == TYPE_TIME )
else if ( tag == zeek::TYPE_TIME )
*pval = make_intrusive<TimeVal>(*kp);
else
*pval = make_intrusive<DoubleVal>(*kp);
}
break;
case TYPE_INTERNAL_ADDR:
case zeek::TYPE_INTERNAL_ADDR:
{
const uint32_t* const kp = AlignType<uint32_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+4);
@ -819,7 +819,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
IPAddr addr(IPv6, kp, IPAddr::Network);
switch ( tag ) {
case TYPE_ADDR:
case zeek::TYPE_ADDR:
*pval = make_intrusive<AddrVal>(addr);
break;
@ -831,7 +831,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_SUBNET:
case zeek::TYPE_INTERNAL_SUBNET:
{
const uint32_t* const kp = AlignType<uint32_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+5);
@ -839,11 +839,11 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_VOID:
case TYPE_INTERNAL_OTHER:
case zeek::TYPE_INTERNAL_VOID:
case zeek::TYPE_INTERNAL_OTHER:
{
switch ( t->Tag() ) {
case TYPE_FUNC:
case zeek::TYPE_FUNC:
{
const uint32_t* const kp = AlignType<uint32_t>(kp0);
kp1 = reinterpret_cast<const char*>(kp+1);
@ -859,18 +859,18 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
if ( ! pvt )
reporter->InternalError("bad aggregate Val in CompositeHash::RecoverOneVal()");
else if ( t->Tag() != TYPE_FUNC && ! same_type(pvt, t) )
else if ( t->Tag() != zeek::TYPE_FUNC && ! same_type(pvt, t) )
// ### Maybe fix later, but may be fundamentally
// un-checkable --US
reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()");
// ### A crude approximation for now.
else if ( t->Tag() == TYPE_FUNC && pvt->Tag() != TYPE_FUNC )
else if ( t->Tag() == zeek::TYPE_FUNC && pvt->Tag() != zeek::TYPE_FUNC )
reporter->InternalError("inconsistent aggregate Val in CompositeHash::RecoverOneVal()");
}
break;
case TYPE_PATTERN:
case zeek::TYPE_PATTERN:
{
RE_Matcher* re = nullptr;
if ( is_singleton )
@ -897,10 +897,10 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_RECORD:
case zeek::TYPE_RECORD:
{
const char* kp = kp0;
RecordType* rt = t->AsRecordType();
zeek::RecordType* rt = t->AsRecordType();
int num_fields = rt->NumFields();
std::vector<IntrusivePtr<Val>> values;
@ -909,8 +909,8 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
{
IntrusivePtr<Val> v;
Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(ATTR_OPTIONAL));
zeek::detail::Attributes* a = rt->FieldDecl(i)->attrs.get();
bool optional = (a && a->Find(zeek::detail::ATTR_OPTIONAL));
kp = RecoverOneVal(k, kp, k_end,
rt->GetFieldType(i).get(), &v, optional);
@ -940,13 +940,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_TABLE:
case zeek::TYPE_TABLE:
{
int n;
const int* const kp = AlignType<int>(kp0);
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
TableType* tt = t->AsTableType();
zeek::TableType* tt = t->AsTableType();
auto tv = make_intrusive<TableVal>(IntrusivePtr{NewRef{}, tt});
for ( int i = 0; i < n; ++i )
@ -969,13 +969,13 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_VECTOR:
case zeek::TYPE_VECTOR:
{
unsigned int n;
const unsigned int* kp = AlignType<unsigned int>(kp0);
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
VectorType* vt = t->AsVectorType();
zeek::VectorType* vt = t->AsVectorType();
auto vv = make_intrusive<VectorVal>(IntrusivePtr{NewRef{}, vt});
for ( unsigned int i = 0; i < n; ++i )
@ -999,19 +999,19 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_LIST:
case zeek::TYPE_LIST:
{
int n;
const int* const kp = AlignType<int>(kp0);
n = *kp;
kp1 = reinterpret_cast<const char*>(kp+1);
TypeList* tl = t->AsTypeList();
auto lv = make_intrusive<ListVal>(TYPE_ANY);
zeek::TypeList* tl = t->AsTypeList();
auto lv = make_intrusive<ListVal>(zeek::TYPE_ANY);
for ( int i = 0; i < n; ++i )
{
IntrusivePtr<Val> v;
BroType* it = tl->Types()[i].get();
zeek::Type* it = tl->Types()[i].get();
kp1 = RecoverOneVal(k, kp1, k_end, it, &v, false);
lv->Append(std::move(v));
}
@ -1028,7 +1028,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_STRING:
case zeek::TYPE_INTERNAL_STRING:
{
// There is a minor issue here -- the pointer does not have to
// be aligned by int in the singleton case.
@ -1051,7 +1051,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey& k, const char* kp0,
}
break;
case TYPE_INTERNAL_ERROR:
case zeek::TYPE_INTERNAL_ERROR:
break;
}

View file

@ -12,7 +12,7 @@ class HashKey;
class CompositeHash {
public:
explicit CompositeHash(IntrusivePtr<TypeList> composite_type);
explicit CompositeHash(IntrusivePtr<zeek::TypeList> composite_type);
~CompositeHash();
// Compute the hash corresponding to the given index val,
@ -37,7 +37,7 @@ protected:
// Computes the piece of the hash for Val*, returning the new kp.
// Used as a helper for ComputeHash in the non-singleton case.
char* SingleValHash(bool type_check, char* kp, BroType* bt, Val* v,
char* SingleValHash(bool type_check, char* kp, zeek::Type* bt, Val* v,
bool optional) const;
// Recovers just one Val of possibly many; called from RecoverVals.
@ -46,7 +46,7 @@ protected:
// upon errors, so there is no return value for invalid input.
const char* RecoverOneVal(const HashKey& k,
const char* kp, const char* const k_end,
BroType* t, IntrusivePtr<Val>* pval, bool optional) const;
zeek::Type* t, IntrusivePtr<Val>* pval, bool optional) const;
// Rounds the given pointer up to the nearest multiple of the
// given size, if not already a multiple.
@ -85,11 +85,11 @@ protected:
int ComputeKeySize(const Val* v, bool type_check,
bool calc_static_size) const;
int SingleTypeKeySize(BroType*, const Val*,
int SingleTypeKeySize(zeek::Type*, const Val*,
bool type_check, int sz, bool optional,
bool calc_static_size) const;
IntrusivePtr<TypeList> type;
IntrusivePtr<zeek::TypeList> type;
char* key; // space for composite key
int size;
bool is_singleton; // if just one type in index
@ -97,5 +97,5 @@ protected:
// If one type, but not normal "singleton", e.g. record.
bool is_complex_type;
InternalTypeTag singleton_tag;
zeek::InternalTypeTag singleton_tag;
};

View file

@ -175,10 +175,10 @@ void DNS_Mgr_mapping_delete_func(void* v)
static IntrusivePtr<TableVal> empty_addr_set()
{
auto addr_t = base_type(TYPE_ADDR);
auto set_index = make_intrusive<TypeList>(addr_t);
auto addr_t = zeek::base_type(zeek::TYPE_ADDR);
auto set_index = make_intrusive<zeek::TypeList>(addr_t);
set_index->Append(std::move(addr_t));
auto s = make_intrusive<SetType>(std::move(set_index), nullptr);
auto s = make_intrusive<zeek::SetType>(std::move(set_index), nullptr);
return make_intrusive<TableVal>(std::move(s));
}
@ -283,7 +283,7 @@ IntrusivePtr<ListVal> DNS_Mapping::Addrs()
if ( ! addrs_val )
{
auto addrs_val = make_intrusive<ListVal>(TYPE_ADDR);
auto addrs_val = make_intrusive<ListVal>(zeek::TYPE_ADDR);
for ( int i = 0; i < num_addrs; ++i )
addrs_val->Append(make_intrusive<AddrVal>(addrs[i]));
@ -450,7 +450,7 @@ void DNS_Mgr::InitSource()
void DNS_Mgr::InitPostScript()
{
dm_rec = zeek::id::find_type<RecordType>("dns_mapping");
dm_rec = zeek::id::find_type<zeek::RecordType>("dns_mapping");
// Registering will call Init()
iosource_mgr->Register(this, true);
@ -465,7 +465,7 @@ static IntrusivePtr<TableVal> fake_name_lookup_result(const char* name)
{
hash128_t hash;
KeyedHash::StaticHash128(name, strlen(name), &hash);
auto hv = make_intrusive<ListVal>(TYPE_ADDR);
auto hv = make_intrusive<ListVal>(zeek::TYPE_ADDR);
hv->Append(make_intrusive<AddrVal>(reinterpret_cast<const uint32_t*>(&hash)));
return hv->ToSetVal();
}
@ -872,7 +872,7 @@ void DNS_Mgr::CompareMappings(DNS_Mapping* prev_dm, DNS_Mapping* new_dm)
IntrusivePtr<ListVal> DNS_Mgr::AddrListDelta(ListVal* al1, ListVal* al2)
{
auto delta = make_intrusive<ListVal>(TYPE_ADDR);
auto delta = make_intrusive<ListVal>(zeek::TYPE_ADDR);
for ( int i = 0; i < al1->Length(); ++i )
{

View file

@ -11,6 +11,7 @@
#include "EventHandler.h"
#include "iosource/IOSource.h"
#include "IPAddr.h"
#include "util.h"
template <class T> class IntrusivePtr;
class Val;
@ -18,9 +19,10 @@ class ListVal;
class TableVal;
class Func;
class EventHandler;
class RecordType;
class DNS_Mgr_Request;
ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek);
typedef PList<DNS_Mgr_Request> DNS_mgr_request_list;
struct nb_dns_info;
@ -149,7 +151,7 @@ protected:
bool did_init;
IntrusivePtr<RecordType> dm_rec;
IntrusivePtr<zeek::RecordType> dm_rec;
typedef std::list<LookupCallback*> CallbackList;

View file

@ -166,7 +166,7 @@ bool DbgBreakpoint::SetLocation(ParseLocationRec plr, std::string_view loc_str)
return true;
}
bool DbgBreakpoint::SetLocation(Stmt* stmt)
bool DbgBreakpoint::SetLocation(zeek::detail::Stmt* stmt)
{
if ( ! stmt )
return false;
@ -258,8 +258,8 @@ BreakCode DbgBreakpoint::HasHit()
return bcHit;
}
if ( ! IsIntegral(yes->GetType()->Tag()) &&
! IsBool(yes->GetType()->Tag()) )
if ( ! zeek::IsIntegral(yes->GetType()->Tag()) &&
! zeek::IsBool(yes->GetType()->Tag()) )
{
PrintHitMsg();
debug_msg("Breakpoint condition should return an integral type");
@ -290,7 +290,7 @@ BreakCode DbgBreakpoint::HasHit()
return bcHit;
}
BreakCode DbgBreakpoint::ShouldBreak(Stmt* s)
BreakCode DbgBreakpoint::ShouldBreak(zeek::detail::Stmt* s)
{
if ( ! IsEnabled() )
return bcNoHit;

View file

@ -3,9 +3,11 @@
#pragma once
#include <string>
#include "util.h"
struct ParseLocationRec;
class Stmt;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
enum BreakCode { bcNoHit, bcHit, bcHitAndDelete };
class DbgBreakpoint {
@ -20,7 +22,7 @@ public:
// True if breakpoint could be set; false otherwise
bool SetLocation(ParseLocationRec plr, std::string_view loc_str);
bool SetLocation(Stmt* stmt);
bool SetLocation(zeek::detail::Stmt* stmt);
bool SetLocation(double time);
bool Reset(); // cancel and re-apply bpt when restarting execution
@ -35,7 +37,7 @@ public:
//
// NOTE: If it returns a hit, the DbgBreakpoint object will take
// appropriate action (e.g., resetting counters).
BreakCode ShouldBreak(Stmt* s);
BreakCode ShouldBreak(zeek::detail::Stmt* s);
BreakCode ShouldBreak(double t);
const std::string& GetCondition() const { return condition; }
@ -70,7 +72,7 @@ protected:
bool enabled; // ### comment this and next
bool temporary;
Stmt* at_stmt;
zeek::detail::Stmt* at_stmt;
double at_time; // break when the virtual time is this
// Support for conditional and N'th time breakpoints.

View file

@ -12,7 +12,7 @@ DbgWatch::DbgWatch(BroObj* var_to_watch)
reporter->InternalError("DbgWatch unimplemented");
}
DbgWatch::DbgWatch(Expr* expr_to_watch)
DbgWatch::DbgWatch(zeek::detail::Expr* expr_to_watch)
{
reporter->InternalError("DbgWatch unimplemented");
}

View file

@ -2,16 +2,19 @@
#pragma once
#include "util.h"
class BroObj;
class Expr;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
class DbgWatch {
public:
explicit DbgWatch(BroObj* var_to_watch);
explicit DbgWatch(Expr* expr_to_watch);
explicit DbgWatch(zeek::detail::Expr* expr_to_watch);
~DbgWatch();
protected:
BroObj* var;
Expr* expr;
zeek::detail::Expr* expr;
};

View file

@ -135,7 +135,7 @@ int TraceState::LogTrace(const char* fmt, ...)
// Prefix includes timestamp and file/line info.
fprintf(trace_file, "%.6f ", network_time);
const Stmt* stmt;
const zeek::detail::Stmt* stmt;
Location loc;
loc.filename = nullptr;
@ -174,7 +174,7 @@ int TraceState::LogTrace(const char* fmt, ...)
// Helper functions.
void get_first_statement(Stmt* list, Stmt*& first, Location& loc)
void get_first_statement(zeek::detail::Stmt* list, zeek::detail::Stmt*& first, Location& loc)
{
if ( ! list )
{
@ -231,7 +231,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
return;
}
Stmt* body = nullptr; // the particular body we care about; 0 = all
zeek::detail::Stmt* body = nullptr; // the particular body we care about; 0 = all
if ( bodies.size() == 1 )
body = bodies[0].stmts.get();
@ -243,7 +243,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
"Please choose one of the following options:\n");
for ( unsigned int i = 0; i < bodies.size(); ++i )
{
Stmt* first;
zeek::detail::Stmt* first;
Location stmt_loc;
get_first_statement(bodies[i].stmts.get(), first, stmt_loc);
debug_msg("[%d] %s:%d\n", i+1, stmt_loc.filename, stmt_loc.first_line);
@ -286,7 +286,7 @@ static void parse_function_name(vector<ParseLocationRec>& result,
plr.type = plrFunction;
// Find first atomic (non-STMT_LIST) statement
Stmt* first;
zeek::detail::Stmt* first;
Location stmt_loc;
if ( body )
@ -728,7 +728,7 @@ static char* get_prompt(bool reset_counter = false)
return prompt;
}
string get_context_description(const Stmt* stmt, const Frame* frame)
string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame)
{
ODesc d;
const BroFunc* func = frame ? frame->GetFunction() : nullptr;
@ -776,7 +776,7 @@ int dbg_handle_debug_input()
else
current_module = GLOBAL_MODULE_NAME;
const Stmt* stmt = curr_frame->GetNextStmt();
const zeek::detail::Stmt* stmt = curr_frame->GetNextStmt();
if ( ! stmt )
reporter->InternalError("Assertion failed: stmt != 0");
@ -840,7 +840,7 @@ int dbg_handle_debug_input()
// Return true to continue execution, false to abort.
bool pre_execute_stmt(Stmt* stmt, Frame* f)
bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f)
{
if ( ! g_policy_debug ||
stmt->Tag() == STMT_LIST || stmt->Tag() == STMT_NULL )
@ -905,7 +905,7 @@ bool pre_execute_stmt(Stmt* stmt, Frame* f)
return true;
}
bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow)
bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow)
{
// Handle the case where someone issues a "next" debugger command,
// but we're at a return statement, so the next statement is in
@ -935,7 +935,7 @@ bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow)
// Evaluates the given expression in the context of the currently selected
// frame. Returns the resulting value, or nil if none (or there was an error).
Expr* g_curr_debug_expr = nullptr;
zeek::detail::Expr* g_curr_debug_expr = nullptr;
const char* g_curr_debug_error = nullptr;
bool in_debug = false;

View file

@ -5,6 +5,7 @@
#include "Obj.h"
#include "Queue.h"
#include "StmtEnums.h"
#include "util.h"
#include <vector>
#include <map>
@ -12,14 +13,15 @@
template <class T> class IntrusivePtr;
class Val;
class Stmt;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
// This needs to be defined before we do the includes that come after it.
enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction };
struct ParseLocationRec {
ParseLocationRecType type;
int32_t line;
Stmt* stmt;
zeek::detail::Stmt* stmt;
const char* filename;
};
@ -33,7 +35,7 @@ class DbgDisplay;
class StmtHashFn;
typedef std::map<int, DbgBreakpoint*> BPIDMapType;
typedef std::multimap<const Stmt*, DbgBreakpoint*> BPMapType;
typedef std::multimap<const zeek::detail::Stmt*, DbgBreakpoint*> BPMapType;
extern std::string current_module;
@ -104,15 +106,15 @@ private:
class StmtLocMapping {
public:
StmtLocMapping() { }
StmtLocMapping(const Location* l, Stmt* s) { loc = *l; stmt = s; }
StmtLocMapping(const Location* l, zeek::detail::Stmt* s) { loc = *l; stmt = s; }
bool StartsAfter(const StmtLocMapping* m2);
const Location& Loc() const { return loc; }
Stmt* Statement() const { return stmt; }
zeek::detail::Stmt* Statement() const { return stmt; }
protected:
Location loc;
Stmt* stmt;
zeek::detail::Stmt* stmt;
};
@ -143,8 +145,8 @@ std::vector<ParseLocationRec> parse_location_string(const std::string& s);
// Debugging hooks.
// Return true to continue execution, false to abort.
bool pre_execute_stmt(Stmt* stmt, Frame* f);
bool post_execute_stmt(Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow);
bool pre_execute_stmt(zeek::detail::Stmt* stmt, Frame* f);
bool post_execute_stmt(zeek::detail::Stmt* stmt, Frame* f, Val* result, stmt_flow_type* flow);
// Returns 1 if successful, 0 otherwise.
// If cmdfile is non-nil, it contains the location of a file of commands
@ -168,7 +170,7 @@ IntrusivePtr<Val> dbg_eval_expr(const char* expr);
int dbg_read_internal_state();
// Get line that looks like "In FnFoo(arg = val) at File:Line".
std::string get_context_description(const Stmt* stmt, const Frame* frame);
std::string get_context_description(const zeek::detail::Stmt* stmt, const Frame* frame);
extern Frame* g_dbg_locals; // variables created within debugger context

View file

@ -30,13 +30,13 @@ using namespace std;
//
// Helper routines
//
bool string_is_regex(const string& s)
static bool string_is_regex(const string& s)
{
return strpbrk(s.data(), "?*\\+");
}
void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
bool func_only = false)
static void lookup_global_symbols_regex(const string& orig_regex, vector<zeek::detail::ID*>& matches,
bool func_only = false)
{
if ( streq(orig_regex.c_str(), "") )
return;
@ -61,18 +61,18 @@ void lookup_global_symbols_regex(const string& orig_regex, vector<ID*>& matches,
Scope* global = global_scope();
const auto& syms = global->Vars();
ID* nextid;
zeek::detail::ID* nextid;
for ( const auto& sym : syms )
{
ID* nextid = sym.second.get();
if ( ! func_only || nextid->GetType()->Tag() == TYPE_FUNC )
zeek::detail::ID* nextid = sym.second.get();
if ( ! func_only || nextid->GetType()->Tag() == zeek::TYPE_FUNC )
if ( ! regexec (&re, nextid->Name(), 0, 0, 0) )
matches.push_back(nextid);
}
}
void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
bool func_only = false)
static void choose_global_symbols_regex(const string& regex, vector<zeek::detail::ID*>& choices,
bool func_only = false)
{
lookup_global_symbols_regex(regex, choices, func_only);
@ -111,7 +111,7 @@ void choose_global_symbols_regex(const string& regex, vector<ID*>& choices,
int option = atoi(input.c_str());
if ( option > 0 && option <= (int) choices.size() )
{
ID* choice = choices[option - 1];
zeek::detail::ID* choice = choices[option - 1];
choices.clear();
choices.push_back(choice);
return;
@ -216,7 +216,7 @@ static int dbg_backtrace_internal(int start, int end)
for ( int i = start; i >= end; --i )
{
const Frame* f = g_frame_stack[i];
const Stmt* stmt = f ? f->GetNextStmt() : nullptr;
const zeek::detail::Stmt* stmt = f ? f->GetNextStmt() : nullptr;
string context = get_context_description(stmt, f);
debug_msg("#%d %s\n",
@ -333,7 +333,7 @@ int dbg_cmd_frame(DebugCmd cmd, const vector<string>& args)
// Set the current location to the new frame being looked at
// for 'list', 'break', etc.
const Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt();
const zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt();
if ( ! stmt )
reporter->InternalError("Assertion failed: %s", "stmt != 0");
@ -373,7 +373,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector<string>& args)
g_frame_stack.size() - 1 -
g_debugger_state.curr_frame_idx;
Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt();
zeek::detail::Stmt* stmt = g_frame_stack[user_frame_number]->GetNextStmt();
if ( ! stmt )
reporter->InternalError("Assertion failed: %s", "stmt != 0");
@ -398,7 +398,7 @@ int dbg_cmd_break(DebugCmd cmd, const vector<string>& args)
vector<string> locstrings;
if ( string_is_regex(args[0]) )
{
vector<ID*> choices;
vector<zeek::detail::ID*> choices;
choose_global_symbols_regex(args[0], choices, true);
for ( unsigned int i = 0; i < choices.size(); ++i )
locstrings.push_back(choices[i]->Name());

View file

@ -163,7 +163,7 @@ void DebugLogger::Log(DebugStream stream, const char* fmt, ...)
fflush(file);
}
void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...)
void DebugLogger::Log(const zeek::plugin::Plugin& plugin, const char* fmt, ...)
{
std::string tok = std::string("plugin-") + plugin.Name();
tok = strreplace(tok, "::", "-");

View file

@ -45,7 +45,7 @@ enum DebugStream {
#define PLUGIN_DBG_LOG(plugin, args...) debug_logger.Log(plugin, args)
namespace plugin { class Plugin; }
namespace zeek::plugin { class Plugin; }
class DebugLogger {
public:
@ -56,7 +56,7 @@ public:
void OpenDebugLog(const char* filename = 0);
void Log(DebugStream stream, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
void Log(const plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
void Log(const zeek::plugin::Plugin& plugin, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
void PushIndent(DebugStream stream)
{ ++streams[int(stream)].indent; }

View file

@ -403,19 +403,19 @@ void ODesc::Clear()
}
}
bool ODesc::PushType(const BroType* type)
bool ODesc::PushType(const zeek::Type* type)
{
auto res = encountered_types.insert(type);
return std::get<1>(res);
}
bool ODesc::PopType(const BroType* type)
bool ODesc::PopType(const zeek::Type* type)
{
size_t res = encountered_types.erase(type);
return (res == 1);
}
bool ODesc::FindType(const BroType* type)
bool ODesc::FindType(const zeek::Type* type)
{
auto res = encountered_types.find(type);

View file

@ -25,7 +25,9 @@ typedef enum {
class BroFile;
class IPAddr;
class IPPrefix;
class BroType;
namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
class ODesc {
public:
@ -146,9 +148,9 @@ public:
// Used to determine recursive types. Records push their types on here;
// if the same type (by address) is re-encountered, processing aborts.
bool PushType(const BroType* type);
bool PopType(const BroType* type);
bool FindType(const BroType* type);
bool PushType(const zeek::Type* type);
bool PopType(const zeek::Type* type);
bool FindType(const zeek::Type* type);
protected:
void Indent();
@ -204,5 +206,5 @@ protected:
bool do_flush;
bool include_stats;
std::set<const BroType*> encountered_types;
std::set<const zeek::Type*> encountered_types;
};

View file

@ -145,7 +145,7 @@ protected:
analyzer::ID current_aid;
RecordVal* src_val;
bool draining;
bro::Flare queue_flare;
zeek::detail::Flare queue_flare;
};
extern EventMgr mgr;

View file

@ -26,7 +26,7 @@ EventHandler::operator bool() const
|| ! auto_publish.empty());
}
const IntrusivePtr<FuncType>& EventHandler::GetType(bool check_export)
const IntrusivePtr<zeek::FuncType>& EventHandler::GetType(bool check_export)
{
if ( type )
return type;
@ -35,12 +35,12 @@ const IntrusivePtr<FuncType>& EventHandler::GetType(bool check_export)
check_export);
if ( ! id )
return FuncType::nil;
return zeek::FuncType::nil;
if ( id->GetType()->Tag() != TYPE_FUNC )
return FuncType::nil;
if ( id->GetType()->Tag() != zeek::TYPE_FUNC )
return zeek::FuncType::nil;
type = id->GetType<FuncType>();
type = id->GetType<zeek::FuncType>();
return type;
}
@ -117,7 +117,7 @@ void EventHandler::NewEvent(zeek::Args* vl)
return;
const auto& args = GetType()->Params();
static auto call_argument_vector = zeek::id::find_type<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);
for ( int i = 0; i < args->NumFields(); i++ )
@ -126,7 +126,7 @@ void EventHandler::NewEvent(zeek::Args* vl)
const auto& ftype = args->GetFieldType(i);
auto fdefault = args->FieldDefault(i);
static auto call_argument = zeek::id::find_type<RecordType>("call_argument");
static auto call_argument = zeek::id::find_type<zeek::RecordType>("call_argument");
auto rec = make_intrusive<RecordVal>(call_argument);
rec->Assign(0, make_intrusive<StringVal>(fname));
@ -150,4 +150,3 @@ void EventHandler::NewEvent(zeek::Args* vl)
});
mgr.Dispatch(ev);
}

View file

@ -23,10 +23,10 @@ public:
[[deprecated("Remove in v4.1. Use GetFunc().")]]
Func* LocalHandler() { return local.get(); }
const IntrusivePtr<FuncType>& GetType(bool check_export = true);
const IntrusivePtr<zeek::FuncType>& GetType(bool check_export = true);
[[deprecated("Remove in v4.1. Use GetType().")]]
FuncType* FType(bool check_export = true)
zeek::FuncType* FType(bool check_export = true)
{ return GetType().get(); }
void SetFunc(IntrusivePtr<Func> f);
@ -69,7 +69,7 @@ private:
std::string name;
IntrusivePtr<Func> local;
IntrusivePtr<FuncType> type;
IntrusivePtr<zeek::FuncType> type;
bool used; // this handler is indeed used somewhere
bool enabled;
bool error_handler; // this handler reports error messages.

File diff suppressed because it is too large Load diff

View file

@ -17,6 +17,13 @@
#include "Val.h"
#include "ZeekArgs.h"
template <class T> class IntrusivePtr;
class Frame;
class Scope;
struct function_ingredients;
namespace zeek::detail {
enum BroExprTag : int {
EXPR_ANY = -1,
EXPR_NAME, EXPR_CONST,
@ -58,26 +65,20 @@ enum BroExprTag : int {
extern const char* expr_name(BroExprTag t);
template <class T> class IntrusivePtr;
class Stmt;
class Frame;
class Scope;
class ListExpr;
class NameExpr;
class IndexExpr;
class AssignExpr;
class CallExpr;
class EventExpr;
struct function_ingredients;
class Stmt;
class Expr : public BroObj {
public:
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() const { return type.get(); }
zeek::Type* Type() const { return type.get(); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<zeek::Type>& GetType() const
{ return type; }
template <class T>
@ -96,7 +97,7 @@ public:
// into the given aggregate of the given type. Note that
// return type is void since it's updating an existing
// value, rather than creating a new one.
virtual void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f)
virtual void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f)
const;
// Assign to the given value, if appropriate.
@ -104,7 +105,7 @@ public:
// Returns the type corresponding to this expression interpreted
// as an initialization. Returns nil if the initialization is illegal.
virtual IntrusivePtr<BroType> InitType() const;
virtual IntrusivePtr<zeek::Type> InitType() const;
// Returns true if this expression, interpreted as an initialization,
// constitutes a record element, false otherwise. If the TypeDecl*
@ -117,7 +118,7 @@ public:
// with the given type. If "aggr" is non-nil, then this expression
// is an element of the given aggregate, and it is added to it
// accordingly.
virtual IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const;
virtual IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const;
// True if the expression has no side effects, false otherwise.
virtual bool IsPure() const;
@ -222,7 +223,7 @@ protected:
// Puts the expression in canonical form.
virtual void Canonicize();
void SetType(IntrusivePtr<BroType> t);
void SetType(IntrusivePtr<zeek::Type> t);
// Reports the given error and sets the expression's type to
// TYPE_ERROR.
@ -234,7 +235,7 @@ protected:
[[noreturn]] void RuntimeErrorWithCallStack(const std::string& msg) const;
BroExprTag tag;
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
bool paren;
};
@ -523,10 +524,10 @@ public:
const IntrusivePtr<Attributes>& attrs = nullptr);
IntrusivePtr<Val> Eval(Frame* f) const override;
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
IntrusivePtr<BroType> InitType() const override;
void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override;
IntrusivePtr<zeek::Type> InitType() const override;
bool IsRecordElement(TypeDecl* td) const override;
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
bool IsPure() const override;
protected:
@ -623,7 +624,7 @@ public:
~RecordConstructorExpr() override;
protected:
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override;
@ -633,7 +634,7 @@ class TableConstructorExpr final : public UnaryExpr {
public:
TableConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs,
IntrusivePtr<BroType> arg_type = nullptr);
IntrusivePtr<zeek::Type> arg_type = nullptr);
[[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); }
@ -644,7 +645,7 @@ public:
IntrusivePtr<Val> Eval(Frame* f) const override;
protected:
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
void ExprDescribe(ODesc* d) const override;
@ -655,7 +656,7 @@ class SetConstructorExpr final : public UnaryExpr {
public:
SetConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs,
IntrusivePtr<BroType> arg_type = nullptr);
IntrusivePtr<zeek::Type> arg_type = nullptr);
[[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); }
@ -666,7 +667,7 @@ public:
IntrusivePtr<Val> Eval(Frame* f) const override;
protected:
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
void ExprDescribe(ODesc* d) const override;
@ -676,12 +677,12 @@ protected:
class VectorConstructorExpr final : public UnaryExpr {
public:
explicit VectorConstructorExpr(IntrusivePtr<ListExpr> constructor_list,
IntrusivePtr<BroType> arg_type = nullptr);
IntrusivePtr<zeek::Type> arg_type = nullptr);
IntrusivePtr<Val> Eval(Frame* f) const override;
protected:
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
void ExprDescribe(ODesc* d) const override;
};
@ -692,7 +693,7 @@ public:
const char* FieldName() const { return field_name.c_str(); }
void EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const override;
void EvalIntoAggregate(const zeek::Type* t, Val* aggr, Frame* f) const override;
bool IsRecordElement(TypeDecl* td) const override;
protected:
@ -703,7 +704,7 @@ protected:
class ArithCoerceExpr final : public UnaryExpr {
public:
ArithCoerceExpr(IntrusivePtr<Expr> op, TypeTag t);
ArithCoerceExpr(IntrusivePtr<Expr> op, zeek::TypeTag t);
protected:
IntrusivePtr<Val> FoldSingleVal(Val* v, InternalTypeTag t) const;
@ -716,7 +717,7 @@ public:
~RecordCoerceExpr() override;
protected:
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Val> Fold(Val* v) const override;
// For each super-record slot, gives subrecord slot with which to
@ -867,15 +868,15 @@ public:
IntrusivePtr<Val> Eval(Frame* f) const override;
IntrusivePtr<BroType> InitType() const override;
IntrusivePtr<Val> InitVal(const BroType* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<zeek::Type> InitType() const override;
IntrusivePtr<Val> InitVal(const zeek::Type* t, IntrusivePtr<Val> aggr) const override;
IntrusivePtr<Expr> MakeLvalue() override;
void Assign(Frame* f, IntrusivePtr<Val> v) override;
TraversalCode Traverse(TraversalCallback* cb) const override;
protected:
IntrusivePtr<Val> AddSetInit(const BroType* t, IntrusivePtr<Val> aggr) const;
IntrusivePtr<Val> AddSetInit(const zeek::Type* t, IntrusivePtr<Val> aggr) const;
void ExprDescribe(ODesc* d) const override;
@ -890,7 +891,7 @@ public:
class CastExpr final : public UnaryExpr {
public:
CastExpr(IntrusivePtr<Expr> op, IntrusivePtr<BroType> t);
CastExpr(IntrusivePtr<Expr> op, IntrusivePtr<zeek::Type> t);
protected:
IntrusivePtr<Val> Eval(Frame* f) const override;
@ -899,14 +900,14 @@ protected:
class IsExpr final : public UnaryExpr {
public:
IsExpr(IntrusivePtr<Expr> op, IntrusivePtr<BroType> t);
IsExpr(IntrusivePtr<Expr> op, IntrusivePtr<zeek::Type> t);
protected:
IntrusivePtr<Val> Fold(Val* v) const override;
void ExprDescribe(ODesc* d) const override;
private:
IntrusivePtr<BroType> t;
IntrusivePtr<zeek::Type> t;
};
inline Val* Expr::ExprVal() const
@ -935,11 +936,11 @@ IntrusivePtr<Expr> get_assign_expr(IntrusivePtr<Expr> op1,
* Returns nullptr if the expression cannot match or a promoted
* expression.
*/
extern IntrusivePtr<Expr> check_and_promote_expr(Expr* e, BroType* t);
extern 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_args(ListExpr* args, RecordType* types);
extern bool check_and_promote_exprs_to_type(ListExpr* elements, BroType* type);
extern bool check_and_promote_exprs_to_type(ListExpr* elements, Type* type);
// Returns a ListExpr simplified down to a list a values, or nil
// if they couldn't all be reduced.
@ -953,3 +954,55 @@ extern bool expr_greater(const Expr* e1, const Expr* e2);
// True if the given Expr* has a vector type
inline bool is_vector(Expr* e) { return e->GetType()->Tag() == TYPE_VECTOR; }
inline bool is_vector(const IntrusivePtr<Expr>& e) { return is_vector(e.get()); }
}
using Expr [[deprecated("Remove in v4.1. Use zeek::detail::Expr instead.")]] = zeek::detail::Expr;
using NameExpr [[deprecated("Remove in v4.1. Use zeek::detail::NameExpr instead.")]] = zeek::detail::NameExpr;
using ConstExpr [[deprecated("Remove in v4.1. Use zeek::detail::ConstExpr instead.")]] = zeek::detail::ConstExpr;
using UnaryExpr [[deprecated("Remove in v4.1. Use zeek::detail::UnaryExpr instead.")]] = zeek::detail::UnaryExpr;
using BinaryExpr [[deprecated("Remove in v4.1. Use zeek::detail::BinaryExpr instead.")]] = zeek::detail::BinaryExpr;
using CloneExpr [[deprecated("Remove in v4.1. Use zeek::detail::CloneExpr instead.")]] = zeek::detail::CloneExpr;
using IncrExpr [[deprecated("Remove in v4.1. Use zeek::detail::IncrExpr instead.")]] = zeek::detail::IncrExpr;
using ComplementExpr [[deprecated("Remove in v4.1. Use zeek::detail::ComplementExpr instead.")]] = zeek::detail::ComplementExpr;
using NotExpr [[deprecated("Remove in v4.1. Use zeek::detail::NotExpr instead.")]] = zeek::detail::NotExpr;
using PosExpr [[deprecated("Remove in v4.1. Use zeek::detail::PosExpr instead.")]] = zeek::detail::PosExpr;
using NegExpr [[deprecated("Remove in v4.1. Use zeek::detail::NegExpr instead.")]] = zeek::detail::NegExpr;
using SizeExpr [[deprecated("Remove in v4.1. Use zeek::detail::SizeExpr instead.")]] = zeek::detail::SizeExpr;
using AddExpr [[deprecated("Remove in v4.1. Use zeek::detail::AddExpr instead.")]] = zeek::detail::AddExpr;
using AddToExpr [[deprecated("Remove in v4.1. Use zeek::detail::AddToExpr instead.")]] = zeek::detail::AddToExpr;
using RemoveFromExpr [[deprecated("Remove in v4.1. Use zeek::detail::RemoveFromExpr instead.")]] = zeek::detail::RemoveFromExpr;
using SubExpr [[deprecated("Remove in v4.1. Use zeek::detail::SubExpr instead.")]] = zeek::detail::SubExpr;
using TimesExpr [[deprecated("Remove in v4.1. Use zeek::detail::TimesExpr instead.")]] = zeek::detail::TimesExpr;
using DivideExpr [[deprecated("Remove in v4.1. Use zeek::detail::DivideExpr instead.")]] = zeek::detail::DivideExpr;
using ModExpr [[deprecated("Remove in v4.1. Use zeek::detail::ModExpr instead.")]] = zeek::detail::ModExpr;
using BoolExpr [[deprecated("Remove in v4.1. Use zeek::detail::BoolExpr instead.")]] = zeek::detail::BoolExpr;
using BitExpr [[deprecated("Remove in v4.1. Use zeek::detail::BitExpr instead.")]] = zeek::detail::BitExpr;
using EqExpr [[deprecated("Remove in v4.1. Use zeek::detail::EqExpr instead.")]] = zeek::detail::EqExpr;
using RelExpr [[deprecated("Remove in v4.1. Use zeek::detail::RelExpr instead.")]] = zeek::detail::RelExpr;
using CondExpr [[deprecated("Remove in v4.1. Use zeek::detail::CondExpr instead.")]] = zeek::detail::CondExpr;
using RefExpr [[deprecated("Remove in v4.1. Use zeek::detail::RefExpr instead.")]] = zeek::detail::RefExpr;
using AssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::AssignExpr instead.")]] = zeek::detail::AssignExpr;
using IndexSliceAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::IndexSliceAssignExpr instead.")]] = zeek::detail::IndexSliceAssignExpr;
using IndexExpr [[deprecated("Remove in v4.1. Use zeek::detail::IndexExpr instead.")]] = zeek::detail::IndexExpr;
using FieldExpr [[deprecated("Remove in v4.1. Use zeek::detail::FieldExpr instead.")]] = zeek::detail::FieldExpr;
using HasFieldExpr [[deprecated("Remove in v4.1. Use zeek::detail::HasFieldExpr instead.")]] = zeek::detail::HasFieldExpr;
using RecordConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordConstructorExpr instead.")]] = zeek::detail::RecordConstructorExpr;
using TableConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::TableConstructorExpr instead.")]] = zeek::detail::TableConstructorExpr;
using SetConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::SetConstructorExpr instead.")]] = zeek::detail::SetConstructorExpr;
using VectorConstructorExpr [[deprecated("Remove in v4.1. Use zeek::detail::VectorConstructorExpr instead.")]] = zeek::detail::VectorConstructorExpr;
using FieldAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::FieldAssignExpr instead.")]] = zeek::detail::FieldAssignExpr;
using ArithCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::ArithCoerceExpr instead.")]] = zeek::detail::ArithCoerceExpr;
using RecordCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordCoerceExpr instead.")]] = zeek::detail::RecordCoerceExpr;
using TableCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::TableCoerceExpr instead.")]] = zeek::detail::TableCoerceExpr;
using VectorCoerceExpr [[deprecated("Remove in v4.1. Use zeek::detail::VectorCoerceExpr instead.")]] = zeek::detail::VectorCoerceExpr;
using ScheduleTimer [[deprecated("Remove in v4.1. Use zeek::detail::ScheduleTimer instead.")]] = zeek::detail::ScheduleTimer;
using ScheduleExpr [[deprecated("Remove in v4.1. Use zeek::detail::ScheduleExpr instead.")]] = zeek::detail::ScheduleExpr;
using InExpr [[deprecated("Remove in v4.1. Use zeek::detail::InExpr instead.")]] = zeek::detail::InExpr;
using CallExpr [[deprecated("Remove in v4.1. Use zeek::detail::CallExpr instead.")]] = zeek::detail::CallExpr;
using LambdaExpr [[deprecated("Remove in v4.1. Use zeek::detail::LambdaExpr instead.")]] = zeek::detail::LambdaExpr;
using EventExpr [[deprecated("Remove in v4.1. Use zeek::detail::EventExpr instead.")]] = zeek::detail::EventExpr;
using ListExpr [[deprecated("Remove in v4.1. Use zeek::detail::ListExpr instead.")]] = zeek::detail::ListExpr;
using RecordAssignExpr [[deprecated("Remove in v4.1. Use zeek::detail::RecordAssignExpr instead.")]] = zeek::detail::RecordAssignExpr;
using CastExpr [[deprecated("Remove in v4.1. Use zeek::detail::CastExpr instead.")]] = zeek::detail::CastExpr;
using IsExpr [[deprecated("Remove in v4.1. Use zeek::detail::IsExpr instead.")]] = zeek::detail::IsExpr;

View file

@ -58,7 +58,7 @@ BroFile::BroFile(FILE* arg_f)
Init();
f = arg_f;
name = access = nullptr;
t = base_type(TYPE_STRING);
t = zeek::base_type(zeek::TYPE_STRING);
is_open = (f != nullptr);
}
@ -68,7 +68,7 @@ BroFile::BroFile(FILE* arg_f, const char* arg_name, const char* arg_access)
f = arg_f;
name = copy_string(arg_name);
access = copy_string(arg_access);
t = base_type(TYPE_STRING);
t = zeek::base_type(zeek::TYPE_STRING);
is_open = (f != nullptr);
}
@ -78,7 +78,7 @@ BroFile::BroFile(const char* arg_name, const char* arg_access)
f = nullptr;
name = copy_string(arg_name);
access = copy_string(arg_access);
t = base_type(TYPE_STRING);
t = zeek::base_type(zeek::TYPE_STRING);
if ( streq(name, "/dev/stdin") )
f = stdin;
@ -257,7 +257,7 @@ void BroFile::Describe(ODesc* d) const
d->Add("(no type)");
}
void BroFile::SetAttrs(Attributes* arg_attrs)
void BroFile::SetAttrs(zeek::detail::Attributes* arg_attrs)
{
if ( ! arg_attrs )
return;
@ -265,7 +265,7 @@ void BroFile::SetAttrs(Attributes* arg_attrs)
attrs = arg_attrs;
Ref(attrs);
if ( attrs->Find(ATTR_RAW_OUTPUT) )
if ( attrs->Find(zeek::detail::ATTR_RAW_OUTPUT) )
EnableRawOutput();
}
@ -278,7 +278,7 @@ RecordVal* BroFile::Rotate()
if ( f == stdin || f == stdout || f == stderr )
return nullptr;
static auto rotate_info = zeek::id::find_type<RecordType>("rotate_info");
static auto rotate_info = zeek::id::find_type<zeek::RecordType>("rotate_info");
RecordVal* info = new RecordVal(rotate_info);
FILE* newf = rotate_file(name, info);

View file

@ -2,23 +2,28 @@
#pragma once
#include "Obj.h"
#include "IntrusivePtr.h"
#include <list>
#include <string>
#include <utility>
#include <fcntl.h>
# ifdef NEED_KRB5_H
# include <krb5.h>
# endif // NEED_KRB5_H
#ifdef NEED_KRB5_H
#include <krb5.h>
#endif // NEED_KRB5_H
#include "Obj.h"
#include "IntrusivePtr.h"
#include "util.h"
class Attributes;
class BroType;
class RecordVal;
namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
ZEEK_FORWARD_DECLARE_NAMESPACED(PrintStmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
class BroFile final : public BroObj {
public:
explicit BroFile(FILE* arg_f);
@ -38,9 +43,9 @@ public:
void SetBuf(bool buffered); // false=line buffered, true=fully buffered
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* FType() const { return t.get(); }
zeek::Type* FType() const { return t.get(); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<zeek::Type>& GetType() const
{ return t; }
// Whether the file is open in a general sense; it might
@ -58,7 +63,7 @@ public:
RecordVal* Rotate();
// Set &raw_output attribute.
void SetAttrs(Attributes* attrs);
void SetAttrs(zeek::detail::Attributes* attrs);
// Returns the current size of the file, after fresh stat'ing.
double Size();
@ -77,7 +82,7 @@ public:
protected:
friend class PrintStmt;
friend class zeek::detail::PrintStmt;
BroFile() { Init(); }
void Init();
@ -101,10 +106,10 @@ protected:
void RaiseOpenEvent();
FILE* f;
IntrusivePtr<BroType> t;
IntrusivePtr<zeek::Type> t;
char* name;
char* access;
Attributes* attrs;
zeek::detail::Attributes* attrs;
double open_time;
bool is_open; // whether the file is open in a general sense
bool buffered;

View file

@ -6,7 +6,7 @@
#include <fcntl.h>
#include <errno.h>
using namespace bro;
using namespace zeek::detail;
Flare::Flare()
: pipe(FD_CLOEXEC, FD_CLOEXEC, O_NONBLOCK, O_NONBLOCK)

View file

@ -4,7 +4,7 @@
#include "Pipe.h"
namespace bro {
namespace zeek::detail {
class Flare {
public:
@ -21,8 +21,7 @@ public:
* @return a file descriptor that will become ready if the flare has been
* Fire()'d and not yet Extinguished()'d.
*/
int FD() const
{ return pipe.ReadFD(); }
int FD() const { return pipe.ReadFD(); }
/**
* Put the object in the "ready" state.
@ -44,4 +43,4 @@ private:
Pipe pipe;
};
} // namespace bro
} // namespace zeek::detail

View file

@ -77,7 +77,7 @@ void Frame::SetElementWeak(int n, Val* v)
frame[n] = {{AdoptRef{}, v}, true};
}
void Frame::SetElement(const ID* id, IntrusivePtr<Val> v)
void Frame::SetElement(const zeek::detail::ID* id, IntrusivePtr<Val> v)
{
if ( closure )
{
@ -106,7 +106,7 @@ void Frame::SetElement(const ID* id, IntrusivePtr<Val> v)
SetElement(id->Offset(), std::move(v));
}
const IntrusivePtr<Val>& Frame::GetElementByID(const ID* id) const
const IntrusivePtr<Val>& Frame::GetElementByID(const zeek::detail::ID* id) const
{
if ( closure )
{
@ -175,7 +175,7 @@ Frame* Frame::Clone() const
static bool val_is_func(const IntrusivePtr<Val>& v, BroFunc* func)
{
if ( v->GetType()->Tag() != TYPE_FUNC )
if ( v->GetType()->Tag() != zeek::TYPE_FUNC )
return false;
return v->AsFunc() == func;
@ -333,7 +333,7 @@ broker::expected<broker::data> Frame::Serialize(const Frame* target, const id_li
const auto& val = target->frame[location].val;
TypeTag tag = val->GetType()->Tag();
zeek::TypeTag tag = val->GetType()->Tag();
auto expected = bro_broker::val_to_data(val.get());
if ( ! expected )
@ -460,7 +460,7 @@ std::pair<bool, IntrusivePtr<Frame>> Frame::Unserialize(const broker::vector& da
return std::make_pair(false, nullptr);
broker::integer g = *has_type;
BroType t( static_cast<TypeTag>(g) );
zeek::Type t( static_cast<zeek::TypeTag>(g) );
auto val = bro_broker::data_to_val(std::move(val_tuple[0]), &t);
if ( ! val )
@ -478,7 +478,7 @@ void Frame::AddKnownOffsets(const id_list& ids)
offset_map = std::make_unique<OffsetMap>();
std::transform(ids.begin(), ids.end(), std::inserter(*offset_map, offset_map->end()),
[] (const ID* id) -> std::pair<std::string, int>
[] (const zeek::detail::ID* id) -> std::pair<std::string, int>
{
return std::make_pair(std::string(id->Name()), id->Offset());
});
@ -505,7 +505,7 @@ void Frame::CaptureClosure(Frame* c, id_list arg_outer_ids)
// if (c) closure = c->SelectiveClone(outer_ids);
}
void Frame::SetTrigger(IntrusivePtr<trigger::Trigger> arg_trigger)
void Frame::SetTrigger(IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger)
{
trigger = std::move(arg_trigger);
}
@ -523,10 +523,10 @@ void Frame::ClearElement(int n)
frame[n] = {nullptr, false};
}
bool Frame::IsOuterID(const ID* in) const
bool Frame::IsOuterID(const zeek::detail::ID* in) const
{
return std::any_of(outer_ids.begin(), outer_ids.end(),
[&in](ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; });
[&in](zeek::detail::ID* id)-> bool { return strcmp(id->Name(), in->Name()) == 0; });
}
broker::expected<broker::data> Frame::SerializeIDList(const id_list& in)
@ -588,7 +588,7 @@ Frame::UnserializeIDList(const broker::vector& data)
return std::make_pair(false, std::move(rval));
}
ID* id = new ID(has_name->c_str(), SCOPE_FUNCTION, false);
auto* id = new zeek::detail::ID(has_name->c_str(), zeek::detail::SCOPE_FUNCTION, false);
id->SetOffset(*has_offset);
rval.push_back(id);
std::advance(where, 1);

View file

@ -16,10 +16,11 @@
#include <broker/data.hh>
#include <broker/expected.hh>
namespace trigger { class Trigger; }
class CallExpr;
class BroFunc;
ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Trigger, zeek::detail::trigger);
class Frame : public BroObj {
public:
/**
@ -65,8 +66,8 @@ public:
* @param id the ID to associate
* @param v the value to associate it with
*/
void SetElement(const ID* id, IntrusivePtr<Val> v);
void SetElement(const IntrusivePtr<ID>& id, IntrusivePtr<Val> v)
void SetElement(const zeek::detail::ID* id, IntrusivePtr<Val> v);
void SetElement(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<Val> v)
{ SetElement(id.get(), std::move(v)); }
/**
@ -76,11 +77,11 @@ public:
* @param id the id who's value to retreive
* @return the value associated with *id*
*/
const IntrusivePtr<Val>& GetElementByID(const IntrusivePtr<ID>& id) const
const IntrusivePtr<Val>& GetElementByID(const IntrusivePtr<zeek::detail::ID>& id) const
{ return GetElementByID(id.get()); }
[[deprecated("Remove in v4.1. Use GetElementByID().")]]
Val* GetElement(const ID* id) const
Val* GetElement(const zeek::detail::ID* id) const
{ return GetElementByID(id).get(); }
/**
@ -118,12 +119,12 @@ public:
*
* @param stmt the statement to set it to.
*/
void SetNextStmt(Stmt* stmt) { next_stmt = stmt; }
void SetNextStmt(zeek::detail::Stmt* stmt) { next_stmt = stmt; }
/**
* @return the next statement to be executed in the context of the frame.
*/
Stmt* GetNextStmt() const { return next_stmt; }
zeek::detail::Stmt* GetNextStmt() const { return next_stmt; }
/** Used to implement "next" command in debugger. */
void BreakBeforeNextStmt(bool should_break)
@ -215,13 +216,13 @@ public:
// If the frame is run in the context of a trigger condition evaluation,
// the trigger needs to be registered.
void SetTrigger(IntrusivePtr<trigger::Trigger> arg_trigger);
void SetTrigger(IntrusivePtr<zeek::detail::trigger::Trigger> arg_trigger);
void ClearTrigger();
trigger::Trigger* GetTrigger() const { return trigger.get(); }
zeek::detail::trigger::Trigger* GetTrigger() const { return trigger.get(); }
void SetCall(const CallExpr* arg_call) { call = arg_call; }
void SetCall(const zeek::detail::CallExpr* arg_call) { call = arg_call; }
void ClearCall() { call = nullptr; }
const CallExpr* GetCall() const { return call; }
const zeek::detail::CallExpr* GetCall() const { return call; }
void SetDelayed() { delayed = true; }
bool HasDelayed() const { return delayed; }
@ -246,7 +247,7 @@ private:
bool weak_ref;
};
const IntrusivePtr<Val>& GetElementByID(const ID* id) const;
const IntrusivePtr<Val>& GetElementByID(const zeek::detail::ID* id) const;
/**
* Sets the element at index *n* of the underlying array to *v*, but does
@ -272,7 +273,7 @@ private:
void ClearElement(int n);
/** Have we captured this id? */
bool IsOuterID(const ID* in) const;
bool IsOuterID(const zeek::detail::ID* in) const;
/** Serializes an offset_map */
static broker::expected<broker::data>
@ -319,10 +320,10 @@ private:
const zeek::Args* func_args;
/** The next statement to be evaluted in the context of this frame. */
Stmt* next_stmt;
zeek::detail::Stmt* next_stmt;
IntrusivePtr<trigger::Trigger> trigger;
const CallExpr* call;
IntrusivePtr<zeek::detail::trigger::Trigger> trigger;
const zeek::detail::CallExpr* call;
std::unique_ptr<std::vector<BroFunc*>> functions_with_closure_frame_reference;
};

View file

@ -121,8 +121,8 @@ Func::Func(Kind arg_kind) : kind(arg_kind)
Func::~Func() = default;
void Func::AddBody(IntrusivePtr<Stmt> /* new_body */,
const std::vector<IntrusivePtr<ID>>& /* new_inits */,
void Func::AddBody(IntrusivePtr<zeek::detail::Stmt> /* new_body */,
const std::vector<IntrusivePtr<zeek::detail::ID>>& /* new_inits */,
size_t /* new_frame_size */, int /* priority */)
{
Internal("Func::AddBody called");
@ -216,7 +216,7 @@ void Func::CopyStateInto(Func* other) const
}
void Func::CheckPluginResult(bool handled, const IntrusivePtr<Val>& hook_result,
function_flavor flavor) const
zeek::FunctionFlavor flavor) const
{
// Helper function factoring out this code from BroFunc:Call() for
// better readability.
@ -232,32 +232,32 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr<Val>& hook_result,
}
switch ( flavor ) {
case FUNC_FLAVOR_EVENT:
case zeek::FUNC_FLAVOR_EVENT:
if ( hook_result )
reporter->InternalError("plugin returned non-void result for event %s",
this->Name());
break;
case FUNC_FLAVOR_HOOK:
if ( hook_result->GetType()->Tag() != TYPE_BOOL )
case zeek::FUNC_FLAVOR_HOOK:
if ( hook_result->GetType()->Tag() != zeek::TYPE_BOOL )
reporter->InternalError("plugin returned non-bool for hook %s",
this->Name());
break;
case FUNC_FLAVOR_FUNCTION:
case zeek::FUNC_FLAVOR_FUNCTION:
{
const auto& yt = GetType()->Yield();
if ( (! yt) || yt->Tag() == TYPE_VOID )
if ( (! yt) || yt->Tag() == zeek::TYPE_VOID )
{
if ( hook_result )
reporter->InternalError("plugin returned non-void result for void method %s",
this->Name());
}
else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && yt->Tag() != TYPE_ANY )
else if ( hook_result && hook_result->GetType()->Tag() != yt->Tag() && yt->Tag() != zeek::TYPE_ANY )
{
reporter->InternalError("plugin returned wrong type (got %d, expecting %d) for %s",
hook_result->GetType()->Tag(), yt->Tag(), this->Name());
@ -268,13 +268,13 @@ void Func::CheckPluginResult(bool handled, const IntrusivePtr<Val>& hook_result,
}
}
BroFunc::BroFunc(const IntrusivePtr<ID>& arg_id, IntrusivePtr<Stmt> arg_body,
const std::vector<IntrusivePtr<ID>>& aggr_inits,
BroFunc::BroFunc(const IntrusivePtr<zeek::detail::ID>& arg_id, IntrusivePtr<zeek::detail::Stmt> arg_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& aggr_inits,
size_t arg_frame_size, int priority)
: Func(BRO_FUNC)
{
name = arg_id->Name();
type = arg_id->GetType<FuncType>();
type = arg_id->GetType<zeek::FuncType>();
frame_size = arg_frame_size;
if ( arg_body )
@ -326,8 +326,8 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
if ( bodies.empty() )
{
// Can only happen for events and hooks.
assert(Flavor() == FUNC_FLAVOR_EVENT || Flavor() == FUNC_FLAVOR_HOOK);
return Flavor() == FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr;
assert(Flavor() == zeek::FUNC_FLAVOR_EVENT || Flavor() == zeek::FUNC_FLAVOR_HOOK);
return Flavor() == zeek::FUNC_FLAVOR_HOOK ? val_mgr->True() : nullptr;
}
auto f = make_intrusive<Frame>(frame_size, this, args);
@ -343,7 +343,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
}
g_frame_stack.push_back(f.get()); // used for backtracing
const CallExpr* call_expr = parent ? parent->GetCall() : nullptr;
const zeek::detail::CallExpr* call_expr = parent ? parent->GetCall() : nullptr;
call_stack.emplace_back(CallInfo{call_expr, this, *args});
if ( g_trace_state.DoTrace() )
@ -384,7 +384,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
catch ( InterpreterException& e )
{
// Already reported, but now determine whether to unwind further.
if ( Flavor() == FUNC_FLAVOR_FUNCTION )
if ( Flavor() == zeek::FUNC_FLAVOR_FUNCTION )
{
g_frame_stack.pop_back();
call_stack.pop_back();
@ -404,7 +404,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
break;
}
if ( Flavor() == FUNC_FLAVOR_HOOK )
if ( Flavor() == zeek::FUNC_FLAVOR_HOOK )
{
// Ignore any return values of hook bodies, final return value
// depends on whether a body returns as a result of break statement.
@ -421,7 +421,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
call_stack.pop_back();
if ( Flavor() == FUNC_FLAVOR_HOOK )
if ( Flavor() == zeek::FUNC_FLAVOR_HOOK )
{
if ( ! result )
result = val_mgr->True();
@ -429,7 +429,7 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
// Warn if the function returns something, but we returned from
// the function without an explicit return, or without a value.
else if ( GetType()->Yield() && GetType()->Yield()->Tag() != TYPE_VOID &&
else if ( GetType()->Yield() && GetType()->Yield()->Tag() != zeek::TYPE_VOID &&
(flow != FLOW_RETURN /* we fell off the end */ ||
! result /* explicit return with no result */) &&
! f->HasDelayed() )
@ -449,8 +449,8 @@ IntrusivePtr<Val> BroFunc::Invoke(zeek::Args* args, Frame* parent) const
return result;
}
void BroFunc::AddBody(IntrusivePtr<Stmt> new_body,
const std::vector<IntrusivePtr<ID>>& new_inits,
void BroFunc::AddBody(IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits,
size_t new_frame_size, int priority)
{
if ( new_frame_size > frame_size )
@ -463,7 +463,7 @@ void BroFunc::AddBody(IntrusivePtr<Stmt> new_body,
new_body = AddInits(std::move(new_body), new_inits);
if ( Flavor() == FUNC_FLAVOR_FUNCTION )
if ( Flavor() == zeek::FUNC_FLAVOR_FUNCTION )
{
// For functions, we replace the old body with the new one.
assert(bodies.size() <= 1);
@ -574,14 +574,14 @@ void BroFunc::Describe(ODesc* d) const
}
}
IntrusivePtr<Stmt> BroFunc::AddInits(IntrusivePtr<Stmt> body,
const std::vector<IntrusivePtr<ID>>& inits)
IntrusivePtr<zeek::detail::Stmt> BroFunc::AddInits(IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits)
{
if ( inits.empty() )
return body;
auto stmt_series = make_intrusive<StmtList>();
stmt_series->Stmts().push_back(new InitStmt(inits));
auto stmt_series = make_intrusive<zeek::detail::StmtList>();
stmt_series->Stmts().push_back(new zeek::detail::InitStmt(inits));
stmt_series->Stmts().push_back(body.release());
return stmt_series;
@ -601,7 +601,7 @@ BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name,
if ( id->HasVal() )
reporter->InternalError("built-in function %s multiply defined", Name());
type = id->GetType<FuncType>();
type = id->GetType<zeek::FuncType>();
id->SetVal(make_intrusive<Val>(IntrusivePtr{NewRef{}, this}));
}
@ -628,7 +628,7 @@ IntrusivePtr<Val> BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const
HookCallFunction(this, parent, args),
empty_hook_result);
CheckPluginResult(handled, hook_result, FUNC_FLAVOR_FUNCTION);
CheckPluginResult(handled, hook_result, zeek::FUNC_FLAVOR_FUNCTION);
if ( handled )
return hook_result;
@ -641,7 +641,7 @@ IntrusivePtr<Val> BuiltinFunc::Invoke(zeek::Args* args, Frame* parent) const
g_trace_state.LogTrace("\tBuiltin Function called: %s\n", d.Description());
}
const CallExpr* call_expr = parent ? parent->GetCall() : nullptr;
const zeek::detail::CallExpr* call_expr = parent ? parent->GetCall() : nullptr;
call_stack.emplace_back(CallInfo{call_expr, this, *args});
auto result = std::move(func(parent, args).rval);
call_stack.pop_back();
@ -675,7 +675,7 @@ void builtin_error(const char* msg, IntrusivePtr<Val> arg)
void builtin_error(const char* msg, BroObj* arg)
{
auto emit = [=](const CallExpr* ce)
auto emit = [=](const zeek::detail::CallExpr* ce)
{
if ( ce )
ce->Error(msg, arg);
@ -758,19 +758,19 @@ void builtin_error(const char* msg, BroObj* arg)
void init_builtin_funcs()
{
ProcStats = zeek::id::find_type<RecordType>("ProcStats");
NetStats = zeek::id::find_type<RecordType>("NetStats");
MatcherStats = zeek::id::find_type<RecordType>("MatcherStats");
ConnStats = zeek::id::find_type<RecordType>("ConnStats");
ReassemblerStats = zeek::id::find_type<RecordType>("ReassemblerStats");
DNSStats = zeek::id::find_type<RecordType>("DNSStats");
GapStats = zeek::id::find_type<RecordType>("GapStats");
EventStats = zeek::id::find_type<RecordType>("EventStats");
TimerStats = zeek::id::find_type<RecordType>("TimerStats");
FileAnalysisStats = zeek::id::find_type<RecordType>("FileAnalysisStats");
ThreadStats = zeek::id::find_type<RecordType>("ThreadStats");
BrokerStats = zeek::id::find_type<RecordType>("BrokerStats");
ReporterStats = zeek::id::find_type<RecordType>("ReporterStats");
ProcStats = zeek::id::find_type<zeek::RecordType>("ProcStats");
NetStats = zeek::id::find_type<zeek::RecordType>("NetStats");
MatcherStats = zeek::id::find_type<zeek::RecordType>("MatcherStats");
ConnStats = zeek::id::find_type<zeek::RecordType>("ConnStats");
ReassemblerStats = zeek::id::find_type<zeek::RecordType>("ReassemblerStats");
DNSStats = zeek::id::find_type<zeek::RecordType>("DNSStats");
GapStats = zeek::id::find_type<zeek::RecordType>("GapStats");
EventStats = zeek::id::find_type<zeek::RecordType>("EventStats");
TimerStats = zeek::id::find_type<zeek::RecordType>("TimerStats");
FileAnalysisStats = zeek::id::find_type<zeek::RecordType>("FileAnalysisStats");
ThreadStats = zeek::id::find_type<zeek::RecordType>("ThreadStats");
BrokerStats = zeek::id::find_type<zeek::RecordType>("BrokerStats");
ReporterStats = zeek::id::find_type<zeek::RecordType>("ReporterStats");
var_sizes = zeek::id::find_type("var_sizes")->AsTableType();
@ -789,7 +789,7 @@ void init_builtin_funcs_subdirs()
#include "__all__.bif.init.cc" // Autogenerated for compiling in the bif_target() code.
}
bool check_built_in_call(BuiltinFunc* f, CallExpr* call)
bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call)
{
if ( f->TheFunc() != zeek::BifFunc::fmt_bif)
return true;
@ -802,8 +802,8 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call)
return true;
}
const Expr* fmt_str_arg = args[0];
if ( fmt_str_arg->GetType()->Tag() != TYPE_STRING )
const zeek::detail::Expr* fmt_str_arg = args[0];
if ( fmt_str_arg->GetType()->Tag() != zeek::TYPE_STRING )
{
call->Error("first argument to fmt() needs to be a format string");
return false;
@ -844,16 +844,16 @@ bool check_built_in_call(BuiltinFunc* f, CallExpr* call)
// Gets a function's priority from its Scope's attributes. Errors if it sees any
// problems.
static int get_func_priority(const std::vector<IntrusivePtr<Attr>>& attrs)
static int get_func_priority(const std::vector<IntrusivePtr<zeek::detail::Attr>>& attrs)
{
int priority = 0;
for ( const auto& a : attrs )
{
if ( a->Tag() == ATTR_DEPRECATED )
if ( a->Tag() == zeek::detail::ATTR_DEPRECATED )
continue;
if ( a->Tag() != ATTR_PRIORITY )
if ( a->Tag() != zeek::detail::ATTR_PRIORITY )
{
a->Error("illegal attribute for function body");
continue;
@ -867,7 +867,7 @@ static int get_func_priority(const std::vector<IntrusivePtr<Attr>>& attrs)
continue;
}
if ( ! IsIntegral(v->GetType()->Tag()) )
if ( ! zeek::IsIntegral(v->GetType()->Tag()) )
{
a->Error("expression is not of integral type");
continue;
@ -879,7 +879,7 @@ static int get_func_priority(const std::vector<IntrusivePtr<Attr>>& attrs)
return priority;
}
function_ingredients::function_ingredients(IntrusivePtr<Scope> scope, IntrusivePtr<Stmt> body)
function_ingredients::function_ingredients(IntrusivePtr<Scope> scope, IntrusivePtr<zeek::detail::Stmt> body)
{
frame_size = scope->Length();
inits = scope->GetInits();

View file

@ -18,14 +18,14 @@
#include "BifReturnVal.h"
class Val;
class ListExpr;
class FuncType;
class Stmt;
class Frame;
class ID;
class CallExpr;
class Scope;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek);
namespace caf {
template <class> class expected;
}
@ -47,10 +47,10 @@ public:
~Func() override;
virtual bool IsPure() const = 0;
function_flavor Flavor() const { return GetType()->Flavor(); }
zeek::FunctionFlavor Flavor() const { return GetType()->Flavor(); }
struct Body {
IntrusivePtr<Stmt> stmts;
IntrusivePtr<zeek::detail::Stmt> stmts;
int priority;
bool operator<(const Body& other) const
{ return priority > other.priority; } // reverse sort
@ -86,17 +86,17 @@ public:
}
// Add a new event handler to an existing function (event).
virtual void AddBody(IntrusivePtr<Stmt> new_body,
const std::vector<IntrusivePtr<ID>>& new_inits,
virtual void AddBody(IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits,
size_t new_frame_size, int priority = 0);
virtual void SetScope(IntrusivePtr<Scope> newscope);
virtual Scope* GetScope() const { return scope.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
virtual FuncType* FType() const { return type.get(); }
virtual zeek::FuncType* FType() const { return type.get(); }
const IntrusivePtr<FuncType>& GetType() const
const IntrusivePtr<zeek::FuncType>& GetType() const
{ return type; }
Kind GetKind() const { return kind; }
@ -123,13 +123,13 @@ protected:
// Helper function for checking result of plugin hook.
void CheckPluginResult(bool handled, const IntrusivePtr<Val>& hook_result,
function_flavor flavor) const;
zeek::FunctionFlavor flavor) const;
std::vector<Body> bodies;
IntrusivePtr<Scope> scope;
Kind kind;
uint32_t unique_id;
IntrusivePtr<FuncType> type;
IntrusivePtr<zeek::FuncType> type;
std::string name;
static inline std::vector<IntrusivePtr<Func>> unique_ids;
};
@ -137,8 +137,8 @@ protected:
class BroFunc final : public Func {
public:
BroFunc(const IntrusivePtr<ID>& id, IntrusivePtr<Stmt> body,
const std::vector<IntrusivePtr<ID>>& inits,
BroFunc(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits,
size_t frame_size, int priority);
~BroFunc() override;
@ -175,8 +175,8 @@ public:
*/
broker::expected<broker::data> SerializeClosure() const;
void AddBody(IntrusivePtr<Stmt> new_body,
const std::vector<IntrusivePtr<ID>>& new_inits,
void AddBody(IntrusivePtr<zeek::detail::Stmt> new_body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& new_inits,
size_t new_frame_size, int priority) override;
/** Sets this function's outer_id list. */
@ -187,8 +187,9 @@ public:
protected:
BroFunc() : Func(BRO_FUNC) {}
IntrusivePtr<Stmt> AddInits(IntrusivePtr<Stmt> body,
const std::vector<IntrusivePtr<ID>>& inits);
IntrusivePtr<zeek::detail::Stmt> AddInits(
IntrusivePtr<zeek::detail::Stmt> body,
const std::vector<IntrusivePtr<zeek::detail::ID>>& inits);
/**
* Clones this function along with its closures.
@ -240,10 +241,10 @@ extern void builtin_error(const char* msg, BroObj* arg);
extern void init_builtin_funcs();
extern void init_builtin_funcs_subdirs();
extern bool check_built_in_call(BuiltinFunc* f, CallExpr* call);
extern bool check_built_in_call(BuiltinFunc* f, zeek::detail::CallExpr* call);
struct CallInfo {
const CallExpr* call;
const zeek::detail::CallExpr* call;
const Func* func;
const zeek::Args& args;
};
@ -254,11 +255,11 @@ struct function_ingredients {
// Gathers all of the information from a scope and a function body needed
// to build a function.
function_ingredients(IntrusivePtr<Scope> scope, IntrusivePtr<Stmt> body);
function_ingredients(IntrusivePtr<Scope> scope, IntrusivePtr<zeek::detail::Stmt> body);
IntrusivePtr<ID> id;
IntrusivePtr<Stmt> body;
std::vector<IntrusivePtr<ID>> inits;
IntrusivePtr<zeek::detail::ID> id;
IntrusivePtr<zeek::detail::Stmt> body;
std::vector<IntrusivePtr<zeek::detail::ID>> inits;
int frame_size;
int priority;
IntrusivePtr<Scope> scope;

View file

@ -19,24 +19,24 @@
#include "zeekygen/ScriptInfo.h"
#include "module_util.h"
IntrusivePtr<RecordType> zeek::id::conn_id;
IntrusivePtr<RecordType> zeek::id::endpoint;
IntrusivePtr<RecordType> zeek::id::connection;
IntrusivePtr<RecordType> zeek::id::fa_file;
IntrusivePtr<RecordType> zeek::id::fa_metadata;
IntrusivePtr<EnumType> zeek::id::transport_proto;
IntrusivePtr<TableType> zeek::id::string_set;
IntrusivePtr<TableType> zeek::id::string_array;
IntrusivePtr<TableType> zeek::id::count_set;
IntrusivePtr<VectorType> zeek::id::string_vec;
IntrusivePtr<VectorType> zeek::id::index_vec;
IntrusivePtr<zeek::RecordType> zeek::id::conn_id;
IntrusivePtr<zeek::RecordType> zeek::id::endpoint;
IntrusivePtr<zeek::RecordType> zeek::id::connection;
IntrusivePtr<zeek::RecordType> zeek::id::fa_file;
IntrusivePtr<zeek::RecordType> zeek::id::fa_metadata;
IntrusivePtr<zeek::EnumType> zeek::id::transport_proto;
IntrusivePtr<zeek::TableType> zeek::id::string_set;
IntrusivePtr<zeek::TableType> zeek::id::string_array;
IntrusivePtr<zeek::TableType> zeek::id::count_set;
IntrusivePtr<zeek::VectorType> zeek::id::string_vec;
IntrusivePtr<zeek::VectorType> zeek::id::index_vec;
const IntrusivePtr<ID>& zeek::id::find(std::string_view name)
const IntrusivePtr<zeek::detail::ID>& zeek::id::find(std::string_view name)
{
return global_scope()->Find(name);
}
const IntrusivePtr<BroType>& zeek::id::find_type(std::string_view name)
const IntrusivePtr<zeek::Type>& zeek::id::find_type(std::string_view name)
{
auto id = global_scope()->Find(name);
@ -89,19 +89,21 @@ IntrusivePtr<Func> zeek::id::find_func(std::string_view name)
void zeek::id::detail::init()
{
conn_id = zeek::id::find_type<RecordType>("conn_id");
endpoint = zeek::id::find_type<RecordType>("endpoint");
connection = zeek::id::find_type<RecordType>("connection");
fa_file = zeek::id::find_type<RecordType>("fa_file");
fa_metadata = zeek::id::find_type<RecordType>("fa_metadata");
transport_proto = zeek::id::find_type<EnumType>("transport_proto");
string_set = zeek::id::find_type<TableType>("string_set");
string_array = zeek::id::find_type<TableType>("string_array");
count_set = zeek::id::find_type<TableType>("count_set");
string_vec = zeek::id::find_type<VectorType>("string_vec");
index_vec = zeek::id::find_type<VectorType>("index_vec");
conn_id = zeek::id::find_type<zeek::RecordType>("conn_id");
endpoint = zeek::id::find_type<zeek::RecordType>("endpoint");
connection = zeek::id::find_type<zeek::RecordType>("connection");
fa_file = zeek::id::find_type<zeek::RecordType>("fa_file");
fa_metadata = zeek::id::find_type<zeek::RecordType>("fa_metadata");
transport_proto = zeek::id::find_type<zeek::EnumType>("transport_proto");
string_set = zeek::id::find_type<zeek::TableType>("string_set");
string_array = zeek::id::find_type<zeek::TableType>("string_array");
count_set = zeek::id::find_type<zeek::TableType>("count_set");
string_vec = zeek::id::find_type<zeek::VectorType>("string_vec");
index_vec = zeek::id::find_type<zeek::VectorType>("index_vec");
}
namespace zeek::detail {
ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export)
{
name = copy_string(arg_name);
@ -118,6 +120,12 @@ ID::ID(const char* arg_name, IDScope arg_scope, bool arg_is_export)
SetLocationInfo(&start_location, &end_location);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
ID::ID(const char* arg_name, ::IDScope arg_scope, bool arg_is_export) :
ID(arg_name, static_cast<IDScope>(arg_scope), arg_is_export) {}
#pragma GCC diagnostic pop
ID::~ID()
{
delete [] name;
@ -128,7 +136,7 @@ std::string ID::ModuleName() const
return extract_module_name(name);
}
void ID::SetType(IntrusivePtr<BroType> t)
void ID::SetType(IntrusivePtr<zeek::Type> t)
{
type = std::move(t);
}
@ -215,6 +223,19 @@ void ID::SetVal(IntrusivePtr<Expr> ev, init_class c)
EvalFunc(a->GetExpr(), std::move(ev));
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
void ID::SetVal(IntrusivePtr<Val> v, ::init_class c)
{
SetVal(v, static_cast<init_class>(c));
}
void ID::SetVal(IntrusivePtr<Expr> ev, ::init_class c)
{
SetVal(ev, static_cast<init_class>(c));
}
#pragma GCC diagnostic pop
bool ID::IsRedefinable() const
{
return GetAttr(ATTR_REDEF) != nullptr;
@ -252,7 +273,7 @@ void ID::UpdateValAttrs()
if ( attr )
{
// Apply &log to all record fields.
RecordType* rt = GetType()->AsRecordType();
zeek::RecordType* rt = GetType()->AsRecordType();
for ( int i = 0; i < rt->NumFields(); ++i )
{
TypeDecl* fd = rt->FieldDecl(i);
@ -292,7 +313,7 @@ std::string ID::GetDeprecationWarning() const
if ( depr_attr )
{
auto expr = static_cast<ConstExpr*>(depr_attr->GetExpr().get());
auto expr = static_cast<zeek::detail::ConstExpr*>(depr_attr->GetExpr().get());
if ( expr )
{
StringVal* text = expr->Value()->AsStringVal();
@ -322,6 +343,14 @@ void ID::RemoveAttr(attr_tag a)
attrs->RemoveAttr(a);
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
void ID::RemoveAttr(::attr_tag a)
{
RemoveAttr(static_cast<attr_tag>(a));
}
#pragma GCC diagnostic pop
void ID::SetOption()
{
if ( is_option )
@ -339,8 +368,8 @@ void ID::SetOption()
void ID::EvalFunc(IntrusivePtr<Expr> ef, IntrusivePtr<Expr> ev)
{
auto arg1 = make_intrusive<ConstExpr>(val);
auto args = make_intrusive<ListExpr>();
auto arg1 = make_intrusive<zeek::detail::ConstExpr>(val);
auto args = make_intrusive<zeek::detail::ListExpr>();
args->Append(std::move(arg1));
args->Append(std::move(ev));
auto ce = make_intrusive<CallExpr>(std::move(ef), std::move(args));
@ -655,3 +684,5 @@ std::vector<Func*> ID::GetOptionHandlers() const
v.push_back(element.second.get());
return v;
}
}

100
src/ID.h
View file

@ -14,23 +14,39 @@
#include <vector>
class Val;
class Expr;
class Func;
class BroType;
class RecordType;
class TableType;
class VectorType;
class EnumType;
class Attributes;
typedef enum { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, } init_class;
typedef enum { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL } IDScope;
namespace zeek { class Type; }
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
ZEEK_FORWARD_DECLARE_NAMESPACED(RecordType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(TableType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(VectorType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek);
enum [[deprecated("Remove in v4.1. Use zeek::detail::init_class instead.")]] init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, };
enum [[deprecated("Remove in v4.1. Use zeek::detail::IDScope instead.")]] IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
namespace zeek::detail {
class Attributes;
class Expr;
enum init_class { INIT_NONE, INIT_FULL, INIT_EXTRA, INIT_REMOVE, };
enum IDScope { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
class ID final : public BroObj, public notifier::Modifiable {
public:
static inline const IntrusivePtr<ID> nil;
ID(const char* name, IDScope arg_scope, bool arg_is_export);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::IDScope")]]
ID(const char* name, ::IDScope arg_scope, bool arg_is_export);
#pragma GCC diagnostic pop
~ID() override;
const char* Name() const { return name; }
@ -43,14 +59,14 @@ public:
std::string ModuleName() const;
void SetType(IntrusivePtr<BroType> t);
void SetType(IntrusivePtr<Type> t);
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() { return type.get(); }
zeek::Type* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
const BroType* Type() const { return type.get(); }
const zeek::Type* Type() const { return type.get(); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<zeek::Type>& GetType() const
{ return type; }
template <class T>
@ -58,9 +74,9 @@ public:
{ return cast_intrusive<T>(type); }
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
BroType* AsType() { return is_type ? GetType().get() : nullptr; }
zeek::Type* AsType() { return is_type ? GetType().get() : nullptr; }
[[deprecated("Remove in v4.1. Use IsType() and GetType().")]]
const BroType* AsType() const { return is_type ? GetType().get() : nullptr; }
const zeek::Type* AsType() const { return is_type ? GetType().get() : nullptr; }
bool IsType() const
{ return is_type; }
@ -72,6 +88,14 @@ public:
void SetVal(IntrusivePtr<Val> v, init_class c);
void SetVal(IntrusivePtr<Expr> ev, init_class c);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]]
void SetVal(IntrusivePtr<Val> v, ::init_class c);
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::init_class")]]
void SetVal(IntrusivePtr<Expr> ev, ::init_class c);
#pragma GCC diagnostic pop
bool HasVal() const { return val != nullptr; }
[[deprecated("Remove in v4.1. Use GetVal().")]]
@ -101,6 +125,11 @@ public:
void SetAttrs(IntrusivePtr<Attributes> attr);
void AddAttrs(IntrusivePtr<Attributes> attr);
void RemoveAttr(attr_tag a);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag")]]
void RemoveAttr(::attr_tag a);
#pragma GCC diagnostic pop
void UpdateValAttrs();
const IntrusivePtr<Attributes>& GetAttrs() const
@ -109,11 +138,14 @@ public:
[[deprecated("Remove in 4.1. Use GetAttrs().")]]
Attributes* Attrs() const { return attrs.get(); }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in 4.1. Use GetAttr().")]]
Attr* FindAttr(attr_tag t) const
{ return GetAttr(t).get(); }
Attr* FindAttr(::attr_tag t) const
{ return GetAttr(static_cast<zeek::detail::attr_tag>(t)).get(); }
#pragma GCC diagnostic pop
const IntrusivePtr<Attr>& GetAttr(attr_tag t) const;
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::attr_tag t) const;
bool IsDeprecated() const;
@ -154,7 +186,7 @@ protected:
IDScope scope;
bool is_export;
bool infer_return_type;
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
bool is_const, is_enum_const, is_type, is_option;
int offset;
IntrusivePtr<Val> val;
@ -164,6 +196,10 @@ protected:
};
}
using ID [[deprecated("Remove in v4.1. Use zeek::detail::ID instead.")]] = zeek::detail::ID;
namespace zeek::id {
/**
@ -172,7 +208,7 @@ namespace zeek::id {
* @return The identifier, which may reference a nil object if no such
* name exists.
*/
const IntrusivePtr<ID>& find(std::string_view name);
const 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
@ -180,7 +216,7 @@ const IntrusivePtr<ID>& find(std::string_view name);
* @param name The identifier name to lookup
* @return The type of the identifier.
*/
const IntrusivePtr<BroType>& find_type(std::string_view name);
const IntrusivePtr<zeek::Type>& find_type(std::string_view name);
/**
* Lookup an ID by its name and return its type (as cast to @c T).
@ -236,17 +272,17 @@ IntrusivePtr<T> find_const(std::string_view name)
*/
IntrusivePtr<Func> find_func(std::string_view name);
extern IntrusivePtr<RecordType> conn_id;
extern IntrusivePtr<RecordType> endpoint;
extern IntrusivePtr<RecordType> connection;
extern IntrusivePtr<RecordType> fa_file;
extern IntrusivePtr<RecordType> fa_metadata;
extern IntrusivePtr<EnumType> transport_proto;
extern IntrusivePtr<TableType> string_set;
extern IntrusivePtr<TableType> string_array;
extern IntrusivePtr<TableType> count_set;
extern IntrusivePtr<VectorType> string_vec;
extern IntrusivePtr<VectorType> index_vec;
extern IntrusivePtr<zeek::RecordType> conn_id;
extern IntrusivePtr<zeek::RecordType> endpoint;
extern IntrusivePtr<zeek::RecordType> connection;
extern IntrusivePtr<zeek::RecordType> fa_file;
extern IntrusivePtr<zeek::RecordType> fa_metadata;
extern IntrusivePtr<zeek::EnumType> transport_proto;
extern IntrusivePtr<zeek::TableType> string_set;
extern IntrusivePtr<zeek::TableType> string_array;
extern IntrusivePtr<zeek::TableType> count_set;
extern IntrusivePtr<zeek::VectorType> string_vec;
extern IntrusivePtr<zeek::VectorType> index_vec;
namespace detail {

View file

@ -15,11 +15,11 @@
static IntrusivePtr<VectorVal> BuildOptionsVal(const u_char* data, int len)
{
auto vv = make_intrusive<VectorVal>(zeek::id::find_type<VectorType>("ip6_options"));
auto vv = make_intrusive<VectorVal>(zeek::id::find_type<zeek::VectorType>("ip6_options"));
while ( len > 0 )
{
static auto ip6_option_type = zeek::id::find_type<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;
auto rv = make_intrusive<RecordVal>(ip6_option_type);
rv->Assign(0, val_mgr->Count(opt->ip6o_type));
@ -56,7 +56,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
switch ( type ) {
case IPPROTO_IPV6:
{
static auto ip6_hdr_type = zeek::id::find_type<RecordType>("ip6_hdr");
static auto ip6_hdr_type = zeek::id::find_type<zeek::RecordType>("ip6_hdr");
rv = make_intrusive<RecordVal>(ip6_hdr_type);
const struct ip6_hdr* ip6 = (const struct ip6_hdr*)data;
rv->Assign(0, val_mgr->Count((ntohl(ip6->ip6_flow) & 0x0ff00000)>>20));
@ -68,14 +68,14 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
rv->Assign(6, make_intrusive<AddrVal>(IPAddr(ip6->ip6_dst)));
if ( ! chain )
chain = make_intrusive<VectorVal>(
zeek::id::find_type<VectorType>("ip6_ext_hdr_chain"));
zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain"));
rv->Assign(7, std::move(chain));
}
break;
case IPPROTO_HOPOPTS:
{
static auto ip6_hopopts_type = zeek::id::find_type<RecordType>("ip6_hopopts");
static auto ip6_hopopts_type = zeek::id::find_type<zeek::RecordType>("ip6_hopopts");
rv = make_intrusive<RecordVal>(ip6_hopopts_type);
const struct ip6_hbh* hbh = (const struct ip6_hbh*)data;
rv->Assign(0, val_mgr->Count(hbh->ip6h_nxt));
@ -88,7 +88,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_DSTOPTS:
{
static auto ip6_dstopts_type = zeek::id::find_type<RecordType>("ip6_dstopts");
static auto ip6_dstopts_type = zeek::id::find_type<zeek::RecordType>("ip6_dstopts");
rv = make_intrusive<RecordVal>(ip6_dstopts_type);
const struct ip6_dest* dst = (const struct ip6_dest*)data;
rv->Assign(0, val_mgr->Count(dst->ip6d_nxt));
@ -100,7 +100,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ROUTING:
{
static auto ip6_routing_type = zeek::id::find_type<RecordType>("ip6_routing");
static auto ip6_routing_type = zeek::id::find_type<zeek::RecordType>("ip6_routing");
rv = make_intrusive<RecordVal>(ip6_routing_type);
const struct ip6_rthdr* rt = (const struct ip6_rthdr*)data;
rv->Assign(0, val_mgr->Count(rt->ip6r_nxt));
@ -114,7 +114,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_FRAGMENT:
{
static auto ip6_fragment_type = zeek::id::find_type<RecordType>("ip6_fragment");
static auto ip6_fragment_type = zeek::id::find_type<zeek::RecordType>("ip6_fragment");
rv = make_intrusive<RecordVal>(ip6_fragment_type);
const struct ip6_frag* frag = (const struct ip6_frag*)data;
rv->Assign(0, val_mgr->Count(frag->ip6f_nxt));
@ -128,7 +128,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_AH:
{
static auto ip6_ah_type = zeek::id::find_type<RecordType>("ip6_ah");
static auto ip6_ah_type = zeek::id::find_type<zeek::RecordType>("ip6_ah");
rv = make_intrusive<RecordVal>(ip6_ah_type);
rv->Assign(0, val_mgr->Count(((ip6_ext*)data)->ip6e_nxt));
rv->Assign(1, val_mgr->Count(((ip6_ext*)data)->ip6e_len));
@ -148,7 +148,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
case IPPROTO_ESP:
{
static auto ip6_esp_type = zeek::id::find_type<RecordType>("ip6_esp");
static auto ip6_esp_type = zeek::id::find_type<zeek::RecordType>("ip6_esp");
rv = make_intrusive<RecordVal>(ip6_esp_type);
const uint32_t* esp = (const uint32_t*)data;
rv->Assign(0, val_mgr->Count(ntohl(esp[0])));
@ -159,7 +159,7 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
#ifdef ENABLE_MOBILE_IPV6
case IPPROTO_MOBILITY:
{
static auto ip6_mob_type = zeek::id::find_type<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);
const struct ip6_mobility* mob = (const struct ip6_mobility*) data;
rv->Assign(0, val_mgr->Count(mob->ip6mob_payload));
@ -168,21 +168,21 @@ IntrusivePtr<RecordVal> IPv6_Hdr::ToVal(IntrusivePtr<VectorVal> chain) const
rv->Assign(3, val_mgr->Count(mob->ip6mob_rsv));
rv->Assign(4, val_mgr->Count(ntohs(mob->ip6mob_chksum)));
static auto ip6_mob_msg_type = zeek::id::find_type<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);
msg->Assign(0, val_mgr->Count(mob->ip6mob_type));
uint16_t off = sizeof(ip6_mobility);
const u_char* msg_data = data + off;
static auto ip6_mob_brr_type = zeek::id::find_type<RecordType>("ip6_mobility_brr");
static auto ip6_mob_hoti_type = zeek::id::find_type<RecordType>("ip6_mobility_hoti");
static auto ip6_mob_coti_type = zeek::id::find_type<RecordType>("ip6_mobility_coti");
static auto ip6_mob_hot_type = zeek::id::find_type<RecordType>("ip6_mobility_hot");
static auto ip6_mob_cot_type = zeek::id::find_type<RecordType>("ip6_mobility_cot");
static auto ip6_mob_bu_type = zeek::id::find_type<RecordType>("ip6_mobility_bu");
static auto ip6_mob_back_type = zeek::id::find_type<RecordType>("ip6_mobility_back");
static auto ip6_mob_be_type = zeek::id::find_type<RecordType>("ip6_mobility_be");
static auto ip6_mob_brr_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_brr");
static auto ip6_mob_hoti_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_hoti");
static auto ip6_mob_coti_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_coti");
static auto ip6_mob_hot_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_hot");
static auto ip6_mob_cot_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_cot");
static auto ip6_mob_bu_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_bu");
static auto ip6_mob_back_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_back");
static auto ip6_mob_be_type = zeek::id::find_type<zeek::RecordType>("ip6_mobility_be");
switch ( mob->ip6mob_type ) {
case 0:
@ -332,7 +332,7 @@ IntrusivePtr<RecordVal> IP_Hdr::ToIPHdrVal() const
if ( ip4 )
{
static auto ip4_hdr_type = zeek::id::find_type<RecordType>("ip4_hdr");
static auto ip4_hdr_type = zeek::id::find_type<zeek::RecordType>("ip4_hdr");
rval = make_intrusive<RecordVal>(ip4_hdr_type);
rval->Assign(0, val_mgr->Count(ip4->ip_hl * 4));
rval->Assign(1, val_mgr->Count(ip4->ip_tos));
@ -358,7 +358,7 @@ RecordVal* IP_Hdr::BuildIPHdrVal() const
IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal() const
{
static auto pkt_hdr_type = zeek::id::find_type<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);
}
@ -369,9 +369,9 @@ RecordVal* IP_Hdr::BuildPktHdrVal() const
IntrusivePtr<RecordVal> IP_Hdr::ToPktHdrVal(IntrusivePtr<RecordVal> pkt_hdr, int sindex) const
{
static auto tcp_hdr_type = zeek::id::find_type<RecordType>("tcp_hdr");
static auto udp_hdr_type = zeek::id::find_type<RecordType>("udp_hdr");
static auto icmp_hdr_type = zeek::id::find_type<RecordType>("icmp_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 icmp_hdr_type = zeek::id::find_type<zeek::RecordType>("icmp_hdr");
if ( ip4 )
pkt_hdr->Assign(sindex + 0, ToIPHdrVal());
@ -678,14 +678,14 @@ void IPv6_Hdr_Chain::ProcessDstOpts(const struct ip6_dest* d, uint16_t len)
IntrusivePtr<VectorVal> IPv6_Hdr_Chain::ToVal() const
{
static auto ip6_ext_hdr_type = zeek::id::find_type<RecordType>("ip6_ext_hdr");
static auto ip6_hopopts_type = zeek::id::find_type<RecordType>("ip6_hopopts");
static auto ip6_dstopts_type = zeek::id::find_type<RecordType>("ip6_dstopts");
static auto ip6_routing_type = zeek::id::find_type<RecordType>("ip6_routing");
static auto ip6_fragment_type = zeek::id::find_type<RecordType>("ip6_fragment");
static auto ip6_ah_type = zeek::id::find_type<RecordType>("ip6_ah");
static auto ip6_esp_type = zeek::id::find_type<RecordType>("ip6_esp");
static auto ip6_ext_hdr_chain_type = zeek::id::find_type<VectorType>("ip6_ext_hdr_chain");
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_dstopts_type = zeek::id::find_type<zeek::RecordType>("ip6_dstopts");
static auto ip6_routing_type = zeek::id::find_type<zeek::RecordType>("ip6_routing");
static auto ip6_fragment_type = zeek::id::find_type<zeek::RecordType>("ip6_fragment");
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_ext_hdr_chain_type = zeek::id::find_type<zeek::VectorType>("ip6_ext_hdr_chain");
auto rval = make_intrusive<VectorVal>(ip6_ext_hdr_chain_type);
for ( size_t i = 1; i < chain.size(); ++i )

View file

@ -199,7 +199,7 @@ void net_init(const std::optional<std::string>& interface,
reporter->Error("trace_output_file not defined in bro.init");
}
init_ip_addr_anonymizers();
zeek::detail::init_ip_addr_anonymizers();
sessions = new NetSessions();
@ -409,8 +409,8 @@ void net_delete()
delete sessions;
for ( int i = 0; i < NUM_ADDR_ANONYMIZATION_METHODS; ++i )
delete ip_anonymizer[i];
for ( int i = 0; i < zeek::detail::NUM_ADDR_ANONYMIZATION_METHODS; ++i )
delete zeek::detail::ip_anonymizer[i];
}
int _processing_suspended = 0;

View file

@ -8,27 +8,27 @@
#include "Val.h"
#include "ID.h"
RecordType* conn_id;
RecordType* endpoint;
RecordType* endpoint_stats;
RecordType* connection_type;
RecordType* fa_file_type;
RecordType* fa_metadata_type;
RecordType* icmp_conn;
RecordType* icmp_context;
RecordType* SYN_packet;
RecordType* pcap_packet;
RecordType* raw_pkt_hdr_type;
RecordType* l2_hdr_type;
RecordType* signature_state;
EnumType* transport_proto;
TableType* string_set;
TableType* string_array;
TableType* count_set;
VectorType* string_vec;
VectorType* index_vec;
VectorType* mime_matches;
RecordType* mime_match;
zeek::RecordType* conn_id;
zeek::RecordType* endpoint;
zeek::RecordType* endpoint_stats;
zeek::RecordType* connection_type;
zeek::RecordType* fa_file_type;
zeek::RecordType* fa_metadata_type;
zeek::RecordType* icmp_conn;
zeek::RecordType* icmp_context;
zeek::RecordType* SYN_packet;
zeek::RecordType* pcap_packet;
zeek::RecordType* raw_pkt_hdr_type;
zeek::RecordType* l2_hdr_type;
zeek::RecordType* signature_state;
zeek::EnumType* transport_proto;
zeek::TableType* string_set;
zeek::TableType* string_array;
zeek::TableType* count_set;
zeek::VectorType* string_vec;
zeek::VectorType* index_vec;
zeek::VectorType* mime_matches;
zeek::RecordType* mime_match;
int watchdog_interval;
@ -56,7 +56,7 @@ int tcp_max_above_hole_without_any_acks;
int tcp_excessive_data_without_further_acks;
int tcp_max_old_segments;
RecordType* socks_address;
zeek::RecordType* socks_address;
double non_analyzed_lifetime;
double tcp_inactivity_timeout;
@ -86,32 +86,32 @@ double rpc_timeout;
int mime_segment_length;
int mime_segment_overlap_length;
RecordType* mime_header_rec;
TableType* mime_header_list;
zeek::RecordType* mime_header_rec;
zeek::TableType* mime_header_list;
int http_entity_data_delivery_size;
RecordType* http_stats_rec;
RecordType* http_message_stat;
zeek::RecordType* http_stats_rec;
zeek::RecordType* http_message_stat;
int truncate_http_URI;
RecordType* pm_mapping;
TableType* pm_mappings;
RecordType* pm_port_request;
RecordType* pm_callit_request;
zeek::RecordType* pm_mapping;
zeek::TableType* pm_mappings;
zeek::RecordType* pm_port_request;
zeek::RecordType* pm_callit_request;
RecordType* geo_location;
zeek::RecordType* geo_location;
RecordType* entropy_test_result;
zeek::RecordType* entropy_test_result;
RecordType* dns_msg;
RecordType* dns_answer;
RecordType* dns_soa;
RecordType* dns_edns_additional;
RecordType* dns_tsig_additional;
RecordType* dns_rrsig_rr;
RecordType* dns_dnskey_rr;
RecordType* dns_nsec3_rr;
RecordType* dns_ds_rr;
zeek::RecordType* dns_msg;
zeek::RecordType* dns_answer;
zeek::RecordType* dns_soa;
zeek::RecordType* dns_edns_additional;
zeek::RecordType* dns_tsig_additional;
zeek::RecordType* dns_rrsig_rr;
zeek::RecordType* dns_dnskey_rr;
zeek::RecordType* dns_nsec3_rr;
zeek::RecordType* dns_ds_rr;
TableVal* dns_skip_auth;
TableVal* dns_skip_addl;
int dns_skip_all_auth;
@ -134,7 +134,7 @@ TableVal* preserve_orig_addr;
TableVal* preserve_resp_addr;
TableVal* preserve_other_addr;
RecordType* rotate_info;
zeek::RecordType* rotate_info;
StringVal* log_rotate_base_time;
StringVal* peer_description;
@ -153,8 +153,8 @@ int packet_filter_default;
int sig_max_group_size;
TableType* irc_join_list;
RecordType* irc_join_info;
zeek::TableType* irc_join_list;
zeek::RecordType* irc_join_info;
int dpd_reassemble_first_packets;
int dpd_buffer_size;
@ -172,12 +172,12 @@ StringVal* trace_output_file;
int record_all_packets;
RecordType* script_id;
TableType* id_table;
RecordType* record_field;
TableType* record_field_table;
RecordType* call_argument;
VectorType* call_argument_vector;
zeek::RecordType* script_id;
zeek::TableType* id_table;
zeek::RecordType* record_field;
zeek::TableType* record_field_table;
zeek::RecordType* call_argument;
zeek::VectorType* call_argument_vector;
StringVal* cmd_line_bpf_filter;

View file

@ -7,47 +7,47 @@
#include "Stats.h"
[[deprecated("Remove in v4.1. Use zeek::id::conn_id.")]]
extern RecordType* conn_id;
extern zeek::RecordType* conn_id;
[[deprecated("Remove in v4.1. Use zeek::id::endpoint.")]]
extern RecordType* endpoint;
extern zeek::RecordType* endpoint;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* endpoint_stats;
extern zeek::RecordType* endpoint_stats;
[[deprecated("Remove in v4.1. Use zeek::id::connection.")]]
extern RecordType* connection_type;
extern zeek::RecordType* connection_type;
[[deprecated("Remove in v4.1. Use zeek::id::fa_file.")]]
extern RecordType* fa_file_type;
extern zeek::RecordType* fa_file_type;
[[deprecated("Remove in v4.1. Use zeek::id::fa_metadata.")]]
extern RecordType* fa_metadata_type;
extern zeek::RecordType* fa_metadata_type;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* icmp_conn;
extern zeek::RecordType* icmp_conn;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* icmp_context;
extern zeek::RecordType* icmp_context;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* signature_state;
extern zeek::RecordType* signature_state;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* SYN_packet;
extern zeek::RecordType* SYN_packet;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* pcap_packet;
extern zeek::RecordType* pcap_packet;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* raw_pkt_hdr_type;
extern zeek::RecordType* raw_pkt_hdr_type;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* l2_hdr_type;
extern zeek::RecordType* l2_hdr_type;
[[deprecated("Remove in v4.1. Use zeek::id::transport_proto.")]]
extern EnumType* transport_proto;
extern zeek::EnumType* transport_proto;
[[deprecated("Remove in v4.1. Use zeek::id::string_set.")]]
extern TableType* string_set;
extern zeek::TableType* string_set;
[[deprecated("Remove in v4.1. Use zeek::id::string_array.")]]
extern TableType* string_array;
extern zeek::TableType* string_array;
[[deprecated("Remove in v4.1. Use zeek::id::count_set.")]]
extern TableType* count_set;
extern zeek::TableType* count_set;
[[deprecated("Remove in v4.1. Use zeek::id::string_vec.")]]
extern VectorType* string_vec;
extern zeek::VectorType* string_vec;
[[deprecated("Remove in v4.1. Use zeek::id::index_vec.")]]
extern VectorType* index_vec;
extern zeek::VectorType* index_vec;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern VectorType* mime_matches;
extern zeek::VectorType* mime_matches;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* mime_match;
extern zeek::RecordType* mime_match;
extern int watchdog_interval;
@ -76,7 +76,7 @@ extern int tcp_excessive_data_without_further_acks;
extern int tcp_max_old_segments;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* socks_address;
extern zeek::RecordType* socks_address;
extern double non_analyzed_lifetime;
extern double tcp_inactivity_timeout;
@ -114,50 +114,50 @@ extern double rpc_timeout;
extern int mime_segment_length;
extern int mime_segment_overlap_length;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* mime_header_rec;
extern zeek::RecordType* mime_header_rec;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableType* mime_header_list;
extern zeek::TableType* mime_header_list;
extern int http_entity_data_delivery_size;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* http_stats_rec;
extern zeek::RecordType* http_stats_rec;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* http_message_stat;
extern zeek::RecordType* http_message_stat;
extern int truncate_http_URI;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* pm_mapping;
extern zeek::RecordType* pm_mapping;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableType* pm_mappings;
extern zeek::TableType* pm_mappings;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* pm_port_request;
extern zeek::RecordType* pm_port_request;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* pm_callit_request;
extern zeek::RecordType* pm_callit_request;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* geo_location;
extern zeek::RecordType* geo_location;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* entropy_test_result;
extern zeek::RecordType* entropy_test_result;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_msg;
extern zeek::RecordType* dns_msg;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_answer;
extern zeek::RecordType* dns_answer;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_soa;
extern zeek::RecordType* dns_soa;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_edns_additional;
extern zeek::RecordType* dns_edns_additional;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_tsig_additional;
extern zeek::RecordType* dns_tsig_additional;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_rrsig_rr;
extern zeek::RecordType* dns_rrsig_rr;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_dnskey_rr;
extern zeek::RecordType* dns_dnskey_rr;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_nsec3_rr;
extern zeek::RecordType* dns_nsec3_rr;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* dns_ds_rr;
extern zeek::RecordType* dns_ds_rr;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableVal* dns_skip_auth;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
@ -187,7 +187,7 @@ extern TableVal* preserve_other_addr;
extern double connection_status_update_interval;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* rotate_info;
extern zeek::RecordType* rotate_info;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern StringVal* log_rotate_base_time;
@ -212,9 +212,9 @@ extern int packet_filter_default;
extern int sig_max_group_size;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableType* irc_join_list;
extern zeek::TableType* irc_join_list;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* irc_join_info;
extern zeek::RecordType* irc_join_info;
extern int dpd_reassemble_first_packets;
extern int dpd_buffer_size;
@ -235,17 +235,17 @@ extern StringVal* trace_output_file;
extern int record_all_packets;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* script_id;
extern zeek::RecordType* script_id;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableType* id_table;
extern zeek::TableType* id_table;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* record_field;
extern zeek::RecordType* record_field;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern TableType* record_field_table;
extern zeek::TableType* record_field_table;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern RecordType* call_argument;
extern zeek::RecordType* call_argument;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern VectorType* call_argument_vector;
extern zeek::VectorType* call_argument_vector;
[[deprecated("Remove in v4.1. Perform your own lookup.")]]
extern StringVal* cmd_line_bpf_filter;

View file

@ -37,10 +37,10 @@ OpaqueMgr* OpaqueMgr::mgr()
return &mgr;
}
OpaqueVal::OpaqueVal(OpaqueType* t) : OpaqueVal({NewRef{}, t})
OpaqueVal::OpaqueVal(zeek::OpaqueType* t) : OpaqueVal({NewRef{}, t})
{}
OpaqueVal::OpaqueVal(IntrusivePtr<OpaqueType> t) : Val(std::move(t))
OpaqueVal::OpaqueVal(IntrusivePtr<zeek::OpaqueType> t) : Val(std::move(t))
{}
OpaqueVal::~OpaqueVal()
@ -96,12 +96,12 @@ IntrusivePtr<OpaqueVal> OpaqueVal::Unserialize(const broker::data& data)
return val;
}
broker::expected<broker::data> OpaqueVal::SerializeType(const IntrusivePtr<BroType>& t)
broker::expected<broker::data> OpaqueVal::SerializeType(const IntrusivePtr<zeek::Type>& t)
{
if ( t->InternalType() == TYPE_INTERNAL_ERROR )
if ( t->InternalType() == zeek::TYPE_INTERNAL_ERROR )
return broker::ec::invalid_data;
if ( t->InternalType() == TYPE_INTERNAL_OTHER )
if ( t->InternalType() == zeek::TYPE_INTERNAL_OTHER )
{
// Serialize by name.
assert(t->GetName().size());
@ -112,7 +112,7 @@ broker::expected<broker::data> OpaqueVal::SerializeType(const IntrusivePtr<BroTy
return {broker::vector{false, static_cast<uint64_t>(t->Tag())}};
}
IntrusivePtr<BroType> OpaqueVal::UnserializeType(const broker::data& data)
IntrusivePtr<zeek::Type> OpaqueVal::UnserializeType(const broker::data& data)
{
auto v = caf::get_if<broker::vector>(&data);
if ( ! (v && v->size() == 2) )
@ -142,7 +142,7 @@ IntrusivePtr<BroType> OpaqueVal::UnserializeType(const broker::data& data)
if ( ! tag )
return nullptr;
return base_type(static_cast<TypeTag>(*tag));
return zeek::base_type(static_cast<zeek::TypeTag>(*tag));
}
IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state)
@ -206,12 +206,12 @@ IntrusivePtr<StringVal> HashVal::DoGet()
return val_mgr->EmptyString();
}
HashVal::HashVal(IntrusivePtr<OpaqueType> t) : OpaqueVal(std::move(t))
HashVal::HashVal(IntrusivePtr<zeek::OpaqueType> t) : OpaqueVal(std::move(t))
{
valid = false;
}
HashVal::HashVal(OpaqueType* t) : HashVal({NewRef{}, t})
HashVal::HashVal(zeek::OpaqueType* t) : HashVal({NewRef{}, t})
{}
MD5Val::MD5Val() : HashVal(md5_type)
@ -226,7 +226,7 @@ MD5Val::~MD5Val()
void HashVal::digest_one(EVP_MD_CTX* h, const Val* v)
{
if ( v->GetType()->Tag() == TYPE_STRING )
if ( v->GetType()->Tag() == zeek::TYPE_STRING )
{
const BroString* str = v->AsString();
hash_update(h, str->Bytes(), str->Len());
@ -723,14 +723,14 @@ IntrusivePtr<Val> BloomFilterVal::DoClone(CloneState* state)
return state->NewClone(this, make_intrusive<BloomFilterVal>());
}
bool BloomFilterVal::Typify(IntrusivePtr<BroType> arg_type)
bool BloomFilterVal::Typify(IntrusivePtr<zeek::Type> arg_type)
{
if ( type )
return false;
type = std::move(arg_type);
auto tl = make_intrusive<TypeList>(type);
auto tl = make_intrusive<zeek::TypeList>(type);
tl->Append(type);
hash = new CompositeHash(std::move(tl));
@ -882,14 +882,14 @@ IntrusivePtr<Val> CardinalityVal::DoClone(CloneState* state)
make_intrusive<CardinalityVal>(new probabilistic::CardinalityCounter(*c)));
}
bool CardinalityVal::Typify(IntrusivePtr<BroType> arg_type)
bool CardinalityVal::Typify(IntrusivePtr<zeek::Type> arg_type)
{
if ( type )
return false;
type = std::move(arg_type);
auto tl = make_intrusive<TypeList>(type);
auto tl = make_intrusive<zeek::TypeList>(type);
tl->Append(type);
hash = new CompositeHash(std::move(tl));

View file

@ -88,8 +88,8 @@ private:
class OpaqueVal : public Val {
public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit OpaqueVal(OpaqueType* t);
explicit OpaqueVal(IntrusivePtr<OpaqueType> t);
explicit OpaqueVal(zeek::OpaqueType* t);
explicit OpaqueVal(IntrusivePtr<zeek::OpaqueType> t);
~OpaqueVal() override;
/**
@ -148,13 +148,13 @@ protected:
* Helper function for derived class that need to record a type
* during serialization.
*/
static broker::expected<broker::data> SerializeType(const IntrusivePtr<BroType>& t);
static broker::expected<broker::data> SerializeType(const IntrusivePtr<zeek::Type>& t);
/**
* Helper function for derived class that need to restore a type
* during unserialization. Returns the type at reference count +1.
*/
static IntrusivePtr<BroType> UnserializeType(const broker::data& data);
static IntrusivePtr<zeek::Type> UnserializeType(const broker::data& data);
};
namespace probabilistic {
@ -187,8 +187,8 @@ protected:
HashVal() { valid = false; }
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit HashVal(OpaqueType* t);
explicit HashVal(IntrusivePtr<OpaqueType> t);
explicit HashVal(zeek::OpaqueType* t);
explicit HashVal(IntrusivePtr<zeek::OpaqueType> t);
virtual bool DoInit();
virtual bool DoFeed(const void* data, size_t size);
@ -304,10 +304,10 @@ public:
IntrusivePtr<Val> DoClone(CloneState* state) override;
const IntrusivePtr<BroType>& Type() const
const IntrusivePtr<zeek::Type>& Type() const
{ return type; }
bool Typify(IntrusivePtr<BroType> type);
bool Typify(IntrusivePtr<zeek::Type> type);
void Add(const Val* val);
size_t Count(const Val* val) const;
@ -328,7 +328,7 @@ private:
BloomFilterVal(const BloomFilterVal&);
BloomFilterVal& operator=(const BloomFilterVal&);
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
CompositeHash* hash;
probabilistic::BloomFilter* bloom_filter;
};
@ -343,10 +343,10 @@ public:
void Add(const Val* val);
const IntrusivePtr<BroType>& Type() const
const IntrusivePtr<zeek::Type>& Type() const
{ return type; }
bool Typify(IntrusivePtr<BroType> type);
bool Typify(IntrusivePtr<zeek::Type> type);
probabilistic::CardinalityCounter* Get() { return c; };
@ -355,7 +355,7 @@ protected:
DECLARE_OPAQUE_VALUE(CardinalityVal)
private:
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
CompositeHash* hash;
probabilistic::CardinalityCounter* c;
};

View file

@ -7,7 +7,7 @@
#include <errno.h>
#include <cstdio>
using namespace bro;
using namespace zeek::detail;
static void pipe_fail(int eno)
{

View file

@ -2,7 +2,7 @@
#pragma once
namespace bro {
namespace zeek::detail {
class Pipe {
public:
@ -136,4 +136,4 @@ private:
bool swapped = false;
};
} // namespace bro
} // namespace zeek::detail

View file

@ -43,16 +43,16 @@ void* PrefixTable::Insert(const IPAddr& addr, int width, void* data)
void* PrefixTable::Insert(const Val* value, void* data)
{
// [elem] -> elem
if ( value->GetType()->Tag() == TYPE_LIST &&
if ( value->GetType()->Tag() == zeek::TYPE_LIST &&
value->AsListVal()->Length() == 1 )
value = value->AsListVal()->Idx(0).get();
switch ( value->GetType()->Tag() ) {
case TYPE_ADDR:
case zeek::TYPE_ADDR:
return Insert(value->AsAddr(), 128, data);
break;
case TYPE_SUBNET:
case zeek::TYPE_SUBNET:
return Insert(value->AsSubNet().Prefix(),
value->AsSubNet().LengthIPv6(), data);
break;
@ -103,16 +103,16 @@ void* PrefixTable::Lookup(const IPAddr& addr, int width, bool exact) const
void* PrefixTable::Lookup(const Val* value, bool exact) const
{
// [elem] -> elem
if ( value->GetType()->Tag() == TYPE_LIST &&
if ( value->GetType()->Tag() == zeek::TYPE_LIST &&
value->AsListVal()->Length() == 1 )
value = value->AsListVal()->Idx(0).get();
switch ( value->GetType()->Tag() ) {
case TYPE_ADDR:
case zeek::TYPE_ADDR:
return Lookup(value->AsAddr(), 128, exact);
break;
case TYPE_SUBNET:
case zeek::TYPE_SUBNET:
return Lookup(value->AsSubNet().Prefix(),
value->AsSubNet().LengthIPv6(), exact);
break;
@ -142,16 +142,16 @@ void* PrefixTable::Remove(const IPAddr& addr, int width)
void* PrefixTable::Remove(const Val* value)
{
// [elem] -> elem
if ( value->GetType()->Tag() == TYPE_LIST &&
if ( value->GetType()->Tag() == zeek::TYPE_LIST &&
value->AsListVal()->Length() == 1 )
value = value->AsListVal()->Idx(0).get();
switch ( value->GetType()->Tag() ) {
case TYPE_ADDR:
case zeek::TYPE_ADDR:
return Remove(value->AsAddr(), 128);
break;
case TYPE_SUBNET:
case zeek::TYPE_SUBNET:
return Remove(value->AsSubNet().Prefix(),
value->AsSubNet().LengthIPv6());
break;

View file

@ -143,7 +143,7 @@ void Reporter::FatalErrorWithCore(const char* fmt, ...)
abort();
}
void Reporter::ExprRuntimeError(const Expr* expr, const char* fmt, ...)
void Reporter::ExprRuntimeError(const zeek::detail::Expr* expr, const char* fmt, ...)
{
++errors;

View file

@ -36,7 +36,8 @@ protected:
};
class IPAddr;
class Expr;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
#define FMT_ATTR __attribute__((format(printf, 2, 3))) // sic! 1st is "this" I guess.
@ -77,7 +78,7 @@ public:
// Report a runtime error in evaluating a Bro script expression. This
// function will not return but raise an InterpreterException.
[[noreturn]] void ExprRuntimeError(const Expr* expr, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
[[noreturn]] void ExprRuntimeError(const zeek::detail::Expr* expr, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
// Report a runtime error in evaluating a Bro script expression. This
// function will not return but raise an InterpreterException.

View file

@ -136,18 +136,18 @@ RuleConditionEval::RuleConditionEval(const char* func)
return;
}
if ( id->GetType()->Tag() == TYPE_FUNC )
if ( id->GetType()->Tag() == zeek::TYPE_FUNC )
{
// Validate argument quantity and type.
FuncType* f = id->GetType()->AsFuncType();
zeek::FuncType* f = id->GetType()->AsFuncType();
if ( f->Yield()->Tag() != TYPE_BOOL )
if ( f->Yield()->Tag() != zeek::TYPE_BOOL )
rules_error("eval function type must yield a 'bool'", func);
static auto signature_state = zeek::id::find_type<RecordType>("signature_state");
TypeList tl;
static auto signature_state = zeek::id::find_type<zeek::RecordType>("signature_state");
zeek::TypeList tl;
tl.Append(signature_state);
tl.Append(base_type(TYPE_STRING));
tl.Append(zeek::base_type(zeek::TYPE_STRING));
if ( ! f->CheckArgs(tl.Types()) )
rules_error("eval function parameters must be a 'signature_state' "
@ -164,7 +164,7 @@ bool RuleConditionEval::DoMatch(Rule* rule, RuleEndpointState* state,
return false;
}
if ( id->GetType()->Tag() != TYPE_FUNC )
if ( id->GetType()->Tag() != zeek::TYPE_FUNC )
return id->GetVal()->AsBool();
// Call function with a signature_state value as argument.

View file

@ -2,11 +2,13 @@
#include <stdint.h> // for u_char
#include <sys/types.h> // for u_char
#include "util.h"
class ID;
class Rule;
class RuleEndpointState;
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
// Base class for all rule conditions except patterns and "header".
class RuleCondition {
public:
@ -111,7 +113,5 @@ public:
void PrintDebug() override;
private:
ID* id;
zeek::detail::ID* id;
};

View file

@ -81,7 +81,7 @@ RuleHdrTest::RuleHdrTest(Prot arg_prot, Comp arg_comp, vector<IPPrefix> arg_v)
Val* RuleMatcher::BuildRuleStateValue(const Rule* rule,
const RuleEndpointState* state) const
{
static auto signature_state = zeek::id::find_type<RecordType>("signature_state");
static auto signature_state = zeek::id::find_type<zeek::RecordType>("signature_state");
RecordVal* val = new RecordVal(signature_state);
val->Assign(0, make_intrusive<StringVal>(rule->ID()));
val->Assign(1, state->GetAnalyzer()->ConnVal());
@ -1294,20 +1294,20 @@ static bool val_to_maskedval(Val* v, maskedvalue_list* append_to,
MaskedValue* mval = new MaskedValue;
switch ( v->GetType()->Tag() ) {
case TYPE_PORT:
case zeek::TYPE_PORT:
mval->val = v->AsPortVal()->Port();
mval->mask = 0xffffffff;
break;
case TYPE_BOOL:
case TYPE_COUNT:
case TYPE_ENUM:
case TYPE_INT:
case zeek::TYPE_BOOL:
case zeek::TYPE_COUNT:
case zeek::TYPE_ENUM:
case zeek::TYPE_INT:
mval->val = v->CoerceToUnsigned();
mval->mask = 0xffffffff;
break;
case TYPE_SUBNET:
case zeek::TYPE_SUBNET:
{
if ( prefix_vector )
{
@ -1362,7 +1362,7 @@ void id_to_maskedvallist(const char* id, maskedvalue_list* append_to,
if ( ! v )
return;
if ( v->GetType()->Tag() == TYPE_TABLE )
if ( v->GetType()->Tag() == zeek::TYPE_TABLE )
{
auto lv = v->AsTableVal()->ToPureListVal();
@ -1384,7 +1384,7 @@ char* id_to_str(const char* id)
if ( ! v )
goto error;
if ( v->GetType()->Tag() != TYPE_STRING )
if ( v->GetType()->Tag() != zeek::TYPE_STRING )
{
rules_error("Identifier must refer to string");
goto error;
@ -1407,10 +1407,10 @@ uint32_t id_to_uint(const char* id)
if ( ! v )
return 0;
TypeTag t = v->GetType()->Tag();
zeek::TypeTag t = v->GetType()->Tag();
if ( t == TYPE_BOOL || t == TYPE_COUNT || t == TYPE_ENUM ||
t == TYPE_INT || t == TYPE_PORT )
if ( t == zeek::TYPE_BOOL || t == zeek::TYPE_COUNT || t == zeek::TYPE_ENUM ||
t == zeek::TYPE_INT || t == zeek::TYPE_PORT )
return v->CoerceToUnsigned();
rules_error("Identifier must refer to integer");

View file

@ -15,8 +15,8 @@ typedef PList<Scope> scope_list;
static scope_list scopes;
static Scope* top_scope;
Scope::Scope(IntrusivePtr<ID> id,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> al)
Scope::Scope(IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> al)
: scope_id(std::move(id)), attrs(std::move(al))
{
return_type = nullptr;
@ -25,27 +25,27 @@ Scope::Scope(IntrusivePtr<ID> id,
{
const auto& id_type = scope_id->GetType();
if ( id_type->Tag() == TYPE_ERROR )
if ( id_type->Tag() == zeek::TYPE_ERROR )
return;
else if ( id_type->Tag() != TYPE_FUNC )
else if ( id_type->Tag() != zeek::TYPE_FUNC )
reporter->InternalError("bad scope id");
FuncType* ft = id->GetType()->AsFuncType();
zeek::FuncType* ft = id->GetType()->AsFuncType();
return_type = ft->Yield();
}
}
const IntrusivePtr<ID>& Scope::Find(std::string_view name) const
const IntrusivePtr<zeek::detail::ID>& Scope::Find(std::string_view name) const
{
auto entry = local.find(name);
if ( entry != local.end() )
return entry->second;
return ID::nil;
return zeek::detail::ID::nil;
}
IntrusivePtr<ID> Scope::Remove(std::string_view name)
IntrusivePtr<zeek::detail::ID> Scope::Remove(std::string_view name)
{
auto entry = local.find(name);
@ -59,12 +59,12 @@ IntrusivePtr<ID> Scope::Remove(std::string_view name)
return nullptr;
}
IntrusivePtr<ID> Scope::GenerateTemporary(const char* name)
IntrusivePtr<zeek::detail::ID> Scope::GenerateTemporary(const char* name)
{
return make_intrusive<ID>(name, SCOPE_FUNCTION, false);
return make_intrusive<zeek::detail::ID>(name, zeek::detail::SCOPE_FUNCTION, false);
}
std::vector<IntrusivePtr<ID>> Scope::GetInits()
std::vector<IntrusivePtr<zeek::detail::ID>> Scope::GetInits()
{
auto rval = std::move(inits);
inits = {};
@ -100,7 +100,7 @@ void Scope::Describe(ODesc* d) const
for ( const auto& entry : local )
{
ID* id = entry.second.get();
zeek::detail::ID* id = entry.second.get();
id->Describe(d);
d->NL();
}
@ -110,7 +110,7 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
{
for ( const auto& entry : local )
{
ID* id = entry.second.get();
zeek::detail::ID* id = entry.second.get();
TraversalCode tc = id->Traverse(cb);
HANDLE_TC_STMT_PRE(tc);
}
@ -119,9 +119,9 @@ TraversalCode Scope::Traverse(TraversalCallback* cb) const
}
const IntrusivePtr<ID>& lookup_ID(const char* name, const char* curr_module,
bool no_global, bool same_module_only,
bool check_export)
const IntrusivePtr<zeek::detail::ID>& lookup_ID(const char* name, const char* curr_module,
bool no_global, bool same_module_only,
bool check_export)
{
std::string fullname = make_full_var_name(curr_module, name);
@ -150,30 +150,30 @@ const IntrusivePtr<ID>& lookup_ID(const char* name, const char* curr_module,
return global_scope()->Find(globalname);
}
return ID::nil;
return zeek::detail::ID::nil;
}
IntrusivePtr<ID> install_ID(const char* name, const char* module_name,
IntrusivePtr<zeek::detail::ID> install_ID(const char* name, const char* module_name,
bool is_global, bool is_export)
{
if ( scopes.empty() && ! is_global )
reporter->InternalError("local identifier in global scope");
IDScope scope;
zeek::detail::IDScope scope;
if ( is_export || ! module_name ||
(is_global &&
normalized_module_name(module_name) == GLOBAL_MODULE_NAME) )
scope = SCOPE_GLOBAL;
scope = zeek::detail::SCOPE_GLOBAL;
else if ( is_global )
scope = SCOPE_MODULE;
scope = zeek::detail::SCOPE_MODULE;
else
scope = SCOPE_FUNCTION;
scope = zeek::detail::SCOPE_FUNCTION;
std::string full_name = make_full_var_name(module_name, name);
auto id = make_intrusive<ID>(full_name.data(), scope, is_export);
auto id = make_intrusive<zeek::detail::ID>(full_name.data(), scope, is_export);
if ( SCOPE_FUNCTION != scope )
if ( zeek::detail::SCOPE_FUNCTION != scope )
global_scope()->Insert(std::move(full_name), id);
else
{
@ -189,8 +189,8 @@ void push_existing_scope(Scope* scope)
scopes.push_back(scope);
}
void push_scope(IntrusivePtr<ID> id,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs)
void push_scope(IntrusivePtr<zeek::detail::ID> id,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs)
{
top_scope = new Scope(std::move(id), std::move(attrs));
scopes.push_back(top_scope);

View file

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

View file

@ -923,10 +923,10 @@ FragReassembler* NetSessions::NextFragment(double t, const IP_Hdr* ip,
Connection* NetSessions::FindConnection(Val* v)
{
const auto& vt = v->GetType();
if ( ! IsRecord(vt->Tag()) )
if ( ! zeek::IsRecord(vt->Tag()) )
return nullptr;
RecordType* vr = vt->AsRecordType();
zeek::RecordType* vr = vt->AsRecordType();
auto vl = v->AsRecord();
int orig_h, orig_p; // indices into record's value list

View file

@ -58,10 +58,10 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const
VectorVal* BroSubstring::VecToPolicy(Vec* vec)
{
static auto sw_substring_type = zeek::id::find_type<RecordType>("sw_substring");
static auto sw_align_type = zeek::id::find_type<RecordType>("sw_align");
static auto sw_align_vec_type = zeek::id::find_type<VectorType>("sw_align_vec");
static auto sw_substring_vec_type = zeek::id::find_type<VectorType>("sw_substring_vec");
static auto sw_substring_type = zeek::id::find_type<zeek::RecordType>("sw_substring");
static auto sw_align_type = zeek::id::find_type<zeek::RecordType>("sw_align");
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");
auto result = make_intrusive<VectorVal>(sw_substring_vec_type);

View file

@ -191,7 +191,7 @@ void ProfileLogger::Log()
dstats.requests, dstats.successful, dstats.failed, dstats.pending,
dstats.cached_hosts, dstats.cached_addresses));
trigger::Manager::Stats tstats;
zeek::detail::trigger::Manager::Stats tstats;
trigger_mgr->GetStats(&tstats);
file->Write(fmt("%.06f Triggers: total=%lu pending=%lu\n", network_time, tstats.total, tstats.pending));
@ -252,7 +252,7 @@ void ProfileLogger::Log()
for ( const auto& global : globals )
{
ID* id = global.second.get();
auto& id = global.second;
// We don't show/count internal globals as they are always
// contained in some other global user-visible container.
@ -270,7 +270,7 @@ void ProfileLogger::Log()
if ( size > 100 * 1024 )
print = true;
if ( v->GetType()->Tag() == TYPE_TABLE )
if ( v->GetType()->Tag() == zeek::TYPE_TABLE )
{
entries = v->AsTable()->Length();
total_table_entries += entries;
@ -339,7 +339,7 @@ void ProfileLogger::SegmentProfile(const char* name, const Location* loc,
SampleLogger::SampleLogger()
{
static TableType* load_sample_info = nullptr;
static zeek::TableType* load_sample_info = nullptr;
if ( ! load_sample_info )
load_sample_info = zeek::id::find_type("load_sample_info")->AsTableType();

View file

@ -2,6 +2,8 @@
#include "zeek-config.h"
#include "Stmt.h"
#include "CompHash.h"
#include "Expr.h"
#include "Event.h"
@ -9,7 +11,6 @@
#include "File.h"
#include "Reporter.h"
#include "NetVar.h"
#include "Stmt.h"
#include "Scope.h"
#include "Var.h"
#include "Desc.h"
@ -34,6 +35,8 @@ const char* stmt_name(BroStmtTag t)
return stmt_names[int(t)];
}
namespace zeek::detail {
Stmt::Stmt(BroStmtTag arg_tag)
{
tag = arg_tag;
@ -1833,3 +1836,5 @@ TraversalCode WhenStmt::Traverse(TraversalCallback* cb) const
tc = cb->PostStmt(this);
HANDLE_TC_STMT_POST(tc);
}
}

View file

@ -13,12 +13,15 @@
#include "TraverseTypes.h"
class StmtList;
class CompositeHash;
class Frame;
namespace zeek::detail {
class StmtList;
class ForStmt;
class EventExpr;
class ListExpr;
class ForStmt;
class Frame;
class Stmt : public BroObj {
public:
@ -447,3 +450,27 @@ protected:
IntrusivePtr<Expr> timeout;
bool is_return;
};
}
using Stmt [[deprecated("Remove in v4.1. Use zeek::detail::Stmt instead.")]] = zeek::detail::Stmt;
using ExprListStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprListStmt instead.")]] = zeek::detail::ExprListStmt;
using PrintStmt [[deprecated("Remove in v4.1. Use zeek::detail::PrintStmt instead.")]] = zeek::detail::PrintStmt;
using ExprStmt [[deprecated("Remove in v4.1. Use zeek::detail::ExprStmt instead.")]] = zeek::detail::ExprStmt;
using IfStmt [[deprecated("Remove in v4.1. Use zeek::detail::IfStmt instead.")]] = zeek::detail::IfStmt;
using Case [[deprecated("Remove in v4.1. Use zeek::detail::Case instead.")]] = zeek::detail::Case;
using SwitchStmt [[deprecated("Remove in v4.1. Use zeek::detail::SwitchStmt instead.")]] = zeek::detail::SwitchStmt;
using AddStmt [[deprecated("Remove in v4.1. Use zeek::detail::AddStmt instead.")]] = zeek::detail::AddStmt;
using DelStmt [[deprecated("Remove in v4.1. Use zeek::detail::DelStmt instead.")]] = zeek::detail::DelStmt;
using EventStmt [[deprecated("Remove in v4.1. Use zeek::detail::EventStmt instead.")]] = zeek::detail::EventStmt;
using WhileStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhileStmt instead.")]] = zeek::detail::WhileStmt;
using ForStmt [[deprecated("Remove in v4.1. Use zeek::detail::ForStmt instead.")]] = zeek::detail::ForStmt;
using NextStmt [[deprecated("Remove in v4.1. Use zeek::detail::NextStmt instead.")]] = zeek::detail::NextStmt;
using BreakStmt [[deprecated("Remove in v4.1. Use zeek::detail::BreakStmt instead.")]] = zeek::detail::BreakStmt;
using FallthroughStmt [[deprecated("Remove in v4.1. Use zeek::detail::FallthroughStmt instead.")]] = zeek::detail::FallthroughStmt;
using ReturnStmt [[deprecated("Remove in v4.1. Use zeek::detail::ReturnStmt instead.")]] = zeek::detail::ReturnStmt;
using StmtList [[deprecated("Remove in v4.1. Use zeek::detail::StmtList instead.")]] = zeek::detail::StmtList;
using EventBodyList [[deprecated("Remove in v4.1. Use zeek::detail::EventBodyList instead.")]] = zeek::detail::EventBodyList;
using InitStmt [[deprecated("Remove in v4.1. Use zeek::detail::InitStmt instead.")]] = zeek::detail::InitStmt;
using NullStmt [[deprecated("Remove in v4.1. Use zeek::detail::NullStmt instead.")]] = zeek::detail::NullStmt;
using WhenStmt [[deprecated("Remove in v4.1. Use zeek::detail::WhenStmt instead.")]] = zeek::detail::WhenStmt;

View file

@ -4,7 +4,7 @@
#include "Val.h"
#include "IntrusivePtr.h"
Tag::Tag(const IntrusivePtr<EnumType>& etype, type_t arg_type, subtype_t arg_subtype)
Tag::Tag(const IntrusivePtr<zeek::EnumType>& etype, type_t arg_type, subtype_t arg_subtype)
{
assert(arg_type > 0);
@ -14,7 +14,7 @@ Tag::Tag(const IntrusivePtr<EnumType>& etype, type_t arg_type, subtype_t arg_sub
val = etype->GetVal(i);
}
Tag::Tag(EnumType* etype, type_t arg_type, subtype_t arg_subtype)
Tag::Tag(zeek::EnumType* etype, type_t arg_type, subtype_t arg_subtype)
: Tag({NewRef{}, etype}, arg_type, arg_subtype)
{ }
@ -73,7 +73,7 @@ Tag& Tag::operator=(const Tag&& other) noexcept
return *this;
}
const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<EnumType>& etype) const
const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<zeek::EnumType>& etype) const
{
if ( ! val )
{
@ -84,7 +84,7 @@ const IntrusivePtr<EnumVal>& Tag::AsVal(const IntrusivePtr<EnumType>& etype) con
return val;
}
EnumVal* Tag::AsEnumVal(EnumType* etype) const
EnumVal* Tag::AsEnumVal(zeek::EnumType* etype) const
{
return AsVal({NewRef{}, etype}).get();
}

View file

@ -3,14 +3,15 @@
#pragma once
#include "zeek-config.h"
#include "IntrusivePtr.h"
#include <string>
#include <stdint.h>
#include <string>
#include "IntrusivePtr.h"
#include "util.h"
class EnumVal;
class EnumType;
ZEEK_FORWARD_DECLARE_NAMESPACED(EnumType, zeek);
/**
* Class to identify an analyzer type.
@ -115,10 +116,10 @@ protected:
*
* @param etype the script-layer enum type associated with the tag.
*/
const IntrusivePtr<EnumVal>& AsVal(const IntrusivePtr<EnumType>& etype) const;
const IntrusivePtr<EnumVal>& AsVal(const IntrusivePtr<zeek::EnumType>& etype) const;
[[deprecated("Remove in v4.1. Use AsVal() instead.")]]
EnumVal* AsEnumVal(EnumType* etype) const;
EnumVal* AsEnumVal(zeek::EnumType* etype) const;
/**
* Constructor.
@ -131,10 +132,10 @@ protected:
* @param subtype The sub type, which is left to an analyzer for
* interpretation. By default it's set to zero.
*/
Tag(const IntrusivePtr<EnumType>& etype, type_t type, subtype_t subtype = 0);
Tag(const IntrusivePtr<zeek::EnumType>& etype, type_t type, subtype_t subtype = 0);
[[deprecated("Remove in v4.1. Construct from IntrusivePtr& instead.")]]
Tag(EnumType* etype, type_t type, subtype_t subtype = 0);
Tag(zeek::EnumType* etype, type_t type, subtype_t subtype = 0);
/**
* Constructor.

View file

@ -6,9 +6,10 @@
class Func;
class Scope;
class Stmt;
class Expr;
class ID;
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
class TraversalCallback {
public:
@ -18,20 +19,20 @@ public:
virtual TraversalCode PreFunction(const Func*) { return TC_CONTINUE; }
virtual TraversalCode PostFunction(const Func*) { return TC_CONTINUE; }
virtual TraversalCode PreStmt(const Stmt*) { return TC_CONTINUE; }
virtual TraversalCode PostStmt(const Stmt*) { return TC_CONTINUE; }
virtual TraversalCode PreStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; }
virtual TraversalCode PostStmt(const zeek::detail::Stmt*) { return TC_CONTINUE; }
virtual TraversalCode PreExpr(const Expr*) { return TC_CONTINUE; }
virtual TraversalCode PostExpr(const Expr*) { return TC_CONTINUE; }
virtual TraversalCode PreExpr(const zeek::detail::Expr*) { return TC_CONTINUE; }
virtual TraversalCode PostExpr(const zeek::detail::Expr*) { return TC_CONTINUE; }
virtual TraversalCode PreID(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PostID(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PreID(const zeek::detail::ID*) { return TC_CONTINUE; }
virtual TraversalCode PostID(const zeek::detail::ID*) { return TC_CONTINUE; }
virtual TraversalCode PreTypedef(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PostTypedef(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PreTypedef(const zeek::detail::ID*) { return TC_CONTINUE; }
virtual TraversalCode PostTypedef(const zeek::detail::ID*) { return TC_CONTINUE; }
virtual TraversalCode PreDecl(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PostDecl(const ID*) { return TC_CONTINUE; }
virtual TraversalCode PreDecl(const zeek::detail::ID*) { return TC_CONTINUE; }
virtual TraversalCode PostDecl(const zeek::detail::ID*) { return TC_CONTINUE; }
Scope* current_scope;
};

View file

@ -15,12 +15,13 @@
#include "DebugLogger.h"
#include "iosource/Manager.h"
using namespace trigger;
using namespace zeek::detail;
using namespace zeek::detail::trigger;
// Callback class to traverse an expression, registering all relevant IDs and
// Vals for change notifications.
namespace trigger {
namespace zeek::detail::trigger {
class TriggerTraversalCallback : public TraversalCallback {
public:
@ -30,15 +31,13 @@ public:
~TriggerTraversalCallback()
{ Unref(trigger); }
virtual TraversalCode PreExpr(const Expr*);
virtual TraversalCode PreExpr(const zeek::detail::Expr*) override;
private:
Trigger* trigger;
};
}
TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr)
TraversalCode zeek::detail::trigger::TriggerTraversalCallback::PreExpr(const zeek::detail::Expr* expr)
{
// We catch all expressions here which in some way reference global
// state.
@ -46,7 +45,7 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr)
switch ( expr->Tag() ) {
case EXPR_NAME:
{
const NameExpr* e = static_cast<const NameExpr*>(expr);
const auto* e = static_cast<const zeek::detail::NameExpr*>(expr);
if ( e->Id()->IsGlobal() )
trigger->Register(e->Id());
@ -59,7 +58,7 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr)
case EXPR_INDEX:
{
const IndexExpr* e = static_cast<const IndexExpr*>(expr);
const auto* e = static_cast<const zeek::detail::IndexExpr*>(expr);
BroObj::SuppressErrors no_errors;
try
@ -83,8 +82,6 @@ TraversalCode TriggerTraversalCallback::PreExpr(const Expr* expr)
return TC_CONTINUE;
}
namespace trigger {
class TriggerTimer final : public Timer {
public:
TriggerTimer(double arg_timeout, Trigger* arg_trigger)
@ -120,10 +117,9 @@ protected:
double time;
};
}
Trigger::Trigger(Expr* arg_cond, Stmt* arg_body, Stmt* arg_timeout_stmts,
Expr* arg_timeout, Frame* arg_frame,
Trigger::Trigger(zeek::detail::Expr* arg_cond, zeek::detail::Stmt* arg_body,
zeek::detail::Stmt* arg_timeout_stmts,
zeek::detail::Expr* arg_timeout, Frame* arg_frame,
bool arg_is_return, const Location* arg_location)
{
cond = arg_cond;
@ -389,7 +385,7 @@ void Trigger::Timeout()
Unref(this);
}
void Trigger::Register(ID* id)
void Trigger::Register(zeek::detail::ID* id)
{
assert(! disabled);
notifier::registry.Register(id, this);
@ -440,7 +436,7 @@ void Trigger::Attach(Trigger *trigger)
Hold();
}
bool Trigger::Cache(const CallExpr* expr, Val* v)
bool Trigger::Cache(const zeek::detail::CallExpr* expr, Val* v)
{
if ( disabled || ! v )
return false;
@ -463,7 +459,7 @@ bool Trigger::Cache(const CallExpr* expr, Val* v)
}
Val* Trigger::Lookup(const CallExpr* expr)
Val* Trigger::Lookup(const zeek::detail::CallExpr* expr)
{
assert(! disabled);
@ -553,3 +549,5 @@ void Manager::GetStats(Stats* stats)
stats->total = total_triggers;
stats->pending = pending->size();
}
}

View file

@ -1,22 +1,25 @@
#pragma once
#include "Obj.h"
#include "Notifier.h"
#include "iosource/IOSource.h"
#include <list>
#include <vector>
#include <map>
class CallExpr;
class Expr;
class Stmt;
#include "Obj.h"
#include "Notifier.h"
#include "iosource/IOSource.h"
#include "util.h"
class Frame;
class Val;
class ID;
class ODesc;
namespace trigger {
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(CallExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail);
namespace zeek::detail::trigger {
// Triggers are the heart of "when" statements: expressions that when
// they become true execute a body of statements.
@ -29,7 +32,7 @@ public:
// instantiation. Note that if the condition is already true, the
// statements are executed immediately and the object is deleted
// right away.
Trigger(Expr* cond, Stmt* body, Stmt* timeout_stmts, Expr* timeout,
Trigger(zeek::detail::Expr* cond, zeek::detail::Stmt* body, zeek::detail::Stmt* timeout_stmts, zeek::detail::Expr* timeout,
Frame* f, bool is_return, const Location* loc);
~Trigger() override;
@ -60,8 +63,8 @@ public:
// Cache for return values of delayed function calls. Returns whether
// the trigger is queued for later evaluation -- it may not be queued
// if the Val is null or it's disabled.
bool Cache(const CallExpr* expr, Val* val);
Val* Lookup(const CallExpr*);
bool Cache(const zeek::detail::CallExpr* expr, Val* val);
Val* Lookup(const zeek::detail::CallExpr*);
// Disable this trigger completely. Needed because Unref'ing the trigger
// may not immediately delete it as other references may still exist.
@ -87,14 +90,14 @@ private:
friend class TriggerTimer;
void Init();
void Register(ID* id);
void Register(zeek::detail::ID* id);
void Register(Val* val);
void UnregisterAll();
Expr* cond;
Stmt* body;
Stmt* timeout_stmts;
Expr* timeout;
zeek::detail::Expr* cond;
zeek::detail::Stmt* body;
zeek::detail::Stmt* timeout_stmts;
zeek::detail::Expr* timeout;
double timeout_value;
Frame* frame;
bool is_return;
@ -108,7 +111,7 @@ private:
std::vector<std::pair<BroObj *, notifier::Modifiable*>> objs;
using ValCache = std::map<const CallExpr*, Val*>;
using ValCache = std::map<const zeek::detail::CallExpr*, Val*>;
ValCache cache;
};
@ -140,4 +143,9 @@ private:
}
extern trigger::Manager* trigger_mgr;
namespace trigger {
using Trigger [[deprecated("Remove in v4.1. Use zeek::detail::trigger::Trigger instead")]] = zeek::detail::trigger::Trigger;
using Manager [[deprecated("Remove in v4.1. Use zeek::detail::trigger::Manager instead")]] = zeek::detail::trigger::Manager;
}
extern zeek::detail::trigger::Manager* trigger_mgr;

View file

@ -3,14 +3,15 @@
#pragma once
#include "zeek-config.h"
#include <vector>
#include "IntrusivePtr.h"
#include "NetVar.h"
#include "IPAddr.h"
#include "ID.h"
#include "UID.h"
#include <vector>
class Connection;
/**
@ -198,7 +199,7 @@ public:
IntrusivePtr<VectorVal> ToVal() const
{
auto vv = make_intrusive<VectorVal>(
zeek::id::find_type<VectorType>("EncapsulatingConnVector"));
zeek::id::find_type<zeek::VectorType>("EncapsulatingConnVector"));
if ( conns )
{

View file

@ -22,10 +22,12 @@
using namespace std;
BroType::TypeAliasMap BroType::type_aliases;
namespace zeek {
Type::TypeAliasMap Type::type_aliases;
// Note: This function must be thread-safe.
const char* type_name(TypeTag t)
const char* type_name(zeek::TypeTag t)
{
static constexpr const char* type_names[int(NUM_TYPES)] = {
"void", // 0
@ -62,14 +64,14 @@ const char* type_name(TypeTag t)
return type_names[int(t)];
}
BroType::BroType(TypeTag t, bool arg_base_type)
Type::Type(zeek::TypeTag t, bool arg_base_type)
: tag(t), internal_tag(to_internal_type_tag(tag)),
is_network_order(::is_network_order(t)),
is_network_order(zeek::is_network_order(t)),
base_type(arg_base_type)
{
}
IntrusivePtr<BroType> BroType::ShallowClone()
IntrusivePtr<Type> Type::ShallowClone()
{
switch ( tag ) {
case TYPE_VOID:
@ -87,44 +89,44 @@ IntrusivePtr<BroType> BroType::ShallowClone()
case TYPE_ADDR:
case TYPE_SUBNET:
case TYPE_ANY:
return make_intrusive<BroType>(tag, base_type);
return make_intrusive<Type>(tag, base_type);
default:
reporter->InternalError("cloning illegal base BroType");
reporter->InternalError("cloning illegal base Type");
}
return nullptr;
}
int BroType::MatchesIndex(ListExpr* const index) const
int Type::MatchesIndex(zeek::detail::ListExpr* const index) const
{
if ( Tag() == TYPE_STRING )
{
if ( index->Exprs().length() != 1 && index->Exprs().length() != 2 )
return DOES_NOT_MATCH_INDEX;
if ( check_and_promote_exprs_to_type(index, ::base_type(TYPE_INT).get()) )
if ( check_and_promote_exprs_to_type(index, zeek::base_type(zeek::TYPE_INT).get()) )
return MATCHES_INDEX_SCALAR;
}
return DOES_NOT_MATCH_INDEX;
}
const IntrusivePtr<BroType>& BroType::Yield() const
const IntrusivePtr<Type>& Type::Yield() const
{
return BroType::nil;
return Type::nil;
}
bool BroType::HasField(const char* /* field */) const
bool Type::HasField(const char* /* field */) const
{
return false;
}
BroType* BroType::FieldType(const char* /* field */) const
Type* Type::FieldType(const char* /* field */) const
{
return nullptr;
}
void BroType::Describe(ODesc* d) const
void Type::Describe(ODesc* d) const
{
if ( d->IsBinary() )
d->Add(int(Tag()));
@ -138,22 +140,22 @@ void BroType::Describe(ODesc* d) const
}
}
void BroType::DescribeReST(ODesc* d, bool roles_only) const
void Type::DescribeReST(ODesc* d, bool roles_only) const
{
d->Add(fmt(":zeek:type:`%s`", type_name(Tag())));
}
void BroType::SetError()
void Type::SetError()
{
tag = TYPE_ERROR;
}
unsigned int BroType::MemoryAllocation() const
unsigned int Type::MemoryAllocation() const
{
return padded_sizeof(*this);
}
bool TypeList::AllMatch(const BroType* t, bool is_init) const
bool TypeList::AllMatch(const Type* t, bool is_init) const
{
for ( const auto& type : types )
if ( ! same_type(type, t, is_init) )
@ -161,7 +163,7 @@ bool TypeList::AllMatch(const BroType* t, bool is_init) const
return true;
}
void TypeList::Append(IntrusivePtr<BroType> t)
void TypeList::Append(IntrusivePtr<Type> t)
{
if ( pure_type && ! same_type(t, pure_type) )
reporter->InternalError("pure type-list violation");
@ -169,7 +171,7 @@ void TypeList::Append(IntrusivePtr<BroType> t)
types.emplace_back(std::move(t));
}
void TypeList::AppendEvenIfNotPure(IntrusivePtr<BroType> t)
void TypeList::AppendEvenIfNotPure(IntrusivePtr<Type> t)
{
if ( pure_type && ! same_type(t, pure_type) )
pure_type = nullptr;
@ -213,14 +215,14 @@ unsigned int TypeList::MemoryAllocation() const
size += pad_size(types.capacity() * sizeof(decltype(types)::value_type));
return BroType::MemoryAllocation()
+ padded_sizeof(*this) - padded_sizeof(BroType)
return Type::MemoryAllocation()
+ padded_sizeof(*this) - padded_sizeof(Type)
+ size;
}
IndexType::~IndexType() = default;
int IndexType::MatchesIndex(ListExpr* const index) const
int IndexType::MatchesIndex(zeek::detail::ListExpr* const index) const
{
// If we have a type indexed by subnets, addresses are ok.
const auto& types = indices->Types();
@ -236,7 +238,7 @@ int IndexType::MatchesIndex(ListExpr* const index) const
void IndexType::Describe(ODesc* d) const
{
BroType::Describe(d);
Type::Describe(d);
if ( ! d->IsBinary() )
d->Add("[");
@ -315,7 +317,7 @@ bool IndexType::IsSubNetIndex() const
return false;
}
TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield)
TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield)
: IndexType(TYPE_TABLE, std::move(ind), std::move(yield))
{
if ( ! indices )
@ -342,7 +344,7 @@ TableType::TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield)
}
}
IntrusivePtr<BroType> TableType::ShallowClone()
IntrusivePtr<Type> TableType::ShallowClone()
{
return make_intrusive<TableType>(indices, yield_type);
}
@ -353,7 +355,7 @@ bool TableType::IsUnspecifiedTable() const
return indices->Types().empty();
}
SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements)
SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements)
: TableType(std::move(ind), nullptr), elements(std::move(arg_elements))
{
if ( elements )
@ -376,7 +378,7 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements
else if ( tl.size() == 1 )
{
IntrusivePtr<BroType> ft{NewRef{}, flatten_type(tl[0].get())};
IntrusivePtr<Type> ft{NewRef{}, flatten_type(tl[0].get())};
indices = make_intrusive<TypeList>(ft);
indices->Append(std::move(ft));
}
@ -401,7 +403,7 @@ SetType::SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements
}
}
IntrusivePtr<BroType> SetType::ShallowClone()
IntrusivePtr<Type> SetType::ShallowClone()
{
return make_intrusive<SetType>(indices, elements);
}
@ -409,8 +411,8 @@ IntrusivePtr<BroType> SetType::ShallowClone()
SetType::~SetType() = default;
FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
IntrusivePtr<BroType> arg_yield, function_flavor arg_flavor)
: BroType(TYPE_FUNC), args(std::move(arg_args)),
IntrusivePtr<Type> arg_yield, FunctionFlavor arg_flavor)
: Type(TYPE_FUNC), args(std::move(arg_args)),
arg_types(make_intrusive<TypeList>()), yield(std::move(arg_yield))
{
flavor = arg_flavor;
@ -422,7 +424,7 @@ FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
{
const TypeDecl* td = args->FieldDecl(i);
if ( td->attrs && td->attrs->Find(ATTR_DEFAULT) )
if ( td->attrs && td->attrs->Find(zeek::detail::ATTR_DEFAULT) )
has_default_arg = true;
else if ( has_default_arg )
@ -439,7 +441,7 @@ FuncType::FuncType(IntrusivePtr<RecordType> arg_args,
prototypes.emplace_back(Prototype{false, args, std::move(offsets)});
}
IntrusivePtr<BroType> FuncType::ShallowClone()
IntrusivePtr<Type> FuncType::ShallowClone()
{
auto f = make_intrusive<FuncType>();
f->args = args;
@ -471,7 +473,7 @@ string FuncType::FlavorString() const
FuncType::~FuncType() = default;
int FuncType::MatchesIndex(ListExpr* const index) const
int FuncType::MatchesIndex(zeek::detail::ListExpr* const index) const
{
return check_and_promote_args(index, args.get()) ?
MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX;
@ -479,7 +481,7 @@ int FuncType::MatchesIndex(ListExpr* const index) const
bool FuncType::CheckArgs(const type_list* args, bool is_init) const
{
std::vector<IntrusivePtr<BroType>> as;
std::vector<IntrusivePtr<Type>> as;
as.reserve(args->length());
for ( auto a : *args )
@ -488,7 +490,7 @@ bool FuncType::CheckArgs(const type_list* args, bool is_init) const
return CheckArgs(as, is_init);
}
bool FuncType::CheckArgs(const std::vector<IntrusivePtr<BroType>>& args,
bool FuncType::CheckArgs(const std::vector<IntrusivePtr<Type>>& args,
bool is_init) const
{
const auto& my_args = arg_types->Types();
@ -607,8 +609,8 @@ std::optional<FuncType::Prototype> FuncType::FindPrototype(const RecordType& arg
return {};
}
TypeDecl::TypeDecl(const char* i, IntrusivePtr<BroType> t,
IntrusivePtr<Attributes> arg_attrs)
TypeDecl::TypeDecl(const char* i, IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> arg_attrs)
: type(std::move(t)),
attrs(std::move(arg_attrs)),
id(i)
@ -648,7 +650,7 @@ void TypeDecl::DescribeReST(ODesc* d, bool roles_only) const
}
}
RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD)
RecordType::RecordType(type_decl_list* arg_types) : Type(TYPE_RECORD)
{
types = arg_types;
num_fields = types ? types->length() : 0;
@ -656,7 +658,7 @@ RecordType::RecordType(type_decl_list* arg_types) : BroType(TYPE_RECORD)
// in this case the clone is actually not so shallow, since
// it gets modified by everyone.
IntrusivePtr<BroType> RecordType::ShallowClone()
IntrusivePtr<Type> RecordType::ShallowClone()
{
auto pass = new type_decl_list();
for ( const auto& type : *types )
@ -687,7 +689,7 @@ IntrusivePtr<Val> RecordType::FieldDefault(int field) const
if ( ! td->attrs )
return nullptr;
const auto& def_attr = td->attrs->Find(ATTR_DEFAULT);
const auto& def_attr = td->attrs->Find(zeek::detail::ATTR_DEFAULT);
return def_attr ? def_attr->GetExpr()->Eval(nullptr) : nullptr;
}
@ -758,7 +760,7 @@ void RecordType::DescribeReST(ODesc* d, bool roles_only) const
d->PopType(this);
}
static string container_type_name(const BroType* ft)
static string container_type_name(const Type* ft)
{
string s;
if ( ft->Tag() == TYPE_RECORD )
@ -807,7 +809,7 @@ IntrusivePtr<TableVal> RecordType::GetRecordFieldsVal(const RecordVal* rv) const
if ( rv )
fv = rv->GetField(i);
bool logged = (fd->attrs && fd->GetAttr(ATTR_LOG) != nullptr);
bool logged = (fd->attrs && fd->GetAttr(zeek::detail::ATTR_LOG) != nullptr);
auto nr = make_intrusive<RecordVal>(record_field);
@ -832,7 +834,7 @@ const char* RecordType::AddFields(const type_decl_list& others,
for ( const auto& td : others )
{
if ( ! td->GetAttr(ATTR_DEFAULT) && ! td->GetAttr(ATTR_OPTIONAL) )
if ( ! td->GetAttr(zeek::detail::ATTR_DEFAULT) && ! td->GetAttr(zeek::detail::ATTR_OPTIONAL) )
return "extension field must be &optional or have &default";
}
@ -843,9 +845,9 @@ const char* RecordType::AddFields(const type_decl_list& others,
if ( add_log_attr )
{
if ( ! td->attrs )
td->attrs = make_intrusive<Attributes>(td->type, true, false);
td->attrs = make_intrusive<zeek::detail::Attributes>(td->type, true, false);
td->attrs->AddAttr(make_intrusive<Attr>(ATTR_LOG));
td->attrs->AddAttr(make_intrusive<zeek::detail::Attr>(zeek::detail::ATTR_LOG));
}
types->push_back(td);
@ -993,9 +995,9 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const
if ( decl)
{
string result;
if ( const auto& deprecation = decl->GetAttr(ATTR_DEPRECATED) )
if ( const auto& deprecation = decl->GetAttr(zeek::detail::ATTR_DEPRECATED) )
{
auto expr = static_cast<ConstExpr*>(deprecation->GetExpr().get());
auto expr = static_cast<zeek::detail::ConstExpr*>(deprecation->GetExpr().get());
if ( expr )
{
StringVal* text = expr->Value()->AsStringVal();
@ -1014,7 +1016,7 @@ string RecordType::GetFieldDeprecationWarning(int field, bool has_check) const
return "";
}
SubNetType::SubNetType() : BroType(TYPE_SUBNET)
SubNetType::SubNetType() : Type(TYPE_SUBNET)
{
}
@ -1026,8 +1028,8 @@ void SubNetType::Describe(ODesc* d) const
d->Add(int(Tag()));
}
FileType::FileType(IntrusivePtr<BroType> yield_type)
: BroType(TYPE_FILE), yield(std::move(yield_type))
FileType::FileType(IntrusivePtr<Type> yield_type)
: Type(TYPE_FILE), yield(std::move(yield_type))
{
}
@ -1047,7 +1049,7 @@ void FileType::Describe(ODesc* d) const
}
}
OpaqueType::OpaqueType(const string& arg_name) : BroType(TYPE_OPAQUE)
OpaqueType::OpaqueType(const string& arg_name) : Type(TYPE_OPAQUE)
{
name = arg_name;
}
@ -1068,20 +1070,20 @@ void OpaqueType::DescribeReST(ODesc* d, bool roles_only) const
}
EnumType::EnumType(const string& name)
: BroType(TYPE_ENUM)
: Type(TYPE_ENUM)
{
counter = 0;
SetName(name);
}
EnumType::EnumType(const EnumType* e)
: BroType(TYPE_ENUM), names(e->names), vals(e->vals)
: Type(TYPE_ENUM), names(e->names), vals(e->vals)
{
counter = e->counter;
SetName(e->GetName());
}
IntrusivePtr<BroType> EnumType::ShallowClone()
IntrusivePtr<Type> EnumType::ShallowClone()
{
if ( counter == 0 )
return make_intrusive<EnumType>(GetName());
@ -1094,7 +1096,7 @@ EnumType::~EnumType() = default;
// Note, we use reporter->Error() here (not Error()) to include the current script
// location in the error message, rather than the one where the type was
// originally defined.
void EnumType::AddName(const string& module_name, const char* name, bool is_export, Expr* deprecation)
void EnumType::AddName(const string& module_name, const char* name, bool is_export, zeek::detail::Expr* deprecation)
{
/* implicit, auto-increment */
if ( counter < 0)
@ -1107,7 +1109,7 @@ void EnumType::AddName(const string& module_name, const char* name, bool is_expo
counter++;
}
void EnumType::AddName(const string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation)
void EnumType::AddName(const string& module_name, const char* name, bro_int_t val, bool is_export, zeek::detail::Expr* deprecation)
{
/* explicit value specified */
if ( counter > 0 )
@ -1121,7 +1123,7 @@ void EnumType::AddName(const string& module_name, const char* name, bro_int_t va
}
void EnumType::CheckAndAddName(const string& module_name, const char* name,
bro_int_t val, bool is_export, Expr* deprecation)
bro_int_t val, bool is_export, zeek::detail::Expr* deprecation)
{
if ( Lookup(val) )
{
@ -1164,8 +1166,8 @@ void EnumType::CheckAndAddName(const string& module_name, const char* name,
if ( vals.find(val) == vals.end() )
vals[val] = make_intrusive<EnumVal>(IntrusivePtr{NewRef{}, this}, val);
set<BroType*> types = BroType::GetAliases(GetName());
set<BroType*>::const_iterator it;
set<Type*> types = Type::GetAliases(GetName());
set<Type*>::const_iterator it;
for ( it = types.begin(); it != types.end(); ++it )
if ( *it != this )
@ -1301,31 +1303,31 @@ void EnumType::DescribeReST(ODesc* d, bool roles_only) const
}
}
VectorType::VectorType(IntrusivePtr<BroType> element_type)
: BroType(TYPE_VECTOR), yield_type(std::move(element_type))
VectorType::VectorType(IntrusivePtr<Type> element_type)
: Type(TYPE_VECTOR), yield_type(std::move(element_type))
{
}
IntrusivePtr<BroType> VectorType::ShallowClone()
IntrusivePtr<Type> VectorType::ShallowClone()
{
return make_intrusive<VectorType>(yield_type);
}
VectorType::~VectorType() = default;
const IntrusivePtr<BroType>& VectorType::Yield() const
const IntrusivePtr<Type>& VectorType::Yield() const
{
// Work around the fact that we use void internally to mark a vector
// as being unspecified. When looking at its yield type, we need to
// return any as that's what other code historically expects for type
// comparisions.
if ( IsUnspecifiedVector() )
return ::base_type(TYPE_ANY);
return zeek::base_type(zeek::TYPE_ANY);
return yield_type;
}
int VectorType::MatchesIndex(ListExpr* const index) const
int VectorType::MatchesIndex(zeek::detail::ListExpr* const index) const
{
expr_list& el = index->Exprs();
@ -1369,28 +1371,12 @@ void VectorType::DescribeReST(ODesc* d, bool roles_only) const
d->Add(fmt(":zeek:type:`%s`", yield_type->GetName().c_str()));
}
const IntrusivePtr<BroType>& base_type(TypeTag tag)
{
static IntrusivePtr<BroType> base_types[NUM_TYPES];
// We could check here that "tag" actually corresponds to a basic type.
if ( ! base_types[tag] )
{
base_types[tag] = make_intrusive<BroType>(tag, true);
// Give the base types a pseudo-location for easier identification.
Location l(type_name(tag), 0, 0, 0, 0);
base_types[tag]->SetLocationInfo(&l);
}
return base_types[tag];
}
// Returns true if t1 is initialization-compatible with t2 (i.e., if an
// initializer with type t1 can be used to initialize a value with type t2),
// false otherwise. Assumes that t1's tag is different from t2's. Note
// that the test is in only one direction - we don't check whether t2 is
// initialization-compatible with t1.
static bool is_init_compat(const BroType& t1, const BroType& t2)
static bool is_init_compat(const Type& t1, const Type& t2)
{
if ( t1.Tag() == TYPE_LIST )
{
@ -1406,7 +1392,7 @@ static bool is_init_compat(const BroType& t1, const BroType& t2)
return false;
}
bool same_type(const BroType& arg_t1, const BroType& arg_t2,
bool same_type(const Type& arg_t1, const Type& arg_t2,
bool is_init, bool match_record_field_names)
{
if ( &arg_t1 == &arg_t2 ||
@ -1559,7 +1545,7 @@ bool same_type(const BroType& arg_t1, const BroType& arg_t2,
return false;
}
bool same_attrs(const Attributes* a1, const Attributes* a2)
bool same_attrs(const zeek::detail::Attributes* a1, const zeek::detail::Attributes* a2)
{
if ( ! a1 )
return (a2 == nullptr);
@ -1601,7 +1587,7 @@ bool record_promotion_compatible(const RecordType* super_rec,
return true;
}
const BroType* flatten_type(const BroType* t)
const Type* flatten_type(const Type* t)
{
if ( t->Tag() != TYPE_LIST )
return t;
@ -1624,9 +1610,9 @@ const BroType* flatten_type(const BroType* t)
return t;
}
BroType* flatten_type(BroType* t)
Type* flatten_type(Type* t)
{
return (BroType*) flatten_type((const BroType*) t);
return (Type*) flatten_type((const Type*) t);
}
bool is_assignable(TypeTag t)
@ -1698,8 +1684,8 @@ TypeTag max_type(TypeTag t1, TypeTag t2)
}
}
IntrusivePtr<BroType> merge_types(const IntrusivePtr<BroType>& arg_t1,
const IntrusivePtr<BroType>& arg_t2)
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& arg_t1,
const IntrusivePtr<Type>& arg_t2)
{
auto t1 = arg_t1.get();
auto t2 = arg_t2.get();
@ -1793,7 +1779,7 @@ IntrusivePtr<BroType> merge_types(const IntrusivePtr<BroType>& arg_t1,
const auto& y1 = t1->Yield();
const auto& y2 = t2->Yield();
IntrusivePtr<BroType> y3;
IntrusivePtr<Type> y3;
if ( y1 || y2 )
{
@ -1938,7 +1924,7 @@ IntrusivePtr<BroType> merge_types(const IntrusivePtr<BroType>& arg_t1,
}
}
IntrusivePtr<BroType> merge_type_list(ListExpr* elements)
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements)
{
TypeList* tl_type = elements->GetType()->AsTypeList();
const auto& tl = tl_type->Types();
@ -1964,7 +1950,7 @@ IntrusivePtr<BroType> merge_type_list(ListExpr* elements)
}
// Reduces an aggregate type.
static BroType* reduce_type(BroType* t)
static Type* reduce_type(Type* t)
{
if ( t->Tag() == TYPE_LIST )
return flatten_type(t);
@ -1983,9 +1969,9 @@ static BroType* reduce_type(BroType* t)
return t;
}
IntrusivePtr<BroType> init_type(Expr* init)
IntrusivePtr<Type> init_type(zeek::detail::Expr* init)
{
if ( init->Tag() != EXPR_LIST )
if ( init->Tag() != zeek::detail::EXPR_LIST )
{
auto t = init->InitType();
@ -2002,7 +1988,7 @@ IntrusivePtr<BroType> init_type(Expr* init)
return t;
}
ListExpr* init_list = init->AsListExpr();
zeek::detail::ListExpr* init_list = init->AsListExpr();
const expr_list& el = init_list->Exprs();
if ( el.length() == 0 )
@ -2012,7 +1998,7 @@ IntrusivePtr<BroType> init_type(Expr* init)
}
// Could be a record, a set, or a list of table elements.
Expr* e0 = el[0];
zeek::detail::Expr* e0 = el[0];
if ( e0->IsRecordElement(nullptr) )
// ListExpr's know how to build a record from their
@ -2030,7 +2016,7 @@ IntrusivePtr<BroType> init_type(Expr* init)
for ( int i = 1; t && i < el.length(); ++i )
{
auto el_t = el[i]->InitType();
IntrusivePtr<BroType> ti;
IntrusivePtr<Type> ti;
if ( el_t )
ti = {NewRef{}, reduce_type(el_t.get())};
@ -2067,7 +2053,7 @@ IntrusivePtr<BroType> init_type(Expr* init)
nullptr);
}
bool is_atomic_type(const BroType& t)
bool is_atomic_type(const Type& t)
{
switch ( t.InternalType() ) {
case TYPE_INTERNAL_INT:
@ -2081,3 +2067,22 @@ bool is_atomic_type(const BroType& t)
return false;
}
}
const IntrusivePtr<Type>& base_type(zeek::TypeTag tag)
{
static IntrusivePtr<Type> base_types[NUM_TYPES];
// We could check here that "tag" actually corresponds to a basic type.
if ( ! base_types[tag] )
{
base_types[tag] = make_intrusive<Type>(tag, true);
// Give the base types a pseudo-location for easier identification.
Location l(type_name(tag), 0, 0, 0, 0);
base_types[tag]->SetLocationInfo(&l);
}
return base_types[tag];
}
} // namespace zeek

View file

@ -14,8 +14,59 @@
#include <list>
#include <optional>
// BRO types.
class EnumVal;
class TableVal;
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(ListExpr, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Attributes, zeek::detail);
enum [[deprecated("Remove in v4.1. Use zeek::TypeTag instead.")]] TypeTag {
TYPE_VOID, // 0
TYPE_BOOL, // 1
TYPE_INT, // 2
TYPE_COUNT, // 3
TYPE_COUNTER, // 4
TYPE_DOUBLE, // 5
TYPE_TIME, // 6
TYPE_INTERVAL, // 7
TYPE_STRING, // 8
TYPE_PATTERN, // 9
TYPE_ENUM, // 10
TYPE_TIMER, // 11
TYPE_PORT, // 12
TYPE_ADDR, // 13
TYPE_SUBNET, // 14
TYPE_ANY, // 15
TYPE_TABLE, // 16
TYPE_UNION, // 17
TYPE_RECORD, // 18
TYPE_LIST, // 19
TYPE_FUNC, // 20
TYPE_FILE, // 21
TYPE_VECTOR, // 22
TYPE_OPAQUE, // 23
TYPE_TYPE, // 24
TYPE_ERROR // 25
#define NUM_TYPES (int(TYPE_ERROR) + 1)
};
enum [[deprecated("Remove in v4.1. Use zeek::FunctionFlavor instead.")]] function_flavor {
FUNC_FLAVOR_FUNCTION,
FUNC_FLAVOR_EVENT,
FUNC_FLAVOR_HOOK
};
enum [[deprecated("Remove in v4.1. Use zeek::InternalTypeTag instead.")]] InternalTypeTag : uint16_t {
TYPE_INTERNAL_VOID,
TYPE_INTERNAL_INT, TYPE_INTERNAL_UNSIGNED, TYPE_INTERNAL_DOUBLE,
TYPE_INTERNAL_STRING, TYPE_INTERNAL_ADDR, TYPE_INTERNAL_SUBNET,
TYPE_INTERNAL_OTHER, TYPE_INTERNAL_ERROR
};
namespace zeek {
// BRO types.
enum TypeTag {
TYPE_VOID, // 0
TYPE_BOOL, // 1
@ -46,12 +97,15 @@ enum TypeTag {
#define NUM_TYPES (int(TYPE_ERROR) + 1)
};
// Returns the name of the type.
extern const char* type_name(TypeTag t);
constexpr bool is_network_order(TypeTag tag) noexcept
{
return tag == TYPE_PORT;
}
enum function_flavor {
enum FunctionFlavor {
FUNC_FLAVOR_FUNCTION,
FUNC_FLAVOR_EVENT,
FUNC_FLAVOR_HOOK
@ -116,34 +170,34 @@ constexpr InternalTypeTag to_internal_type_tag(TypeTag tag) noexcept
return TYPE_INTERNAL_VOID;
}
// Returns the name of the type.
extern const char* type_name(TypeTag t);
class Expr;
class Attributes;
class TypeList;
class TableType;
class SetType;
class RecordType;
class SubNetType;
class FuncType;
class ListExpr;
class EnumType;
class VectorType;
class TypeType;
class OpaqueType;
class EnumVal;
class TableVal;
const int DOES_NOT_MATCH_INDEX = 0;
const int MATCHES_INDEX_SCALAR = 1;
const int MATCHES_INDEX_VECTOR = 2;
constexpr int DOES_NOT_MATCH_INDEX = 0;
constexpr int MATCHES_INDEX_SCALAR = 1;
constexpr int MATCHES_INDEX_VECTOR = 2;
class BroType : public BroObj {
class Type : public BroObj {
public:
static inline const IntrusivePtr<BroType> nil;
static inline const IntrusivePtr<Type> nil;
explicit BroType(TypeTag tag, bool base_type = false);
explicit Type(zeek::TypeTag tag, bool base_type = false);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag instead.")]]
explicit Type(::TypeTag tag, bool base_type = false)
: Type(static_cast<zeek::TypeTag>(tag), base_type)
{}
#pragma GCC diagnostic pop
// Performs a shallow clone operation of the Bro type.
// This especially means that especially for tables the types
@ -153,7 +207,7 @@ public:
// Clone operations will mostly be implemented in the derived classes;
// in addition cloning will be limited to classes that can be reached by
// the script-level.
virtual IntrusivePtr<BroType> ShallowClone();
virtual IntrusivePtr<Type> ShallowClone();
TypeTag Tag() const { return tag; }
InternalTypeTag InternalType() const { return internal_tag; }
@ -168,18 +222,18 @@ public:
// if it matches and produces a vector result; and
// DOES_NOT_MATCH_INDEX = 0 if it can't match (or the type
// is not an indexable type).
virtual int MatchesIndex(ListExpr* index) const;
virtual int MatchesIndex(zeek::detail::ListExpr* index) const;
// Returns the type yielded by this type. For example, if
// this type is a table[string] of port, then returns the "port"
// type. Returns nil if this is not an index type.
virtual const IntrusivePtr<BroType>& Yield() const;
virtual const IntrusivePtr<Type>& Yield() const;
[[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual BroType* YieldType()
virtual Type* YieldType()
{ return Yield().get(); }
[[deprecated("Remove in v4.1. Use Yield() instead.")]]
virtual const BroType* YieldType() const
virtual const Type* YieldType() const
{ return Yield().get(); }
// Returns true if this type is a record and contains the
@ -189,126 +243,126 @@ public:
// Returns the type of the given field, or nil if no such field.
[[deprecated("Remove in v4.1. Use RecordType::GetFieldType() directly.")]]
virtual BroType* FieldType(const char* field) const;
virtual Type* FieldType(const char* field) const;
#define CHECK_TYPE_TAG(tag_type, func_name) \
CHECK_TAG(tag, tag_type, func_name, type_name)
const TypeList* AsTypeList() const
{
CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList");
CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList");
return (const TypeList*) this;
}
TypeList* AsTypeList()
{
CHECK_TYPE_TAG(TYPE_LIST, "BroType::AsTypeList");
CHECK_TYPE_TAG(TYPE_LIST, "Type::AsTypeList");
return (TypeList*) this;
}
const TableType* AsTableType() const
{
CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType");
CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType");
return (const TableType*) this;
}
TableType* AsTableType()
{
CHECK_TYPE_TAG(TYPE_TABLE, "BroType::AsTableType");
CHECK_TYPE_TAG(TYPE_TABLE, "Type::AsTableType");
return (TableType*) this;
}
SetType* AsSetType()
{
if ( ! IsSet() )
BadTag("BroType::AsSetType", type_name(tag));
BadTag("Type::AsSetType", type_name(tag));
return (SetType*) this;
}
const SetType* AsSetType() const
{
if ( ! IsSet() )
BadTag("BroType::AsSetType", type_name(tag));
BadTag("Type::AsSetType", type_name(tag));
return (const SetType*) this;
}
const RecordType* AsRecordType() const
{
CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType");
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
return (const RecordType*) this;
}
RecordType* AsRecordType()
{
CHECK_TYPE_TAG(TYPE_RECORD, "BroType::AsRecordType");
CHECK_TYPE_TAG(TYPE_RECORD, "Type::AsRecordType");
return (RecordType*) this;
}
const SubNetType* AsSubNetType() const
{
CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType");
CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType");
return (const SubNetType*) this;
}
SubNetType* AsSubNetType()
{
CHECK_TYPE_TAG(TYPE_SUBNET, "BroType::AsSubNetType");
CHECK_TYPE_TAG(TYPE_SUBNET, "Type::AsSubNetType");
return (SubNetType*) this;
}
const FuncType* AsFuncType() const
{
CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType");
CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType");
return (const FuncType*) this;
}
FuncType* AsFuncType()
{
CHECK_TYPE_TAG(TYPE_FUNC, "BroType::AsFuncType");
CHECK_TYPE_TAG(TYPE_FUNC, "Type::AsFuncType");
return (FuncType*) this;
}
const EnumType* AsEnumType() const
{
CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType");
CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType");
return (EnumType*) this;
}
EnumType* AsEnumType()
{
CHECK_TYPE_TAG(TYPE_ENUM, "BroType::AsEnumType");
CHECK_TYPE_TAG(TYPE_ENUM, "Type::AsEnumType");
return (EnumType*) this;
}
const VectorType* AsVectorType() const
{
CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType");
CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType");
return (VectorType*) this;
}
OpaqueType* AsOpaqueType()
{
CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType");
CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType");
return (OpaqueType*) this;
}
const OpaqueType* AsOpaqueType() const
{
CHECK_TYPE_TAG(TYPE_OPAQUE, "BroType::AsOpaqueType");
CHECK_TYPE_TAG(TYPE_OPAQUE, "Type::AsOpaqueType");
return (OpaqueType*) this;
}
VectorType* AsVectorType()
{
CHECK_TYPE_TAG(TYPE_VECTOR, "BroType::AsVectorType");
CHECK_TYPE_TAG(TYPE_VECTOR, "Type::AsVectorType");
return (VectorType*) this;
}
const TypeType* AsTypeType() const
{
CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType");
CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType");
return (TypeType*) this;
}
TypeType* AsTypeType()
{
CHECK_TYPE_TAG(TYPE_TYPE, "BroType::AsTypeType");
CHECK_TYPE_TAG(TYPE_TYPE, "Type::AsTypeType");
return (TypeType*) this;
}
@ -322,7 +376,7 @@ public:
return tag == TYPE_TABLE && Yield();
}
BroType* Ref() { ::Ref(this); return this; }
Type* Ref() { ::Ref(this); return this; }
void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d, bool roles_only = false) const;
@ -332,16 +386,16 @@ public:
void SetName(const std::string& arg_name) { name = arg_name; }
const std::string& GetName() const { return name; }
typedef std::map<std::string, std::set<BroType*> > TypeAliasMap;
typedef std::map<std::string, std::set<Type*> > TypeAliasMap;
static std::set<BroType*> GetAliases(const std::string& type_name)
{ return BroType::type_aliases[type_name]; }
static std::set<Type*> GetAliases(const std::string& type_name)
{ return Type::type_aliases[type_name]; }
static void AddAlias(const std::string &type_name, BroType* type)
{ BroType::type_aliases[type_name].insert(type); }
static void AddAlias(const std::string &type_name, Type* type)
{ Type::type_aliases[type_name].insert(type); }
protected:
BroType() { }
Type() = default;
void SetError();
@ -355,50 +409,50 @@ private:
static TypeAliasMap type_aliases;
};
class TypeList final : public BroType {
class TypeList final : public Type {
public:
explicit TypeList(IntrusivePtr<BroType> arg_pure_type = nullptr)
: BroType(TYPE_LIST), pure_type(std::move(arg_pure_type))
explicit TypeList(IntrusivePtr<Type> arg_pure_type = nullptr)
: Type(TYPE_LIST), pure_type(std::move(arg_pure_type))
{
}
const std::vector<IntrusivePtr<BroType>>& Types() const
const std::vector<IntrusivePtr<Type>>& Types() const
{ return types; }
bool IsPure() const { return pure_type != nullptr; }
// Returns the underlying pure type, or nil if the list
// is not pure or is empty.
const IntrusivePtr<BroType>& GetPureType() const
const IntrusivePtr<Type>& GetPureType() const
{ return pure_type; }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
BroType* PureType() { return pure_type.get(); }
Type* PureType() { return pure_type.get(); }
[[deprecated("Remove in v4.1. Use GetPureType() instead.")]]
const BroType* PureType() const { return pure_type.get(); }
const Type* PureType() const { return pure_type.get(); }
// True if all of the types match t, false otherwise. If
// is_init is true, then the matching is done in the context
// of an initialization.
bool AllMatch(const BroType* t, bool is_init) const;
bool AllMatch(const IntrusivePtr<BroType>& t, bool is_init) const
bool AllMatch(const Type* t, bool is_init) const;
bool AllMatch(const IntrusivePtr<Type>& t, bool is_init) const
{ return AllMatch(t.get(), is_init); }
void Append(IntrusivePtr<BroType> t);
void AppendEvenIfNotPure(IntrusivePtr<BroType> t);
void Append(IntrusivePtr<Type> t);
void AppendEvenIfNotPure(IntrusivePtr<Type> t);
void Describe(ODesc* d) const override;
unsigned int MemoryAllocation() const override;
protected:
IntrusivePtr<BroType> pure_type;
std::vector<IntrusivePtr<BroType>> types;
IntrusivePtr<Type> pure_type;
std::vector<IntrusivePtr<Type>> types;
};
class IndexType : public BroType {
class IndexType : public Type {
public:
int MatchesIndex(ListExpr* index) const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override;
const IntrusivePtr<TypeList>& GetIndices() const
{ return indices; }
@ -406,10 +460,10 @@ public:
[[deprecated("Remove in v4.1. Use GetIndices().")]]
TypeList* Indices() const { return indices.get(); }
const std::vector<IntrusivePtr<BroType>>& IndexTypes() const
const std::vector<IntrusivePtr<Type>>& IndexTypes() const
{ return indices->Types(); }
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield_type; }
void Describe(ODesc* d) const override;
@ -420,8 +474,8 @@ public:
protected:
IndexType(TypeTag t, IntrusivePtr<TypeList> arg_indices,
IntrusivePtr<BroType> arg_yield_type)
: BroType(t), indices(std::move(arg_indices)),
IntrusivePtr<Type> arg_yield_type)
: Type(t), indices(std::move(arg_indices)),
yield_type(std::move(arg_yield_type))
{
}
@ -429,14 +483,14 @@ protected:
~IndexType() override;
IntrusivePtr<TypeList> indices;
IntrusivePtr<BroType> yield_type;
IntrusivePtr<Type> yield_type;
};
class TableType : public IndexType {
public:
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<BroType> yield);
TableType(IntrusivePtr<TypeList> ind, IntrusivePtr<Type> yield);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
// Returns true if this table type is "unspecified", which is
// what one gets using an empty "set()" or "table()" constructor.
@ -445,22 +499,22 @@ public:
class SetType final : public TableType {
public:
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<ListExpr> arg_elements);
SetType(IntrusivePtr<TypeList> ind, IntrusivePtr<zeek::detail::ListExpr> arg_elements);
~SetType() override;
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
[[deprecated("Remove in v4.1. Use Elements() isntead.")]]
ListExpr* SetElements() const { return elements.get(); }
zeek::detail::ListExpr* SetElements() const { return elements.get(); }
const IntrusivePtr<ListExpr>& Elements() const
const IntrusivePtr<zeek::detail::ListExpr>& Elements() const
{ return elements; }
protected:
IntrusivePtr<ListExpr> elements;
IntrusivePtr<zeek::detail::ListExpr> elements;
};
class FuncType final : public BroType {
class FuncType final : public Type {
public:
static inline const IntrusivePtr<FuncType> nil;
@ -475,9 +529,18 @@ public:
std::map<int, int> offsets;
};
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<BroType> yield,
function_flavor f);
IntrusivePtr<BroType> ShallowClone() override;
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<Type> yield,
FunctionFlavor f);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]]
FuncType(IntrusivePtr<RecordType> args, IntrusivePtr<Type> yield, ::function_flavor f)
: FuncType(args, yield, static_cast<FunctionFlavor>(f))
{}
#pragma GCC diagnostic pop
IntrusivePtr<Type> ShallowClone() override;
~FuncType() override;
@ -487,20 +550,27 @@ public:
const IntrusivePtr<RecordType>& Params() const
{ return args; }
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield; }
void SetYieldType(IntrusivePtr<BroType> arg_yield) { yield = std::move(arg_yield); }
function_flavor Flavor() const { return flavor; }
void SetYieldType(IntrusivePtr<Type> arg_yield) { yield = std::move(arg_yield); }
FunctionFlavor Flavor() const { return flavor; }
std::string FlavorString() const;
// Used to convert a function type to an event or hook type.
void ClearYieldType(function_flavor arg_flav)
void ClearYieldType(FunctionFlavor arg_flav)
{ yield = nullptr; flavor = arg_flav; }
int MatchesIndex(ListExpr* index) const override;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::FunctionFlavor instead.")]]
void ClearYieldType(::function_flavor arg_flav)
{ yield = nullptr; flavor = static_cast<FunctionFlavor>(arg_flav); }
#pragma GCC diagnostic pop
int MatchesIndex(zeek::detail::ListExpr* index) const override;
bool CheckArgs(const type_list* args, bool is_init = false) const;
bool CheckArgs(const std::vector<IntrusivePtr<BroType>>& args,
bool CheckArgs(const std::vector<IntrusivePtr<Type>>& args,
bool is_init = false) const;
[[deprecated("Remove in v4.1. Use ParamList().")]]
@ -531,20 +601,20 @@ public:
protected:
friend IntrusivePtr<FuncType> make_intrusive<FuncType>();
FuncType() : BroType(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
FuncType() : Type(TYPE_FUNC) { flavor = FUNC_FLAVOR_FUNCTION; }
IntrusivePtr<RecordType> args;
IntrusivePtr<TypeList> arg_types;
IntrusivePtr<BroType> yield;
function_flavor flavor;
IntrusivePtr<Type> yield;
FunctionFlavor flavor;
std::vector<Prototype> prototypes;
};
class TypeType final : public BroType {
class TypeType final : public Type {
public:
explicit TypeType(IntrusivePtr<BroType> t) : BroType(TYPE_TYPE), type(std::move(t)) {}
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<TypeType>(type); }
explicit TypeType(IntrusivePtr<Type> t) : zeek::Type(TYPE_TYPE), type(std::move(t)) {}
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<TypeType>(type); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<Type>& GetType() const
{ return type; }
template <class T>
@ -552,62 +622,66 @@ public:
{ return cast_intrusive<T>(type); }
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() { return type.get(); }
zeek::Type* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
const BroType* Type() const { return type.get(); }
const zeek::Type* Type() const { return type.get(); }
protected:
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
};
class TypeDecl final {
public:
TypeDecl() = default;
TypeDecl(const char* i, IntrusivePtr<BroType> t, IntrusivePtr<Attributes> attrs = nullptr);
TypeDecl(const char* i, IntrusivePtr<Type> t,
IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
TypeDecl(const TypeDecl& other);
~TypeDecl();
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use GetAttr().")]]
const Attr* FindAttr(attr_tag a) const
{ return attrs ? attrs->Find(a).get() : nullptr; }
const zeek::detail::Attr* FindAttr(::attr_tag a) const
{ return attrs ? attrs->Find(static_cast<zeek::detail::attr_tag>(a)).get() : nullptr; }
#pragma GCC diagnostic pop
const IntrusivePtr<Attr>& GetAttr(attr_tag a) const
{ return attrs ? attrs->Find(a) : Attr::nil; }
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::attr_tag a) const
{ return attrs ? attrs->Find(a) : zeek::detail::Attr::nil; }
void DescribeReST(ODesc* d, bool roles_only = false) const;
IntrusivePtr<BroType> type;
IntrusivePtr<Attributes> attrs;
IntrusivePtr<Type> type;
IntrusivePtr<zeek::detail::Attributes> attrs;
const char* id = nullptr;
};
typedef PList<TypeDecl> type_decl_list;
using type_decl_list = PList<TypeDecl>;
class RecordType final : public BroType {
class RecordType final : public Type {
public:
explicit RecordType(type_decl_list* types);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
~RecordType() override;
bool HasField(const char* field) const override;
[[deprecated("Remove in v4.1. Use GetFieldType() instead (note it doesn't check for invalid names).")]]
BroType* FieldType(const char* field) const override
Type* FieldType(const char* field) const override
{
auto offset = FieldOffset(field);
return offset >= 0 ? GetFieldType(offset).get() : nullptr;
}
[[deprecated("Remove in v4.1. Use GetFieldType() instead.")]]
BroType* FieldType(int field) const
Type* FieldType(int field) const
{ return GetFieldType(field).get(); }
/**
* Looks up a field by name and returns its type. No check for invalid
* field name is performed.
*/
const IntrusivePtr<BroType>& GetFieldType(const char* field_name) const
const IntrusivePtr<Type>& GetFieldType(const char* field_name) const
{ return GetFieldType(FieldOffset(field_name)); }
/**
@ -622,7 +696,7 @@ public:
* Looks up a field by its index and returns its type. No check for
* invalid field offset is performed.
*/
const IntrusivePtr<BroType>& GetFieldType(int field_index) const
const IntrusivePtr<Type>& GetFieldType(int field_index) const
{ return (*types)[field_index]->type; }
/**
@ -669,15 +743,24 @@ public:
bool IsFieldDeprecated(int field) const
{
const TypeDecl* decl = FieldDecl(field);
return decl && decl->GetAttr(ATTR_DEPRECATED) != nullptr;
return decl && decl->GetAttr(zeek::detail::ATTR_DEPRECATED) != nullptr;
}
bool FieldHasAttr(int field, attr_tag at) const
bool FieldHasAttr(int field, zeek::detail::attr_tag at) const
{
const TypeDecl* decl = FieldDecl(field);
return decl && decl->GetAttr(at) != nullptr;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
bool FieldHasAttr(int field, ::attr_tag at) const
{
return FieldHasAttr(field, static_cast<zeek::detail::attr_tag>(at));
}
#pragma GCC diagnostic pop
std::string GetFieldDeprecationWarning(int field, bool has_check) const;
protected:
@ -687,31 +770,31 @@ protected:
type_decl_list* types;
};
class SubNetType final : public BroType {
class SubNetType final : public Type {
public:
SubNetType();
void Describe(ODesc* d) const override;
};
class FileType final : public BroType {
class FileType final : public Type {
public:
explicit FileType(IntrusivePtr<BroType> yield_type);
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<FileType>(yield); }
explicit FileType(IntrusivePtr<Type> yield_type);
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<FileType>(yield); }
~FileType() override;
const IntrusivePtr<BroType>& Yield() const override
const IntrusivePtr<Type>& Yield() const override
{ return yield; }
void Describe(ODesc* d) const override;
protected:
IntrusivePtr<BroType> yield;
IntrusivePtr<Type> yield;
};
class OpaqueType final : public BroType {
class OpaqueType final : public Type {
public:
explicit OpaqueType(const std::string& name);
IntrusivePtr<BroType> ShallowClone() override { return make_intrusive<OpaqueType>(name); }
IntrusivePtr<Type> ShallowClone() override { return make_intrusive<OpaqueType>(name); }
~OpaqueType() override { };
const std::string& Name() const { return name; }
@ -725,23 +808,23 @@ protected:
std::string name;
};
class EnumType final : public BroType {
class EnumType final : public Type {
public:
typedef std::list<std::pair<std::string, bro_int_t> > enum_name_list;
explicit EnumType(const EnumType* e);
explicit EnumType(const std::string& arg_name);
IntrusivePtr<BroType> ShallowClone() override;
IntrusivePtr<Type> ShallowClone() override;
~EnumType() override;
// The value of this name is next internal counter value, starting
// with zero. The internal counter is incremented.
void AddName(const std::string& module_name, const char* name, bool is_export, Expr* deprecation = nullptr);
void AddName(const std::string& module_name, const char* name, bool is_export, zeek::detail::Expr* deprecation = nullptr);
// The value of this name is set to val. Once a value has been
// explicitly assigned using this method, no further names can be
// added that aren't likewise explicitly initalized.
void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr);
void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, zeek::detail::Expr* deprecation = nullptr);
// -1 indicates not found.
bro_int_t Lookup(const std::string& module_name, const char* name) const;
@ -761,7 +844,7 @@ protected:
void CheckAndAddName(const std::string& module_name,
const char* name, bro_int_t val, bool is_export,
Expr* deprecation = nullptr);
zeek::detail::Expr* deprecation = nullptr);
typedef std::map<std::string, bro_int_t> NameMap;
NameMap names;
@ -778,15 +861,15 @@ protected:
bro_int_t counter;
};
class VectorType final : public BroType {
class VectorType final : public Type {
public:
explicit VectorType(IntrusivePtr<BroType> t);
IntrusivePtr<BroType> ShallowClone() override;
explicit VectorType(IntrusivePtr<Type> t);
IntrusivePtr<Type> ShallowClone() override;
~VectorType() override;
const IntrusivePtr<BroType>& Yield() const override;
const IntrusivePtr<Type>& Yield() const override;
int MatchesIndex(ListExpr* index) const override;
int MatchesIndex(zeek::detail::ListExpr* index) const override;
// Returns true if this table type is "unspecified", which is what one
// gets using an empty "vector()" constructor.
@ -796,62 +879,39 @@ public:
void DescribeReST(ODesc* d, bool roles_only = false) const override;
protected:
IntrusivePtr<BroType> yield_type;
IntrusivePtr<Type> yield_type;
};
extern IntrusivePtr<OpaqueType> md5_type;
extern IntrusivePtr<OpaqueType> sha1_type;
extern IntrusivePtr<OpaqueType> sha256_type;
extern IntrusivePtr<OpaqueType> entropy_type;
extern IntrusivePtr<OpaqueType> cardinality_type;
extern IntrusivePtr<OpaqueType> topk_type;
extern IntrusivePtr<OpaqueType> bloomfilter_type;
extern IntrusivePtr<OpaqueType> x509_opaque_type;
extern IntrusivePtr<OpaqueType> ocsp_resp_opaque_type;
extern IntrusivePtr<OpaqueType> paraglob_type;
// Returns the basic (non-parameterized) type with the given type.
const IntrusivePtr<BroType>& base_type(TypeTag tag);
// Returns the basic (non-parameterized) type with the given type.
// The reference count of the type is not increased.
[[deprecated("Remove in v4.1. Use ::base_type() instead")]]
inline BroType* base_type_no_ref(TypeTag tag)
{ return base_type(tag).get(); }
// Returns the basic error type.
inline const IntrusivePtr<BroType>& error_type() { return base_type(TYPE_ERROR); }
// True if the two types are equivalent. If is_init is true then the test is
// done in the context of an initialization. If match_record_field_names is
// true then for record types the field names have to match, too.
extern bool same_type(const BroType& t1, const BroType& t2,
extern bool same_type(const Type& t1, const Type& t2,
bool is_init=false, bool match_record_field_names=true);
inline bool same_type(const IntrusivePtr<BroType>& t1, const IntrusivePtr<BroType>& t2,
inline bool same_type(const IntrusivePtr<Type>& t1, const IntrusivePtr<Type>& t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const BroType* t1, const BroType* t2,
inline bool same_type(const Type* t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const IntrusivePtr<BroType>& t1, const BroType* t2,
inline bool same_type(const IntrusivePtr<Type>& t1, const Type* t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
inline bool same_type(const BroType* t1, const IntrusivePtr<BroType>& t2,
inline bool same_type(const Type* t1, const IntrusivePtr<Type>& t2,
bool is_init=false, bool match_record_field_names=true)
{ return same_type(*t1, *t2, is_init, match_record_field_names); }
// True if the two attribute lists are equivalent.
extern bool same_attrs(const Attributes* a1, const Attributes* a2);
extern bool same_attrs(const zeek::detail::Attributes* a1, const zeek::detail::Attributes* a2);
// Returns true if the record sub_rec can be promoted to the record
// super_rec.
extern bool record_promotion_compatible(const RecordType* super_rec,
const RecordType* sub_rec);
// If the given BroType is a TypeList with just one element, returns
// If the given Type is a TypeList with just one element, returns
// that element, otherwise returns the type.
extern const BroType* flatten_type(const BroType* t);
extern BroType* flatten_type(BroType* t);
extern const Type* flatten_type(const Type* t);
extern Type* flatten_type(Type* t);
// Returns the "maximum" of two type tags, in a type-promotion sense.
extern TypeTag max_type(TypeTag t1, TypeTag t2);
@ -859,28 +919,28 @@ extern TypeTag max_type(TypeTag t1, TypeTag t2);
// Given two types, returns the "merge", in which promotable types
// are promoted to the maximum of the two. Returns nil (and generates
// an error message) if the types are incompatible.
IntrusivePtr<BroType> merge_types(const IntrusivePtr<BroType>& t1,
const IntrusivePtr<BroType>& t2);
IntrusivePtr<Type> merge_types(const IntrusivePtr<Type>& t1,
const IntrusivePtr<Type>& t2);
// Given a list of expressions, returns a (ref'd) type reflecting
// a merged type consistent across all of them, or nil if this
// cannot be done.
IntrusivePtr<BroType> merge_type_list(ListExpr* elements);
IntrusivePtr<Type> merge_type_list(zeek::detail::ListExpr* elements);
// Given an expression, infer its type when used for an initialization.
IntrusivePtr<BroType> init_type(Expr* init);
IntrusivePtr<Type> init_type(zeek::detail::Expr* init);
// Returns true if argument is an atomic type.
bool is_atomic_type(const BroType& t);
inline bool is_atomic_type(const BroType* t)
bool is_atomic_type(const Type& t);
inline bool is_atomic_type(const Type* t)
{ return is_atomic_type(*t); }
inline bool is_atomic_type(const IntrusivePtr<BroType>& t)
inline bool is_atomic_type(const IntrusivePtr<Type>& t)
{ return is_atomic_type(*t); }
// True if the given type tag corresponds to type that can be assigned to.
extern bool is_assignable(TypeTag t);
inline bool is_assignable(BroType* t)
{ return ::is_assignable(t->Tag()); }
inline bool is_assignable(Type* t)
{ return zeek::is_assignable(t->Tag()); }
// True if the given type tag corresponds to an integral type.
inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); }
@ -929,3 +989,68 @@ inline bool BothString(TypeTag t1, TypeTag t2) { return (IsString(t1) && IsStrin
// True if either tag is the error type.
inline bool EitherError(TypeTag t1, TypeTag t2) { return (IsErrorType(t1) || IsErrorType(t2)); }
// Returns the basic (non-parameterized) type with the given type.
const IntrusivePtr<zeek::Type>& base_type(zeek::TypeTag tag);
// Returns the basic error type.
inline const IntrusivePtr<zeek::Type>& error_type() { return base_type(TYPE_ERROR); }
} // namespace zeek
// Returns the basic (non-parameterized) type with the given type.
// The reference count of the type is not increased.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use zeek::base_type() instead")]]
inline zeek::Type* base_type_no_ref(::TypeTag tag)
{ return zeek::base_type(static_cast<zeek::TypeTag>(tag)).get(); }
#pragma GCC diagnostic pop
extern IntrusivePtr<zeek::OpaqueType> md5_type;
extern IntrusivePtr<zeek::OpaqueType> sha1_type;
extern IntrusivePtr<zeek::OpaqueType> sha256_type;
extern IntrusivePtr<zeek::OpaqueType> entropy_type;
extern IntrusivePtr<zeek::OpaqueType> cardinality_type;
extern IntrusivePtr<zeek::OpaqueType> topk_type;
extern IntrusivePtr<zeek::OpaqueType> bloomfilter_type;
extern IntrusivePtr<zeek::OpaqueType> x509_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> ocsp_resp_opaque_type;
extern IntrusivePtr<zeek::OpaqueType> paraglob_type;
using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type;
using TypeList [[deprecated("Remove in v4.1. Use zeek::TypeList instead.")]] = zeek::TypeList;
using IndexType [[deprecated("Remove in v4.1. Use zeek::IndexType instead.")]] = zeek::IndexType;
using TableType [[deprecated("Remove in v4.1. Use zeek::TableType instead.")]] = zeek::TableType;
using SetType [[deprecated("Remove in v4.1. Use zeek::SetType instead.")]] = zeek::SetType;
using FuncType [[deprecated("Remove in v4.1. Use zeek::FuncType instead.")]] = zeek::FuncType;
using TypeType [[deprecated("Remove in v4.1. Use zeek::TypeType instead.")]] = zeek::TypeType;
using TypeDecl [[deprecated("Remove in v4.1. Use zeek::TypeDecl instead.")]] = zeek::TypeDecl;
using RecordType [[deprecated("Remove in v4.1. Use zeek::RecordType instead.")]] = zeek::RecordType;
using SubNetType [[deprecated("Remove in v4.1. Use zeek::SubNetType instead.")]] = zeek::SubNetType;
using FileType [[deprecated("Remove in v4.1. Use zeek::FileType instead.")]] = zeek::FileType;
using OpaqueType [[deprecated("Remove in v4.1. Use zeek::OpaqueType instead.")]] = zeek::OpaqueType;
using EnumType [[deprecated("Remove in v4.1. Use zeek::EnumType instead.")]] = zeek::EnumType;
using VectorType [[deprecated("Remove in v4.1. Use zeek::VectorType instead.")]] = zeek::VectorType;
using type_decl_list [[deprecated("Remove in v4.1. Use zeek::type_decl_list instead.")]] = zeek::type_decl_list;
constexpr auto IsIntegral [[deprecated("Remove in v4.1. Use zeek::IsIntegral instead.")]] = zeek::IsIntegral;
constexpr auto IsArithmetic [[deprecated("Remove in v4.1. Use zeek::IsArithmetic instead.")]] = zeek::IsArithmetic;
constexpr auto IsBool [[deprecated("Remove in v4.1. Use zeek::IsBool instead.")]] = zeek::IsBool;
constexpr auto IsInterval [[deprecated("Remove in v4.1. Use zeek::IsInterval instead.")]] = zeek::IsInterval;
constexpr auto IsRecord [[deprecated("Remove in v4.1. Use zeek::IsRecord instead.")]] = zeek::IsRecord;
constexpr auto IsFunc [[deprecated("Remove in v4.1. Use zeek::IsFunc instead.")]] = zeek::IsFunc;
constexpr auto IsVector [[deprecated("Remove in v4.1. Use zeek::IsVector instead.")]] = zeek::IsVector;
constexpr auto IsString [[deprecated("Remove in v4.1. Use zeek::IsString instead.")]] = zeek::IsString;
constexpr auto IsErrorType [[deprecated("Remove in v4.1. Use zeek::IsErrorType instead.")]] = zeek::IsErrorType;
constexpr auto BothIntegral [[deprecated("Remove in v4.1. Use zeek::BothIntegral instead.")]] = zeek::BothIntegral;
constexpr auto BothArithmetic [[deprecated("Remove in v4.1. Use zeek::BothArithmetic instead.")]] = zeek::BothArithmetic;
constexpr auto EitherArithmetic [[deprecated("Remove in v4.1. Use zeek::EitherArithmetic instead.")]] = zeek::EitherArithmetic;
constexpr auto BothBool [[deprecated("Remove in v4.1. Use zeek::BothBool instead.")]] = zeek::BothBool;
constexpr auto BothInterval [[deprecated("Remove in v4.1. Use zeek::BothInterval instead.")]] = zeek::BothInterval;
constexpr auto BothString [[deprecated("Remove in v4.1. Use zeek::BothString instead.")]] = zeek::BothString;
constexpr auto EitherError [[deprecated("Remove in v4.1. Use zeek::EitherError instead.")]] = zeek::EitherError;
constexpr auto base_type [[deprecated("Remove in v4.1. Use zeek::base_type instead.")]] = zeek::base_type;
constexpr auto error_type [[deprecated("Remove in v4.1. Use zeek::error_type instead.")]] = zeek::error_type;
constexpr auto type_name [[deprecated("Remove in v4.1. Use zeek::type_name instead.")]] = zeek::type_name;
constexpr auto is_network_order [[deprecated("Remove in v4.1. Use zeek::is_network_order instead.")]] = zeek::is_network_order;

File diff suppressed because it is too large Load diff

255
src/Val.h
View file

@ -121,10 +121,17 @@ public:
static inline const IntrusivePtr<Val> nil;
[[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]]
Val(double d, TypeTag t)
: val(d), type(base_type(t))
Val(double d, zeek::TypeTag t)
: val(d), type(zeek::base_type(t))
{}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use IntervalVal(), TimeVal(), or DoubleVal() constructors.")]]
Val(double d, ::TypeTag t) : Val(d, static_cast<zeek::TypeTag>(t))
{}
#pragma GCC diagnostic pop
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit Val(Func* f);
explicit Val(IntrusivePtr<Func> f);
@ -136,16 +143,16 @@ public:
explicit Val(IntrusivePtr<BroFile> f);
// Extra arg to differentiate from protected version.
Val(IntrusivePtr<BroType> t, bool type_type)
: type(make_intrusive<TypeType>(std::move(t)))
Val(IntrusivePtr<zeek::Type> t, bool type_type)
: type(make_intrusive<zeek::TypeType>(std::move(t)))
{}
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
Val(BroType* t, bool type_type) : Val({NewRef{}, t}, type_type)
Val(zeek::Type* t, bool type_type) : Val({NewRef{}, t}, type_type)
{}
Val()
: val(bro_int_t(0)), type(base_type(TYPE_ERROR))
: val(bro_int_t(0)), type(zeek::base_type(zeek::TYPE_ERROR))
{}
~Val() override;
@ -181,11 +188,11 @@ public:
virtual bool RemoveFrom(Val* v) const;
[[deprecated("Remove in v4.1. Use GetType().")]]
BroType* Type() { return type.get(); }
zeek::Type* Type() { return type.get(); }
[[deprecated("Remove in v4.1. Use GetType().")]]
const BroType* Type() const { return type.get(); }
const zeek::Type* Type() const { return type.get(); }
const IntrusivePtr<BroType>& GetType() const
const IntrusivePtr<zeek::Type>& GetType() const
{ return type; }
template <class T>
@ -195,7 +202,7 @@ public:
#define CONST_ACCESSOR(tag, ctype, accessor, name) \
const ctype name() const \
{ \
CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", type_name) \
CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", zeek::type_name) \
return val.accessor; \
}
@ -203,72 +210,72 @@ public:
#define CONST_ACCESSOR2(tag, ctype, accessor, name) \
ctype name() const \
{ \
CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", type_name) \
CHECK_TAG(type->Tag(), tag, "Val::CONST_ACCESSOR", zeek::type_name) \
return val.accessor; \
}
CONST_ACCESSOR2(TYPE_BOOL, bool, int_val, AsBool)
CONST_ACCESSOR2(TYPE_INT, bro_int_t, int_val, AsInt)
CONST_ACCESSOR2(TYPE_COUNT, bro_uint_t, uint_val, AsCount)
CONST_ACCESSOR2(TYPE_COUNTER, bro_uint_t, uint_val, AsCounter)
CONST_ACCESSOR2(TYPE_DOUBLE, double, double_val, AsDouble)
CONST_ACCESSOR2(TYPE_TIME, double, double_val, AsTime)
CONST_ACCESSOR2(TYPE_INTERVAL, double, double_val, AsInterval)
CONST_ACCESSOR2(TYPE_ENUM, int, int_val, AsEnum)
CONST_ACCESSOR(TYPE_STRING, BroString*, string_val, AsString)
CONST_ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc)
CONST_ACCESSOR(TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable)
CONST_ACCESSOR(TYPE_RECORD, std::vector<IntrusivePtr<Val>>*, record_val, AsRecord)
CONST_ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile)
CONST_ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
CONST_ACCESSOR(TYPE_VECTOR, std::vector<IntrusivePtr<Val>>*, vector_val, AsVector)
CONST_ACCESSOR2(zeek::TYPE_BOOL, bool, int_val, AsBool)
CONST_ACCESSOR2(zeek::TYPE_INT, bro_int_t, int_val, AsInt)
CONST_ACCESSOR2(zeek::TYPE_COUNT, bro_uint_t, uint_val, AsCount)
CONST_ACCESSOR2(zeek::TYPE_COUNTER, bro_uint_t, uint_val, AsCounter)
CONST_ACCESSOR2(zeek::TYPE_DOUBLE, double, double_val, AsDouble)
CONST_ACCESSOR2(zeek::TYPE_TIME, double, double_val, AsTime)
CONST_ACCESSOR2(zeek::TYPE_INTERVAL, double, double_val, AsInterval)
CONST_ACCESSOR2(zeek::TYPE_ENUM, int, int_val, AsEnum)
CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString)
CONST_ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
CONST_ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsTable)
CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector<IntrusivePtr<Val>>*, record_val, AsRecord)
CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
CONST_ACCESSOR(zeek::TYPE_VECTOR, std::vector<IntrusivePtr<Val>>*, vector_val, AsVector)
const IPPrefix& AsSubNet() const
{
CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name)
CHECK_TAG(type->Tag(), zeek::TYPE_SUBNET, "Val::SubNet", zeek::type_name)
return *val.subnet_val;
}
BroType* AsType() const
zeek::Type* AsType() const
{
CHECK_TAG(type->Tag(), TYPE_TYPE, "Val::Type", type_name)
CHECK_TAG(type->Tag(), zeek::TYPE_TYPE, "Val::Type", zeek::type_name)
return type.get();
}
const IPAddr& AsAddr() const
{
if ( type->Tag() != TYPE_ADDR )
BadTag("Val::AsAddr", type_name(type->Tag()));
if ( type->Tag() != zeek::TYPE_ADDR )
BadTag("Val::AsAddr", zeek::type_name(type->Tag()));
return *val.addr_val;
}
#define ACCESSOR(tag, ctype, accessor, name) \
ctype name() \
{ \
CHECK_TAG(type->Tag(), tag, "Val::ACCESSOR", type_name) \
CHECK_TAG(type->Tag(), tag, "Val::ACCESSOR", zeek::type_name) \
return val.accessor; \
}
// Accessors for mutable values are called AsNonConst* and
// are protected to avoid external state changes.
// ACCESSOR(TYPE_STRING, BroString*, string_val, AsString)
ACCESSOR(TYPE_FUNC, Func*, func_val, AsFunc)
ACCESSOR(TYPE_FILE, BroFile*, file_val, AsFile)
ACCESSOR(TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
ACCESSOR(TYPE_VECTOR, std::vector<IntrusivePtr<Val>>*, vector_val, AsVector)
// ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString)
ACCESSOR(zeek::TYPE_FUNC, Func*, func_val, AsFunc)
ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile)
ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern)
ACCESSOR(zeek::TYPE_VECTOR, std::vector<IntrusivePtr<Val>>*, vector_val, AsVector)
IntrusivePtr<Func> AsFuncPtr() const;
const IPPrefix& AsSubNet()
{
CHECK_TAG(type->Tag(), TYPE_SUBNET, "Val::SubNet", type_name)
CHECK_TAG(type->Tag(), zeek::TYPE_SUBNET, "Val::SubNet", zeek::type_name)
return *val.subnet_val;
}
const IPAddr& AsAddr()
{
if ( type->Tag() != TYPE_ADDR )
BadTag("Val::AsAddr", type_name(type->Tag()));
if ( type->Tag() != zeek::TYPE_ADDR )
BadTag("Val::AsAddr", zeek::type_name(type->Tag()));
return *val.addr_val;
}
@ -280,39 +287,39 @@ public:
#define CONVERTER(tag, ctype, name) \
ctype name() \
{ \
CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", type_name) \
CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", zeek::type_name) \
return (ctype)(this); \
}
CONVERTER(TYPE_PATTERN, PatternVal*, AsPatternVal)
CONVERTER(TYPE_PORT, PortVal*, AsPortVal)
CONVERTER(TYPE_SUBNET, SubNetVal*, AsSubNetVal)
CONVERTER(TYPE_ADDR, AddrVal*, AsAddrVal)
CONVERTER(TYPE_TABLE, TableVal*, AsTableVal)
CONVERTER(TYPE_RECORD, RecordVal*, AsRecordVal)
CONVERTER(TYPE_LIST, ListVal*, AsListVal)
CONVERTER(TYPE_STRING, StringVal*, AsStringVal)
CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal)
CONVERTER(TYPE_ENUM, EnumVal*, AsEnumVal)
CONVERTER(TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal)
CONVERTER(zeek::TYPE_PATTERN, PatternVal*, AsPatternVal)
CONVERTER(zeek::TYPE_PORT, PortVal*, AsPortVal)
CONVERTER(zeek::TYPE_SUBNET, SubNetVal*, AsSubNetVal)
CONVERTER(zeek::TYPE_ADDR, AddrVal*, AsAddrVal)
CONVERTER(zeek::TYPE_TABLE, TableVal*, AsTableVal)
CONVERTER(zeek::TYPE_RECORD, RecordVal*, AsRecordVal)
CONVERTER(zeek::TYPE_LIST, ListVal*, AsListVal)
CONVERTER(zeek::TYPE_STRING, StringVal*, AsStringVal)
CONVERTER(zeek::TYPE_VECTOR, VectorVal*, AsVectorVal)
CONVERTER(zeek::TYPE_ENUM, EnumVal*, AsEnumVal)
CONVERTER(zeek::TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal)
#define CONST_CONVERTER(tag, ctype, name) \
const ctype name() const \
{ \
CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", type_name) \
CHECK_TAG(type->Tag(), tag, "Val::CONVERTER", zeek::type_name) \
return (const ctype)(this); \
}
CONST_CONVERTER(TYPE_PATTERN, PatternVal*, AsPatternVal)
CONST_CONVERTER(TYPE_PORT, PortVal*, AsPortVal)
CONST_CONVERTER(TYPE_SUBNET, SubNetVal*, AsSubNetVal)
CONST_CONVERTER(TYPE_ADDR, AddrVal*, AsAddrVal)
CONST_CONVERTER(TYPE_TABLE, TableVal*, AsTableVal)
CONST_CONVERTER(TYPE_RECORD, RecordVal*, AsRecordVal)
CONST_CONVERTER(TYPE_LIST, ListVal*, AsListVal)
CONST_CONVERTER(TYPE_STRING, StringVal*, AsStringVal)
CONST_CONVERTER(TYPE_VECTOR, VectorVal*, AsVectorVal)
CONST_CONVERTER(TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal)
CONST_CONVERTER(zeek::TYPE_PATTERN, PatternVal*, AsPatternVal)
CONST_CONVERTER(zeek::TYPE_PORT, PortVal*, AsPortVal)
CONST_CONVERTER(zeek::TYPE_SUBNET, SubNetVal*, AsSubNetVal)
CONST_CONVERTER(zeek::TYPE_ADDR, AddrVal*, AsAddrVal)
CONST_CONVERTER(zeek::TYPE_TABLE, TableVal*, AsTableVal)
CONST_CONVERTER(zeek::TYPE_RECORD, RecordVal*, AsRecordVal)
CONST_CONVERTER(zeek::TYPE_LIST, ListVal*, AsListVal)
CONST_CONVERTER(zeek::TYPE_STRING, StringVal*, AsStringVal)
CONST_CONVERTER(zeek::TYPE_VECTOR, VectorVal*, AsVectorVal)
CONST_CONVERTER(zeek::TYPE_OPAQUE, OpaqueVal*, AsOpaqueVal)
void Describe(ODesc* d) const override;
virtual void DescribeReST(ODesc* d) const;
@ -324,12 +331,12 @@ public:
#ifdef DEBUG
// For debugging, we keep a reference to the global ID to which a
// value has been bound *last*.
ID* GetID() const;
zeek::detail::ID* GetID() const;
void SetID(ID* id);
void SetID(zeek::detail::ID* id);
#endif
static bool WouldOverflow(const BroType* from_type, const BroType* to_type, const Val* val);
static bool WouldOverflow(const zeek::Type* from_type, const zeek::Type* to_type, const Val* val);
IntrusivePtr<TableVal> GetRecordFields();
@ -337,7 +344,7 @@ public:
protected:
friend class EnumType;
friend class zeek::EnumType;
friend class ListVal;
friend class RecordVal;
friend class VectorVal;
@ -352,21 +359,21 @@ protected:
static IntrusivePtr<Val> MakeCount(bro_uint_t u);
template<typename V>
Val(V&& v, TypeTag t) noexcept
: val(std::forward<V>(v)), type(base_type(t))
Val(V&& v, zeek::TypeTag t) noexcept
: val(std::forward<V>(v)), type(zeek::base_type(t))
{}
template<typename V>
Val(V&& v, IntrusivePtr<BroType> t) noexcept
Val(V&& v, IntrusivePtr<zeek::Type> t) noexcept
: val(std::forward<V>(v)), type(std::move(t))
{}
explicit Val(IntrusivePtr<BroType> t) noexcept
explicit Val(IntrusivePtr<zeek::Type> t) noexcept
: type(std::move(t))
{}
ACCESSOR(TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable)
ACCESSOR(TYPE_RECORD, std::vector<IntrusivePtr<Val>>*, record_val, AsNonConstRecord)
ACCESSOR(zeek::TYPE_TABLE, PDict<TableEntryVal>*, table_val, AsNonConstTable)
ACCESSOR(zeek::TYPE_RECORD, std::vector<IntrusivePtr<Val>>*, record_val, AsNonConstRecord)
// For internal use by the Val::Clone() methods.
struct CloneState {
@ -382,7 +389,7 @@ protected:
virtual IntrusivePtr<Val> DoClone(CloneState* state);
BroValUnion val;
IntrusivePtr<BroType> type;
IntrusivePtr<zeek::Type> type;
#ifdef DEBUG
// For debugging, we keep the name of the ID to which a Val is bound.
@ -491,7 +498,7 @@ extern ValManager* val_mgr;
class IntervalVal final : public Val {
public:
IntervalVal(double quantity, double units = Seconds)
: Val(quantity * units, base_type(TYPE_INTERVAL))
: Val(quantity * units, zeek::base_type(zeek::TYPE_INTERVAL))
{}
protected:
@ -501,14 +508,14 @@ protected:
class TimeVal final : public Val {
public:
TimeVal(double t)
: Val(t, base_type(TYPE_TIME))
: Val(t, zeek::base_type(zeek::TYPE_TIME))
{}
};
class DoubleVal final : public Val {
public:
DoubleVal(double v)
: Val(v, base_type(TYPE_DOUBLE))
: Val(v, zeek::base_type(zeek::TYPE_DOUBLE))
{}
};
@ -647,10 +654,17 @@ protected:
// element in their index.
class ListVal final : public Val {
public:
explicit ListVal(TypeTag t);
explicit ListVal(zeek::TypeTag t);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use the version that takes zeek::TypeTag")]]
explicit ListVal(::TypeTag t) : ListVal(static_cast<zeek::TypeTag>(t)) {}
#pragma GCC diagnostic pop
~ListVal() override;
TypeTag BaseTag() const { return tag; }
zeek::TypeTag BaseTag() const { return tag; }
IntrusivePtr<Val> SizeVal() const override;
@ -698,7 +712,7 @@ protected:
IntrusivePtr<Val> DoClone(CloneState* state) override;
std::vector<IntrusivePtr<Val>> vals;
TypeTag tag;
zeek::TypeTag tag;
};
extern double bro_start_network_time;
@ -758,9 +772,10 @@ class Frame;
class TableVal final : public Val, public notifier::Modifiable {
public:
explicit TableVal(IntrusivePtr<TableType> t, IntrusivePtr<Attributes> attrs = nullptr);
explicit TableVal(IntrusivePtr<zeek::TableType> t, IntrusivePtr<zeek::detail::Attributes> attrs = nullptr);
[[deprecated("Remove in v4.1. Construct from IntrusivePtrs instead.")]]
explicit TableVal(TableType* t, Attributes* attrs = nullptr)
explicit TableVal(zeek::TableType* t, zeek::detail::Attributes* attrs = nullptr)
: TableVal({NewRef{}, t}, {NewRef{}, attrs})
{}
@ -932,29 +947,32 @@ public:
{ return Remove(*k).release(); }
// Returns a ListVal representation of the table (which must be a set).
IntrusivePtr<ListVal> ToListVal(TypeTag t = TYPE_ANY) const;
IntrusivePtr<ListVal> ToListVal(zeek::TypeTag t = zeek::TYPE_ANY) const;
// Returns a ListVal representation of the table (which must be a set
// with non-composite index type).
IntrusivePtr<ListVal> ToPureListVal() const;
[[deprecated("Remove in v4.1. Use ToListVal() instead.")]]
ListVal* ConvertToList(TypeTag t=TYPE_ANY) const;
ListVal* ConvertToList(zeek::TypeTag t=zeek::TYPE_ANY) const;
[[deprecated("Remove in v4.1. Use ToPureListVal() instead.")]]
ListVal* ConvertToPureList() const; // must be single index type
void SetAttrs(IntrusivePtr<Attributes> attrs);
void SetAttrs(IntrusivePtr<zeek::detail::Attributes> attrs);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use GetAttr().")]]
Attr* FindAttr(attr_tag t) const
{ return GetAttr(t).get(); }
Attr* FindAttr(::attr_tag t) const
{ return GetAttr(static_cast<zeek::detail::attr_tag>(t)).get(); }
#pragma GCC diagnostic pop
const IntrusivePtr<Attr>& GetAttr(attr_tag t) const;
const IntrusivePtr<zeek::detail::Attr>& GetAttr(zeek::detail::attr_tag t) const;
[[deprecated("Remove in v4.1. Use GetAttrs().")]]
Attributes* Attrs() { return attrs.get(); }
zeek::detail::Attributes* Attrs() { return attrs.get(); }
const IntrusivePtr<Attributes>& GetAttrs() const
const IntrusivePtr<zeek::detail::Attributes>& GetAttrs() const
{ return attrs; }
// Returns the size of the table.
@ -997,8 +1015,8 @@ public:
notifier::Modifiable* Modifiable() override { return this; }
// Retrieves and saves all table state (key-value pairs) for
// tables whose index type depends on the given RecordType.
static void SaveParseTimeTableState(RecordType* rt);
// tables whose index type depends on the given zeek::RecordType.
static void SaveParseTimeTableState(zeek::RecordType* rt);
// Rebuilds all TableVals whose state was previously saved by
// SaveParseTimeTableState(). This is used to re-recreate the tables
@ -1006,13 +1024,13 @@ public:
static void RebuildParseTimeTables();
// Clears all state that was used to track TableVals that depending
// on RecordTypes.
// on zeek::RecordTypes.
static void DoneParsing();
protected:
void Init(IntrusivePtr<TableType> t);
void Init(IntrusivePtr<zeek::TableType> t);
using TableRecordDependencies = std::unordered_map<RecordType*, std::vector<IntrusivePtr<TableVal>>>;
using TableRecordDependencies = std::unordered_map<zeek::RecordType*, std::vector<IntrusivePtr<TableVal>>>;
using ParseTimeTableState = std::vector<std::pair<IntrusivePtr<Val>, IntrusivePtr<Val>>>;
using ParseTimeTableStates = std::unordered_map<TableVal*, ParseTimeTableState>;
@ -1020,7 +1038,12 @@ protected:
ParseTimeTableState DumpTableState();
void RebuildTable(ParseTimeTableState ptts);
void CheckExpireAttr(attr_tag at);
void CheckExpireAttr(zeek::detail::attr_tag at);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
[[deprecated("Remove in v4.1. Use version that takes zeek::detail::attr_tag.")]]
void CheckExpireAttr(::attr_tag at);
#pragma GCC diagnostic pop
bool ExpandCompoundAndInit(ListVal* lv, int k, IntrusivePtr<Val> new_val);
bool CheckAndAssign(IntrusivePtr<Val> index, IntrusivePtr<Val> new_val);
@ -1047,16 +1070,16 @@ protected:
IntrusivePtr<Val> DoClone(CloneState* state) override;
IntrusivePtr<TableType> table_type;
IntrusivePtr<zeek::TableType> table_type;
CompositeHash* table_hash;
IntrusivePtr<Attributes> attrs;
IntrusivePtr<Expr> expire_time;
IntrusivePtr<Expr> expire_func;
IntrusivePtr<zeek::detail::Attributes> attrs;
IntrusivePtr<zeek::detail::Expr> expire_time;
IntrusivePtr<zeek::detail::Expr> expire_func;
TableValTimer* timer;
IterCookie* expire_cookie;
PrefixTable* subnets;
IntrusivePtr<Val> def_val;
IntrusivePtr<Expr> change_func;
IntrusivePtr<zeek::detail::Expr> change_func;
// prevent recursion of change functions
bool in_change_func = false;
@ -1067,8 +1090,8 @@ protected:
class RecordVal final : public Val, public notifier::Modifiable {
public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit RecordVal(RecordType* t, bool init_fields = true);
explicit RecordVal(IntrusivePtr<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);
~RecordVal() override;
@ -1208,10 +1231,10 @@ public:
//
// The *allow_orphaning* parameter allows for a record to be demoted
// down to a record type that contains less fields.
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<RecordType> other,
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<zeek::RecordType> other,
IntrusivePtr<RecordVal> aggr,
bool allow_orphaning = false) const;
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<RecordType> other,
IntrusivePtr<RecordVal> CoerceTo(IntrusivePtr<zeek::RecordType> other,
bool allow_orphaning = false);
unsigned int MemoryAllocation() const override;
@ -1222,7 +1245,7 @@ public:
// Extend the underlying arrays of record instances created during
// parsing to match the number of fields in the record type (they may
// mismatch as a result of parse-time record type redefinitions.
static void ResizeParseTimeRecords(RecordType* rt);
static void ResizeParseTimeRecords(zeek::RecordType* rt);
static void DoneParsing();
@ -1231,7 +1254,7 @@ protected:
BroObj* origin;
using RecordTypeValMap = std::unordered_map<RecordType*, std::vector<IntrusivePtr<RecordVal>>>;
using RecordTypeValMap = std::unordered_map<zeek::RecordType*, std::vector<IntrusivePtr<RecordVal>>>;
static RecordTypeValMap parse_time_records;
};
@ -1241,12 +1264,12 @@ public:
protected:
friend class Val;
friend class EnumType;
friend class zeek::EnumType;
template<class T, class... Ts>
friend IntrusivePtr<T> make_intrusive(Ts&&... args);
EnumVal(IntrusivePtr<EnumType> t, int i) : Val(bro_int_t(i), std::move(t))
EnumVal(IntrusivePtr<zeek::EnumType> t, int i) : Val(bro_int_t(i), std::move(t))
{}
void ValDescribe(ODesc* d) const override;
@ -1257,8 +1280,8 @@ protected:
class VectorVal final : public Val, public notifier::Modifiable {
public:
[[deprecated("Remove in v4.1. Construct from IntrusivePtr instead.")]]
explicit VectorVal(VectorType* t);
explicit VectorVal(IntrusivePtr<VectorType> t);
explicit VectorVal(zeek::VectorType* t);
explicit VectorVal(IntrusivePtr<zeek::VectorType> t);
~VectorVal() override;
IntrusivePtr<Val> SizeVal() const override;
@ -1363,7 +1386,7 @@ protected:
// If not a match, generates an error message and return nil. If is_init is
// true, then the checking is done in the context of an initialization.
extern IntrusivePtr<Val> check_and_promote(IntrusivePtr<Val> v,
const BroType* t, bool is_init,
const zeek::Type* t, bool is_init,
const Location* expr_location = nullptr);
extern bool same_val(const Val* v1, const Val* v2);
@ -1375,22 +1398,22 @@ extern void describe_vals(const std::vector<IntrusivePtr<Val>>& vals,
extern void delete_vals(val_list* vals);
// True if the given Val* has a vector type.
inline bool is_vector(Val* v) { return v->GetType()->Tag() == TYPE_VECTOR; }
inline bool is_vector(Val* v) { return v->GetType()->Tag() == zeek::TYPE_VECTOR; }
inline bool is_vector(const IntrusivePtr<Val>& v) { return is_vector(v.get()); }
// Returns v casted to type T if the type supports that. Returns null if not.
//
// Note: This implements the script-level cast operator.
extern IntrusivePtr<Val> cast_value_to_type(Val* v, BroType* t);
extern 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
// succeed as well.
//
// Note: This implements the script-level type comparision operator.
extern bool can_cast_value_to_type(const Val* v, BroType* t);
extern bool can_cast_value_to_type(const Val* v, zeek::Type* t);
// Returns true if values of type s may support casting to type t. This is
// purely static check to weed out cases early on that will never succeed.
// However, even this function returns true, casting may still fail for a
// specific instance later.
extern bool can_cast_value_to_type(const BroType* s, BroType* t);
extern bool can_cast_value_to_type(const zeek::Type* s, zeek::Type* t);

View file

@ -17,7 +17,9 @@
#include "module_util.h"
#include "ID.h"
static IntrusivePtr<Val> init_val(Expr* init, const BroType* t,
using namespace zeek::detail;
static IntrusivePtr<Val> init_val(zeek::detail::Expr* init, const zeek::Type* t,
IntrusivePtr<Val> aggr)
{
try
@ -30,14 +32,14 @@ static IntrusivePtr<Val> init_val(Expr* init, const BroType* t,
}
}
static bool add_prototype(const IntrusivePtr<ID>& id, BroType* t,
std::vector<IntrusivePtr<Attr>>* attrs,
const IntrusivePtr<Expr>& init)
static bool add_prototype(const IntrusivePtr<zeek::detail::ID>& id, zeek::Type* t,
std::vector<IntrusivePtr<zeek::detail::Attr>>* attrs,
const IntrusivePtr<zeek::detail::Expr>& init)
{
if ( ! IsFunc(id->GetType()->Tag()) )
if ( ! zeek::IsFunc(id->GetType()->Tag()) )
return false;
if ( ! IsFunc(t->Tag()) )
if ( ! zeek::IsFunc(t->Tag()) )
{
t->Error("type incompatible with previous definition", id.get());
return false;
@ -52,7 +54,7 @@ static bool add_prototype(const IntrusivePtr<ID>& id, BroType* t,
return false;
}
if ( canon_ft->Flavor() == FUNC_FLAVOR_FUNCTION )
if ( canon_ft->Flavor() == zeek::FUNC_FLAVOR_FUNCTION )
{
alt_ft->Error("redeclaration of function", canon_ft);
return false;
@ -100,23 +102,24 @@ static bool add_prototype(const IntrusivePtr<ID>& id, BroType* t,
if ( attrs )
for ( const auto& a : *attrs )
if ( a->Tag() == ATTR_DEPRECATED )
if ( a->Tag() == zeek::detail::ATTR_DEPRECATED )
deprecated = true;
FuncType::Prototype p{deprecated, alt_args, std::move(offsets)};
zeek::FuncType::Prototype p{deprecated, alt_args, std::move(offsets)};
canon_ft->AddPrototype(std::move(p));
return true;
}
static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_class c,
IntrusivePtr<Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr,
static void make_var(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::Type> t,
zeek::detail::init_class c,
IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt,
bool do_init)
{
if ( id->GetType() )
{
if ( id->IsRedefinable() || (! init && attr && ! IsFunc(id->GetType()->Tag())) )
if ( id->IsRedefinable() || (! init && attr && ! zeek::IsFunc(id->GetType()->Tag())) )
{
BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get();
if ( dt != VAR_REDEF )
@ -125,7 +128,7 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
else if ( dt != VAR_REDEF || init || ! attr )
{
if ( IsFunc(id->GetType()->Tag()) )
if ( zeek::IsFunc(id->GetType()->Tag()) )
add_prototype(id, t.get(), attr.get(), init);
else
id->Error("already defined", init.get());
@ -146,10 +149,10 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
t = id->GetType();
}
if ( id->GetType() && id->GetType()->Tag() != TYPE_ERROR )
if ( id->GetType() && id->GetType()->Tag() != zeek::TYPE_ERROR )
{
if ( dt != VAR_REDEF &&
(! init || ! do_init || (! t && ! (t = init_type(init.get())))) )
(! init || ! do_init || (! t && ! (t = zeek::init_type(init.get())))) )
{
id->Error("already defined", init.get());
return;
@ -165,7 +168,7 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
if ( t && t->IsSet() )
{ // Check for set with explicit elements.
SetType* st = t->AsTableType()->AsSetType();
zeek::SetType* st = t->AsTableType()->AsSetType();
const auto& elements = st->Elements();
if ( elements )
@ -188,10 +191,10 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
return;
}
t = init_type(init.get());
t = zeek::init_type(init.get());
if ( ! t )
{
id->SetType(error_type());
id->SetType(zeek::error_type());
return;
}
}
@ -199,22 +202,22 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
id->SetType(t);
if ( attr )
id->AddAttrs(make_intrusive<Attributes>(std::move(*attr), t, false, id->IsGlobal()));
id->AddAttrs(make_intrusive<zeek::detail::Attributes>(std::move(*attr), t, false, id->IsGlobal()));
if ( init )
{
switch ( init->Tag() ) {
case EXPR_TABLE_CONSTRUCTOR:
case zeek::detail::EXPR_TABLE_CONSTRUCTOR:
{
TableConstructorExpr* ctor = (TableConstructorExpr*) init.get();
auto* ctor = static_cast<zeek::detail::TableConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
break;
case EXPR_SET_CONSTRUCTOR:
case zeek::detail::EXPR_SET_CONSTRUCTOR:
{
SetConstructorExpr* ctor = (SetConstructorExpr*) init.get();
auto* ctor = static_cast<zeek::detail::SetConstructorExpr*>(init.get());
if ( ctor->GetAttrs() )
id->AddAttrs(ctor->GetAttrs());
}
@ -227,14 +230,14 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
if ( do_init )
{
if ( c == INIT_NONE && dt == VAR_REDEF && t->IsTable() &&
init && init->Tag() == EXPR_ASSIGN )
if ( c == zeek::detail::INIT_NONE && dt == VAR_REDEF && t->IsTable() &&
init && init->Tag() == zeek::detail::EXPR_ASSIGN )
// e.g. 'redef foo["x"] = 1' is missing an init class, but the
// intention clearly isn't to overwrite entire existing table val.
c = INIT_EXTRA;
c = zeek::detail::INIT_EXTRA;
if ( init && ((c == INIT_EXTRA && id->GetAttr(ATTR_ADD_FUNC)) ||
(c == INIT_REMOVE && id->GetAttr(ATTR_DEL_FUNC)) ))
if ( init && ((c == zeek::detail::INIT_EXTRA && id->GetAttr(zeek::detail::ATTR_ADD_FUNC)) ||
(c == zeek::detail::INIT_REMOVE && id->GetAttr(zeek::detail::ATTR_DEL_FUNC)) ))
// Just apply the function.
id->SetVal(init, c);
@ -242,22 +245,22 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
{
IntrusivePtr<Val> aggr;
if ( t->Tag() == TYPE_RECORD )
if ( t->Tag() == zeek::TYPE_RECORD )
{
aggr = make_intrusive<RecordVal>(cast_intrusive<RecordType>(t));
aggr = make_intrusive<RecordVal>(cast_intrusive<zeek::RecordType>(t));
if ( init && t )
// Have an initialization and type is not deduced.
init = make_intrusive<RecordCoerceExpr>(std::move(init),
init = make_intrusive<zeek::detail::RecordCoerceExpr>(std::move(init),
IntrusivePtr{NewRef{}, t->AsRecordType()});
}
else if ( t->Tag() == TYPE_TABLE )
aggr = make_intrusive<TableVal>(cast_intrusive<TableType>(t),
else if ( t->Tag() == zeek::TYPE_TABLE )
aggr = make_intrusive<TableVal>(cast_intrusive<zeek::TableType>(t),
id->GetAttrs());
else if ( t->Tag() == TYPE_VECTOR )
aggr = make_intrusive<VectorVal>(cast_intrusive<VectorType>(t));
else if ( t->Tag() == zeek::TYPE_VECTOR )
aggr = make_intrusive<VectorVal>(cast_intrusive<zeek::VectorType>(t));
IntrusivePtr<Val> v;
@ -294,49 +297,48 @@ static void make_var(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t, init_c
id->UpdateValAttrs();
if ( t && t->Tag() == TYPE_FUNC &&
(t->AsFuncType()->Flavor() == FUNC_FLAVOR_EVENT ||
t->AsFuncType()->Flavor() == FUNC_FLAVOR_HOOK) )
if ( t && t->Tag() == zeek::TYPE_FUNC &&
(t->AsFuncType()->Flavor() == zeek::FUNC_FLAVOR_EVENT ||
t->AsFuncType()->Flavor() == zeek::FUNC_FLAVOR_HOOK) )
{
// For events, add a function value (without any body) here so that
// we can later access the ID even if no implementations have been
// defined.
std::vector<IntrusivePtr<ID>> inits;
std::vector<IntrusivePtr<zeek::detail::ID>> inits;
auto f = make_intrusive<BroFunc>(id, nullptr, inits, 0, 0);
id->SetVal(make_intrusive<Val>(std::move(f)));
}
}
void add_global(const IntrusivePtr<ID>& id, IntrusivePtr<BroType> t,
init_class c, IntrusivePtr<Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr,
void add_global(const IntrusivePtr<zeek::detail::ID>& id, IntrusivePtr<zeek::Type> t,
zeek::detail::init_class c, IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt)
{
make_var(id, std::move(t), c, std::move(init), std::move(attr), dt, true);
}
IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id, IntrusivePtr<BroType> t,
init_class c, IntrusivePtr<Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr,
IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id, IntrusivePtr<zeek::Type> t,
zeek::detail::init_class c, IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt)
{
make_var(id, std::move(t), c, init, std::move(attr), dt, false);
if ( init )
{
if ( c != INIT_FULL )
if ( c != zeek::detail::INIT_FULL )
id->Error("can't use += / -= for initializations of local variables");
// copy Location to the stack, because AssignExpr may free "init"
const Location location = init->GetLocationInfo() ?
*init->GetLocationInfo() : no_location;
auto name_expr = make_intrusive<NameExpr>(id, dt == VAR_CONST);
auto assign_expr = make_intrusive<AssignExpr>(std::move(name_expr),
std::move(init), 0,
nullptr, id->GetAttrs());
auto stmt = make_intrusive<ExprStmt>(std::move(assign_expr));
auto name_expr = make_intrusive<zeek::detail::NameExpr>(id, dt == VAR_CONST);
auto assign_expr = make_intrusive<zeek::detail::AssignExpr>(std::move(name_expr),
std::move(init), 0,
nullptr, id->GetAttrs());
auto stmt = make_intrusive<zeek::detail::ExprStmt>(std::move(assign_expr));
stmt->SetLocationInfo(&location);
return stmt;
}
@ -344,28 +346,28 @@ IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id, IntrusivePtr<BroType> t,
else
{
current_scope()->AddInit(std::move(id));
return make_intrusive<NullStmt>();
return make_intrusive<zeek::detail::NullStmt>();
}
}
extern IntrusivePtr<Expr> add_and_assign_local(IntrusivePtr<ID> id,
IntrusivePtr<Expr> init,
extern IntrusivePtr<zeek::detail::Expr> add_and_assign_local(IntrusivePtr<zeek::detail::ID> id,
IntrusivePtr<zeek::detail::Expr> init,
IntrusivePtr<Val> val)
{
make_var(id, nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false);
auto name_expr = make_intrusive<NameExpr>(std::move(id));
return make_intrusive<AssignExpr>(std::move(name_expr), std::move(init),
false, std::move(val));
make_var(id, nullptr, zeek::detail::INIT_FULL, init, nullptr, VAR_REGULAR, false);
auto name_expr = make_intrusive<zeek::detail::NameExpr>(std::move(id));
return make_intrusive<zeek::detail::AssignExpr>(std::move(name_expr), std::move(init),
false, std::move(val));
}
void add_type(ID* id, IntrusivePtr<BroType> t,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr)
void add_type(zeek::detail::ID* id, IntrusivePtr<zeek::Type> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr)
{
std::string new_type_name = id->Name();
std::string old_type_name = t->GetName();
IntrusivePtr<BroType> tnew;
IntrusivePtr<zeek::Type> tnew;
if ( (t->Tag() == TYPE_RECORD || t->Tag() == TYPE_ENUM) &&
if ( (t->Tag() == zeek::TYPE_RECORD || t->Tag() == zeek::TYPE_ENUM) &&
old_type_name.empty() )
// An extensible type (record/enum) being declared for first time.
tnew = std::move(t);
@ -373,10 +375,10 @@ void add_type(ID* id, IntrusivePtr<BroType> t,
// Clone the type to preserve type name aliasing.
tnew = t->ShallowClone();
BroType::AddAlias(new_type_name, tnew.get());
zeek::Type::AddAlias(new_type_name, tnew.get());
if ( new_type_name != old_type_name && ! old_type_name.empty() )
BroType::AddAlias(old_type_name, tnew.get());
zeek::Type::AddAlias(old_type_name, tnew.get());
tnew->SetName(id->Name());
@ -384,35 +386,36 @@ void add_type(ID* id, IntrusivePtr<BroType> t,
id->MakeType();
if ( attr )
id->SetAttrs(make_intrusive<Attributes>(std::move(*attr), tnew, false, false));
id->SetAttrs(make_intrusive<zeek::detail::Attributes>(std::move(*attr), tnew, false, false));
}
static void transfer_arg_defaults(RecordType* args, RecordType* recv)
static void transfer_arg_defaults(zeek::RecordType* args, zeek::RecordType* recv)
{
for ( int i = 0; i < args->NumFields(); ++i )
{
TypeDecl* args_i = args->FieldDecl(i);
TypeDecl* recv_i = recv->FieldDecl(i);
zeek::TypeDecl* args_i = args->FieldDecl(i);
zeek::TypeDecl* recv_i = recv->FieldDecl(i);
const auto& def = args_i->attrs ? args_i->attrs->Find(ATTR_DEFAULT) : nullptr;
const auto& def = args_i->attrs ? args_i->attrs->Find(zeek::detail::ATTR_DEFAULT) : nullptr;
if ( ! def )
continue;
if ( ! recv_i->attrs )
{
std::vector<IntrusivePtr<Attr>> a{def};
recv_i->attrs = make_intrusive<Attributes>(std::move(a),
recv_i->type,
true, false);
std::vector<IntrusivePtr<zeek::detail::Attr>> a{def};
recv_i->attrs = make_intrusive<zeek::detail::Attributes>(std::move(a),
recv_i->type,
true, false);
}
else if ( ! recv_i->attrs->Find(ATTR_DEFAULT) )
else if ( ! recv_i->attrs->Find(zeek::detail::ATTR_DEFAULT) )
recv_i->attrs->AddAttr(def);
}
}
static Attr* find_attr(const std::vector<IntrusivePtr<Attr>>* al, attr_tag tag)
static zeek::detail::Attr* find_attr(const std::vector<IntrusivePtr<zeek::detail::Attr>>* al,
zeek::detail::attr_tag tag)
{
if ( ! al )
return nullptr;
@ -424,7 +427,7 @@ static Attr* find_attr(const std::vector<IntrusivePtr<Attr>>* al, attr_tag tag)
return nullptr;
}
static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl, const FuncType* impl)
static std::optional<zeek::FuncType::Prototype> func_type_check(const zeek::FuncType* decl, const zeek::FuncType* impl)
{
if ( decl->Flavor() != impl->Flavor() )
{
@ -432,7 +435,7 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
return {};
}
if ( impl->Flavor() == FUNC_FLAVOR_FUNCTION )
if ( impl->Flavor() == zeek::FUNC_FLAVOR_FUNCTION )
{
if ( same_type(decl, impl) )
return decl->Prototypes()[0];
@ -444,7 +447,7 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
return decl->FindPrototype(*impl->Params());
}
static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl)
static bool canonical_arg_types_match(const zeek::FuncType* decl, const zeek::FuncType* impl)
{
const auto& canon_args = decl->Params();
const auto& impl_args = impl->Params();
@ -459,22 +462,22 @@ static bool canonical_arg_types_match(const FuncType* decl, const FuncType* impl
return true;
}
void begin_func(IntrusivePtr<ID> id, const char* module_name,
function_flavor flavor, bool is_redef,
IntrusivePtr<FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs)
void begin_func(IntrusivePtr<zeek::detail::ID> id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef,
IntrusivePtr<zeek::FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs)
{
if ( flavor == FUNC_FLAVOR_EVENT )
if ( flavor == zeek::FUNC_FLAVOR_EVENT )
{
const auto& yt = t->Yield();
if ( yt && yt->Tag() != TYPE_VOID )
if ( yt && yt->Tag() != zeek::TYPE_VOID )
id->Error("event cannot yield a value", t.get());
t->ClearYieldType(flavor);
}
std::optional<FuncType::Prototype> prototype;
std::optional<zeek::FuncType::Prototype> prototype;
if ( id->GetType() )
{
@ -483,7 +486,7 @@ void begin_func(IntrusivePtr<ID> id, const char* module_name,
if ( prototype )
{
if ( decl->Flavor() == FUNC_FLAVOR_FUNCTION )
if ( decl->Flavor() == zeek::FUNC_FLAVOR_FUNCTION )
{
// If a previous declaration of the function had &default
// params, automatically transfer any that are missing
@ -502,7 +505,7 @@ void begin_func(IntrusivePtr<ID> id, const char* module_name,
{
auto f = args->FieldDecl(i);
if ( f->attrs && f->attrs->Find(ATTR_DEFAULT) )
if ( f->attrs && f->attrs->Find(zeek::detail::ATTR_DEFAULT) )
{
reporter->PushLocation(args->GetLocationInfo());
reporter->Warning(
@ -532,21 +535,21 @@ void begin_func(IntrusivePtr<ID> id, const char* module_name,
if ( id->HasVal() )
{
function_flavor id_flavor = id->GetVal()->AsFunc()->Flavor();
zeek::FunctionFlavor id_flavor = id->GetVal()->AsFunc()->Flavor();
if ( id_flavor != flavor )
id->Error("inconsistent function flavor", t.get());
switch ( id_flavor ) {
case FUNC_FLAVOR_EVENT:
case FUNC_FLAVOR_HOOK:
case zeek::FUNC_FLAVOR_EVENT:
case zeek::FUNC_FLAVOR_HOOK:
if ( is_redef )
// Clear out value so it will be replaced.
id->SetVal(nullptr);
break;
case FUNC_FLAVOR_FUNCTION:
case zeek::FUNC_FLAVOR_FUNCTION:
if ( ! id->IsRedefinable() )
id->Error("already defined");
break;
@ -566,7 +569,7 @@ void begin_func(IntrusivePtr<ID> id, const char* module_name,
for ( int i = 0; i < num_args; ++i )
{
TypeDecl* arg_i = args->FieldDecl(i);
zeek::TypeDecl* arg_i = args->FieldDecl(i);
auto arg_id = lookup_ID(arg_i->id, module_name);
if ( arg_id && ! arg_id->IsGlobal() )
@ -579,8 +582,8 @@ void begin_func(IntrusivePtr<ID> id, const char* module_name,
arg_id->SetOffset(prototype->offsets[i]);
}
if ( Attr* depr_attr = find_attr(current_scope()->Attrs().get(),
ATTR_DEPRECATED) )
if ( zeek::detail::Attr* depr_attr = find_attr(current_scope()->Attrs().get(),
zeek::detail::ATTR_DEPRECATED) )
current_scope()->GetID()->MakeDeprecated(depr_attr->GetExpr());
}
@ -591,26 +594,26 @@ public:
scopes.emplace_back(s);
}
TraversalCode PreExpr(const Expr*) override;
TraversalCode PostExpr(const Expr*) override;
TraversalCode PreExpr(const zeek::detail::Expr*) override;
TraversalCode PostExpr(const zeek::detail::Expr*) override;
std::vector<Scope*> scopes;
std::vector<const NameExpr*> outer_id_references;
std::vector<const zeek::detail::NameExpr*> outer_id_references;
};
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
TraversalCode OuterIDBindingFinder::PreExpr(const zeek::detail::Expr* expr)
{
if ( expr->Tag() == EXPR_LAMBDA )
if ( expr->Tag() == zeek::detail::EXPR_LAMBDA )
{
auto le = static_cast<const LambdaExpr*>(expr);
auto le = static_cast<const zeek::detail::LambdaExpr*>(expr);
scopes.emplace_back(le->GetScope());
return TC_CONTINUE;
}
if ( expr->Tag() != EXPR_NAME )
if ( expr->Tag() != zeek::detail::EXPR_NAME )
return TC_CONTINUE;
const NameExpr* e = static_cast<const NameExpr*>(expr);
auto* e = static_cast<const zeek::detail::NameExpr*>(expr);
if ( e->Id()->IsGlobal() )
return TC_CONTINUE;
@ -625,15 +628,15 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
return TC_CONTINUE;
}
TraversalCode OuterIDBindingFinder::PostExpr(const Expr* expr)
TraversalCode OuterIDBindingFinder::PostExpr(const zeek::detail::Expr* expr)
{
if ( expr->Tag() == EXPR_LAMBDA )
if ( expr->Tag() == zeek::detail::EXPR_LAMBDA )
scopes.pop_back();
return TC_CONTINUE;
}
void end_func(IntrusivePtr<Stmt> body)
void end_func(IntrusivePtr<zeek::detail::Stmt> body)
{
auto ingredients = std::make_unique<function_ingredients>(pop_scope(), std::move(body));
@ -668,7 +671,7 @@ Val* internal_val(const char* name)
return zeek::id::find_val(name).get();
}
id_list gather_outer_ids(Scope* scope, Stmt* body)
id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body)
{
OuterIDBindingFinder cb(scope);
body->Traverse(&cb);
@ -749,7 +752,7 @@ ListVal* internal_list_val(const char* name)
if ( v )
{
if ( v->GetType()->Tag() == TYPE_LIST )
if ( v->GetType()->Tag() == zeek::TYPE_LIST )
return (ListVal*) v;
else if ( v->GetType()->IsSet() )
@ -766,7 +769,7 @@ ListVal* internal_list_val(const char* name)
return nullptr;
}
BroType* internal_type(const char* name)
zeek::Type* internal_type(const char* name)
{
return zeek::id::find_type(name).get();
}

View file

@ -6,47 +6,48 @@
#include "ID.h"
#include "Type.h"
class Expr;
class FuncType;
class Stmt;
class Scope;
class EventHandlerPtr;
class StringVal;
class TableVal;
class ListVal;
ZEEK_FORWARD_DECLARE_NAMESPACED(FuncType, zeek);
ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail);
ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail);
typedef enum { VAR_REGULAR, VAR_CONST, VAR_REDEF, VAR_OPTION, } decl_type;
extern void add_global(const IntrusivePtr<ID>& id,
IntrusivePtr<BroType> t,
init_class c,
IntrusivePtr<Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr,
extern void add_global(const IntrusivePtr<zeek::detail::ID>& id,
IntrusivePtr<zeek::Type> t,
zeek::detail::init_class c,
IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt);
extern IntrusivePtr<Stmt> add_local(IntrusivePtr<ID> id,
IntrusivePtr<BroType> t,
init_class c,
IntrusivePtr<Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr,
decl_type dt);
extern IntrusivePtr<zeek::detail::Stmt> add_local(IntrusivePtr<zeek::detail::ID> id,
IntrusivePtr<zeek::Type> t,
zeek::detail::init_class c,
IntrusivePtr<zeek::detail::Expr> init,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr,
decl_type dt);
extern IntrusivePtr<Expr> add_and_assign_local(IntrusivePtr<ID> id,
IntrusivePtr<Expr> init,
extern IntrusivePtr<zeek::detail::Expr> add_and_assign_local(IntrusivePtr<zeek::detail::ID> id,
IntrusivePtr<zeek::detail::Expr> init,
IntrusivePtr<Val> val = nullptr);
extern void add_type(ID* id, IntrusivePtr<BroType> t,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attr);
extern void add_type(zeek::detail::ID* id, IntrusivePtr<zeek::Type> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attr);
extern void begin_func(IntrusivePtr<ID> id, const char* module_name,
function_flavor flavor, bool is_redef,
IntrusivePtr<FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<Attr>>> attrs = nullptr);
extern void begin_func(IntrusivePtr<zeek::detail::ID> id, const char* module_name,
zeek::FunctionFlavor flavor, bool is_redef,
IntrusivePtr<zeek::FuncType> t,
std::unique_ptr<std::vector<IntrusivePtr<zeek::detail::Attr>>> attrs = nullptr);
extern void end_func(IntrusivePtr<Stmt> body);
extern void end_func(IntrusivePtr<zeek::detail::Stmt> body);
// Gather all IDs referenced inside a body that aren't part of a given scope.
extern id_list gather_outer_ids(Scope* scope, Stmt* body);
extern id_list gather_outer_ids(Scope* scope, zeek::detail::Stmt* body);
[[deprecated("Remove in v4.1. Use zeek::id::find_val().")]]
extern Val* internal_val(const char* name);
@ -76,7 +77,7 @@ extern TableVal* opt_internal_table(const char* name); // nil if not defined
extern ListVal* internal_list_val(const char* name);
[[deprecated("Remove in v4.1. Use zeek::id::find_type().")]]
extern BroType* internal_type(const char* name);
extern zeek::Type* internal_type(const char* name);
[[deprecated("Remove in v4.1. Use zeek::id::find_func().")]]
extern Func* internal_func(const char* name);

View file

@ -9,7 +9,7 @@
using namespace analyzer;
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype, bool arg_enabled, bool arg_partial)
: plugin::Component(plugin::component::ANALYZER, name),
: zeek::plugin::Component(zeek::plugin::component::ANALYZER, name),
plugin::TaggedComponent<analyzer::Tag>(arg_subtype)
{
factory = arg_factory;

View file

@ -21,7 +21,7 @@ class Analyzer;
* A plugin can provide a specific protocol analyzer by registering this
* analyzer component, describing the analyzer.
*/
class Component : public plugin::Component,
class Component : public zeek::plugin::Component,
public plugin::TaggedComponent<analyzer::Tag> {
public:
typedef Analyzer* (*factory_callback)(Connection* conn);

View file

@ -7,11 +7,17 @@
class EnumVal;
namespace zeek::plugin {
template <class T> class TaggedComponent;
template <class T, class C> class ComponentManager;
}
namespace plugin {
template <class T>
class TaggedComponent;
template <class T, class C>
class ComponentManager;
template <class T>
using TaggedComponent [[deprecated("Remove in v4.1. Use zeek::plugin::TaggedComponent instead.")]] =
zeek::plugin::TaggedComponent<T>;
template <class T, class C>
using ComponentManager [[deprecated("Remove in v4.1. Use zeek::plugin::ComponentManager instead.")]] =
zeek::plugin::ComponentManager<T, C>;
}
namespace analyzer {
@ -92,8 +98,8 @@ public:
protected:
friend class analyzer::Manager;
friend class plugin::ComponentManager<Tag, Component>;
friend class plugin::TaggedComponent<Tag>;
friend class zeek::plugin::ComponentManager<Tag, Component>;
friend class zeek::plugin::TaggedComponent<Tag>;
/**
* Constructor.

View file

@ -6,11 +6,11 @@
namespace plugin {
namespace Zeek_ARP {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::ARP";
config.description = "ARP Parsing";
return config;

View file

@ -3,8 +3,8 @@
%}
%header{
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, TypeTag t);
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, TypeTag t);
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t);
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t);
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1Encoding* oid);
IntrusivePtr<StringVal> asn1_oid_to_val(const ASN1ObjectIdentifier* oid);
IntrusivePtr<StringVal> asn1_octet_string_to_val(const ASN1Encoding* s);
@ -102,25 +102,25 @@ function binary_to_int64(bs: bytestring): int64
%code{
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, TypeTag t)
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Integer* i, zeek::TypeTag t)
{
return asn1_integer_to_val(i->encoding(), t);
}
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, TypeTag t)
IntrusivePtr<Val> asn1_integer_to_val(const ASN1Encoding* i, zeek::TypeTag t)
{
auto v = binary_to_int64(i->content());
switch ( t ) {
case TYPE_BOOL:
case zeek::TYPE_BOOL:
return val_mgr->Bool(v);
case TYPE_INT:
case zeek::TYPE_INT:
return val_mgr->Int(v);
case TYPE_COUNT:
case TYPE_COUNTER:
case zeek::TYPE_COUNT:
case zeek::TYPE_COUNTER:
return val_mgr->Count(v);
default:
reporter->Error("bad asn1_integer_to_val tag: %s", type_name(t));
reporter->Error("bad asn1_integer_to_val tag: %s", zeek::type_name(t));
return val_mgr->Count(v);
}
}

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_AYIYA {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("AYIYA", ::analyzer::ayiya::AYIYA_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::AYIYA";
config.description = "AYIYA Analyzer";
return config;

View file

@ -15,11 +15,11 @@
using namespace analyzer::bittorrent;
static IntrusivePtr<TableType> bt_tracker_headers;
static IntrusivePtr<RecordType> bittorrent_peer;
static IntrusivePtr<TableType> bittorrent_peer_set;
static IntrusivePtr<RecordType> bittorrent_benc_value;
static IntrusivePtr<TableType> bittorrent_benc_dir;
static IntrusivePtr<zeek::TableType> bt_tracker_headers;
static IntrusivePtr<zeek::RecordType> bittorrent_peer;
static IntrusivePtr<zeek::TableType> bittorrent_peer_set;
static IntrusivePtr<zeek::RecordType> bittorrent_benc_value;
static IntrusivePtr<zeek::TableType> bittorrent_benc_dir;
BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c)
: tcp::TCP_ApplicationAnalyzer("BITTORRENTTRACKER", c)
@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c)
if ( ! bt_tracker_headers )
{
bt_tracker_headers =
zeek::id::find_type<TableType>("bt_tracker_headers");
zeek::id::find_type<zeek::TableType>("bt_tracker_headers");
bittorrent_peer =
zeek::id::find_type<RecordType>("bittorrent_peer");
zeek::id::find_type<zeek::RecordType>("bittorrent_peer");
bittorrent_peer_set =
zeek::id::find_type<TableType>("bittorrent_peer_set");
zeek::id::find_type<zeek::TableType>("bittorrent_peer_set");
bittorrent_benc_value =
zeek::id::find_type<RecordType>("bittorrent_benc_value");
zeek::id::find_type<zeek::RecordType>("bittorrent_benc_value");
bittorrent_benc_dir =
zeek::id::find_type<TableType>("bittorrent_benc_dir");
zeek::id::find_type<zeek::TableType>("bittorrent_benc_dir");
}
keep_alive = false;

View file

@ -8,14 +8,14 @@
namespace plugin {
namespace Zeek_BitTorrent {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("BitTorrent", ::analyzer::bittorrent::BitTorrent_Analyzer::Instantiate));
AddComponent(new ::analyzer::Component("BitTorrentTracker", ::analyzer::bittorrent::BitTorrentTracker_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::BitTorrent";
config.description = "BitTorrent Analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_ConnSize {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("ConnSize", ::analyzer::conn_size::ConnSize_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::ConnSize";
config.description = "Connection size analyzer";
return config;

View file

@ -8,13 +8,13 @@
namespace plugin {
namespace Zeek_DCE_RPC {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("DCE_RPC", ::analyzer::dce_rpc::DCE_RPC_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::DCE_RPC";
config.description = "DCE-RPC analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_DHCP {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("DHCP", ::analyzer::dhcp::DHCP_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::DHCP";
config.description = "DHCP analyzer";
return config;

View file

@ -119,4 +119,3 @@ refine typeattr DHCP_Message += &let {
refine typeattr Option += &let {
proc_create_options = $context.flow.create_options(code);
};

View file

@ -7,14 +7,14 @@
namespace plugin {
namespace Zeek_DNP3 {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("DNP3_TCP", ::analyzer::dnp3::DNP3_TCP_Analyzer::Instantiate));
AddComponent(new ::analyzer::Component("DNP3_UDP", ::analyzer::dnp3::DNP3_UDP_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::DNP3";
config.description = "DNP3 UDP/TCP analyzers";
return config;

View file

@ -594,7 +594,7 @@ bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg,
if ( dns_SOA_reply && ! msg->skip_event )
{
static auto dns_soa = zeek::id::find_type<RecordType>("dns_soa");
static auto dns_soa = zeek::id::find_type<zeek::RecordType>("dns_soa");
auto r = make_intrusive<RecordVal>(dns_soa);
r->Assign(0, make_intrusive<StringVal>(new BroString(mname, mname_end - mname, true)));
r->Assign(1, make_intrusive<StringVal>(new BroString(rname, rname_end - rname, true)));
@ -1438,7 +1438,7 @@ DNS_MsgInfo::DNS_MsgInfo(DNS_RawMsgHdr* hdr, int arg_is_query)
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal()
{
static auto dns_msg = zeek::id::find_type<RecordType>("dns_msg");
static auto dns_msg = zeek::id::find_type<zeek::RecordType>("dns_msg");
auto r = make_intrusive<RecordVal>(dns_msg);
r->Assign(0, val_mgr->Count(id));
@ -1460,7 +1460,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildHdrVal()
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildAnswerVal()
{
static auto dns_answer = zeek::id::find_type<RecordType>("dns_answer");
static auto dns_answer = zeek::id::find_type<zeek::RecordType>("dns_answer");
auto r = make_intrusive<RecordVal>(dns_answer);
r->Assign(0, val_mgr->Count(int(answer_type)));
@ -1476,7 +1476,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val()
{
// We have to treat the additional record type in EDNS differently
// than a regular resource record.
static auto dns_edns_additional = zeek::id::find_type<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);
r->Assign(0, val_mgr->Count(int(answer_type)));
@ -1510,7 +1510,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildEDNS_Val()
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig)
{
static auto dns_tsig_additional = zeek::id::find_type<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);
double rtime = tsig->time_s + tsig->time_ms / 1000.0;
@ -1530,7 +1530,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildTSIG_Val(struct TSIG_DATA* tsig)
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig)
{
static auto dns_rrsig_rr = zeek::id::find_type<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);
r->Assign(0, query_name);
@ -1551,7 +1551,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildRRSIG_Val(RRSIG_DATA* rrsig)
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey)
{
static auto dns_dnskey_rr = zeek::id::find_type<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);
r->Assign(0, query_name);
@ -1567,7 +1567,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDNSKEY_Val(DNSKEY_DATA* dnskey)
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3)
{
static auto dns_nsec3_rr = zeek::id::find_type<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);
r->Assign(0, query_name);
@ -1587,7 +1587,7 @@ IntrusivePtr<RecordVal> DNS_MsgInfo::BuildNSEC3_Val(NSEC3_DATA* nsec3)
IntrusivePtr<RecordVal> DNS_MsgInfo::BuildDS_Val(DS_DATA* ds)
{
static auto dns_ds_rr = zeek::id::find_type<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);
r->Assign(0, query_name);

View file

@ -7,14 +7,14 @@
namespace plugin {
namespace Zeek_DNS {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("DNS", ::analyzer::dns::DNS_Analyzer::Instantiate));
AddComponent(new ::analyzer::Component("Contents_DNS", nullptr));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::DNS";
config.description = "DNS analyzer";
return config;

View file

@ -7,14 +7,14 @@
namespace plugin {
namespace Zeek_File {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("FTP_Data", ::analyzer::file::FTP_Data::Instantiate));
AddComponent(new ::analyzer::Component("IRC_Data", ::analyzer::file::IRC_Data::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::File";
config.description = "Generic file analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_Finger {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("Finger", ::analyzer::finger::Finger_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::Finger";
config.description = "Finger analyzer";
return config;

View file

@ -7,14 +7,14 @@
namespace plugin {
namespace Zeek_FTP {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("FTP", ::analyzer::ftp::FTP_Analyzer::Instantiate));
AddComponent(new ::analyzer::Component("FTP_ADAT", nullptr));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::FTP";
config.description = "FTP analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_Gnutella {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("Gnutella", ::analyzer::gnutella::Gnutella_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::Gnutella";
config.description = "Gnutella analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_GSSAPI {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("GSSAPI", ::analyzer::gssapi::GSSAPI_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::GSSAPI";
config.description = "GSSAPI analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_GTPv1 {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("GTPv1", ::analyzer::gtpv1::GTPv1_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::GTPv1";
config.description = "GTPv1 analyzer";
return config;

View file

@ -615,7 +615,7 @@ HTTP_Message::~HTTP_Message()
IntrusivePtr<RecordVal> HTTP_Message::BuildMessageStat(bool interrupted, const char* msg)
{
static auto http_message_stat = zeek::id::find_type<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);
int field = 0;
stat->Assign(field++, make_intrusive<TimeVal>(start_time));
@ -1152,7 +1152,7 @@ void HTTP_Analyzer::GenStats()
{
if ( http_stats )
{
static auto http_stats_rec = zeek::id::find_type<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);
r->Assign(0, val_mgr->Count(num_requests));
r->Assign(1, val_mgr->Count(num_replies));

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_HTTP {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("HTTP", ::analyzer::http::HTTP_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::HTTP";
config.description = "HTTP analyzer";
return config;

View file

@ -225,7 +225,7 @@ ICMP_Analyzer::BuildICMPVal(const struct icmp* icmpp, int len,
{
if ( ! icmp_conn_val )
{
static auto icmp_conn = zeek::id::find_type<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->Assign(0, make_intrusive<AddrVal>(Conn()->OrigAddr()));
@ -351,7 +351,7 @@ IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP4Context(int len, const u_char
}
}
static auto icmp_context = zeek::id::find_type<RecordType>("icmp_context");
static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context");
auto iprec = make_intrusive<RecordVal>(icmp_context);
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id);
@ -411,7 +411,7 @@ IntrusivePtr<RecordVal> ICMP_Analyzer::ExtractICMP6Context(int len, const u_char
}
}
static auto icmp_context = zeek::id::find_type<RecordType>("icmp_context");
static auto icmp_context = zeek::id::find_type<zeek::RecordType>("icmp_context");
auto iprec = make_intrusive<RecordVal>(icmp_context);
auto id_val = make_intrusive<RecordVal>(zeek::id::conn_id);
@ -724,11 +724,11 @@ void ICMP_Analyzer::Context6(double t, const struct icmp* icmpp,
IntrusivePtr<VectorVal> ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data)
{
static auto icmp6_nd_option_type = zeek::id::find_type<RecordType>("icmp6_nd_option");
static auto icmp6_nd_prefix_info_type = zeek::id::find_type<RecordType>("icmp6_nd_prefix_info");
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");
auto vv = make_intrusive<VectorVal>(
zeek::id::find_type<VectorType>("icmp6_nd_options"));
zeek::id::find_type<zeek::VectorType>("icmp6_nd_options"));
while ( caplen > 0 )
{

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_ICMP {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("ICMP", ::analyzer::icmp::ICMP_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::ICMP";
config.description = "ICMP analyzer";
return config;

View file

@ -7,13 +7,13 @@
namespace plugin {
namespace Zeek_Ident {
class Plugin : public plugin::Plugin {
class Plugin : public zeek::plugin::Plugin {
public:
plugin::Configuration Configure() override
zeek::plugin::Configuration Configure() override
{
AddComponent(new ::analyzer::Component("Ident", ::analyzer::ident::Ident_Analyzer::Instantiate));
plugin::Configuration config;
zeek::plugin::Configuration config;
config.name = "Zeek::Ident";
config.description = "Ident analyzer";
return config;

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