From a9c940996bac5c61168f06ef61bc20225fb7a65e Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 15 Sep 2011 11:48:41 +0300 Subject: [PATCH] Hide or add proper copy ctor and assignement operator, initialize members via initialization lists --- .../stargazer/plugins/authorization/ao/ao.cpp | 9 +++- .../stargazer/plugins/authorization/ao/ao.h | 43 ++++++++++++------- .../authorization/inetaccess/inetaccess.cpp | 24 ++++++++++- .../authorization/inetaccess/inetaccess.h | 16 +++++++ .../plugins/capture/cap_nf/cap_nf.cpp | 22 +++++----- .../stargazer/plugins/capture/cap_nf/cap_nf.h | 3 ++ .../capture/divert_freebsd/divert_cap.cpp | 5 ++- .../capture/divert_freebsd/divert_cap.h | 3 ++ .../capture/ether_freebsd/ether_cap.cpp | 8 +++- .../plugins/capture/ether_freebsd/ether_cap.h | 3 ++ .../plugins/capture/ether_linux/ether_cap.cpp | 4 +- .../plugins/capture/ether_linux/ether_cap.h | 3 ++ .../plugins/capture/ipq_linux/ipq_cap.cpp | 5 ++- .../plugins/capture/ipq_linux/ipq_cap.h | 3 ++ stglibs/locker.lib/locker.h | 7 ++- stglibs/logger.lib/logger.cpp | 3 +- stglibs/logger.lib/logger.h | 11 +++-- stglibs/pinger.lib/pinger.cpp | 10 ++++- 18 files changed, 142 insertions(+), 40 deletions(-) diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index 7079d7d9..cef272c0 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -70,8 +70,15 @@ return "Always Online authorizator v.1.0"; } //----------------------------------------------------------------------------- AUTH_AO::AUTH_AO() - : users(NULL), + : errorStr(), + users(NULL), + usersList(), isRunning(false), + settings(), + BeforeChgAONotifierList(), + AfterChgAONotifierList(), + BeforeChgIPNotifierList(), + AfterChgIPNotifierList(), onAddUserNotifier(*this), onDelUserNotifier(*this) { diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index df21803b..5d17cbff 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -43,26 +43,36 @@ extern "C" PLUGIN * GetPlugin(); class AUTH_AO; class USERS; //----------------------------------------------------------------------------- -template -class CHG_BEFORE_NOTIFIER : public PROPERTY_NOTIFIER_BASE { +template +class CHG_BEFORE_NOTIFIER : public PROPERTY_NOTIFIER_BASE { public: CHG_BEFORE_NOTIFIER(AUTH_AO & a, USER_PTR u) : user(u), auth(a) {} - void Notify(const varParamType & oldValue, const varParamType & newValue); + CHG_BEFORE_NOTIFIER(const CHG_BEFORE_NOTIFIER & rvalue) + : user(rvalue.user), auth(rvalue.auth) + {} + void Notify(const T & oldValue, const T & newValue); USER_PTR GetUser() const { return user; } private: + CHG_BEFORE_NOTIFIER & operator=(const CHG_BEFORE_NOTIFIER & rvalue); + USER_PTR user; const AUTH_AO & auth; }; //----------------------------------------------------------------------------- -template -class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE { +template +class CHG_AFTER_NOTIFIER : public PROPERTY_NOTIFIER_BASE { public: CHG_AFTER_NOTIFIER(AUTH_AO & a, USER_PTR u) : user(u), auth(a) {} - void Notify(const varParamType & oldValue, const varParamType & newValue); + CHG_AFTER_NOTIFIER(const CHG_AFTER_NOTIFIER & rvalue) + : user(rvalue.user), auth(rvalue.auth) + {} + void Notify(const T & oldValue, const T & newValue); USER_PTR GetUser() const { return user; } private: + CHG_AFTER_NOTIFIER & operator=(const CHG_AFTER_NOTIFIER & rvalue); + USER_PTR user; const AUTH_AO & auth; }; @@ -91,6 +101,9 @@ public: int SendMessage(const STG_MSG & msg, uint32_t ip) const; private: + AUTH_AO(const AUTH_AO & rvalue); + AUTH_AO & operator=(const AUTH_AO & rvalue); + void GetUsers(); void SetUserNotifiers(USER_PTR u); void UnSetUserNotifiers(USER_PTR u); @@ -112,13 +125,12 @@ private: public: ADD_USER_NONIFIER(AUTH_AO & a) : auth(a) {} virtual ~ADD_USER_NONIFIER() {} - - void Notify(const USER_PTR & user) - { - auth.AddUser(user); - } + void Notify(const USER_PTR & user) { auth.AddUser(user); } private: + ADD_USER_NONIFIER(const ADD_USER_NONIFIER & rvalue); + ADD_USER_NONIFIER & operator=(const ADD_USER_NONIFIER & rvalue); + AUTH_AO & auth; } onAddUserNotifier; @@ -126,13 +138,12 @@ private: public: DEL_USER_NONIFIER(AUTH_AO & a) : auth(a) {} virtual ~DEL_USER_NONIFIER() {} - - void Notify(const USER_PTR & user) - { - auth.DelUser(user); - } + void Notify(const USER_PTR & user) { auth.DelUser(user); } private: + DEL_USER_NONIFIER(const DEL_USER_NONIFIER & rvalue); + DEL_USER_NONIFIER & operator=(const DEL_USER_NONIFIER & rvalue); + AUTH_AO & auth; } onDelUserNotifier; diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 9fc12ecc..5e468d0f 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -70,6 +70,7 @@ AUTH_IA_SETTINGS::AUTH_IA_SETTINGS() : userDelay(0), userTimeout(0), port(0), + errorStr(), freeMbShowType(freeMbCash) { } @@ -173,13 +174,15 @@ return 0; #ifdef IA_PHASE_DEBUG IA_PHASE::IA_PHASE() : phase(1), + phaseTime(), flog(NULL) { gettimeofday(&phaseTime, NULL); } #else IA_PHASE::IA_PHASE() - : phase(1) + : phase(1), + phaseTime() { gettimeofday(&phaseTime, NULL); } @@ -295,12 +298,29 @@ return phaseTime; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- AUTH_IA::AUTH_IA() - : nonstop(false), + : ctxS(), + errorStr(), + iaSettings(), + settings(), + nonstop(false), isRunningRun(false), isRunningRunTimeouter(false), users(NULL), stgSettings(NULL), + ip2user(), + recvThread(), + timeouterThread(), + mutex(), listenSocket(-1), + connSynAck6(), + connSynAck8(), + disconnSynAck6(), + disconnSynAck8(), + aliveSyn6(), + aliveSyn8(), + fin6(), + fin8(), + packetTypes(), WriteServLog(GetStgLogger()), enabledDirs(0xFFffFFff), onDelUserNotifier(*this) diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index e55733c1..ad1c7fe7 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -120,9 +120,12 @@ struct IA_USER { IA_USER() : login(), user(NULL), + phase(), lastSendAlive(0), rnd(random()), port(0), + ctx(), + messagesToSend(), protoVer(0), password("NO PASSWORD") { @@ -143,6 +146,7 @@ struct IA_USER { lastSendAlive(u.lastSendAlive), rnd(u.rnd), port(u.port), + ctx(), messagesToSend(u.messagesToSend), protoVer(u.protoVer), password(u.password) @@ -191,6 +195,9 @@ struct IA_USER { #ifdef IA_DEBUG bool aliveSent; #endif + +private: + IA_USER & operator=(const IA_USER & rvalue); }; //----------------------------------------------------------------------------- class AUTH_IA_SETTINGS { @@ -221,6 +228,9 @@ public: void Notify(const USER_PTR & user); private: + DEL_USER_NOTIFIER(const DEL_USER_NOTIFIER & rvalue); + DEL_USER_NOTIFIER & operator=(const DEL_USER_NOTIFIER & rvalue); + AUTH_IA & auth; }; //----------------------------------------------------------------------------- @@ -248,6 +258,9 @@ public: int SendMessage(const STG_MSG & msg, uint32_t ip) const; private: + AUTH_IA(const AUTH_IA & rvalue); + AUTH_IA & operator=(const AUTH_IA & rvalue); + static void * Run(void *); static void * RunTimeouter(void * d); int PrepareNet(); @@ -354,11 +367,14 @@ private: class UnauthorizeUser : std::unary_function &, void> { public: UnauthorizeUser(AUTH_IA * a) : auth(a) {} + UnauthorizeUser(const UnauthorizeUser & rvalue) : auth(rvalue.auth) {} void operator()(const std::pair & p) { auth->users->Unauthorize(p.second.user->GetLogin(), auth); } private: + UnauthorizeUser & operator=(const UnauthorizeUser & rvalue); + AUTH_IA * auth; }; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index a572e8a1..9ed50756 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -54,8 +54,9 @@ return cnc.GetPlugin(); NF_CAP::NF_CAP() : traffCnt(NULL), - tidTCP(0), - tidUDP(0), + settings(), + tidTCP(), + tidUDP(), runningTCP(false), runningUDP(false), stoppedTCP(true), @@ -63,7 +64,8 @@ NF_CAP::NF_CAP() portT(0), portU(0), sockTCP(-1), - sockUDP(-1) + sockUDP(-1), + errorStr() { } @@ -373,14 +375,14 @@ for (int i = 0; i < packets; ++i) { NF_DATA * data = reinterpret_cast(buf + 24 + i * 48); - ip.header.ipHeader.ip_v = 4; - ip.header.ipHeader.ip_hl = 5; - ip.header.ipHeader.ip_p = data->proto; + ip.rawPacket.header.ipHeader.ip_v = 4; + ip.rawPacket.header.ipHeader.ip_hl = 5; + ip.rawPacket.header.ipHeader.ip_p = data->proto; ip.dataLen = ntohl(data->octets); - ip.header.ipHeader.ip_src.s_addr = data->srcAddr; - ip.header.ipHeader.ip_dst.s_addr = data->dstAddr; - ip.header.sPort = data->srcPort; - ip.header.dPort = data->dstPort; + ip.rawPacket.header.ipHeader.ip_src.s_addr = data->srcAddr; + ip.rawPacket.header.ipHeader.ip_dst.s_addr = data->dstAddr; + ip.rawPacket.header.sPort = data->srcPort; + ip.rawPacket.header.dPort = data->dstPort; traffCnt->Process(ip); } diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index 3b531353..e6961643 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -106,6 +106,9 @@ public: uint16_t GetStopPosition() const { return STOP_POS; } private: + NF_CAP(const NF_CAP & rvalue); + NF_CAP & operator=(const NF_CAP & rvalue); + TRAFFCOUNTER * traffCnt; MODULE_SETTINGS settings; pthread_t tidTCP; diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 603c5209..98bf1b6c 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -80,7 +80,10 @@ return "Divert_cap v.1.0"; } //----------------------------------------------------------------------------- DIVERT_CAP::DIVERT_CAP() - : port(0), + : settings(), + port(0), + errorStr(), + thread(), nonstop(false), isRunning(false), traffCnt(NULL) diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index 432ee4b1..65ee87d3 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -63,6 +63,9 @@ public: uint16_t GetStopPosition() const { return 10; } private: + DIVERT_CAP(const DIVERT_CAP & rvalue); + DIVERT_CAP & operator=(const DIVERT_CAP & rvalue); + static void * Run(void *); int DivertCapOpen(); diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index 20ca2480..c415e691 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -117,9 +117,15 @@ return "bpf_cap v.1.0"; } //----------------------------------------------------------------------------- BPF_CAP::BPF_CAP() - : nonstop(false), + : capSettings(), + errorStr(), + bpfData(), + polld(), + thread(), + nonstop(false), isRunning(false), capSock(-1), + settings(), traffCnt(NULL) { } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index b51cc56d..8f7e1f2f 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -111,6 +111,9 @@ public: uint16_t GetStopPosition() const { return 10; } private: + BPF_CAP(const BPF_CAP & rvalue); + BPF_CAP & operator=(const BPF_CAP & rvalue); + static void * Run(void *); int BPFCapOpen(); int BPFCapOpen(BPF_DATA * bd); diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index d45b1755..97e9b171 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -72,7 +72,9 @@ return "Ether_cap v.1.2"; } //----------------------------------------------------------------------------- ETHER_CAP::ETHER_CAP() - : nonstop(false), + : errorStr(), + thread(), + nonstop(false), isRunning(false), capSock(-1), traffCnt(NULL) diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index 994fea8a..64560ca4 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -63,6 +63,9 @@ public: uint16_t GetStopPosition() const { return 10; } private: + ETHER_CAP(const ETHER_CAP & rvalue); + ETHER_CAP & operator=(const ETHER_CAP & rvalue); + static void * Run(void *); int EthCapOpen(); int EthCapClose(); diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index de5cd0ed..7f60c7eb 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -54,10 +54,13 @@ return "ipq_cap v.1.2"; //----------------------------------------------------------------------------- IPQ_CAP::IPQ_CAP() : ipq_h(NULL), + errorStr(), + thread(), nonstop(false), isRunning(false), capSock(-1), - traffCnt(NULL) + traffCnt(NULL), + buf() { memset(buf, 0, BUFSIZE); } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 990aae3b..308234b4 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -58,6 +58,9 @@ public: uint16_t GetStopPosition() const { return 10; } private: + IPQ_CAP(const IPQ_CAP & rvalue); + IPQ_CAP & operator=(const IPQ_CAP & rvalue); + static void * Run(void *); int IPQCapOpen(); int IPQCapClose(); diff --git a/stglibs/locker.lib/locker.h b/stglibs/locker.lib/locker.h index 4621388e..7a8d0b8d 100644 --- a/stglibs/locker.lib/locker.h +++ b/stglibs/locker.lib/locker.h @@ -38,9 +38,8 @@ #endif -#include "stg/noncopyable.h" //----------------------------------------------------------------------------- -class STG_LOCKER : private NONCOPYABLE +class STG_LOCKER { public: #ifdef DEBUG_LOCKER @@ -48,6 +47,7 @@ public: : mutex(m), file(__file__), line(__line__), + lockerMutex(), lockID(0) #else STG_LOCKER(pthread_mutex_t * m, const char *, int) @@ -79,6 +79,9 @@ public: #endif }; private: + STG_LOCKER(const STG_LOCKER & rvalue); + STG_LOCKER & operator=(const STG_LOCKER & rvalue); + pthread_mutex_t * mutex; #ifdef DEBUG_LOCKER std::string file; diff --git a/stglibs/logger.lib/logger.cpp b/stglibs/logger.lib/logger.cpp index 18c9de7e..215c6392 100644 --- a/stglibs/logger.lib/logger.cpp +++ b/stglibs/logger.lib/logger.cpp @@ -15,7 +15,8 @@ return logger; } //----------------------------------------------------------------------------- STG_LOGGER::STG_LOGGER() - : fileName() + : fileName(), + mutex() { pthread_mutex_init(&mutex, NULL); } diff --git a/stglibs/logger.lib/logger.h b/stglibs/logger.lib/logger.h index f8375b06..9fe14878 100644 --- a/stglibs/logger.lib/logger.h +++ b/stglibs/logger.lib/logger.h @@ -5,19 +5,21 @@ #include -#include "stg/noncopyable.h" - const char * LogDate(time_t t); //----------------------------------------------------------------------------- class STG_LOGGER; STG_LOGGER & GetStgLogger(); //----------------------------------------------------------------------------- -class STG_LOGGER_LOCKER : private NONCOPYABLE +class STG_LOGGER_LOCKER { public: STG_LOGGER_LOCKER(pthread_mutex_t * m) : mutex(m) { pthread_mutex_lock(mutex); }; ~STG_LOGGER_LOCKER() { pthread_mutex_unlock(mutex); }; + private: + STG_LOGGER_LOCKER(const STG_LOGGER_LOCKER & rvalue); + STG_LOGGER_LOCKER & operator=(const STG_LOGGER_LOCKER & rvalue); + pthread_mutex_t * mutex; }; //----------------------------------------------------------------------------- @@ -32,6 +34,9 @@ public: private: STG_LOGGER(); + STG_LOGGER(const STG_LOGGER & rvalue); + STG_LOGGER & operator=(const STG_LOGGER & rvalue); + const char * LogDate(time_t t); std::string fileName; diff --git a/stglibs/pinger.lib/pinger.cpp b/stglibs/pinger.lib/pinger.cpp index 216b5977..f3686806 100644 --- a/stglibs/pinger.lib/pinger.cpp +++ b/stglibs/pinger.lib/pinger.cpp @@ -30,7 +30,15 @@ STG_PINGER::STG_PINGER(time_t d) isRunningSender(false), sendSocket(-1), recvSocket(-1), - pid(0) + sendThread(), + recvThread(), + pmSend(), + pid(0), + errorStr(), + pingIP(), + ipToAdd(), + ipToDel(), + mutex() { pthread_mutex_init(&mutex, NULL); memset(&pmSend, 0, sizeof(pmSend)); -- 2.43.2