From fd5e15b1161f3d3858abb421648e3b75173c3dde Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Wed, 11 Mar 2020 10:41:46 -0700 Subject: [PATCH] The Great Embooleanating A large number of functions had return values and/or arguments changed to use ``bool`` types instead of ``int``. --- NEWS | 6 + src/Anon.cc | 14 +- src/Anon.h | 8 +- src/Attr.cc | 5 +- src/Base64.cc | 6 +- src/Base64.h | 2 +- src/BroString.cc | 4 +- src/CCL.h | 2 +- src/CompHash.cc | 28 +-- src/CompHash.h | 14 +- src/Conn.cc | 4 +- src/Conn.h | 32 +-- src/DNS_Mgr.cc | 46 ++-- src/DNS_Mgr.h | 6 +- src/DbgBreakpoint.cc | 4 +- src/Debug.cc | 4 +- src/DebugCmds.cc | 2 +- src/Desc.cc | 8 +- src/Desc.h | 30 +-- src/Dict.cc | 12 +- src/Dict.h | 6 +- src/Discard.cc | 18 +- src/Discard.h | 10 +- src/EquivClass.h | 2 +- src/Event.cc | 6 +- src/Event.h | 2 +- src/Expr.cc | 66 ++--- src/Expr.h | 20 +- src/File.cc | 29 +-- src/File.h | 10 +- src/Frag.cc | 2 +- src/Frag.h | 2 +- src/Func.cc | 6 +- src/Func.h | 10 +- src/Hash.cc | 17 +- src/Hash.h | 4 +- src/ID.cc | 4 +- src/IP.cc | 6 +- src/List.h | 1 + src/Obj.cc | 8 +- src/Obj.h | 8 +- src/OpaqueVal.cc | 6 +- src/PrefixTable.cc | 4 +- src/RE.cc | 24 +- src/RE.h | 16 +- src/Reassem.h | 2 +- src/Reporter.cc | 4 +- src/RuleCondition.cc | 1 - src/RuleMatcher.cc | 16 +- src/Sessions.cc | 10 +- src/Sessions.h | 2 +- src/Stats.cc | 4 +- src/Stmt.cc | 60 ++--- src/Stmt.h | 28 +-- src/Timer.cc | 4 +- src/Timer.h | 2 +- src/Trigger.cc | 2 +- src/Type.cc | 92 +++---- src/Type.h | 20 +- src/Val.cc | 134 +++++------ src/Val.h | 46 ++-- src/Var.cc | 14 +- src/Var.h | 2 +- src/WeirdState.h | 2 +- src/analyzer/Analyzer.cc | 10 +- src/analyzer/Analyzer.h | 2 +- src/analyzer/protocol/conn-size/functions.bif | 20 +- .../protocol/dce-rpc/dce_rpc-protocol.pac | 8 +- src/analyzer/protocol/dnp3/DNP3.cc | 9 +- src/analyzer/protocol/dns/DNS.cc | 226 +++++++++--------- src/analyzer/protocol/dns/DNS.h | 60 +++-- src/analyzer/protocol/finger/Finger.cc | 2 +- src/analyzer/protocol/ftp/FTP.cc | 2 +- src/analyzer/protocol/ftp/functions.bif | 3 +- src/analyzer/protocol/gnutella/Gnutella.cc | 25 +- src/analyzer/protocol/gnutella/Gnutella.h | 10 +- .../protocol/gtpv1/gtpv1-analyzer.pac | 21 +- src/analyzer/protocol/http/HTTP.cc | 113 +++++---- src/analyzer/protocol/http/HTTP.h | 46 ++-- src/analyzer/protocol/icmp/ICMP.cc | 19 +- src/analyzer/protocol/icmp/ICMP.h | 4 +- src/analyzer/protocol/ident/Ident.cc | 2 +- src/analyzer/protocol/login/Login.cc | 44 ++-- src/analyzer/protocol/login/Login.h | 26 +- src/analyzer/protocol/login/NVT.cc | 46 ++-- src/analyzer/protocol/login/NVT.h | 35 +-- src/analyzer/protocol/login/functions.bif | 10 +- src/analyzer/protocol/mime/MIME.cc | 66 ++--- src/analyzer/protocol/mime/MIME.h | 36 +-- src/analyzer/protocol/ncp/NCP.cc | 3 +- src/analyzer/protocol/ncp/NCP.h | 5 +- src/analyzer/protocol/netbios/NetbiosSSN.cc | 114 ++++----- src/analyzer/protocol/netbios/NetbiosSSN.h | 28 +-- src/analyzer/protocol/pop3/POP3.cc | 4 +- src/analyzer/protocol/rpc/MOUNT.cc | 22 +- src/analyzer/protocol/rpc/MOUNT.h | 4 +- src/analyzer/protocol/rpc/NFS.cc | 22 +- src/analyzer/protocol/rpc/NFS.h | 6 +- src/analyzer/protocol/rpc/Portmap.cc | 34 +-- src/analyzer/protocol/rpc/Portmap.h | 6 +- src/analyzer/protocol/rpc/RPC.cc | 20 +- src/analyzer/protocol/rpc/RPC.h | 10 +- .../protocol/smb/smb1-com-locking-andx.pac | 2 +- .../protocol/smb/smb1-com-logoff-andx.pac | 2 +- .../protocol/smb/smb1-com-nt-create-andx.pac | 4 +- .../protocol/smb/smb1-com-read-andx.pac | 4 +- .../smb/smb1-com-session-setup-andx.pac | 11 +- .../smb/smb1-com-tree-connect-andx.pac | 9 +- .../protocol/smb/smb1-com-write-andx.pac | 4 +- src/analyzer/protocol/smtp/SMTP.cc | 70 +++--- src/analyzer/protocol/smtp/SMTP.h | 22 +- src/analyzer/protocol/ssl/ssl-analyzer.pac | 2 +- .../protocol/ssl/tls-handshake-analyzer.pac | 4 +- .../protocol/stepping-stone/SteppingStone.cc | 12 +- .../protocol/stepping-stone/SteppingStone.h | 9 +- src/analyzer/protocol/syslog/Syslog.cc | 4 +- src/analyzer/protocol/tcp/ContentLine.cc | 2 +- src/analyzer/protocol/tcp/TCP.cc | 106 ++++---- src/analyzer/protocol/tcp/TCP.h | 52 ++-- src/analyzer/protocol/tcp/TCP_Endpoint.cc | 22 +- src/analyzer/protocol/tcp/TCP_Endpoint.h | 30 +-- src/analyzer/protocol/tcp/TCP_Reassembler.cc | 24 +- src/analyzer/protocol/tcp/TCP_Reassembler.h | 10 +- src/analyzer/protocol/teredo/Teredo.cc | 4 +- src/analyzer/protocol/udp/UDP.cc | 8 +- src/analyzer/protocol/udp/UDP.h | 4 +- src/file_analysis/AnalyzerSet.cc | 2 +- src/file_analysis/File.cc | 4 +- src/file_analysis/FileTimer.cc | 2 +- src/file_analysis/FileTimer.h | 2 +- .../analyzer/data_event/DataEvent.cc | 4 +- src/file_analysis/analyzer/x509/X509.cc | 6 +- src/file_analysis/analyzer/x509/functions.bif | 6 +- src/input/Manager.cc | 32 +-- src/iosource/Packet.cc | 4 +- src/iosource/Packet.h | 4 +- src/logging/Manager.cc | 10 +- src/probabilistic/Topk.cc | 2 +- src/probabilistic/cardinality-counter.bif | 12 +- src/supervisor/Supervisor.cc | 2 +- src/supervisor/Supervisor.h | 2 +- src/threading/Manager.cc | 2 +- src/threading/Manager.h | 2 +- src/zeek.bif | 2 +- src/zeekygen/ScriptInfo.cc | 6 +- 145 files changed, 1288 insertions(+), 1331 deletions(-) diff --git a/NEWS b/NEWS index 682dd8d97a..10f3936eda 100644 --- a/NEWS +++ b/NEWS @@ -39,6 +39,12 @@ Changed Functionality detected and used at configuration-time. Use the ``--enable-rocksdb`` and ``--with-rocksdb=`` flags to opt-in. +- A large number of functions had return values and/or arguments changed + to use ``bool`` types instead of ``int``. This includes some virtual + methods, which may cause build failures in plugins that were overriding + those methods. Those plugins will need to be updated to match these API + changes. + Removed Functionality --------------------- diff --git a/src/Anon.cc b/src/Anon.cc index bfc8f57aa1..4c54510217 100644 --- a/src/Anon.cc +++ b/src/Anon.cc @@ -69,13 +69,13 @@ ipaddr32_t AnonymizeIPAddr::Anonymize(ipaddr32_t addr) } // Keep the specified prefix unchanged. -int AnonymizeIPAddr::PreservePrefix(ipaddr32_t /* input */, int /* num_bits */) +bool AnonymizeIPAddr::PreservePrefix(ipaddr32_t /* input */, int /* num_bits */) { reporter->InternalError("prefix preserving is not supported for the anonymizer"); - return 0; + return false; } -int AnonymizeIPAddr::PreserveNet(ipaddr32_t input) +bool AnonymizeIPAddr::PreserveNet(ipaddr32_t input) { switch ( addr_to_class(ntohl(input)) ) { case 'A': @@ -85,7 +85,7 @@ int AnonymizeIPAddr::PreserveNet(ipaddr32_t input) case 'C': return PreservePrefix(input, 24); default: - return 0; + return false; } } @@ -160,7 +160,7 @@ void AnonymizeIPAddr_A50::init() new_mapping = 0; } -int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits) +bool AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits) { DEBUG_MSG("%s/%d\n", IPAddr(IPv4, &input, IPAddr::Network).AsString().c_str(), @@ -169,7 +169,7 @@ int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits) if ( ! before_anonymization ) { reporter->Error("prefix perservation specified after anonymization begun"); - return 0; + return false; } input = ntohl(input); @@ -191,7 +191,7 @@ int AnonymizeIPAddr_A50::PreservePrefix(ipaddr32_t input, int num_bits) n->output = (input & prefix_mask) | (rand32() & suffix_mask); } - return 1; + return true; } ipaddr32_t AnonymizeIPAddr_A50::anonymize(ipaddr32_t a) diff --git a/src/Anon.h b/src/Anon.h index 8bd9861e2a..a3d7016cb7 100644 --- a/src/Anon.h +++ b/src/Anon.h @@ -44,11 +44,11 @@ public: ipaddr32_t Anonymize(ipaddr32_t addr); - virtual int PreservePrefix(ipaddr32_t input, int num_bits); + virtual bool PreservePrefix(ipaddr32_t input, int num_bits); virtual ipaddr32_t anonymize(ipaddr32_t addr) = 0; - - int PreserveNet(ipaddr32_t input); + + bool PreserveNet(ipaddr32_t input); protected: map mapping; @@ -85,7 +85,7 @@ public: ~AnonymizeIPAddr_A50() override; ipaddr32_t anonymize(ipaddr32_t addr) override; - int PreservePrefix(ipaddr32_t input, int num_bits) override; + bool PreservePrefix(ipaddr32_t input, int num_bits) override; protected: struct Node { diff --git a/src/Attr.cc b/src/Attr.cc index bbef7742ea..ea735b67f0 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -104,7 +104,7 @@ void Attr::DescribeReST(ODesc* d, bool shorten) const else if ( expr->Tag() == EXPR_CONST ) { ODesc dd; - dd.SetQuotes(1); + dd.SetQuotes(true); expr->Describe(&dd); string s = dd.Description(); add_long_expr_string(d, s, shorten); @@ -260,7 +260,7 @@ void Attributes::CheckAttr(Attr* a) case ATTR_ADD_FUNC: case ATTR_DEL_FUNC: { - int is_add = a->Tag() == ATTR_ADD_FUNC; + bool is_add = a->Tag() == ATTR_ADD_FUNC; BroType* at = a->AttrExpr()->Type(); if ( at->Tag() != TYPE_FUNC ) @@ -635,4 +635,3 @@ bool Attributes::operator==(const Attributes& other) const return true; } - diff --git a/src/Base64.cc b/src/Base64.cc index 95e140e6c1..51d2b707ad 100644 --- a/src/Base64.cc +++ b/src/Base64.cc @@ -138,7 +138,7 @@ int Base64Converter::Decode(int len, const char* data, int* pblen, char** pbuf) int dlen = 0; - while ( 1 ) + while ( true ) { if ( base64_group_next == 4 ) { @@ -255,7 +255,7 @@ BroString* decode_base64(const BroString* s, const BroString* a, Connection* con rlen += rlen2; rbuf[rlen] = '\0'; - return new BroString(1, (u_char*) rbuf, rlen); + return new BroString(true, (u_char*) rbuf, rlen); err: delete [] rbuf; @@ -276,5 +276,5 @@ BroString* encode_base64(const BroString* s, const BroString* a, Connection* con Base64Converter enc(conn, a ? a->CheckString() : ""); enc.Encode(s->Len(), (const unsigned char*) s->Bytes(), &outlen, &outbuf); - return new BroString(1, (u_char*)outbuf, outlen); + return new BroString(true, (u_char*)outbuf, outlen); } diff --git a/src/Base64.h b/src/Base64.h index eaa6921c48..cdebc93017 100644 --- a/src/Base64.h +++ b/src/Base64.h @@ -32,7 +32,7 @@ public: void Encode(int len, const unsigned char* data, int* blen, char** buf); int Done(int* pblen, char** pbuf); - int HasData() const { return base64_group_next != 0; } + bool HasData() const { return base64_group_next != 0; } // True if an error has occurred. int Errored() const { return errored; } diff --git a/src/BroString.cc b/src/BroString.cc index ddd1b8093f..33a14a315b 100644 --- a/src/BroString.cc +++ b/src/BroString.cc @@ -107,7 +107,7 @@ void BroString::Adopt(byte_vec bytes, int len) // Check if the string ends with a NUL. If so, mark it as having // a final NUL and adjust the length accordingly. - final_NUL = (b[len-1] == '\0') ? 1 : 0; + final_NUL = (b[len-1] == '\0'); n = len - final_NUL; } @@ -289,7 +289,7 @@ BroString* BroString::GetSubstring(int start, int len) const if ( len < 0 || len > n - start ) len = n - start; - return new BroString(&b[start], len, 1); + return new BroString(&b[start], len, true); } int BroString::FindSubstring(const BroString* s) const diff --git a/src/CCL.h b/src/CCL.h index 58c04688d9..b92c69c801 100644 --- a/src/CCL.h +++ b/src/CCL.h @@ -15,7 +15,7 @@ public: void Add(int sym); void Negate(); - int IsNegated() { return negated; } + bool IsNegated() { return negated != 0; } int Index() { return index; } void Sort(); diff --git a/src/CompHash.cc b/src/CompHash.cc index 935d0ade93..eaaa45a7f3 100644 --- a/src/CompHash.cc +++ b/src/CompHash.cc @@ -25,20 +25,20 @@ CompositeHash::CompositeHash(IntrusivePtr composite_type) { if ( (*type->Types())[0]->Tag() == TYPE_RECORD ) { - is_complex_type = 1; - is_singleton = 0; + is_complex_type = true; + is_singleton = false; } else { - is_complex_type = 0; - is_singleton = 1; + is_complex_type = false; + is_singleton = true; } } else { - is_singleton = 0; - is_complex_type = 0; + is_singleton = false; + is_complex_type = false; } if ( is_singleton ) @@ -52,7 +52,7 @@ CompositeHash::CompositeHash(IntrusivePtr composite_type) else { - size = ComputeKeySize(0, 1, true); + size = ComputeKeySize(0, true, true); if ( size > 0 ) // Fixed size. Make sure what we get is fully aligned. @@ -69,7 +69,7 @@ CompositeHash::~CompositeHash() } // Computes the piece of the hash for Val*, returning the new kp. -char* CompositeHash::SingleValHash(int type_check, char* kp0, +char* CompositeHash::SingleValHash(bool type_check, char* kp0, BroType* bt, Val* v, bool optional) const { char* kp1 = 0; @@ -333,7 +333,7 @@ char* CompositeHash::SingleValHash(int type_check, char* kp0, } -HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const +HashKey* CompositeHash::ComputeHash(const Val* v, bool type_check) const { if ( ! v ) reporter->InternalError("null value given to CompositeHash::ComputeHash"); @@ -364,7 +364,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const return 0; k = reinterpret_cast(new double[sz/sizeof(double) + 1]); - type_check = 0; // no need to type-check again. + type_check = false; // no need to type-check again. } const type_list* tl = type->Types(); @@ -387,7 +387,7 @@ HashKey* CompositeHash::ComputeHash(const Val* v, int type_check) const return new HashKey((k == key), (void*) k, kp - k); } -HashKey* CompositeHash::ComputeSingletonHash(const Val* v, int type_check) const +HashKey* CompositeHash::ComputeSingletonHash(const Val* v, bool type_check) const { if ( v->Type()->Tag() == TYPE_LIST ) { @@ -449,7 +449,7 @@ HashKey* CompositeHash::ComputeSingletonHash(const Val* v, int type_check) const } int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, - int type_check, int sz, bool optional, + bool type_check, int sz, bool optional, bool calc_static_size) const { InternalTypeTag t = bt->InternalType(); @@ -629,7 +629,7 @@ int CompositeHash::SingleTypeKeySize(BroType* bt, const Val* v, return sz; } -int CompositeHash::ComputeKeySize(const Val* v, int type_check, bool calc_static_size) const +int CompositeHash::ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const { const type_list* tl = type->Types(); const val_list* vl = 0; @@ -1044,7 +1044,7 @@ const char* CompositeHash::RecoverOneVal(const HashKey* k, const char* kp0, kp1 = reinterpret_cast(kp+1); } - *pval = make_intrusive(new BroString((const byte_vec) kp1, n, 1)); + *pval = make_intrusive(new BroString((const byte_vec) kp1, n, true)); kp1 += n; } break; diff --git a/src/CompHash.h b/src/CompHash.h index c604576bd3..849245b9db 100644 --- a/src/CompHash.h +++ b/src/CompHash.h @@ -15,7 +15,7 @@ public: // Compute the hash corresponding to the given index val, // or 0 if it fails to typecheck. - HashKey* ComputeHash(const Val* v, int type_check) const; + HashKey* ComputeHash(const Val* v, bool type_check) const; // Given a hash key, recover the values used to create it. IntrusivePtr RecoverVals(const HashKey* k) const; @@ -23,11 +23,11 @@ public: unsigned int MemoryAllocation() const { return padded_sizeof(*this) + pad_size(size); } protected: - HashKey* ComputeSingletonHash(const Val* v, int type_check) const; + HashKey* ComputeSingletonHash(const Val* v, bool type_check) const; // Computes the piece of the hash for Val*, returning the new kp. // Used as a helper for ComputeHash in the non-singleton case. - char* SingleValHash(int type_check, char* kp, BroType* bt, Val* v, + char* SingleValHash(bool type_check, char* kp, BroType* bt, Val* v, bool optional) const; // Recovers just one Val of possibly many; called from RecoverVals. @@ -72,20 +72,20 @@ protected: // the value is computed for the particular list of values. // Returns 0 if the key has an indeterminant size (if v not given), // or if v doesn't match the index type (if given). - int ComputeKeySize(const Val* v, int type_check, + int ComputeKeySize(const Val* v, bool type_check, bool calc_static_size) const; int SingleTypeKeySize(BroType*, const Val*, - int type_check, int sz, bool optional, + bool type_check, int sz, bool optional, bool calc_static_size) const; IntrusivePtr type; char* key; // space for composite key int size; - int is_singleton; // if just one type in index + bool is_singleton; // if just one type in index // If one type, but not normal "singleton", e.g. record. - int is_complex_type; + bool is_complex_type; InternalTypeTag singleton_tag; }; diff --git a/src/Conn.cc b/src/Conn.cc index b7c80118be..bc37dea87a 100644 --- a/src/Conn.cc +++ b/src/Conn.cc @@ -39,7 +39,7 @@ ConnectionTimer::~ConnectionTimer() Unref(conn); } -void ConnectionTimer::Dispatch(double t, int is_expire) +void ConnectionTimer::Dispatch(double t, bool is_expire) { if ( is_expire && ! do_expire ) return; @@ -177,7 +177,7 @@ void Connection::Done() root_analyzer->Done(); } -void Connection::NextPacket(double t, int is_orig, +void Connection::NextPacket(double t, bool is_orig, const IP_Hdr* ip, int len, int caplen, const u_char*& data, int& record_packet, int& record_content, diff --git a/src/Conn.h b/src/Conn.h index 547f5c0bfd..a2bb1face5 100644 --- a/src/Conn.h +++ b/src/Conn.h @@ -87,7 +87,7 @@ public: // If record_content is true, then its entire contents should // be recorded, otherwise just up through the transport header. // Both are assumed set to true when called. - void NextPacket(double t, int is_orig, + void NextPacket(double t, bool is_orig, const IP_Hdr* ip, int len, int caplen, const u_char*& data, int& record_packet, int& record_content, @@ -126,27 +126,27 @@ public: // True if we should record subsequent packets (either headers or // in their entirety, depending on record_contents). We still // record subsequent SYN/FIN/RST, regardless of how this is set. - int RecordPackets() const { return record_packets; } - void SetRecordPackets(int do_record) { record_packets = do_record; } + bool RecordPackets() const { return record_packets; } + void SetRecordPackets(bool do_record) { record_packets = do_record ? 1 : 0; } // True if we should record full packets for this connection, // false if we should just record headers. - int RecordContents() const { return record_contents; } - void SetRecordContents(int do_record) { record_contents = do_record; } + bool RecordContents() const { return record_contents; } + void SetRecordContents(bool do_record) { record_contents = do_record ? 1 : 0; } // Set whether to record *current* packet header/full. - void SetRecordCurrentPacket(int do_record) - { record_current_packet = do_record; } - void SetRecordCurrentContent(int do_record) - { record_current_content = do_record; } + void SetRecordCurrentPacket(bool do_record) + { record_current_packet = do_record ? 1 : 0; } + void SetRecordCurrentContent(bool do_record) + { record_current_content = do_record ? 1 : 0; } // FIXME: Now this is in Analyzer and should eventually be removed here. // // If true, skip processing of remainder of connection. Note // that this does not in itself imply that record_packets is false; // we might want instead to process the connection off-line. - void SetSkip(int do_skip) { skip = do_skip; } - int Skipping() const { return skip; } + void SetSkip(bool do_skip) { skip = do_skip ? 1 : 0; } + bool Skipping() const { return skip; } // Arrange for the connection to expire after the given amount of time. void SetLifetime(double lifetime); @@ -237,16 +237,16 @@ public: // Cancel all associated timers. void CancelTimers(); - inline int FlagEvent(ConnEventToFlag e) + inline bool FlagEvent(ConnEventToFlag e) { if ( e >= 0 && e < NUM_EVENTS_TO_FLAG ) { if ( suppress_event & (1 << e) ) - return 0; + return false; suppress_event |= 1 << e; } - return 1; + return true; } void Describe(ODesc* d) const override; @@ -264,7 +264,7 @@ public: { return current_connections; } // Returns true if the history was already seen, false otherwise. - int CheckHistory(uint32_t mask, char code) + bool CheckHistory(uint32_t mask, char code) { if ( (hist_seen & mask) == 0 ) { @@ -387,7 +387,7 @@ public: { Init(arg_conn, arg_timer, arg_do_expire); } ~ConnectionTimer() override; - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; protected: ConnectionTimer() {} diff --git a/src/DNS_Mgr.cc b/src/DNS_Mgr.cc index 43e0d8962a..e0bc8ffe90 100644 --- a/src/DNS_Mgr.cc +++ b/src/DNS_Mgr.cc @@ -107,8 +107,8 @@ public: DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl); DNS_Mapping(FILE* f); - int NoMapping() const { return no_mapping; } - int InitFailed() const { return init_failed; } + bool NoMapping() const { return no_mapping; } + bool InitFailed() const { return init_failed; } ~DNS_Mapping(); @@ -128,8 +128,8 @@ public: void Save(FILE* f) const; - int Failed() const { return failed; } - int Valid() const { return ! failed; } + bool Failed() const { return failed; } + bool Valid() const { return ! failed; } bool Expired() const { @@ -147,9 +147,6 @@ protected: void Init(struct hostent* h); void Clear(); - int no_mapping; // when initializing from a file, immediately hit EOF - int init_failed; - char* req_host; IPAddr req_addr; uint32_t req_ttl; @@ -162,9 +159,11 @@ protected: IPAddr* addrs; IntrusivePtr addrs_val; - int failed; double creation_time; int map_type; + bool no_mapping; // when initializing from a file, immediately hit EOF + bool init_failed; + bool failed; }; void DNS_Mgr_mapping_delete_func(void* v) @@ -202,7 +201,7 @@ DNS_Mapping::DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32_t ttl) DNS_Mapping::DNS_Mapping(FILE* f) { Clear(); - init_failed = 1; + init_failed = true; req_host = 0; req_ttl = 0; @@ -212,18 +211,21 @@ DNS_Mapping::DNS_Mapping(FILE* f) if ( ! fgets(buf, sizeof(buf), f) ) { - no_mapping = 1; + no_mapping = true; return; } char req_buf[512+1], name_buf[512+1]; int is_req_host; + int failed_local; if ( sscanf(buf, "%lf %d %512s %d %512s %d %d %" PRIu32, &creation_time, - &is_req_host, req_buf, &failed, name_buf, &map_type, &num_addrs, + &is_req_host, req_buf, &failed_local, name_buf, &map_type, &num_addrs, &req_ttl) != 8 ) return; + failed = static_cast(failed_local); + if ( is_req_host ) req_host = copy_string(req_buf); else @@ -255,7 +257,7 @@ DNS_Mapping::DNS_Mapping(FILE* f) else addrs = 0; - init_failed = 0; + init_failed = false; } DNS_Mapping::~DNS_Mapping() @@ -310,8 +312,8 @@ IntrusivePtr DNS_Mapping::Host() void DNS_Mapping::Init(struct hostent* h) { - no_mapping = 0; - init_failed = 0; + no_mapping = false; + init_failed = false; creation_time = current_time(); host_val = 0; addrs_val = 0; @@ -344,7 +346,7 @@ void DNS_Mapping::Init(struct hostent* h) else addrs = 0; - failed = 0; + failed = false; } void DNS_Mapping::Clear() @@ -354,9 +356,9 @@ void DNS_Mapping::Clear() addrs = 0; host_val = 0; addrs_val = 0; - no_mapping = 0; + no_mapping = false; map_type = 0; - failed = 1; + failed = true; } void DNS_Mapping::Save(FILE* f) const @@ -373,7 +375,7 @@ void DNS_Mapping::Save(FILE* f) const DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode) { - did_init = 0; + did_init = false; mode = arg_mode; @@ -680,15 +682,15 @@ void DNS_Mgr::Resolve() delete requests.remove_nth(i); } -int DNS_Mgr::Save() +bool DNS_Mgr::Save() { if ( ! cache_name ) - return 0; + return false; FILE* f = fopen(cache_name, "w"); if ( ! f ) - return 0; + return false; Save(f, host_mappings); Save(f, addr_mappings); @@ -696,7 +698,7 @@ int DNS_Mgr::Save() fclose(f); - return 1; + return true; } void DNS_Mgr::Event(EventHandlerPtr e, DNS_Mapping* dm) diff --git a/src/DNS_Mgr.h b/src/DNS_Mgr.h index 248949b51b..8155375e2d 100644 --- a/src/DNS_Mgr.h +++ b/src/DNS_Mgr.h @@ -57,7 +57,7 @@ public: void Verify(); void Resolve(); - int Save(); + bool Save(); const char* LookupAddrInCache(const IPAddr& addr); IntrusivePtr LookupNameInCache(const string& name); @@ -147,7 +147,7 @@ protected: char* cache_name; char* dir; // directory in which cache_name resides - int did_init; + bool did_init; // DNS-related events. EventHandlerPtr dns_mapping_valid; @@ -171,7 +171,7 @@ protected: AsyncRequest() : time(0.0), is_txt(false), processed(false) { } - bool IsAddrReq() const { return name.length() == 0; } + bool IsAddrReq() const { return name.empty(); } void Resolved(const char* name) { diff --git a/src/DbgBreakpoint.cc b/src/DbgBreakpoint.cc index 11033c789c..7bd18ce05f 100644 --- a/src/DbgBreakpoint.cc +++ b/src/DbgBreakpoint.cc @@ -27,13 +27,13 @@ public: : Timer(arg_t, TIMER_BREAKPOINT) { bp = arg_bp; } - void Dispatch(double t, int is_expire); + void Dispatch(double t, bool is_expire) override; protected: DbgBreakpoint* bp; }; -void BreakpointTimer::Dispatch(double t, int is_expire) +void BreakpointTimer::Dispatch(double t, bool is_expire) { if ( is_expire ) return; diff --git a/src/Debug.cc b/src/Debug.cc index 39757277f6..7bc6e3f4bb 100644 --- a/src/Debug.cc +++ b/src/Debug.cc @@ -237,7 +237,7 @@ static void parse_function_name(vector& result, body = bodies[0].stmts.get(); else { - while ( 1 ) + while ( true ) { debug_msg("There are multiple definitions of that event handler.\n" "Please choose one of the following options:\n"); @@ -600,7 +600,7 @@ int dbg_execute_command(const char* cmd) { /* The prototype for add_history(), at least under MacOS, * has it taking a char* rather than a const char*. - * But documentation at + * But documentation at * http://tiswww.case.edu/php/chet/readline/history.html * suggests that it's safe to assume it's really const char*. */ diff --git a/src/DebugCmds.cc b/src/DebugCmds.cc index f59651d65e..b65d979f5e 100644 --- a/src/DebugCmds.cc +++ b/src/DebugCmds.cc @@ -77,7 +77,7 @@ void choose_global_symbols_regex(const string& regex, vector& choices, if ( choices.size() <= 1 ) return; - while ( 1 ) + while ( true ) { debug_msg("There were multiple matches, please choose:\n"); diff --git a/src/Desc.cc b/src/Desc.cc index 40ef4c6677..50d95f80c8 100644 --- a/src/Desc.cc +++ b/src/Desc.cc @@ -35,10 +35,10 @@ ODesc::ODesc(desc_type t, BroFile* arg_f) } indent_level = 0; - is_short = 0; - want_quotes = 0; - do_flush = 1; - include_stats = 0; + is_short = false; + want_quotes = false; + do_flush = true; + include_stats = false; indent_with_spaces = 0; escape = false; utf8 = false; diff --git a/src/Desc.h b/src/Desc.h index 99ccffea0f..2a29c75a92 100644 --- a/src/Desc.h +++ b/src/Desc.h @@ -33,27 +33,27 @@ public: ~ODesc(); - int IsReadable() const { return type == DESC_READABLE; } - int IsPortable() const { return type == DESC_PORTABLE; } - int IsBinary() const { return type == DESC_BINARY; } + bool IsReadable() const { return type == DESC_READABLE; } + bool IsPortable() const { return type == DESC_PORTABLE; } + bool IsBinary() const { return type == DESC_BINARY; } - int IsShort() const { return is_short; } - void SetShort() { is_short = 1; } - void SetShort(int s) { is_short = s; } + bool IsShort() const { return is_short; } + void SetShort() { is_short = true; } + void SetShort(bool s) { is_short = s; } // Whether we want to have quotes around strings. - int WantQuotes() const { return want_quotes; } - void SetQuotes(int q) { want_quotes = q; } + bool WantQuotes() const { return want_quotes; } + void SetQuotes(bool q) { want_quotes = q; } // Whether we want to print statistics like access time and execution // count where available. - int IncludeStats() const { return include_stats; } - void SetIncludeStats(int s) { include_stats = s; } + bool IncludeStats() const { return include_stats; } + void SetIncludeStats(bool s) { include_stats = s; } desc_style Style() const { return style; } void SetStyle(desc_style s) { style = s; } - void SetFlush(int arg_do_flush) { do_flush = arg_do_flush; } + void SetFlush(bool arg_do_flush) { do_flush = arg_do_flush; } void EnableEscaping(); void EnableUTF8(); @@ -196,11 +196,11 @@ protected: BroFile* f; // or the file we're using. int indent_level; - int is_short; - int want_quotes; - int do_flush; - int include_stats; int indent_with_spaces; + bool is_short; + bool want_quotes; + bool do_flush; + bool include_stats; std::set encountered_types; }; diff --git a/src/Dict.cc b/src/Dict.cc index 5b5be6fe4b..369510f7b1 100644 --- a/src/Dict.cc +++ b/src/Dict.cc @@ -284,7 +284,7 @@ void* Dictionary::Lookup(const void* key, int key_size, hash_t hash) const } void* Dictionary::Insert(void* key, int key_size, hash_t hash, void* val, - int copy_key) + bool copy_key) { if ( ! tbl ) Init(DEFAULT_DICT_SIZE); @@ -524,7 +524,7 @@ void Dictionary::Init2(int size) } // private -void* Dictionary::Insert(DictEntry* new_entry, int copy_key) +void* Dictionary::Insert(DictEntry* new_entry, bool copy_key) { if ( ! tbl ) Init(DEFAULT_DICT_SIZE); @@ -623,13 +623,13 @@ int Dictionary::NextPrime(int n) const return n; } -int Dictionary::IsPrime(int n) const +bool Dictionary::IsPrime(int n) const { for ( int j = 3; j * j <= n; ++j ) if ( n % j == 0 ) - return 0; + return false; - return 1; + return true; } void Dictionary::StartChangeSize(int new_size) @@ -669,7 +669,7 @@ void Dictionary::MoveChains() for ( int j = 0; j < chain->length(); ++j ) { - Insert((*chain)[j], 0); + Insert((*chain)[j], false); --num_entries; --num; } diff --git a/src/Dict.h b/src/Dict.h index 81a61baaf8..b5edeba76b 100644 --- a/src/Dict.h +++ b/src/Dict.h @@ -42,7 +42,7 @@ public: // that it's a heap pointer that now belongs to the Dictionary to // manage as needed. void* Insert(void* key, int key_size, hash_t hash, void* val, - int copy_key); + bool copy_key); // Removes the given element. Returns a pointer to the element in // case it needs to be deleted. Returns 0 if no such element exists. @@ -125,13 +125,13 @@ private: void DeInit(); // Internal version of Insert(). - void* Insert(DictEntry* entry, int copy_key); + void* Insert(DictEntry* entry, bool copy_key); void* DoRemove(DictEntry* entry, hash_t h, PList* chain, int chain_offset); int NextPrime(int n) const; - int IsPrime(int n) const; + bool IsPrime(int n) const; void StartChangeSize(int new_size); void FinishChangeSize(); void MoveChains(); diff --git a/src/Discard.cc b/src/Discard.cc index b08d454bed..bdfda9128d 100644 --- a/src/Discard.cc +++ b/src/Discard.cc @@ -28,14 +28,14 @@ Discarder::~Discarder() { } -int Discarder::IsActive() +bool Discarder::IsActive() { return check_ip || check_tcp || check_udp || check_icmp; } -int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) +bool Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) { - int discard_packet = 0; + bool discard_packet = false; if ( check_ip ) { @@ -59,26 +59,26 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen) if ( proto != IPPROTO_TCP && proto != IPPROTO_UDP && proto != IPPROTO_ICMP ) // This is not a protocol we understand. - return 0; + return false; // XXX shall we only check the first packet??? if ( ip->IsFragment() ) // Never check any fragment. - return 0; + return false; int ip_hdr_len = ip->HdrLen(); len -= ip_hdr_len; // remove IP header caplen -= ip_hdr_len; - int is_tcp = (proto == IPPROTO_TCP); - int is_udp = (proto == IPPROTO_UDP); + bool is_tcp = (proto == IPPROTO_TCP); + bool is_udp = (proto == IPPROTO_UDP); int min_hdr_len = is_tcp ? sizeof(struct tcphdr) : (is_udp ? sizeof(struct udphdr) : sizeof(struct icmp)); if ( len < min_hdr_len || caplen < min_hdr_len ) // we don't have a complete protocol header - return 0; + return false; // Where the data starts - if this is a protocol we know about, // this gets advanced past the transport header. @@ -163,5 +163,5 @@ Val* Discarder::BuildData(const u_char* data, int hdrlen, int len, int caplen) len = max(min(min(len, caplen), discarder_maxlen), 0); - return new StringVal(new BroString(data, len, 1)); + return new StringVal(new BroString(data, len, true)); } diff --git a/src/Discard.h b/src/Discard.h index fb154dcf92..01b55d6e4a 100644 --- a/src/Discard.h +++ b/src/Discard.h @@ -4,14 +4,8 @@ #include // for u_char -struct ip; -struct tcphdr; -struct udphdr; -struct icmp; - class IP_Hdr; class Val; -class RecordType; class Func; class Discarder { @@ -19,9 +13,9 @@ public: Discarder(); ~Discarder(); - int IsActive(); + bool IsActive(); - int NextPacket(const IP_Hdr* ip, int len, int caplen); + bool NextPacket(const IP_Hdr* ip, int len, int caplen); protected: Val* BuildData(const u_char* data, int hdrlen, int len, int caplen); diff --git a/src/EquivClass.h b/src/EquivClass.h index 8285a8d866..88e42e4085 100644 --- a/src/EquivClass.h +++ b/src/EquivClass.h @@ -20,7 +20,7 @@ public: void ConvertCCL(CCL* ccl); - int IsRep(int sym) const { return rep[sym] == sym; } + bool IsRep(int sym) const { return rep[sym] == sym; } int EquivRep(int sym) const { return rep[sym]; } int SymEquivClass(int sym) const { return equiv_class[sym]; } int* EquivClasses() const { return equiv_class; } diff --git a/src/Event.cc b/src/Event.cc index 96f35f6a91..c33fba5929 100644 --- a/src/Event.cc +++ b/src/Event.cc @@ -36,9 +36,7 @@ void Event::Describe(ODesc* d) const if ( d->IsReadable() ) d->AddSP("event"); - int s = d->IsShort(); - d->SetShort(); -// handler->Describe(d); + bool s = d->IsShort(); d->SetShort(s); if ( ! d->IsBinary() ) @@ -80,7 +78,7 @@ EventMgr::EventMgr() current_src = SOURCE_LOCAL; current_aid = 0; src_val = 0; - draining = 0; + draining = false; } EventMgr::~EventMgr() diff --git a/src/Event.h b/src/Event.h index 0f97ed5538..6bf43a0aa4 100644 --- a/src/Event.h +++ b/src/Event.h @@ -117,7 +117,7 @@ public: void Drain(); bool IsDraining() const { return draining; } - int HasEvents() const { return head != 0; } + bool HasEvents() const { return head != 0; } // Returns the source ID of last raised event. SourceID CurrentSource() const { return current_src; } diff --git a/src/Expr.cc b/src/Expr.cc index 4c5f19a158..e1a12db019 100644 --- a/src/Expr.cc +++ b/src/Expr.cc @@ -124,7 +124,7 @@ IntrusivePtr Expr::InitVal(const BroType* t, IntrusivePtr aggr) const if ( IsError() ) return nullptr; - return check_and_promote(Eval(nullptr), t, 1); + return check_and_promote(Eval(nullptr), t, true); } bool Expr::IsError() const @@ -439,8 +439,8 @@ IntrusivePtr BinaryExpr::Eval(Frame* f) const if ( ! v2 ) return nullptr; - int is_vec1 = is_vector(v1.get()); - int is_vec2 = is_vector(v2.get()); + bool is_vec1 = is_vector(v1.get()); + bool is_vec2 = is_vector(v2.get()); if ( is_vec1 && is_vec2 ) { // fold pairs of elements @@ -2013,7 +2013,7 @@ void RefExpr::Assign(Frame* f, IntrusivePtr v) } AssignExpr::AssignExpr(IntrusivePtr arg_op1, IntrusivePtr arg_op2, - int arg_is_init, IntrusivePtr arg_val, + bool arg_is_init, IntrusivePtr arg_val, attr_list* arg_attrs) : BinaryExpr(EXPR_ASSIGN, arg_is_init ? std::move(arg_op1) : arg_op1->MakeLvalue(), @@ -2328,7 +2328,7 @@ void AssignExpr::EvalIntoAggregate(const BroType* t, Val* aggr, Frame* f) const TableVal* tv = aggr->AsTableVal(); auto index = op1->Eval(f); - auto v = check_and_promote(op2->Eval(f), t->YieldType(), 1); + auto v = check_and_promote(op2->Eval(f), t->YieldType(), true); if ( ! index || ! v ) return; @@ -2439,7 +2439,7 @@ bool AssignExpr::IsPure() const } IndexSliceAssignExpr::IndexSliceAssignExpr(IntrusivePtr op1, - IntrusivePtr op2, int is_init) + IntrusivePtr op2, bool is_init) : AssignExpr(std::move(op1), std::move(op2), is_init) { } @@ -3285,7 +3285,7 @@ IntrusivePtr SetConstructorExpr::InitVal(const BroType* t, IntrusivePtrEval(nullptr), index_type, 1); + auto element = check_and_promote(e->Eval(nullptr), index_type, true); if ( ! element || ! tval->Assign(element.get(), 0) ) { @@ -3383,7 +3383,7 @@ IntrusivePtr VectorConstructorExpr::InitVal(const BroType* t, IntrusivePtr< loop_over_list(exprs, i) { Expr* e = exprs[i]; - auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), 1); + auto v = check_and_promote(e->Eval(nullptr), t->YieldType(), true); if ( ! v || ! vec->Assign(i, std::move(v)) ) { @@ -3855,7 +3855,7 @@ ScheduleTimer::~ScheduleTimer() { } -void ScheduleTimer::Dispatch(double /* t */, int /* is_expire */) +void ScheduleTimer::Dispatch(double /* t */, bool /* is_expire */) { if ( event ) mgr.Enqueue(event, std::move(args)); @@ -4138,15 +4138,15 @@ CallExpr::CallExpr(IntrusivePtr arg_func, bool CallExpr::IsPure() const { if ( IsError() ) - return 1; + return true; if ( ! func->IsPure() ) - return 0; + return false; auto func_val = func->Eval(nullptr); if ( ! func_val ) - return 0; + return false; ::Func* f = func_val->AsFunc(); @@ -4154,7 +4154,7 @@ bool CallExpr::IsPure() const // functions can lead to infinite recursion if the function being // called here happens to be recursive (either directly // or indirectly). - int pure = 0; + bool pure = false; if ( f->GetKind() == Func::BUILTIN_FUNC ) pure = f->IsPure() && args->IsPure(); @@ -4523,7 +4523,7 @@ IntrusivePtr ListExpr::InitType() const ti->AsTypeList(); if ( ! til->IsPure() || - ! til->AllMatch(til->PureType(), 1) ) + ! til->AllMatch(til->PureType(), true) ) tl->Append({NewRef{}, til}); else tl->Append({NewRef{}, til->PureType()}); @@ -4547,7 +4547,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co // Check whether each element of this list itself matches t, // in which case we should expand as a ListVal. - if ( ! aggr && type->AsTypeList()->AllMatch(t, 1) ) + if ( ! aggr && type->AsTypeList()->AllMatch(t, true) ) { auto v = make_intrusive(TYPE_ANY); const type_list* tl = type->AsTypeList()->Types(); @@ -4671,7 +4671,7 @@ IntrusivePtr ListExpr::InitVal(const BroType* t, IntrusivePtr aggr) co return nullptr; } - if ( ! v->AsTableVal()->AddTo(aggr->AsTableVal(), 1) ) + if ( ! v->AsTableVal()->AddTo(aggr->AsTableVal(), true) ) return nullptr; } } @@ -4711,16 +4711,16 @@ IntrusivePtr ListExpr::AddSetInit(const BroType* t, IntrusivePtr aggr) return nullptr; } - if ( ! element->AsTableVal()->AddTo(tv, 1) ) + if ( ! element->AsTableVal()->AddTo(tv, true) ) return nullptr; continue; } if ( expr->Type()->Tag() == TYPE_LIST ) - element = check_and_promote(std::move(element), it, 1); + element = check_and_promote(std::move(element), it, true); else - element = check_and_promote(std::move(element), (*it->Types())[0], 1); + element = check_and_promote(std::move(element), (*it->Types())[0], true); if ( ! element ) return nullptr; @@ -4781,7 +4781,7 @@ TraversalCode ListExpr::Traverse(TraversalCallback* cb) const } RecordAssignExpr::RecordAssignExpr(const IntrusivePtr& record, - const IntrusivePtr& init_list, int is_init) + const IntrusivePtr& init_list, bool is_init) { const expr_list& inits = init_list->AsListExpr()->Exprs(); @@ -4912,7 +4912,7 @@ void IsExpr::ExprDescribe(ODesc* d) const } IntrusivePtr get_assign_expr(IntrusivePtr op1, - IntrusivePtr op2, int is_init) + IntrusivePtr op2, bool is_init) { if ( op1->Type()->Tag() == TYPE_RECORD && op2->Type()->Tag() == TYPE_LIST ) @@ -5005,18 +5005,18 @@ IntrusivePtr check_and_promote_expr(Expr* const e, BroType* t) return {NewRef{}, e}; } -int check_and_promote_exprs(ListExpr* const elements, TypeList* types) +bool check_and_promote_exprs(ListExpr* const elements, TypeList* types) { expr_list& el = elements->Exprs(); const type_list* tl = types->Types(); if ( tl->length() == 1 && (*tl)[0]->Tag() == TYPE_ANY ) - return 1; + return true; if ( el.length() != tl->length() ) { types->Error("indexing mismatch", elements); - return 0; + return false; } loop_over_list(el, i) @@ -5027,7 +5027,7 @@ int check_and_promote_exprs(ListExpr* const elements, TypeList* types) if ( ! promoted_e ) { e->Error("type mismatch", (*tl)[i]); - return 0; + return false; } if ( promoted_e.get() != e ) @@ -5037,17 +5037,17 @@ int check_and_promote_exprs(ListExpr* const elements, TypeList* types) } } - return 1; + return true; } -int check_and_promote_args(ListExpr* const args, RecordType* types) +bool check_and_promote_args(ListExpr* const args, RecordType* types) { expr_list& el = args->Exprs(); int ntypes = types->NumFields(); // give variadic BIFs automatic pass if ( ntypes == 1 && types->FieldDecl(0)->type->Tag() == TYPE_ANY ) - return 1; + return true; if ( el.length() < ntypes ) { @@ -5063,7 +5063,7 @@ int check_and_promote_args(ListExpr* const args, RecordType* types) if ( ! def_attr ) { types->Error("parameter mismatch", args); - return 0; + return false; } def_elements.push_front(def_attr->AttrExpr()); @@ -5084,12 +5084,12 @@ int check_and_promote_args(ListExpr* const args, RecordType* types) return rval; } -int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) +bool check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) { expr_list& el = elements->Exprs(); if ( type->Tag() == TYPE_ANY ) - return 1; + return true; loop_over_list(el, i) { @@ -5099,7 +5099,7 @@ int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) if ( ! promoted_e ) { e->Error("type mismatch", type); - return 0; + return false; } if ( promoted_e.get() != e ) @@ -5109,7 +5109,7 @@ int check_and_promote_exprs_to_type(ListExpr* const elements, BroType* type) } } - return 1; + return true; } std::optional>> eval_list(Frame* f, const ListExpr* l) diff --git a/src/Expr.h b/src/Expr.h index 5e3c7b020e..ed2d953416 100644 --- a/src/Expr.h +++ b/src/Expr.h @@ -331,7 +331,7 @@ protected: virtual IntrusivePtr AddrFold(Val* v1, Val* v2) const; virtual IntrusivePtr SubNetFold(Val* v1, Val* v2) const; - int BothConst() const { return op1->IsConst() && op2->IsConst(); } + bool BothConst() const { return op1->IsConst() && op2->IsConst(); } // Exchange op1 and op2. void SwapOps(); @@ -511,7 +511,7 @@ class AssignExpr : public BinaryExpr { public: // If val is given, evaluating this expression will always yield the val // yet still perform the assignment. Used for triggers. - AssignExpr(IntrusivePtr op1, IntrusivePtr op2, int is_init, + AssignExpr(IntrusivePtr op1, IntrusivePtr op2, bool is_init, IntrusivePtr val = nullptr, attr_list* attrs = nullptr); IntrusivePtr Eval(Frame* f) const override; @@ -525,14 +525,14 @@ protected: bool TypeCheck(attr_list* attrs = 0); bool TypeCheckArithmetics(TypeTag bt1, TypeTag bt2); - int is_init; + bool is_init; IntrusivePtr val; // optional }; class IndexSliceAssignExpr : public AssignExpr { public: IndexSliceAssignExpr(IntrusivePtr op1, - IntrusivePtr op2, int is_init); + IntrusivePtr op2, bool is_init); IntrusivePtr Eval(Frame* f) const override; }; @@ -744,7 +744,7 @@ public: ScheduleTimer(const EventHandlerPtr& event, zeek::Args args, double t); ~ScheduleTimer() override; - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; protected: EventHandlerPtr event; @@ -879,7 +879,7 @@ protected: class RecordAssignExpr : public ListExpr { public: - RecordAssignExpr(const IntrusivePtr& record, const IntrusivePtr& init_list, int is_init); + RecordAssignExpr(const IntrusivePtr& record, const IntrusivePtr& init_list, bool is_init); }; class CastExpr : public UnaryExpr { @@ -912,7 +912,7 @@ inline Val* Expr::ExprVal() const // Decides whether to return an AssignExpr or a RecordAssignExpr. IntrusivePtr get_assign_expr(IntrusivePtr op1, - IntrusivePtr op2, int is_init); + IntrusivePtr op2, bool is_init); // Type-check the given expression(s) against the given type(s). Complain // if the expression cannot match the given type, returning 0. If it can @@ -931,9 +931,9 @@ IntrusivePtr get_assign_expr(IntrusivePtr op1, */ extern IntrusivePtr check_and_promote_expr(Expr* e, BroType* t); -extern int check_and_promote_exprs(ListExpr* elements, TypeList* types); -extern int check_and_promote_args(ListExpr* args, RecordType* types); -extern int check_and_promote_exprs_to_type(ListExpr* elements, BroType* type); +extern bool check_and_promote_exprs(ListExpr* elements, TypeList* types); +extern bool check_and_promote_args(ListExpr* args, RecordType* types); +extern bool check_and_promote_exprs_to_type(ListExpr* elements, BroType* type); // Returns a ListExpr simplified down to a list a values, or nil // if they couldn't all be reduced. diff --git a/src/File.cc b/src/File.cc index 9e01c144ff..ade6918715 100644 --- a/src/File.cc +++ b/src/File.cc @@ -87,12 +87,12 @@ BroFile::BroFile(const char* arg_name, const char* arg_access) f = stderr; if ( f ) - is_open = 1; + is_open = true; else if ( ! Open() ) { reporter->Error("cannot open %s: %s", name, strerror(errno)); - is_open = 0; + is_open = false; } } @@ -139,11 +139,11 @@ bool BroFile::Open(FILE* file, const char* mode) if ( ! f ) { - is_open = 0; + is_open = false; return false; } - is_open = 1; + is_open = true; open_files.emplace_back(std::make_pair(name, this)); RaiseOpenEvent(); @@ -166,7 +166,8 @@ BroFile::~BroFile() void BroFile::Init() { - open_time = is_open = 0; + open_time = 0; + is_open = false; attrs = 0; buffered = true; raw_output = false; @@ -203,25 +204,26 @@ void BroFile::SetBuf(bool arg_buffered) buffered = arg_buffered; } -int BroFile::Close() +bool BroFile::Close() { if ( ! is_open ) - return 1; + return true; // Do not close stdin/stdout/stderr. if ( f == stdin || f == stdout || f == stderr ) - return 0; + return false; if ( ! f ) - return 0; + return false; fclose(f); f = nullptr; - open_time = is_open = 0; + open_time = 0; + is_open = false; Unlink(); - return 1; + return true; } void BroFile::Unlink() @@ -305,10 +307,10 @@ void BroFile::CloseOpenFiles() } } -int BroFile::Write(const char* data, int len) +bool BroFile::Write(const char* data, int len) { if ( ! is_open ) - return 0; + return false; if ( ! len ) len = strlen(data); @@ -355,4 +357,3 @@ BroFile* BroFile::GetFile(const char* name) return new BroFile(name, "w"); } - diff --git a/src/File.h b/src/File.h index b1b15a6661..2d10237a76 100644 --- a/src/File.h +++ b/src/File.h @@ -29,7 +29,7 @@ public: const char* Name() const; // Returns false if an error occured. - int Write(const char* data, int len = 0); + bool Write(const char* data, int len = 0); void Flush() { fflush(f); } @@ -42,11 +42,11 @@ public: // Whether the file is open in a general sense; it might // not be open as a Unix file due to our management of // a finite number of FDs. - int IsOpen() const { return is_open; } + bool IsOpen() const { return is_open; } // Returns true if the close made sense, false if it was already // closed, not active, or whatever. - int Close(); + bool Close(); void Describe(ODesc* d) const override; @@ -97,10 +97,10 @@ protected: IntrusivePtr t; char* name; char* access; - int is_open; // whether the file is open in a general sense Attributes* attrs; - bool buffered; double open_time; + bool is_open; // whether the file is open in a general sense + bool buffered; bool raw_output; static const int MIN_BUFFER_SIZE = 1024; diff --git a/src/Frag.cc b/src/Frag.cc index c09ffe9834..c571a039d5 100644 --- a/src/Frag.cc +++ b/src/Frag.cc @@ -18,7 +18,7 @@ FragTimer::~FragTimer() f->ClearTimer(); } -void FragTimer::Dispatch(double t, int /* is_expire */) +void FragTimer::Dispatch(double t, bool /* is_expire */) { if ( f ) f->Expire(t); diff --git a/src/Frag.h b/src/Frag.h index 2a8b21db6c..31d5ec5bd0 100644 --- a/src/Frag.h +++ b/src/Frag.h @@ -60,7 +60,7 @@ public: { f = arg_f; } ~FragTimer() override; - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; // Break the association between this timer and its creator. void ClearReassembler() { f = 0; } diff --git a/src/Func.cc b/src/Func.cc index 79216fea17..e9933a6a6a 100644 --- a/src/Func.cc +++ b/src/Func.cc @@ -289,7 +289,7 @@ BroFunc::~BroFunc() Unref(closure); } -int BroFunc::IsPure() const +bool BroFunc::IsPure() const { return std::all_of(bodies.begin(), bodies.end(), [](const Body& b) { return b.stmts->IsPure(); }); @@ -575,7 +575,7 @@ IntrusivePtr BroFunc::AddInits(IntrusivePtr body, id_list* inits) } BuiltinFunc::BuiltinFunc(built_in_func arg_func, const char* arg_name, - int arg_is_pure) + bool arg_is_pure) : Func(BUILTIN_FUNC) { func = arg_func; @@ -596,7 +596,7 @@ BuiltinFunc::~BuiltinFunc() { } -int BuiltinFunc::IsPure() const +bool BuiltinFunc::IsPure() const { return is_pure; } diff --git a/src/Func.h b/src/Func.h index e790f71cdf..c414e3ac85 100644 --- a/src/Func.h +++ b/src/Func.h @@ -39,7 +39,7 @@ public: ~Func() override; - virtual int IsPure() const = 0; + virtual bool IsPure() const = 0; function_flavor Flavor() const { return FType()->Flavor(); } struct Body { @@ -123,7 +123,7 @@ public: BroFunc(ID* id, IntrusivePtr body, id_list* inits, size_t frame_size, int priority); ~BroFunc() override; - int IsPure() const override; + bool IsPure() const override; IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; /** @@ -195,10 +195,10 @@ using built_in_func = Val* (*)(Frame* frame, const zeek::Args* args); class BuiltinFunc : public Func { public: - BuiltinFunc(built_in_func func, const char* name, int is_pure); + BuiltinFunc(built_in_func func, const char* name, bool is_pure); ~BuiltinFunc() override; - int IsPure() const override; + bool IsPure() const override; IntrusivePtr Call(const zeek::Args& args, Frame* parent) const override; built_in_func TheFunc() const { return func; } @@ -208,7 +208,7 @@ protected: BuiltinFunc() { func = 0; is_pure = 0; } built_in_func func; - int is_pure; + bool is_pure; }; diff --git a/src/Hash.cc b/src/Hash.cc index c20e928dd5..3ba13b7d54 100644 --- a/src/Hash.cc +++ b/src/Hash.cc @@ -36,7 +36,6 @@ HashKey::HashKey(bro_int_t i) key = (void*) &key_u; size = sizeof(i); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(bro_uint_t u) @@ -45,7 +44,6 @@ HashKey::HashKey(bro_uint_t u) key = (void*) &key_u; size = sizeof(u); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(uint32_t u) @@ -54,7 +52,6 @@ HashKey::HashKey(uint32_t u) key = (void*) &key_u; size = sizeof(u); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(const uint32_t u[], int n) @@ -62,7 +59,6 @@ HashKey::HashKey(const uint32_t u[], int n) size = n * sizeof(u[0]); key = (void*) u; hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(double d) @@ -76,7 +72,6 @@ HashKey::HashKey(double d) key = (void*) &key_u; size = sizeof(d); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(const void* p) @@ -85,7 +80,6 @@ HashKey::HashKey(const void* p) key = (void*) &key_u; size = sizeof(p); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(const char* s) @@ -93,7 +87,6 @@ HashKey::HashKey(const char* s) size = strlen(s); // note - skip final \0 key = (void*) s; hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(const BroString* s) @@ -101,13 +94,12 @@ HashKey::HashKey(const BroString* s) size = s->Len(); key = (void*) s->Bytes(); hash = HashBytes(key, size); - is_our_dynamic = 0; } HashKey::HashKey(int copy_key, void* arg_key, int arg_size) { size = arg_size; - is_our_dynamic = 1; + is_our_dynamic = true; if ( copy_key ) { @@ -125,7 +117,7 @@ HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash) size = arg_size; hash = arg_hash; key = CopyKey(arg_key, size); - is_our_dynamic = 1; + is_our_dynamic = true; } HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash, @@ -134,7 +126,6 @@ HashKey::HashKey(const void* arg_key, int arg_size, hash_t arg_hash, size = arg_size; hash = arg_hash; key = const_cast(arg_key); - is_our_dynamic = 0; } HashKey::HashKey(const void* bytes, int arg_size) @@ -142,14 +133,14 @@ HashKey::HashKey(const void* bytes, int arg_size) size = arg_size; key = CopyKey(bytes, size); hash = HashBytes(key, size); - is_our_dynamic = 1; + is_our_dynamic = true; } void* HashKey::TakeKey() { if ( is_our_dynamic ) { - is_our_dynamic = 0; + is_our_dynamic = false; return key; } else diff --git a/src/Hash.h b/src/Hash.h index 9a5c99c60e..5f668977a5 100644 --- a/src/Hash.h +++ b/src/Hash.h @@ -81,9 +81,9 @@ protected: } key_u; void* key; - int is_our_dynamic; - int size; hash_t hash; + int size; + bool is_our_dynamic = false; }; extern void init_hash_function(); diff --git a/src/ID.cc b/src/ID.cc index f8d4c97bd1..bd7b536419 100644 --- a/src/ID.cc +++ b/src/ID.cc @@ -125,7 +125,7 @@ void ID::SetVal(IntrusivePtr v, init_class c) return; } else - v->AddTo(val, 0); + v->AddTo(val, false); } else { @@ -313,7 +313,7 @@ TraversalCode ID::Traverse(TraversalCallback* cb) const void ID::Error(const char* msg, const BroObj* o2) { - BroObj::Error(msg, o2, 1); + BroObj::Error(msg, o2, true); SetType(error_type()); } diff --git a/src/IP.cc b/src/IP.cc index b1e8a72414..65c34c8e40 100644 --- a/src/IP.cc +++ b/src/IP.cc @@ -66,7 +66,7 @@ static VectorVal* BuildOptionsVal(const u_char* data, int len) uint16_t off = 2 * sizeof(uint8_t); rv->Assign(1, val_mgr->GetCount(opt->ip6o_len)); rv->Assign(2, make_intrusive( - new BroString(data + off, opt->ip6o_len, 1))); + new BroString(data + off, opt->ip6o_len, true))); data += opt->ip6o_len + off; len -= opt->ip6o_len + off; } @@ -132,7 +132,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const rv->Assign(2, val_mgr->GetCount(rt->ip6r_type)); rv->Assign(3, val_mgr->GetCount(rt->ip6r_segleft)); uint16_t off = 4 * sizeof(uint8_t); - rv->Assign(4, make_intrusive(new BroString(data + off, Length() - off, 1))); + rv->Assign(4, make_intrusive(new BroString(data + off, Length() - off, true))); } break; @@ -163,7 +163,7 @@ RecordVal* IPv6_Hdr::BuildRecordVal(VectorVal* chain) const // Payload Len was non-zero for this header. rv->Assign(4, val_mgr->GetCount(ntohl(((uint32_t*)data)[2]))); uint16_t off = 3 * sizeof(uint32_t); - rv->Assign(5, make_intrusive(new BroString(data + off, Length() - off, 1))); + rv->Assign(5, make_intrusive(new BroString(data + off, Length() - off, true))); } } break; diff --git a/src/List.h b/src/List.h index 16393a34ed..58624c7f0b 100644 --- a/src/List.h +++ b/src/List.h @@ -136,6 +136,7 @@ public: } bool empty() const noexcept { return num_entries == 0; } + size_t size() const noexcept { return num_entries; } int length() const { return num_entries; } int max() const { return max_entries; } diff --git a/src/Obj.cc b/src/Obj.cc index 61ce530e08..43cee1e7d6 100644 --- a/src/Obj.cc +++ b/src/Obj.cc @@ -58,7 +58,7 @@ BroObj::~BroObj() delete location; } -void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const +void BroObj::Warn(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const { ODesc d; DoMsg(&d, msg, obj2, pinpoint_only, expr_location); @@ -66,7 +66,7 @@ void BroObj::Warn(const char* msg, const BroObj* obj2, int pinpoint_only, const reporter->PopLocation(); } -void BroObj::Error(const char* msg, const BroObj* obj2, int pinpoint_only, const Location* expr_location) const +void BroObj::Error(const char* msg, const BroObj* obj2, bool pinpoint_only, const Location* expr_location) const { if ( suppress_errors ) return; @@ -158,7 +158,7 @@ void BroObj::UpdateLocationEndInfo(const Location& end) } void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, - int pinpoint_only, const Location* expr_location) const + bool pinpoint_only, const Location* expr_location) const { d->SetShort(); @@ -175,7 +175,7 @@ void BroObj::DoMsg(ODesc* d, const char s1[], const BroObj* obj2, reporter->PushLocation(GetLocationInfo(), loc2); } -void BroObj::PinPoint(ODesc* d, const BroObj* obj2, int pinpoint_only) const +void BroObj::PinPoint(ODesc* d, const BroObj* obj2, bool pinpoint_only) const { d->Add(" ("); Describe(d); diff --git a/src/Obj.h b/src/Obj.h index 57b346efde..ec09dd8571 100644 --- a/src/Obj.h +++ b/src/Obj.h @@ -81,9 +81,9 @@ public: // included in the message, though if pinpoint_only is non-zero, // then obj2 is only used to pinpoint the location. void Warn(const char* msg, const BroObj* obj2 = 0, - int pinpoint_only = 0, const Location* expr_location = 0) const; + bool pinpoint_only = false, const Location* expr_location = 0) const; void Error(const char* msg, const BroObj* obj2 = 0, - int pinpoint_only = 0, const Location* expr_location = 0) const; + bool pinpoint_only = false, const Location* expr_location = 0) const; // Report internal errors. void BadTag(const char* msg, const char* t1 = 0, @@ -135,9 +135,9 @@ private: friend class SuppressErrors; void DoMsg(ODesc* d, const char s1[], const BroObj* obj2 = 0, - int pinpoint_only = 0, const Location* expr_location = 0) const; + bool pinpoint_only = false, const Location* expr_location = 0) const; void PinPoint(ODesc* d, const BroObj* obj2 = 0, - int pinpoint_only = 0) const; + bool pinpoint_only = false) const; friend inline void Ref(BroObj* o); friend inline void Unref(BroObj* o); diff --git a/src/OpaqueVal.cc b/src/OpaqueVal.cc index ecaa245fb7..b8d7669d54 100644 --- a/src/OpaqueVal.cc +++ b/src/OpaqueVal.cc @@ -754,14 +754,14 @@ BroType* BloomFilterVal::Type() const void BloomFilterVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, 1); + HashKey* key = hash->ComputeHash(val, true); bloom_filter->Add(key); delete key; } size_t BloomFilterVal::Count(const Val* val) const { - HashKey* key = hash->ComputeHash(val, 1); + HashKey* key = hash->ComputeHash(val, true); size_t cnt = bloom_filter->Count(key); delete key; return cnt; @@ -924,7 +924,7 @@ BroType* CardinalityVal::Type() const void CardinalityVal::Add(const Val* val) { - HashKey* key = hash->ComputeHash(val, 1); + HashKey* key = hash->ComputeHash(val, true); c->AddElement(key->Hash()); delete key; } diff --git a/src/PrefixTable.cc b/src/PrefixTable.cc index ee2280757a..391d11e673 100644 --- a/src/PrefixTable.cc +++ b/src/PrefixTable.cc @@ -16,7 +16,7 @@ prefix_t* PrefixTable::MakePrefix(const IPAddr& addr, int width) IPPrefix PrefixTable::PrefixToIPPrefix(prefix_t* prefix) { - return IPPrefix(IPAddr(IPv6, reinterpret_cast(&prefix->add.sin6), IPAddr::Network), prefix->bitlen, 1); + return IPPrefix(IPAddr(IPv6, reinterpret_cast(&prefix->add.sin6), IPAddr::Network), prefix->bitlen, true); } void* PrefixTable::Insert(const IPAddr& addr, int width, void* data) @@ -173,7 +173,7 @@ PrefixTable::iterator PrefixTable::InitIterator() void* PrefixTable::GetNext(iterator* i) { - while ( 1 ) + while ( true ) { i->Xnode = i->Xrn; if ( ! i->Xnode ) diff --git a/src/RE.cc b/src/RE.cc index 083356b5c4..183c421e17 100644 --- a/src/RE.cc +++ b/src/RE.cc @@ -116,10 +116,10 @@ void Specific_RE_Matcher::MakeCaseInsensitive() pattern_text = s; } -int Specific_RE_Matcher::Compile(int lazy) +bool Specific_RE_Matcher::Compile(bool lazy) { if ( ! pattern_text ) - return 0; + return false; rem = this; RE_set_input(pattern_text); @@ -132,7 +132,7 @@ int Specific_RE_Matcher::Compile(int lazy) reporter->Error("error compiling pattern /%s/", pattern_text); Unref(nfa); nfa = 0; - return 0; + return false; } EC()->BuildECs(); @@ -140,15 +140,15 @@ int Specific_RE_Matcher::Compile(int lazy) dfa = new DFA_Machine(nfa, EC()); - Unref(nfa); + Unref(nfa); nfa = 0; ecs = EC()->EquivClasses(); - return 1; + return true; } -int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx) +bool Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx) { if ( (size_t)set.length() != idx.size() ) reporter->InternalError("compileset: lengths of sets differ"); @@ -173,7 +173,7 @@ int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx) Unref(nfa); nfa = 0; - return 0; + return false; } nfa->FinalState()->SetAccept(idx[i]); @@ -192,7 +192,7 @@ int Specific_RE_Matcher::CompileSet(const string_list& set, const int_list& idx) dfa = new DFA_Machine(nfa, EC()); ecs = EC()->EquivClasses(); - return 1; + return true; } string Specific_RE_Matcher::LookupDef(const string& def) @@ -204,12 +204,12 @@ string Specific_RE_Matcher::LookupDef(const string& def) return string(); } -int Specific_RE_Matcher::MatchAll(const char* s) +bool Specific_RE_Matcher::MatchAll(const char* s) { return MatchAll((const u_char*)(s), strlen(s)); } -int Specific_RE_Matcher::MatchAll(const BroString* s) +bool Specific_RE_Matcher::MatchAll(const BroString* s) { // s->Len() does not include '\0'. return MatchAll(s->Bytes(), s->Len()); @@ -235,7 +235,7 @@ int Specific_RE_Matcher::LongestMatch(const BroString* s) return LongestMatch(s->Bytes(), s->Len()); } -int Specific_RE_Matcher::MatchAll(const u_char* bv, int n) +bool Specific_RE_Matcher::MatchAll(const u_char* bv, int n) { if ( ! dfa ) // An empty pattern matches "all" iff what's being @@ -480,7 +480,7 @@ void RE_Matcher::MakeCaseInsensitive() re_exact->MakeCaseInsensitive(); } -int RE_Matcher::Compile(int lazy) +bool RE_Matcher::Compile(bool lazy) { return re_anywhere->Compile(lazy) && re_exact->Compile(lazy); } diff --git a/src/RE.h b/src/RE.h index 7ff6df112c..702767016c 100644 --- a/src/RE.h +++ b/src/RE.h @@ -54,7 +54,7 @@ public: void SetPat(const char* pat) { pattern_text = copy_string(pat); } - int Compile(int lazy = 0); + bool Compile(bool lazy = false); // The following is vestigial from flex's use of "{name}" definitions. // It's here because at some point we may want to support such @@ -80,14 +80,14 @@ public: void ConvertCCLs(); - int MatchAll(const char* s); - int MatchAll(const BroString* s); + bool MatchAll(const char* s); + bool MatchAll(const BroString* s); // Compiles a set of regular expressions simultaniously. // 'idx' contains indizes associated with the expressions. // On matching, the set of indizes is returned which correspond // to the matching expressions. (idx must not contain zeros). - int CompileSet(const string_list& set, const int_list& idx); + bool CompileSet(const string_list& set, const int_list& idx); // Returns the position in s just beyond where the first match // occurs, or 0 if there is no such position in s. Note that @@ -119,7 +119,7 @@ protected: // appending to an existing pattern_text. void AddPat(const char* pat, const char* orig_fmt, const char* app_fmt); - int MatchAll(const u_char* bv, int n); + bool MatchAll(const u_char* bv, int n); int Match(const u_char* bv, int n); match_type mt; @@ -186,12 +186,12 @@ public: // Makes the matcher as specified to date case-insensitive. void MakeCaseInsensitive(); - int Compile(int lazy = 0); + bool Compile(bool lazy = false); // Returns true if s exactly matches the pattern, false otherwise. - int MatchExactly(const char* s) + bool MatchExactly(const char* s) { return re_exact->MatchAll(s); } - int MatchExactly(const BroString* s) + bool MatchExactly(const BroString* s) { return re_exact->MatchAll(s); } // Returns the position in s just beyond where the first match diff --git a/src/Reassem.h b/src/Reassem.h index 1baf93bc84..4166f4dccb 100644 --- a/src/Reassem.h +++ b/src/Reassem.h @@ -265,7 +265,7 @@ public: void ClearBlocks(); void ClearOldBlocks(); - int HasBlocks() const + bool HasBlocks() const { return ! block_list.Empty(); } uint64_t LastReassemSeq() const { return last_reassem_seq; } diff --git a/src/Reporter.cc b/src/Reporter.cc index 14434146cc..68446dd553 100644 --- a/src/Reporter.cc +++ b/src/Reporter.cc @@ -244,7 +244,7 @@ public: : Timer(t + timeout, TIMER_NET_WEIRD_EXPIRE), weird_name(name) {} - void Dispatch(double t, int is_expire) override + void Dispatch(double t, bool is_expire) override { reporter->ResetNetWeird(weird_name); } std::string weird_name; @@ -258,7 +258,7 @@ public: : Timer(t + timeout, TIMER_FLOW_WEIRD_EXPIRE), endpoints(std::move(p)) {} - void Dispatch(double t, int is_expire) override + void Dispatch(double t, bool is_expire) override { reporter->ResetFlowWeird(endpoints.first, endpoints.second); } IPPair endpoints; diff --git a/src/RuleCondition.cc b/src/RuleCondition.cc index b5331d5be1..16efe35821 100644 --- a/src/RuleCondition.cc +++ b/src/RuleCondition.cc @@ -195,4 +195,3 @@ void RuleConditionEval::PrintDebug() { fprintf(stderr, " RuleConditionEval: %s\n", id->Name()); } - diff --git a/src/RuleMatcher.cc b/src/RuleMatcher.cc index e49503e276..f492846a4d 100644 --- a/src/RuleMatcher.cc +++ b/src/RuleMatcher.cc @@ -758,8 +758,8 @@ RuleEndpointState* RuleMatcher::InitEndpoint(analyzer::Analyzer* analyzer, // Evaluate all rules on this node which don't contain // any patterns. for ( Rule* r = hdr_test->pure_rules; r; r = r->next ) - if ( EvalRuleConditions(r, state, 0, 0, 0) ) - ExecRuleActions(r, state, 0, 0, 0); + if ( EvalRuleConditions(r, state, 0, 0, false) ) + ExecRuleActions(r, state, 0, 0, false); // If we're on or above the RE_level, we may have some // pattern matching to do. @@ -953,17 +953,17 @@ void RuleMatcher::Match(RuleEndpointState* state, Rule::PatternType type, if ( ! state->matched_by_patterns.is_member(r) ) { state->matched_by_patterns.push_back(r); - BroString* s = new BroString(data, data_len, 0); + BroString* s = new BroString(data, data_len, false); state->matched_text.push_back(s); } DBG_LOG(DBG_RULES, "And has not already fired"); // Eval additional conditions. - if ( ! EvalRuleConditions(r, state, data, data_len, 0) ) + if ( ! EvalRuleConditions(r, state, data, data_len, false) ) continue; // Found a match. - ExecRuleActions(r, state, data, data_len, 0); + ExecRuleActions(r, state, data, data_len, false); } } } @@ -977,11 +977,11 @@ void RuleMatcher::FinishEndpoint(RuleEndpointState* state) // although they have not matched at the beginning. So, we have // to test the candidates here. - ExecPureRules(state, 1); + ExecPureRules(state, true); loop_over_list(state->matched_by_patterns, i) ExecRulePurely(state->matched_by_patterns[i], - state->matched_text[i], state, 1); + state->matched_text[i], state, true); } void RuleMatcher::ExecPureRules(RuleEndpointState* state, bool eos) @@ -1115,7 +1115,7 @@ void RuleMatcher::ExecRule(Rule* rule, RuleEndpointState* state, bool eos) void RuleMatcher::ClearEndpointState(RuleEndpointState* state) { - ExecPureRules(state, 1); + ExecPureRules(state, true); state->payload_size = -1; diff --git a/src/Sessions.cc b/src/Sessions.cc index 7870880013..b250b85a39 100644 --- a/src/Sessions.cc +++ b/src/Sessions.cc @@ -43,7 +43,7 @@ enum NetBIOS_Service { NetSessions* sessions; -void IPTunnelTimer::Dispatch(double t, int is_expire) +void IPTunnelTimer::Dispatch(double t, bool is_expire) { NetSessions::IPTunnelMap::const_iterator it = sessions->ip_tunnels.find(tunnel_idx); @@ -360,7 +360,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr const struct tcphdr* tp = (const struct tcphdr *) data; id.src_port = tp->th_sport; id.dst_port = tp->th_dport; - id.is_one_way = 0; + id.is_one_way = false; d = &tcp_conns; break; } @@ -370,7 +370,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr const struct udphdr* up = (const struct udphdr *) data; id.src_port = up->uh_sport; id.dst_port = up->uh_dport; - id.is_one_way = 0; + id.is_one_way = false; d = &udp_conns; break; } @@ -681,7 +681,7 @@ void NetSessions::DoNextPacket(double t, const Packet* pkt, const IP_Hdr* ip_hdr int record_packet = 1; // whether to record the packet at all int record_content = 1; // whether to record its data - int is_orig = (id.src_addr == conn->OrigAddr()) && + bool is_orig = (id.src_addr == conn->OrigAddr()) && (id.src_port == conn->OrigPort()); conn->CheckFlowLabel(is_orig, ip_hdr->FlowLabel()); @@ -951,7 +951,7 @@ Connection* NetSessions::FindConnection(Val* v) id.src_port = htons((unsigned short) orig_portv->Port()); id.dst_port = htons((unsigned short) resp_portv->Port()); - id.is_one_way = 0; // ### incorrect for ICMP connections + id.is_one_way = false; // ### incorrect for ICMP connections ConnIDKey key = BuildConnIDKey(id); ConnectionMap* d; diff --git a/src/Sessions.h b/src/Sessions.h index 0140e7694f..57547a9ad3 100644 --- a/src/Sessions.h +++ b/src/Sessions.h @@ -245,7 +245,7 @@ public: ~IPTunnelTimer() override {} - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; protected: NetSessions::IPPair tunnel_idx; diff --git a/src/Stats.cc b/src/Stats.cc index d59ffa8e02..8720933fae 100644 --- a/src/Stats.cc +++ b/src/Stats.cc @@ -31,14 +31,14 @@ public: interval = i; } - void Dispatch(double t, int is_expire); + void Dispatch(double t, bool is_expire) override; protected: double interval; ProfileLogger* logger; }; -void ProfileTimer::Dispatch(double t, int is_expire) +void ProfileTimer::Dispatch(double t, bool is_expire) { logger->Log(); diff --git a/src/Stmt.cc b/src/Stmt.cc index 1cfc0c93df..0a7e0cdcae 100644 --- a/src/Stmt.cc +++ b/src/Stmt.cc @@ -83,9 +83,9 @@ bool Stmt::SetLocationInfo(const Location* start, const Location* end) return true; } -int Stmt::IsPure() const +bool Stmt::IsPure() const { - return 0; + return false; } void Stmt::Describe(ODesc* d) const @@ -267,7 +267,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, if ( f->IsRawOutput() ) { ODesc d(DESC_READABLE); - d.SetFlush(0); + d.SetFlush(false); d.SetStyle(style); describe_vals(vals, &d, offset); @@ -276,7 +276,7 @@ IntrusivePtr PrintStmt::DoExec(std::vector> vals, else { ODesc d(DESC_READABLE, f); - d.SetFlush(0); + d.SetFlush(false); d.SetStyle(style); describe_vals(vals, &d, offset); @@ -320,7 +320,7 @@ IntrusivePtr ExprStmt::DoExec(Frame* /* f */, Val* /* v */, stmt_flow_type& return nullptr; } -int ExprStmt::IsPure() const +bool ExprStmt::IsPure() const { return ! e || e->IsPure(); } @@ -396,7 +396,7 @@ IntrusivePtr IfStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const return result; } -int IfStmt::IsPure() const +bool IfStmt::IsPure() const { return e->IsPure() && s1->IsPure() && s2->IsPure(); } @@ -718,7 +718,7 @@ SwitchStmt::~SwitchStmt() bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) { - HashKey* hk = comp_hash->ComputeHash(v, 1); + HashKey* hk = comp_hash->ComputeHash(v, true); if ( ! hk ) { @@ -762,7 +762,7 @@ std::pair SwitchStmt::FindCaseLabelMatch(const Val* v) const // Find matching expression cases. if ( case_label_value_map.Length() ) { - HashKey* hk = comp_hash->ComputeHash(v, 1); + HashKey* hk = comp_hash->ComputeHash(v, true); if ( ! hk ) { @@ -832,18 +832,18 @@ IntrusivePtr SwitchStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) con return rval; } -int SwitchStmt::IsPure() const +bool SwitchStmt::IsPure() const { if ( ! e->IsPure() ) - return 0; + return false; for ( const auto& c : *cases ) { if ( ! c->ExprCases()->IsPure() || ! c->Body()->IsPure() ) - return 0; + return false; } - return 1; + return true; } void SwitchStmt::Describe(ODesc* d) const @@ -889,9 +889,9 @@ AddStmt::AddStmt(IntrusivePtr arg_e) : ExprStmt(STMT_ADD, std::move(arg_e) Error("illegal add statement"); } -int AddStmt::IsPure() const +bool AddStmt::IsPure() const { - return 0; + return false; } IntrusivePtr AddStmt::Exec(Frame* f, stmt_flow_type& flow) const @@ -925,9 +925,9 @@ DelStmt::DelStmt(IntrusivePtr arg_e) : ExprStmt(STMT_DELETE, std::move(arg Error("illegal delete statement"); } -int DelStmt::IsPure() const +bool DelStmt::IsPure() const { - return 0; + return false; } IntrusivePtr DelStmt::Exec(Frame* f, stmt_flow_type& flow) const @@ -993,7 +993,7 @@ WhileStmt::WhileStmt(IntrusivePtr arg_loop_condition, WhileStmt::~WhileStmt() = default; -int WhileStmt::IsPure() const +bool WhileStmt::IsPure() const { return loop_condition->IsPure() && body->IsPure(); } @@ -1269,7 +1269,7 @@ IntrusivePtr ForStmt::DoExec(Frame* f, Val* v, stmt_flow_type& flow) const return ret; } -int ForStmt::IsPure() const +bool ForStmt::IsPure() const { return e->IsPure() && body->IsPure(); } @@ -1338,9 +1338,9 @@ IntrusivePtr NextStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const return nullptr; } -int NextStmt::IsPure() const +bool NextStmt::IsPure() const { - return 1; + return true; } void NextStmt::Describe(ODesc* d) const @@ -1365,9 +1365,9 @@ IntrusivePtr BreakStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const return nullptr; } -int BreakStmt::IsPure() const +bool BreakStmt::IsPure() const { - return 1; + return true; } void BreakStmt::Describe(ODesc* d) const @@ -1392,9 +1392,9 @@ IntrusivePtr FallthroughStmt::Exec(Frame* /* f */, stmt_flow_type& flow) co return nullptr; } -int FallthroughStmt::IsPure() const +bool FallthroughStmt::IsPure() const { - return 1; + return false; } void FallthroughStmt::Describe(ODesc* d) const @@ -1521,12 +1521,12 @@ IntrusivePtr StmtList::Exec(Frame* f, stmt_flow_type& flow) const return nullptr; } -int StmtList::IsPure() const +bool StmtList::IsPure() const { for ( const auto& stmt : stmts ) if ( ! stmt->IsPure() ) - return 0; - return 1; + return false; + return true; } void StmtList::Describe(ODesc* d) const @@ -1718,9 +1718,9 @@ IntrusivePtr NullStmt::Exec(Frame* /* f */, stmt_flow_type& flow) const return nullptr; } -int NullStmt::IsPure() const +bool NullStmt::IsPure() const { - return 1; + return true; } void NullStmt::Describe(ODesc* d) const @@ -1780,7 +1780,7 @@ IntrusivePtr WhenStmt::Exec(Frame* f, stmt_flow_type& flow) const return nullptr; } -int WhenStmt::IsPure() const +bool WhenStmt::IsPure() const { return cond->IsPure() && s1->IsPure() && (! s2 || s2->IsPure()); } diff --git a/src/Stmt.h b/src/Stmt.h index 78cb91ae29..cd28c60172 100644 --- a/src/Stmt.h +++ b/src/Stmt.h @@ -35,7 +35,7 @@ public: bool SetLocationInfo(const Location* start, const Location* end) override; // True if the statement has no side effects, false otherwise. - virtual int IsPure() const; + virtual bool IsPure() const; StmtList* AsStmtList() { @@ -131,7 +131,7 @@ protected: virtual IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const; - int IsPure() const override; + bool IsPure() const override; IntrusivePtr e; }; @@ -150,7 +150,7 @@ public: protected: IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; IntrusivePtr s1; IntrusivePtr s2; @@ -195,7 +195,7 @@ public: protected: IntrusivePtr DoExec(Frame* f, Val* v, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; // Initialize composite hash and case label map. void Init(); @@ -227,7 +227,7 @@ class AddStmt : public ExprStmt { public: explicit AddStmt(IntrusivePtr e); - int IsPure() const override; + bool IsPure() const override; IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; TraversalCode Traverse(TraversalCallback* cb) const override; @@ -237,7 +237,7 @@ class DelStmt : public ExprStmt { public: explicit DelStmt(IntrusivePtr e); - int IsPure() const override; + bool IsPure() const override; IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; TraversalCode Traverse(TraversalCallback* cb) const override; @@ -261,7 +261,7 @@ public: WhileStmt(IntrusivePtr loop_condition, IntrusivePtr body); ~WhileStmt() override; - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -287,7 +287,7 @@ public: const Expr* LoopExpr() const { return e.get(); } const Stmt* LoopBody() const { return body.get(); } - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -308,7 +308,7 @@ public: NextStmt() : Stmt(STMT_NEXT) { } IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -322,7 +322,7 @@ public: BreakStmt() : Stmt(STMT_BREAK) { } IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -336,7 +336,7 @@ public: FallthroughStmt() : Stmt(STMT_FALLTHROUGH) { } IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -369,7 +369,7 @@ public: TraversalCode Traverse(TraversalCallback* cb) const override; protected: - int IsPure() const override; + bool IsPure() const override; stmt_list stmts; }; @@ -414,7 +414,7 @@ public: NullStmt() : Stmt(STMT_NULL) { } IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; void Describe(ODesc* d) const override; @@ -430,7 +430,7 @@ public: ~WhenStmt() override; IntrusivePtr Exec(Frame* f, stmt_flow_type& flow) const override; - int IsPure() const override; + bool IsPure() const override; const Expr* Cond() const { return cond.get(); } const Stmt* Body() const { return s1.get(); } diff --git a/src/Timer.cc b/src/Timer.cc index dc0fb5e470..b6d6100e7f 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -139,7 +139,7 @@ void PQ_TimerMgr::Expire() { DBG_LOG(DBG_TM, "Dispatching timer %s (%p)", timer_type_to_string(timer->Type()), timer); - timer->Dispatch(t, 1); + timer->Dispatch(t, true); --current_timers[timer->Type()]; delete timer; } @@ -161,7 +161,7 @@ int PQ_TimerMgr::DoAdvance(double new_t, int max_expire) DBG_LOG(DBG_TM, "Dispatching timer %s (%p)", timer_type_to_string(timer->Type()), timer); - timer->Dispatch(new_t, 0); + timer->Dispatch(new_t, false); delete timer; timer = Top(); diff --git a/src/Timer.h b/src/Timer.h index 5148248d20..970eef7064 100644 --- a/src/Timer.h +++ b/src/Timer.h @@ -57,7 +57,7 @@ public: // t gives the dispatch time. is_expire is true if the // timer is being dispatched because we're expiring all // pending timers. - virtual void Dispatch(double t, int is_expire) = 0; + virtual void Dispatch(double t, bool is_expire) = 0; void Describe(ODesc* d) const; diff --git a/src/Trigger.cc b/src/Trigger.cc index ae2127f791..d3b11e5cd8 100644 --- a/src/Trigger.cc +++ b/src/Trigger.cc @@ -98,7 +98,7 @@ public: ~TriggerTimer() { Unref(trigger); } - void Dispatch(double t, int is_expire) + void Dispatch(double t, bool is_expire) override { // The network_time may still have been zero when the // timer was instantiated. In this case, it fires diff --git a/src/Type.cc b/src/Type.cc index d5b29ef346..baa1b6552a 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -112,9 +112,9 @@ BroType* BroType::YieldType() return nullptr; } -int BroType::HasField(const char* /* field */) const +bool BroType::HasField(const char* /* field */) const { - return 0; + return false; } BroType* BroType::FieldType(const char* /* field */) const @@ -157,12 +157,12 @@ TypeList::~TypeList() Unref(type); } -int TypeList::AllMatch(const BroType* t, int is_init) const +bool TypeList::AllMatch(const BroType* t, bool is_init) const { for ( const auto& type : types ) if ( ! same_type(type, t, is_init) ) - return 0; - return 1; + return false; + return true; } void TypeList::Append(IntrusivePtr t) @@ -498,7 +498,7 @@ int FuncType::MatchesIndex(ListExpr* const index) const MATCHES_INDEX_SCALAR : DOES_NOT_MATCH_INDEX; } -int FuncType::CheckArgs(const type_list* args, bool is_init) const +bool FuncType::CheckArgs(const type_list* args, bool is_init) const { const type_list* my_args = arg_types->Types(); @@ -506,17 +506,17 @@ int FuncType::CheckArgs(const type_list* args, bool is_init) const { Warn(fmt("Wrong number of arguments for function. Expected %d, got %d.", args->length(), my_args->length())); - return 0; + return false; } - int success = 1; + bool success = true; for ( int i = 0; i < my_args->length(); ++i ) if ( ! same_type((*args)[i], (*my_args)[i], is_init) ) { Warn(fmt("Type mismatch in function argument #%d. Expected %s, got %s.", i, type_name((*args)[i]->Tag()), type_name((*my_args)[i]->Tag()))); - success = 0; + success = false; } return success; @@ -640,7 +640,7 @@ RecordType::~RecordType() } } -int RecordType::HasField(const char* field) const +bool RecordType::HasField(const char* field) const { return FieldOffset(field) >= 0; } @@ -1410,40 +1410,40 @@ BroType* base_type_no_ref(TypeTag tag) // false otherwise. Assumes that t1's tag is different from t2's. Note // that the test is in only one direction - we don't check whether t2 is // initialization-compatible with t1. -static int is_init_compat(const BroType* t1, const BroType* t2) +static bool is_init_compat(const BroType* t1, const BroType* t2) { if ( t1->Tag() == TYPE_LIST ) { if ( t2->Tag() == TYPE_RECORD ) - return 1; + return true; else - return t1->AsTypeList()->AllMatch(t2, 1); + return t1->AsTypeList()->AllMatch(t2, true); } if ( t1->IsSet() ) - return same_type(t1->AsSetType()->Indices(), t2, 1); + return same_type(t1->AsSetType()->Indices(), t2, true); - return 0; + return false; } -int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_record_field_names) +bool same_type(const BroType* t1, const BroType* t2, bool is_init, bool match_record_field_names) { if ( t1 == t2 || t1->Tag() == TYPE_ANY || t2->Tag() == TYPE_ANY ) - return 1; + return true; t1 = flatten_type(t1); t2 = flatten_type(t2); if ( t1 == t2 ) - return 1; + return true; if ( t1->Tag() != t2->Tag() ) { if ( is_init ) return is_init_compat(t1, t2) || is_init_compat(t2, t1); - return 0; + return false; } switch ( t1->Tag() ) { @@ -1463,14 +1463,14 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco case TYPE_SUBNET: case TYPE_ANY: case TYPE_ERROR: - return 1; + return true; case TYPE_ENUM: // We should probably check to see whether all of the // enumerations are present and in the same location. // FIXME: Yes, but perhaps we should better return // true per default? - return 1; + return true; case TYPE_TABLE: { @@ -1483,7 +1483,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco if ( tl1 || tl2 ) { if ( ! tl1 || ! tl2 || ! same_type(tl1, tl2, is_init, match_record_field_names) ) - return 0; + return false; } const BroType* y1 = t1->YieldType(); @@ -1492,10 +1492,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco if ( y1 || y2 ) { if ( ! y1 || ! y2 || ! same_type(y1, y2, is_init, match_record_field_names) ) - return 0; + return false; } - return 1; + return true; } case TYPE_FUNC: @@ -1504,13 +1504,13 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco const FuncType* ft2 = (const FuncType*) t2; if ( ft1->Flavor() != ft2->Flavor() ) - return 0; + return false; if ( t1->YieldType() || t2->YieldType() ) { if ( ! t1->YieldType() || ! t2->YieldType() || ! same_type(t1->YieldType(), t2->YieldType(), is_init, match_record_field_names) ) - return 0; + return false; } return ft1->CheckArgs(ft2->ArgTypes()->Types(), is_init); @@ -1522,7 +1522,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco const RecordType* rt2 = (const RecordType*) t2; if ( rt1->NumFields() != rt2->NumFields() ) - return 0; + return false; for ( int i = 0; i < rt1->NumFields(); ++i ) { @@ -1531,10 +1531,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco if ( (match_record_field_names && ! streq(td1->id, td2->id)) || ! same_type(td1->type.get(), td2->type.get(), is_init, match_record_field_names) ) - return 0; + return false; } - return 1; + return true; } case TYPE_LIST: @@ -1543,13 +1543,13 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco const type_list* tl2 = t2->AsTypeList()->Types(); if ( tl1->length() != tl2->length() ) - return 0; + return false; loop_over_list(*tl1, i) if ( ! same_type((*tl1)[i], (*tl2)[i], is_init, match_record_field_names) ) - return 0; + return false; - return 1; + return true; } case TYPE_VECTOR: @@ -1560,7 +1560,7 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco { const OpaqueType* ot1 = (const OpaqueType*) t1; const OpaqueType* ot2 = (const OpaqueType*) t2; - return ot1->Name() == ot2->Name() ? 1 : 0; + return ot1->Name() == ot2->Name(); } case TYPE_TYPE: @@ -1569,10 +1569,10 @@ int same_type(const BroType* t1, const BroType* t2, int is_init, bool match_reco case TYPE_UNION: reporter->Error("union type in same_type()"); } - return 0; + return false; } -int same_attrs(const Attributes* a1, const Attributes* a2) +bool same_attrs(const Attributes* a1, const Attributes* a2) { if ( ! a1 ) return (a2 == 0); @@ -1583,7 +1583,7 @@ int same_attrs(const Attributes* a1, const Attributes* a2) return (*a1 == *a2); } -int record_promotion_compatible(const RecordType* super_rec, +bool record_promotion_compatible(const RecordType* super_rec, const RecordType* sub_rec) { for ( int i = 0; i < sub_rec->NumFields(); ++i ) @@ -1601,17 +1601,17 @@ int record_promotion_compatible(const RecordType* super_rec, continue; if ( sub_field_type->Tag() != TYPE_RECORD ) - return 0; + return false; if ( super_field_type->Tag() != TYPE_RECORD ) - return 0; + return false; if ( ! record_promotion_compatible(super_field_type->AsRecordType(), sub_field_type->AsRecordType()) ) - return 0; + return false; } - return 1; + return true; } const BroType* flatten_type(const BroType* t) @@ -1630,7 +1630,7 @@ const BroType* flatten_type(const BroType* t) reporter->InternalError("empty type list in flatten_type"); const BroType* ft = (*types)[0]; - if ( types->length() == 1 || tl->AllMatch(ft, 0) ) + if ( types->length() == 1 || tl->AllMatch(ft, false) ) return ft; return t; @@ -1641,7 +1641,7 @@ BroType* flatten_type(BroType* t) return (BroType*) flatten_type((const BroType*) t); } -int is_assignable(BroType* t) +bool is_assignable(BroType* t) { switch ( t->Tag() ) { case TYPE_BOOL: @@ -1663,23 +1663,23 @@ int is_assignable(BroType* t) case TYPE_ANY: case TYPE_ERROR: case TYPE_LIST: - return 1; + return true; case TYPE_VECTOR: case TYPE_FILE: case TYPE_OPAQUE: case TYPE_TABLE: case TYPE_TYPE: - return 1; + return true; case TYPE_VOID: - return 0; + return false; case TYPE_UNION: reporter->Error("union type in is_assignable()"); } - return 0; + return false; } #define CHECK_TYPE(t) \ diff --git a/src/Type.h b/src/Type.h index b6ba45a376..9686bcdf9f 100644 --- a/src/Type.h +++ b/src/Type.h @@ -156,7 +156,7 @@ public: InternalTypeTag InternalType() const { return internal_tag; } // Whether it's stored in network order. - int IsNetworkOrder() const { return is_network_order; } + bool IsNetworkOrder() const { return is_network_order; } // Type-checks the given expression list, returning // MATCHES_INDEX_SCALAR = 1 if it matches this type's index @@ -176,7 +176,7 @@ public: // Returns true if this type is a record and contains the // given field, false otherwise. - virtual int HasField(const char* field) const; + virtual bool HasField(const char* field) const; // Returns the type of the given field, or nil if no such field. virtual BroType* FieldType(const char* field) const; @@ -357,7 +357,7 @@ public: const type_list* Types() const { return &types; } type_list* Types() { return &types; } - int IsPure() const { return pure_type != 0; } + bool IsPure() const { return pure_type != 0; } // Returns the underlying pure type, or nil if the list // is not pure or is empty. @@ -367,7 +367,7 @@ public: // True if all of the types match t, false otherwise. If // is_init is true, then the matching is done in the context // of an initialization. - int AllMatch(const BroType* t, int is_init) const; + bool AllMatch(const BroType* t, bool is_init) const; void Append(IntrusivePtr t); void AppendEvenIfNotPure(IntrusivePtr t); @@ -457,7 +457,7 @@ public: { yield = nullptr; flavor = arg_flav; } int MatchesIndex(ListExpr* index) const override; - int CheckArgs(const type_list* args, bool is_init = false) const; + bool CheckArgs(const type_list* args, bool is_init = false) const; TypeList* ArgTypes() const { return arg_types.get(); } @@ -508,7 +508,7 @@ public: ~RecordType() override; - int HasField(const char* field) const override; + bool HasField(const char* field) const override; BroType* FieldType(const char* field) const override; BroType* FieldType(int field) const; IntrusivePtr FieldDefault(int field) const; @@ -702,14 +702,14 @@ inline IntrusivePtr error_type() { return base_type(TYPE_ERROR); } // True if the two types are equivalent. If is_init is true then the test is // done in the context of an initialization. If match_record_field_names is // true then for record types the field names have to match, too. -extern int same_type(const BroType* t1, const BroType* t2, int is_init=0, bool match_record_field_names=true); +extern bool same_type(const BroType* t1, const BroType* t2, bool is_init=false, bool match_record_field_names=true); // True if the two attribute lists are equivalent. -extern int same_attrs(const Attributes* a1, const Attributes* a2); +extern bool same_attrs(const Attributes* a1, const Attributes* a2); // Returns true if the record sub_rec can be promoted to the record // super_rec. -extern int record_promotion_compatible(const RecordType* super_rec, +extern bool record_promotion_compatible(const RecordType* super_rec, const RecordType* sub_rec); // If the given BroType is a TypeList with just one element, returns @@ -737,7 +737,7 @@ IntrusivePtr init_type(Expr* init); bool is_atomic_type(const BroType* t); // True if the given type tag corresponds to type that can be assigned to. -extern int is_assignable(BroType* t); +extern bool is_assignable(BroType* t); // True if the given type tag corresponds to an integral type. inline bool IsIntegral(TypeTag t) { return (t == TYPE_INT || t == TYPE_COUNT || t == TYPE_COUNTER); } diff --git a/src/Val.cc b/src/Val.cc index 45bf78cb90..0597323b89 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -144,25 +144,25 @@ IntrusivePtr Val::DoClone(CloneState* state) return nullptr; } -int Val::IsZero() const +bool Val::IsZero() const { switch ( type->InternalType() ) { case TYPE_INTERNAL_INT: return val.int_val == 0; case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 0; case TYPE_INTERNAL_DOUBLE: return val.double_val == 0.0; - default: return 0; + default: return false; } } -int Val::IsOne() const +bool Val::IsOne() const { switch ( type->InternalType() ) { case TYPE_INTERNAL_INT: return val.int_val == 1; case TYPE_INTERNAL_UNSIGNED: return val.uint_val == 1; case TYPE_INTERNAL_DOUBLE: return val.double_val == 1.0; - default: return 0; + default: return false; } } @@ -278,16 +278,16 @@ unsigned int Val::MemoryAllocation() const return padded_sizeof(*this); } -int Val::AddTo(Val* v, int is_first_init) const +bool Val::AddTo(Val* v, bool is_first_init) const { Error("+= initializer only applies to aggregate values"); - return 0; + return false; } -int Val::RemoveFrom(Val* v) const +bool Val::RemoveFrom(Val* v) const { Error("-= initializer only applies to aggregate values"); - return 0; + return false; } void Val::Describe(ODesc* d) const @@ -581,7 +581,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* { auto blank = make_intrusive(""); auto fn_val = make_intrusive(field_name); - auto key_val = fn_val->Substitute(re, blank.get(), 0)->AsStringVal(); + auto key_val = fn_val->Substitute(re, blank.get(), false)->AsStringVal(); key_str = key_val->ToStdString(); Unref(key_val); } @@ -786,17 +786,17 @@ string PortVal::Protocol() const return "unknown"; } -int PortVal::IsTCP() const +bool PortVal::IsTCP() const { return (val.uint_val & PORT_SPACE_MASK) == TCP_PORT_MASK; } -int PortVal::IsUDP() const +bool PortVal::IsUDP() const { return (val.uint_val & PORT_SPACE_MASK) == UDP_PORT_MASK; } -int PortVal::IsICMP() const +bool PortVal::IsICMP() const { return (val.uint_val & PORT_SPACE_MASK) == ICMP_PORT_MASK; } @@ -963,7 +963,7 @@ StringVal::StringVal(BroString* s) : Val(s, TYPE_STRING) // The following adds a NUL at the end. StringVal::StringVal(int length, const char* s) - : StringVal(new BroString(reinterpret_cast(s), length, 1)) + : StringVal(new BroString(reinterpret_cast(s), length, true)) { } @@ -1103,7 +1103,7 @@ Val* StringVal::Substitute(RE_Matcher* re, StringVal* repl, bool do_all) // the NUL. r[0] = '\0'; - return new StringVal(new BroString(1, result, r - result)); + return new StringVal(new BroString(true, result, r - result)); } IntrusivePtr StringVal::DoClone(CloneState* state) @@ -1113,7 +1113,7 @@ IntrusivePtr StringVal::DoClone(CloneState* state) // audit whether anything internal actually does mutate it. return state->NewClone(this, make_intrusive( new BroString((u_char*) val.string_val->Bytes(), - val.string_val->Len(), 1))); + val.string_val->Len(), true))); } PatternVal::PatternVal(RE_Matcher* re) @@ -1128,12 +1128,12 @@ PatternVal::~PatternVal() Unref(type); // base_type() ref'd it, so did our base constructor } -int PatternVal::AddTo(Val* v, int /* is_first_init */) const +bool PatternVal::AddTo(Val* v, bool /* is_first_init */) const { if ( v->Type()->Tag() != TYPE_PATTERN ) { v->Error("not a pattern"); - return 0; + return false; } PatternVal* pv = v->AsPatternVal(); @@ -1144,7 +1144,7 @@ int PatternVal::AddTo(Val* v, int /* is_first_init */) const pv->SetMatcher(re); - return 1; + return true; } void PatternVal::SetMatcher(RE_Matcher* re) @@ -1303,7 +1303,7 @@ TableValTimer::~TableValTimer() table->ClearTimer(this); } -void TableValTimer::Dispatch(double t, int is_expire) +void TableValTimer::Dispatch(double t, bool is_expire) { if ( ! is_expire ) { @@ -1491,26 +1491,26 @@ void TableVal::CheckExpireAttr(attr_tag at) } } -int TableVal::Assign(Val* index, IntrusivePtr new_val) +bool TableVal::Assign(Val* index, IntrusivePtr new_val) { HashKey* k = ComputeHash(index); if ( ! k ) { index->Error("index type doesn't match table", table_type->Indices()); - return 0; + return false; } return Assign(index, k, std::move(new_val)); } -int TableVal::Assign(Val* index, Val* new_val) +bool TableVal::Assign(Val* index, Val* new_val) { return Assign(index, {AdoptRef{}, new_val}); } -int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) +bool TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) { - int is_set = table_type->IsSet(); + bool is_set = table_type->IsSet(); if ( (is_set && new_val) || (! is_set && ! new_val) ) InternalWarning("bad set/table in TableVal::Assign"); @@ -1523,7 +1523,7 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) // memory allocated to the key bytes, so have to assume k is invalid // from here on out. delete k; - k = 0; + k = nullptr; if ( subnets ) { @@ -1552,10 +1552,10 @@ int TableVal::Assign(Val* index, HashKey* k, IntrusivePtr new_val) delete old_entry_val; - return 1; + return true; } -int TableVal::Assign(Val* index, HashKey* k, Val* new_val) +bool TableVal::Assign(Val* index, HashKey* k, Val* new_val) { return Assign(index, k, {AdoptRef{}, new_val}); } @@ -1565,17 +1565,17 @@ IntrusivePtr TableVal::SizeVal() const return {AdoptRef{}, val_mgr->GetCount(Size())}; } -int TableVal::AddTo(Val* val, int is_first_init) const +bool TableVal::AddTo(Val* val, bool is_first_init) const { return AddTo(val, is_first_init, true); } -int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const +bool TableVal::AddTo(Val* val, bool is_first_init, bool propagate_ops) const { if ( val->Type()->Tag() != TYPE_TABLE ) { val->Error("not a table"); - return 0; + return false; } TableVal* t = val->AsTableVal(); @@ -1583,7 +1583,7 @@ int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const if ( ! same_type(type, t->Type()) ) { type->Error("table type clash", t->Type()); - return 0; + return false; } const PDict* tbl = AsTable(); @@ -1604,24 +1604,24 @@ int TableVal::AddTo(Val* val, int is_first_init, bool propagate_ops) const if ( type->IsSet() ) { if ( ! t->Assign(v->Value(), k, 0) ) - return 0; + return false; } else { if ( ! t->Assign(0, k, {NewRef{}, v->Value()}) ) - return 0; + return false; } } - return 1; + return true; } -int TableVal::RemoveFrom(Val* val) const +bool TableVal::RemoveFrom(Val* val) const { if ( val->Type()->Tag() != TYPE_TABLE ) { val->Error("not a table"); - return 0; + return false; } TableVal* t = val->AsTableVal(); @@ -1629,7 +1629,7 @@ int TableVal::RemoveFrom(Val* val) const if ( ! same_type(type, t->Type()) ) { type->Error("table type clash", t->Type()); - return 0; + return false; } const PDict* tbl = AsTable(); @@ -1647,7 +1647,7 @@ int TableVal::RemoveFrom(Val* val) const delete k; } - return 1; + return true; } TableVal* TableVal::Intersect(const TableVal* tv) const @@ -1735,7 +1735,7 @@ bool TableVal::IsSubsetOf(const TableVal* tv) const return true; } -int TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) +bool TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) { BroType* index_type = index->Type(); @@ -1757,9 +1757,9 @@ int TableVal::ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val) for ( int i = 0; i < iv->Length(); ++i ) if ( ! ExpandAndInit({NewRef{}, iv->Index(i)}, new_val) ) - return 0; + return false; - return 1; + return true; } else @@ -2225,7 +2225,7 @@ void TableVal::Describe(ODesc* d) const } } -int TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val) +bool TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val) { Val* ind_k_v = (*vl)[k]; auto ind_k = ind_k_v->Type()->IsSet() ? @@ -2244,16 +2244,14 @@ int TableVal::ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_v expd->Append((*vl)[j]->Ref()); } - int success = ExpandAndInit(std::move(expd), new_val); - - if ( ! success ) - return 0; + if ( ! ExpandAndInit(std::move(expd), new_val) ) + return false; } - return 1; + return true; } -int TableVal::CheckAndAssign(Val* index, IntrusivePtr new_val) +bool TableVal::CheckAndAssign(Val* index, IntrusivePtr new_val) { Val* v = 0; if ( subnets ) @@ -2559,7 +2557,7 @@ unsigned int TableVal::MemoryAllocation() const HashKey* TableVal::ComputeHash(const Val* index) const { - return table_hash->ComputeHash(index, 1); + return table_hash->ComputeHash(index, true); } void TableVal::SaveParseTimeTableState(RecordType* rt) @@ -2974,7 +2972,7 @@ IntrusivePtr VectorVal::SizeVal() const bool VectorVal::Assign(unsigned int index, IntrusivePtr element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), 0) ) + ! same_type(element->Type(), vector_type->YieldType(), false) ) return false; Val* val_at_index = 0; @@ -3015,7 +3013,7 @@ bool VectorVal::AssignRepeat(unsigned int index, unsigned int how_many, bool VectorVal::Insert(unsigned int index, Val* element) { if ( element && - ! same_type(element->Type(), vector_type->YieldType(), 0) ) + ! same_type(element->Type(), vector_type->YieldType(), false) ) { Unref(element); return false; @@ -3051,12 +3049,12 @@ bool VectorVal::Remove(unsigned int index) return true; } -int VectorVal::AddTo(Val* val, int /* is_first_init */) const +bool VectorVal::AddTo(Val* val, bool /* is_first_init */) const { if ( val->Type()->Tag() != TYPE_VECTOR ) { val->Error("not a vector"); - return 0; + return false; } VectorVal* v = val->AsVectorVal(); @@ -3064,7 +3062,7 @@ int VectorVal::AddTo(Val* val, int /* is_first_init */) const if ( ! same_type(type, v->Type()) ) { type->Error("vector type clash", v->Type()); - return 0; + return false; } auto last_idx = v->Size(); @@ -3072,7 +3070,7 @@ int VectorVal::AddTo(Val* val, int /* is_first_init */) const for ( auto i = 0u; i < Size(); ++i ) v->Assign(last_idx++, {NewRef{}, Lookup(i)}); - return 1; + return true; } Val* VectorVal::Lookup(unsigned int index) const @@ -3135,7 +3133,7 @@ void VectorVal::ValDescribe(ODesc* d) const } IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, - int is_init, + bool is_init, const Location* expr_location) { if ( ! v ) @@ -3160,7 +3158,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, if ( same_type(t, vt, is_init) ) return v; - t->Error("type clash", v.get(), 0, expr_location); + t->Error("type clash", v.get(), false, expr_location); return nullptr; } @@ -3168,9 +3166,9 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, (! IsArithmetic(v_tag) || t_tag != TYPE_TIME || ! v->IsZero()) ) { if ( t_tag == TYPE_LIST || v_tag == TYPE_LIST ) - t->Error("list mixed with scalar", v.get(), 0, expr_location); + t->Error("list mixed with scalar", v.get(), false, expr_location); else - t->Error("arithmetic mixed with non-arithmetic", v.get(), 0, expr_location); + t->Error("arithmetic mixed with non-arithmetic", v.get(), false, expr_location); return nullptr; } @@ -3182,7 +3180,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, TypeTag mt = max_type(t_tag, v_tag); if ( mt != t_tag ) { - t->Error("over-promotion of arithmetic value", v.get(), 0, expr_location); + t->Error("over-promotion of arithmetic value", v.get(), false, expr_location); return nullptr; } } @@ -3201,7 +3199,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, case TYPE_INTERNAL_INT: if ( ( vit == TYPE_INTERNAL_UNSIGNED || vit == TYPE_INTERNAL_DOUBLE ) && Val::WouldOverflow(vt, t, v.get()) ) { - t->Error("overflow promoting from unsigned/double to signed arithmetic value", v.get(), 0, expr_location); + t->Error("overflow promoting from unsigned/double to signed arithmetic value", v.get(), false, expr_location); return nullptr; } else if ( t_tag == TYPE_INT ) @@ -3217,7 +3215,7 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, case TYPE_INTERNAL_UNSIGNED: if ( ( vit == TYPE_INTERNAL_DOUBLE || vit == TYPE_INTERNAL_INT) && Val::WouldOverflow(vt, t, v.get()) ) { - t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), 0, expr_location); + t->Error("overflow promoting from signed/double to unsigned arithmetic value", v.get(), false, expr_location); return nullptr; } else if ( t_tag == TYPE_COUNT || t_tag == TYPE_COUNTER ) @@ -3242,10 +3240,10 @@ IntrusivePtr check_and_promote(IntrusivePtr v, const BroType* t, return promoted_v; } -int same_val(const Val* /* v1 */, const Val* /* v2 */) +bool same_val(const Val* /* v1 */, const Val* /* v2 */) { reporter->InternalError("same_val not implemented"); - return 0; + return false; } bool is_atomic_val(const Val* v) @@ -3253,12 +3251,12 @@ bool is_atomic_val(const Val* v) return is_atomic_type(v->Type()); } -int same_atomic_val(const Val* v1, const Val* v2) +bool same_atomic_val(const Val* v1, const Val* v2) { // This is a very preliminary implementation of same_val(), // true only for equal, simple atomic values of same type. if ( v1->Type()->Tag() != v2->Type()->Tag() ) - return 0; + return false; switch ( v1->Type()->InternalType() ) { case TYPE_INTERNAL_INT: @@ -3276,10 +3274,10 @@ int same_atomic_val(const Val* v1, const Val* v2) default: reporter->InternalWarning("same_atomic_val called for non-atomic value"); - return 0; + return false; } - return 0; + return false; } void describe_vals(const val_list* vals, ODesc* d, int offset) diff --git a/src/Val.h b/src/Val.h index da5d9afba5..96b610892d 100644 --- a/src/Val.h +++ b/src/Val.h @@ -155,8 +155,8 @@ public: Val* Ref() { ::Ref(this); return this; } IntrusivePtr Clone(); - int IsZero() const; - int IsOne() const; + bool IsZero() const; + bool IsOne() const; bro_int_t InternalInt() const; bro_uint_t InternalUnsigned() const; @@ -177,10 +177,10 @@ public: // Returns true if succcessful. is_first_init is true only if // this is the *first* initialization of the value, not // if it's a subsequent += initialization. - virtual int AddTo(Val* v, int is_first_init) const; + virtual bool AddTo(Val* v, bool is_first_init) const; // Remove this value from the given value (if appropriate). - virtual int RemoveFrom(Val* v) const; + virtual bool RemoveFrom(Val* v) const; BroType* Type() { return type; } const BroType* Type() const { return type; } @@ -478,9 +478,9 @@ public: string Protocol() const; // Tests for protocol types. - int IsTCP() const; - int IsUDP() const; - int IsICMP() const; + bool IsTCP() const; + bool IsUDP() const; + bool IsICMP() const; TransportProto PortType() const { @@ -584,7 +584,7 @@ public: explicit PatternVal(RE_Matcher* re); ~PatternVal() override; - int AddTo(Val* v, int is_first_init) const override; + bool AddTo(Val* v, bool is_first_init) const override; void SetMatcher(RE_Matcher* re); @@ -679,7 +679,7 @@ public: TableValTimer(TableVal* val, double t); ~TableValTimer() override; - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; TableVal* Table() { return table; } @@ -701,10 +701,10 @@ public: // version takes a HashKey and Unref()'s it when done. If we're a // set, new_val has to be nil. If we aren't a set, index may be nil // in the second version. - int Assign(Val* index, IntrusivePtr new_val); - int Assign(Val* index, Val* new_val); - int Assign(Val* index, HashKey* k, IntrusivePtr new_val); - int Assign(Val* index, HashKey* k, Val* new_val); + bool Assign(Val* index, IntrusivePtr new_val); + bool Assign(Val* index, Val* new_val); + bool Assign(Val* index, HashKey* k, IntrusivePtr new_val); + bool Assign(Val* index, HashKey* k, Val* new_val); IntrusivePtr SizeVal() const override; @@ -713,10 +713,10 @@ public: // Returns true if the addition typechecked, false if not. // If is_first_init is true, then this is the *first* initialization // (and so should be strictly adding new elements). - int AddTo(Val* v, int is_first_init) const override; + bool AddTo(Val* v, bool is_first_init) const override; // Same but allows suppression of state operations. - int AddTo(Val* v, int is_first_init, bool propagate_ops) const; + bool AddTo(Val* v, bool is_first_init, bool propagate_ops) const; // Remove the entire contents. void RemoveAll(); @@ -724,7 +724,7 @@ public: // Remove the entire contents of the table from the given value. // which must also be a TableVal. // Returns true if the addition typechecked, false if not. - int RemoveFrom(Val* v) const override; + bool RemoveFrom(Val* v) const override; // Returns a new table that is the intersection of this // table and the given table. Intersection is just done @@ -744,7 +744,7 @@ public: // Expands any lists in the index into multiple initializations. // Returns true if the initializations typecheck, false if not. - int ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val); + bool ExpandAndInit(IntrusivePtr index, IntrusivePtr new_val); // Returns the element's value if it exists in the table, // nil otherwise. Note, "index" is not const because we @@ -836,8 +836,8 @@ protected: void RebuildTable(ParseTimeTableState ptts); void CheckExpireAttr(attr_tag at); - int ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val); - int CheckAndAssign(Val* index, IntrusivePtr new_val); + bool ExpandCompoundAndInit(val_list* vl, int k, IntrusivePtr new_val); + bool CheckAndAssign(Val* index, IntrusivePtr new_val); // Calculates default value for index. Returns 0 if none. IntrusivePtr Default(Val* index); @@ -993,7 +993,7 @@ public: // Add this value to the given value (if appropriate). // Returns true if succcessful. - int AddTo(Val* v, int is_first_init) const override; + bool AddTo(Val* v, bool is_first_init) const override; // Returns nil if no element was at that value. // Lookup does NOT grow the vector to this size. @@ -1035,11 +1035,11 @@ protected: // and returns nil, also Unref()'ing v. If is_init is true, then // the checking is done in the context of an initialization. extern IntrusivePtr check_and_promote(IntrusivePtr v, - const BroType* t, int is_init, + const BroType* t, bool is_init, const Location* expr_location = nullptr); -extern int same_val(const Val* v1, const Val* v2); -extern int same_atomic_val(const Val* v1, const Val* v2); +extern bool same_val(const Val* v1, const Val* v2); +extern bool same_atomic_val(const Val* v1, const Val* v2); extern bool is_atomic_val(const Val* v); extern void describe_vals(const val_list* vals, ODesc* d, int offset=0); extern void describe_vals(const std::vector>& vals, diff --git a/src/Var.cc b/src/Var.cc index c447517b53..28bd4d5ed5 100644 --- a/src/Var.cc +++ b/src/Var.cc @@ -31,7 +31,7 @@ static IntrusivePtr init_val(Expr* init, const BroType* t, static void make_var(ID* id, IntrusivePtr t, init_class c, IntrusivePtr init, attr_list* attr, decl_type dt, - int do_init) + bool do_init) { if ( id->Type() ) { @@ -39,7 +39,7 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, { BroObj* redef_obj = init ? (BroObj*) init.get() : (BroObj*) t.get(); if ( dt != VAR_REDEF ) - id->Warn("redefinition requires \"redef\"", redef_obj, 1); + id->Warn("redefinition requires \"redef\"", redef_obj, true); } else if ( dt != VAR_REDEF || init || ! attr ) @@ -225,14 +225,14 @@ static void make_var(ID* id, IntrusivePtr t, init_class c, void add_global(ID* id, IntrusivePtr t, init_class c, IntrusivePtr init, attr_list* attr, decl_type dt) { - make_var(id, std::move(t), c, std::move(init), attr, dt, 1); + make_var(id, std::move(t), c, std::move(init), attr, dt, true); } IntrusivePtr add_local(IntrusivePtr id, IntrusivePtr t, init_class c, IntrusivePtr init, attr_list* attr, decl_type dt) { - make_var(id.get(), std::move(t), c, init, attr, dt, 0); + make_var(id.get(), std::move(t), c, init, attr, dt, false); if ( init ) { @@ -264,10 +264,10 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr id, IntrusivePtr init, IntrusivePtr val) { - make_var(id.get(), 0, INIT_FULL, init, 0, VAR_REGULAR, 0); + make_var(id.get(), nullptr, INIT_FULL, init, nullptr, VAR_REGULAR, false); auto name_expr = make_intrusive(std::move(id)); return make_intrusive(std::move(name_expr), std::move(init), - 0, std::move(val)); + false, std::move(val)); } void add_type(ID* id, IntrusivePtr t, attr_list* attr) @@ -339,7 +339,7 @@ static bool has_attr(const attr_list* al, attr_tag tag) } void begin_func(ID* id, const char* module_name, function_flavor flavor, - int is_redef, IntrusivePtr t, attr_list* attrs) + bool is_redef, IntrusivePtr t, attr_list* attrs) { if ( flavor == FUNC_FLAVOR_EVENT ) { diff --git a/src/Var.h b/src/Var.h index 3d78515adc..92af4cd5e9 100644 --- a/src/Var.h +++ b/src/Var.h @@ -32,7 +32,7 @@ extern IntrusivePtr add_and_assign_local(IntrusivePtr id, extern void add_type(ID* id, IntrusivePtr t, attr_list* attr); extern void begin_func(ID* id, const char* module_name, function_flavor flavor, - int is_redef, IntrusivePtr t, + bool is_redef, IntrusivePtr t, attr_list* attrs = nullptr); extern void end_func(IntrusivePtr body); diff --git a/src/WeirdState.h b/src/WeirdState.h index 22f42c5524..41c4049a9a 100644 --- a/src/WeirdState.h +++ b/src/WeirdState.h @@ -6,7 +6,7 @@ #include struct WeirdState { - WeirdState() { count = 0; sampling_start_time = 0; } + WeirdState() = default; uint64_t count = 0; double sampling_start_time = 0; }; diff --git a/src/analyzer/Analyzer.cc b/src/analyzer/Analyzer.cc index e651b58239..6f109c4b72 100644 --- a/src/analyzer/Analyzer.cc +++ b/src/analyzer/Analyzer.cc @@ -19,7 +19,7 @@ public: virtual ~AnalyzerTimer(); - void Dispatch(double t, int is_expire); + void Dispatch(double t, bool is_expire) override; protected: AnalyzerTimer() : analyzer(), timer(), do_expire() {} @@ -48,7 +48,7 @@ AnalyzerTimer::~AnalyzerTimer() Unref(analyzer->Conn()); } -void AnalyzerTimer::Dispatch(double t, int is_expire) +void AnalyzerTimer::Dispatch(double t, bool is_expire) { if ( is_expire && ! do_expire ) return; @@ -725,7 +725,7 @@ void Analyzer::ProtocolViolation(const char* reason, const char* data, int len) } void Analyzer::AddTimer(analyzer_timer_func timer, double t, - int do_expire, TimerType type) + bool do_expire, TimerType type) { Timer* analyzer_timer = new AnalyzerTimer(this, timer, t, do_expire, type); @@ -752,7 +752,7 @@ void Analyzer::CancelTimers() for ( auto timer : tmp ) timer_mgr->Cancel(timer); - timers_canceled = 1; + timers_canceled = true; timers.clear(); } @@ -929,7 +929,7 @@ void TransportLayerAnalyzer::PacketContents(const u_char* data, int len) { if ( packet_contents && len > 0 ) { - BroString* cbs = new BroString(data, len, 1); + BroString* cbs = new BroString(data, len, true); Val* contents = new StringVal(cbs); Event(packet_contents, contents); } diff --git a/src/analyzer/Analyzer.h b/src/analyzer/Analyzer.h index e50c8e4e91..4d25fccb27 100644 --- a/src/analyzer/Analyzer.h +++ b/src/analyzer/Analyzer.h @@ -648,7 +648,7 @@ protected: * * @param type The timer's type. */ - void AddTimer(analyzer_timer_func timer, double t, int do_expire, + void AddTimer(analyzer_timer_func timer, double t, bool do_expire, TimerType type); /** diff --git a/src/analyzer/protocol/conn-size/functions.bif b/src/analyzer/protocol/conn-size/functions.bif index 24b51c895e..f74464aef9 100644 --- a/src/analyzer/protocol/conn-size/functions.bif +++ b/src/analyzer/protocol/conn-size/functions.bif @@ -35,11 +35,11 @@ function set_current_conn_bytes_threshold%(cid: conn_id, threshold: count, is_or %{ analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); if ( ! a ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); - static_cast(a)->SetByteAndPacketThreshold(threshold, 1, is_orig); + static_cast(a)->SetByteAndPacketThreshold(threshold, true, is_orig); - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} ## Sets a threshold for connection packets, overwtiting any potential old thresholds. @@ -59,11 +59,11 @@ function set_current_conn_packets_threshold%(cid: conn_id, threshold: count, is_ %{ analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); if ( ! a ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); - static_cast(a)->SetByteAndPacketThreshold(threshold, 0, is_orig); + static_cast(a)->SetByteAndPacketThreshold(threshold, false, is_orig); - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} ## Sets the current duration threshold for connection, overwriting any potential old @@ -81,11 +81,11 @@ function set_current_conn_duration_threshold%(cid: conn_id, threshold: interval% %{ analyzer::Analyzer* a = GetConnsizeAnalyzer(cid); if ( ! a ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); static_cast(a)->SetDurationThreshold(threshold); - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} # Gets the current byte threshold size for a connection. @@ -105,7 +105,7 @@ function get_current_conn_bytes_threshold%(cid: conn_id, is_orig: bool%): count if ( ! a ) return val_mgr->GetCount(0); - return val_mgr->GetCount(static_cast(a)->GetByteAndPacketThreshold(1, is_orig)); + return val_mgr->GetCount(static_cast(a)->GetByteAndPacketThreshold(true, is_orig)); %} ## Gets the current packet threshold size for a connection. @@ -124,7 +124,7 @@ function get_current_conn_packets_threshold%(cid: conn_id, is_orig: bool%): coun if ( ! a ) return val_mgr->GetCount(0); - return val_mgr->GetCount(static_cast(a)->GetByteAndPacketThreshold(0, is_orig)); + return val_mgr->GetCount(static_cast(a)->GetByteAndPacketThreshold(false, is_orig)); %} ## Gets the current duration threshold size for a connection. diff --git a/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac b/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac index ad71373423..db1b487178 100644 --- a/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac +++ b/src/analyzer/protocol/dce-rpc/dce_rpc-protocol.pac @@ -98,7 +98,7 @@ type DCE_RPC_Bind = record { max_xmit_frag : uint16; max_recv_frag : uint16; assoc_group_id : uint32; - context_list : ContextList(1, DCE_RPC_BIND); + context_list : ContextList(true, DCE_RPC_BIND); }; type DCE_RPC_Bind_Ack = record { @@ -108,7 +108,7 @@ type DCE_RPC_Bind_Ack = record { sec_addr_length : uint16; sec_addr : bytestring &length=sec_addr_length; pad : padding align 4; - contexts : ContextList(0, DCE_RPC_BIND_ACK); + contexts : ContextList(false, DCE_RPC_BIND_ACK); }; type DCE_RPC_Request(h: DCE_RPC_Header) = record { @@ -136,7 +136,7 @@ type DCE_RPC_AlterContext = record { max_xmit_frag : uint16; max_recv_frag : uint16; assoc_group_id : uint32; - context_list : ContextList(1, DCE_RPC_ALTER_CONTEXT); + context_list : ContextList(true, DCE_RPC_ALTER_CONTEXT); }; type DCE_RPC_AlterContext_Resp = record { @@ -146,7 +146,7 @@ type DCE_RPC_AlterContext_Resp = record { sec_addr_length : uint16; sec_addr : bytestring &length=sec_addr_length; pad : padding align 4; - contexts : ContextList(0, DCE_RPC_ALTER_CONTEXT_RESP); + contexts : ContextList(false, DCE_RPC_ALTER_CONTEXT_RESP); }; type DCE_RPC_Body(header: DCE_RPC_Header) = case header.PTYPE of { diff --git a/src/analyzer/protocol/dnp3/DNP3.cc b/src/analyzer/protocol/dnp3/DNP3.cc index 8d22e32e2f..9db5ecce47 100644 --- a/src/analyzer/protocol/dnp3/DNP3.cc +++ b/src/analyzer/protocol/dnp3/DNP3.cc @@ -409,12 +409,12 @@ void DNP3_TCP_Analyzer::DeliverStream(int len, const u_char* data, bool orig) try { if ( ! ProcessData(len, data, orig) ) - SetSkip(1); + SetSkip(true); } catch ( const binpac::Exception& e ) { - SetSkip(1); + SetSkip(true); throw; } } @@ -447,13 +447,12 @@ void DNP3_UDP_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, ui try { if ( ! ProcessData(len, data, orig) ) - SetSkip(1); + SetSkip(true); } catch ( const binpac::Exception& e ) { - SetSkip(1); + SetSkip(true); throw; } } - diff --git a/src/analyzer/protocol/dns/DNS.cc b/src/analyzer/protocol/dns/DNS.cc index 56276a7d55..8ad9d796ce 100644 --- a/src/analyzer/protocol/dns/DNS.cc +++ b/src/analyzer/protocol/dns/DNS.cc @@ -25,14 +25,14 @@ DNS_Interpreter::DNS_Interpreter(analyzer::Analyzer* arg_analyzer) first_message = true; } -int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) +void DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) { int hdr_len = sizeof(DNS_RawMsgHdr); if ( len < hdr_len ) { analyzer->Weird("DNS_truncated_len_lt_hdr_len"); - return 0; + return; } DNS_MsgInfo msg((DNS_RawMsgHdr*) data, is_query); @@ -62,7 +62,7 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) analyzer->ProtocolViolation("DNS_Conn_count_too_large"); analyzer->Weird("DNS_Conn_count_too_large"); EndMessage(&msg); - return 0; + return; } const u_char* msg_start = data; // needed for interpreting compression @@ -73,14 +73,14 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) if ( ! ParseQuestions(&msg, data, len, msg_start) ) { EndMessage(&msg); - return 0; + return; } if ( ! ParseAnswers(&msg, msg.ancount, DNS_ANSWER, data, len, msg_start) ) { EndMessage(&msg); - return 0; + return; } analyzer->ProtocolConfirmation(); @@ -101,7 +101,7 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) { // No point doing further work parsing the message. EndMessage(&msg); - return 1; + return; } msg.skip_event = skip_auth; @@ -109,14 +109,14 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) data, len, msg_start) ) { EndMessage(&msg); - return 0; + return; } if ( skip_addl ) { // No point doing further work parsing the message. EndMessage(&msg); - return 1; + return; } msg.skip_event = skip_addl; @@ -124,25 +124,22 @@ int DNS_Interpreter::ParseMessage(const u_char* data, int len, int is_query) data, len, msg_start) ) { EndMessage(&msg); - return 0; + return; } EndMessage(&msg); - return 1; } -int DNS_Interpreter::EndMessage(DNS_MsgInfo* msg) +void DNS_Interpreter::EndMessage(DNS_MsgInfo* msg) { if ( dns_end ) analyzer->EnqueueConnEvent(dns_end, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()} ); - - return 1; } -int DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* msg_start) { @@ -153,7 +150,7 @@ int DNS_Interpreter::ParseQuestions(DNS_MsgInfo* msg, return n == 0; } -int DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype, +bool DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype, const u_char*& data, int& len, const u_char* msg_start) { @@ -165,7 +162,7 @@ int DNS_Interpreter::ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType atype, return n == 0; } -int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* msg_start) { @@ -174,12 +171,12 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; if ( len < int(sizeof(short)) * 2 ) { analyzer->Weird("DNS_truncated_quest_too_short"); - return 0; + return false; } EventHandlerPtr dns_event = nullptr; @@ -198,7 +195,7 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, if ( dns_event && ! msg->skip_event ) { BroString* question_name = - new BroString(name, name_end - name, 1); + new BroString(name, name_end - name, true); SendReplyOrRejectEvent(msg, dns_event, data, len, question_name); } else @@ -208,10 +205,10 @@ int DNS_Interpreter::ParseQuestion(DNS_MsgInfo* msg, (void) ExtractShort(data, len); } - return 1; + return true; } -int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* msg_start) { @@ -221,19 +218,19 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; if ( len < int(sizeof(short)) * 2 ) { analyzer->Weird("DNS_truncated_ans_too_short"); - return 0; + return false; } // Note that the exact meaning of some of these fields will be // re-interpreted by other, more adventurous RR types. Unref(msg->query_name); - msg->query_name = new StringVal(new BroString(name, name_end - name, 1)); + msg->query_name = new StringVal(new BroString(name, name_end - name, true)); msg->atype = RR_Type(ExtractShort(data, len)); msg->aclass = ExtractShort(data, len); msg->ttl = ExtractLong(data, len); @@ -242,10 +239,10 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, if ( rdlength > len ) { analyzer->Weird("DNS_truncated_RR_rdlength_lt_len"); - return 0; + return false; } - int status; + bool status; switch ( msg->atype ) { case TYPE_A: status = ParseRR_A(msg, data, len, rdlength); @@ -301,7 +298,7 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, // The SRV RFC reused the value that was already being // used for this. // We aren't parsing this yet. - status = 1; + status = true; } else status = ParseRR_SRV(msg, data, len, rdlength, msg_start); @@ -348,7 +345,7 @@ int DNS_Interpreter::ParseAnswer(DNS_MsgInfo* msg, analyzer->Weird("DNS_RR_unknown_type", fmt("%d", msg->atype)); data += rdlength; len -= rdlength; - status = 1; + status = true; break; } @@ -384,12 +381,12 @@ u_char* DNS_Interpreter::ExtractName(const u_char*& data, int& len, return name; } -int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, +bool DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, u_char*& name, int& name_len, const u_char* msg_start) { if ( len <= 0 ) - return 0; + return false; const u_char* orig_data = data; int label_len = data[0]; @@ -398,11 +395,11 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, --len; if ( len <= 0 ) - return 0; + return false; if ( label_len == 0 ) // Found terminating label. - return 0; + return false; if ( (label_len & 0xc0) == 0xc0 ) { @@ -424,7 +421,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, // sometimes compression points to compression.) analyzer->Weird("DNS_label_forward_compress_offset"); - return 0; + return false; } // Recursively resolve name. @@ -437,7 +434,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, name_len -= name_end - name; name = name_end; - return 0; + return false; } if ( label_len > len ) @@ -445,7 +442,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, analyzer->Weird("DNS_label_len_gt_pkt"); data += len; // consume the rest of the packet len = 0; - return 0; + return false; } if ( label_len > 63 && @@ -453,13 +450,13 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, ntohs(analyzer->Conn()->RespPort()) != 137 ) { analyzer->Weird("DNS_label_too_long"); - return 0; + return false; } if ( label_len >= name_len ) { analyzer->Weird("DNS_label_len_gt_name_len"); - return 0; + return false; } memcpy(name, data, label_len); @@ -471,7 +468,7 @@ int DNS_Interpreter::ExtractLabel(const u_char*& data, int& len, data += label_len; len -= label_len; - return 1; + return true; } uint16_t DNS_Interpreter::ExtractShort(const u_char*& data, int& len) @@ -512,7 +509,7 @@ uint32_t DNS_Interpreter::ExtractLong(const u_char*& data, int& len) return val; } -int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -523,7 +520,7 @@ int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; if ( data - data_start != rdlength ) { @@ -556,13 +553,13 @@ int DNS_Interpreter::ParseRR_Name(DNS_MsgInfo* msg, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - make_intrusive(new BroString(name, name_end - name, 1)) + make_intrusive(new BroString(name, name_end - name, true)) ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -573,17 +570,17 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, u_char* mname_end = ExtractName(data, len, mname, mname_len, msg_start); if ( ! mname_end ) - return 0; + return false; u_char rname[513]; int rname_len = sizeof(rname) - 1; u_char* rname_end = ExtractName(data, len, rname, rname_len, msg_start); if ( ! rname_end ) - return 0; + return false; if ( len < 20 ) - return 0; + return false; uint32_t serial = ExtractLong(data, len); uint32_t refresh = ExtractLong(data, len); @@ -597,8 +594,8 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, if ( dns_SOA_reply && ! msg->skip_event ) { auto r = make_intrusive(dns_soa); - r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, 1))); - r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, 1))); + r->Assign(0, make_intrusive(new BroString(mname, mname_end - mname, true))); + r->Assign(1, make_intrusive(new BroString(rname, rname_end - rname, true))); r->Assign(2, val_mgr->GetCount(serial)); r->Assign(3, make_intrusive(double(refresh), Seconds)); r->Assign(4, make_intrusive(double(retry), Seconds)); @@ -613,10 +610,10 @@ int DNS_Interpreter::ParseRR_SOA(DNS_MsgInfo* msg, ); } - return 1; + return true; } -int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -629,7 +626,7 @@ int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; if ( data - data_start != rdlength ) analyzer->Weird("DNS_RR_length_mismatch"); @@ -639,23 +636,23 @@ int DNS_Interpreter::ParseRR_MX(DNS_MsgInfo* msg, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - make_intrusive(new BroString(name, name_end - name, 1)), + make_intrusive(new BroString(name, name_end - name, true)), IntrusivePtr{AdoptRef{}, val_mgr->GetCount(preference)} ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_NBS(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_NBS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { data += rdlength; len -= rdlength; - return 1; + return true; } -int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -670,7 +667,7 @@ int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; if ( data - data_start != rdlength ) analyzer->Weird("DNS_RR_length_mismatch"); @@ -680,16 +677,16 @@ int DNS_Interpreter::ParseRR_SRV(DNS_MsgInfo* msg, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - make_intrusive(new BroString(name, name_end - name, 1)), + make_intrusive(new BroString(name, name_end - name, true)), IntrusivePtr{AdoptRef{}, val_mgr->GetCount(priority)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(weight)}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(port)} ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -712,7 +709,7 @@ int DNS_Interpreter::ParseRR_EDNS(DNS_MsgInfo* msg, len -= rdlength; } - return 1; + return true; } void DNS_Interpreter::ExtractOctets(const u_char*& data, int& len, @@ -722,7 +719,7 @@ void DNS_Interpreter::ExtractOctets(const u_char*& data, int& len, dlen = min(len, static_cast(dlen)); if ( p ) - *p = new BroString(data, dlen, 0); + *p = new BroString(data, dlen, false); data += dlen; len -= dlen; @@ -732,14 +729,14 @@ BroString* DNS_Interpreter::ExtractStream(const u_char*& data, int& len, int l) { l = max(l, 0); int dlen = min(len, l); // Len in bytes of the algorithm use - auto rval = new BroString(data, dlen, 0); + auto rval = new BroString(data, dlen, false); data += dlen; len -= dlen; return rval; } -int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -751,7 +748,7 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, ExtractName(data, len, alg_name, alg_name_len, msg_start); if ( ! alg_name_end ) - return 0; + return false; uint32_t sign_time_sec = ExtractLong(data, len); unsigned int sign_time_msec = ExtractShort(data, len); @@ -766,7 +763,7 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, { TSIG_DATA tsig; tsig.alg_name = - new BroString(alg_name, alg_name_end - alg_name, 1); + new BroString(alg_name, alg_name_end - alg_name, true); tsig.sig = request_MAC; tsig.time_s = sign_time_sec; tsig.time_ms = sign_time_msec; @@ -781,10 +778,10 @@ int DNS_Interpreter::ParseRR_TSIG(DNS_MsgInfo* msg, ); } - return 1; + return true; } -int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -792,11 +789,11 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } if ( len < 18 ) - return 0; + return false; unsigned int type_covered = ExtractShort(data, len); // split the two bytes for algo and labels extraction @@ -816,7 +813,7 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; int sig_len = rdlength - ((data - data_start) + 18); DNSSEC_Algo dsa = DNSSEC_Algo(algo); @@ -872,7 +869,7 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, rrsig.sig_exp = sign_exp; rrsig.sig_incep = sign_incp; rrsig.key_tag = key_tag; - rrsig.signer_name = new BroString(name, name_end - name, 1); + rrsig.signer_name = new BroString(name, name_end - name, true); rrsig.signature = sign; analyzer->EnqueueConnEvent(dns_RRSIG, @@ -883,10 +880,10 @@ int DNS_Interpreter::ParseRR_RRSIG(DNS_MsgInfo* msg, ); } - return 1; + return true; } -int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -894,11 +891,11 @@ int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } if ( len < 4 ) - return 0; + return false; auto dflags = ExtractShort(data, len); // split the two bytes for protocol and algorithm extraction @@ -978,10 +975,10 @@ int DNS_Interpreter::ParseRR_DNSKEY(DNS_MsgInfo* msg, ); } - return 1; + return true; } -int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -989,7 +986,7 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } const u_char* data_start = data; @@ -998,7 +995,7 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, u_char* name_end = ExtractName(data, len, name, name_len, msg_start); if ( ! name_end ) - return 0; + return false; int typebitmaps_len = rdlength - (data - data_start); @@ -1026,14 +1023,14 @@ int DNS_Interpreter::ParseRR_NSEC(DNS_MsgInfo* msg, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, msg->BuildHdrVal()}, IntrusivePtr{AdoptRef{}, msg->BuildAnswerVal()}, - make_intrusive(new BroString(name, name_end - name, 1)), + make_intrusive(new BroString(name, name_end - name, true)), std::move(char_strings) ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -1041,11 +1038,11 @@ int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } if ( len < 6 ) - return 0; + return false; const u_char* data_start = data; uint32_t halgo_flags = ExtractShort(data, len); @@ -1118,10 +1115,10 @@ int DNS_Interpreter::ParseRR_NSEC3(DNS_MsgInfo* msg, else Unref(char_strings); - return 1; + return true; } -int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -1129,11 +1126,11 @@ int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } if ( len < 4 ) - return 0; + return false; unsigned int ds_key_tag = ExtractShort(data, len); // split the two bytes for algorithm and digest type extraction @@ -1176,16 +1173,16 @@ int DNS_Interpreter::ParseRR_DS(DNS_MsgInfo* msg, ); } - return 1; + return true; } -int DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength) { if ( rdlength != 4 ) { analyzer->Weird("DNS_RR_bad_length"); - return 0; + return false; } uint32_t addr = ExtractLong(data, len); @@ -1198,10 +1195,10 @@ int DNS_Interpreter::ParseRR_A(DNS_MsgInfo* msg, make_intrusive(htonl(addr)) ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength) { uint32_t addr[4]; @@ -1216,7 +1213,7 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, analyzer->Weird("DNS_AAAA_neg_length"); else analyzer->Weird("DNS_A6_neg_length"); - return 0; + return false; } } @@ -1234,25 +1231,25 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg, make_intrusive(addr) ); - return 1; + return true; } -int DNS_Interpreter::ParseRR_WKS(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_WKS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength) { data += rdlength; len -= rdlength; - return 1; + return true; } -int DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_HINFO(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength) { data += rdlength; len -= rdlength; - return 1; + return true; } static StringVal* extract_char_string(analyzer::Analyzer* analyzer, @@ -1283,7 +1280,7 @@ static StringVal* extract_char_string(analyzer::Analyzer* analyzer, return rval; } -int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -1291,7 +1288,7 @@ int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } auto char_strings = make_intrusive(string_vec); @@ -1311,7 +1308,7 @@ int DNS_Interpreter::ParseRR_TXT(DNS_MsgInfo* msg, return rdlength == 0; } -int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -1319,7 +1316,7 @@ int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } auto char_strings = make_intrusive(string_vec); @@ -1339,7 +1336,7 @@ int DNS_Interpreter::ParseRR_SPF(DNS_MsgInfo* msg, return rdlength == 0; } -int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, +bool DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start) { @@ -1347,7 +1344,7 @@ int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, { data += rdlength; len -= rdlength; - return 1; + return true; } unsigned int flags = ExtractShort(data, len); @@ -1357,13 +1354,13 @@ int DNS_Interpreter::ParseRR_CAA(DNS_MsgInfo* msg, if ( (int) tagLen >= rdlength ) { analyzer->Weird("DNS_CAA_char_str_past_rdlen"); - return 0; + return false; } - BroString* tag = new BroString(data, tagLen, 1); + BroString* tag = new BroString(data, tagLen, true); len -= tagLen; data += tagLen; rdlength -= tagLen; - BroString* value = new BroString(data, rdlength, 0); + BroString* value = new BroString(data, rdlength, false); len -= value->Len(); data += value->Len(); @@ -1703,7 +1700,6 @@ DNS_Analyzer::DNS_Analyzer(Connection* conn) { interp = new DNS_Interpreter(this); contents_dns_orig = contents_dns_resp = 0; - did_session_done = 0; if ( Conn()->ConnTransport() == TRANSPORT_TCP ) { @@ -1715,7 +1711,7 @@ DNS_Analyzer::DNS_Analyzer(Connection* conn) else { ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer, - network_time + dns_session_timeout, 1, + network_time + dns_session_timeout, true, TIMER_DNS_EXPIRE); } } @@ -1733,7 +1729,7 @@ void DNS_Analyzer::Done() { tcp::TCP_ApplicationAnalyzer::Done(); - if ( Conn()->ConnTransport() == TRANSPORT_UDP && ! did_session_done ) + if ( Conn()->ConnTransport() == TRANSPORT_UDP ) Event(udp_session_done); else interp->Timeout(); @@ -1743,12 +1739,12 @@ void DNS_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, uint64_t seq, const IP_Hdr* ip, int caplen) { tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen); - interp->ParseMessage(data, len, orig); + interp->ParseMessage(data, len, orig ? 1 : 0); } void DNS_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint, tcp::TCP_Endpoint* peer, - int gen_event) + bool gen_event) { tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event); @@ -1769,5 +1765,5 @@ void DNS_Analyzer::ExpireTimer(double t) } else ADD_ANALYZER_TIMER(&DNS_Analyzer::ExpireTimer, - t + dns_session_timeout, 1, TIMER_DNS_EXPIRE); + t + dns_session_timeout, true, TIMER_DNS_EXPIRE); } diff --git a/src/analyzer/protocol/dns/DNS.h b/src/analyzer/protocol/dns/DNS.h index a0fd2fa643..51c297bbf1 100644 --- a/src/analyzer/protocol/dns/DNS.h +++ b/src/analyzer/protocol/dns/DNS.h @@ -222,29 +222,29 @@ class DNS_Interpreter { public: explicit DNS_Interpreter(analyzer::Analyzer* analyzer); - int ParseMessage(const u_char* data, int len, int is_query); + void ParseMessage(const u_char* data, int len, int is_query); void Timeout() { } protected: - int EndMessage(DNS_MsgInfo* msg); + void EndMessage(DNS_MsgInfo* msg); - int ParseQuestions(DNS_MsgInfo* msg, + bool ParseQuestions(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* start); - int ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType answer_type, + bool ParseAnswers(DNS_MsgInfo* msg, int n, DNS_AnswerType answer_type, const u_char*& data, int& len, const u_char* start); - int ParseQuestion(DNS_MsgInfo* msg, + bool ParseQuestion(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* start); - int ParseAnswer(DNS_MsgInfo* msg, + bool ParseAnswer(DNS_MsgInfo* msg, const u_char*& data, int& len, const u_char* start); u_char* ExtractName(const u_char*& data, int& len, u_char* label, int label_len, const u_char* msg_start); - int ExtractLabel(const u_char*& data, int& len, + bool ExtractLabel(const u_char*& data, int& len, u_char*& label, int& label_len, const u_char* msg_start); @@ -254,57 +254,57 @@ protected: BroString* ExtractStream(const u_char*& data, int& len, int sig_len); - int ParseRR_Name(DNS_MsgInfo* msg, + bool ParseRR_Name(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_SOA(DNS_MsgInfo* msg, + bool ParseRR_SOA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_MX(DNS_MsgInfo* msg, + bool ParseRR_MX(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_NBS(DNS_MsgInfo* msg, + bool ParseRR_NBS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_SRV(DNS_MsgInfo* msg, + bool ParseRR_SRV(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_EDNS(DNS_MsgInfo* msg, + bool ParseRR_EDNS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_A(DNS_MsgInfo* msg, + bool ParseRR_A(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength); - int ParseRR_AAAA(DNS_MsgInfo* msg, + bool ParseRR_AAAA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength); - int ParseRR_WKS(DNS_MsgInfo* msg, + bool ParseRR_WKS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength); - int ParseRR_HINFO(DNS_MsgInfo* msg, + bool ParseRR_HINFO(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength); - int ParseRR_TXT(DNS_MsgInfo* msg, + bool ParseRR_TXT(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_SPF(DNS_MsgInfo* msg, + bool ParseRR_SPF(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_CAA(DNS_MsgInfo* msg, + bool ParseRR_CAA(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_TSIG(DNS_MsgInfo* msg, + bool ParseRR_TSIG(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_RRSIG(DNS_MsgInfo* msg, + bool ParseRR_RRSIG(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_DNSKEY(DNS_MsgInfo* msg, + bool ParseRR_DNSKEY(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_NSEC(DNS_MsgInfo* msg, + bool ParseRR_NSEC(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_NSEC3(DNS_MsgInfo* msg, + bool ParseRR_NSEC3(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); - int ParseRR_DS(DNS_MsgInfo* msg, + bool ParseRR_DS(DNS_MsgInfo* msg, const u_char*& data, int& len, int rdlength, const u_char* msg_start); void SendReplyOrRejectEvent(DNS_MsgInfo* msg, EventHandlerPtr event, @@ -357,7 +357,7 @@ public: void Init() override; void Done() override; void ConnectionClosed(tcp::TCP_Endpoint* endpoint, - tcp::TCP_Endpoint* peer, int gen_event) override; + tcp::TCP_Endpoint* peer, bool gen_event) override; void ExpireTimer(double t); static analyzer::Analyzer* Instantiate(Connection* conn) @@ -367,10 +367,6 @@ protected: DNS_Interpreter* interp; Contents_DNS* contents_dns_orig; Contents_DNS* contents_dns_resp; - int did_session_done; }; -// FIXME: Doesn't really fit into new analyzer structure. What to do? -int IsReuse(double t, const u_char* pkt); - -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/finger/Finger.cc b/src/analyzer/protocol/finger/Finger.cc index cbb1e94ce0..1beba6947d 100644 --- a/src/analyzer/protocol/finger/Finger.cc +++ b/src/analyzer/protocol/finger/Finger.cc @@ -75,7 +75,7 @@ void Finger_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig ); Conn()->Match(Rule::FINGER, (const u_char *) line, - end_of_line - line, true, true, 1, true); + end_of_line - line, true, true, true, true); did_deliver = 1; } diff --git a/src/analyzer/protocol/ftp/FTP.cc b/src/analyzer/protocol/ftp/FTP.cc index a9b658e06b..7957bb01be 100644 --- a/src/analyzer/protocol/ftp/FTP.cc +++ b/src/analyzer/protocol/ftp/FTP.cc @@ -111,7 +111,7 @@ void FTP_Analyzer::DeliverStream(int length, const u_char* data, bool orig) if ( rule_matcher ) Conn()->Match(Rule::FTP, (const u_char *) cmd, - end_of_line - cmd, true, true, 1, true); + end_of_line - cmd, true, true, true, true); } else { diff --git a/src/analyzer/protocol/ftp/functions.bif b/src/analyzer/protocol/ftp/functions.bif index 304c7674d5..d75f4bb899 100644 --- a/src/analyzer/protocol/ftp/functions.bif +++ b/src/analyzer/protocol/ftp/functions.bif @@ -41,7 +41,7 @@ static Val* parse_port(const char* line) { r->Assign(0, make_intrusive(uint32_t(0))); r->Assign(1, val_mgr->GetPort(0, TRANSPORT_TCP)); - r->Assign(2, val_mgr->GetBool(0)); + r->Assign(2, val_mgr->GetFalse()); } return r; @@ -218,4 +218,3 @@ function fmt_ftp_port%(a: addr, p: port%): string return val_mgr->GetEmptyString(); } %} - diff --git a/src/analyzer/protocol/gnutella/Gnutella.cc b/src/analyzer/protocol/gnutella/Gnutella.cc index abb1bb892e..e22a5ad755 100644 --- a/src/analyzer/protocol/gnutella/Gnutella.cc +++ b/src/analyzer/protocol/gnutella/Gnutella.cc @@ -85,13 +85,13 @@ void Gnutella_Analyzer::Done() } -int Gnutella_Analyzer::NextLine(const u_char* data, int len) +bool Gnutella_Analyzer::NextLine(const u_char* data, int len) { if ( ! ms ) - return 0; + return false; if ( Established() || ms->current_offset >= len ) - return 0; + return false; for ( ; ms->current_offset < len; ++ms->current_offset ) { @@ -102,20 +102,20 @@ int Gnutella_Analyzer::NextLine(const u_char* data, int len) { ms->got_CR = 0; ++ms->current_offset; - return 1; + return true; } else ms->buffer += data[ms->current_offset]; } - return 0; + return false; } -int Gnutella_Analyzer::IsHTTP(string header) +bool Gnutella_Analyzer::IsHTTP(string header) { if ( header.find(" HTTP/1.") == string::npos ) - return 0; + return false; if ( gnutella_http_notify ) EnqueueConnEvent(gnutella_http_notify, IntrusivePtr{AdoptRef{}, BuildConnVal()}); @@ -135,20 +135,20 @@ int Gnutella_Analyzer::IsHTTP(string header) Parent()->RemoveChildAnalyzer(this); } - return 1; + return true; } -int Gnutella_Analyzer::GnutellaOK(string header) +bool Gnutella_Analyzer::GnutellaOK(string header) { if ( strncmp("GNUTELLA", header.data(), 8) ) - return 0; + return false; int codepos = header.find(' ') + 1; if ( ! strncmp("200", header.data() + codepos, 3) ) - return 1; + return true; - return 0; + return false; } @@ -320,4 +320,3 @@ void Gnutella_Analyzer::DeliverStream(int len, const u_char* data, bool orig) else if ( gnutella_binary_msg ) DeliverMessages(len, data, orig); } - diff --git a/src/analyzer/protocol/gnutella/Gnutella.h b/src/analyzer/protocol/gnutella/Gnutella.h index 191156a168..e7f22ece6e 100644 --- a/src/analyzer/protocol/gnutella/Gnutella.h +++ b/src/analyzer/protocol/gnutella/Gnutella.h @@ -45,12 +45,12 @@ public: { return new Gnutella_Analyzer(conn); } private: - int NextLine(const u_char* data, int len); + bool NextLine(const u_char* data, int len); - int GnutellaOK(string header); - int IsHTTP(string header); + bool GnutellaOK(string header); + bool IsHTTP(string header); - int Established() const { return state == (ORIG_OK | RESP_OK); } + bool Established() const { return state == (ORIG_OK | RESP_OK); } void DeliverLines(int len, const u_char* data, bool orig); @@ -68,4 +68,4 @@ private: GnutellaMsgState* ms; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac index 3c9f43a4a0..9c7c369132 100644 --- a/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac +++ b/src/analyzer/protocol/gtpv1/gtpv1-analyzer.pac @@ -106,7 +106,7 @@ Val* BuildEndUserAddr(const InformationElement* ie) break; default: ev->Assign(3, make_intrusive( - new BroString((const u_char*) d, len, 0))); + new BroString((const u_char*) d, len, false))); break; } } @@ -117,7 +117,7 @@ Val* BuildEndUserAddr(const InformationElement* ie) Val* BuildAccessPointName(const InformationElement* ie) { BroString* bs = new BroString((const u_char*) ie->ap_name()->value().data(), - ie->ap_name()->value().length(), 0); + ie->ap_name()->value().length(), false); return new StringVal(bs); } @@ -125,7 +125,7 @@ Val* BuildProtoConfigOptions(const InformationElement* ie) { const u_char* d = (const u_char*) ie->proto_config_opts()->value().data(); int len = ie->proto_config_opts()->value().length(); - return new StringVal(new BroString(d, len, 0)); + return new StringVal(new BroString(d, len, false)); } Val* BuildGSN_Addr(const InformationElement* ie) @@ -142,7 +142,7 @@ Val* BuildGSN_Addr(const InformationElement* ie) ev->Assign(0, make_intrusive( IPAddr(IPv6, (const uint32*) d, IPAddr::Network))); else - ev->Assign(1, make_intrusive(new BroString((const u_char*) d, len, 0))); + ev->Assign(1, make_intrusive(new BroString((const u_char*) d, len, false))); return ev; } @@ -151,7 +151,7 @@ Val* BuildMSISDN(const InformationElement* ie) { const u_char* d = (const u_char*) ie->msisdn()->value().data(); int len = ie->msisdn()->value().length(); - return new StringVal(new BroString(d, len, 0)); + return new StringVal(new BroString(d, len, false)); } Val* BuildQoS_Profile(const InformationElement* ie) @@ -162,7 +162,7 @@ Val* BuildQoS_Profile(const InformationElement* ie) int len = ie->qos_profile()->data().length(); ev->Assign(0, val_mgr->GetCount(ie->qos_profile()->alloc_retention_priority())); - ev->Assign(1, make_intrusive(new BroString(d, len, 0))); + ev->Assign(1, make_intrusive(new BroString(d, len, false))); return ev; } @@ -171,21 +171,21 @@ Val* BuildTrafficFlowTemplate(const InformationElement* ie) { const uint8* d = ie->traffic_flow_template()->value().data(); int len = ie->traffic_flow_template()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, 0)); + return new StringVal(new BroString((const u_char*) d, len, false)); } Val* BuildTriggerID(const InformationElement* ie) { const uint8* d = ie->trigger_id()->value().data(); int len = ie->trigger_id()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, 0)); + return new StringVal(new BroString((const u_char*) d, len, false)); } Val* BuildOMC_ID(const InformationElement* ie) { const uint8* d = ie->omc_id()->value().data(); int len = ie->omc_id()->value().length(); - return new StringVal(new BroString((const u_char*) d, len, 0)); + return new StringVal(new BroString((const u_char*) d, len, false)); } Val* BuildPrivateExt(const InformationElement* ie) @@ -196,7 +196,7 @@ Val* BuildPrivateExt(const InformationElement* ie) int len = ie->private_ext()->value().length(); ev->Assign(0, val_mgr->GetCount(ie->private_ext()->id())); - ev->Assign(1, make_intrusive(new BroString((const u_char*) d, len, 0))); + ev->Assign(1, make_intrusive(new BroString((const u_char*) d, len, false))); return ev; } @@ -771,4 +771,3 @@ flow GTPv1_Flow(is_orig: bool) }; refine typeattr GTPv1_Header += &let { proc_gtpv1 = $context.flow.process_gtpv1(this); }; - diff --git a/src/analyzer/protocol/http/HTTP.cc b/src/analyzer/protocol/http/HTTP.cc index afae705756..e3fc68498d 100644 --- a/src/analyzer/protocol/http/HTTP.cc +++ b/src/analyzer/protocol/http/HTTP.cc @@ -78,7 +78,7 @@ void HTTP_Entity::EndOfData() MIME_Entity::EndOfData(); } -void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF) +void HTTP_Entity::Deliver(int len, const char* data, bool trailing_CRLF) { if ( DEBUG_http ) { @@ -142,7 +142,7 @@ void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF) SetPlainDelivery(0); chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF; } - DeliverBody(len, data, 0); + DeliverBody(len, data, false); break; case EXPECT_CHUNK_DATA_CRLF: @@ -159,7 +159,7 @@ void HTTP_Entity::Deliver(int len, const char* data, int trailing_CRLF) ASSERT(! trailing_CRLF); ASSERT(len <= expect_data_length); - DeliverBody(len, data, 0); + DeliverBody(len, data, false); expect_data_length -= len; if ( expect_data_length <= 0 ) @@ -184,7 +184,7 @@ private: HTTP_Entity* entity; }; -void HTTP_Entity::DeliverBody(int len, const char* data, int trailing_CRLF) +void HTTP_Entity::DeliverBody(int len, const char* data, bool trailing_CRLF) { if ( encoding == GZIP || encoding == DEFLATE ) { @@ -207,7 +207,7 @@ void HTTP_Entity::DeliverBody(int len, const char* data, int trailing_CRLF) DeliverBodyClear(len, data, trailing_CRLF); } -void HTTP_Entity::DeliverBodyClear(int len, const char* data, int trailing_CRLF) +void HTTP_Entity::DeliverBodyClear(int len, const char* data, bool trailing_CRLF) { bool new_data = (body_length == 0); @@ -233,7 +233,7 @@ void HTTP_Entity::DeliverBodyClear(int len, const char* data, int trailing_CRLF) // Returns 1 if the undelivered bytes are completely within the body, // otherwise returns 0. -int HTTP_Entity::Undelivered(int64_t len) +bool HTTP_Entity::Undelivered(int64_t len) { if ( DEBUG_http ) { @@ -244,7 +244,7 @@ int HTTP_Entity::Undelivered(int64_t len) // Don't propogate an entity (file) gap if we're still in the headers, // or the body length was declared to be zero. if ( (end_of_data && in_header) || body_length == 0 ) - return 0; + return false; if ( is_partial_content ) { @@ -273,10 +273,10 @@ int HTTP_Entity::Undelivered(int64_t len) if ( expect_data_length == 0 ) chunked_transfer_state = EXPECT_CHUNK_DATA_CRLF; - return 1; + return true; } else - return 0; + return false; } else if ( content_length >= 0 ) @@ -291,14 +291,14 @@ int HTTP_Entity::Undelivered(int64_t len) if ( expect_data_length <= 0 ) EndOfData(); - return 1; + return true; } else - return 0; + return false; } - return 0; + return false; } void HTTP_Entity::SubmitData(int len, const char* buf) @@ -613,7 +613,7 @@ HTTP_Message::~HTTP_Message() delete [] entity_data_buffer; } -Val* HTTP_Message::BuildMessageStat(const int interrupted, const char* msg) +Val* HTTP_Message::BuildMessageStat(bool interrupted, const char* msg) { RecordVal* stat = new RecordVal(http_message_stat); int field = 0; @@ -626,7 +626,7 @@ Val* HTTP_Message::BuildMessageStat(const int interrupted, const char* msg) return stat; } -void HTTP_Message::Done(const int interrupted, const char* detail) +void HTTP_Message::Done(bool interrupted, const char* detail) { if ( finished ) return; @@ -658,7 +658,7 @@ void HTTP_Message::Done(const int interrupted, const char* detail) MyHTTP_Analyzer()->HTTP_MessageDone(is_orig, this); } -int HTTP_Message::Undelivered(int64_t len) +bool HTTP_Message::Undelivered(int64_t len) { HTTP_Entity* e = current_entity ? current_entity : static_cast(top_level); @@ -666,10 +666,10 @@ int HTTP_Message::Undelivered(int64_t len) if ( e && e->Undelivered(len) ) { content_gap_length += len; - return 1; + return true; } - return 0; + return false; } void HTTP_Message::BeginEntity(mime::MIME_Entity* entity) @@ -766,17 +766,17 @@ void HTTP_Message::SubmitData(int len, const char* buf) { if ( http_entity_data ) MyHTTP_Analyzer()->HTTP_EntityData(is_orig, - new BroString(reinterpret_cast(buf), len, 0)); + new BroString(reinterpret_cast(buf), len, false)); } -int HTTP_Message::RequestBuffer(int* plen, char** pbuf) +bool HTTP_Message::RequestBuffer(int* plen, char** pbuf) { if ( ! entity_data_buffer ) entity_data_buffer = new char[http_entity_data_delivery_size]; *plen = http_entity_data_delivery_size; *pbuf = entity_data_buffer; - return 1; + return true; } void HTTP_Message::SubmitAllData() @@ -878,8 +878,8 @@ void HTTP_Analyzer::Done() tcp::TCP_ApplicationAnalyzer::Done(); - RequestMade(1, "message interrupted when connection done"); - ReplyMade(1, "message interrupted when connection done"); + RequestMade(true, "message interrupted when connection done"); + ReplyMade(true, "message interrupted when connection done"); delete request_message; request_message = 0; @@ -933,14 +933,14 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) if ( is_orig ) { if ( request_message ) - request_message->Deliver(len, line, 0); + request_message->Deliver(len, line, false); else Weird("unexpected_client_HTTP_data"); } else { if ( reply_message ) - reply_message->Deliver(len, line, 0); + reply_message->Deliver(len, line, false); else Weird("unexpected_server_HTTP_data"); } @@ -1004,7 +1004,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) break; case EXPECT_REQUEST_MESSAGE: - request_message->Deliver(len, line, 1); + request_message->Deliver(len, line, true); break; case EXPECT_REQUEST_TRAILER: @@ -1051,7 +1051,7 @@ void HTTP_Analyzer::DeliverStream(int len, const u_char* data, bool is_orig) break; case EXPECT_REPLY_MESSAGE: - reply_message->Deliver(len, line, 1); + reply_message->Deliver(len, line, true); if ( connect_request && len == 0 ) { @@ -1118,16 +1118,15 @@ void HTTP_Analyzer::Undelivered(uint64_t seq, int len, bool is_orig) // reply contains a body may depend on knowing the // request method - RequestMade(1, "message interrupted by a content gap"); - ReplyMade(1, "message interrupted by a content gap"); + RequestMade(true, "message interrupted by a content gap"); + ReplyMade(true, "message interrupted by a content gap"); - content_line->SetSkipDeliveries(1); - content_line->SetSkipDeliveries(1); + content_line->SetSkipDeliveries(true); } else { - ReplyMade(1, "message interrupted by a content gap"); - content_line->SetSkipDeliveries(1); + ReplyMade(true, "message interrupted by a content gap"); + content_line->SetSkipDeliveries(true); } } @@ -1138,34 +1137,34 @@ void HTTP_Analyzer::EndpointEOF(bool is_orig) // DEBUG_MSG("%.6f eof\n", network_time); if ( is_orig ) - RequestMade(0, "message ends as connection contents are completely delivered"); + RequestMade(false, "message ends as connection contents are completely delivered"); else - ReplyMade(0, "message ends as connection contents are completely delivered"); + ReplyMade(false, "message ends as connection contents are completely delivered"); } -void HTTP_Analyzer::ConnectionFinished(int half_finished) +void HTTP_Analyzer::ConnectionFinished(bool half_finished) { tcp::TCP_ApplicationAnalyzer::ConnectionFinished(half_finished); // DEBUG_MSG("%.6f connection finished\n", network_time); - RequestMade(1, "message ends as connection is finished"); - ReplyMade(1, "message ends as connection is finished"); + RequestMade(true, "message ends as connection is finished"); + ReplyMade(true, "message ends as connection is finished"); } void HTTP_Analyzer::ConnectionReset() { tcp::TCP_ApplicationAnalyzer::ConnectionReset(); - RequestMade(1, "message interrupted by RST"); - ReplyMade(1, "message interrupted by RST"); + RequestMade(true, "message interrupted by RST"); + ReplyMade(true, "message interrupted by RST"); } void HTTP_Analyzer::PacketWithRST() { tcp::TCP_ApplicationAnalyzer::PacketWithRST(); - RequestMade(1, "message interrupted by RST"); - ReplyMade(1, "message interrupted by RST"); + RequestMade(true, "message interrupted by RST"); + ReplyMade(true, "message interrupted by RST"); } void HTTP_Analyzer::GenStats() @@ -1278,7 +1277,7 @@ error: return 0; } -int HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) +bool HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) { const char* end_of_uri; const char* version_start; @@ -1335,7 +1334,7 @@ int HTTP_Analyzer::ParseRequest(const char* line, const char* end_of_line) unescaped_URI = new StringVal(unescape_URI((const u_char*) line, (const u_char*) end_of_uri, this)); - return 1; + return true; } // Only recognize [0-9][.][0-9]. @@ -1396,7 +1395,7 @@ StringVal* HTTP_Analyzer::TruncateURI(StringVal* uri) u_char* s = new u_char[truncate_http_URI + 4]; memcpy(s, str->Bytes(), truncate_http_URI); memcpy(s + truncate_http_URI, "...", 4); - return new StringVal(new BroString(1, s, truncate_http_URI+3)); + return new StringVal(new BroString(true, s, truncate_http_URI+3)); } else { @@ -1444,7 +1443,7 @@ void HTTP_Analyzer::HTTP_Reply() } } -void HTTP_Analyzer::RequestMade(const int interrupted, const char* msg) +void HTTP_Analyzer::RequestMade(bool interrupted, const char* msg) { if ( ! request_ongoing ) return; @@ -1470,7 +1469,7 @@ void HTTP_Analyzer::RequestMade(const int interrupted, const char* msg) request_state = EXPECT_REQUEST_LINE; } -void HTTP_Analyzer::ReplyMade(const int interrupted, const char* msg) +void HTTP_Analyzer::ReplyMade(bool interrupted, const char* msg) { if ( ! reply_ongoing ) return; @@ -1527,7 +1526,7 @@ void HTTP_Analyzer::RequestClash(Val* /* clash_val */) Weird("multiple_HTTP_request_elements"); // Flush out old values. - RequestMade(1, "request clash"); + RequestMade(true, "request clash"); } const BroString* HTTP_Analyzer::UnansweredRequestMethod() @@ -1626,7 +1625,7 @@ int HTTP_Analyzer::ExpectReplyMessageBody() return HTTP_BODY_EXPECTED; } -void HTTP_Analyzer::HTTP_Header(int is_orig, mime::MIME_Header* h) +void HTTP_Analyzer::HTTP_Header(bool is_orig, mime::MIME_Header* h) { // To be "liberal", we only look at "keep-alive" on the client // side, and if seen assume the connection to be persistent. @@ -1679,7 +1678,7 @@ void HTTP_Analyzer::HTTP_Header(int is_orig, mime::MIME_Header* h) } } -void HTTP_Analyzer::HTTP_EntityData(int is_orig, BroString* entity_data) +void HTTP_Analyzer::HTTP_EntityData(bool is_orig, BroString* entity_data) { if ( http_entity_data ) EnqueueConnEvent(http_entity_data, @@ -1693,12 +1692,12 @@ void HTTP_Analyzer::HTTP_EntityData(int is_orig, BroString* entity_data) } // Calls request/reply done -void HTTP_Analyzer::HTTP_MessageDone(int is_orig, HTTP_Message* /* message */) +void HTTP_Analyzer::HTTP_MessageDone(bool is_orig, HTTP_Message* /* message */) { if ( is_orig ) - RequestMade(0, "message ends normally"); + RequestMade(false, "message ends normally"); else - ReplyMade(0, "message ends normally"); + ReplyMade(false, "message ends normally"); } void HTTP_Analyzer::InitHTTPMessage(tcp::ContentLine_Analyzer* cl, HTTP_Message*& message, @@ -1717,7 +1716,7 @@ void HTTP_Analyzer::InitHTTPMessage(tcp::ContentLine_Analyzer* cl, HTTP_Message* init_header_length); } -void HTTP_Analyzer::SkipEntityData(int is_orig) +void HTTP_Analyzer::SkipEntityData(bool is_orig) { HTTP_Message* msg = is_orig ? request_message : reply_message; @@ -1725,14 +1724,14 @@ void HTTP_Analyzer::SkipEntityData(int is_orig) msg->SkipEntityData(); } -int analyzer::http::is_reserved_URI_char(unsigned char ch) +bool analyzer::http::is_reserved_URI_char(unsigned char ch) { // see RFC 3986 (definition of URI) return strchr(":/?#[]@!$&'()*+,;=", ch) != 0; } -int analyzer::http::is_unreserved_URI_char(unsigned char ch) +bool analyzer::http::is_unreserved_URI_char(unsigned char ch) { // see RFC 3986 (definition of URI) - return isalnum(ch) || strchr("-_.!~*\'()", ch) != 0; + return isalnum(ch) != 0 || strchr("-_.!~*\'()", ch) != 0; } void analyzer::http::escape_URI_char(unsigned char ch, unsigned char*& p) @@ -1838,5 +1837,5 @@ BroString* analyzer::http::unescape_URI(const u_char* line, const u_char* line_e URI_p[0] = 0; - return new BroString(1, decoded_URI, URI_p - decoded_URI); + return new BroString(true, decoded_URI, URI_p - decoded_URI); } diff --git a/src/analyzer/protocol/http/HTTP.h b/src/analyzer/protocol/http/HTTP.h index 09a266fba5..3eb0da80b1 100644 --- a/src/analyzer/protocol/http/HTTP.h +++ b/src/analyzer/protocol/http/HTTP.h @@ -38,8 +38,8 @@ public: } void EndOfData() override; - void Deliver(int len, const char* data, int trailing_CRLF) override; - int Undelivered(int64_t len); + void Deliver(int len, const char* data, bool trailing_CRLF) override; + bool Undelivered(int64_t len); int64_t BodyLength() const { return body_length; } int64_t HeaderLength() const { return header_length; } void SkipBody() { deliver_body = 0; } @@ -57,9 +57,9 @@ protected: int expect_body; int64_t body_length; int64_t header_length; - int deliver_body; enum { IDENTITY, GZIP, COMPRESS, DEFLATE } encoding; zip::ZIP_Analyzer* zip; + bool deliver_body; bool is_partial_content; uint64_t offset; int64_t instance_length; // total length indicated by content-range @@ -68,8 +68,8 @@ protected: MIME_Entity* NewChildEntity() override { return new HTTP_Entity(http_message, this, 1); } - void DeliverBody(int len, const char* data, int trailing_CRLF); - void DeliverBodyClear(int len, const char* data, int trailing_CRLF); + void DeliverBody(int len, const char* data, bool trailing_CRLF); + void DeliverBodyClear(int len, const char* data, bool trailing_CRLF); void SubmitData(int len, const char* buf) override; @@ -103,17 +103,17 @@ public: HTTP_Message(HTTP_Analyzer* analyzer, tcp::ContentLine_Analyzer* cl, bool is_orig, int expect_body, int64_t init_header_length); ~HTTP_Message() override; - void Done(const int interrupted, const char* msg); - void Done() override { Done(0, "message ends normally"); } + void Done(bool interrupted, const char* msg); + void Done() override { Done(false, "message ends normally"); } - int Undelivered(int64_t len); + bool Undelivered(int64_t len); void BeginEntity(mime::MIME_Entity* /* entity */) override; void EndEntity(mime::MIME_Entity* entity) override; void SubmitHeader(mime::MIME_Header* h) override; void SubmitAllHeaders(mime::MIME_HeaderList& /* hlist */) override; void SubmitData(int len, const char* buf) override; - int RequestBuffer(int* plen, char** pbuf) override; + bool RequestBuffer(int* plen, char** pbuf) override; void SubmitAllData(); void SubmitEvent(int event_type, const char* detail) override; @@ -145,7 +145,7 @@ protected: HTTP_Entity* current_entity; - Val* BuildMessageStat(const int interrupted, const char* msg); + Val* BuildMessageStat(bool interrupted, const char* msg); }; class HTTP_Analyzer : public tcp::TCP_ApplicationAnalyzer { @@ -153,15 +153,15 @@ public: HTTP_Analyzer(Connection* conn); ~HTTP_Analyzer() override; - void HTTP_Header(int is_orig, mime::MIME_Header* h); - void HTTP_EntityData(int is_orig, BroString* entity_data); - void HTTP_MessageDone(int is_orig, HTTP_Message* message); + void HTTP_Header(bool is_orig, mime::MIME_Header* h); + void HTTP_EntityData(bool is_orig, BroString* entity_data); + void HTTP_MessageDone(bool is_orig, HTTP_Message* message); void HTTP_Event(const char* category, const char* detail); void HTTP_Event(const char* category, StringVal *detail); - void SkipEntityData(int is_orig); + void SkipEntityData(bool is_orig); - int IsConnectionClose() { return connection_close; } + bool IsConnectionClose() { return connection_close; } int HTTP_ReplyCode() const { return reply_code; }; // Overriden from Analyzer. @@ -171,7 +171,7 @@ public: // Overriden from tcp::TCP_ApplicationAnalyzer void EndpointEOF(bool is_orig) override; - void ConnectionFinished(int half_finished) override; + void ConnectionFinished(bool half_finished) override; void ConnectionReset() override; void PacketWithRST() override; @@ -219,18 +219,18 @@ protected: const char* PrefixWordMatch(const char* line, const char* end_of_line, const char* prefix); - int ParseRequest(const char* line, const char* end_of_line); + bool ParseRequest(const char* line, const char* end_of_line); HTTP_VersionNumber HTTP_Version(int len, const char* data); void SetVersion(HTTP_VersionNumber* version, HTTP_VersionNumber new_version); - int RequestExpected() const { return num_requests == 0 || keep_alive; } + bool RequestExpected() const { return num_requests == 0 || keep_alive; } void HTTP_Request(); void HTTP_Reply(); - void RequestMade(const int interrupted, const char* msg); - void ReplyMade(const int interrupted, const char* msg); + void RequestMade(bool interrupted, const char* msg); + void ReplyMade(bool interrupted, const char* msg); void RequestClash(Val* clash_val); const BroString* UnansweredRequestMethod(); @@ -279,10 +279,10 @@ protected: HTTP_Message* reply_message; }; -extern int is_reserved_URI_char(unsigned char ch); -extern int is_unreserved_URI_char(unsigned char ch); +extern bool is_reserved_URI_char(unsigned char ch); +extern bool is_unreserved_URI_char(unsigned char ch); extern void escape_URI_char(unsigned char ch, unsigned char*& p); extern BroString* unescape_URI(const u_char* line, const u_char* line_end, analyzer::Analyzer* analyzer); -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/icmp/ICMP.cc b/src/analyzer/protocol/icmp/ICMP.cc index 1a3cb6ad34..59e8d93909 100644 --- a/src/analyzer/protocol/icmp/ICMP.cc +++ b/src/analyzer/protocol/icmp/ICMP.cc @@ -209,7 +209,7 @@ void ICMP_Analyzer::ICMP_Sent(const struct icmp* icmpp, int len, int caplen, if ( icmp_sent_payload ) { - BroString* payload = new BroString(data, min(len, caplen), 0); + BroString* payload = new BroString(data, min(len, caplen), false); EnqueueConnEvent(icmp_sent_payload, IntrusivePtr{AdoptRef{}, BuildConnVal()}, @@ -424,7 +424,7 @@ RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) iprec->Assign(3, val_mgr->GetCount(frag_offset)); iprec->Assign(4, val_mgr->GetBool(bad_hdr_len)); // bad_checksum is always false since IPv6 layer doesn't have a checksum. - iprec->Assign(5, val_mgr->GetBool(0)); + iprec->Assign(5, val_mgr->GetFalse()); iprec->Assign(6, val_mgr->GetBool(MF)); iprec->Assign(7, val_mgr->GetBool(DF)); @@ -433,7 +433,7 @@ RecordVal* ICMP_Analyzer::ExtractICMP6Context(int len, const u_char*& data) bool ICMP_Analyzer::IsReuse(double /* t */, const u_char* /* pkt */) { - return 0; + return false; } void ICMP_Analyzer::Describe(ODesc* d) const @@ -460,14 +460,14 @@ void ICMP_Analyzer::UpdateConnVal(RecordVal *conn_val) RecordVal *orig_endp = conn_val->Lookup("orig")->AsRecordVal(); RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); - UpdateEndpointVal(orig_endp, 1); - UpdateEndpointVal(resp_endp, 0); + UpdateEndpointVal(orig_endp, true); + UpdateEndpointVal(resp_endp, false); // Call children's UpdateConnVal Analyzer::UpdateConnVal(conn_val); } -void ICMP_Analyzer::UpdateEndpointVal(RecordVal* endp, int is_orig) +void ICMP_Analyzer::UpdateEndpointVal(RecordVal* endp, bool is_orig) { Conn()->EnableStatusUpdateTimer(); @@ -512,7 +512,7 @@ void ICMP_Analyzer::Echo(double t, const struct icmp* icmpp, int len, int iid = ntohs(icmpp->icmp_hun.ih_idseq.icd_id); int iseq = ntohs(icmpp->icmp_hun.ih_idseq.icd_seq); - BroString* payload = new BroString(data, caplen, 0); + BroString* payload = new BroString(data, caplen, false); EnqueueConnEvent(f, IntrusivePtr{AdoptRef{}, BuildConnVal()}, @@ -771,7 +771,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) { if ( caplen >= length ) { - BroString* link_addr = new BroString(data, length, 0); + BroString* link_addr = new BroString(data, length, false); rv->Assign(2, make_intrusive(link_addr)); } else @@ -841,8 +841,7 @@ VectorVal* ICMP_Analyzer::BuildNDOptionsVal(int caplen, const u_char* data) if ( set_payload_field ) { - BroString* payload = - new BroString(data, min((int)length, caplen), 0); + BroString* payload = new BroString(data, min((int)length, caplen), false); rv->Assign(6, make_intrusive(payload)); } diff --git a/src/analyzer/protocol/icmp/ICMP.h b/src/analyzer/protocol/icmp/ICMP.h index 7106f53dd9..baf1405e4e 100644 --- a/src/analyzer/protocol/icmp/ICMP.h +++ b/src/analyzer/protocol/icmp/ICMP.h @@ -84,7 +84,7 @@ protected: RuleMatcherState matcher_state; private: - void UpdateEndpointVal(RecordVal* endp, int is_orig); + void UpdateEndpointVal(RecordVal* endp, bool is_orig); }; // Returns the counterpart type to the given type (e.g., the counterpart @@ -92,4 +92,4 @@ private: extern int ICMP4_counterpart(int icmp_type, int icmp_code, bool& is_one_way); extern int ICMP6_counterpart(int icmp_type, int icmp_code, bool& is_one_way); -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/ident/Ident.cc b/src/analyzer/protocol/ident/Ident.cc index eb9a7d71df..5417492f58 100644 --- a/src/analyzer/protocol/ident/Ident.cc +++ b/src/analyzer/protocol/ident/Ident.cc @@ -174,7 +174,7 @@ void Ident_Analyzer::DeliverStream(int length, const u_char* data, bool is_orig) BroString* sys_type_s = new BroString((const u_char*) sys_type, - sys_end - sys_type + 1, 1); + sys_end - sys_type + 1, true); line = skip_whitespace(colon + 1, end_of_line); diff --git a/src/analyzer/protocol/login/Login.cc b/src/analyzer/protocol/login/Login.cc index 2b34fa5f48..39767ca420 100644 --- a/src/analyzer/protocol/login/Login.cc +++ b/src/analyzer/protocol/login/Login.cc @@ -40,7 +40,7 @@ Login_Analyzer::Login_Analyzer(const char* name, Connection* conn) user_text_last = MAX_USER_TEXT - 1; num_user_text = 0; client_name = username = 0; - saw_ploy = is_VMS = 0; + saw_ploy = is_VMS = false; if ( ! re_skip_authentication ) { @@ -136,7 +136,7 @@ void Login_Analyzer::NewLine(bool orig, char* line) else if ( ! saw_ploy && IsSuccessMsg(line) ) { - LoginEvent(login_success, line, 1); + LoginEvent(login_success, line, true); state = LOGIN_STATE_LOGGED_IN; } } @@ -192,7 +192,7 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line) Confused("no_login_prompt", line); const char* prompt = IsLoginPrompt(line); - int is_timeout = IsTimeout(line); + bool is_timeout = IsTimeout(line); if ( prompt && ! IsSuccessMsg(line) && ! is_timeout ) { is_VMS = strstr(line, "Username:") != 0; @@ -255,9 +255,9 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line) if ( IsDirectLoginPrompt(line) ) { - LoginEvent(login_success, line, 1); + LoginEvent(login_success, line, true); state = LOGIN_STATE_LOGGED_IN; - SetSkip(1); + SetSkip(true); return; } } @@ -293,7 +293,7 @@ void Login_Analyzer::AuthenticationDialog(bool orig, char* line) EnqueueConnEvent(authentication_skipped, IntrusivePtr{AdoptRef{}, BuildConnVal()}); state = LOGIN_STATE_SKIP; - SetSkip(1); + SetSkip(true); } else if ( IsSuccessMsg(line) || @@ -359,13 +359,13 @@ void Login_Analyzer::EndpointEOF(bool orig) if ( state == LOGIN_STATE_AUTHENTICATE && HaveTypeahead() ) { - LoginEvent(login_success, "", 1); + LoginEvent(login_success, "", true); state = LOGIN_STATE_LOGGED_IN; } } void Login_Analyzer::LoginEvent(EventHandlerPtr f, const char* line, - int no_user_okay) + bool no_user_okay) { if ( ! f ) return; @@ -484,20 +484,20 @@ void Login_Analyzer::ConfusionText(const char* line) ); } -int Login_Analyzer::IsPloy(const char* line) +bool Login_Analyzer::IsPloy(const char* line) { if ( IsLoginPrompt(line) || IsFailureMsg(line) || IsSuccessMsg(line) || IsSkipAuthentication(line) ) { - saw_ploy = 1; + saw_ploy = true; Confused("possible_login_ploy", line); - return 1; + return true; } else - return 0; + return false; } -int Login_Analyzer::IsSkipAuthentication(const char* line) const +bool Login_Analyzer::IsSkipAuthentication(const char* line) const { return re_skip_authentication->MatchAnywhere(line); } @@ -512,28 +512,28 @@ const char* Login_Analyzer::IsLoginPrompt(const char* line) const return &line[prompt_match]; } -int Login_Analyzer::IsDirectLoginPrompt(const char* line) const +bool Login_Analyzer::IsDirectLoginPrompt(const char* line) const { return re_direct_login_prompts->MatchAnywhere(line); } -int Login_Analyzer::IsFailureMsg(const char* line) const +bool Login_Analyzer::IsFailureMsg(const char* line) const { return re_login_failure_msgs->MatchAnywhere(line) && ! re_login_non_failure_msgs->MatchAnywhere(line); } -int Login_Analyzer::IsSuccessMsg(const char* line) const +bool Login_Analyzer::IsSuccessMsg(const char* line) const { return re_login_success_msgs->MatchAnywhere(line); } -int Login_Analyzer::IsTimeout(const char* line) const +bool Login_Analyzer::IsTimeout(const char* line) const { return re_login_timeouts->MatchAnywhere(line); } -int Login_Analyzer::IsEmpty(const char* line) const +bool Login_Analyzer::IsEmpty(const char* line) const { if ( ! line ) return true; @@ -591,12 +591,12 @@ Val* Login_Analyzer::PopUserTextVal() char* s = PopUserText(); if ( s ) - return new StringVal(new BroString(1, byte_vec(s), strlen(s))); + return new StringVal(new BroString(true, byte_vec(s), strlen(s))); else return val_mgr->GetEmptyString(); } -int Login_Analyzer::MatchesTypeahead(const char* line) const +bool Login_Analyzer::MatchesTypeahead(const char* line) const { for ( int i = user_text_first, n = 0; n < num_user_text; ++i, ++n ) { @@ -604,10 +604,10 @@ int Login_Analyzer::MatchesTypeahead(const char* line) const i = 0; if ( streq(user_text[i], line) ) - return 1; + return true; } - return 0; + return false; } void Login_Analyzer::FlushEmptyTypeahead() diff --git a/src/analyzer/protocol/login/Login.h b/src/analyzer/protocol/login/Login.h index 59602d9148..6398725ec0 100644 --- a/src/analyzer/protocol/login/Login.h +++ b/src/analyzer/protocol/login/Login.h @@ -38,28 +38,28 @@ protected: void NewLine(bool orig, char* line); void AuthenticationDialog(bool orig, char* line); - void LoginEvent(EventHandlerPtr f, const char* line, int no_user_okay=0); + void LoginEvent(EventHandlerPtr f, const char* line, bool no_user_okay=false); const char* GetUsername(const char* line) const; void LineEvent(EventHandlerPtr f, const char* line); void Confused(const char* msg, const char* addl); void ConfusionText(const char* line); - int IsPloy(const char* line); - int IsSkipAuthentication(const char* line) const; + bool IsPloy(const char* line); + bool IsSkipAuthentication(const char* line) const; const char* IsLoginPrompt(const char* line) const; // nil if not - int IsDirectLoginPrompt(const char* line) const; - int IsFailureMsg(const char* line) const; - int IsSuccessMsg(const char* line) const; - int IsTimeout(const char* line) const; - int IsEmpty(const char* line) const; + bool IsDirectLoginPrompt(const char* line) const; + bool IsFailureMsg(const char* line) const; + bool IsSuccessMsg(const char* line) const; + bool IsTimeout(const char* line) const; + bool IsEmpty(const char* line) const; void AddUserText(const char* line); // complains on overflow char* PeekUserText(); // internal warning on underflow char* PopUserText(); // internal warning on underflow Val* PopUserTextVal(); - int MatchesTypeahead(const char* line) const; - int HaveTypeahead() const { return num_user_text > 0; } + bool MatchesTypeahead(const char* line) const; + bool HaveTypeahead() const { return num_user_text > 0; } void FlushEmptyTypeahead(); // If we have more user text than this unprocessed, we complain about @@ -79,8 +79,8 @@ protected: int login_prompt_line; int failure_line; - int is_VMS; - int saw_ploy; + bool is_VMS; + bool saw_ploy; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/login/NVT.cc b/src/analyzer/protocol/login/NVT.cc index 09d866fe3b..89295e1ac2 100644 --- a/src/analyzer/protocol/login/NVT.cc +++ b/src/analyzer/protocol/login/NVT.cc @@ -58,7 +58,7 @@ void TelnetOption::RecvOption(unsigned int type) peer->SetWill(); if ( SaidDo() ) - peer->SetActive(1); + peer->SetActive(true); break; case TELNET_OPT_WONT: @@ -68,7 +68,7 @@ void TelnetOption::RecvOption(unsigned int type) peer->SetWont(); if ( SaidDont() ) - peer->SetActive(0); + peer->SetActive(false); break; case TELNET_OPT_DO: @@ -78,7 +78,7 @@ void TelnetOption::RecvOption(unsigned int type) peer->SetDo(); if ( SaidWill() ) - SetActive(1); + SetActive(true); break; case TELNET_OPT_DONT: @@ -88,7 +88,7 @@ void TelnetOption::RecvOption(unsigned int type) peer->SetDont(); if ( SaidWont() ) - SetActive(0); + SetActive(false); break; default: @@ -102,7 +102,7 @@ void TelnetOption::RecvSubOption(u_char* /* data */, int /* len */) { } -void TelnetOption::SetActive(int is_active) +void TelnetOption::SetActive(bool is_active) { active = is_active; } @@ -366,7 +366,7 @@ char* TelnetEnvironmentOption::ExtractEnv(u_char*& data, int& len, int& code) return env; } -void TelnetBinaryOption::SetActive(int is_active) +void TelnetBinaryOption::SetActive(bool is_active) { endp->SetBinaryMode(is_active); active = is_active; @@ -381,10 +381,7 @@ void TelnetBinaryOption::InconsistentOption(unsigned int /* type */) NVT_Analyzer::NVT_Analyzer(Connection* conn, bool orig) - : tcp::ContentLine_Analyzer("NVT", conn, orig), - peer(), pending_IAC(), IAC_pos(), is_suboption(), last_was_IAC(), - binary_mode(), encrypting_mode(), authentication_has_been_accepted(), - auth_name(), options(), num_options() + : tcp::ContentLine_Analyzer("NVT", conn, orig), options() { } @@ -443,13 +440,13 @@ TelnetOption* NVT_Analyzer::FindPeerOption(unsigned int code) void NVT_Analyzer::AuthenticationAccepted() { - authentication_has_been_accepted = 1; + authentication_has_been_accepted = true; Event(authentication_accepted, PeerAuthName()); } void NVT_Analyzer::AuthenticationRejected() { - authentication_has_been_accepted = 0; + authentication_has_been_accepted = false; Event(authentication_rejected, PeerAuthName()); } @@ -464,7 +461,7 @@ void NVT_Analyzer::SetTerminal(const u_char* terminal, int len) if ( login_terminal ) EnqueueConnEvent(login_terminal, IntrusivePtr{AdoptRef{}, BuildConnVal()}, - make_intrusive(new BroString(terminal, len, 0)) + make_intrusive(new BroString(terminal, len, false)) ); } @@ -554,9 +551,9 @@ void NVT_Analyzer::DoDeliver(int len, const u_char* data) break; case TELNET_IAC: - pending_IAC = 1; + pending_IAC = true; IAC_pos = offset; - is_suboption = 0; + is_suboption = false; buf[offset++] = c; ScanOption(seq, len - 1, data + 1); return; @@ -590,14 +587,14 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) { // An escaped 255, throw away the second // instance and drop the IAC state. - pending_IAC = 0; + pending_IAC = false; last_char = code; } else if ( code == TELNET_OPT_SB ) { - is_suboption = 1; - last_was_IAC = 0; + is_suboption = true; + last_was_IAC = false; if ( offset >= buf_len ) InitBuffer(buf_len * 2); @@ -607,7 +604,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) else if ( IS_3_BYTE_OPTION(code) ) { - is_suboption = 0; + is_suboption = false; if ( offset >= buf_len ) InitBuffer(buf_len * 2); @@ -622,7 +619,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) // Throw it and the IAC away. --offset; - pending_IAC = 0; + pending_IAC = false; } // Recurse to munch on the remainder. @@ -637,7 +634,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) // Delete the option. offset -= 2; // code + IAC - pending_IAC = 0; + pending_IAC = false; DeliverStream(len - 1, data + 1, IsOrig()); return; @@ -653,7 +650,7 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) if ( last_was_IAC ) { - last_was_IAC = 0; + last_was_IAC = false; if ( code == TELNET_IAC ) { @@ -676,14 +673,14 @@ void NVT_Analyzer::ScanOption(int seq, int len, const u_char* data) // Delete suboption. offset = IAC_pos; - pending_IAC = is_suboption = 0; + pending_IAC = is_suboption = false; if ( code == TELNET_OPT_SE ) DeliverStream(len - 1, data + 1, IsOrig()); else { // Munch on the new (broken) option. - pending_IAC = 1; + pending_IAC = true; IAC_pos = offset; buf[offset++] = TELNET_IAC; DeliverStream(len, data, IsOrig()); @@ -726,4 +723,3 @@ void NVT_Analyzer::BadOptionTermination(unsigned int /* code */) { Event(bad_option_termination); } - diff --git a/src/analyzer/protocol/login/NVT.h b/src/analyzer/protocol/login/NVT.h index b055ede6be..2320d38fc3 100644 --- a/src/analyzer/protocol/login/NVT.h +++ b/src/analyzer/protocol/login/NVT.h @@ -28,12 +28,12 @@ public: unsigned int Code() const { return code; } - int IsActive() const { return active; } + bool IsActive() const { return active; } - int SaidWill() const { return flags & OPT_SAID_WILL; } - int SaidWont() const { return flags & OPT_SAID_WONT; } - int SaidDo() const { return flags & OPT_SAID_DO; } - int SaidDont() const { return flags & OPT_SAID_DONT; } + bool SaidWill() const { return flags & OPT_SAID_WILL; } + bool SaidWont() const { return flags & OPT_SAID_WONT; } + bool SaidDo() const { return flags & OPT_SAID_DO; } + bool SaidDont() const { return flags & OPT_SAID_DONT; } void SetWill() { flags |= OPT_SAID_WILL; } void SetWont() { flags |= OPT_SAID_WONT; } @@ -43,7 +43,7 @@ public: void RecvOption(unsigned int type); virtual void RecvSubOption(u_char* data, int len); - virtual void SetActive(int is_active); + virtual void SetActive(bool is_active); const NVT_Analyzer* Endpoint() const { return endp; } @@ -116,7 +116,7 @@ public: : TelnetOption(arg_endp, TELNET_OPTION_BINARY) { } - void SetActive(int is_active) override; + void SetActive(bool is_active) override; protected: void InconsistentOption(unsigned int type) override; @@ -154,19 +154,20 @@ protected: virtual void BadOptionTermination(unsigned int code); const char* PeerAuthName() const; - NVT_Analyzer* peer; + NVT_Analyzer* peer = nullptr; - int pending_IAC; // true if we're working on an option/IAC - int IAC_pos; // where the IAC was seen - int is_suboption; // true if current option is suboption - int last_was_IAC; // for scanning suboptions + int IAC_pos = 0; // where the IAC was seen + bool pending_IAC = false; // true if we're working on an option/IAC + bool is_suboption = false; // true if current option is suboption + bool last_was_IAC = false; // for scanning suboptions + bool authentication_has_been_accepted = false; // if true, we accepted peer's authentication - int binary_mode, encrypting_mode; - int authentication_has_been_accepted; // if true, we accepted peer's authentication - char* auth_name; + int binary_mode = 0; + int encrypting_mode = 0; + char* auth_name = nullptr; TelnetOption* options[NUM_TELNET_OPTIONS]; - int num_options; + int num_options = 0; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/login/functions.bif b/src/analyzer/protocol/login/functions.bif index 2872a5aa02..99a4cac6ff 100644 --- a/src/analyzer/protocol/login/functions.bif +++ b/src/analyzer/protocol/login/functions.bif @@ -28,11 +28,11 @@ function get_login_state%(cid: conn_id%): count %{ Connection* c = sessions->FindConnection(cid); if ( ! c ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); analyzer::Analyzer* la = c->FindAnalyzer("Login"); if ( ! la ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); return val_mgr->GetCount(int(static_cast(la)->LoginState())); %} @@ -52,12 +52,12 @@ function set_login_state%(cid: conn_id, new_state: count%): bool %{ Connection* c = sessions->FindConnection(cid); if ( ! c ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); analyzer::Analyzer* la = c->FindAnalyzer("Login"); if ( ! la ) - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); static_cast(la)->SetLoginState(analyzer::login::login_state(new_state)); - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} diff --git a/src/analyzer/protocol/mime/MIME.cc b/src/analyzer/protocol/mime/MIME.cc index 0a4a901d90..ea689733de 100644 --- a/src/analyzer/protocol/mime/MIME.cc +++ b/src/analyzer/protocol/mime/MIME.cc @@ -98,12 +98,12 @@ static const char* MIMEContentEncodingName[] = { 0, }; -int is_null_data_chunk(data_chunk_t b) +bool is_null_data_chunk(data_chunk_t b) { return b.data == 0; } -int is_lws(char ch) +bool is_lws(char ch) { return ch == 9 || ch == 32; } @@ -250,7 +250,7 @@ int MIME_get_field_name(int len, const char* data, data_chunk_t* name) } // See RFC 2045, page 12. -int MIME_is_tspecial (char ch, bool is_boundary = false) +static bool MIME_is_tspecial (char ch, bool is_boundary = false) { if ( is_boundary ) return ch == '"'; @@ -260,12 +260,12 @@ int MIME_is_tspecial (char ch, bool is_boundary = false) ch == '/' || ch == '[' || ch == ']' || ch == '?' || ch == '='; } -int MIME_is_field_name_char (char ch) +bool MIME_is_field_name_char (char ch) { return ch >= 33 && ch <= 126 && ch != ':'; } -int MIME_is_token_char (char ch, bool is_boundary = false) +static bool MIME_is_token_char (char ch, bool is_boundary = false) { return ch >= 33 && ch <= 126 && ! MIME_is_tspecial(ch, is_boundary); } @@ -399,7 +399,7 @@ int MIME_get_value(int len, const char* data, BroString*& buf, bool is_boundary) if ( end < 0 ) return -1; - buf = new BroString((const u_char*)str.data, str.length, 1); + buf = new BroString((const u_char*)str.data, str.length, true); return offset + end; } } @@ -427,7 +427,7 @@ BroString* MIME_decode_quoted_pairs(data_chunk_t buf) dest[j++] = data[i]; dest[j] = 0; - return new BroString(1, (byte_vec) dest, j); + return new BroString(true, (byte_vec) dest, j); } @@ -448,12 +448,12 @@ MIME_Multiline::~MIME_Multiline() void MIME_Multiline::append(int len, const char* data) { - buffer.push_back(new BroString((const u_char*) data, len, 1)); + buffer.push_back(new BroString((const u_char*) data, len, true)); } BroString* MIME_Multiline::get_concatenated_line() { - if ( buffer.size() == 0 ) + if ( buffer.empty() ) return 0; delete line; @@ -593,7 +593,7 @@ MIME_Entity::~MIME_Entity() delete base64_decoder; } -void MIME_Entity::Deliver(int len, const char* data, int trailing_CRLF) +void MIME_Entity::Deliver(int len, const char* data, bool trailing_CRLF) { if ( in_header ) { @@ -669,7 +669,7 @@ void MIME_Entity::EndOfData() message->EndEntity (this); } -void MIME_Entity::NewDataLine(int len, const char* data, int trailing_CRLF) +void MIME_Entity::NewDataLine(int len, const char* data, bool trailing_CRLF) { if ( content_type == CONTENT_TYPE_MULTIPART ) { @@ -786,7 +786,7 @@ void MIME_Entity::ParseMIMEHeader(MIME_Header* h) } } -int MIME_Entity::ParseContentTypeField(MIME_Header* h) +bool MIME_Entity::ParseContentTypeField(MIME_Header* h) { data_chunk_t val = h->get_value(); int len = val.length; @@ -799,7 +799,7 @@ int MIME_Entity::ParseContentTypeField(MIME_Header* h) if ( offset < 0 ) { IllegalFormat("media type/subtype not found in content type"); - return 0; + return false; } data += offset; len -= offset; @@ -822,10 +822,10 @@ int MIME_Entity::ParseContentTypeField(MIME_Header* h) content_subtype = CONTENT_SUBTYPE_OTHER; } - return 1; + return true; } -int MIME_Entity::ParseContentEncodingField(MIME_Header* h) +bool MIME_Entity::ParseContentEncodingField(MIME_Header* h) { data_chunk_t enc; @@ -833,10 +833,10 @@ int MIME_Entity::ParseContentEncodingField(MIME_Header* h) if ( is_null_data_chunk(enc) ) { IllegalFormat("encoding type not found in content encoding"); - return 0; + return false; } - content_encoding_str = new BroString((const u_char*)enc.data, enc.length, 1); + content_encoding_str = new BroString((const u_char*)enc.data, enc.length, true); ParseContentEncoding(enc); if ( need_to_parse_parameters ) @@ -846,14 +846,14 @@ int MIME_Entity::ParseContentEncodingField(MIME_Header* h) ParseFieldParameters(val.length, val.data); } - return 1; + return true; } -int MIME_Entity::ParseFieldParameters(int len, const char* data) +bool MIME_Entity::ParseFieldParameters(int len, const char* data) { data_chunk_t attr; - while ( 1 ) + while ( true ) { int offset = MIME_skip_lws_comments(len, data); if ( offset < 0 || offset >= len || data[offset] != ';' ) @@ -867,7 +867,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data) if ( offset < 0 ) { IllegalFormat("attribute name not found in parameter specification"); - return 0; + return false; } data += offset; @@ -902,7 +902,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data) data_chunk_t vd = get_data_chunk(val); multipart_boundary = new BroString((const u_char*)vd.data, - vd.length, 1); + vd.length, true); } else // token or quoted-string @@ -920,7 +920,7 @@ int MIME_Entity::ParseFieldParameters(int len, const char* data) delete val; } - return 1; + return true; } void MIME_Entity::ParseContentType(data_chunk_t type, data_chunk_t sub_type) @@ -1000,7 +1000,7 @@ int MIME_Entity::CheckBoundaryDelimiter(int len, const char* data) // trailing_CRLF indicates whether an implicit CRLF sequence follows data // (the CRLF sequence is not included in data). -void MIME_Entity::DecodeDataLine(int len, const char* data, int trailing_CRLF) +void MIME_Entity::DecodeDataLine(int len, const char* data, bool trailing_CRLF) { if ( ! mime_submit_data ) return; @@ -1024,7 +1024,7 @@ void MIME_Entity::DecodeDataLine(int len, const char* data, int trailing_CRLF) FlushData(); } -void MIME_Entity::DecodeBinary(int len, const char* data, int trailing_CRLF) +void MIME_Entity::DecodeBinary(int len, const char* data, bool trailing_CRLF) { if ( delay_adding_implicit_CRLF ) { @@ -1175,17 +1175,17 @@ void MIME_Entity::FinishDecodeBase64() base64_decoder = 0; } -int MIME_Entity::GetDataBuffer() +bool MIME_Entity::GetDataBuffer() { int ret = message->RequestBuffer(&data_buf_length, &data_buf_data); if ( ! ret || data_buf_length == 0 || data_buf_data == 0 ) { // reporter->InternalError("cannot get data buffer from MIME_Message", ""); - return 0; + return false; } data_buf_offset = 0; - return 1; + return true; } void MIME_Entity::DataOctet(char ch) @@ -1337,7 +1337,7 @@ MIME_Mail::MIME_Mail(analyzer::Analyzer* mail_analyzer, bool orig, int buf_size) length = max_chunk_length; buffer_start = data_start = 0; - data_buffer = new BroString(1, new u_char[length+1], length); + data_buffer = new BroString(true, new u_char[length+1], length); if ( mime_content_hash ) { @@ -1368,7 +1368,7 @@ void MIME_Mail::Done() analyzer->EnqueueConnEvent(mime_content_hash, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, val_mgr->GetCount(content_hash_length)}, - make_intrusive(new BroString(1, digest, 16)) + make_intrusive(new BroString(true, digest, 16)) ); } @@ -1459,7 +1459,7 @@ void MIME_Mail::SubmitData(int len, const char* buf) if ( mime_entity_data || mime_all_data ) { - BroString* s = new BroString((const u_char*) buf, len, 0); + BroString* s = new BroString((const u_char*) buf, len, false); if ( mime_entity_data ) entity_content.push_back(s); @@ -1487,7 +1487,7 @@ void MIME_Mail::SubmitData(int len, const char* buf) buffer_start = (buf + len) - (char*)data_buffer->Bytes(); } -int MIME_Mail::RequestBuffer(int* plen, char** pbuf) +bool MIME_Mail::RequestBuffer(int* plen, char** pbuf) { data_start = buffer_start - min_overlap_length; if ( data_start < 0 ) @@ -1509,7 +1509,7 @@ int MIME_Mail::RequestBuffer(int* plen, char** pbuf) *plen = max_chunk_length - overlap; *pbuf = (char*) data_buffer->Bytes() + buffer_start; - return 1; + return true; } void MIME_Mail::SubmitAllData() diff --git a/src/analyzer/protocol/mime/MIME.h b/src/analyzer/protocol/mime/MIME.h index 33acab12be..f7026bf758 100644 --- a/src/analyzer/protocol/mime/MIME.h +++ b/src/analyzer/protocol/mime/MIME.h @@ -93,7 +93,7 @@ public: MIME_Entity(MIME_Message* output_message, MIME_Entity* parent_entity); virtual ~MIME_Entity(); - virtual void Deliver(int len, const char* data, int trailing_CRLF); + virtual void Deliver(int len, const char* data, bool trailing_CRLF); virtual void EndOfData(); MIME_Entity* Parent() const { return parent; } @@ -112,25 +112,25 @@ protected: void ParseMIMEHeader(MIME_Header* h); int LookupMIMEHeaderName(data_chunk_t name); - int ParseContentTypeField(MIME_Header* h); - int ParseContentEncodingField(MIME_Header* h); - int ParseFieldParameters(int len, const char* data); + bool ParseContentTypeField(MIME_Header* h); + bool ParseContentEncodingField(MIME_Header* h); + bool ParseFieldParameters(int len, const char* data); void ParseContentType(data_chunk_t type, data_chunk_t sub_type); void ParseContentEncoding(data_chunk_t encoding_mechanism); void BeginBody(); - void NewDataLine(int len, const char* data, int trailing_CRLF); + void NewDataLine(int len, const char* data, bool trailing_CRLF); int CheckBoundaryDelimiter(int len, const char* data); - void DecodeDataLine(int len, const char* data, int trailing_CRLF); - void DecodeBinary(int len, const char* data, int trailing_CRLF); + void DecodeDataLine(int len, const char* data, bool trailing_CRLF); + void DecodeBinary(int len, const char* data, bool trailing_CRLF); void DecodeQuotedPrintable(int len, const char* data); void DecodeBase64(int len, const char* data); void StartDecodeBase64(); void FinishDecodeBase64(); - int GetDataBuffer(); + bool GetDataBuffer(); void DataOctet(char ch); void DataOctets(int len, const char* data); void FlushData(); @@ -189,7 +189,7 @@ public: // not know its type yet (MIME_Entity / MIME_Mail / // etc.). top_level = 0; - finished = 0; + finished = false; analyzer = arg_analyzer; } @@ -200,11 +200,11 @@ public: "missing MIME_Message::Done() call"); } - virtual void Done() { finished = 1; } + virtual void Done() { finished = true; } - int Finished() const { return finished; } + bool Finished() const { return finished; } - virtual void Deliver(int len, const char* data, int trailing_CRLF) + virtual void Deliver(int len, const char* data, bool trailing_CRLF) { top_level->Deliver(len, data, trailing_CRLF); } @@ -217,14 +217,14 @@ public: virtual void SubmitHeader(MIME_Header* h) = 0; virtual void SubmitAllHeaders(MIME_HeaderList& hlist) = 0; virtual void SubmitData(int len, const char* buf) = 0; - virtual int RequestBuffer(int* plen, char** pbuf) = 0; + virtual bool RequestBuffer(int* plen, char** pbuf) = 0; virtual void SubmitEvent(int event_type, const char* detail) = 0; protected: analyzer::Analyzer* analyzer; MIME_Entity* top_level; - int finished; + bool finished; RecordVal* BuildHeaderVal(MIME_Header* h); TableVal* BuildHeaderTable(MIME_HeaderList& hlist); @@ -241,7 +241,7 @@ public: void SubmitHeader(MIME_Header* h) override; void SubmitAllHeaders(MIME_HeaderList& hlist) override; void SubmitData(int len, const char* buf) override; - int RequestBuffer(int* plen, char** pbuf) override; + bool RequestBuffer(int* plen, char** pbuf) override; void SubmitAllData(); void SubmitEvent(int event_type, const char* detail) override; void Undelivered(int len); @@ -265,14 +265,14 @@ protected: }; -extern int is_null_data_chunk(data_chunk_t b); +extern bool is_null_data_chunk(data_chunk_t b); extern StringVal* new_string_val(int length, const char* data); extern StringVal* new_string_val(const char* data, const char* end_of_data); extern StringVal* new_string_val(const data_chunk_t buf); extern int fputs(data_chunk_t b, FILE* fp); extern bool istrequal(data_chunk_t s, const char* t); -extern int is_lws(char ch); -extern int MIME_is_field_name_char(char ch); +extern bool is_lws(char ch); +extern bool MIME_is_field_name_char(char ch); extern int MIME_count_leading_lws(int len, const char* data); extern int MIME_count_trailing_lws(int len, const char* data); extern int MIME_skip_comments(int len, const char* data); diff --git a/src/analyzer/protocol/ncp/NCP.cc b/src/analyzer/protocol/ncp/NCP.cc index c987c78c7a..03580d2abb 100644 --- a/src/analyzer/protocol/ncp/NCP.cc +++ b/src/analyzer/protocol/ncp/NCP.cc @@ -30,7 +30,7 @@ NCP_Session::NCP_Session(analyzer::Analyzer* a) req_func = 0; } -void NCP_Session::Deliver(int is_orig, int len, const u_char* data) +void NCP_Session::Deliver(bool is_orig, int len, const u_char* data) { try { @@ -258,4 +258,3 @@ NCP_Analyzer::~NCP_Analyzer() { delete session; } - diff --git a/src/analyzer/protocol/ncp/NCP.h b/src/analyzer/protocol/ncp/NCP.h index 52dc21cdf1..22c9ef0a56 100644 --- a/src/analyzer/protocol/ncp/NCP.h +++ b/src/analyzer/protocol/ncp/NCP.h @@ -31,9 +31,8 @@ namespace analyzer { namespace ncp { class NCP_Session { public: explicit NCP_Session(analyzer::Analyzer* analyzer); - virtual ~NCP_Session() {} - virtual void Deliver(int is_orig, int len, const u_char* data); + void Deliver(bool is_orig, int len, const u_char* data); static bool any_ncp_event() { @@ -115,4 +114,4 @@ protected: Contents_NCP_Analyzer * r_ncp; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/netbios/NetbiosSSN.cc b/src/analyzer/protocol/netbios/NetbiosSSN.cc index 86f10e9698..31b662d4e6 100644 --- a/src/analyzer/protocol/netbios/NetbiosSSN.cc +++ b/src/analyzer/protocol/netbios/NetbiosSSN.cc @@ -55,8 +55,8 @@ NetbiosSSN_Interpreter::NetbiosSSN_Interpreter(Analyzer* arg_analyzer) //smb_session = arg_smb_session; } -int NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags, - const u_char* data, int len, int is_query) +void NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags, + const u_char* data, int len, bool is_query) { if ( netbios_session_message ) analyzer->EnqueueConnEvent(netbios_session_message, @@ -68,54 +68,59 @@ int NetbiosSSN_Interpreter::ParseMessage(unsigned int type, unsigned int flags, switch ( type ) { case NETBIOS_SSN_MSG: - return ParseSessionMsg(data, len, is_query); + ParseSessionMsg(data, len, is_query); + break; case NETBIOS_SSN_REQ: - return ParseSessionReq(data, len, is_query); + ParseSessionReq(data, len, is_query); + break; case NETBIOS_SSN_POS_RESP: - return ParseSessionPosResp(data, len, is_query); + ParseSessionPosResp(data, len, is_query); + break; case NETBIOS_SSN_NEG_RESP: - return ParseSessionNegResp(data, len, is_query); + ParseSessionNegResp(data, len, is_query); + break; case NETBIOS_SSN_RETARG_RESP: - return ParseRetArgResp(data, len, is_query); + ParseRetArgResp(data, len, is_query); + break; case NETBIOS_SSN_KEEP_ALIVE: - return ParseKeepAlive(data, len, is_query); + ParseKeepAlive(data, len, is_query); + break; case NETBIOS_DGM_DIRECT_UNIQUE: case NETBIOS_DGM_DIRECT_GROUP: case NETBIOS_DGM_BROADCAST: - return ParseBroadcast(data, len, is_query); + ParseBroadcast(data, len, is_query); + break; case NETBIOS_DGM_ERROR: case NETBIOS_DGG_QUERY_REQ: case NETBIOS_DGM_POS_RESP: case NETBIOS_DGM_NEG_RESP: - return ParseDatagram(data, len, is_query); + ParseDatagram(data, len, is_query); + break; default: analyzer->Weird("unknown_netbios_type", fmt("0x%x", type)); - return 1; + break; } } -int NetbiosSSN_Interpreter::ParseDatagram(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseDatagram(const u_char* data, int len, + bool is_query) { //if ( smb_session ) // { // smb_session->Deliver(is_query, len, data); - // return 0; // } - - return 0; } -int NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len, + bool is_query) { // FIND THE NUL-TERMINATED NAME STRINGS HERE! // Not sure what's in them, so we don't keep them currently. @@ -133,12 +138,10 @@ int NetbiosSSN_Interpreter::ParseBroadcast(const u_char* data, int len, //if ( smb_session ) // smb_session->Deliver(is_query, len, data); - - return 0; } -int NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len, + bool is_query) { NetbiosSSN_RawMsgHdr hdr(data, len); @@ -152,11 +155,11 @@ int NetbiosSSN_Interpreter::ParseMessageTCP(const u_char* data, int len, len = hdr.length; } - return ParseMessage(hdr.type, hdr.flags, data, len, is_query); + ParseMessage(hdr.type, hdr.flags, data, len, is_query); } -int NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len, + bool is_query) { NetbiosDGM_RawMsgHdr hdr(data, len); @@ -172,19 +175,19 @@ int NetbiosSSN_Interpreter::ParseMessageUDP(const u_char* data, int len, len = hdr.length; } - return ParseMessage(hdr.type, hdr.flags, data, len, is_query); + ParseMessage(hdr.type, hdr.flags, data, len, is_query); } -int NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len, + bool is_query) { if ( len < 4 || strncmp((const char*) data, "\xffSMB", 4) ) { // This should be an event, too. analyzer->Weird("netbios_raw_session_msg"); Event(netbios_session_raw_message, data, len, is_query); - return 0; + return; } //if ( smb_session ) @@ -197,14 +200,13 @@ int NetbiosSSN_Interpreter::ParseSessionMsg(const u_char* data, int len, analyzer->Weird("no_smb_session_using_parsesambamsg"); data += 4; len -= 4; - return ParseSambaMsg(data, len, is_query); + ParseSambaMsg(data, len, is_query); } } -int NetbiosSSN_Interpreter::ParseSambaMsg(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseSambaMsg(const u_char* data, int len, + bool is_query) { - return 0; } int NetbiosSSN_Interpreter::ConvertName(const u_char* name, int name_len, @@ -246,8 +248,8 @@ int NetbiosSSN_Interpreter::ConvertName(const u_char* name, int name_len, return 1; } -int NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len, + bool is_query) { if ( ! is_query ) analyzer->Weird("netbios_server_session_request"); @@ -259,23 +261,19 @@ int NetbiosSSN_Interpreter::ParseSessionReq(const u_char* data, int len, Event(netbios_session_request, xname, xlen); delete [] xname; - - return 0; } -int NetbiosSSN_Interpreter::ParseSessionPosResp(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseSessionPosResp(const u_char* data, int len, + bool is_query) { if ( is_query ) analyzer->Weird("netbios_client_session_reply"); Event(netbios_session_accepted, data, len); - - return 0; } -int NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len, + bool is_query) { if ( is_query ) analyzer->Weird("netbios_client_session_reply"); @@ -299,27 +297,21 @@ int NetbiosSSN_Interpreter::ParseSessionNegResp(const u_char* data, int len, printf("Unspecified error 0x%X\n",ecode); break; #endif - - return 0; } -int NetbiosSSN_Interpreter::ParseRetArgResp(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseRetArgResp(const u_char* data, int len, + bool is_query) { if ( is_query ) analyzer->Weird("netbios_client_session_reply"); Event(netbios_session_ret_arg_resp, data, len); - - return 0; } -int NetbiosSSN_Interpreter::ParseKeepAlive(const u_char* data, int len, - int is_query) +void NetbiosSSN_Interpreter::ParseKeepAlive(const u_char* data, int len, + bool is_query) { Event(netbios_session_keepalive, data, len); - - return 0; } void NetbiosSSN_Interpreter::Event(EventHandlerPtr event, const u_char* data, @@ -332,12 +324,12 @@ void NetbiosSSN_Interpreter::Event(EventHandlerPtr event, const u_char* data, analyzer->EnqueueConnEvent(event, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, IntrusivePtr{AdoptRef{}, val_mgr->GetBool(is_orig)}, - make_intrusive(new BroString(data, len, 0)) + make_intrusive(new BroString(data, len, false)) ); else analyzer->EnqueueConnEvent(event, IntrusivePtr{AdoptRef{}, analyzer->BuildConnVal()}, - make_intrusive(new BroString(data, len, 0)) + make_intrusive(new BroString(data, len, false)) ); } @@ -448,7 +440,7 @@ void Contents_NetbiosSSN::DeliverStream(int len, const u_char* data, bool orig) // Haven't filled up the message buffer yet, no more to do. return; - (void) interp->ParseMessage(type, flags, msg_buf, msg_size, IsOrig()); + interp->ParseMessage(type, flags, msg_buf, msg_size, IsOrig()); buf_n = 0; state = NETBIOS_SSN_TYPE; @@ -476,7 +468,7 @@ NetbiosSSN_Analyzer::NetbiosSSN_Analyzer(Connection* conn) else { ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer, - network_time + netbios_ssn_session_timeout, 1, + network_time + netbios_ssn_session_timeout, true, TIMER_NB_EXPIRE); } } @@ -506,7 +498,7 @@ void NetbiosSSN_Analyzer::EndpointEOF(bool orig) } void NetbiosSSN_Analyzer::ConnectionClosed(tcp::TCP_Endpoint* endpoint, - tcp::TCP_Endpoint* peer, int gen_event) + tcp::TCP_Endpoint* peer, bool gen_event) { tcp::TCP_ApplicationAnalyzer::ConnectionClosed(endpoint, peer, gen_event); @@ -521,9 +513,9 @@ void NetbiosSSN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, tcp::TCP_ApplicationAnalyzer::DeliverPacket(len, data, orig, seq, ip, caplen); if ( orig ) - interp->ParseMessageUDP(data, len, 1); + interp->ParseMessageUDP(data, len, true); else - interp->ParseMessageUDP(data, len, 0); + interp->ParseMessageUDP(data, len, false); } void NetbiosSSN_Analyzer::ExpireTimer(double t) @@ -541,5 +533,5 @@ void NetbiosSSN_Analyzer::ExpireTimer(double t) else ADD_ANALYZER_TIMER(&NetbiosSSN_Analyzer::ExpireTimer, t + netbios_ssn_session_timeout, - 1, TIMER_NB_EXPIRE); + true, TIMER_NB_EXPIRE); } diff --git a/src/analyzer/protocol/netbios/NetbiosSSN.h b/src/analyzer/protocol/netbios/NetbiosSSN.h index 7a6c1fab8f..fb7800bd77 100644 --- a/src/analyzer/protocol/netbios/NetbiosSSN.h +++ b/src/analyzer/protocol/netbios/NetbiosSSN.h @@ -65,28 +65,28 @@ class NetbiosSSN_Interpreter { public: explicit NetbiosSSN_Interpreter(Analyzer* analyzer); - int ParseMessage(unsigned int type, unsigned int flags, - const u_char* data, int len, int is_query); + void ParseMessage(unsigned int type, unsigned int flags, + const u_char* data, int len, bool is_query); // Version used when data points to type/flags/length. - int ParseMessageTCP(const u_char* data, int len, int is_query); - int ParseMessageUDP(const u_char* data, int len, int is_query); + void ParseMessageTCP(const u_char* data, int len, bool is_query); + void ParseMessageUDP(const u_char* data, int len, bool is_query); void Timeout() { } protected: - int ParseSessionMsg(const u_char* data, int len, int is_query); - int ParseSessionReq(const u_char* data, int len, int is_query); - int ParseSessionPosResp(const u_char* data, int len, int is_query); - int ParseSessionNegResp(const u_char* data, int len, int is_query); - int ParseRetArgResp(const u_char* data, int len, int is_query); - int ParseKeepAlive(const u_char* data, int len, int is_query); + void ParseSessionMsg(const u_char* data, int len, bool is_query); + void ParseSessionReq(const u_char* data, int len, bool is_query); + void ParseSessionPosResp(const u_char* data, int len, bool is_query); + void ParseSessionNegResp(const u_char* data, int len, bool is_query); + void ParseRetArgResp(const u_char* data, int len, bool is_query); + void ParseKeepAlive(const u_char* data, int len, bool is_query); // Datagram parsing - int ParseBroadcast(const u_char* data, int len, int is_query); - int ParseDatagram(const u_char* data, int len, int is_query); + void ParseBroadcast(const u_char* data, int len, bool is_query); + void ParseDatagram(const u_char* data, int len, bool is_query); - int ParseSambaMsg(const u_char* data, int len, int is_query); + void ParseSambaMsg(const u_char* data, int len, bool is_query); void Event(EventHandlerPtr event, const u_char* data, int len, int is_orig = -1); @@ -152,7 +152,7 @@ public: protected: void ConnectionClosed(tcp::TCP_Endpoint* endpoint, - tcp::TCP_Endpoint* peer, int gen_event) override; + tcp::TCP_Endpoint* peer, bool gen_event) override; void EndpointEOF(bool is_orig) override; void ExpireTimer(double t); diff --git a/src/analyzer/protocol/pop3/POP3.cc b/src/analyzer/protocol/pop3/POP3.cc index 2e4af7afcf..c5e2d9bb1f 100644 --- a/src/analyzer/protocol/pop3/POP3.cc +++ b/src/analyzer/protocol/pop3/POP3.cc @@ -78,7 +78,7 @@ void POP3_Analyzer::DeliverStream(int len, const u_char* data, bool orig) if ( (TCP() && TCP()->IsPartial()) ) return; - BroString terminated_string(data, len, 1); + BroString terminated_string(data, len, true); if ( orig ) ProcessRequest(len, (char*) terminated_string.Bytes()); @@ -860,7 +860,7 @@ void POP3_Analyzer::EndData() void POP3_Analyzer::ProcessData(int length, const char* line) { - mail->Deliver(length, line, 1); + mail->Deliver(length, line, true); } int POP3_Analyzer::ParseCmd(string cmd) diff --git a/src/analyzer/protocol/rpc/MOUNT.cc b/src/analyzer/protocol/rpc/MOUNT.cc index c4bfd373bc..f15a9f154a 100644 --- a/src/analyzer/protocol/rpc/MOUNT.cc +++ b/src/analyzer/protocol/rpc/MOUNT.cc @@ -15,7 +15,7 @@ using namespace analyzer::rpc; -int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) +bool MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { if ( c->Program() != 100005 ) Weird("bad_RPC_program", fmt("%d", c->Program())); @@ -54,7 +54,7 @@ int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) // Return 1 so that replies to unprocessed calls will still // be processed, and the return status extracted. - return 1; + return true; } if ( ! buf ) @@ -66,15 +66,15 @@ int MOUNT_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) // Unref() the call arguments, and we are fine. Unref(callarg); callarg = 0; - return 0; + return false; } c->AddVal(callarg); // It's save to AddVal(0). - return 1; + return true; } -int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, +bool MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) { @@ -143,7 +143,7 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status event = mount_proc_not_implemented; } else - return 0; + return false; } if ( rpc_success && ! buf ) @@ -152,7 +152,7 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status // also comments in RPC_BuildCall. Unref(reply); reply = 0; - return 0; + return false; } // Note: if reply == 0, it won't be added to the val_list for the @@ -178,11 +178,11 @@ int MOUNT_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status } else Unref(reply); - return 1; + return true; } zeek::Args MOUNT_Interp::event_common_vl(RPC_CallInfo *c, - BifEnum::rpc_status rpc_status, + BifEnum::rpc_status rpc_status, BifEnum::MOUNT3::status_t mount_status, double rep_start_time, double rep_last_time, int reply_len, int extra_elements) @@ -232,7 +232,7 @@ StringVal* MOUNT_Interp::mount3_fh(const u_char*& buf, int& n) if ( ! fh ) return 0; - return new StringVal(new BroString(fh, fh_n, 0)); + return new StringVal(new BroString(fh, fh_n, false)); } StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) @@ -243,7 +243,7 @@ StringVal* MOUNT_Interp::mount3_filename(const u_char*& buf, int& n) if ( ! name ) return 0; - return new StringVal(new BroString(name, name_len, 0)); + return new StringVal(new BroString(name, name_len, false)); } RecordVal* MOUNT_Interp::mount3_dirmntargs(const u_char*& buf, int& n) diff --git a/src/analyzer/protocol/rpc/MOUNT.h b/src/analyzer/protocol/rpc/MOUNT.h index 2d78aaaf31..b3b2683f8e 100644 --- a/src/analyzer/protocol/rpc/MOUNT.h +++ b/src/analyzer/protocol/rpc/MOUNT.h @@ -11,8 +11,8 @@ public: explicit MOUNT_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } protected: - int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; - int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, + bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; + bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) override; diff --git a/src/analyzer/protocol/rpc/NFS.cc b/src/analyzer/protocol/rpc/NFS.cc index a832b0f96d..bb76727705 100644 --- a/src/analyzer/protocol/rpc/NFS.cc +++ b/src/analyzer/protocol/rpc/NFS.cc @@ -15,7 +15,7 @@ using namespace analyzer::rpc; -int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) +bool NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { if ( c->Program() != 100003 ) Weird("bad_RPC_program", fmt("%d", c->Program())); @@ -108,7 +108,7 @@ int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) // Return 1 so that replies to unprocessed calls will still // be processed, and the return status extracted. - return 1; + return true; } if ( ! buf ) @@ -120,15 +120,15 @@ int NFS_Interp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) // Unref() the call arguments, and we are fine. Unref(callarg); callarg = 0; - return 0; + return false; } c->AddVal(callarg); // It's save to AddVal(0). - return 1; + return true; } -int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, +bool NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) { @@ -255,7 +255,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, event = nfs_proc_not_implemented; } else - return 0; + return false; } if ( rpc_success && ! buf ) @@ -264,7 +264,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, // also comments in RPC_BuildCall. Unref(reply); reply = 0; - return 0; + return false; } // Note: if reply == 0, it won't be added to the val_list for the @@ -291,7 +291,7 @@ int NFS_Interp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, else Unref(reply); - return 1; + return true; } StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offset, int size) @@ -313,7 +313,7 @@ StringVal* NFS_Interp::nfs3_file_data(const u_char*& buf, int& n, uint64_t offse data_n = min(data_n, int(BifConst::NFS3::return_data_max)); if ( data && data_n > 0 ) - return new StringVal(new BroString(data, data_n, 0)); + return new StringVal(new BroString(data, data_n, false)); return 0; } @@ -360,7 +360,7 @@ StringVal* NFS_Interp::nfs3_fh(const u_char*& buf, int& n) if ( ! fh ) return 0; - return new StringVal(new BroString(fh, fh_n, 0)); + return new StringVal(new BroString(fh, fh_n, false)); } @@ -466,7 +466,7 @@ StringVal *NFS_Interp::nfs3_filename(const u_char*& buf, int& n) if ( ! name ) return 0; - return new StringVal(new BroString(name, name_len, 0)); + return new StringVal(new BroString(name, name_len, false)); } RecordVal *NFS_Interp::nfs3_diropargs(const u_char*& buf, int& n) diff --git a/src/analyzer/protocol/rpc/NFS.h b/src/analyzer/protocol/rpc/NFS.h index 272c0612ab..a215dfc14a 100644 --- a/src/analyzer/protocol/rpc/NFS.h +++ b/src/analyzer/protocol/rpc/NFS.h @@ -12,8 +12,8 @@ public: explicit NFS_Interp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } protected: - int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; - int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, + bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; + bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status rpc_status, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) override; @@ -89,4 +89,4 @@ public: }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/rpc/Portmap.cc b/src/analyzer/protocol/rpc/Portmap.cc index 1b2a01875f..c67d1b3c52 100644 --- a/src/analyzer/protocol/rpc/Portmap.cc +++ b/src/analyzer/protocol/rpc/Portmap.cc @@ -18,7 +18,7 @@ using namespace analyzer::rpc; #define PMAPPROC_DUMP 4 #define PMAPPROC_CALLIT 5 -int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) +bool PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { if ( c->Program() != 100000 ) Weird("bad_RPC_program"); @@ -31,7 +31,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { Val* m = ExtractMapping(buf, n); if ( ! m ) - return 0; + return false; c->AddVal(m); } break; @@ -40,7 +40,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { Val* m = ExtractMapping(buf, n); if ( ! m ) - return 0; + return false; c->AddVal(m); } break; @@ -49,7 +49,7 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { Val* pr = ExtractPortRequest(buf, n); if ( ! pr ) - return 0; + return false; c->AddVal(pr); } break; @@ -61,19 +61,19 @@ int PortmapperInterp::RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) { Val* call_it = ExtractCallItRequest(buf, n); if ( ! call_it ) - return 0; + return false; c->AddVal(call_it); } break; default: - return 0; + return false; } - return 1; + return true; } -int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status, +bool PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) @@ -92,7 +92,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status { uint32_t status = extract_XDR_uint32(buf, n); if ( ! buf ) - return 0; + return false; reply = val_mgr->GetBool(status); event = pm_request_set; @@ -107,7 +107,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status { uint32_t status = extract_XDR_uint32(buf, n); if ( ! buf ) - return 0; + return false; reply = val_mgr->GetBool(status); event = pm_request_unset; @@ -122,7 +122,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status { uint32_t port = extract_XDR_uint32(buf, n); if ( ! buf ) - return 0; + return false; RecordVal* rv = c->RequestVal()->AsRecordVal(); Val* is_tcp = rv->Lookup(2); @@ -158,7 +158,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status if ( ! buf ) { Unref(mappings); - return 0; + return false; } reply = mappings; @@ -176,7 +176,7 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status const u_char* opaque_reply = extract_XDR_opaque(buf, n, reply_n); if ( ! opaque_reply ) - return 0; + return false; reply = val_mgr->GetPort(CheckPort(port), TRANSPORT_UDP); event = pm_request_callit; @@ -186,11 +186,11 @@ int PortmapperInterp::RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status status break; default: - return 0; + return false; } Event(event, c->TakeRequestVal(), status, reply); - return 1; + return true; } Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) @@ -200,7 +200,7 @@ Val* PortmapperInterp::ExtractMapping(const u_char*& buf, int& len) mapping->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len))); mapping->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len))); - int is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; + bool is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; uint32_t port = extract_XDR_uint32(buf, len); mapping->Assign(2, val_mgr->GetPort(CheckPort(port), is_tcp ? TRANSPORT_TCP : TRANSPORT_UDP)); @@ -221,7 +221,7 @@ Val* PortmapperInterp::ExtractPortRequest(const u_char*& buf, int& len) pr->Assign(0, val_mgr->GetCount(extract_XDR_uint32(buf, len))); pr->Assign(1, val_mgr->GetCount(extract_XDR_uint32(buf, len))); - int is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; + bool is_tcp = extract_XDR_uint32(buf, len) == IPPROTO_TCP; pr->Assign(2, val_mgr->GetBool(is_tcp)); (void) extract_XDR_uint32(buf, len); // consume the bogus port diff --git a/src/analyzer/protocol/rpc/Portmap.h b/src/analyzer/protocol/rpc/Portmap.h index d12ff3fe06..cf8f9be7e2 100644 --- a/src/analyzer/protocol/rpc/Portmap.h +++ b/src/analyzer/protocol/rpc/Portmap.h @@ -11,8 +11,8 @@ public: explicit PortmapperInterp(analyzer::Analyzer* arg_analyzer) : RPC_Interpreter(arg_analyzer) { } protected: - int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; - int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success, + bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) override; + bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) override; uint32_t CheckPort(uint32_t port); @@ -34,4 +34,4 @@ public: { return new Portmapper_Analyzer(conn); } }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/rpc/RPC.cc b/src/analyzer/protocol/rpc/RPC.cc index 7cb0015a92..50c86a69dd 100644 --- a/src/analyzer/protocol/rpc/RPC.cc +++ b/src/analyzer/protocol/rpc/RPC.cc @@ -101,10 +101,10 @@ RPC_CallInfo::~RPC_CallInfo() Unref(v); } -int RPC_CallInfo::CompareRexmit(const u_char* buf, int n) const +bool RPC_CallInfo::CompareRexmit(const u_char* buf, int n) const { if ( n != call_n ) - return 0; + return false; return memcmp((const void*) call_buf, (const void*) buf, call_n) == 0; } @@ -122,7 +122,7 @@ RPC_Interpreter::~RPC_Interpreter() } int RPC_Interpreter::DeliverRPC(const u_char* buf, int n, int rpclen, - int is_orig, double start_time, double last_time) + bool is_orig, double start_time, double last_time) { uint32_t xid = extract_XDR_uint32(buf, n); uint32_t msg_type = extract_XDR_uint32(buf, n); @@ -451,10 +451,10 @@ bool Contents_RPC::CheckResync(int& len, const u_char*& data, bool orig) bool discard_this_chunk = false; if ( resync_state == RESYNC_INIT ) - { + { // First time CheckResync is called. If the TCP endpoint - // is fully established we are in sync (since it's the first chunk - // of data after the SYN if its not established we need to + // is fully established we are in sync (since it's the first chunk + // of data after the SYN if its not established we need to // resync. tcp::TCP_Analyzer* tcp = static_cast(Parent())->TCP(); @@ -647,7 +647,7 @@ void Contents_RPC::DeliverStream(int len, const u_char* data, bool orig) // know yet how much we expect, so we set expected to // 0. msg_buf.Init(MAX_RPC_LEN, 0); - last_frag = 0; + last_frag = false; state = WAIT_FOR_MARKER; start_time = network_time; // no break. fall through @@ -729,7 +729,7 @@ RPC_Analyzer::RPC_Analyzer(const char* name, Connection* conn, { if ( Conn()->ConnTransport() == TRANSPORT_UDP ) ADD_ANALYZER_TIMER(&RPC_Analyzer::ExpireTimer, - network_time + rpc_timeout, 1, TIMER_RPC_EXPIRE); + network_time + rpc_timeout, true, TIMER_RPC_EXPIRE); } RPC_Analyzer::~RPC_Analyzer() @@ -745,12 +745,12 @@ void RPC_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, if ( orig ) { - if ( ! interp->DeliverRPC(data, len, len, 1, network_time, network_time) ) + if ( ! interp->DeliverRPC(data, len, len, true, network_time, network_time) ) Weird("bad_RPC"); } else { - if ( ! interp->DeliverRPC(data, len, len, 0, network_time, network_time) ) + if ( ! interp->DeliverRPC(data, len, len, false, network_time, network_time) ) Weird("bad_RPC"); } } diff --git a/src/analyzer/protocol/rpc/RPC.h b/src/analyzer/protocol/rpc/RPC.h index b7a03ebac5..60488cd6d0 100644 --- a/src/analyzer/protocol/rpc/RPC.h +++ b/src/analyzer/protocol/rpc/RPC.h @@ -56,7 +56,7 @@ public: Val* RequestVal() const { return v; } Val* TakeRequestVal() { Val* rv = v; v = 0; return rv; } - int CompareRexmit(const u_char* buf, int n) const; + bool CompareRexmit(const u_char* buf, int n) const; uint32_t Program() const { return prog; } uint32_t Version() const { return vers; } @@ -106,13 +106,13 @@ public: // Delivers the given RPC. Returns true if "len" bytes were // enough, false otherwise. "is_orig" is true if the data is // from the originator of the connection. - int DeliverRPC(const u_char* data, int len, int caplen, int is_orig, double start_time, double last_time); + int DeliverRPC(const u_char* data, int len, int caplen, bool is_orig, double start_time, double last_time); void Timeout(); protected: - virtual int RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) = 0; - virtual int RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success, + virtual bool RPC_BuildCall(RPC_CallInfo* c, const u_char*& buf, int& n) = 0; + virtual bool RPC_BuildReply(RPC_CallInfo* c, BifEnum::rpc_status success, const u_char*& buf, int& n, double start_time, double last_time, int reply_len) = 0; @@ -250,4 +250,4 @@ protected: Contents_RPC* resp_rpc; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/smb/smb1-com-locking-andx.pac b/src/analyzer/protocol/smb/smb1-com-locking-andx.pac index f937dafbab..71d391916b 100644 --- a/src/analyzer/protocol/smb/smb1-com-locking-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-locking-andx.pac @@ -50,7 +50,7 @@ type SMB1_locking_andx_request(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_locking_andx_request(header, this); }; diff --git a/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac b/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac index 2284568bb5..f693d50135 100644 --- a/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-logoff-andx.pac @@ -17,7 +17,7 @@ type SMB1_logoff_andx(header: SMB_Header, offset: uint16, is_orig: bool) = recor extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_logoff_andx(header, this); }; diff --git a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac index 01eae48d0b..d03a0fc0b4 100644 --- a/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-nt-create-andx.pac @@ -70,7 +70,7 @@ type SMB1_nt_create_andx_request(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_nt_create_andx_request(header, this); }; @@ -96,7 +96,7 @@ type SMB1_nt_create_andx_response(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_nt_create_andx_response(header, this); }; diff --git a/src/analyzer/protocol/smb/smb1-com-read-andx.pac b/src/analyzer/protocol/smb/smb1-com-read-andx.pac index 712ad8948b..b13977df8e 100644 --- a/src/analyzer/protocol/smb/smb1-com-read-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-read-andx.pac @@ -64,7 +64,7 @@ type SMB1_read_andx_request(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=((andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters)))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { offset_high_64 : uint64 = offset_high; offset_high : uint32 = (word_count == 0x0C && offset_high_tmp != 0xffffffff) ? offset_high_tmp : 0; @@ -91,7 +91,7 @@ type SMB1_read_andx_response(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { pipe_proc : bool = $context.connection.forward_dce_rpc(data, 0, false) &if(header.is_pipe); diff --git a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac index af802c3bd0..7ba49ff6bd 100644 --- a/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-session-setup-andx.pac @@ -157,7 +157,7 @@ type SMB1_session_setup_andx_request_lanman(header: SMB_Header, offset: uint16) extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); }; type SMB1_session_setup_andx_response_lanman(header: SMB_Header, offset: uint16) = record { @@ -171,7 +171,7 @@ type SMB1_session_setup_andx_response_lanman(header: SMB_Header, offset: uint16) extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { is_guest: bool = ( action & 0x1 ) > 0; }; @@ -208,7 +208,7 @@ type SMB1_session_setup_andx_request_ntlm_nonextended_security(header: SMB_Heade extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); }; type SMB1_session_setup_andx_request_ntlm_extended_security(header: SMB_Header, offset: uint16) = record { @@ -228,7 +228,7 @@ type SMB1_session_setup_andx_request_ntlm_extended_security(header: SMB_Header, extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { pipe_proc : bool = $context.connection.forward_gssapi(security_blob, true); }; @@ -245,9 +245,8 @@ type SMB1_session_setup_andx_response_ntlm(header: SMB_Header, offset: uint16) = extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { is_guest : bool = ( action & 0x1 ) > 0; gssapi_proc : bool = $context.connection.forward_gssapi(security_blob, false); }; - diff --git a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac index c86f138ff8..887c1d8bfa 100644 --- a/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-tree-connect-andx.pac @@ -41,11 +41,11 @@ type SMB1_tree_connect_andx_request(header: SMB_Header, offset: uint16) = record byte_count : uint16; password : uint8[password_length]; path : SMB_string(header.unicode, offsetof(path)); - service : SMB_string(0, offsetof(service)); + service : SMB_string(false, offsetof(service)); extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_tree_connect_andx_request(header, this); }; @@ -57,13 +57,12 @@ type SMB1_tree_connect_andx_response(header: SMB_Header, offset: uint16) = recor pad : padding[word_count<3 ? 0 : (word_count-3)*2]; byte_count : uint16; - service : SMB_string(0, offsetof(service)); + service : SMB_string(false, offsetof(service)); native_file_system : SMB_string(header.unicode, offsetof(native_file_system))[byte_count > sizeof(service) ? 1 : 0]; extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { proc : bool = $context.connection.proc_smb1_tree_connect_andx_response(header, this); }; - diff --git a/src/analyzer/protocol/smb/smb1-com-write-andx.pac b/src/analyzer/protocol/smb/smb1-com-write-andx.pac index 8b4eed7056..50463a4a49 100644 --- a/src/analyzer/protocol/smb/smb1-com-write-andx.pac +++ b/src/analyzer/protocol/smb/smb1-com-write-andx.pac @@ -56,7 +56,7 @@ type SMB1_write_andx_request(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 1, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, true, offset+offsetof(andx_command), andx.command); } &let { pipe_proc : bool = $context.connection.forward_dce_rpc(data, 0, true) &if(header.is_pipe); @@ -78,7 +78,7 @@ type SMB1_write_andx_response(header: SMB_Header, offset: uint16) = record { extra_byte_parameters : bytestring &transient &length=(andx.offset == 0 || andx.offset >= (offset+offsetof(extra_byte_parameters))+2) ? 0 : (andx.offset-(offset+offsetof(extra_byte_parameters))); - andx_command : SMB_andx_command(header, 0, offset+offsetof(andx_command), andx.command); + andx_command : SMB_andx_command(header, false, offset+offsetof(andx_command), andx.command); } &let { written_bytes : uint32 = (written_high * 0x10000) + written_low; proc : bool = $context.connection.proc_smb1_write_andx_response(header, this); diff --git a/src/analyzer/protocol/smtp/SMTP.cc b/src/analyzer/protocol/smtp/SMTP.cc index 1aa3d8ee70..eee9ac81b8 100644 --- a/src/analyzer/protocol/smtp/SMTP.cc +++ b/src/analyzer/protocol/smtp/SMTP.cc @@ -29,8 +29,8 @@ static const char* unknown_cmd = "(UNKNOWN)"; SMTP_Analyzer::SMTP_Analyzer(Connection* conn) : tcp::TCP_ApplicationAnalyzer("SMTP", conn) { - expect_sender = 0; - expect_recver = 1; + expect_sender = false; + expect_recver = true; state = SMTP_CONNECTED; last_replied_cmd = -1; first_cmd = SMTP_CMD_CONN_ESTABLISHMENT; @@ -39,9 +39,9 @@ SMTP_Analyzer::SMTP_Analyzer(Connection* conn) // Some clients appear to assume pipelining is always enabled // and do not bother to check whether "PIPELINING" appears in // the server reply to EHLO. - pipelining = 1; + pipelining = true; - skip_data = 0; + skip_data = false; orig_is_sender = true; line_after_gap = 0; mail = 0; @@ -57,7 +57,7 @@ SMTP_Analyzer::SMTP_Analyzer(Connection* conn) AddSupportAnalyzer(cl_resp); } -void SMTP_Analyzer::ConnectionFinished(int half_finished) +void SMTP_Analyzer::ConnectionFinished(bool half_finished) { tcp::TCP_ApplicationAnalyzer::ConnectionFinished(half_finished); @@ -128,7 +128,7 @@ void SMTP_Analyzer::DeliverStream(int length, const u_char* line, bool orig) } // NOTE: do not use IsOrig() here, because of TURN command. - int is_sender = orig_is_sender ? orig : ! orig; + bool is_sender = orig_is_sender ? orig : ! orig; #if 0 ### @@ -165,7 +165,7 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) const char* cmd = ""; // NOTE: do not use IsOrig() here, because of TURN command. - int is_sender = orig_is_sender ? orig : ! orig; + bool is_sender = orig_is_sender ? orig : ! orig; if ( ! pipelining && ((is_sender && ! expect_sender) || @@ -183,7 +183,7 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) delete line_after_gap; line_after_gap = - new BroString((const u_char *) line, length, 1); + new BroString((const u_char *) line, length, true); } else if ( state == SMTP_IN_DATA && line[0] == '.' && length == 1 ) @@ -193,14 +193,14 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) cmd_code = SMTP_CMD_END_OF_DATA; NewCmd(cmd_code); - expect_sender = 0; - expect_recver = 1; + expect_sender = false; + expect_recver = true; } else if ( state == SMTP_IN_DATA ) { // Check "." for end of data. - expect_recver = 0; // ?? MAY server respond to mail data? + expect_recver = false; // ?? MAY server respond to mail data? if ( line[0] == '.' ) ++line; @@ -237,8 +237,8 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) else { - expect_sender = 0; - expect_recver = 1; + expect_sender = false; + expect_recver = true; get_word(length, line, cmd_len, cmd); line = skip_whitespace(line + cmd_len, end_of_line); @@ -246,7 +246,7 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) if ( cmd_code == -1 ) { - Unexpected(1, "unknown command", cmd_len, cmd); + Unexpected(true, "unknown command", cmd_len, cmd); cmd = 0; } else @@ -327,14 +327,14 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) line = skip_whitespace(line+3, end_of_line); pending_reply = 0; - expect_sender = 1; - expect_recver = 0; + expect_sender = true; + expect_recver = false; } // Generate events. if ( smtp_reply && reply_code >= 0 ) { - const int cmd_code = last_replied_cmd; + int cmd_code = last_replied_cmd; switch ( cmd_code ) { case SMTP_CMD_CONN_ESTABLISHMENT: cmd = ">"; @@ -372,7 +372,7 @@ void SMTP_Analyzer::ProcessLine(int length, const char* line, bool orig) } } -void SMTP_Analyzer::NewCmd(const int cmd_code) +void SMTP_Analyzer::NewCmd(int cmd_code) { if ( pipelining ) { @@ -400,7 +400,7 @@ void SMTP_Analyzer::StartTLS() // STARTTLS was succesful. Remove SMTP support analyzers, add SSL // analyzer, and throw event signifying the change. state = SMTP_IN_TLS; - expect_sender = expect_recver = 1; + expect_sender = expect_recver = true; RemoveSupportAnalyzer(cl_orig); RemoveSupportAnalyzer(cl_resp); @@ -427,7 +427,7 @@ void SMTP_Analyzer::StartTLS() // we want to understand the behavior of SMTP and check how far it may // deviate from our knowledge. -void SMTP_Analyzer::NewReply(const int reply_code, bool orig) +void SMTP_Analyzer::NewReply(int reply_code, bool orig) { if ( state == SMTP_AFTER_GAP && reply_code > 0 ) { @@ -440,7 +440,7 @@ void SMTP_Analyzer::NewReply(const int reply_code, bool orig) } // Make all parameters constants. - const int cmd_code = first_cmd; + int cmd_code = first_cmd; // To recover from a gap, we detect replies -- the critical // assumptions here are 1) receiver does not reply during a DATA @@ -465,9 +465,9 @@ void SMTP_Analyzer::NewReply(const int reply_code, bool orig) // in the RPC), and as a result we have to update the state following // the commands in addition to the replies. -void SMTP_Analyzer::UpdateState(const int cmd_code, const int reply_code, bool orig) +void SMTP_Analyzer::UpdateState(int cmd_code, int reply_code, bool orig) { - const int st = state; + int st = state; if ( st == SMTP_QUIT && reply_code == 0 ) UnexpectedCommand(cmd_code, reply_code); @@ -753,8 +753,8 @@ void SMTP_Analyzer::UpdateState(const int cmd_code, const int reply_code, bool o orig_is_sender = ! orig_is_sender; state = SMTP_CONNECTED; - expect_sender = 0; - expect_recver = 1; + expect_sender = false; + expect_recver = true; break; case 502: @@ -829,7 +829,7 @@ void SMTP_Analyzer::ProcessExtension(int ext_len, const char* ext) return; if ( istrequal(ext, "PIPELINING", ext_len) ) - pipelining = 1; + pipelining = true; } int SMTP_Analyzer::ParseCmd(int cmd_len, const char* cmd) @@ -867,15 +867,15 @@ void SMTP_Analyzer::RequestEvent(int cmd_len, const char* cmd, } } -void SMTP_Analyzer::Unexpected(const int is_sender, const char* msg, +void SMTP_Analyzer::Unexpected(bool is_sender, const char* msg, int detail_len, const char* detail) { // Either party can send a line after an unexpected line. - expect_sender = expect_recver = 1; + expect_sender = expect_recver = true; if ( smtp_unexpected ) { - int is_orig = is_sender; + bool is_orig = is_sender; if ( ! orig_is_sender ) is_orig = ! is_orig; @@ -888,7 +888,7 @@ void SMTP_Analyzer::Unexpected(const int is_sender, const char* msg, } } -void SMTP_Analyzer::UnexpectedCommand(const int cmd_code, const int reply_code) +void SMTP_Analyzer::UnexpectedCommand(int cmd_code, int reply_code) { // If this happens, please fix the SMTP state machine! // ### Eventually, these should be turned into "weird" events. @@ -898,10 +898,10 @@ void SMTP_Analyzer::UnexpectedCommand(const int cmd_code, const int reply_code) SMTP_CMD_WORD(cmd_code), reply_code, state); if ( len > (int) sizeof(buf) ) len = sizeof(buf); - Unexpected (1, "unexpected command", len, buf); + Unexpected(true, "unexpected command", len, buf); } -void SMTP_Analyzer::UnexpectedReply(const int cmd_code, const int reply_code) +void SMTP_Analyzer::UnexpectedReply(int cmd_code, int reply_code) { // If this happens, please fix the SMTP state machine! // ### Eventually, these should be turned into "weird" events. @@ -909,18 +909,18 @@ void SMTP_Analyzer::UnexpectedReply(const int cmd_code, const int reply_code) int len = snprintf(buf, sizeof(buf), "%d state = %d, last command = %s", reply_code, state, SMTP_CMD_WORD(cmd_code)); - Unexpected (1, "unexpected reply", len, buf); + Unexpected(true, "unexpected reply", len, buf); } void SMTP_Analyzer::ProcessData(int length, const char* line) { - mail->Deliver(length, line, 1 /* trailing_CRLF */); + mail->Deliver(length, line, true /* trailing_CRLF */); } void SMTP_Analyzer::BeginData(bool orig) { state = SMTP_IN_DATA; - skip_data = 0; // reset the flag at the beginning of the mail + skip_data = false; // reset the flag at the beginning of the mail if ( mail != 0 ) { Weird("smtp_nested_mail_transaction"); diff --git a/src/analyzer/protocol/smtp/SMTP.h b/src/analyzer/protocol/smtp/SMTP.h index 07a9af9b08..929bdda45c 100644 --- a/src/analyzer/protocol/smtp/SMTP.h +++ b/src/analyzer/protocol/smtp/SMTP.h @@ -43,7 +43,7 @@ public: void Done() override; void DeliverStream(int len, const u_char* data, bool orig) override; - void ConnectionFinished(int half_finished) override; + void ConnectionFinished(bool half_finished) override; void Undelivered(uint64_t seq, int len, bool orig) override; void SkipData() { skip_data = 1; } // skip delivery of data lines @@ -56,12 +56,12 @@ public: protected: void ProcessLine(int length, const char* line, bool orig); - void NewCmd(const int cmd_code); - void NewReply(const int reply_code, bool orig); + void NewCmd(int cmd_code); + void NewReply(int reply_code, bool orig); void ProcessExtension(int ext_len, const char* ext); void ProcessData(int length, const char* line); - void UpdateState(const int cmd_code, const int reply_code, bool orig); + void UpdateState(int cmd_code, int reply_code, bool orig); void BeginData(bool orig); void EndData(); @@ -70,21 +70,21 @@ protected: void RequestEvent(int cmd_len, const char* cmd, int arg_len, const char* arg); - void Unexpected(const int is_orig, const char* msg, + void Unexpected(bool is_sender, const char* msg, int detail_len, const char* detail); - void UnexpectedCommand(const int cmd_code, const int reply_code); - void UnexpectedReply(const int cmd_code, const int reply_code); + void UnexpectedCommand(int cmd_code, int reply_code); + void UnexpectedReply(int cmd_code, int reply_code); void StartTLS(); bool orig_is_sender; - int expect_sender, expect_recver; + bool expect_sender, expect_recver; + bool pipelining; // whether pipelining is supported int state; int last_replied_cmd; int first_cmd; // first un-replied SMTP cmd, or -1 int pending_reply; // code assoc. w/ multi-line reply, or 0 - int pipelining; // whether pipelining is supported list pending_cmd_q; // to support pipelining - int skip_data; // whether to skip message body + bool skip_data; // whether to skip message body BroString* line_after_gap; // last line before the first reply // after a gap @@ -95,4 +95,4 @@ private: tcp::ContentLine_Analyzer* cl_resp; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/ssl/ssl-analyzer.pac b/src/analyzer/protocol/ssl/ssl-analyzer.pac index f901119f23..e9040ee570 100644 --- a/src/analyzer/protocol/ssl/ssl-analyzer.pac +++ b/src/analyzer/protocol/ssl/ssl-analyzer.pac @@ -44,7 +44,7 @@ refine typeattr V2ClientHello += &let { refine typeattr V2ServerHello += &let { check_v2 : bool = $context.connection.proc_check_v2_server_hello_version(server_version); - proc : bool = $context.connection.proc_server_hello(server_version, 1, + proc : bool = $context.connection.proc_server_hello(server_version, true, conn_id_data, 0, 0, ciphers, 0) &requires(check_v2) &if(check_v2 == true); cert : bool = $context.connection.proc_v2_certificate(rec.is_orig, cert_data) diff --git a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac index 45b7c636d4..02f8a5ffba 100644 --- a/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac +++ b/src/analyzer/protocol/ssl/tls-handshake-analyzer.pac @@ -527,13 +527,13 @@ refine typeattr ClientHello += &let { refine typeattr ServerHello += &let { proc : bool = $context.connection.proc_server_hello(server_version, - 0, random_bytes, session_id, cipher_suite, 0, + false, random_bytes, session_id, cipher_suite, 0, compression_method); }; refine typeattr ServerHello13 += &let { proc : bool = $context.connection.proc_server_hello(server_version, - 0, random, 0, cipher_suite, 0, + false, random, 0, cipher_suite, 0, 0); }; diff --git a/src/analyzer/protocol/stepping-stone/SteppingStone.cc b/src/analyzer/protocol/stepping-stone/SteppingStone.cc index 79133ffdca..54351768f4 100644 --- a/src/analyzer/protocol/stepping-stone/SteppingStone.cc +++ b/src/analyzer/protocol/stepping-stone/SteppingStone.cc @@ -60,7 +60,7 @@ void SteppingStoneEndpoint::Done() Event(stp_remove_endp, stp_id); } -int SteppingStoneEndpoint::DataSent(double t, uint64_t seq, int len, int caplen, +bool SteppingStoneEndpoint::DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, const IP_Hdr* /* ip */, const struct tcphdr* tp) { @@ -68,7 +68,7 @@ int SteppingStoneEndpoint::DataSent(double t, uint64_t seq, int len, int caplen, len = caplen; if ( len <= 0 ) - return 0; + return false; double tmin = t - stp_delta; @@ -91,14 +91,14 @@ int SteppingStoneEndpoint::DataSent(double t, uint64_t seq, int len, int caplen, if ( top_seq <= ack || top_seq <= stp_max_top_seq ) // There is no new data in this packet - return 0; + return false; stp_max_top_seq = top_seq; if ( stp_last_time && t <= stp_last_time + stp_idle_min ) { stp_last_time = t; - return 1; + return true; } // Either just starts, or resumes from an idle period. @@ -126,7 +126,7 @@ int SteppingStoneEndpoint::DataSent(double t, uint64_t seq, int len, int caplen, stp_manager->OrderedEndpoints().push_back(this); Ref(this); - return 1; + return true; } void SteppingStoneEndpoint::Event(EventHandlerPtr f, int id1, int id2) @@ -141,7 +141,7 @@ void SteppingStoneEndpoint::Event(EventHandlerPtr f, int id1, int id2) endp->TCP()->EnqueueConnEvent(f, IntrusivePtr{AdoptRef{}, val_mgr->GetInt(id1)}); } -void SteppingStoneEndpoint::CreateEndpEvent(int is_orig) +void SteppingStoneEndpoint::CreateEndpEvent(bool is_orig) { if ( ! stp_create_endp ) return; diff --git a/src/analyzer/protocol/stepping-stone/SteppingStone.h b/src/analyzer/protocol/stepping-stone/SteppingStone.h index 1a10bbfc5a..b0a22ace90 100644 --- a/src/analyzer/protocol/stepping-stone/SteppingStone.h +++ b/src/analyzer/protocol/stepping-stone/SteppingStone.h @@ -18,12 +18,12 @@ public: ~SteppingStoneEndpoint() override; void Done(); - int DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, + bool DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, const IP_Hdr* ip, const struct tcphdr* tp); protected: void Event(EventHandlerPtr f, int id1, int id2 = -1); - void CreateEndpEvent(int is_orig); + void CreateEndpEvent(bool is_orig); tcp::TCP_Endpoint* endp; uint64_t stp_max_top_seq; @@ -69,7 +69,6 @@ protected: // Manages ids for the possible stepping stone connections. class SteppingStoneManager { public: - SteppingStoneManager() { endp_cnt = 0; } PQueue& OrderedEndpoints() { return ordered_endps; } @@ -79,7 +78,7 @@ public: protected: PQueue ordered_endps; - int endp_cnt; + int endp_cnt = 0; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/syslog/Syslog.cc b/src/analyzer/protocol/syslog/Syslog.cc index b1a8429bd1..225bd1957b 100644 --- a/src/analyzer/protocol/syslog/Syslog.cc +++ b/src/analyzer/protocol/syslog/Syslog.cc @@ -12,7 +12,7 @@ Syslog_Analyzer::Syslog_Analyzer(Connection* conn) interp = new binpac::Syslog::Syslog_Conn(this); did_session_done = 0; //ADD_ANALYZER_TIMER(&Syslog_Analyzer::ExpireTimer, - // network_time + Syslog_session_timeout, 1, TIMER_Syslog_EXPIRE); + // network_time + Syslog_session_timeout, true, TIMER_Syslog_EXPIRE); } Syslog_Analyzer::~Syslog_Analyzer() @@ -46,7 +46,7 @@ void Syslog_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, uint // } // else // ADD_ANALYZER_TIMER(&Syslog_Analyzer::ExpireTimer, -// t + Syslog_session_timeout, 1, TIMER_Syslog_EXPIRE); +// t + Syslog_session_timeout, true, TIMER_Syslog_EXPIRE); // } //Syslog_tcp::TCP_Analyzer::Syslog_tcp::TCP_Analyzer(Connection* conn) diff --git a/src/analyzer/protocol/tcp/ContentLine.cc b/src/analyzer/protocol/tcp/ContentLine.cc index 0c68e6ae2c..193a18fa65 100644 --- a/src/analyzer/protocol/tcp/ContentLine.cc +++ b/src/analyzer/protocol/tcp/ContentLine.cc @@ -312,7 +312,7 @@ void ContentLine_Analyzer::CheckNUL() { if ( ! suppress_weirds && Conn()->FlagEvent(NUL_IN_LINE) ) Conn()->Weird("NUL_in_line"); - flag_NULs = 0; + flag_NULs = false; } } } diff --git a/src/analyzer/protocol/tcp/TCP.cc b/src/analyzer/protocol/tcp/TCP.cc index 77d22d6c1b..6d6ad3a41b 100644 --- a/src/analyzer/protocol/tcp/TCP.cc +++ b/src/analyzer/protocol/tcp/TCP.cc @@ -42,7 +42,7 @@ namespace { // local namespace static const int ORIG = 1; static const int RESP = 2; -static RecordVal* build_syn_packet_val(int is_orig, const IP_Hdr* ip, +static RecordVal* build_syn_packet_val(bool is_orig, const IP_Hdr* ip, const struct tcphdr* tcp) { int winscale = -1; @@ -127,7 +127,7 @@ TCP_Analyzer::TCP_Analyzer(Connection* conn) { // Set a timer to eventually time out this connection. ADD_ANALYZER_TIMER(&TCP_Analyzer::ExpireTimer, - network_time + tcp_SYN_timeout, 0, + network_time + tcp_SYN_timeout, false, TIMER_TCP_EXPIRE); deferred_gen_event = close_deferred = 0; @@ -139,8 +139,8 @@ TCP_Analyzer::TCP_Analyzer(Connection* conn) first_packet_seen = 0; is_partial = 0; - orig = new TCP_Endpoint(this, 1); - resp = new TCP_Endpoint(this, 0); + orig = new TCP_Endpoint(this, true); + resp = new TCP_Endpoint(this, false); orig->SetPeer(resp); resp->SetPeer(orig); @@ -478,8 +478,8 @@ static void syn_weirds(TCP_Flags flags, TCP_Endpoint* endpoint, int data_len) void TCP_Analyzer::UpdateInactiveState(double t, TCP_Endpoint* endpoint, TCP_Endpoint* peer, uint32_t base_seq, uint32_t ack_seq, - int len, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event) + int len, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event) { if ( flags.SYN() ) { @@ -495,7 +495,7 @@ void TCP_Analyzer::UpdateInactiveState(double t, if ( tcp_attempt_delay ) ADD_ANALYZER_TIMER(&TCP_Analyzer::AttemptTimer, - t + tcp_attempt_delay, 1, + t + tcp_attempt_delay, true, TIMER_TCP_ATTEMPT); } else @@ -548,7 +548,7 @@ void TCP_Analyzer::UpdateInactiveState(double t, if ( flags.FIN() ) { endpoint->SetState(TCP_ENDPOINT_CLOSED); - do_close = gen_event = 1; + do_close = gen_event = true; if ( peer->state != TCP_ENDPOINT_PARTIAL && ! flags.SYN() ) Weird("spontaneous_FIN"); } @@ -557,7 +557,7 @@ void TCP_Analyzer::UpdateInactiveState(double t, { endpoint->SetState(TCP_ENDPOINT_RESET); - int is_reject = 0; + bool is_reject = false; if ( is_orig ) { @@ -566,15 +566,15 @@ void TCP_Analyzer::UpdateInactiveState(double t, // scan, and we should treat this as a // reject. if ( peer->state == TCP_ENDPOINT_ESTABLISHED ) - is_reject = 1; + is_reject = true; } else if ( peer->state == TCP_ENDPOINT_SYN_SENT || peer->state == TCP_ENDPOINT_SYN_ACK_SENT ) // We're rejecting an initial SYN. - is_reject = 1; + is_reject = true; - do_close = 1; + do_close = true; gen_event = ! is_reject; if ( is_reject ) @@ -619,8 +619,8 @@ void TCP_Analyzer::UpdateInactiveState(double t, } void TCP_Analyzer::UpdateSYN_SentState(TCP_Endpoint* endpoint, TCP_Endpoint* peer, - int len, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event) + int len, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event) { if ( flags.SYN() ) { @@ -645,14 +645,14 @@ void TCP_Analyzer::UpdateSYN_SentState(TCP_Endpoint* endpoint, TCP_Endpoint* pee Weird("inappropriate_FIN"); endpoint->SetState(TCP_ENDPOINT_CLOSED); - do_close = gen_event = 1; + do_close = gen_event = true; } if ( flags.RST() ) { endpoint->SetState(TCP_ENDPOINT_RESET); ConnectionReset(); - do_close = 1; + do_close = true; } else if ( len > 0 ) @@ -661,7 +661,7 @@ void TCP_Analyzer::UpdateSYN_SentState(TCP_Endpoint* endpoint, TCP_Endpoint* pee void TCP_Analyzer::UpdateEstablishedState( TCP_Endpoint* endpoint, TCP_Endpoint* peer, - TCP_Flags flags, int& do_close, int& gen_event) + TCP_Flags flags, bool& do_close, bool& gen_event) { if ( flags.SYN() ) { @@ -684,13 +684,13 @@ void TCP_Analyzer::UpdateEstablishedState( // this was actually normal termination. peer->SetState(TCP_ENDPOINT_CLOSED); - do_close = gen_event = 1; + do_close = gen_event = true; } if ( flags.RST() ) { endpoint->SetState(TCP_ENDPOINT_RESET); - do_close = 1; + do_close = true; if ( peer->state != TCP_ENDPOINT_RESET || peer->prev_state != TCP_ENDPOINT_ESTABLISHED ) @@ -699,7 +699,7 @@ void TCP_Analyzer::UpdateEstablishedState( } void TCP_Analyzer::UpdateClosedState(double t, TCP_Endpoint* endpoint, - int32_t delta_last, TCP_Flags flags, int& do_close) + int32_t delta_last, TCP_Flags flags, bool& do_close) { if ( flags.SYN() ) Weird("SYN_after_close"); @@ -721,11 +721,11 @@ void TCP_Analyzer::UpdateClosedState(double t, TCP_Endpoint* endpoint, if ( ! endpoint->did_close ) // RST after FIN. - do_close = 1; + do_close = true; if ( connection_reset ) ADD_ANALYZER_TIMER(&TCP_Analyzer::ResetTimer, - t + tcp_reset_delay, 1, + t + tcp_reset_delay, true, TIMER_TCP_RESET); } } @@ -745,11 +745,11 @@ void TCP_Analyzer::UpdateResetState(int len, TCP_Flags flags) void TCP_Analyzer::UpdateStateMachine(double t, TCP_Endpoint* endpoint, TCP_Endpoint* peer, uint32_t base_seq, uint32_t ack_seq, - int len, int32_t delta_last, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event) + int len, int32_t delta_last, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event) { - do_close = 0; // whether to report the connection as closed - gen_event = 0; // if so, whether to generate an event + do_close = false; // whether to report the connection as closed + gen_event = false; // if so, whether to generate an event switch ( endpoint->state ) { @@ -783,7 +783,7 @@ void TCP_Analyzer::UpdateStateMachine(double t, void TCP_Analyzer::GeneratePacketEvent( uint64_t rel_seq, uint64_t rel_ack, const u_char* data, int len, int caplen, - int is_orig, TCP_Flags flags) + bool is_orig, TCP_Flags flags) { EnqueueConnEvent(tcp_packet, IntrusivePtr{AdoptRef{}, BuildConnVal()}, @@ -798,15 +798,15 @@ void TCP_Analyzer::GeneratePacketEvent( ); } -int TCP_Analyzer::DeliverData(double t, const u_char* data, int len, int caplen, +bool TCP_Analyzer::DeliverData(double t, const u_char* data, int len, int caplen, const IP_Hdr* ip, const struct tcphdr* tp, TCP_Endpoint* endpoint, uint64_t rel_data_seq, - int is_orig, TCP_Flags flags) + bool is_orig, TCP_Flags flags) { return endpoint->DataSent(t, rel_data_seq, len, caplen, data, ip, tp); } -void TCP_Analyzer::CheckRecording(int need_contents, TCP_Flags flags) +void TCP_Analyzer::CheckRecording(bool need_contents, TCP_Flags flags) { bool record_current_content = need_contents || Conn()->RecordContents(); bool record_current_packet = @@ -817,7 +817,7 @@ void TCP_Analyzer::CheckRecording(int need_contents, TCP_Flags flags) Conn()->SetRecordCurrentPacket(record_current_packet); } -void TCP_Analyzer::CheckPIA_FirstPacket(int is_orig, const IP_Hdr* ip) +void TCP_Analyzer::CheckPIA_FirstPacket(bool is_orig, const IP_Hdr* ip) { if ( is_orig && ! (first_packet_seen & ORIG) ) { @@ -1173,8 +1173,8 @@ void TCP_Analyzer::DeliverPacket(int len, const u_char* data, bool is_orig, int32_t delta_last = update_last_seq(endpoint, seq_one_past_segment, flags, len); endpoint->last_time = current_timestamp; - int do_close; - int gen_event; + bool do_close; + bool gen_event; UpdateStateMachine(current_timestamp, endpoint, peer, base_seq, ack_seq, len, delta_last, is_orig, flags, do_close, gen_event); @@ -1559,7 +1559,7 @@ void TCP_Analyzer::ExpireTimer(double t) // ### if PQ_Element's were BroObj's, could just Ref the timer // and adjust its value here, instead of creating a new timer. ADD_ANALYZER_TIMER(&TCP_Analyzer::ExpireTimer, t + tcp_session_timer, - 0, TIMER_TCP_EXPIRE); + false, TIMER_TCP_EXPIRE); } void TCP_Analyzer::ResetTimer(double /* t */) @@ -1629,7 +1629,7 @@ BroFile* TCP_Analyzer::GetContentsFile(unsigned int direction) const } void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, - int gen_event) + bool gen_event) { const analyzer_list& children(GetChildren()); LOOP_OVER_CONST_CHILDREN(i) @@ -1654,7 +1654,7 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, if ( endpoint->did_close ) return; // nothing new to report - endpoint->did_close = 1; + endpoint->did_close = true; int close_complete = endpoint->state == TCP_ENDPOINT_RESET || @@ -1674,7 +1674,7 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, { if ( deferred_gen_event ) { - gen_event = 1; + gen_event = true; deferred_gen_event = 0; // clear flag } @@ -1682,9 +1682,9 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, if ( gen_event ) { if ( peer->state == TCP_ENDPOINT_INACTIVE ) - ConnectionFinished(1); + ConnectionFinished(true); else - ConnectionFinished(0); + ConnectionFinished(false); } } @@ -1699,10 +1699,10 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, // deleted out from under us. if ( tcp_close_delay != 0.0 ) ADD_ANALYZER_TIMER(&TCP_Analyzer::ConnDeleteTimer, - Conn()->LastTime() + tcp_close_delay, 0, + Conn()->LastTime() + tcp_close_delay, false, TIMER_CONN_DELETE); else - ADD_ANALYZER_TIMER(&TCP_Analyzer::DeleteTimer, Conn()->LastTime(), 0, + ADD_ANALYZER_TIMER(&TCP_Analyzer::DeleteTimer, Conn()->LastTime(), false, TIMER_TCP_DELETE); } @@ -1712,7 +1712,7 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, { // First time we've seen anything from this side. if ( connection_partial_close ) ADD_ANALYZER_TIMER(&TCP_Analyzer::PartialCloseTimer, - Conn()->LastTime() + tcp_partial_close_delay, 0, + Conn()->LastTime() + tcp_partial_close_delay, false, TIMER_TCP_PARTIAL_CLOSE ); } @@ -1721,13 +1721,13 @@ void TCP_Analyzer::ConnectionClosed(TCP_Endpoint* endpoint, TCP_Endpoint* peer, // Create a timer to look for the other side closing, // too. ADD_ANALYZER_TIMER(&TCP_Analyzer::ExpireTimer, - Conn()->LastTime() + tcp_session_timer, 0, + Conn()->LastTime() + tcp_session_timer, false, TIMER_TCP_EXPIRE); } } } -void TCP_Analyzer::ConnectionFinished(int half_finished) +void TCP_Analyzer::ConnectionFinished(bool half_finished) { const analyzer_list& children(GetChildren()); LOOP_OVER_CONST_CHILDREN(i) @@ -1769,10 +1769,10 @@ void TCP_Analyzer::AddChildPacketAnalyzer(analyzer::Analyzer* a) a->SetParent(this); } -int TCP_Analyzer::DataPending(TCP_Endpoint* closing_endp) +bool TCP_Analyzer::DataPending(TCP_Endpoint* closing_endp) { if ( Skipping() ) - return 0; + return false; return closing_endp->DataPending(); } @@ -1923,7 +1923,7 @@ void TCP_ApplicationAnalyzer::EndpointEOF(bool is_orig) } void TCP_ApplicationAnalyzer::ConnectionClosed(TCP_Endpoint* endpoint, - TCP_Endpoint* peer, int gen_event) + TCP_Endpoint* peer, bool gen_event) { analyzer::SupportAnalyzer* sa = endpoint->IsOrig() ? orig_supporters : resp_supporters; @@ -1933,7 +1933,7 @@ void TCP_ApplicationAnalyzer::ConnectionClosed(TCP_Endpoint* endpoint, ->ConnectionClosed(endpoint, peer, gen_event); } -void TCP_ApplicationAnalyzer::ConnectionFinished(int half_finished) +void TCP_ApplicationAnalyzer::ConnectionFinished(bool half_finished) { for ( analyzer::SupportAnalyzer* sa = orig_supporters; sa; sa = sa->Sibling() ) static_cast(sa) @@ -1981,14 +1981,14 @@ int endian_flip(int n) return ((n & 0xff) << 8) | ((n & 0xff00) >> 8); } -int TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int caplen, +bool TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int caplen, const u_char* /* data */, const IP_Hdr* ip, const struct tcphdr* /* tp */) { if ( ++num_pkts == 1 ) { // First packet. last_id = ip->ID(); - return 0; + return false; } int id = ip->ID(); @@ -1996,7 +1996,7 @@ int TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int caple if ( id == last_id ) { ++num_repl; - return 0; + return false; } short id_delta = id - last_id; @@ -2034,7 +2034,7 @@ int TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int caple if ( final_id_delta < 0 && final_id_delta > -256 ) { ++num_OO; - return 0; + return false; } last_id = id; @@ -2072,7 +2072,7 @@ int TCPStats_Endpoint::DataSent(double /* t */, uint64_t seq, int len, int caple else max_top_seq = top_seq; - return 0; + return false; } RecordVal* TCPStats_Endpoint::BuildStats() diff --git a/src/analyzer/protocol/tcp/TCP.h b/src/analyzer/protocol/tcp/TCP.h index 02c783b730..1a2d29c8b2 100644 --- a/src/analyzer/protocol/tcp/TCP.h +++ b/src/analyzer/protocol/tcp/TCP.h @@ -12,7 +12,7 @@ // - TCP_Analyzer is the analyzer for the TCP protocol itself. // - TCP_ApplicationAnalyzer is an abstract base class for analyzers for a // protocol running on top of TCP. -// +// namespace analyzer { namespace pia { class PIA_TCP; } }; namespace analyzer { namespace tcp { @@ -37,10 +37,10 @@ public: bool RemoveChildAnalyzer(ID id) override; // True if the connection has closed in some sense, false otherwise. - int IsClosed() const { return orig->did_close || resp->did_close; } - int BothClosed() const { return orig->did_close && resp->did_close; } + bool IsClosed() const { return orig->did_close || resp->did_close; } + bool BothClosed() const { return orig->did_close && resp->did_close; } - int IsPartial() const { return is_partial; } + bool IsPartial() const { return is_partial; } bool HadGap(bool orig) const; @@ -58,7 +58,7 @@ public: // which we have seen a FIN) - for it, data is pending unless // everything's been delivered up to the FIN. For its peer, // the test is whether it has any outstanding, un-acked data. - int DataPending(TCP_Endpoint* closing_endp); + bool DataPending(TCP_Endpoint* closing_endp); void SetContentsFile(unsigned int direction, BroFile* f) override; BroFile* GetContentsFile(unsigned int direction) const override; @@ -107,39 +107,39 @@ protected: void UpdateStateMachine(double t, TCP_Endpoint* endpoint, TCP_Endpoint* peer, uint32_t base_seq, uint32_t ack_seq, - int len, int32_t delta_last, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event); + int len, int32_t delta_last, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event); void UpdateInactiveState(double t, TCP_Endpoint* endpoint, TCP_Endpoint* peer, uint32_t base_seq, uint32_t ack_seq, - int len, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event); + int len, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event); void UpdateSYN_SentState(TCP_Endpoint* endpoint, TCP_Endpoint* peer, - int len, int is_orig, TCP_Flags flags, - int& do_close, int& gen_event); + int len, bool is_orig, TCP_Flags flags, + bool& do_close, bool& gen_event); void UpdateEstablishedState(TCP_Endpoint* endpoint, TCP_Endpoint* peer, - TCP_Flags flags, int& do_close, int& gen_event); + TCP_Flags flags, bool& do_close, bool& gen_event); void UpdateClosedState(double t, TCP_Endpoint* endpoint, int32_t delta_last, TCP_Flags flags, - int& do_close); + bool& do_close); void UpdateResetState(int len, TCP_Flags flags); void GeneratePacketEvent(uint64_t rel_seq, uint64_t rel_ack, const u_char* data, int len, int caplen, - int is_orig, TCP_Flags flags); + bool is_orig, TCP_Flags flags); - int DeliverData(double t, const u_char* data, int len, int caplen, + bool DeliverData(double t, const u_char* data, int len, int caplen, const IP_Hdr* ip, const struct tcphdr* tp, TCP_Endpoint* endpoint, uint64_t rel_data_seq, - int is_orig, TCP_Flags flags); + bool is_orig, TCP_Flags flags); - void CheckRecording(int need_contents, TCP_Flags flags); - void CheckPIA_FirstPacket(int is_orig, const IP_Hdr* ip); + void CheckRecording(bool need_contents, TCP_Flags flags); + void CheckPIA_FirstPacket(bool is_orig, const IP_Hdr* ip); friend class ConnectionTimer; void AttemptTimer(double t); @@ -151,8 +151,8 @@ protected: void EndpointEOF(TCP_Reassembler* endp); void ConnectionClosed(TCP_Endpoint* endpoint, - TCP_Endpoint* peer, int gen_event); - void ConnectionFinished(int half_finished); + TCP_Endpoint* peer, bool gen_event); + void ConnectionFinished(bool half_finished); void ConnectionReset(); void PacketWithRST(); @@ -220,8 +220,8 @@ public: // is now fully closed, a connection_finished event will be // generated; otherwise not. virtual void ConnectionClosed(analyzer::tcp::TCP_Endpoint* endpoint, - analyzer::tcp::TCP_Endpoint* peer, int gen_event); - virtual void ConnectionFinished(int half_finished); + analyzer::tcp::TCP_Endpoint* peer, bool gen_event); + virtual void ConnectionFinished(bool half_finished); virtual void ConnectionReset(); // Called whenever a RST packet is seen - sometimes the invocation @@ -255,8 +255,8 @@ public: // These are passed on from TCP_Analyzer. virtual void EndpointEOF(bool is_orig) { } virtual void ConnectionClosed(TCP_Endpoint* endpoint, - TCP_Endpoint* peer, int gen_event) { } - virtual void ConnectionFinished(int half_finished) { } + TCP_Endpoint* peer, bool gen_event) { } + virtual void ConnectionFinished(bool half_finished) { } virtual void ConnectionReset() { } virtual void PacketWithRST() { } }; @@ -266,7 +266,7 @@ class TCPStats_Endpoint { public: explicit TCPStats_Endpoint(TCP_Endpoint* endp); - int DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, + bool DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, const IP_Hdr* ip, const struct tcphdr* tp); RecordVal* BuildStats(); @@ -303,4 +303,4 @@ protected: TCPStats_Endpoint* resp_stats; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.cc b/src/analyzer/protocol/tcp/TCP_Endpoint.cc index b05265a1ef..59f0b21778 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.cc +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.cc @@ -14,7 +14,7 @@ using namespace analyzer::tcp; -TCP_Endpoint::TCP_Endpoint(TCP_Analyzer* arg_analyzer, int arg_is_orig) +TCP_Endpoint::TCP_Endpoint(TCP_Analyzer* arg_analyzer, bool arg_is_orig) { contents_processor = 0; prev_state = state = TCP_ENDPOINT_INACTIVE; @@ -28,7 +28,7 @@ TCP_Endpoint::TCP_Endpoint(TCP_Analyzer* arg_analyzer, int arg_is_orig) contents_start_seq = 0; FIN_seq = 0; SYN_cnt = FIN_cnt = RST_cnt = 0; - did_close = 0; + did_close = false; contents_file = 0; tcp_analyzer = arg_analyzer; is_orig = arg_is_orig; @@ -75,7 +75,7 @@ void TCP_Endpoint::SetPeer(TCP_Endpoint* p) sessions->tcp_stats.StateEntered(state, peer->state); } -int TCP_Endpoint::HadGap() const +bool TCP_Endpoint::HadGap() const { return contents_processor && contents_processor->HadGap(); } @@ -90,20 +90,20 @@ void TCP_Endpoint::AddReassembler(TCP_Reassembler* arg_contents_processor) contents_processor->SetContentsFile(contents_file); } -int TCP_Endpoint::DataPending() const +bool TCP_Endpoint::DataPending() const { if ( contents_processor ) return contents_processor->DataPending(); else - return 0; + return false; } -int TCP_Endpoint::HasUndeliveredData() const +bool TCP_Endpoint::HasUndeliveredData() const { if ( contents_processor ) return contents_processor->HasUndeliveredData(); else - return 0; + return false; } void TCP_Endpoint::CheckEOF() @@ -121,7 +121,7 @@ void TCP_Endpoint::SizeBufferedData(uint64_t& waiting_on_hole, waiting_on_hole = waiting_on_ack = 0; } -int TCP_Endpoint::ValidChecksum(const struct tcphdr* tp, int len) const +bool TCP_Endpoint::ValidChecksum(const struct tcphdr* tp, int len) const { uint32_t sum = checksum_base; int tcp_len = tp->th_off * 4 + len; @@ -199,11 +199,11 @@ uint64_t TCP_Endpoint::Size() const return size; } -int TCP_Endpoint::DataSent(double t, uint64_t seq, int len, int caplen, +bool TCP_Endpoint::DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, const IP_Hdr* ip, const struct tcphdr* tp) { - int status = 0; + bool status = false; if ( contents_processor ) { @@ -267,7 +267,7 @@ void TCP_Endpoint::SetContentsFile(BroFile* f) contents_processor->SetContentsFile(contents_file); } -int TCP_Endpoint::CheckHistory(uint32_t mask, char code) +bool TCP_Endpoint::CheckHistory(uint32_t mask, char code) { if ( ! IsOrig() ) { diff --git a/src/analyzer/protocol/tcp/TCP_Endpoint.h b/src/analyzer/protocol/tcp/TCP_Endpoint.h index 60ec19a5da..79c9ee2849 100644 --- a/src/analyzer/protocol/tcp/TCP_Endpoint.h +++ b/src/analyzer/protocol/tcp/TCP_Endpoint.h @@ -27,7 +27,7 @@ typedef enum { // One endpoint of a TCP connection. class TCP_Endpoint { public: - TCP_Endpoint(TCP_Analyzer* analyzer, int is_orig); + TCP_Endpoint(TCP_Analyzer* analyzer, bool is_orig); ~TCP_Endpoint(); void Done(); @@ -39,7 +39,7 @@ public: EndpointState State() const { return state; } void SetState(EndpointState new_state); uint64_t Size() const; - int IsActive() const + bool IsActive() const { return state != TCP_ENDPOINT_INACTIVE && ! did_close; } double StartTime() const { return start_time; } @@ -132,7 +132,7 @@ public: // True if none of this endpoint's data has been acknowledged. // We allow for possibly one octet being ack'd in the case of // an initial SYN exchange. - int NoDataAcked() const + bool NoDataAcked() const { uint64_t ack = ToFullSeqSpace(ack_seq, ack_wraps); uint64_t start = static_cast(StartSeqI64()); @@ -141,17 +141,17 @@ public: Connection* Conn() const; - int HasContents() const { return contents_processor != 0; } - int HadGap() const; + bool HasContents() const { return contents_processor != 0; } + bool HadGap() const; - inline int IsOrig() const { return is_orig; } + inline bool IsOrig() const { return is_orig; } - int HasDoneSomething() const { return last_time != 0.0; } + bool HasDoneSomething() const { return last_time != 0.0; } void AddReassembler(TCP_Reassembler* contents_processor); - int DataPending() const; - int HasUndeliveredData() const; + bool DataPending() const; + bool HasUndeliveredData() const; void CheckEOF(); // Returns the volume of data buffered in the reassembler. @@ -166,7 +166,7 @@ public: // WARNING: this is an O(n) operation and potentially very slow. void SizeBufferedData(uint64_t& waiting_on_hole, uint64_t& waiting_on_ack); - int ValidChecksum(const struct tcphdr* tp, int len) const; + bool ValidChecksum(const struct tcphdr* tp, int len) const; // Called to inform endpoint that it has generated a checksum error. void ChecksumError(); @@ -182,7 +182,7 @@ public: // Returns true if the data was used (and hence should be recorded // in the save file), false otherwise. - int DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, + bool DataSent(double t, uint64_t seq, int len, int caplen, const u_char* data, const IP_Hdr* ip, const struct tcphdr* tp); void AckReceived(uint64_t seq); @@ -203,7 +203,7 @@ public: #define HIST_CORRUPT_PKT 0x80 #define HIST_RXMIT 0x100 #define HIST_WIN0 0x200 - int CheckHistory(uint32_t mask, char code); + bool CheckHistory(uint32_t mask, char code); void AddHistory(char code); //### combine into a set of flags: @@ -224,8 +224,8 @@ public: uint64_t contents_start_seq; // relative seq # where contents file starts uint64_t FIN_seq; // relative seq # to start_seq int SYN_cnt, FIN_cnt, RST_cnt; - int did_close; // whether we've reported it closing - int is_orig; + bool did_close; // whether we've reported it closing + bool is_orig; // Relative sequence numbers associated with last control packets. // Used to determine whether ones seen again are interesting, @@ -253,4 +253,4 @@ protected: #define ENDIAN_BIG 2 #define ENDIAN_CONFUSED 3 -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.cc b/src/analyzer/protocol/tcp/TCP_Reassembler.cc index 61166f82fb..f77cbda026 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.cc +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.cc @@ -453,8 +453,8 @@ void TCP_Reassembler::Overlap(const u_char* b1, const u_char* b2, uint64_t n) // we've ever seen for the connection. (n > 1 || endp->peer->HasDoneSomething()) ) { - BroString* b1_s = new BroString((const u_char*) b1, n, 0); - BroString* b2_s = new BroString((const u_char*) b2, n, 0); + BroString* b1_s = new BroString((const u_char*) b1, n, false); + BroString* b2_s = new BroString((const u_char*) b2, n, false); tcp_analyzer->EnqueueConnEvent(rexmit_inconsistency, IntrusivePtr{AdoptRef{}, tcp_analyzer->BuildConnVal()}, @@ -473,7 +473,7 @@ void TCP_Reassembler::Deliver(uint64_t seq, int len, const u_char* data) dst_analyzer->ForwardStream(len, data, IsOrig()); } -int TCP_Reassembler::DataSent(double t, uint64_t seq, int len, +bool TCP_Reassembler::DataSent(double t, uint64_t seq, int len, const u_char* data, TCP_Flags arg_flags, bool replaying) { uint64_t ack = endp->ToRelativeSeqSpace(endp->AckSeq(), endp->AckWraps()); @@ -486,13 +486,13 @@ int TCP_Reassembler::DataSent(double t, uint64_t seq, int len, } if ( skip_deliveries ) - return 0; + return false; if ( seq < ack && ! replaying ) { if ( upper_seq <= ack ) // We've already delivered this and it's been acked. - return 0; + return false; // We've seen an ack for part of this packet, but not the // whole thing. This can happen when, for example, a previous @@ -525,7 +525,7 @@ int TCP_Reassembler::DataSent(double t, uint64_t seq, int len, skip_deliveries = true; } - return 1; + return true; } @@ -647,19 +647,19 @@ void TCP_Reassembler::SkipToSeq(uint64_t seq) } } -int TCP_Reassembler::DataPending() const +bool TCP_Reassembler::DataPending() const { // If we are skipping deliveries, the reassembler will not get called // in DataSent(), and DataSeq() will not be updated. if ( skip_deliveries ) - return 0; + return false; uint64_t delivered_seq = Endpoint()->StartSeqI64() + DataSeq(); uint64_t last_seq = TCP_Endpoint::ToFullSeqSpace(Endpoint()->LastSeq(), Endpoint()->SeqWraps()); if ( last_seq < delivered_seq ) - return 0; + return false; // Q. Can we say that? // ASSERT(delivered_seq <= last_seq); @@ -676,12 +676,12 @@ int TCP_Reassembler::DataPending() const // sequence space), or right at it (because a RST does not). if ( delivered_seq != last_seq - 1 && delivered_seq != last_seq ) - return 1; + return true; // If we've sent RST, then we can't send ACKs any more. if ( Endpoint()->state != TCP_ENDPOINT_RESET && Endpoint()->peer->HasUndeliveredData() ) - return 1; + return true; - return 0; + return false; } diff --git a/src/analyzer/protocol/tcp/TCP_Reassembler.h b/src/analyzer/protocol/tcp/TCP_Reassembler.h index 3137160f36..d519da5497 100644 --- a/src/analyzer/protocol/tcp/TCP_Reassembler.h +++ b/src/analyzer/protocol/tcp/TCP_Reassembler.h @@ -60,7 +60,7 @@ public: // Can be used to skip HTTP data for performance considerations. void SkipToSeq(uint64_t seq); - int DataSent(double t, uint64_t seq, int len, const u_char* data, + bool DataSent(double t, uint64_t seq, int len, const u_char* data, analyzer::tcp::TCP_Flags flags, bool replaying=true); void AckReceived(uint64_t seq); @@ -69,9 +69,9 @@ public: // when so. void CheckEOF(); - int HasUndeliveredData() const { return HasBlocks(); } - int HadGap() const { return had_gap; } - int DataPending() const; + bool HasUndeliveredData() const { return HasBlocks(); } + bool HadGap() const { return had_gap; } + bool DataPending() const; uint64_t DataSeq() const { return LastReassemSeq(); } void DeliverBlock(uint64_t seq, int len, const u_char* data); @@ -80,7 +80,7 @@ public: TCP_Endpoint* Endpoint() { return endp; } const TCP_Endpoint* Endpoint() const { return endp; } - int IsOrig() const { return endp->IsOrig(); } + bool IsOrig() const { return endp->IsOrig(); } bool IsSkippedContents(uint64_t seq, int length) const { return seq + length <= seq_to_skip; } diff --git a/src/analyzer/protocol/teredo/Teredo.cc b/src/analyzer/protocol/teredo/Teredo.cc index 7f2b134b54..2089fd3f3e 100644 --- a/src/analyzer/protocol/teredo/Teredo.cc +++ b/src/analyzer/protocol/teredo/Teredo.cc @@ -119,9 +119,9 @@ RecordVal* TeredoEncapsulation::BuildVal(const IP_Hdr* inner) const uint64_t nonce = ntohll(*((uint64_t*)(auth + 4 + id_len + au_len))); uint8_t conf = *((uint8_t*)(auth + 4 + id_len + au_len + 8)); teredo_auth->Assign(0, make_intrusive( - new BroString(auth + 4, id_len, 1))); + new BroString(auth + 4, id_len, true))); teredo_auth->Assign(1, make_intrusive( - new BroString(auth + 4 + id_len, au_len, 1))); + new BroString(auth + 4 + id_len, au_len, true))); teredo_auth->Assign(2, val_mgr->GetCount(nonce)); teredo_auth->Assign(3, val_mgr->GetCount(conf)); teredo_hdr->Assign(0, teredo_auth); diff --git a/src/analyzer/protocol/udp/UDP.cc b/src/analyzer/protocol/udp/UDP.cc index 04bbe31259..faaee88075 100644 --- a/src/analyzer/protocol/udp/UDP.cc +++ b/src/analyzer/protocol/udp/UDP.cc @@ -207,14 +207,14 @@ void UDP_Analyzer::UpdateConnVal(RecordVal *conn_val) RecordVal *orig_endp = conn_val->Lookup("orig")->AsRecordVal(); RecordVal *resp_endp = conn_val->Lookup("resp")->AsRecordVal(); - UpdateEndpointVal(orig_endp, 1); - UpdateEndpointVal(resp_endp, 0); + UpdateEndpointVal(orig_endp, true); + UpdateEndpointVal(resp_endp, false); // Call children's UpdateConnVal Analyzer::UpdateConnVal(conn_val); } -void UDP_Analyzer::UpdateEndpointVal(RecordVal* endp, int is_orig) +void UDP_Analyzer::UpdateEndpointVal(RecordVal* endp, bool is_orig) { bro_int_t size = is_orig ? request_len : reply_len; if ( size < 0 ) @@ -232,7 +232,7 @@ void UDP_Analyzer::UpdateEndpointVal(RecordVal* endp, int is_orig) bool UDP_Analyzer::IsReuse(double /* t */, const u_char* /* pkt */) { - return 0; + return false; } unsigned int UDP_Analyzer::MemoryAllocation() const diff --git a/src/analyzer/protocol/udp/UDP.h b/src/analyzer/protocol/udp/UDP.h index 57ae23c7b6..adaa65bbf1 100644 --- a/src/analyzer/protocol/udp/UDP.h +++ b/src/analyzer/protocol/udp/UDP.h @@ -39,7 +39,7 @@ protected: bro_int_t request_len, reply_len; private: - void UpdateEndpointVal(RecordVal* endp, int is_orig); + void UpdateEndpointVal(RecordVal* endp, bool is_orig); #define HIST_ORIG_DATA_PKT 0x1 #define HIST_RESP_DATA_PKT 0x2 @@ -51,4 +51,4 @@ private: uint32_t rep_chk_cnt, rep_chk_thresh; }; -} } // namespace analyzer::* +} } // namespace analyzer::* diff --git a/src/file_analysis/AnalyzerSet.cc b/src/file_analysis/AnalyzerSet.cc index e2eed8e4ac..2c4dc50189 100644 --- a/src/file_analysis/AnalyzerSet.cc +++ b/src/file_analysis/AnalyzerSet.cc @@ -166,7 +166,7 @@ HashKey* AnalyzerSet::GetKey(const file_analysis::Tag& t, RecordVal* args) const ListVal* lv = new ListVal(TYPE_ANY); lv->Append(t.AsEnumVal()->Ref()); lv->Append(args->Ref()); - HashKey* key = analyzer_hash->ComputeHash(lv, 1); + HashKey* key = analyzer_hash->ComputeHash(lv, true); Unref(lv); if ( ! key ) reporter->InternalError("AnalyzerArgs type mismatch"); diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index 9ea5d3370b..045c5c8026 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -301,7 +301,7 @@ bool File::SetMime(const string& mime_type) auto meta = make_intrusive(fa_metadata_type); meta->Assign(meta_mime_type_idx, make_intrusive(mime_type)); - meta->Assign(meta_inferred_idx, val_mgr->GetBool(0)); + meta->Assign(meta_inferred_idx, val_mgr->GetFalse()); FileEvent(file_sniff, {IntrusivePtr{NewRef{}, val}, std::move(meta)}); return true; @@ -352,7 +352,7 @@ bool File::BufferBOF(const u_char* data, uint64_t len) uint64_t desired_size = LookupFieldDefaultCount(bof_buffer_size_idx); - bof_buffer.chunks.push_back(new BroString(data, len, 0)); + bof_buffer.chunks.push_back(new BroString(data, len, false)); bof_buffer.size += len; if ( bof_buffer.size < desired_size ) diff --git a/src/file_analysis/FileTimer.cc b/src/file_analysis/FileTimer.cc index 015915c36b..b43a5de677 100644 --- a/src/file_analysis/FileTimer.cc +++ b/src/file_analysis/FileTimer.cc @@ -13,7 +13,7 @@ FileTimer::FileTimer(double t, const string& id, double interval) interval, file_id.c_str()); } -void FileTimer::Dispatch(double t, int is_expire) +void FileTimer::Dispatch(double t, bool is_expire) { File* file = file_mgr->LookupFile(file_id); diff --git a/src/file_analysis/FileTimer.h b/src/file_analysis/FileTimer.h index 32ddd4fb9c..605fc2b8a8 100644 --- a/src/file_analysis/FileTimer.h +++ b/src/file_analysis/FileTimer.h @@ -30,7 +30,7 @@ public: * @param t current unix time * @param is_expire true if all pending timers are being expired. */ - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; private: string file_id; diff --git a/src/file_analysis/analyzer/data_event/DataEvent.cc b/src/file_analysis/analyzer/data_event/DataEvent.cc index b8e00ff9b7..4277ee1dda 100644 --- a/src/file_analysis/analyzer/data_event/DataEvent.cc +++ b/src/file_analysis/analyzer/data_event/DataEvent.cc @@ -44,7 +44,7 @@ bool DataEvent::DeliverChunk(const u_char* data, uint64_t len, uint64_t offset) mgr.Enqueue(chunk_event, IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - make_intrusive(new BroString(data, len, 0)), + make_intrusive(new BroString(data, len, false)), IntrusivePtr{AdoptRef{}, val_mgr->GetCount(offset)} ); @@ -57,7 +57,7 @@ bool DataEvent::DeliverStream(const u_char* data, uint64_t len) mgr.Enqueue(stream_event, IntrusivePtr{NewRef{}, GetFile()->GetVal()}, - make_intrusive(new BroString(data, len, 0)) + make_intrusive(new BroString(data, len, false)) ); return true; diff --git a/src/file_analysis/analyzer/x509/X509.cc b/src/file_analysis/analyzer/x509/X509.cc index ee19cb29fc..6085bbdf6a 100644 --- a/src/file_analysis/analyzer/x509/X509.cc +++ b/src/file_analysis/analyzer/x509/X509.cc @@ -290,7 +290,7 @@ void file_analysis::X509::ParseBasicConstraints(X509_EXTENSION* ex) if ( x509_ext_basic_constraints ) { auto pBasicConstraint = make_intrusive(BifType::Record::X509::BasicConstraints); - pBasicConstraint->Assign(0, val_mgr->GetBool(constr->ca ? 1 : 0)); + pBasicConstraint->Assign(0, val_mgr->GetBool(constr->ca)); if ( constr->pathlen ) pBasicConstraint->Assign(1, val_mgr->GetCount((int32_t) ASN1_INTEGER_get(constr->pathlen))); @@ -344,7 +344,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) VectorVal* uris = 0; VectorVal* ips = 0; - unsigned int otherfields = 0; + bool otherfields = false; for ( int i = 0; i < sk_GENERAL_NAME_num(altname); i++ ) { @@ -415,7 +415,7 @@ void file_analysis::X509::ParseSAN(X509_EXTENSION* ext) { // reporter->Error("Subject alternative name contained unsupported fields. fuid %s", GetFile()->GetID().c_str()); // This happens quite often - just mark it - otherfields = 1; + otherfields = true; continue; } } diff --git a/src/file_analysis/analyzer/x509/functions.bif b/src/file_analysis/analyzer/x509/functions.bif index 7b4819e213..bdea24a15c 100644 --- a/src/file_analysis/analyzer/x509/functions.bif +++ b/src/file_analysis/analyzer/x509/functions.bif @@ -623,7 +623,7 @@ function sct_verify%(cert: opaque of x509, logid: string, log_key: string, signa if ( precert && issuer_key_hash->Len() != 32) { reporter->Error("Invalid issuer_key_hash length"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } std::string data; @@ -647,7 +647,7 @@ function sct_verify%(cert: opaque of x509, logid: string, log_key: string, signa if ( pos < 0 ) { reporter->Error("NID_ct_precert_scts not found"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } #else int num_ext = X509_get_ext_count(x); @@ -751,7 +751,7 @@ sct_verify_err: EVP_PKEY_free(key); reporter->Error("%s", errstr.c_str()); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); %} diff --git a/src/input/Manager.cc b/src/input/Manager.cc index 010d4f88fa..6c4fe3e9d0 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -224,9 +224,9 @@ ReaderBackend* Manager::CreateBackend(ReaderFrontend* frontend, EnumVal* tag) bool Manager::CreateStream(Stream* info, RecordVal* description) { RecordType* rtype = description->Type()->AsRecordType(); - if ( ! ( same_type(rtype, BifType::Record::Input::TableDescription, 0) - || same_type(rtype, BifType::Record::Input::EventDescription, 0) - || same_type(rtype, BifType::Record::Input::AnalysisDescription, 0) ) ) + if ( ! ( same_type(rtype, BifType::Record::Input::TableDescription, false) + || same_type(rtype, BifType::Record::Input::EventDescription, false) + || same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) ) { reporter->Error("Stream description argument not of right type for new input stream"); return false; @@ -311,7 +311,7 @@ bool Manager::CreateStream(Stream* info, RecordVal* description) bool Manager::CreateEventStream(RecordVal* fval) { RecordType* rtype = fval->Type()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::EventDescription, 0) ) + if ( ! same_type(rtype, BifType::Record::Input::EventDescription, false) ) { reporter->Error("EventDescription argument not of right type"); return false; @@ -344,13 +344,13 @@ bool Manager::CreateEventStream(RecordVal* fval) return false; } - if ( ! same_type((*args)[1], BifType::Enum::Input::Event, 0) ) + if ( ! same_type((*args)[1], BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Event's second attribute must be of type Input::Event", stream_name.c_str()); return false; } - if ( ! same_type((*args)[0], BifType::Record::Input::EventDescription, 0) ) + if ( ! same_type((*args)[0], BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -464,7 +464,7 @@ bool Manager::CreateEventStream(RecordVal* fval) bool Manager::CreateTableStream(RecordVal* fval) { RecordType* rtype = fval->Type()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::TableDescription, 0) ) + if ( ! same_type(rtype, BifType::Record::Input::TableDescription, false) ) { reporter->Error("TableDescription argument not of right type"); return false; @@ -571,13 +571,13 @@ bool Manager::CreateTableStream(RecordVal* fval) return false; } - if ( ! same_type((*args)[0], BifType::Record::Input::TableDescription, 0) ) + if ( ! same_type((*args)[0], BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Table event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! same_type((*args)[1], BifType::Enum::Input::Event, 0) ) + if ( ! same_type((*args)[1], BifType::Enum::Input::Event, false) ) { reporter->Error("Input stream %s: Table event's second attribute must be of type Input::Event", stream_name.c_str()); return false; @@ -718,13 +718,13 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( table && ! same_type((*args)[0], BifType::Record::Input::TableDescription, 0) ) + if ( table && ! same_type((*args)[0], BifType::Record::Input::TableDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::TableDescription", stream_name.c_str()); return false; } - if ( ! table && ! same_type((*args)[0], BifType::Record::Input::EventDescription, 0) ) + if ( ! table && ! same_type((*args)[0], BifType::Record::Input::EventDescription, false) ) { reporter->Error("Input stream %s: Error event's first attribute must be of type Input::EventDescription", stream_name.c_str()); return false; @@ -736,7 +736,7 @@ bool Manager::CheckErrorEventTypes(const std::string& stream_name, const Func* e return false; } - if ( ! same_type((*args)[2], BifType::Enum::Reporter::Level, 0) ) + if ( ! same_type((*args)[2], BifType::Enum::Reporter::Level, false) ) { reporter->Error("Input stream %s: Error event's third attribute must be of type Reporter::Level", stream_name.c_str()); return false; @@ -749,7 +749,7 @@ bool Manager::CreateAnalysisStream(RecordVal* fval) { RecordType* rtype = fval->Type()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Input::AnalysisDescription, 0) ) + if ( ! same_type(rtype, BifType::Record::Input::AnalysisDescription, false) ) { reporter->Error("AnalysisDescription argument not of right type"); return false; @@ -1536,7 +1536,7 @@ int Manager::PutTable(Stream* i, const Value* const *vals) assert(i->stream_type == TABLE_STREAM); TableStream* stream = (TableStream*) i; - bool convert_error = 0; + bool convert_error = false; Val* idxval = ValueToIndexVal(i, stream->num_idx_fields, stream->itype, vals, convert_error); Val* valval; @@ -2276,7 +2276,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, BroType* request_typ case TYPE_STRING: { - BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, 1); + BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, true); return new StringVal(s); } @@ -2424,7 +2424,7 @@ Val* Manager::ValueToVal(const Stream* i, const Value* val, bool& have_error) co case TYPE_STRING: { - BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, 1); + BroString *s = new BroString((const u_char*)val->val.string_val.data, val->val.string_val.length, true); return new StringVal(s); } diff --git a/src/iosource/Packet.cc b/src/iosource/Packet.cc index 48f9bc4f3f..96a9816dd0 100644 --- a/src/iosource/Packet.cc +++ b/src/iosource/Packet.cc @@ -19,7 +19,7 @@ extern "C" { } void Packet::Init(int arg_link_type, pkt_timeval *arg_ts, uint32_t arg_caplen, - uint32_t arg_len, const u_char *arg_data, int arg_copy, + uint32_t arg_len, const u_char *arg_data, bool arg_copy, std::string arg_tag) { if ( data && copy ) @@ -595,7 +595,7 @@ RecordVal* Packet::BuildPktHdrVal() const RecordVal* pkt_hdr = new RecordVal(raw_pkt_hdr_type); RecordVal* l2_hdr = new RecordVal(l2_hdr_type); - int is_ethernet = (link_type == DLT_EN10MB) ? 1 : 0; + bool is_ethernet = link_type == DLT_EN10MB; int l3 = BifEnum::L3_UNKNOWN; diff --git a/src/iosource/Packet.h b/src/iosource/Packet.h index 70a745383a..4913514678 100644 --- a/src/iosource/Packet.h +++ b/src/iosource/Packet.h @@ -57,7 +57,7 @@ public: * differentiating the input streams. */ Packet(int link_type, pkt_timeval *ts, uint32_t caplen, - uint32_t len, const u_char *data, int copy = false, + uint32_t len, const u_char *data, bool copy = false, std::string tag = std::string("")) : data(0), l2_src(0), l2_dst(0) { @@ -105,7 +105,7 @@ public: * differentiating the input streams. */ void Init(int link_type, pkt_timeval *ts, uint32_t caplen, - uint32_t len, const u_char *data, int copy = false, + uint32_t len, const u_char *data, bool copy = false, std::string tag = std::string("")); /** diff --git a/src/logging/Manager.cc b/src/logging/Manager.cc index 8b5021b3f1..e85990e6c8 100644 --- a/src/logging/Manager.cc +++ b/src/logging/Manager.cc @@ -230,7 +230,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) { RecordType* rtype = sval->Type()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Log::Stream, 0) ) + if ( ! same_type(rtype, BifType::Record::Log::Stream, false) ) { reporter->Error("sval argument not of right type"); return false; @@ -288,7 +288,7 @@ bool Manager::CreateStream(EnumVal* id, RecordVal* sval) if ( ! same_type((*args)[0], columns) ) { reporter->Error("stream event's argument type does not match column record type"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } } @@ -533,7 +533,7 @@ bool Manager::AddFilter(EnumVal* id, RecordVal* fval) { RecordType* rtype = fval->Type()->AsRecordType(); - if ( ! same_type(rtype, BifType::Record::Log::Filter, 0) ) + if ( ! same_type(rtype, BifType::Record::Log::Filter, false) ) { reporter->Error("filter argument not of right type"); return false; @@ -1401,7 +1401,7 @@ public: ~RotationTimer(); - void Dispatch(double t, int is_expire); + void Dispatch(double t, bool is_expire) override; protected: Manager::WriterInfo* winfo; @@ -1414,7 +1414,7 @@ RotationTimer::~RotationTimer() winfo->rotation_timer = 0; } -void RotationTimer::Dispatch(double t, int is_expire) +void RotationTimer::Dispatch(double t, bool is_expire) { winfo->rotation_timer = 0; diff --git a/src/probabilistic/Topk.cc b/src/probabilistic/Topk.cc index 94c357357a..de3643a65d 100644 --- a/src/probabilistic/Topk.cc +++ b/src/probabilistic/Topk.cc @@ -34,7 +34,7 @@ void TopkVal::Typify(BroType* t) HashKey* TopkVal::GetHash(Val* v) const { - HashKey* key = hash->ComputeHash(v, 1); + HashKey* key = hash->ComputeHash(v, true); assert(key); return key; } diff --git a/src/probabilistic/cardinality-counter.bif b/src/probabilistic/cardinality-counter.bif index dea6581df2..d1e1a2836b 100644 --- a/src/probabilistic/cardinality-counter.bif +++ b/src/probabilistic/cardinality-counter.bif @@ -45,17 +45,17 @@ function hll_cardinality_add%(handle: opaque of cardinality, elem: any%): bool if ( ! cv->Type() && ! cv->Typify(elem->Type()) ) { reporter->Error("failed to set HLL type"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } else if ( ! same_type(cv->Type(), elem->Type()) ) { reporter->Error("incompatible HLL data type"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } cv->Add(elem); - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} ## Merges a HLL cardinality counter into another. @@ -82,7 +82,7 @@ function hll_cardinality_merge_into%(handle1: opaque of cardinality, handle2: op ! same_type(v1->Type(), v2->Type()) ) { reporter->Error("incompatible HLL types"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } CardinalityCounter* h1 = v1->Get(); @@ -92,10 +92,10 @@ function hll_cardinality_merge_into%(handle1: opaque of cardinality, handle2: op if ( ! res ) { reporter->Error("Cardinality counters with different parameters cannot be merged"); - return val_mgr->GetBool(0); + return val_mgr->GetFalse(); } - return val_mgr->GetBool(1); + return val_mgr->GetTrue(); %} ## Estimate the current cardinality of an HLL cardinality counter. diff --git a/src/supervisor/Supervisor.cc b/src/supervisor/Supervisor.cc index a8af880138..fd96a15874 100644 --- a/src/supervisor/Supervisor.cc +++ b/src/supervisor/Supervisor.cc @@ -145,7 +145,7 @@ ParentProcessCheckTimer::ParentProcessCheckTimer(double t, double arg_interval) { } -void ParentProcessCheckTimer::Dispatch(double t, int is_expire) +void ParentProcessCheckTimer::Dispatch(double t, bool is_expire) { // Note: only simple + portable way of detecting loss of parent // process seems to be polling for change in PPID. There's platform diff --git a/src/supervisor/Supervisor.h b/src/supervisor/Supervisor.h index 36d00f1808..d7de0d0c2b 100644 --- a/src/supervisor/Supervisor.h +++ b/src/supervisor/Supervisor.h @@ -406,7 +406,7 @@ public: protected: - void Dispatch(double t, int is_expire) override; + void Dispatch(double t, bool is_expire) override; double interval; }; diff --git a/src/threading/Manager.cc b/src/threading/Manager.cc index 7c8b9fd1a2..e5562a0ddd 100644 --- a/src/threading/Manager.cc +++ b/src/threading/Manager.cc @@ -8,7 +8,7 @@ using namespace threading; -void HeartbeatTimer::Dispatch(double t, int is_expire) +void HeartbeatTimer::Dispatch(double t, bool is_expire) { if ( is_expire ) return; diff --git a/src/threading/Manager.h b/src/threading/Manager.h index 55724b6fab..146420aca6 100644 --- a/src/threading/Manager.h +++ b/src/threading/Manager.h @@ -14,7 +14,7 @@ public: HeartbeatTimer(double t) : Timer(t, TIMER_THREAD_HEARTBEAT) {} virtual ~HeartbeatTimer() {} - void Dispatch(double t, int is_expire); + void Dispatch(double t, bool is_expire) override; protected: diff --git a/src/zeek.bif b/src/zeek.bif index 8a957165a4..69edd36b34 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -144,7 +144,7 @@ static void do_fmt(const char*& fmt, Val* v, ODesc* d) time_t time = time_t(v->InternalDouble()); struct tm t; - int is_time_fmt = *fmt == 'T'; + bool is_time_fmt = *fmt == 'T'; if ( ! localtime_r(&time, &t) ) s.AddSP(""); diff --git a/src/zeekygen/ScriptInfo.cc b/src/zeekygen/ScriptInfo.cc index a2c41bb300..532a6667ff 100644 --- a/src/zeekygen/ScriptInfo.cc +++ b/src/zeekygen/ScriptInfo.cc @@ -83,7 +83,7 @@ static string make_summary(const string& heading, char underline, char border, { ID* id = (*it)->GetID(); ODesc d; - d.SetQuotes(1); + d.SetQuotes(true); id->DescribeReSTShort(&d); add_summary_rows(d, summary_comment((*it)->GetComments()), &table); } @@ -106,7 +106,7 @@ static string make_redef_summary(const string& heading, char underline, { ID* id = (*it)->GetID(); ODesc d; - d.SetQuotes(1); + d.SetQuotes(true); id->DescribeReSTShort(&d); typedef list redef_list; @@ -389,5 +389,3 @@ time_t ScriptInfo::DoGetModificationTime() const return most_recent; } - -