From 464efbe66aa23c75772dc2e07b8a69df8efdd30a Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Tue, 23 Jun 2020 13:25:43 -0700 Subject: [PATCH] Move Dictionary/PDict, List/PList, and Queue/PQueue to zeek namespace --- src/BroList.h | 14 +-- src/Continuation.h | 3 +- src/DNS_Mgr.h | 3 +- src/Debug.h | 2 +- src/DebugCmds.cc | 2 +- src/DebugCmds.h | 2 +- src/Dict.cc | 99 ++++++++++--------- src/Dict.h | 43 ++++---- src/List.cc | 12 +-- src/List.h | 10 +- src/NFA.h | 2 +- src/Queue.h | 6 ++ src/RE.h | 4 +- src/Reporter.cc | 2 +- src/Rule.h | 14 +-- src/RuleMatcher.h | 15 ++- src/Scope.cc | 2 +- src/Stmt.h | 4 +- src/Type.h | 2 +- src/Val.h | 13 ++- .../protocol/stepping-stone/SteppingStone.h | 4 +- src/broker/messaging.bif | 4 +- src/file_analysis/AnalyzerSet.h | 6 +- src/file_analysis/File.cc | 8 +- src/input.h | 2 +- src/input/Manager.cc | 14 +-- src/logging/Manager.cc | 2 +- src/probabilistic/Topk.cc | 4 +- src/probabilistic/Topk.h | 2 +- src/scan.l | 10 +- 30 files changed, 172 insertions(+), 138 deletions(-) diff --git a/src/BroList.h b/src/BroList.h index 2a76b6999d..cd80531d4a 100644 --- a/src/BroList.h +++ b/src/BroList.h @@ -5,23 +5,23 @@ #include "List.h" ZEEK_FORWARD_DECLARE_NAMESPACED(Val, zeek); -using val_list = PList; +using val_list = zeek::PList; ZEEK_FORWARD_DECLARE_NAMESPACED(Expr, zeek::detail); -using expr_list = PList; +using expr_list = zeek::PList; ZEEK_FORWARD_DECLARE_NAMESPACED(ID, zeek::detail); -using id_list = PList; +using id_list = zeek::PList; ZEEK_FORWARD_DECLARE_NAMESPACED(Stmt, zeek::detail); -using stmt_list = PList; +using stmt_list = zeek::PList; namespace zeek { class Type; } using BroType [[deprecated("Remove in v4.1. Use zeek::Type instead.")]] = zeek::Type; -using type_list = PList; +using type_list = zeek::PList; ZEEK_FORWARD_DECLARE_NAMESPACED(Attr, zeek::detail); -using attr_list = PList; +using attr_list = zeek::PList; class Timer; -using timer_list = PList; +using timer_list = zeek::PList; diff --git a/src/Continuation.h b/src/Continuation.h index 039b37f249..455cf52a73 100644 --- a/src/Continuation.h +++ b/src/Continuation.h @@ -49,7 +49,6 @@ private: int current_level; int suspend_level; - typedef PList voidp_list; - + using voidp_list = zeek::PList; voidp_list states; }; diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 57b0da8d27..a8f353562e 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -29,8 +29,7 @@ using ListValPtr = zeek::IntrusivePtr; using TableValPtr = zeek::IntrusivePtr; } - -typedef PList DNS_mgr_request_list; +using DNS_mgr_request_list = zeek::PList; struct nb_dns_info; struct nb_dns_result; diff --git a/src/Debug.h b/src/Debug.h index 32fc329723..a53746728a 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -30,7 +30,7 @@ struct ParseLocationRec { }; class StmtLocMapping; -typedef PQueue Filemap; // mapping for a single file +typedef zeek::PQueue Filemap; // mapping for a single file class DbgBreakpoint; class DbgWatch; diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index 550a0c6f7f..525fc73342 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -123,7 +123,7 @@ static void choose_global_symbols_regex(const string& regex, vector g_DebugCmdInfos; +zeek::PQueue g_DebugCmdInfos; DebugCmdInfo::DebugCmdInfo(const DebugCmdInfo& info) : cmd(info.cmd), helpstring(nullptr) diff --git a/src/DebugCmds.h b/src/DebugCmds.h index ff318140e0..9753923903 100644 --- a/src/DebugCmds.h +++ b/src/DebugCmds.h @@ -41,7 +41,7 @@ protected: bool repeatable; }; -extern PQueue g_DebugCmdInfos; +extern zeek::PQueue g_DebugCmdInfos; void init_global_dbg_constants (); diff --git a/src/Dict.cc b/src/Dict.cc index 2fa2eae0a6..2d1f82f40f 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -13,17 +13,18 @@ // If the mean bucket length exceeds the following then Insert() will // increase the size of the hash table. -#define DEFAULT_DENSITY_THRESH 3.0 +constexpr double DEFAULT_DENSITY_THRESH = 3.0; // Threshold above which we do not try to ensure that the hash size // is prime. -#define PRIME_THRESH 1000 +constexpr int PRIME_THRESH = 1000; // Default number of hash buckets in dictionary. The dictionary will // increase the size of the hash table as needed. -#define DEFAULT_DICT_SIZE 16 +constexpr int DEFAULT_DICT_SIZE = 16; -TEST_SUITE_BEGIN("Dict"); +namespace zeek { +namespace detail { class DictEntry { public: @@ -40,6 +41,8 @@ public: void* value; }; +} //namespace detail + // The value of an iteration cookie is the bucket and offset within the // bucket at which to start looking for the next value to return. class IterCookie { @@ -47,25 +50,29 @@ public: IterCookie(int b, int o) : bucket(b), offset(o) {} int bucket, offset; - PList** ttbl = nullptr; + zeek::PList** ttbl = nullptr; const int* num_buckets_p = nullptr; - PList inserted; // inserted while iterating + zeek::PList inserted; // inserted while iterating }; +} // namespace zeek + +TEST_SUITE_BEGIN("Dict"); + TEST_CASE("dict construction") { - PDict dict; + zeek::PDict dict; CHECK(dict.IsOrdered() == false); CHECK(dict.Length() == 0); - PDict dict2(ORDERED); + zeek::PDict dict2(zeek::ORDERED); CHECK(dict2.IsOrdered() == true); CHECK(dict2.Length() == 0); } TEST_CASE("dict operation") { - PDict dict; + zeek::PDict dict; uint32_t val = 10; uint32_t key_val = 5; @@ -111,8 +118,8 @@ TEST_CASE("dict operation") TEST_CASE("dict nthentry") { - PDict unordered(UNORDERED); - PDict ordered(ORDERED); + zeek::PDict unordered(zeek::UNORDERED); + zeek::PDict ordered(zeek::ORDERED); uint32_t val = 15; uint32_t key_val = 5; @@ -147,7 +154,7 @@ TEST_CASE("dict nthentry") TEST_CASE("dict iteration") { - PDict dict; + zeek::PDict dict; uint32_t val = 15; uint32_t key_val = 5; @@ -161,7 +168,7 @@ TEST_CASE("dict iteration") dict.Insert(key2, &val2); HashKey* it_key; - IterCookie* it = dict.InitForIteration(); + zeek::IterCookie* it = dict.InitForIteration(); CHECK(it != nullptr); int count = 0; @@ -186,10 +193,14 @@ TEST_CASE("dict iteration") delete key2; } -Dictionary::Dictionary(dict_order ordering, int initial_size) +TEST_SUITE_END(); + +namespace zeek { + +Dictionary::Dictionary(DictOrder ordering, int initial_size) { if ( ordering == ORDERED ) - order = new PList; + order = new zeek::PList; if ( initial_size > 0 ) Init(initial_size); @@ -218,7 +229,7 @@ void Dictionary::DeInit() for ( int i = 0; i < num_buckets; ++i ) if ( tbl[i] ) { - PList* chain = tbl[i]; + zeek::PList* chain = tbl[i]; for ( const auto& e : *chain ) { if ( delete_func ) @@ -238,7 +249,7 @@ void Dictionary::DeInit() for ( int i = 0; i < num_buckets2; ++i ) if ( tbl2[i] ) { - PList* chain = tbl2[i]; + zeek::PList* chain = tbl2[i]; for ( const auto& e : *chain ) { if ( delete_func ) @@ -259,7 +270,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const return nullptr; hash_t h; - PList* chain; + zeek::PList* chain; // Figure out which hash table to look in. h = hash % num_buckets; @@ -287,12 +298,12 @@ void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val, if ( ! tbl ) Init(DEFAULT_DICT_SIZE); - DictEntry* new_entry = new DictEntry(key, key_size, hash, val); + detail::DictEntry* new_entry = new detail::DictEntry(key, key_size, hash, val); void* old_val = Insert(new_entry, copy_key); if ( old_val ) { - // We didn't need the new DictEntry, the key was already + // We didn't need the new detail::DictEntry, the key was already // present. delete new_entry; } @@ -315,7 +326,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, return nullptr; hash_t h; - PList* chain; + zeek::PList* chain; int* num_entries_ptr; // Figure out which hash table to look in @@ -338,7 +349,7 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, for ( auto i = 0u; i < chain_length; ++i ) { - DictEntry* entry = (*chain)[i]; + detail::DictEntry* entry = (*chain)[i]; if ( entry->hash == hash && entry->len == key_size && ! memcmp(key, entry->key, key_size) ) @@ -357,8 +368,8 @@ void* Dictionary::Remove(const void* key, int key_size, hash_t hash, return nullptr; } -void* Dictionary::DoRemove(DictEntry* entry, hash_t h, - PList* chain, int chain_offset) +void* Dictionary::DoRemove(detail::DictEntry* entry, hash_t h, + zeek::PList* chain, int chain_offset) { void* entry_value = entry->value; @@ -397,7 +408,7 @@ void* Dictionary::NthEntry(int n, const void*& key, int& key_len) const if ( ! order || n < 0 || n >= Length() ) return nullptr; - DictEntry* entry = (*order)[n]; + detail::DictEntry* entry = (*order)[n]; key = entry->key; key_len = entry->len; return entry->value; @@ -417,7 +428,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c { if ( ! tbl && ! tbl2 ) { - const_cast*>(&cookies)->remove(cookie); + const_cast*>(&cookies)->remove(cookie); delete cookie; cookie = nullptr; return nullptr; @@ -427,7 +438,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c // That keeps the list small and helps avoiding searching // a large list when deleting an entry. - DictEntry* entry; + detail::DictEntry* entry; if ( cookie->inserted.length() ) { @@ -442,7 +453,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c int b = cookie->bucket; int o = cookie->offset; - PList** ttbl; + zeek::PList** ttbl; const int* num_buckets_p; if ( ! cookie->ttbl ) @@ -484,7 +495,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c // FIXME: I don't like removing the const here. But is there // a better way? - const_cast*>(&cookies)->remove(cookie); + const_cast*>(&cookies)->remove(cookie); delete cookie; cookie = nullptr; return nullptr; @@ -503,7 +514,7 @@ void* Dictionary::NextEntry(HashKey*& h, IterCookie*& cookie, int return_hash) c void Dictionary::Init(int size) { num_buckets = NextPrime(size); - tbl = new PList*[num_buckets]; + tbl = new zeek::PList*[num_buckets]; for ( int i = 0; i < num_buckets; ++i ) tbl[i] = nullptr; @@ -515,7 +526,7 @@ void Dictionary::Init(int size) void Dictionary::Init2(int size) { num_buckets2 = NextPrime(size); - tbl2 = new PList*[num_buckets2]; + tbl2 = new zeek::PList*[num_buckets2]; for ( int i = 0; i < num_buckets2; ++i ) tbl2[i] = nullptr; @@ -524,12 +535,12 @@ void Dictionary::Init2(int size) } // private -void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) +void* Dictionary::Insert(detail::DictEntry* new_entry, bool copy_key) { if ( ! tbl ) Init(DEFAULT_DICT_SIZE); - PList** ttbl; + zeek::PList** ttbl; int* num_entries_ptr; int* max_num_entries_ptr; hash_t h = new_entry->hash % num_buckets; @@ -554,7 +565,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) max_num_entries_ptr = &max_num_entries2; } - PList* chain = ttbl[h]; + zeek::PList* chain = ttbl[h]; int n = new_entry->len; @@ -562,7 +573,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) { for ( int i = 0; i < chain->length(); ++i ) { - DictEntry* entry = (*chain)[i]; + detail::DictEntry* entry = (*chain)[i]; if ( entry->hash == new_entry->hash && entry->len == n && @@ -576,7 +587,7 @@ void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) } else // Create new chain. - chain = ttbl[h] = new PList; + chain = ttbl[h] = new zeek::PList; // If we got this far, then we couldn't use an existing copy // of the key, so make a new one if necessary. @@ -660,7 +671,7 @@ void Dictionary::MoveChains() do { - PList* chain = tbl[tbl_next_ind++]; + zeek::PList* chain = tbl[tbl_next_ind++]; if ( ! chain ) continue; @@ -720,13 +731,13 @@ unsigned int Dictionary::MemoryAllocation() const for ( int i = 0; i < num_buckets; ++i ) if ( tbl[i] ) { - PList* chain = tbl[i]; + zeek::PList* chain = tbl[i]; for ( const auto& c : *chain ) - size += padded_sizeof(DictEntry) + pad_size(c->len); + size += padded_sizeof(detail::DictEntry) + pad_size(c->len); size += chain->MemoryAllocation(); } - size += pad_size(num_buckets * sizeof(PList*)); + size += pad_size(num_buckets * sizeof(zeek::PList*)); if ( order ) size += order->MemoryAllocation(); @@ -736,13 +747,13 @@ unsigned int Dictionary::MemoryAllocation() const for ( int i = 0; i < num_buckets2; ++i ) if ( tbl2[i] ) { - PList* chain = tbl2[i]; + zeek::PList* chain = tbl2[i]; for ( const auto& c : *chain ) - size += padded_sizeof(DictEntry) + pad_size(c->len); + size += padded_sizeof(detail::DictEntry) + pad_size(c->len); size += chain->MemoryAllocation(); } - size += pad_size(num_buckets2 * sizeof(PList*)); + size += pad_size(num_buckets2 * sizeof(zeek::PList*)); } return size; @@ -753,4 +764,4 @@ void generic_delete_func(void* v) free(v); } -TEST_SUITE_END(); +} // namespace zeek diff --git a/src/Dict.h b/src/Dict.h index 22840a0dad..3210605944 100644 --- a/src/Dict.h +++ b/src/Dict.h @@ -2,27 +2,31 @@ #pragma once +#include "zeek-config.h" + #include "List.h" #include "Hash.h" -class Dictionary; -class DictEntry; -class IterCookie; - -// Type indicating whether the dictionary should keep track of the order -// of insertions. -enum dict_order { ORDERED, UNORDERED }; +ZEEK_FORWARD_DECLARE_NAMESPACED(DictEntry, zeek::detail); +ZEEK_FORWARD_DECLARE_NAMESPACED(IterCookie, zeek); // Type for function to be called when deleting elements. typedef void (*dict_delete_func)(void*); +namespace zeek { + +// Type indicating whether the dictionary should keep track of the order +// of insertions. +enum DictOrder { ORDERED, UNORDERED }; + // A dict_delete_func that just calls delete. extern void generic_delete_func(void*); class Dictionary { public: - explicit Dictionary(dict_order ordering = UNORDERED, - int initial_size = 0); + explicit Dictionary(DictOrder ordering = UNORDERED, + int initial_size = 0); + ~Dictionary(); // Member functions for looking up a key, inserting/changing its @@ -125,10 +129,10 @@ private: void DeInit(); // Internal version of Insert(). - void* Insert(DictEntry* entry, bool copy_key); + void* Insert(zeek::detail::DictEntry* entry, bool copy_key); - void* DoRemove(DictEntry* entry, hash_t h, - PList* chain, int chain_offset); + void* DoRemove(zeek::detail::DictEntry* entry, hash_t h, + zeek::PList* chain, int chain_offset); int NextPrime(int n) const; bool IsPrime(int n) const; @@ -158,7 +162,7 @@ private: // When we're resizing, we'll have tbl (old) and tbl2 (new) // tbl_next_ind keeps track of how much we've moved to tbl2 // (it's the next index we're going to move). - PList** tbl = nullptr; + zeek::PList** tbl = nullptr; int num_buckets = 0; int num_entries = 0; int max_num_entries = 0; @@ -167,7 +171,7 @@ private: double den_thresh = 0.0; // Resizing table (replicates tbl above). - PList** tbl2 = nullptr; + zeek::PList** tbl2 = nullptr; int num_buckets2 = 0; int num_entries2 = 0; int max_num_entries2 = 0; @@ -177,16 +181,16 @@ private: hash_t tbl_next_ind = 0; - PList* order = nullptr; + zeek::PList* order = nullptr; dict_delete_func delete_func = nullptr; - PList cookies; + zeek::PList cookies; }; template class PDict : public Dictionary { public: - explicit PDict(dict_order ordering = UNORDERED, int initial_size = 0) : + explicit PDict(DictOrder ordering = UNORDERED, int initial_size = 0) : Dictionary(ordering, initial_size) {} T* Lookup(const char* key) const { @@ -221,3 +225,8 @@ public: T* RemoveEntry(const HashKey& key) { return (T*) Remove(key.Key(), key.Size(), key.Hash()); } }; + +} //namespace zeek + +using Dictionary [[deprecated("Remove in v4.1. Use zeek::Dictionary instead.")]] = zeek::Dictionary; +template using PDict [[deprecated("Remove in v4.1. Use zeek::PDict instead.")]] = zeek::PDict; diff --git a/src/List.cc b/src/List.cc index c19353b341..375d0c21a0 100644 --- a/src/List.cc +++ b/src/List.cc @@ -3,17 +3,17 @@ TEST_CASE("list construction") { - List list; + zeek::List list; CHECK(list.empty()); - List list2(10); + zeek::List list2(10); CHECK(list2.empty()); CHECK(list2.max() == 10); } TEST_CASE("list operation") { - List list({ 1, 2, 3 }); + zeek::List list({ 1, 2, 3 }); CHECK(list.size() == 3); CHECK(list.max() == 3); CHECK(list[0] == 1); @@ -85,7 +85,7 @@ TEST_CASE("list operation") TEST_CASE("list iteration") { - List list({ 1, 2, 3, 4}); + zeek::List list({ 1, 2, 3, 4}); int index = 1; for ( int v : list ) @@ -98,7 +98,7 @@ TEST_CASE("list iteration") TEST_CASE("plists") { - PList list; + zeek::PList list; list.push_back(new int(1)); list.push_back(new int(2)); list.push_back(new int(3)); @@ -117,7 +117,7 @@ TEST_CASE("plists") TEST_CASE("unordered list operation") { - List list({1, 2, 3, 4}); + zeek::List list({1, 2, 3, 4}); CHECK(list.size() == 4); // An unordered list doesn't maintain the ordering of the elements when diff --git a/src/List.h b/src/List.h index 53dc96f9cf..757321439f 100644 --- a/src/List.h +++ b/src/List.h @@ -26,6 +26,10 @@ #include #include "util.h" +//enum class [[deprecated("Remove in v4.1. Use zeek::ListOrder instead.")]] ListOrder : int { ORDERED, UNORDERED }; + +namespace zeek { + enum class ListOrder : int { ORDERED, UNORDERED }; template @@ -331,7 +335,11 @@ template using PList = List; // Popular type of list: list of strings. -typedef PList name_list; +using name_list = PList; + +} // namespace zeek + +using ListOrder [[deprecated("Remove in v4.1. Use zeek::ListOrder instead.")]] = zeek::ListOrder; // Macro to visit each list element in turn. #define loop_over_list(list, iterator) \ diff --git a/src/NFA.h b/src/NFA.h index fa02a3e6a7..c4430a88c0 100644 --- a/src/NFA.h +++ b/src/NFA.h @@ -11,7 +11,7 @@ class EquivClass; ZEEK_FORWARD_DECLARE_NAMESPACED(Func, zeek::detail); -typedef PList NFA_state_list; +using NFA_state_list = zeek::PList; #define NO_ACCEPT 0 diff --git a/src/Queue.h b/src/Queue.h index 1e5447ef27..c3fba49ef9 100644 --- a/src/Queue.h +++ b/src/Queue.h @@ -22,6 +22,7 @@ // Entries must be either a pointer to the data or nonzero data with // sizeof(data) <= sizeof(void*). +namespace zeek { template class Queue { @@ -196,3 +197,8 @@ protected: template using PQueue = Queue; + +} // namespace zeek + +template using Queue [[deprecated("Remove in v4.1. Use zeek::Queue instead.")]] = zeek::Queue; +template using PQueue [[deprecated("Remove in v4.1. Use zeek::Queue instead.")]] = zeek::PQueue; diff --git a/src/RE.h b/src/RE.h index dfadcaaf28..6f6481b92f 100644 --- a/src/RE.h +++ b/src/RE.h @@ -36,7 +36,7 @@ typedef int AcceptIdx; typedef std::set AcceptingSet; typedef uint64_t MatchPos; typedef std::map AcceptingMatchSet; -typedef name_list string_list; +typedef zeek::name_list string_list; typedef enum { MATCH_ANYWHERE, MATCH_EXACTLY, } match_type; @@ -128,7 +128,7 @@ protected: std::map defs; std::map ccl_dict; - PList ccl_list; + zeek::PList ccl_list; EquivClass equiv_class; int* ecs; DFA_Machine* dfa; diff --git a/src/Reporter.cc b/src/Reporter.cc index 8511f6c02a..66c048137e 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -73,7 +73,7 @@ void Reporter::InitOptions() auto wl_table = wl_val->AsTable(); HashKey* k; - IterCookie* c = wl_table->InitForIteration(); + zeek::IterCookie* c = wl_table->InitForIteration(); zeek::TableEntryVal* v; while ( (v = wl_table->NextEntry(k, c)) ) diff --git a/src/Rule.h b/src/Rule.h index 29099dcb8e..ad22186339 100644 --- a/src/Rule.h +++ b/src/Rule.h @@ -14,8 +14,8 @@ class RuleAction; class RuleHdrTest; class Rule; -typedef PList rule_list; -typedef std::map rule_dict; +using rule_list = zeek::PList; +using rule_dict = std::map; class Rule { public: @@ -58,9 +58,9 @@ private: void SortHdrTests(); - typedef PList rule_action_list; - typedef PList rule_condition_list; - typedef PList rule_hdr_test_list; + using rule_action_list = zeek::PList; + using rule_condition_list = zeek::PList; + using rule_hdr_test_list = zeek::PList; rule_hdr_test_list hdr_tests; rule_condition_list conditions; @@ -74,7 +74,7 @@ private: bool negate; // negate test }; - typedef PList precond_list; + using precond_list = zeek::PList; precond_list preconds; rule_list dependents; // rules w/ us as a precondition @@ -92,7 +92,7 @@ private: uint32_t depth; }; - typedef PList pattern_list; + using pattern_list = zeek::PList; pattern_list patterns; Rule* next; // Linkage within RuleHdrTest tree: diff --git a/src/RuleMatcher.h b/src/RuleMatcher.h index 7c5e062cae..c98032d923 100644 --- a/src/RuleMatcher.h +++ b/src/RuleMatcher.h @@ -57,9 +57,9 @@ struct MaskedValue { uint32_t mask; }; -typedef PList maskedvalue_list; -typedef PList string_list; -typedef PList bstr_list; +using maskedvalue_list = zeek::PList; +using string_list = zeek::PList; +using bstr_list = zeek::PList; // Get values from Bro's script-level variables. extern void id_to_maskedvallist(const char* id, maskedvalue_list* append_to, @@ -117,7 +117,7 @@ private: int_list ids; // (only needed for debugging) }; - typedef PList pattern_set_list; + using pattern_set_list = zeek::PList; pattern_set_list psets[Rule::TYPES]; // List of rules belonging to this node. @@ -131,7 +131,7 @@ private: RuleHdrTest* child; }; -typedef PList rule_hdr_test_list; +using rule_hdr_test_list = zeek::PList; // RuleEndpointState keeps the per-stream matching state of one // connection endpoint. @@ -166,7 +166,7 @@ private: Rule::PatternType type; }; - typedef PList matcher_list; + using matcher_list = zeek::PList; analyzer::Analyzer* analyzer; RuleEndpointState* opposite; @@ -205,8 +205,7 @@ private: RE_Match_State* state; }; - typedef PList matcher_list; - + using matcher_list = zeek::PList; matcher_list matchers; }; diff --git a/src/Scope.cc b/src/Scope.cc index 1084291d6c..3743440551 100644 --- a/src/Scope.cc +++ b/src/Scope.cc @@ -12,7 +12,7 @@ namespace zeek::detail { -using scope_list = PList; +using scope_list = zeek::PList; static scope_list scopes; static Scope* top_scope; diff --git a/src/Stmt.h b/src/Stmt.h index 0858c1022c..7eeec1b613 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -190,7 +190,7 @@ protected: StmtPtr s; }; -using case_list = PList; +using case_list = zeek::PList; class SwitchStmt final : public ExprStmt { public: @@ -229,7 +229,7 @@ protected: case_list* cases; int default_case_idx; CompositeHash* comp_hash; - PDict case_label_value_map; + zeek::PDict case_label_value_map; std::vector> case_label_type_list; }; diff --git a/src/Type.h b/src/Type.h index 6fa0d5816a..ac5bab4422 100644 --- a/src/Type.h +++ b/src/Type.h @@ -620,7 +620,7 @@ public: const char* id = nullptr; }; -using type_decl_list = PList; +using type_decl_list = zeek::PList; class RecordType final : public Type { public: diff --git a/src/Val.h b/src/Val.h index 46a5368153..082951ef10 100644 --- a/src/Val.h +++ b/src/Val.h @@ -25,9 +25,12 @@ #define UDP_PORT_MASK 0x20000 #define ICMP_PORT_MASK 0x30000 +namespace zeek { template class PDict; +}; +template using PDict [[deprecated("Remove in v4.1. Use zeek::PDict instead.")]] = zeek::PDict; -class IterCookie; +ZEEK_FORWARD_DECLARE_NAMESPACED(IterCookie, zeek); class BroString; class BroFile; @@ -99,7 +102,7 @@ union BroValUnion { zeek::detail::Func* func_val; BroFile* file_val; RE_Matcher* re_val; - PDict* table_val; + zeek::PDict* table_val; std::vector* record_val; std::vector* vector_val; @@ -132,7 +135,7 @@ union BroValUnion { constexpr BroValUnion(RE_Matcher* value) noexcept : re_val(value) {} - constexpr BroValUnion(PDict* value) noexcept + constexpr BroValUnion(zeek::PDict* value) noexcept : table_val(value) {} }; @@ -237,7 +240,7 @@ public: CONST_ACCESSOR2(zeek::TYPE_ENUM, int, int_val, AsEnum) CONST_ACCESSOR(zeek::TYPE_STRING, BroString*, string_val, AsString) CONST_ACCESSOR(zeek::TYPE_FUNC, zeek::detail::Func*, func_val, AsFunc) - CONST_ACCESSOR(zeek::TYPE_TABLE, PDict*, table_val, AsTable) + CONST_ACCESSOR(zeek::TYPE_TABLE, zeek::PDict*, table_val, AsTable) CONST_ACCESSOR(zeek::TYPE_RECORD, std::vector*, record_val, AsRecord) CONST_ACCESSOR(zeek::TYPE_FILE, BroFile*, file_val, AsFile) CONST_ACCESSOR(zeek::TYPE_PATTERN, RE_Matcher*, re_val, AsPattern) @@ -385,7 +388,7 @@ protected: : type(std::move(t)) {} - ACCESSOR(zeek::TYPE_TABLE, PDict*, table_val, AsNonConstTable) + ACCESSOR(zeek::TYPE_TABLE, zeek::PDict*, table_val, AsNonConstTable) ACCESSOR(zeek::TYPE_RECORD, std::vector*, record_val, AsNonConstRecord) // For internal use by the Val::Clone() methods. diff --git a/src/analyzer/protocol/stepping-stone/SteppingStone.h b/src/analyzer/protocol/stepping-stone/SteppingStone.h index b0a22ace90..77796a5694 100644 --- a/src/analyzer/protocol/stepping-stone/SteppingStone.h +++ b/src/analyzer/protocol/stepping-stone/SteppingStone.h @@ -70,14 +70,14 @@ protected: class SteppingStoneManager { public: - PQueue& OrderedEndpoints() + zeek::PQueue& OrderedEndpoints() { return ordered_endps; } // Use postfix ++, since the first ID needs to be even. int NextID() { return endp_cnt++; } protected: - PQueue ordered_endps; + zeek::PQueue ordered_endps; int endp_cnt = 0; }; diff --git a/src/broker/messaging.bif b/src/broker/messaging.bif index 51a8077a71..7370e9e0bd 100644 --- a/src/broker/messaging.bif +++ b/src/broker/messaging.bif @@ -28,12 +28,12 @@ std::set val_to_topic_set(zeek::Val* val) rval.emplace(val->AsString()->CheckString()); else { - const PDict* tbl = val->AsTable(); + const zeek::PDict* tbl = val->AsTable(); if ( tbl->Length() == 0 ) return rval; - IterCookie* c = tbl->InitForIteration(); + zeek::IterCookie* c = tbl->InitForIteration(); HashKey* k; while ( tbl->NextEntry(k, c) ) diff --git a/src/file_analysis/AnalyzerSet.h b/src/file_analysis/AnalyzerSet.h index e8f5cc9c89..0860d35989 100644 --- a/src/file_analysis/AnalyzerSet.h +++ b/src/file_analysis/AnalyzerSet.h @@ -93,7 +93,7 @@ public: * @see Dictionary#InitForIteration * @return an iterator that may be used to loop over analyzers in the set. */ - IterCookie* InitForIteration() const + zeek::IterCookie* InitForIteration() const { return analyzer_map.InitForIteration(); } /** @@ -103,7 +103,7 @@ public: * @return the next analyzer in the set or a null pointer if there is no * more left (in that case the cookie is also deleted). */ - file_analysis::Analyzer* NextEntry(IterCookie* c) + file_analysis::Analyzer* NextEntry(zeek::IterCookie* c) { return analyzer_map.NextEntry(c); } protected: @@ -145,7 +145,7 @@ private: File* file; /**< File which owns the set */ CompositeHash* analyzer_hash; /**< AnalyzerArgs hashes. */ - PDict analyzer_map; /**< Indexed by AnalyzerArgs. */ + zeek::PDict analyzer_map; /**< Indexed by AnalyzerArgs. */ /** * Abstract base class for analyzer set modifications. diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 7bc87c2b64..0d4a7a1fc3 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -394,7 +394,7 @@ void File::DeliverStream(const u_char* data, uint64_t len) len > 40 ? "..." : ""); file_analysis::Analyzer* a = nullptr; - IterCookie* c = analyzers.InitForIteration(); + zeek::IterCookie* c = analyzers.InitForIteration(); while ( (a = analyzers.NextEntry(c)) ) { @@ -498,7 +498,7 @@ void File::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) len > 40 ? "..." : ""); file_analysis::Analyzer* a = nullptr; - IterCookie* c = analyzers.InitForIteration(); + zeek::IterCookie* c = analyzers.InitForIteration(); while ( (a = analyzers.NextEntry(c)) ) { @@ -562,7 +562,7 @@ void File::EndOfFile() done = true; file_analysis::Analyzer* a = nullptr; - IterCookie* c = analyzers.InitForIteration(); + zeek::IterCookie* c = analyzers.InitForIteration(); while ( (a = analyzers.NextEntry(c)) ) { @@ -595,7 +595,7 @@ void File::Gap(uint64_t offset, uint64_t len) } file_analysis::Analyzer* a = nullptr; - IterCookie* c = analyzers.InitForIteration(); + zeek::IterCookie* c = analyzers.InitForIteration(); while ( (a = analyzers.NextEntry(c)) ) { diff --git a/src/input.h b/src/input.h index 2aacbea9a8..ab21d276ad 100644 --- a/src/input.h +++ b/src/input.h @@ -18,7 +18,7 @@ extern void add_input_file_at_front(const char* file); // Adds the substrings (using the given delimiter) in a string to the // given namelist. -extern void add_to_name_list(char* s, char delim, name_list& nl); +extern void add_to_name_list(char* s, char delim, zeek::name_list& nl); extern void begin_RE(); diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 915ed0140d..ce3daab8ea 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -99,8 +99,8 @@ public: zeek::RecordType* rtype; zeek::RecordType* itype; - PDict* currDict; - PDict* lastDict; + zeek::PDict* currDict; + zeek::PDict* lastDict; zeek::detail::Func* pred; @@ -273,7 +273,7 @@ bool Manager::CreateStream(Stream* info, zeek::RecordVal* description) { // create config mapping in ReaderInfo. Has to be done before the construction of reader_obj. HashKey* k; - IterCookie* c = info->config->AsTable()->InitForIteration(); + zeek::IterCookie* c = info->config->AsTable()->InitForIteration(); zeek::TableEntryVal* v; while ( (v = info->config->AsTable()->NextEntry(k, c)) ) @@ -674,9 +674,9 @@ bool Manager::CreateTableStream(zeek::RecordVal* fval) stream->itype = idx->Ref()->AsRecordType(); stream->event = event ? event_registry->Lookup(event->Name()) : nullptr; stream->error_event = error_event ? event_registry->Lookup(error_event->Name()) : nullptr; - stream->currDict = new PDict; + stream->currDict = new zeek::PDict; stream->currDict->SetDeleteFunc(input_hash_delete_func); - stream->lastDict = new PDict; + stream->lastDict = new zeek::PDict; stream->lastDict->SetDeleteFunc(input_hash_delete_func); stream->want_record = ( want_record->InternalInt() == 1 ); @@ -1319,7 +1319,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) TableStream* stream = (TableStream*) i; // lastdict contains all deleted entries and should be empty apart from that - IterCookie *c = stream->lastDict->InitForIteration(); + zeek::IterCookie *c = stream->lastDict->InitForIteration(); stream->lastDict->MakeRobustCookie(c); InputHash* ih; HashKey *lastDictIdxKey; @@ -1372,7 +1372,7 @@ void Manager::EndCurrentSend(ReaderFrontend* reader) delete(stream->lastDict); stream->lastDict = stream->currDict; - stream->currDict = new PDict; + stream->currDict = new zeek::PDict; stream->currDict->SetDeleteFunc(input_hash_delete_func); #ifdef DEBUG diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 89cb766d04..f4ed52cc3d 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -859,7 +859,7 @@ bool Manager::Write(zeek::EnumVal* id, zeek::RecordVal* columns_arg) info->network_time = network_time; HashKey* k; - IterCookie* c = filter->config->AsTable()->InitForIteration(); + zeek::IterCookie* c = filter->config->AsTable()->InitForIteration(); zeek::TableEntryVal* v; while ( (v = filter->config->AsTable()->NextEntry(k, c)) ) diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 794d39f5ff..b09dafe54b 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -35,7 +35,7 @@ HashKey* TopkVal::GetHash(Val* v) const TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type) { - elementDict = new PDict; + elementDict = new zeek::PDict; elementDict->SetDeleteFunc(topk_element_hash_delete_func); size = arg_size; numElements = 0; @@ -45,7 +45,7 @@ TopkVal::TopkVal(uint64_t arg_size) : OpaqueVal(topk_type) TopkVal::TopkVal() : OpaqueVal(topk_type) { - elementDict = new PDict; + elementDict = new zeek::PDict; elementDict->SetDeleteFunc(topk_element_hash_delete_func); size = 0; numElements = 0; diff --git a/src/probabilistic/Topk.h b/src/probabilistic/Topk.h index 0b3c1c84ca..c3b47277e1 100644 --- a/src/probabilistic/Topk.h +++ b/src/probabilistic/Topk.h @@ -166,7 +166,7 @@ private: zeek::TypePtr type; CompositeHash* hash; std::list buckets; - PDict* elementDict; + zeek::PDict* elementDict; uint64_t size; // how many elements are we tracking? uint64_t numElements; // how many elements do we have at the moment bool pruned; // was this data structure pruned? diff --git a/src/scan.l b/src/scan.l index 2aa9e16090..2f50b9f37e 100644 --- a/src/scan.l +++ b/src/scan.l @@ -139,7 +139,7 @@ public: // A stack of input buffers we're scanning. file_stack[len-1] is the // top of the stack. -static PList file_stack; +static zeek::PList file_stack; #define RET_CONST(v) \ { \ @@ -835,8 +835,8 @@ void do_atendif() // Be careful to never delete things from this list, as the strings // are referred to (in order to save the locations of tokens and statements, // for error reporting and debugging). -static name_list input_files; -static name_list essential_input_files; +static zeek::name_list input_files; +static zeek::name_list essential_input_files; void add_essential_input_file(const char* file) { @@ -871,7 +871,7 @@ void add_input_file_at_front(const char* file) input_files.push_front(copy_string(file)); } -void add_to_name_list(char* s, char delim, name_list& nl) +void add_to_name_list(char* s, char delim, zeek::name_list& nl) { while ( s ) { @@ -917,7 +917,7 @@ int yywrap() // Stack is now empty. while ( essential_input_files.length() > 0 || input_files.length() > 0 ) { - name_list& files = essential_input_files.length() > 0 ? + zeek::name_list& files = essential_input_files.length() > 0 ? essential_input_files : input_files; if ( load_files(files[0]) )