diff --git a/NEWS b/NEWS index 055a1a48a6..0d9a23688e 100644 --- a/NEWS +++ b/NEWS @@ -159,6 +159,8 @@ Deprecated Functionality - ``ID::ID_Val()`` is deprecated, use ``ID::GetVal()``. +- ``internal_type()`` is deprecated, use ``zeek::lookup_type()``. + Zeek 3.1.0 ========== diff --git a/aux/bifcl b/aux/bifcl index 9d6a296d28..2d9b8606d5 160000 --- a/aux/bifcl +++ b/aux/bifcl @@ -1 +1 @@ -Subproject commit 9d6a296d283cfccf2c28a9181d9cee2760229fcb +Subproject commit 2d9b8606d5d7e4ec4a67cc11a72d38c2241ee871 diff --git a/src/BroString.cc b/src/BroString.cc index e9708d1852..80ebe66270 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -341,7 +341,7 @@ BroString::Vec* BroString::Split(const BroString::IdxVec& indices) const VectorVal* BroString:: VecToPolicy(Vec* vec) { VectorVal* result = - new VectorVal(internal_type("string_vec")->AsVectorType()); + new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); if ( ! result ) return nullptr; diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index a97c333a6a..b6f4f4a00e 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -462,7 +462,7 @@ void DNS_Mgr::InitPostScript() dns_mapping_name_changed = internal_handler("dns_mapping_name_changed"); dns_mapping_altered = internal_handler("dns_mapping_altered"); - dm_rec = internal_type("dns_mapping")->AsRecordType(); + dm_rec = zeek::lookup_type("dns_mapping")->AsRecordType(); // Registering will call Init() iosource_mgr->Register(this, true); diff --git a/src/Func.cc b/src/Func.cc index b3fe426b9a..1ac5d9652d 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -54,6 +54,8 @@ #include "iosource/PktSrc.h" #include "iosource/PktDumper.h" +using namespace zeek; + extern RETSIGTYPE sig_handler(int signo); std::vector call_stack; @@ -748,21 +750,21 @@ void builtin_error(const char* msg, BroObj* arg) void init_builtin_funcs() { - ProcStats = internal_type("ProcStats")->AsRecordType(); - NetStats = internal_type("NetStats")->AsRecordType(); - MatcherStats = internal_type("MatcherStats")->AsRecordType(); - ConnStats = internal_type("ConnStats")->AsRecordType(); - ReassemblerStats = internal_type("ReassemblerStats")->AsRecordType(); - DNSStats = internal_type("DNSStats")->AsRecordType(); - GapStats = internal_type("GapStats")->AsRecordType(); - EventStats = internal_type("EventStats")->AsRecordType(); - TimerStats = internal_type("TimerStats")->AsRecordType(); - FileAnalysisStats = internal_type("FileAnalysisStats")->AsRecordType(); - ThreadStats = internal_type("ThreadStats")->AsRecordType(); - BrokerStats = internal_type("BrokerStats")->AsRecordType(); - ReporterStats = internal_type("ReporterStats")->AsRecordType(); + ProcStats = lookup_type("ProcStats")->AsRecordType(); + NetStats = lookup_type("NetStats")->AsRecordType(); + MatcherStats = lookup_type("MatcherStats")->AsRecordType(); + ConnStats = lookup_type("ConnStats")->AsRecordType(); + ReassemblerStats = lookup_type("ReassemblerStats")->AsRecordType(); + DNSStats = lookup_type("DNSStats")->AsRecordType(); + GapStats = lookup_type("GapStats")->AsRecordType(); + EventStats = lookup_type("EventStats")->AsRecordType(); + TimerStats = lookup_type("TimerStats")->AsRecordType(); + FileAnalysisStats = lookup_type("FileAnalysisStats")->AsRecordType(); + ThreadStats = lookup_type("ThreadStats")->AsRecordType(); + BrokerStats = lookup_type("BrokerStats")->AsRecordType(); + ReporterStats = lookup_type("ReporterStats")->AsRecordType(); - var_sizes = internal_type("var_sizes")->AsTableType(); + var_sizes = lookup_type("var_sizes")->AsTableType(); #include "zeek.bif.func_init" #include "stats.bif.func_init" diff --git a/src/IP.cc b/src/IP.cc index 590f932a90..32fc68ba85 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -13,6 +13,8 @@ #include "BroString.h" #include "Reporter.h" +using namespace zeek; + static RecordType* ip4_hdr_type = nullptr; static RecordType* ip6_hdr_type = nullptr; static RecordType* ip6_ext_hdr_type = nullptr; @@ -37,14 +39,14 @@ static RecordType* ip6_mob_be_type = nullptr; static inline RecordType* hdrType(RecordType*& type, const char* name) { if ( ! type ) - type = internal_type(name)->AsRecordType(); + type = lookup_type(name)->AsRecordType(); return type; } static IntrusivePtr BuildOptionsVal(const u_char* data, int len) { - auto vv = make_intrusive(internal_type("ip6_options")->AsVectorType()); + auto vv = make_intrusive(lookup_type("ip6_options")->AsVectorType()); while ( len > 0 ) { @@ -95,7 +97,7 @@ IntrusivePtr IPv6_Hdr::ToVal(IntrusivePtr chain) const rv->Assign(6, make_intrusive(IPAddr(ip6->ip6_dst))); if ( ! chain ) chain = make_intrusive( - internal_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")->AsVectorType()); rv->Assign(7, std::move(chain)); } break; @@ -367,7 +369,7 @@ IntrusivePtr IP_Hdr::ToPktHdrVal() const static RecordType* pkt_hdr_type = nullptr; if ( ! pkt_hdr_type ) - pkt_hdr_type = internal_type("pkt_hdr")->AsRecordType(); + pkt_hdr_type = lookup_type("pkt_hdr")->AsRecordType(); return ToPktHdrVal(make_intrusive(pkt_hdr_type), 0); } @@ -385,9 +387,9 @@ IntrusivePtr IP_Hdr::ToPktHdrVal(IntrusivePtr pkt_hdr, int if ( ! tcp_hdr_type ) { - tcp_hdr_type = internal_type("tcp_hdr")->AsRecordType(); - udp_hdr_type = internal_type("udp_hdr")->AsRecordType(); - icmp_hdr_type = internal_type("icmp_hdr")->AsRecordType(); + tcp_hdr_type = lookup_type("tcp_hdr")->AsRecordType(); + udp_hdr_type = lookup_type("udp_hdr")->AsRecordType(); + icmp_hdr_type = lookup_type("icmp_hdr")->AsRecordType(); } if ( ip4 ) @@ -697,18 +699,18 @@ IntrusivePtr IPv6_Hdr_Chain::ToVal() const { if ( ! ip6_ext_hdr_type ) { - ip6_ext_hdr_type = internal_type("ip6_ext_hdr")->AsRecordType(); - ip6_hopopts_type = internal_type("ip6_hopopts")->AsRecordType(); - ip6_dstopts_type = internal_type("ip6_dstopts")->AsRecordType(); - ip6_routing_type = internal_type("ip6_routing")->AsRecordType(); - ip6_fragment_type = internal_type("ip6_fragment")->AsRecordType(); - ip6_ah_type = internal_type("ip6_ah")->AsRecordType(); - ip6_esp_type = internal_type("ip6_esp")->AsRecordType(); - ip6_mob_type = internal_type("ip6_mobility_hdr")->AsRecordType(); + ip6_ext_hdr_type = lookup_type("ip6_ext_hdr")->AsRecordType(); + ip6_hopopts_type = lookup_type("ip6_hopopts")->AsRecordType(); + ip6_dstopts_type = lookup_type("ip6_dstopts")->AsRecordType(); + ip6_routing_type = lookup_type("ip6_routing")->AsRecordType(); + ip6_fragment_type = lookup_type("ip6_fragment")->AsRecordType(); + ip6_ah_type = lookup_type("ip6_ah")->AsRecordType(); + ip6_esp_type = lookup_type("ip6_esp")->AsRecordType(); + ip6_mob_type = lookup_type("ip6_mobility_hdr")->AsRecordType(); } auto rval = make_intrusive( - internal_type("ip6_ext_hdr_chain")->AsVectorType()); + lookup_type("ip6_ext_hdr_chain")->AsVectorType()); for ( size_t i = 1; i < chain.size(); ++i ) { diff --git a/src/NetVar.cc b/src/NetVar.cc index cb604c75ba..2fcc92735a 100644 --- a/src/NetVar.cc +++ b/src/NetVar.cc @@ -7,6 +7,8 @@ #include "EventHandler.h" #include "Val.h" +using namespace zeek; + RecordType* conn_id; RecordType* endpoint; RecordType* endpoint_stats; @@ -213,7 +215,7 @@ void init_general_global_var() table_expire_delay = opt_internal_double("table_expire_delay"); table_incremental_step = opt_internal_int("table_incremental_step"); - rotate_info = internal_type("rotate_info")->AsRecordType(); + rotate_info = lookup_type("rotate_info")->AsRecordType(); log_rotate_base_time = opt_internal_string("log_rotate_base_time"); peer_description = @@ -247,26 +249,26 @@ void init_net_var() #include "reporter.bif.netvar_init" #include "supervisor.bif.netvar_init" - conn_id = internal_type("conn_id")->AsRecordType(); - endpoint = internal_type("endpoint")->AsRecordType(); - endpoint_stats = internal_type("endpoint_stats")->AsRecordType(); - connection_type = internal_type("connection")->AsRecordType(); - fa_file_type = internal_type("fa_file")->AsRecordType(); - fa_metadata_type = internal_type("fa_metadata")->AsRecordType(); - icmp_conn = internal_type("icmp_conn")->AsRecordType(); - icmp_context = internal_type("icmp_context")->AsRecordType(); - signature_state = internal_type("signature_state")->AsRecordType(); - SYN_packet = internal_type("SYN_packet")->AsRecordType(); - pcap_packet = internal_type("pcap_packet")->AsRecordType(); - raw_pkt_hdr_type = internal_type("raw_pkt_hdr")->AsRecordType(); - l2_hdr_type = internal_type("l2_hdr")->AsRecordType(); - transport_proto = internal_type("transport_proto")->AsEnumType(); - string_set = internal_type("string_set")->AsTableType(); - string_array = internal_type("string_array")->AsTableType(); - string_vec = internal_type("string_vec")->AsVectorType(); - index_vec = internal_type("index_vec")->AsVectorType(); - mime_match = internal_type("mime_match")->AsRecordType(); - mime_matches = internal_type("mime_matches")->AsVectorType(); + conn_id = lookup_type("conn_id")->AsRecordType(); + endpoint = lookup_type("endpoint")->AsRecordType(); + endpoint_stats = lookup_type("endpoint_stats")->AsRecordType(); + connection_type = lookup_type("connection")->AsRecordType(); + fa_file_type = lookup_type("fa_file")->AsRecordType(); + fa_metadata_type = lookup_type("fa_metadata")->AsRecordType(); + icmp_conn = lookup_type("icmp_conn")->AsRecordType(); + icmp_context = lookup_type("icmp_context")->AsRecordType(); + signature_state = lookup_type("signature_state")->AsRecordType(); + SYN_packet = lookup_type("SYN_packet")->AsRecordType(); + pcap_packet = lookup_type("pcap_packet")->AsRecordType(); + raw_pkt_hdr_type = lookup_type("raw_pkt_hdr")->AsRecordType(); + l2_hdr_type = lookup_type("l2_hdr")->AsRecordType(); + transport_proto = lookup_type("transport_proto")->AsEnumType(); + string_set = lookup_type("string_set")->AsTableType(); + string_array = lookup_type("string_array")->AsTableType(); + string_vec = lookup_type("string_vec")->AsVectorType(); + index_vec = lookup_type("index_vec")->AsVectorType(); + mime_match = lookup_type("mime_match")->AsRecordType(); + mime_matches = lookup_type("mime_matches")->AsVectorType(); ignore_checksums = opt_internal_int("ignore_checksums"); partial_connection_ok = opt_internal_int("partial_connection_ok"); @@ -292,7 +294,7 @@ void init_net_var() opt_internal_int("tcp_excessive_data_without_further_acks"); tcp_max_old_segments = opt_internal_int("tcp_max_old_segments"); - socks_address = internal_type("SOCKS::Address")->AsRecordType(); + socks_address = lookup_type("SOCKS::Address")->AsRecordType(); non_analyzed_lifetime = opt_internal_double("non_analyzed_lifetime"); tcp_inactivity_timeout = opt_internal_double("tcp_inactivity_timeout"); @@ -347,34 +349,34 @@ void init_net_var() mime_segment_length = opt_internal_int("mime_segment_length"); mime_segment_overlap_length = opt_internal_int("mime_segment_overlap_length"); - mime_header_rec = internal_type("mime_header_rec")->AsRecordType(); - mime_header_list = internal_type("mime_header_list")->AsTableType(); + mime_header_rec = lookup_type("mime_header_rec")->AsRecordType(); + mime_header_list = lookup_type("mime_header_list")->AsTableType(); http_entity_data_delivery_size = opt_internal_int("http_entity_data_delivery_size"); - http_stats_rec = internal_type("http_stats_rec")->AsRecordType(); - http_message_stat = internal_type("http_message_stat")->AsRecordType(); + http_stats_rec = lookup_type("http_stats_rec")->AsRecordType(); + http_message_stat = lookup_type("http_message_stat")->AsRecordType(); truncate_http_URI = opt_internal_int("truncate_http_URI"); - pm_mapping = internal_type("pm_mapping")->AsRecordType(); - pm_mappings = internal_type("pm_mappings")->AsTableType(); - pm_port_request = internal_type("pm_port_request")->AsRecordType(); - pm_callit_request = internal_type("pm_callit_request")->AsRecordType(); + pm_mapping = lookup_type("pm_mapping")->AsRecordType(); + pm_mappings = lookup_type("pm_mappings")->AsTableType(); + pm_port_request = lookup_type("pm_port_request")->AsRecordType(); + pm_callit_request = lookup_type("pm_callit_request")->AsRecordType(); - geo_location = internal_type("geo_location")->AsRecordType(); + geo_location = lookup_type("geo_location")->AsRecordType(); - entropy_test_result = internal_type("entropy_test_result")->AsRecordType(); + entropy_test_result = lookup_type("entropy_test_result")->AsRecordType(); - dns_msg = internal_type("dns_msg")->AsRecordType(); - dns_answer = internal_type("dns_answer")->AsRecordType(); - dns_soa = internal_type("dns_soa")->AsRecordType(); + dns_msg = lookup_type("dns_msg")->AsRecordType(); + dns_answer = lookup_type("dns_answer")->AsRecordType(); + dns_soa = lookup_type("dns_soa")->AsRecordType(); dns_edns_additional = - internal_type("dns_edns_additional")->AsRecordType(); + lookup_type("dns_edns_additional")->AsRecordType(); dns_tsig_additional = - internal_type("dns_tsig_additional")->AsRecordType(); - dns_rrsig_rr = internal_type("dns_rrsig_rr")->AsRecordType(); - dns_dnskey_rr = internal_type("dns_dnskey_rr")->AsRecordType(); - dns_nsec3_rr = internal_type("dns_nsec3_rr")->AsRecordType(); - dns_ds_rr = internal_type("dns_ds_rr")->AsRecordType(); + lookup_type("dns_tsig_additional")->AsRecordType(); + dns_rrsig_rr = lookup_type("dns_rrsig_rr")->AsRecordType(); + dns_dnskey_rr = lookup_type("dns_dnskey_rr")->AsRecordType(); + dns_nsec3_rr = lookup_type("dns_nsec3_rr")->AsRecordType(); + dns_ds_rr = lookup_type("dns_ds_rr")->AsRecordType(); dns_skip_auth = internal_val("dns_skip_auth")->AsTableVal(); dns_skip_addl = internal_val("dns_skip_addl")->AsTableVal(); dns_skip_all_auth = opt_internal_int("dns_skip_all_auth"); @@ -410,8 +412,8 @@ void init_net_var() gap_report_freq = opt_internal_double("gap_report_freq"); - irc_join_info = internal_type("irc_join_info")->AsRecordType(); - irc_join_list = internal_type("irc_join_list")->AsTableType(); + irc_join_info = lookup_type("irc_join_info")->AsRecordType(); + irc_join_list = lookup_type("irc_join_list")->AsTableType(); dpd_reassemble_first_packets = opt_internal_int("dpd_reassemble_first_packets"); @@ -425,10 +427,10 @@ void init_net_var() timer_mgr_inactivity_timeout = opt_internal_double("timer_mgr_inactivity_timeout"); - script_id = internal_type("script_id")->AsRecordType(); - id_table = internal_type("id_table")->AsTableType(); - record_field = internal_type("record_field")->AsRecordType(); - record_field_table = internal_type("record_field_table")->AsTableType(); - call_argument_vector = internal_type("call_argument_vector")->AsVectorType(); - call_argument = internal_type("call_argument")->AsRecordType(); + script_id = lookup_type("script_id")->AsRecordType(); + id_table = lookup_type("id_table")->AsTableType(); + record_field = lookup_type("record_field")->AsRecordType(); + record_field_table = lookup_type("record_field_table")->AsTableType(); + call_argument_vector = lookup_type("call_argument_vector")->AsVectorType(); + call_argument = lookup_type("call_argument")->AsRecordType(); } diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index 14867819e8..2138c411b9 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -981,7 +981,7 @@ ParaglobVal::ParaglobVal(std::unique_ptr p) IntrusivePtr ParaglobVal::Get(StringVal* &pattern) { - auto rval = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); std::string string_pattern (reinterpret_cast(pattern->Bytes()), pattern->Len()); std::vector matches = this->internal_paraglob->get(string_pattern); diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index 315a40551f..a9f878390a 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -7,7 +7,7 @@ #include "Scope.h" #include "Func.h" #include "Val.h" -#include "Var.h" // for internal_type() +#include "Var.h" static inline bool is_established(const analyzer::tcp::TCP_Endpoint* e) { @@ -145,7 +145,7 @@ RuleConditionEval::RuleConditionEval(const char* func) rules_error("eval function type must yield a 'bool'", func); TypeList tl; - tl.Append({NewRef{}, internal_type("signature_state")}); + tl.Append(zeek::lookup_type("signature_state")); tl.Append(base_type(TYPE_STRING)); if ( ! f->CheckArgs(tl.Types()) ) diff --git a/src/SmithWaterman.cc b/src/SmithWaterman.cc index 02b11cf93d..17693e3f8e 100644 --- a/src/SmithWaterman.cc +++ b/src/SmithWaterman.cc @@ -59,22 +59,22 @@ bool BroSubstring::DoesCover(const BroSubstring* bst) const VectorVal* BroSubstring::VecToPolicy(Vec* vec) { RecordType* sw_substring_type = - internal_type("sw_substring")->AsRecordType(); + zeek::lookup_type("sw_substring")->AsRecordType(); if ( ! sw_substring_type ) return nullptr; RecordType* sw_align_type = - internal_type("sw_align")->AsRecordType(); + zeek::lookup_type("sw_align")->AsRecordType(); if ( ! sw_align_type ) return nullptr; VectorType* sw_align_vec_type = - internal_type("sw_align_vec")->AsVectorType(); + zeek::lookup_type("sw_align_vec")->AsVectorType(); if ( ! sw_align_vec_type ) return nullptr; VectorVal* result = - new VectorVal(internal_type("sw_substring_vec")->AsVectorType()); + new VectorVal(zeek::lookup_type("sw_substring_vec")->AsVectorType()); if ( ! result ) return nullptr; diff --git a/src/Stats.cc b/src/Stats.cc index 70427ebcf5..44d6a5760e 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -5,7 +5,7 @@ #include "Event.h" #include "Net.h" #include "NetVar.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "Sessions.h" #include "Scope.h" #include "DNS_Mgr.h" @@ -342,7 +342,7 @@ SampleLogger::SampleLogger() static TableType* load_sample_info = nullptr; if ( ! load_sample_info ) - load_sample_info = internal_type("load_sample_info")->AsTableType(); + load_sample_info = zeek::lookup_type("load_sample_info")->AsTableType(); load_samples = new TableVal({NewRef{}, load_sample_info}); } diff --git a/src/Stmt.cc b/src/Stmt.cc index 8879921fbf..8184581ce9 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -201,8 +201,8 @@ static IntrusivePtr lookup_enum_val(const char* module_name, const char static void print_log(const std::vector>& vals) { auto plval = lookup_enum_val("Log", "PRINTLOG"); - auto record = make_intrusive(internal_type("Log::PrintLogInfo")->AsRecordType()); - auto vec = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto record = make_intrusive(zeek::lookup_type("Log::PrintLogInfo")->AsRecordType()); + auto vec = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); for ( const auto& val : vals ) { diff --git a/src/TunnelEncapsulation.h b/src/TunnelEncapsulation.h index 106d5dfb74..67d66ced09 100644 --- a/src/TunnelEncapsulation.h +++ b/src/TunnelEncapsulation.h @@ -6,7 +6,7 @@ #include "IntrusivePtr.h" #include "NetVar.h" #include "IPAddr.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "UID.h" #include @@ -198,7 +198,7 @@ public: IntrusivePtr ToVal() const { auto vv = make_intrusive( - internal_type("EncapsulatingConnVector")->AsVectorType()); + zeek::lookup_type("EncapsulatingConnVector")->AsVectorType()); if ( conns ) { diff --git a/src/Type.cc b/src/Type.cc index be18f6d059..122f5370cd 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -796,7 +796,7 @@ static string container_type_name(const BroType* ft) IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const { - auto rval = make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + auto rval = make_intrusive(zeek::lookup_type("record_field_table")); for ( int i = 0; i < NumFields(); ++i ) { @@ -812,7 +812,7 @@ IntrusivePtr RecordType::GetRecordFieldsVal(const RecordVal* rv) const bool logged = (fd->attrs && fd->FindAttr(ATTR_LOG) != nullptr); - auto nr = make_intrusive(internal_type("record_field")->AsRecordType()); + auto nr = make_intrusive(zeek::lookup_type("record_field")->AsRecordType()); string s = container_type_name(ft.get()); nr->Assign(0, make_intrusive(s)); diff --git a/src/Val.cc b/src/Val.cc index cf76a1771f..43d8c4825d 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -34,7 +34,7 @@ #include "Conn.h" #include "Reporter.h" #include "IPAddr.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "broker/Data.h" @@ -417,7 +417,7 @@ IntrusivePtr Val::GetRecordFields() if ( t->Tag() != TYPE_RECORD && t->Tag() != TYPE_TYPE ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + return make_intrusive(zeek::lookup_type("record_field_table")); } RecordType* rt = nullptr; @@ -435,7 +435,7 @@ IntrusivePtr Val::GetRecordFields() if ( t->Tag() != TYPE_RECORD ) { reporter->Error("non-record value/type passed to record_fields"); - return make_intrusive(IntrusivePtr{NewRef{}, internal_type("record_field_table")->AsTableType()}); + return make_intrusive(zeek::lookup_type("record_field_table")); } rt = t->AsRecordType(); @@ -1933,7 +1933,7 @@ IntrusivePtr TableVal::LookupSubnets(const SubNetVal* search) if ( ! subnets ) reporter->InternalError("LookupSubnets called on wrong table type"); - auto result = make_intrusive(internal_type("subnet_vec")->AsVectorType()); + auto result = make_intrusive(zeek::lookup_type("subnet_vec")->AsVectorType()); auto matches = subnets->FindAll(search); for ( auto element : matches ) diff --git a/src/Var.cc b/src/Var.cc index 7a5c9026d8..a78d895eb9 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -761,12 +761,17 @@ ListVal* internal_list_val(const char* name) } BroType* internal_type(const char* name) + { + return zeek::lookup_type(name).get(); + } + +const IntrusivePtr& zeek::lookup_type(const char* name) { auto id = lookup_ID(name, GLOBAL_MODULE_NAME); if ( ! id ) - reporter->InternalError("internal type %s missing", name); + reporter->InternalError("Failed to find type named: %s", name); - return id->GetType().get(); + return id->GetType(); } Func* internal_func(const char* name) diff --git a/src/Var.h b/src/Var.h index 92af4cd5e9..15cfd85a11 100644 --- a/src/Var.h +++ b/src/Var.h @@ -49,8 +49,33 @@ extern bro_uint_t opt_internal_unsigned(const char* name); extern StringVal* opt_internal_string(const char* name); 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::lookup_type().")]] extern BroType* internal_type(const char* name); + extern Func* internal_func(const char* name); extern EventHandlerPtr internal_handler(const char* name); extern int signal_val; // 0 if no signal pending + +namespace zeek { + +/** + * Lookup an ID by its name and return its type. A fatal occurs if the ID + * does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +const IntrusivePtr& lookup_type(const char* name); + +/** + * Lookup an ID by its name and return its type (as cast to @c T). + * A fatal occurs if the ID does not exist. + * @param name The identifier name to lookup + * @return The type of the identifier. + */ +template +IntrusivePtr lookup_type(const char* name) + { return cast_intrusive(lookup_type(name)); } + +} // namespace zeek diff --git a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc index eac30667fa..d400cf771d 100644 --- a/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc +++ b/src/analyzer/protocol/bittorrent/BitTorrentTracker.cc @@ -27,15 +27,15 @@ BitTorrentTracker_Analyzer::BitTorrentTracker_Analyzer(Connection* c) if ( ! bt_tracker_headers ) { bt_tracker_headers = - internal_type("bt_tracker_headers")->AsTableType(); + zeek::lookup_type("bt_tracker_headers")->AsTableType(); bittorrent_peer = - internal_type("bittorrent_peer")->AsRecordType(); + zeek::lookup_type("bittorrent_peer")->AsRecordType(); bittorrent_peer_set = - internal_type("bittorrent_peer_set")->AsTableType(); + zeek::lookup_type("bittorrent_peer_set")->AsTableType(); bittorrent_benc_value = - internal_type("bittorrent_benc_value")->AsRecordType(); + zeek::lookup_type("bittorrent_benc_value")->AsRecordType(); bittorrent_benc_dir = - internal_type("bittorrent_benc_dir")->AsTableType(); + zeek::lookup_type("bittorrent_benc_dir")->AsTableType(); } keep_alive = false; diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 8575e5e59c..1071d0ea0e 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -726,13 +726,13 @@ IntrusivePtr ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_cha if ( ! icmp6_nd_option_type ) { - icmp6_nd_option_type = internal_type("icmp6_nd_option")->AsRecordType(); + icmp6_nd_option_type = zeek::lookup_type("icmp6_nd_option")->AsRecordType(); icmp6_nd_prefix_info_type = - internal_type("icmp6_nd_prefix_info")->AsRecordType(); + zeek::lookup_type("icmp6_nd_prefix_info")->AsRecordType(); } auto vv = make_intrusive( - internal_type("icmp6_nd_options")->AsVectorType()); + zeek::lookup_type("icmp6_nd_options")->AsVectorType()); while ( caplen > 0 ) { diff --git a/src/analyzer/protocol/imap/imap-analyzer.pac b/src/analyzer/protocol/imap/imap-analyzer.pac index 51afb21f0e..7e45bda7a0 100644 --- a/src/analyzer/protocol/imap/imap-analyzer.pac +++ b/src/analyzer/protocol/imap/imap-analyzer.pac @@ -59,7 +59,7 @@ refine connection IMAP_Conn += { if ( ! imap_capabilities ) return true; - auto capv = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto capv = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); for ( unsigned int i = 0; i< capabilities->size(); i++ ) { diff --git a/src/analyzer/protocol/krb/krb-padata.pac b/src/analyzer/protocol/krb/krb-padata.pac index 35e99ff4d9..a73c1cb5d4 100644 --- a/src/analyzer/protocol/krb/krb-padata.pac +++ b/src/analyzer/protocol/krb/krb-padata.pac @@ -13,7 +13,7 @@ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_a %code{ VectorVal* proc_padata(const KRB_PA_Data_Sequence* data, const BroAnalyzer bro_analyzer, bool is_error) { - VectorVal* vv = new VectorVal(internal_type("KRB::Type_Value_Vector")->AsVectorType()); + VectorVal* vv = new VectorVal(zeek::lookup_type("KRB::Type_Value_Vector")->AsVectorType()); if ( ! data->data()->has_padata() ) return vv; diff --git a/src/analyzer/protocol/krb/krb-types.pac b/src/analyzer/protocol/krb/krb-types.pac index 8a70075785..dcb320efbe 100644 --- a/src/analyzer/protocol/krb/krb-types.pac +++ b/src/analyzer/protocol/krb/krb-types.pac @@ -27,7 +27,7 @@ IntrusivePtr GetStringFromPrincipalName(const KRB_Principal_Name* pname) VectorVal* proc_cipher_list(const Array* list) { - VectorVal* ciphers = new VectorVal(internal_type("index_vec")->AsVectorType()); + VectorVal* ciphers = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); for ( uint i = 0; i < list->data()->size(); ++i ) ciphers->Assign(ciphers->Size(), asn1_integer_to_val((*list->data())[i], TYPE_COUNT)); return ciphers; @@ -35,7 +35,7 @@ VectorVal* proc_cipher_list(const Array* list) VectorVal* proc_host_address_list(const BroAnalyzer a, const KRB_Host_Addresses* list) { - VectorVal* addrs = new VectorVal(internal_type("KRB::Host_Address_Vector")->AsVectorType()); + VectorVal* addrs = new VectorVal(zeek::lookup_type("KRB::Host_Address_Vector")->AsVectorType()); for ( uint i = 0; i < list->addresses()->size(); ++i ) { @@ -94,7 +94,7 @@ RecordVal* proc_host_address(const BroAnalyzer a, const KRB_Host_Address* addr) IntrusivePtr proc_tickets(const KRB_Ticket_Sequence* list) { - auto tickets = make_intrusive(internal_type("KRB::Ticket_Vector")->AsVectorType()); + auto tickets = make_intrusive(zeek::lookup_type("KRB::Ticket_Vector")->AsVectorType()); for ( uint i = 0; i < list->tickets()->size(); ++i ) { diff --git a/src/analyzer/protocol/mysql/mysql-analyzer.pac b/src/analyzer/protocol/mysql/mysql-analyzer.pac index f49fbe5625..1f49688f5e 100644 --- a/src/analyzer/protocol/mysql/mysql-analyzer.pac +++ b/src/analyzer/protocol/mysql/mysql-analyzer.pac @@ -82,7 +82,7 @@ refine flow MySQL_Flow += { if ( ! mysql_result_row ) return true; - auto vt = internal_type("string_vec")->AsVectorType(); + auto vt = zeek::lookup_type("string_vec")->AsVectorType(); auto vv = make_intrusive(vt); auto& bstring = ${msg.row.first_field.val}; diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index cddb49c547..5a0bfcd8ba 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -192,7 +192,7 @@ zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for (size_t i = 0; i < c->AuxGIDs().size(); ++i) { diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index d1d7ff4b0e..82d3e519a3 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -328,7 +328,7 @@ zeek::Args NFS_Interp::event_common_vl(RPC_CallInfo *c, BifEnum::rpc_status rpc_ zeek::Args vl; vl.reserve(2 + extra_elements); vl.emplace_back(analyzer->ConnVal()); - auto auxgids = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto auxgids = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( size_t i = 0; i < c->AuxGIDs().size(); ++i ) auxgids->Assign(i, val_mgr->Count(c->AuxGIDs()[i])); diff --git a/src/analyzer/protocol/smb/smb2-protocol.pac b/src/analyzer/protocol/smb/smb2-protocol.pac index dd5a2a109a..861d35f22c 100644 --- a/src/analyzer/protocol/smb/smb2-protocol.pac +++ b/src/analyzer/protocol/smb/smb2-protocol.pac @@ -68,7 +68,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) rpreauth->Assign(0, val_mgr->Count(${ncv.preauth_integrity_capabilities.hash_alg_count})); rpreauth->Assign(1, val_mgr->Count(${ncv.preauth_integrity_capabilities.salt_length})); - auto ha = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto ha = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.preauth_integrity_capabilities.hash_alg_count}; ++i ) { @@ -87,7 +87,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rencr = make_intrusive(BifType::Record::SMB2::EncryptionCapabilities); rencr->Assign(0, val_mgr->Count(${ncv.encryption_capabilities.cipher_count})); - auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.encryption_capabilities.cipher_count}; ++i ) { @@ -105,7 +105,7 @@ IntrusivePtr BuildSMB2ContextVal(SMB3_negotiate_context_value* ncv) auto rcomp = make_intrusive(BifType::Record::SMB2::CompressionCapabilities); rcomp->Assign(0, val_mgr->Count(${ncv.compression_capabilities.alg_count})); - auto c = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto c = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( int i = 0; i < ${ncv.compression_capabilities.alg_count}; ++i ) { diff --git a/src/analyzer/protocol/ssh/ssh-analyzer.pac b/src/analyzer/protocol/ssh/ssh-analyzer.pac index 52b731ccaa..3f4c6e9c69 100644 --- a/src/analyzer/protocol/ssh/ssh-analyzer.pac +++ b/src/analyzer/protocol/ssh/ssh-analyzer.pac @@ -12,7 +12,7 @@ VectorVal* name_list_to_vector(const bytestring& nl); // Copied from IRC_Analyzer::SplitWords VectorVal* name_list_to_vector(const bytestring& nl) { - VectorVal* vv = new VectorVal(internal_type("string_vec")->AsVectorType()); + VectorVal* vv = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); string name_list = std_str(nl); if ( name_list.size() < 1 ) diff --git a/src/analyzer/protocol/ssl/proc-client-hello.pac b/src/analyzer/protocol/ssl/proc-client-hello.pac index 1eae147996..13accc5318 100644 --- a/src/analyzer/protocol/ssl/proc-client-hello.pac +++ b/src/analyzer/protocol/ssl/proc-client-hello.pac @@ -23,7 +23,7 @@ else std::transform(cipher_suites24->begin(), cipher_suites24->end(), std::back_inserter(cipher_suites), to_int()); - auto cipher_vec = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto cipher_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); for ( unsigned int i = 0; i < cipher_suites.size(); ++i ) { @@ -31,7 +31,7 @@ cipher_vec->Assign(i, ciph); } - auto comp_vec = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto comp_vec = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( compression_methods ) { diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 46333fcd13..5db9e711a2 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -75,7 +75,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_ec_point_formats ) return true; - auto points = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto points = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( point_format_list ) { @@ -94,7 +94,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_elliptic_curves ) return true; - auto curves = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto curves = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( list ) { @@ -113,7 +113,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( keyshare ) { @@ -131,7 +131,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); nglist->Assign(0u, val_mgr->Count(keyshare->namedgroup())); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -143,7 +143,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_key_share ) return true; - auto nglist = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto nglist = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); nglist->Assign(0u, val_mgr->Count(namedgroup)); BifEvent::enqueue_ssl_extension_key_share(bro_analyzer(), bro_analyzer()->Conn(), ${rec.is_orig}, std::move(nglist)); @@ -155,7 +155,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_signature_algorithm ) return true; - auto slist = make_intrusive(internal_type("signature_and_hashalgorithm_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("signature_and_hashalgorithm_vec")->AsVectorType()); if ( supported_signature_algorithms ) { @@ -178,7 +178,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_application_layer_protocol_negotiation ) return true; - auto plist = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto plist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( protocols ) { @@ -194,7 +194,7 @@ refine connection Handshake_Conn += { function proc_server_name(rec: HandshakeRecord, list: ServerName[]) : bool %{ - auto servers = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto servers = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( list ) { @@ -226,7 +226,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( versions_list ) { @@ -245,7 +245,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_supported_versions ) return true; - auto versions = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto versions = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); versions->Assign(0u, val_mgr->Count(version)); BifEvent::enqueue_ssl_extension_supported_versions(bro_analyzer(), bro_analyzer()->Conn(), @@ -259,7 +259,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_psk_key_exchange_modes ) return true; - auto modes = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto modes = make_intrusive(zeek::lookup_type("index_vec")->AsVectorType()); if ( mode_list ) { @@ -492,7 +492,7 @@ refine connection Handshake_Conn += { if ( ! ssl_extension_pre_shared_key_server_hello ) return true; - auto slist = make_intrusive(internal_type("psk_identity_vec")->AsVectorType()); + auto slist = make_intrusive(zeek::lookup_type("psk_identity_vec")->AsVectorType()); if ( identities && identities->identities() ) { @@ -505,7 +505,7 @@ refine connection Handshake_Conn += { } } - auto blist = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto blist = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); if ( binders && binders->binders() ) { diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index d94f67e995..e9acdc65b5 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -1421,7 +1421,7 @@ int TCP_Analyzer::ParseTCPOptions(const struct tcphdr* tcp, bool is_orig) { auto p = reinterpret_cast(o + 2); auto num_pointers = (length - 2) / 4; - auto vt = internal_type("index_vec")->AsVectorType(); + auto vt = zeek::lookup_type("index_vec")->AsVectorType(); auto sack = new VectorVal(vt); for ( auto i = 0; i < num_pointers; ++i ) diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 9501378a23..bb551b08b7 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -104,9 +104,9 @@ IntrusivePtr TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const if ( ! teredo_hdr_type ) { - teredo_hdr_type = internal_type("teredo_hdr")->AsRecordType(); - teredo_auth_type = internal_type("teredo_auth")->AsRecordType(); - teredo_origin_type = internal_type("teredo_origin")->AsRecordType(); + teredo_hdr_type = zeek::lookup_type("teredo_hdr")->AsRecordType(); + teredo_auth_type = zeek::lookup_type("teredo_auth")->AsRecordType(); + teredo_origin_type = zeek::lookup_type("teredo_origin")->AsRecordType(); } auto teredo_hdr = make_intrusive(teredo_hdr_type); diff --git a/src/bro-bif.h b/src/bro-bif.h index a20996152b..a2586c692d 100644 --- a/src/bro-bif.h +++ b/src/bro-bif.h @@ -7,4 +7,4 @@ #include "NetVar.h" #include "Event.h" #include "Reporter.h" -#include "Var.h" // for internal_type() +#include "Var.h" diff --git a/src/broker/Data.cc b/src/broker/Data.cc index c653256a89..bc7b1da326 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -3,7 +3,7 @@ #include "Desc.h" #include "IntrusivePtr.h" #include "RE.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "Scope.h" #include "module_util.h" #include "3rdparty/doctest.h" @@ -1154,7 +1154,7 @@ IntrusivePtr bro_broker::DataVal::castTo(BroType* t) BroType* bro_broker::DataVal::ScriptDataType() { if ( ! script_data_type ) - script_data_type = internal_type("Broker::Data"); + script_data_type = zeek::lookup_type("Broker::Data").get(); return script_data_type; } diff --git a/src/broker/Manager.cc b/src/broker/Manager.cc index c5be4b918b..ee93f3b4e7 100644 --- a/src/broker/Manager.cc +++ b/src/broker/Manager.cc @@ -149,8 +149,8 @@ void Manager::InitPostScript() default_log_topic_prefix = get_option("Broker::default_log_topic_prefix")->AsString()->CheckString(); log_topic_func = get_option("Broker::log_topic")->AsFunc(); - log_id_type = internal_type("Log::ID")->AsEnumType(); - writer_id_type = internal_type("Log::Writer")->AsEnumType(); + log_id_type = zeek::lookup_type("Log::ID")->AsEnumType(); + writer_id_type = zeek::lookup_type("Log::Writer")->AsEnumType(); opaque_of_data_type = new OpaqueType("Broker::Data"); opaque_of_set_iterator = new OpaqueType("Broker::SetIterator"); @@ -158,7 +158,7 @@ void Manager::InitPostScript() opaque_of_vector_iterator = new OpaqueType("Broker::VectorIterator"); opaque_of_record_iterator = new OpaqueType("Broker::RecordIterator"); opaque_of_store_handle = new OpaqueType("Broker::Store"); - vector_of_data_type = new VectorType({NewRef{}, internal_type("Broker::Data")}); + vector_of_data_type = new VectorType(zeek::lookup_type("Broker::Data")); // Register as a "dont-count" source first, we may change that later. iosource_mgr->Register(this, true); @@ -1246,13 +1246,13 @@ void Manager::ProcessStatus(broker::status stat) if ( ! event ) return; - auto ei = internal_type("Broker::EndpointInfo")->AsRecordType(); + auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); auto endpoint_info = make_intrusive(ei); if ( ctx ) { endpoint_info->Assign(0, make_intrusive(to_string(ctx->node))); - auto ni = internal_type("Broker::NetworkInfo")->AsRecordType(); + auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto network_info = make_intrusive(ni); if ( ctx->network ) diff --git a/src/broker/Store.cc b/src/broker/Store.cc index 81138edcd9..5502179af8 100644 --- a/src/broker/Store.cc +++ b/src/broker/Store.cc @@ -1,6 +1,6 @@ #include "Store.h" #include "Desc.h" -#include "Var.h" // for internal_type() +#include "Var.h" #include "broker/Manager.h" namespace bro_broker { @@ -15,7 +15,7 @@ EnumVal* query_status(bool success) if ( ! store_query_status ) { - store_query_status = internal_type("Broker::QueryStatus")->AsEnumType(); + store_query_status = zeek::lookup_type("Broker::QueryStatus")->AsEnumType(); success_val = store_query_status->Lookup("Broker", "SUCCESS"); failure_val = store_query_status->Lookup("Broker", "FAILURE"); } diff --git a/src/broker/comm.bif b/src/broker/comm.bif index 4d8ee6c096..aa19638dcc 100644 --- a/src/broker/comm.bif +++ b/src/broker/comm.bif @@ -94,14 +94,14 @@ function Broker::__unpeer%(a: string, p: port%): bool function Broker::__peers%(%): PeerInfos %{ bro_broker::Manager::ScriptScopeGuard ssg; - auto rval = make_intrusive(internal_type("Broker::PeerInfos")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("Broker::PeerInfos")->AsVectorType()); auto i = 0; for ( auto& p : broker_mgr->Peers() ) { - auto pi = internal_type("Broker::PeerInfo")->AsRecordType(); - auto ei = internal_type("Broker::EndpointInfo")->AsRecordType(); - auto ni = internal_type("Broker::NetworkInfo")->AsRecordType(); + auto pi = zeek::lookup_type("Broker::PeerInfo")->AsRecordType(); + auto ei = zeek::lookup_type("Broker::EndpointInfo")->AsRecordType(); + auto ni = zeek::lookup_type("Broker::NetworkInfo")->AsRecordType(); auto peer_info = new RecordVal(pi); auto endpoint_info = new RecordVal(ei); auto network_info = new RecordVal(ni); diff --git a/src/file_analysis/analyzer/pe/pe-analyzer.pac b/src/file_analysis/analyzer/pe/pe-analyzer.pac index 56f110563a..3549ec5267 100644 --- a/src/file_analysis/analyzer/pe/pe-analyzer.pac +++ b/src/file_analysis/analyzer/pe/pe-analyzer.pac @@ -11,7 +11,7 @@ VectorVal* process_rvas(const RVAS* rvas); %code{ VectorVal* process_rvas(const RVAS* rva_table) { - VectorVal* rvas = new VectorVal(internal_type("index_vec")->AsVectorType()); + VectorVal* rvas = new VectorVal(zeek::lookup_type("index_vec")->AsVectorType()); for ( uint16 i=0; i < rva_table->rvas()->size(); ++i ) rvas->Assign(i, val_mgr->Count((*rva_table->rvas())[i]->size())); @@ -25,7 +25,7 @@ refine flow File += { function characteristics_to_bro(c: uint32, len: uint8): TableVal %{ uint64 mask = (len==16) ? 0xFFFF : 0xFFFFFFFF; - TableVal* char_set = new TableVal({NewRef{}, internal_type("count_set")->AsTableType()}); + TableVal* char_set = new TableVal(zeek::lookup_type("count_set")); for ( uint16 i=0; i < len; ++i ) { if ( ((c >> i) & 0x1) == 1 ) diff --git a/src/file_analysis/analyzer/x509/OCSP.cc b/src/file_analysis/analyzer/x509/OCSP.cc index 3eb9b423c9..7355058eb8 100644 --- a/src/file_analysis/analyzer/x509/OCSP.cc +++ b/src/file_analysis/analyzer/x509/OCSP.cc @@ -634,7 +634,7 @@ void file_analysis::OCSP::ParseResponse(OCSP_RESPONSE *resp) //ocsp_resp_record->Assign(7, make_intrusive(len, buf)); //BIO_reset(bio); - certs_vector = new VectorVal(internal_type("x509_opaque_vector")->AsVectorType()); + certs_vector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); vl.emplace_back(AdoptRef{}, certs_vector); #if ( OPENSSL_VERSION_NUMBER < 0x10100000L ) || defined(LIBRESSL_VERSION_NUMBER) diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index d32c8434e8..b3fffdce23 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -367,21 +367,21 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { case GEN_DNS: if ( names == nullptr ) - names = new VectorVal(internal_type("string_vec")->AsVectorType()); + names = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); names->Assign(names->Size(), bs); break; case GEN_URI: if ( uris == nullptr ) - uris = new VectorVal(internal_type("string_vec")->AsVectorType()); + uris = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); uris->Assign(uris->Size(), bs); break; case GEN_EMAIL: if ( emails == nullptr ) - emails = new VectorVal(internal_type("string_vec")->AsVectorType()); + emails = new VectorVal(zeek::lookup_type("string_vec")->AsVectorType()); emails->Assign(emails->Size(), bs); break; @@ -391,7 +391,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) else if ( gen->type == GEN_IPADD ) { if ( ips == nullptr ) - ips = new VectorVal(internal_type("addr_vec")->AsVectorType()); + ips = new VectorVal(zeek::lookup_type("addr_vec")->AsVectorType()); uint32_t* addr = (uint32_t*) gen->d.ip->data; diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index f45bd422ea..5eba5a776d 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -556,7 +556,7 @@ function x509_verify%(certs: x509_opaque_vector, root_certs: table_string_of_str } int num_certs = sk_X509_num(chain); - chainVector = new VectorVal(internal_type("x509_opaque_vector")->AsVectorType()); + chainVector = new VectorVal(zeek::lookup_type("x509_opaque_vector")->AsVectorType()); for ( int i = 0; i < num_certs; i++ ) { diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 5f0933d234..3b37a33e2a 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -1276,7 +1276,7 @@ bool Manager::WriteFromRemote(EnumVal* id, EnumVal* writer, const string& path, void Manager::SendAllWritersTo(const broker::endpoint_info& ei) { - auto et = internal_type("Log::Writer")->AsEnumType(); + auto et = zeek::lookup_type("Log::Writer")->AsEnumType(); for ( vector::iterator s = streams.begin(); s != streams.end(); ++s ) { diff --git a/src/stats.bif b/src/stats.bif index 94baccc78a..30853711a7 100644 --- a/src/stats.bif +++ b/src/stats.bif @@ -470,7 +470,7 @@ function get_reporter_stats%(%): ReporterStats auto r = make_intrusive(ReporterStats); int n = 0; - TableVal* weirds_by_type = new TableVal({NewRef{}, internal_type("table_string_of_count")->AsTableType()}); + auto weirds_by_type = make_intrusive(zeek::lookup_type("table_string_of_count")); for ( auto& kv : reporter->GetWeirdsByType() ) { @@ -479,7 +479,7 @@ function get_reporter_stats%(%): ReporterStats } r->Assign(n++, val_mgr->Count(reporter->GetWeirdCount())); - r->Assign(n++, weirds_by_type); + r->Assign(n++, std::move(weirds_by_type)); return r; %} diff --git a/src/strings.bif b/src/strings.bif index 06ce9939c3..fca92c980d 100644 --- a/src/strings.bif +++ b/src/strings.bif @@ -204,7 +204,7 @@ static IntrusivePtr do_split_string(StringVal* str_val, int max_num_sep) { // string_vec is used early in the version script - do not use the NetVar. - auto rval = make_intrusive(internal_type("string_vec")->AsVectorType()); + auto rval = make_intrusive(zeek::lookup_type("string_vec")->AsVectorType()); const u_char* s = str_val->Bytes(); int n = str_val->Len(); const u_char* end_of_s = s + n; @@ -714,7 +714,7 @@ function str_split%(s: string, idx: index_vec%): string_vec BroString::Vec* result = s->AsString()->Split(indices); auto result_v = make_intrusive( - internal_type("string_vec")->AsVectorType()); + zeek::lookup_type("string_vec")->AsVectorType()); if ( result ) { diff --git a/src/zeek.bif b/src/zeek.bif index 91e7d82000..1bd4227ec2 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -30,6 +30,7 @@ #include "Hash.h" using namespace std; +using namespace zeek; TableType* var_sizes; @@ -1470,7 +1471,7 @@ function sort%(v: any, ...%) : any function order%(v: any, ...%) : index_vec %{ auto result_v = make_intrusive( - internal_type("index_vec")->AsVectorType()); + lookup_type("index_vec")->AsVectorType()); if ( v->Type()->Tag() != TYPE_VECTOR ) { @@ -1824,15 +1825,12 @@ function zeek_version%(%): string function record_type_to_vector%(rt: string%): string_vec %{ auto result = - make_intrusive(internal_type("string_vec")->AsVectorType()); + make_intrusive(lookup_type("string_vec")->AsVectorType()); - RecordType *type = internal_type(rt->CheckString())->AsRecordType(); + RecordType* type = lookup_type(rt->CheckString())->AsRecordType(); - if ( type ) - { - for ( int i = 0; i < type->NumFields(); ++i ) - result->Assign(i+1, make_intrusive(type->FieldName(i))); - } + for ( int i = 0; i < type->NumFields(); ++i ) + result->Assign(i+1, make_intrusive(type->FieldName(i))); return result; %} @@ -1856,7 +1854,7 @@ function type_name%(t: any%): string ## Returns: list of command-line arguments (``argv``) used to run Zeek. function zeek_args%(%): string_vec %{ - auto sv = internal_type("string_vec")->AsVectorType(); + auto sv = lookup_type("string_vec")->AsVectorType(); auto rval = make_intrusive(sv); for ( auto i = 0; i < bro_argc; ++i ) @@ -1894,7 +1892,7 @@ function reading_traces%(%): bool ## .. zeek:see:: reading_live_traffic reading_traces function packet_source%(%): PacketSource %{ - auto ps_type = internal_type("PacketSource")->AsRecordType(); + auto ps_type = lookup_type("PacketSource")->AsRecordType(); auto ps = iosource_mgr->GetPktSrc(); auto r = make_intrusive(ps_type); @@ -2002,7 +2000,7 @@ function record_fields%(rec: any%): record_field_table if ( ! id || ! id->IsType() || id->GetType()->Tag() != TYPE_RECORD ) { reporter->Error("record_fields string argument does not name a record type"); - IntrusivePtr tt{NewRef{}, internal_type("record_field_table")->AsTableType()}; + auto tt = lookup_type("record_field_table"); return make_intrusive(std::move(tt)); } @@ -2189,7 +2187,7 @@ function is_v6_subnet%(s: subnet%): bool ## Returns: The vector of addresses contained in the routing header data. function routing0_data_to_addrs%(s: string%): addr_vec %{ - auto rval = make_intrusive(internal_type("addr_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("addr_vec")->AsVectorType()); int len = s->Len(); const u_char* bytes = s->Bytes(); @@ -2220,7 +2218,7 @@ function routing0_data_to_addrs%(s: string%): addr_vec ## .. zeek:see:: counts_to_addr function addr_to_counts%(a: addr%): index_vec %{ - auto rval = make_intrusive(internal_type("index_vec")->AsVectorType()); + auto rval = make_intrusive(lookup_type("index_vec")->AsVectorType()); const uint32_t* bytes; int len = a->AsAddr().GetBytes(&bytes);