mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Deprecate Scope::Lookup(), replace with Scope::Find()
This commit is contained in:
parent
a5762c12cc
commit
8f95a2a0bb
27 changed files with 65 additions and 72 deletions
2
NEWS
2
NEWS
|
@ -174,6 +174,8 @@ Deprecated Functionality
|
|||
- Most global type/value pointers in NetVar.h are deprecated, but one can
|
||||
still always perform the lookup themselves.
|
||||
|
||||
- ``Scope::Lookup()`` is deprecated, use ``Scope::Find()``.
|
||||
|
||||
Zeek 3.1.0
|
||||
==========
|
||||
|
||||
|
|
|
@ -368,17 +368,17 @@ void init_ip_addr_anonymizers()
|
|||
ip_anonymizer[PREFIX_PRESERVING_A50] = new AnonymizeIPAddr_A50();
|
||||
ip_anonymizer[PREFIX_PRESERVING_MD5] = new AnonymizeIPAddr_PrefixMD5();
|
||||
|
||||
auto id = global_scope()->Lookup("preserve_orig_addr");
|
||||
auto id = global_scope()->Find("preserve_orig_addr");
|
||||
|
||||
if ( id )
|
||||
anon_preserve_orig_addr = cast_intrusive<TableVal>(id->GetVal());
|
||||
|
||||
id = global_scope()->Lookup("preserve_resp_addr");
|
||||
id = global_scope()->Find("preserve_resp_addr");
|
||||
|
||||
if ( id )
|
||||
anon_preserve_resp_addr = cast_intrusive<TableVal>(id->GetVal());
|
||||
|
||||
id = global_scope()->Lookup("preserve_other_addr");
|
||||
id = global_scope()->Find("preserve_other_addr");
|
||||
|
||||
if ( id )
|
||||
anon_preserve_other_addr = cast_intrusive<TableVal>(id->GetVal());
|
||||
|
|
|
@ -4227,7 +4227,7 @@ LambdaExpr::LambdaExpr(std::unique_ptr<function_ingredients> arg_ing,
|
|||
|
||||
my_name = "lambda_<" + std::to_string(h[0]) + ">";
|
||||
auto fullname = make_full_var_name(current_module.data(), my_name.data());
|
||||
auto id = global_scope()->Lookup(fullname);
|
||||
const auto& id = global_scope()->Find(fullname);
|
||||
|
||||
if ( id )
|
||||
// Just try again to make a unique lambda name. If two peer
|
||||
|
|
15
src/ID.cc
15
src/ID.cc
|
@ -31,19 +31,14 @@ IntrusivePtr<TableType> zeek::id::count_set;
|
|||
IntrusivePtr<VectorType> zeek::id::string_vec;
|
||||
IntrusivePtr<VectorType> zeek::id::index_vec;
|
||||
|
||||
IntrusivePtr<ID> zeek::id::lookup(const char* name)
|
||||
const IntrusivePtr<ID>& zeek::id::lookup(const char* name)
|
||||
{
|
||||
auto id = global_scope()->Lookup(name);
|
||||
|
||||
if ( ! id )
|
||||
return nullptr;
|
||||
|
||||
return {NewRef{}, id};
|
||||
return global_scope()->Find(name);
|
||||
}
|
||||
|
||||
const IntrusivePtr<BroType>& zeek::id::lookup_type(const char* name)
|
||||
{
|
||||
auto id = zeek::id::lookup(name);
|
||||
auto id = global_scope()->Find(name);
|
||||
|
||||
if ( ! id )
|
||||
reporter->InternalError("Failed to find type named: %s", name);
|
||||
|
@ -53,7 +48,7 @@ const IntrusivePtr<BroType>& zeek::id::lookup_type(const char* name)
|
|||
|
||||
const IntrusivePtr<Val>& zeek::id::lookup_val(const char* name)
|
||||
{
|
||||
auto id = zeek::id::lookup(name);
|
||||
auto id = global_scope()->Find(name);
|
||||
|
||||
if ( ! id )
|
||||
reporter->InternalError("Failed to find variable named: %s", name);
|
||||
|
@ -63,7 +58,7 @@ const IntrusivePtr<Val>& zeek::id::lookup_val(const char* name)
|
|||
|
||||
const IntrusivePtr<Val>& zeek::id::lookup_const(const char* name)
|
||||
{
|
||||
auto id = zeek::id::lookup(name);
|
||||
auto id = global_scope()->Find(name);
|
||||
|
||||
if ( ! id )
|
||||
reporter->InternalError("Failed to find variable named: %s", name);
|
||||
|
|
2
src/ID.h
2
src/ID.h
|
@ -165,7 +165,7 @@ namespace zeek { namespace id {
|
|||
* @return The identifier, which may reference a nil object if no such
|
||||
* name exists.
|
||||
*/
|
||||
IntrusivePtr<ID> lookup(const char* name);
|
||||
const IntrusivePtr<ID>& lookup(const char* name);
|
||||
|
||||
/**
|
||||
* Lookup an ID by its name and return its type. A fatal occurs if the ID
|
||||
|
|
|
@ -193,7 +193,7 @@ void net_init(const std::optional<std::string>& interface,
|
|||
reporter->FatalError("problem opening dump file %s (%s)",
|
||||
writefile, pkt_dumper->ErrorMsg());
|
||||
|
||||
if ( ID* id = global_scope()->Lookup("trace_output_file") )
|
||||
if ( const auto& id = global_scope()->Find("trace_output_file") )
|
||||
id->SetVal(make_intrusive<StringVal>(writefile));
|
||||
else
|
||||
reporter->Error("trace_output_file not defined in bro.init");
|
||||
|
|
|
@ -126,7 +126,7 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
|
|||
if ( ! name )
|
||||
return nullptr;
|
||||
|
||||
ID* id = global_scope()->Lookup(*name);
|
||||
const auto& id = global_scope()->Find(*name);
|
||||
if ( ! id )
|
||||
return nullptr;
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ bool RuleConditionPayloadSize::DoMatch(Rule* rule, RuleEndpointState* state,
|
|||
|
||||
RuleConditionEval::RuleConditionEval(const char* func)
|
||||
{
|
||||
id = global_scope()->Lookup(func);
|
||||
id = global_scope()->Find(func).get();
|
||||
if ( ! id )
|
||||
{
|
||||
rules_error("unknown identifier", func);
|
||||
|
|
|
@ -129,14 +129,15 @@ IntrusivePtr<ID> lookup_ID(const char* name, const char* curr_module,
|
|||
|
||||
for ( int i = scopes.length() - 1; i >= 0; --i )
|
||||
{
|
||||
ID* id = scopes[i]->Lookup(fullname);
|
||||
const auto& id = scopes[i]->Find(fullname);
|
||||
|
||||
if ( id )
|
||||
{
|
||||
if ( need_export && ! id->IsExport() && ! in_debug )
|
||||
reporter->Error("identifier is not exported: %s",
|
||||
fullname.c_str());
|
||||
|
||||
return {NewRef{}, id};
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -144,9 +145,7 @@ IntrusivePtr<ID> lookup_ID(const char* name, const char* curr_module,
|
|||
! same_module_only) )
|
||||
{
|
||||
std::string globalname = make_full_var_name(GLOBAL_MODULE_NAME, name);
|
||||
ID* id = global_scope()->Lookup(globalname);
|
||||
if ( id )
|
||||
return {NewRef{}, id};
|
||||
return global_scope()->Find(globalname);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
14
src/Scope.h
14
src/Scope.h
|
@ -22,14 +22,22 @@ public:
|
|||
~Scope() override;
|
||||
|
||||
template<typename N>
|
||||
ID* Lookup(N&& name) const
|
||||
const IntrusivePtr<ID>& Find(N&& name) const
|
||||
{
|
||||
static IntrusivePtr<ID> nil;
|
||||
const auto& entry = local.find(std::forward<N>(name));
|
||||
|
||||
if ( entry != local.end() )
|
||||
return entry->second.get();
|
||||
return entry->second;
|
||||
|
||||
return nullptr;
|
||||
return nil;
|
||||
}
|
||||
|
||||
template<typename N>
|
||||
[[deprecated("Remove in v4.1. Use Find().")]]
|
||||
ID* Lookup(N&& name) const
|
||||
{
|
||||
return Find(name).get();
|
||||
}
|
||||
|
||||
template<typename N, typename I>
|
||||
|
|
|
@ -1766,7 +1766,7 @@ IntrusivePtr<BroType> merge_types(const BroType* t1, const BroType* t2)
|
|||
// Doing a lookup here as a roundabout way of ref-ing t1, without
|
||||
// changing the function params which has t1 as const and also
|
||||
// (potentially) avoiding a pitfall mentioned earlier about clones.
|
||||
auto id = global_scope()->Lookup(t1->GetName());
|
||||
const auto& id = global_scope()->Find(t1->GetName());
|
||||
|
||||
if ( id && id->IsType() && id->GetType()->Tag() == TYPE_ENUM )
|
||||
// It should make most sense to return the real type here rather
|
||||
|
|
|
@ -371,7 +371,7 @@ void Val::ValDescribeReST(ODesc* d) const
|
|||
#ifdef DEBUG
|
||||
ID* Val::GetID() const
|
||||
{
|
||||
return bound_id ? global_scope()->Lookup(bound_id) : nullptr;
|
||||
return bound_id ? global_scope()->Find(bound_id).get() : nullptr;
|
||||
}
|
||||
|
||||
void Val::SetID(ID* id)
|
||||
|
|
|
@ -609,7 +609,7 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr)
|
|||
return TC_CONTINUE;
|
||||
|
||||
for ( const auto& scope : scopes )
|
||||
if ( scope->Lookup(e->Id()->Name()) )
|
||||
if ( scope->Find(e->Id()->Name()) )
|
||||
// Shadowing is not allowed, so if it's found at inner scope, it's
|
||||
// not something we have to worry about also being at outer scope.
|
||||
return TC_CONTINUE;
|
||||
|
|
|
@ -90,7 +90,7 @@ void Manager::InitPreScript()
|
|||
|
||||
void Manager::InitPostScript()
|
||||
{
|
||||
auto id = global_scope()->Lookup("Tunnel::vxlan_ports");
|
||||
const auto& id = global_scope()->Find("Tunnel::vxlan_ports");
|
||||
|
||||
if ( ! (id && id->GetVal()) )
|
||||
reporter->FatalError("Tunnel::vxlan_ports not defined");
|
||||
|
|
|
@ -9,20 +9,10 @@
|
|||
|
||||
using namespace analyzer::MQTT;
|
||||
|
||||
const ::ID* MQTT_Analyzer::max_payload_size = nullptr;
|
||||
|
||||
MQTT_Analyzer::MQTT_Analyzer(Connection* c)
|
||||
: tcp::TCP_ApplicationAnalyzer("MQTT", c)
|
||||
{
|
||||
interp = new binpac::MQTT::MQTT_Conn(this);
|
||||
|
||||
if ( ! max_payload_size )
|
||||
{
|
||||
max_payload_size = global_scope()->Lookup("MQTT::max_payload_size");
|
||||
|
||||
if ( ! max_payload_size )
|
||||
reporter->FatalError("option not defined: 'MQTT::max_payload_size'");
|
||||
}
|
||||
}
|
||||
|
||||
MQTT_Analyzer::~MQTT_Analyzer()
|
||||
|
|
|
@ -23,8 +23,6 @@ public:
|
|||
static analyzer::Analyzer* InstantiateAnalyzer(Connection* conn)
|
||||
{ return new MQTT_Analyzer(conn); }
|
||||
|
||||
static const ::ID* max_payload_size;
|
||||
|
||||
protected:
|
||||
binpac::MQTT::MQTT_Conn* interp;
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@ refine flow MQTT_Flow += {
|
|||
reinterpret_cast<const char*>(${msg.topic.str}.begin())));
|
||||
|
||||
auto len = ${msg.payload}.length();
|
||||
auto max = analyzer::MQTT::MQTT_Analyzer::max_payload_size->GetVal()->AsCount();
|
||||
static auto max_payload_size = zeek::id::lookup("MQTT::max_payload_size");
|
||||
auto max = max_payload_size->GetVal()->AsCount();
|
||||
|
||||
if ( len > static_cast<int>(max) )
|
||||
len = max;
|
||||
|
|
|
@ -353,7 +353,7 @@ struct val_converter {
|
|||
if ( ! name )
|
||||
return nullptr;
|
||||
|
||||
auto id = global_scope()->Lookup(*name);
|
||||
const auto& id = global_scope()->Find(*name);
|
||||
if ( ! id )
|
||||
return nullptr;
|
||||
|
||||
|
@ -697,7 +697,7 @@ struct type_checker {
|
|||
if ( ! name )
|
||||
return false;
|
||||
|
||||
auto id = global_scope()->Lookup(*name);
|
||||
const auto& id = global_scope()->Find(*name);
|
||||
if ( ! id )
|
||||
return false;
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace bro_broker {
|
|||
|
||||
static inline Val* get_option(const char* option)
|
||||
{
|
||||
auto id = global_scope()->Lookup(option);
|
||||
const auto& id = global_scope()->Find(option);
|
||||
|
||||
if ( ! (id && id->GetVal()) )
|
||||
reporter->FatalError("Unknown Broker option %s", option);
|
||||
|
@ -412,7 +412,7 @@ bool Manager::PublishIdentifier(std::string topic, std::string id)
|
|||
if ( peer_count == 0 )
|
||||
return true;
|
||||
|
||||
ID* i = global_scope()->Lookup(id);
|
||||
const auto& i = global_scope()->Find(id);
|
||||
|
||||
if ( ! i )
|
||||
return false;
|
||||
|
@ -1186,7 +1186,7 @@ bool Manager::ProcessIdentifierUpdate(broker::zeek::IdentifierUpdate iu)
|
|||
++statistics.num_ids_incoming;
|
||||
auto id_name = std::move(iu.id_name());
|
||||
auto id_value = std::move(iu.id_value());
|
||||
auto id = global_scope()->Lookup(id_name);
|
||||
const auto& id = global_scope()->Find(id_name);
|
||||
|
||||
if ( ! id )
|
||||
{
|
||||
|
|
|
@ -185,7 +185,7 @@ function Cluster::publish_rr%(pool: Pool, key: string, ...%): bool
|
|||
static Func* topic_func = 0;
|
||||
|
||||
if ( ! topic_func )
|
||||
topic_func = global_scope()->Lookup("Cluster::rr_topic")->GetVal()->AsFunc();
|
||||
topic_func = global_scope()->Find("Cluster::rr_topic")->GetVal()->AsFunc();
|
||||
|
||||
zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}};
|
||||
auto topic = topic_func->Call(vl);
|
||||
|
@ -222,7 +222,7 @@ function Cluster::publish_hrw%(pool: Pool, key: any, ...%): bool
|
|||
static Func* topic_func = 0;
|
||||
|
||||
if ( ! topic_func )
|
||||
topic_func = global_scope()->Lookup("Cluster::hrw_topic")->GetVal()->AsFunc();
|
||||
topic_func = global_scope()->Find("Cluster::hrw_topic")->GetVal()->AsFunc();
|
||||
|
||||
zeek::Args vl{{NewRef{}, pool}, {NewRef{}, key}};
|
||||
auto topic = topic_func->Call(vl);
|
||||
|
|
|
@ -2498,7 +2498,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co
|
|||
// Enums are not a base-type, so need to look it up.
|
||||
const auto& sv = val->val.set_val.vals[0]->val.string_val;
|
||||
std::string enum_name(sv.data, sv.length);
|
||||
auto enum_id = global_scope()->Lookup(enum_name);
|
||||
const auto& enum_id = global_scope()->Find(enum_name);
|
||||
|
||||
if ( ! enum_id )
|
||||
{
|
||||
|
|
|
@ -1182,7 +1182,7 @@ WriterFrontend* Manager::CreateWriter(EnumVal* id, EnumVal* writer, WriterBacken
|
|||
|
||||
if ( ! found_filter_match )
|
||||
{
|
||||
ID* id = global_scope()->Lookup("Log::default_rotation_interval");
|
||||
const auto& id = global_scope()->Find("Log::default_rotation_interval");
|
||||
assert(id);
|
||||
winfo->interval = id->GetVal()->AsInterval();
|
||||
}
|
||||
|
@ -1525,7 +1525,7 @@ bool Manager::FinishedRotation(WriterFrontend* writer, const char* new_name, con
|
|||
Func* func = winfo->postprocessor;
|
||||
if ( ! func )
|
||||
{
|
||||
ID* id = global_scope()->Lookup("Log::__default_rotation_postprocessor");
|
||||
const auto& id = global_scope()->Find("Log::__default_rotation_postprocessor");
|
||||
assert(id);
|
||||
func = id->GetVal()->AsFunc();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ module Option;
|
|||
#include "NetVar.h"
|
||||
#include "broker/Data.h"
|
||||
|
||||
static bool call_option_handlers_and_set_value(StringVal* name, ID* i,
|
||||
static bool call_option_handlers_and_set_value(StringVal* name, const IntrusivePtr<ID>& i,
|
||||
IntrusivePtr<Val> val,
|
||||
StringVal* location)
|
||||
{
|
||||
|
@ -59,7 +59,7 @@ static bool call_option_handlers_and_set_value(StringVal* name, ID* i,
|
|||
## lower-level function.
|
||||
function Option::set%(ID: string, val: any, location: string &default=""%): bool
|
||||
%{
|
||||
auto i = global_scope()->Lookup(ID->CheckString());
|
||||
const auto& i = global_scope()->Find(ID->CheckString());
|
||||
if ( ! i )
|
||||
{
|
||||
builtin_error(fmt("Could not find ID named '%s'", ID->CheckString()));
|
||||
|
@ -144,7 +144,7 @@ function Option::set%(ID: string, val: any, location: string &default=""%): bool
|
|||
## .. zeek:see:: Option::set
|
||||
function Option::set_change_handler%(ID: string, on_change: any, priority: int &default=0%): bool
|
||||
%{
|
||||
auto i = global_scope()->Lookup(ID->CheckString());
|
||||
const auto& i = global_scope()->Find(ID->CheckString());
|
||||
if ( ! i )
|
||||
{
|
||||
builtin_error(fmt("Could not find ID named '%s'", ID->CheckString()));
|
||||
|
|
|
@ -1172,7 +1172,7 @@ IntrusivePtr<RecordVal> Supervisor::Node::ToRecord() const
|
|||
|
||||
static IntrusivePtr<Val> supervisor_role_to_cluster_node_type(BifEnum::Supervisor::ClusterRole role)
|
||||
{
|
||||
static auto node_type = global_scope()->Lookup("Cluster::NodeType")->GetType()->AsEnumType();
|
||||
static auto node_type = global_scope()->Find("Cluster::NodeType")->GetType()->AsEnumType();
|
||||
|
||||
switch ( role ) {
|
||||
case BifEnum::Supervisor::LOGGER:
|
||||
|
@ -1193,9 +1193,9 @@ bool Supervisor::SupervisedNode::InitCluster() const
|
|||
if ( config.cluster.empty() )
|
||||
return false;
|
||||
|
||||
auto cluster_node_type = global_scope()->Lookup("Cluster::Node")->GetType()->AsRecordType();
|
||||
auto cluster_nodes_id = global_scope()->Lookup("Cluster::nodes");
|
||||
auto cluster_manager_is_logger_id = global_scope()->Lookup("Cluster::manager_is_logger");
|
||||
const auto& cluster_node_type = global_scope()->Find("Cluster::Node")->GetType()->AsRecordType();
|
||||
const auto& cluster_nodes_id = global_scope()->Find("Cluster::nodes");
|
||||
const auto& cluster_manager_is_logger_id = global_scope()->Find("Cluster::manager_is_logger");
|
||||
auto cluster_nodes = cluster_nodes_id->GetVal()->AsTableVal();
|
||||
auto has_logger = false;
|
||||
std::optional<std::string> manager_name;
|
||||
|
|
|
@ -630,11 +630,11 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
|||
// Must come after plugin activation (and also after hash
|
||||
// initialization).
|
||||
binpac::FlowBuffer::Policy flowbuffer_policy;
|
||||
flowbuffer_policy.max_capacity = global_scope()->Lookup(
|
||||
flowbuffer_policy.max_capacity = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_capacity_max")->GetVal()->AsCount();
|
||||
flowbuffer_policy.min_capacity = global_scope()->Lookup(
|
||||
flowbuffer_policy.min_capacity = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_capacity_min")->GetVal()->AsCount();
|
||||
flowbuffer_policy.contract_threshold = global_scope()->Lookup(
|
||||
flowbuffer_policy.contract_threshold = global_scope()->Find(
|
||||
"BinPAC::flowbuffer_contract_threshold")->GetVal()->AsCount();
|
||||
binpac::init(&flowbuffer_policy);
|
||||
|
||||
|
@ -685,7 +685,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
|||
|
||||
if ( options.pcap_filter )
|
||||
{
|
||||
ID* id = global_scope()->Lookup("cmd_line_bpf_filter");
|
||||
const auto& id = global_scope()->Find("cmd_line_bpf_filter");
|
||||
|
||||
if ( ! id )
|
||||
reporter->InternalError("global cmd_line_bpf_filter not defined");
|
||||
|
@ -769,7 +769,7 @@ zeek::detail::SetupResult zeek::detail::setup(int argc, char** argv,
|
|||
// Print the ID.
|
||||
if ( options.identifier_to_print )
|
||||
{
|
||||
ID* id = global_scope()->Lookup(*options.identifier_to_print);
|
||||
const auto& id = global_scope()->Find(*options.identifier_to_print);
|
||||
if ( ! id )
|
||||
reporter->FatalError("No such ID: %s\n", options.identifier_to_print->data());
|
||||
|
||||
|
|
|
@ -1975,7 +1975,7 @@ function global_ids%(%): id_table
|
|||
## the string ``"<unknown id>"`` or ``"<no ID value>"`` is returned.
|
||||
function lookup_ID%(id: string%) : any
|
||||
%{
|
||||
ID* i = global_scope()->Lookup(id->CheckString());
|
||||
const auto& i = global_scope()->Find(id->CheckString());
|
||||
if ( ! i )
|
||||
return make_intrusive<StringVal>("<unknown id>");
|
||||
|
||||
|
@ -1998,7 +1998,7 @@ function record_fields%(rec: any%): record_field_table
|
|||
|
||||
if ( rec->GetType()->Tag() == TYPE_STRING )
|
||||
{
|
||||
auto id = global_scope()->Lookup(rec->AsStringVal()->ToStdString());
|
||||
const auto& id = global_scope()->Find(rec->AsStringVal()->ToStdString());
|
||||
|
||||
if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD )
|
||||
{
|
||||
|
|
|
@ -257,13 +257,13 @@ void ScriptInfo::DoInitPostScript()
|
|||
// so just manually associating them with scripts for now.
|
||||
if ( name == "base/frameworks/input/main.zeek" )
|
||||
{
|
||||
auto id = global_scope()->Lookup("Input::Reader");
|
||||
types.push_back(new IdentifierInfo({NewRef{}, id}, this));
|
||||
const auto& id = global_scope()->Find("Input::Reader");
|
||||
types.push_back(new IdentifierInfo(id, this));
|
||||
}
|
||||
else if ( name == "base/frameworks/logging/main.zeek" )
|
||||
{
|
||||
auto id = global_scope()->Lookup("Log::Writer");
|
||||
types.push_back(new IdentifierInfo({NewRef{}, id}, this));
|
||||
const auto& id = global_scope()->Find("Log::Writer");
|
||||
types.push_back(new IdentifierInfo(id, this));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue