diff --git a/CHANGES b/CHANGES index 343ee002ea..34cc68dd0f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +3.1.0-dev.237 | 2019-10-31 06:37:23 +0100 + + * Remove "using namespace std" from header files (Jon Siwek, Corelight) + 3.1.0-dev.235 | 2019-10-30 15:04:13 -0700 * GH-649: define missing DLT_NFLOG to support OpenBSD (Jon Siwek, Corelight) diff --git a/VERSION b/VERSION index 6c9ffac794..1c6a28b7f9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.1.0-dev.235 +3.1.0-dev.237 diff --git a/src/Anon.h b/src/Anon.h index 3f19cbd801..f7cbaa24f3 100644 --- a/src/Anon.h +++ b/src/Anon.h @@ -13,7 +13,6 @@ #include #include #include -using namespace std; #include "Reporter.h" #include "net_util.h" diff --git a/src/BroString.h b/src/BroString.h index 35102a7209..f8bcbbc7dd 100644 --- a/src/BroString.h +++ b/src/BroString.h @@ -7,7 +7,6 @@ #include #include #include -using namespace std; #include "util.h" @@ -20,23 +19,23 @@ class VectorVal; class BroString { public: - typedef vector Vec; + typedef std::vector Vec; typedef Vec::iterator VecIt; typedef Vec::const_iterator VecCIt; - typedef vector CVec; + typedef std::vector CVec; typedef Vec::iterator CVecIt; typedef Vec::const_iterator CVecCIt; // IdxVecs are vectors of indices of characters in a string. - typedef vector IdxVec; + typedef std::vector IdxVec; typedef IdxVec::iterator IdxVecIt; typedef IdxVec::const_iterator IdxVecCIt; // Constructors creating internal copies of the data passed in. BroString(const u_char* str, int arg_n, int add_NUL); explicit BroString(const char* str); - explicit BroString(const string& str); + explicit BroString(const std::string& str); BroString(const BroString& bs); // Constructor that takes owernship of the vector passed in. @@ -64,7 +63,7 @@ public: // void Set(const u_char* str, int len, int add_NUL=1); void Set(const char* str); - void Set(const string& str); + void Set(const std::string& str); void Set(const BroString &str); void SetUseFreeToDelete(int use_it) @@ -103,13 +102,13 @@ public: // Also more useful for debugging purposes since no deallocation // is required on your part here. // - ostream& Render(ostream& os, int format = ESC_SER) const; + std::ostream& Render(std::ostream& os, int format = ESC_SER) const; // Reads a string from an input stream. Unless you use a render // style combination that uses ESC_SER, note that the streams // will consider whitespace as a field delimiter. // - istream& Read(istream& is, int format = ESC_SER); + std::istream& Read(std::istream& is, int format = ESC_SER); // XXX Fix redundancy: strings.bif implements both to_lower // XXX and to_upper; the latter doesn't use BroString::ToUpper(). @@ -165,7 +164,7 @@ public: }; // Default output stream operator, using rendering mode EXPANDED_STRING. -ostream& operator<<(ostream& os, const BroString& bs); +std::ostream& operator<<(std::ostream& os, const BroString& bs); extern int Bstr_eq(const BroString* s1, const BroString* s2); extern int Bstr_cmp(const BroString* s1, const BroString* s2); diff --git a/src/DFA.h b/src/DFA.h index 12620568ae..a3b79920f6 100644 --- a/src/DFA.h +++ b/src/DFA.h @@ -4,6 +4,7 @@ #pragma once #include +#include class DFA_State; @@ -66,7 +67,7 @@ protected: static unsigned int transition_counter; // see Xtion() }; -using DigestStr = basic_string; +using DigestStr = std::basic_string; class DFA_State_Cache { public: diff --git a/src/Debug.h b/src/Debug.h index a036dd264e..42fd3bd42a 100644 --- a/src/Debug.h +++ b/src/Debug.h @@ -5,8 +5,6 @@ #include #include #include -using namespace std; - class Stmt; @@ -35,10 +33,10 @@ class DbgWatch; class DbgDisplay; class StmtHashFn; -typedef map BPIDMapType; -typedef multimap BPMapType; +typedef std::map BPIDMapType; +typedef std::multimap BPMapType; -extern string current_module; +extern std::string current_module; class TraceState { public: @@ -88,8 +86,8 @@ public: Location last_loc; // used by 'list'; the last location listed BPIDMapType breakpoints; // BPID -> Breakpoint - vector watches; - vector displays; + std::vector watches; + std::vector displays; BPMapType breakpoint_map; // maps Stmt -> Breakpoints on it protected: @@ -135,7 +133,7 @@ extern DebuggerState g_debugger_state; // Multiple results can be returned depending on the input, but always // at least 1. -vector parse_location_string(const string& s); +std::vector parse_location_string(const std::string& s); // ### TODO: Add a bunch of hook functions for various events // e.g. variable changed, breakpoint hit, etc. @@ -171,11 +169,11 @@ Val* dbg_eval_expr(const char* expr); int dbg_read_internal_state(); // Get line that looks like "In FnFoo(arg = val) at File:Line". -string get_context_description(const Stmt* stmt, const Frame* frame); +std::string get_context_description(const Stmt* stmt, const Frame* frame); extern Frame* g_dbg_locals; // variables created within debugger context -extern std::map g_dbgfilemaps; // filename => filemap +extern std::map g_dbgfilemaps; // filename => filemap // Perhaps add a code/priority argument to do selective output. int debug_msg(const char* fmt, ...) __attribute__ ((format (printf, 1, 2))); diff --git a/src/DebugCmds.h b/src/DebugCmds.h index 7eb0f025a7..470e4ae993 100644 --- a/src/DebugCmds.h +++ b/src/DebugCmds.h @@ -6,7 +6,6 @@ #include #include #include -using namespace std; #include "Queue.h" #include "DebugCmdConstants.h" @@ -23,7 +22,7 @@ public: int Cmd() const { return cmd; } int NumNames() const { return num_names; } - const vector& Names() const { return names; } + const std::vector& Names() const { return names; } bool ResumeExecution() const { return resume_execution; } const char* Helpstring() const { return helpstring; } bool Repeatable() const { return repeatable; } @@ -32,7 +31,7 @@ protected: DebugCmd cmd; int num_names; - vector names; + std::vector names; // Whether executing this should restart execution of the script. bool resume_execution; @@ -57,14 +56,14 @@ const DebugCmdInfo* get_debug_cmd_info(DebugCmd cmd); // on whether or not the prefix supplied matches a name (DebugCmdString) // of the corresponding DebugCmd. The size of the array should be at // least NUM_DEBUG_CMDS. The total number of matches is returned. -int find_all_matching_cmds(const string& prefix, const char* array_of_matches[]); +int find_all_matching_cmds(const std::string& prefix, const char* array_of_matches[]); // Implementation of debugging commands. // // These functions return <= 0 if failure, > 0 for success. // More particular return values are command-specific: see comments w/function. -typedef int DbgCmdFn(DebugCmd cmd, const vector& args); +typedef int DbgCmdFn(DebugCmd cmd, const std::vector& args); DbgCmdFn dbg_cmd_backtrace; DbgCmdFn dbg_cmd_frame; diff --git a/src/Desc.h b/src/Desc.h index fadf61eac7..ff59aba43c 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "BroString.h" @@ -56,13 +57,13 @@ public: void EnableUTF8(); void AddEscapeSequence(const char* s) { escape_sequences.insert(s); } void AddEscapeSequence(const char* s, size_t n) - { escape_sequences.insert(string(s, n)); } - void AddEscapeSequence(const string & s) + { escape_sequences.insert(std::string(s, n)); } + void AddEscapeSequence(const std::string & s) { escape_sequences.insert(s); } void RemoveEscapeSequence(const char* s) { escape_sequences.erase(s); } void RemoveEscapeSequence(const char* s, size_t n) - { escape_sequences.erase(string(s, n)); } - void RemoveEscapeSequence(const string & s) + { escape_sequences.erase(std::string(s, n)); } + void RemoveEscapeSequence(const std::string & s) { escape_sequences.erase(s); } void PushIndent(); @@ -76,7 +77,7 @@ public: void Add(const char* s, int do_indent=1); void AddN(const char* s, int len) { AddBytes(s, len); } - void Add(const string& s) { AddBytes(s.data(), s.size()); } + void Add(const std::string& s) { AddBytes(s.data(), s.size()); } void Add(int i); void Add(uint32_t u); void Add(int64_t i); @@ -119,7 +120,7 @@ public: // Bypasses the escaping enabled via SetEscape(). void AddRaw(const char* s, int len) { AddBytesRaw(s, len); } - void AddRaw(const string &s) { AddBytesRaw(s.data(), s.size()); } + void AddRaw(const std::string &s) { AddBytesRaw(s.data(), s.size()); } // Returns the description as a string. const char* Description() const { return (const char*) base; } @@ -167,7 +168,7 @@ protected: * second element. The first element may be 0 if nothing is * to be escaped. */ - pair FirstEscapeLoc(const char* bytes, size_t n); + std::pair FirstEscapeLoc(const char* bytes, size_t n); /** * @param start start of string to check for starting with an espace @@ -187,7 +188,7 @@ protected: bool utf8; // whether valid utf-8 sequences may pass through unescaped bool escape; // escape unprintable characters in output? - typedef set escape_set; + typedef std::set escape_set; escape_set escape_sequences; // additional sequences of chars to escape BroFile* f; // or the file we're using. diff --git a/src/ID.h b/src/ID.h index 4ebcc9769d..b3e36ebd4f 100644 --- a/src/ID.h +++ b/src/ID.h @@ -27,7 +27,7 @@ public: bool IsExport() const { return is_export; } void SetExport() { is_export = true; } - string ModuleName() const; + std::string ModuleName() const; void SetType(BroType* t) { Unref(type); type = t; } BroType* Type() { return type; } @@ -83,7 +83,7 @@ public: void MakeDeprecated(Expr* deprecation); - string GetDeprecationWarning() const; + std::string GetDeprecationWarning() const; void Error(const char* msg, const BroObj* o2 = 0); @@ -106,7 +106,7 @@ public: // Takes ownership of callback. void AddOptionHandler(Func* callback, int priority); - vector GetOptionHandlers() const; + std::vector GetOptionHandlers() const; protected: ID() { name = 0; type = 0; val = 0; attrs = 0; } diff --git a/src/PacketDumper.h b/src/PacketDumper.h index e45adeb41f..78469b3d7c 100644 --- a/src/PacketDumper.h +++ b/src/PacketDumper.h @@ -2,8 +2,6 @@ #pragma once -using namespace std; - #include #include @@ -35,5 +33,5 @@ struct ltipid { } }; -typedef set IP_IDSet; +typedef std::set IP_IDSet; uint16_t NextIP_ID(const uint32_t src_addr, const uint16_t id); diff --git a/src/RE.h b/src/RE.h index 17fa36c0cf..ace38f2767 100644 --- a/src/RE.h +++ b/src/RE.h @@ -10,6 +10,7 @@ #include #include +#include #include typedef int (*cce_func)(int); @@ -60,7 +61,7 @@ public: // functionality. std::string LookupDef(const std::string& def); - void InsertCCL(const char* txt, CCL* ccl) { ccl_dict[string(txt)] = ccl; } + void InsertCCL(const char* txt, CCL* ccl) { ccl_dict[std::string(txt)] = ccl; } int InsertCCL(CCL* ccl) { ccl_list.push_back(ccl); @@ -68,7 +69,7 @@ public: } CCL* LookupCCL(const char* txt) { - const auto& iter = ccl_dict.find(string(txt)); + const auto& iter = ccl_dict.find(std::string(txt)); if ( iter != ccl_dict.end() ) return iter->second; @@ -125,8 +126,8 @@ protected: int multiline; char* pattern_text; - std::map defs; - std::map ccl_dict; + std::map defs; + std::map ccl_dict; PList ccl_list; EquivClass equiv_class; int* ecs; diff --git a/src/Rule.h b/src/Rule.h index bc478f18f3..663174f28f 100644 --- a/src/Rule.h +++ b/src/Rule.h @@ -15,7 +15,7 @@ class RuleHdrTest; class Rule; typedef PList rule_list; -typedef std::map rule_dict; +typedef std::map rule_dict; class Rule { public: diff --git a/src/Scope.h b/src/Scope.h index 2c25863e23..9b046fafa1 100644 --- a/src/Scope.h +++ b/src/Scope.h @@ -47,7 +47,7 @@ public: BroType* ReturnType() const { return return_type; } size_t Length() const { return local.size(); } - std::map& Vars() { return local; } + std::map& Vars() { return local; } ID* GenerateTemporary(const char* name); @@ -66,7 +66,7 @@ protected: ID* scope_id; attr_list* attrs; BroType* return_type; - std::map local; + std::map local; id_list* inits; }; @@ -90,4 +90,4 @@ extern Scope* current_scope(); extern Scope* global_scope(); // Current module (identified by its name). -extern string current_module; +extern std::string current_module; diff --git a/src/SerializationFormat.h b/src/SerializationFormat.h index 03bf758c31..772837ed91 100644 --- a/src/SerializationFormat.h +++ b/src/SerializationFormat.h @@ -4,8 +4,6 @@ #include -using namespace std; - #include "util.h" class IPAddr; @@ -29,7 +27,7 @@ public: virtual bool Read(char* v, const char* tag) = 0; virtual bool Read(bool* v, const char* tag) = 0; virtual bool Read(double* d, const char* tag) = 0; - virtual bool Read(string* s, const char* tag) = 0; + virtual bool Read(std::string* s, const char* tag) = 0; virtual bool Read(IPAddr* addr, const char* tag) = 0; virtual bool Read(IPPrefix* prefix, const char* tag) = 0; virtual bool Read(struct in_addr* addr, const char* tag) = 0; @@ -63,7 +61,7 @@ public: virtual bool Write(double d, const char* tag) = 0; virtual bool Write(const char* s, const char* tag) = 0; virtual bool Write(const char* buf, int len, const char* tag) = 0; - virtual bool Write(const string& s, const char* tag) = 0; + virtual bool Write(const std::string& s, const char* tag) = 0; virtual bool Write(const IPAddr& addr, const char* tag) = 0; virtual bool Write(const IPPrefix& prefix, const char* tag) = 0; virtual bool Write(const struct in_addr& addr, const char* tag) = 0; @@ -108,7 +106,7 @@ public: bool Read(bool* v, const char* tag) override; bool Read(double* d, const char* tag) override; bool Read(char** str, int* len, const char* tag) override; - bool Read(string* s, const char* tag) override; + bool Read(std::string* s, const char* tag) override; bool Read(IPAddr* addr, const char* tag) override; bool Read(IPPrefix* prefix, const char* tag) override; bool Read(struct in_addr* addr, const char* tag) override; @@ -123,7 +121,7 @@ public: bool Write(double d, const char* tag) override; bool Write(const char* s, const char* tag) override; bool Write(const char* buf, int len, const char* tag) override; - bool Write(const string& s, const char* tag) override; + bool Write(const std::string& s, const char* tag) override; bool Write(const IPAddr& addr, const char* tag) override; bool Write(const IPPrefix& prefix, const char* tag) override; bool Write(const struct in_addr& addr, const char* tag) override; diff --git a/src/SmithWaterman.h b/src/SmithWaterman.h index 541f777b89..3d29eb15a3 100644 --- a/src/SmithWaterman.h +++ b/src/SmithWaterman.h @@ -4,7 +4,6 @@ #include "BroString.h" #include -using namespace std; // BroSubstrings are essentially BroStrings, augmented with indexing // information required for the Smith-Waterman algorithm. Each substring @@ -15,7 +14,7 @@ using namespace std; class BroSubstring : public BroString { public: - typedef vector Vec; + typedef std::vector Vec; typedef Vec::iterator VecIt; typedef Vec::const_iterator VecCIt; @@ -36,11 +35,11 @@ public: int index; }; - typedef vector BSSAlignVec; + typedef std::vector BSSAlignVec; typedef BSSAlignVec::iterator BSSAlignVecIt; typedef BSSAlignVec::const_iterator BSSAlignVecCIt; - explicit BroSubstring(const string& string) + explicit BroSubstring(const std::string& string) : BroString(string), _num(), _new(false) { } explicit BroSubstring(const BroString& string) @@ -76,7 +75,7 @@ public: unsigned int index); private: - typedef map DataMap; + typedef std::map DataMap; typedef DataMap::iterator DataMapIt; BroSubstring(); diff --git a/src/Type.h b/src/Type.h index 04c2bfac47..a4261e453a 100644 --- a/src/Type.h +++ b/src/Type.h @@ -262,8 +262,8 @@ public: virtual unsigned MemoryAllocation() const; - void SetName(const string& arg_name) { name = arg_name; } - const string& GetName() const { return name; } + void SetName(const std::string& arg_name) { name = arg_name; } + const std::string& GetName() const { return name; } typedef std::map > TypeAliasMap; @@ -283,7 +283,7 @@ private: InternalTypeTag internal_tag; bool is_network_order; bool base_type; - string name; + std::string name; static TypeAliasMap type_aliases; }; @@ -402,7 +402,7 @@ public: const BroType* YieldType() const override; void SetYieldType(BroType* arg_yield) { yield = arg_yield; } function_flavor Flavor() const { return flavor; } - string FlavorString() const; + std::string FlavorString() const; // Used to convert a function type to an event or hook type. void ClearYieldType(function_flavor arg_flav) @@ -504,7 +504,7 @@ public: return decl && decl->FindAttr(at) != 0; } - string GetFieldDeprecationWarning(int field, bool has_check) const; + std::string GetFieldDeprecationWarning(int field, bool has_check) const; protected: RecordType() { types = 0; } @@ -537,11 +537,11 @@ protected: class OpaqueType : public BroType { public: - explicit OpaqueType(const string& name); + explicit OpaqueType(const std::string& name); OpaqueType* ShallowClone() override { return new OpaqueType(name); } ~OpaqueType() override { }; - const string& Name() const { return name; } + const std::string& Name() const { return name; } void Describe(ODesc* d) const override; void DescribeReST(ODesc* d, bool roles_only = false) const override; @@ -549,29 +549,29 @@ public: protected: OpaqueType() { } - string name; + std::string name; }; class EnumType : public BroType { public: - typedef std::list > enum_name_list; + typedef std::list > enum_name_list; explicit EnumType(const EnumType* e); - explicit EnumType(const string& arg_name); + explicit EnumType(const std::string& arg_name); EnumType* ShallowClone() override; ~EnumType() override; // The value of this name is next internal counter value, starting // with zero. The internal counter is incremented. - void AddName(const string& module_name, const char* name, bool is_export, Expr* deprecation = nullptr); + void AddName(const std::string& module_name, const char* name, bool is_export, Expr* deprecation = nullptr); // The value of this name is set to val. Once a value has been // explicitly assigned using this method, no further names can be // added that aren't likewise explicitly initalized. - void AddName(const string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr); + void AddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr); // -1 indicates not found. - bro_int_t Lookup(const string& module_name, const char* name) const; + bro_int_t Lookup(const std::string& module_name, const char* name) const; const char* Lookup(bro_int_t value) const; // Returns 0 if not found // Returns the list of defined names with their values. The names @@ -585,10 +585,10 @@ public: protected: EnumType() { counter = 0; } - void AddNameInternal(const string& module_name, + void AddNameInternal(const std::string& module_name, const char* name, bro_int_t val, bool is_export); - void CheckAndAddName(const string& module_name, + void CheckAndAddName(const std::string& module_name, const char* name, bro_int_t val, bool is_export, Expr* deprecation = nullptr); diff --git a/src/input.h b/src/input.h index be898d154b..327423ed9c 100644 --- a/src/input.h +++ b/src/input.h @@ -4,7 +4,6 @@ #include #include -using namespace std; #include "BroList.h" @@ -40,7 +39,7 @@ extern const char* prog; extern name_list prefixes; // -p flag extern char* command_line_policy; // -e flag -extern vector params; +extern std::vector params; class Stmt; extern Stmt* stmts; // global statements diff --git a/src/module_util.cc b/src/module_util.cc index d5817a7d7a..500d7f4d08 100644 --- a/src/module_util.cc +++ b/src/module_util.cc @@ -5,6 +5,8 @@ #include #include "module_util.h" +using namespace std; + static int streq(const char* s1, const char* s2) { return ! strcmp(s1, s2); diff --git a/src/module_util.h b/src/module_util.h index 4e865380d2..5e1597a987 100644 --- a/src/module_util.h +++ b/src/module_util.h @@ -6,14 +6,12 @@ #include -using namespace std; - static const char* GLOBAL_MODULE_NAME = "GLOBAL"; -extern string extract_module_name(const char* name); -extern string extract_var_name(const char* name); -extern string normalized_module_name(const char* module_name); // w/o :: +extern std::string extract_module_name(const char* name); +extern std::string extract_var_name(const char* name); +extern std::string normalized_module_name(const char* module_name); // w/o :: // Concatenates module_name::var_name unless var_name is already fully // qualified, in which case it is returned unmodified. -extern string make_full_var_name(const char* module_name, const char* var_name); +extern std::string make_full_var_name(const char* module_name, const char* var_name); diff --git a/src/probabilistic/BloomFilter.h b/src/probabilistic/BloomFilter.h index 629605c6b6..950235e5f5 100644 --- a/src/probabilistic/BloomFilter.h +++ b/src/probabilistic/BloomFilter.h @@ -3,6 +3,7 @@ #pragma once #include +#include #include #include @@ -75,7 +76,7 @@ public: * Returns a string with a representation of the Bloom filter's * internal state. This is for debugging/testing purposes only. */ - virtual string InternalState() const = 0; + virtual std::string InternalState() const = 0; broker::expected Serialize() const; static std::unique_ptr Unserialize(const broker::data& data); @@ -154,7 +155,7 @@ public: void Clear() override; bool Merge(const BloomFilter* other) override; BasicBloomFilter* Clone() const override; - string InternalState() const override; + std::string InternalState() const override; protected: friend class BloomFilter; @@ -203,7 +204,7 @@ public: void Clear() override; bool Merge(const BloomFilter* other) override; CountingBloomFilter* Clone() const override; - string InternalState() const override; + std::string InternalState() const override; protected: friend class BloomFilter;