From: Maxim Mamontov Date: Tue, 5 Feb 2013 19:02:01 +0000 (+0200) Subject: Massive refactoring. X-Git-Tag: 2.409~367 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/1347f3d1e04bedd1508589173f577673ee2c5554?hp=73f662acc31034cd98fdc6e157454f7763ef0792 Massive refactoring. --- diff --git a/include/stg/admin.h b/include/stg/admin.h index 7552a1a1..961968a1 100644 --- a/include/stg/admin.h +++ b/include/stg/admin.h @@ -32,7 +32,7 @@ public: virtual const std::string & GetPassword() const = 0; virtual const std::string & GetLogin() const = 0; virtual PRIV const * GetPriv() const = 0; - virtual uint16_t GetPrivAsInt() const = 0; + virtual uint32_t GetPrivAsInt() const = 0; virtual const ADMIN_CONF & GetConf() const = 0; virtual uint32_t GetIP() const = 0; virtual std::string GetIPStr() const = 0; diff --git a/include/stg/notifer.h b/include/stg/notifer.h index 57f9928e..6f213328 100644 --- a/include/stg/notifer.h +++ b/include/stg/notifer.h @@ -12,7 +12,7 @@ template class PROPERTY_NOTIFIER_BASE { public: - virtual ~PROPERTY_NOTIFIER_BASE(){}; + virtual ~PROPERTY_NOTIFIER_BASE(){} virtual void Notify(const varParamType & oldValue, const varParamType & newValue) = 0; }; //----------------------------------------------------------------------------- @@ -20,7 +20,7 @@ template class NOTIFIER_BASE { public: - virtual ~NOTIFIER_BASE(){}; + virtual ~NOTIFIER_BASE(){} virtual void Notify(const varParamType & value) = 0; }; //----------------------------------------------------------------------------- diff --git a/include/stg/plugin.h b/include/stg/plugin.h index 2ecf7af0..114ffc8b 100644 --- a/include/stg/plugin.h +++ b/include/stg/plugin.h @@ -62,7 +62,7 @@ public: virtual int Reload() = 0; virtual bool IsRunning() = 0; virtual const std::string & GetStrError() const = 0; - virtual const std::string GetVersion() const = 0; + virtual std::string GetVersion() const = 0; virtual uint16_t GetStartPosition() const = 0; virtual uint16_t GetStopPosition() const = 0; }; diff --git a/include/stg/raw_ip_packet.h b/include/stg/raw_ip_packet.h index f07bf228..b94faf86 100644 --- a/include/stg/raw_ip_packet.h +++ b/include/stg/raw_ip_packet.h @@ -23,13 +23,6 @@ struct RAW_PACKET memset(rawPacket.pckt, 0, pcktSize); } - RAW_PACKET(const RAW_PACKET & rp) - : rawPacket(), - dataLen(rp.dataLen) - { - memcpy(rawPacket.pckt, rp.rawPacket.pckt, pcktSize); - } - uint16_t GetIPVersion() const; uint8_t GetHeaderLen() const; uint8_t GetProto() const; @@ -40,7 +33,7 @@ uint16_t GetSrcPort() const; uint16_t GetDstPort() const; bool operator==(const RAW_PACKET & rvalue) const; -bool operator!=(const RAW_PACKET & rvalue) const { return !(*this == rvalue); }; +bool operator!=(const RAW_PACKET & rvalue) const { return !(*this == rvalue); } bool operator<(const RAW_PACKET & rvalue) const; union @@ -52,7 +45,7 @@ union // Only for packets without options field uint16_t sPort; uint16_t dPort; - } header __attribute__ ((packed)); + } header; } rawPacket; int32_t dataLen; // IP packet length. Set to -1 to use length field from the header }; @@ -93,14 +86,16 @@ inline uint16_t RAW_PACKET::GetSrcPort() const { if (rawPacket.header.ipHeader.ip_p == 1) // for icmp proto return port 0 return 0; -return ntohs(*((uint16_t*)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4))); +const uint8_t * pos = rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4; +return ntohs(*reinterpret_cast(pos)); } //----------------------------------------------------------------------------- inline uint16_t RAW_PACKET::GetDstPort() const { if (rawPacket.header.ipHeader.ip_p == 1) // for icmp proto return port 0 return 0; -return ntohs(*((uint16_t*)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4 + 2))); +const uint8_t * pos = rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4 + 2; +return ntohs(*reinterpret_cast(pos)); } //----------------------------------------------------------------------------- inline bool RAW_PACKET::operator==(const RAW_PACKET & rvalue) const @@ -113,12 +108,14 @@ if (rawPacket.header.ipHeader.ip_dst.s_addr != rvalue.rawPacket.header.ipHeader. if (rawPacket.header.ipHeader.ip_p != 1 && rvalue.rawPacket.header.ipHeader.ip_p != 1) { - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4)) != - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4))) + const uint8_t * pos = rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4; + const uint8_t * rpos = rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4; + if (*reinterpret_cast(pos) != *reinterpret_cast(rpos)) return false; - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4 + 2)) != - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4 + 2))) + pos += 2; + rpos += 2; + if (*reinterpret_cast(pos) != *reinterpret_cast(rpos)) return false; } @@ -142,18 +139,18 @@ if (rawPacket.header.ipHeader.ip_dst.s_addr > rvalue.rawPacket.header.ipHeader.i if (rawPacket.header.ipHeader.ip_p != 1 && rvalue.rawPacket.header.ipHeader.ip_p != 1) { - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4)) < - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4))) + const uint8_t * pos = rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4; + const uint8_t * rpos = rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4; + if (*reinterpret_cast(pos) < *reinterpret_cast(rpos)) return true; - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4)) > - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4))) + if (*reinterpret_cast(pos) > *reinterpret_cast(rpos)) return false; - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4 + 2)) < - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4 + 2))) + pos += 2; + rpos += 2; + if (*reinterpret_cast(pos) < *reinterpret_cast(rpos)) return true; - if (*((uint16_t *)(rawPacket.pckt + rawPacket.header.ipHeader.ip_hl * 4 + 2)) > - *((uint16_t *)(rvalue.rawPacket.pckt + rvalue.rawPacket.header.ipHeader.ip_hl * 4 + 2))) + if (*reinterpret_cast(pos) > *reinterpret_cast(rpos)) return false; } diff --git a/include/stg/service_conf.h b/include/stg/service_conf.h index ef487f8e..ca58154b 100644 --- a/include/stg/service_conf.h +++ b/include/stg/service_conf.h @@ -17,11 +17,11 @@ SERVICE_CONF(const std::string & n, double c) : name(n), comment(), cost(c), payDay(0) {} SERVICE_CONF(const std::string & n, double c, unsigned p) - : name(n), comment(), cost(c), payDay(p) + : name(n), comment(), cost(c), payDay(static_cast(p)) {} SERVICE_CONF(const std::string & n, double c, unsigned p, const std::string & com) - : name(n), comment(com), cost(c), payDay(p) + : name(n), comment(com), cost(c), payDay(static_cast(p)) {} std::string name; diff --git a/include/stg/store.h b/include/stg/store.h index e966076f..412ed65d 100644 --- a/include/stg/store.h +++ b/include/stg/store.h @@ -79,7 +79,7 @@ public: virtual int EditMessage(const STG_MSG & msg, const std::string & login) const = 0; virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const = 0; virtual int DelMessage(uint64_t id, const std::string & login) const = 0; - virtual int GetMessageHdrs(vector * hdrsList, const std::string & login) const = 0; + virtual int GetMessageHdrs(std::vector * hdrsList, const std::string & login) const = 0; virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const = 0; diff --git a/include/stg/tariffs.h b/include/stg/tariffs.h index 9a35f645..13a3f05c 100644 --- a/include/stg/tariffs.h +++ b/include/stg/tariffs.h @@ -32,6 +32,8 @@ struct TARIFF_DATA; class TARIFFS { public: + typedef std::list Tariffs; + virtual ~TARIFFS() {} virtual int ReadTariffs () = 0; virtual const TARIFF * FindByName(const std::string & name) const = 0; diff --git a/include/stg/user_conf.h b/include/stg/user_conf.h index 70cb4fa7..59933658 100644 --- a/include/stg/user_conf.h +++ b/include/stg/user_conf.h @@ -37,7 +37,7 @@ struct USER_CONF userdata(USERDATA_NUM), creditExpire(0), ips() - {}; + {} std::string password; int passive; @@ -81,7 +81,7 @@ struct USER_CONF_RES creditExpire(), ips() { - }; + } USER_CONF_RES & operator=(const USER_CONF & uc) { @@ -107,7 +107,7 @@ struct USER_CONF_RES creditExpire = uc.creditExpire; ips = uc.ips; return *this; - }; + } operator USER_CONF() const { USER_CONF uc; diff --git a/include/stg/user_ips.h b/include/stg/user_ips.h index a29e2812..e68190c5 100644 --- a/include/stg/user_ips.h +++ b/include/stg/user_ips.h @@ -44,8 +44,6 @@ #include "stg/common.h" #include "os_int.h" -using namespace std; - //------------------------------------------------------------------------- struct IP_MASK { @@ -57,15 +55,18 @@ uint32_t mask; //------------------------------------------------------------------------- class USER_IPS { - friend std::ostream & operator<< (ostream & o, const USER_IPS & i); + friend std::ostream & operator<< (std::ostream & o, const USER_IPS & i); //friend stringstream & operator<< (stringstream & s, const USER_IPS & i); - friend const USER_IPS StrToIPS(const string & ipsStr) throw(string); + friend const USER_IPS StrToIPS(const std::string & ipsStr); public: + typedef std::vector ContainerType; + typedef ContainerType::size_type IndexType; + USER_IPS(); USER_IPS(const USER_IPS &); USER_IPS & operator=(const USER_IPS &); - const IP_MASK & operator[](int idx) const; + const IP_MASK & operator[](IndexType idx) const; std::string GetIpStr() const; bool IsIPInIPS(uint32_t ip) const; bool OnlyOneIP() const; @@ -75,7 +76,7 @@ public: private: uint32_t CalcMask(unsigned int msk) const; - std::vector ips; + ContainerType ips; }; //------------------------------------------------------------------------- @@ -98,7 +99,7 @@ return *this; } //----------------------------------------------------------------------------- inline -const IP_MASK & USER_IPS::operator[](int idx) const +const IP_MASK & USER_IPS::operator[](IndexType idx) const { return ips[idx]; } @@ -116,8 +117,8 @@ if (ips[0].ip == 0) return "*"; } -std::vector::const_iterator it(ips.begin()); -std::stringstream s; +ContainerType::const_iterator it(ips.begin()); +std::ostringstream s; s << inet_ntostring(it->ip); ++it; for (; it != ips.end(); ++it) @@ -130,7 +131,7 @@ return s.str(); inline int USER_IPS::Count() const { -return ips.size(); +return static_cast(ips.size()); } //----------------------------------------------------------------------------- inline @@ -152,7 +153,7 @@ if (ips.empty()) if (ips.front().ip == 0) return true; -for (std::vector::const_iterator it(ips.begin()); it != ips.end(); ++it) +for (ContainerType::const_iterator it(ips.begin()); it != ips.end(); ++it) { uint32_t mask(CalcMask(it->mask)); if ((ip & mask) == (it->ip & mask)) @@ -196,7 +197,7 @@ return s; }*/ //----------------------------------------------------------------------------- inline -const USER_IPS StrToIPS(const std::string & ipsStr) throw(std::string) +const USER_IPS StrToIPS(const std::string & ipsStr) { USER_IPS ips; char * paddr; @@ -215,18 +216,18 @@ if (ipsStr[0] == '*' && ipsStr.size() == 1) return ips; } -char * str = new char[ipsStr.size() + 1]; -strcpy(str, ipsStr.c_str()); -char * pstr = str; +char * tmp = new char[ipsStr.size() + 1]; +strcpy(tmp, ipsStr.c_str()); +char * pstr = tmp; while ((paddr = strtok(pstr, ","))) { pstr = NULL; ipMask.push_back(paddr); } -delete[] str; +delete[] tmp; -for (unsigned int i = 0; i < ipMask.size(); i++) +for (USER_IPS::IndexType i = 0; i < ipMask.size(); i++) { char str[128]; char * strIp; diff --git a/include/stg/user_property.h b/include/stg/user_property.h index 9030d37f..2ff8909c 100644 --- a/include/stg/user_property.h +++ b/include/stg/user_property.h @@ -24,7 +24,7 @@ $Author: faust $ #include "notifer.h" #include "noncopyable.h" -extern const volatile time_t stgTime; +extern volatile time_t stgTime; //----------------------------------------------------------------------------- template @@ -295,8 +295,8 @@ if ((priv->userConf && !isStat) || std::stringstream oldVal; std::stringstream newVal; - oldVal.flags(oldVal.flags() | ios::fixed); - newVal.flags(newVal.flags() | ios::fixed); + oldVal.flags(oldVal.flags() | std::ios::fixed); + newVal.flags(newVal.flags() | std::ios::fixed); oldVal << USER_PROPERTY::ConstData(); newVal << val; @@ -377,7 +377,7 @@ else //------------------------------------------------------------------------- template inline -ostream & operator<< (ostream & stream, const USER_PROPERTY & value) +std::ostream & operator<< (std::ostream & stream, const USER_PROPERTY & value) { return stream << value.ConstData(); } diff --git a/include/stg/user_stat.h b/include/stg/user_stat.h index 42d436fd..54f11dec 100644 --- a/include/stg/user_stat.h +++ b/include/stg/user_stat.h @@ -123,7 +123,7 @@ struct USER_STAT lastCashAddTime(0), passiveTime(0), lastActivityTime(0) - {}; + {} DIR_TRAFF up; DIR_TRAFF down; @@ -161,7 +161,7 @@ struct USER_STAT_RES up = us.up; down = us.down; return * this; - }; + } operator USER_STAT() const { USER_STAT us; @@ -174,7 +174,7 @@ struct USER_STAT_RES us.up = up; us.down = down; return us; - }; + } RESETABLE cash; RESETABLE freeMb; diff --git a/include/stg/user_traff.h b/include/stg/user_traff.h index 7ed16361..aee1171c 100644 --- a/include/stg/user_traff.h +++ b/include/stg/user_traff.h @@ -40,17 +40,20 @@ class DIR_TRAFF friend std::ostream & operator<< (std::ostream & o, const DIR_TRAFF & traff); public: + typedef std::vector ContainerType; + typedef ContainerType::size_type IndexType; + //------------------------------------------------------------------------- DIR_TRAFF(); DIR_TRAFF(const DIR_TRAFF & ts); DIR_TRAFF & operator=(const DIR_TRAFF & ts); ~DIR_TRAFF(); - uint64_t operator[](int idx) const; - uint64_t & operator[](int idx); + uint64_t operator[](IndexType idx) const; + uint64_t & operator[](IndexType idx); DIR_TRAFF operator+(const DIR_TRAFF & ts); private: - std::vector traff; + ContainerType traff; }; //----------------------------------------------------------------------------- @@ -75,19 +78,19 @@ traff = ts.traff; return *this; } //----------------------------------------------------------------------------- -inline uint64_t & DIR_TRAFF::operator[](int idx) +inline uint64_t & DIR_TRAFF::operator[](IndexType idx) { return traff[idx]; } //----------------------------------------------------------------------------- -inline uint64_t DIR_TRAFF::operator[](int idx) const +inline uint64_t DIR_TRAFF::operator[](IndexType idx) const { return traff[idx]; } //----------------------------------------------------------------------------- inline DIR_TRAFF DIR_TRAFF::operator+(const DIR_TRAFF & ts) { -for (int i = 0; i < DIR_NUM; i++) +for (IndexType i = 0; i < DIR_NUM; i++) { traff[i] = traff[i] + ts.traff[i]; } @@ -97,7 +100,7 @@ return *this; inline std::ostream & operator<<(std::ostream & o, const DIR_TRAFF & traff) { bool first = true; -for (size_t i = 0; i < DIR_NUM; ++i) +for (DIR_TRAFF::IndexType i = 0; i < DIR_NUM; ++i) { if (first) first = false; diff --git a/projects/rlm_stg/iface.cpp b/projects/rlm_stg/iface.cpp index 9d6a7833..741017b5 100644 --- a/projects/rlm_stg/iface.cpp +++ b/projects/rlm_stg/iface.cpp @@ -1,7 +1,5 @@ #include "iface.h" -#include "loki/Singleton.h" - #include "thriftclient.h" int stgInstantiateImpl(const char * server, uint16_t port, const char * password) diff --git a/projects/stargazer/actions.h b/projects/stargazer/actions.h index 6c1fc8a8..66b8556d 100644 --- a/projects/stargazer/actions.h +++ b/projects/stargazer/actions.h @@ -41,7 +41,7 @@ public: ACTION(ACTIVE_CLASS & ac, typename ACTOR::TYPE a, DATA_TYPE d) - : activeClass(ac), actor(a), data(d) {}; + : activeClass(ac), actor(a), data(d) {} void Invoke(); private: ACTION(const ACTION & rvalue); diff --git a/projects/stargazer/admin_impl.h b/projects/stargazer/admin_impl.h index 6a608e11..9a2b9781 100644 --- a/projects/stargazer/admin_impl.h +++ b/projects/stargazer/admin_impl.h @@ -43,9 +43,9 @@ public: ADMIN_IMPL(); ADMIN_IMPL(const ADMIN_CONF & ac); ADMIN_IMPL(const PRIV & priv, - const std::string & login, - const std::string & password); - virtual ~ADMIN_IMPL() {}; + const std::string & login, + const std::string & password); + virtual ~ADMIN_IMPL() {} ADMIN_IMPL & operator=(const ADMIN_IMPL &); ADMIN_IMPL & operator=(const ADMIN_CONF &); @@ -54,15 +54,15 @@ public: bool operator<(const ADMIN_IMPL & rhs) const; bool operator<=(const ADMIN_IMPL & rhs) const; - const std::string & GetPassword() const { return conf.password; }; - const std::string & GetLogin() const { return conf.login; }; - PRIV const * GetPriv() const { return &conf.priv; }; - uint16_t GetPrivAsInt() const { return conf.priv.ToInt(); }; - const ADMIN_CONF & GetConf() const { return conf; }; + const std::string & GetPassword() const { return conf.password; } + const std::string & GetLogin() const { return conf.login; } + PRIV const * GetPriv() const { return &conf.priv; } + uint32_t GetPrivAsInt() const { return conf.priv.ToInt(); } + const ADMIN_CONF & GetConf() const { return conf; } void Print() const; - uint32_t GetIP() const { return ip; }; + uint32_t GetIP() const { return ip; } std::string GetIPStr() const; - void SetIP(uint32_t ip) { ADMIN_IMPL::ip = ip; }; + void SetIP(uint32_t v) { ip = v; } const std::string GetLogStr() const; private: diff --git a/projects/stargazer/admins_impl.h b/projects/stargazer/admins_impl.h index cb00368c..48435b75 100644 --- a/projects/stargazer/admins_impl.h +++ b/projects/stargazer/admins_impl.h @@ -73,8 +73,8 @@ private: ADMINS_IMPL(const ADMINS_IMPL & rvalue); ADMINS_IMPL & operator=(const ADMINS_IMPL & rvalue); - typedef list::iterator admin_iter; - typedef list::const_iterator const_admin_iter; + typedef std::list::iterator admin_iter; + typedef std::list::const_iterator const_admin_iter; int Read(); diff --git a/projects/stargazer/corps_impl.cpp b/projects/stargazer/corps_impl.cpp index f926d23a..a366f466 100644 --- a/projects/stargazer/corps_impl.cpp +++ b/projects/stargazer/corps_impl.cpp @@ -48,7 +48,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->corpChg) { - string s = admin->GetLogStr() + " Add corporation \'" + corp.name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Add corporation \'" + corp.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -79,14 +79,14 @@ WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } //----------------------------------------------------------------------------- -int CORPORATIONS_IMPL::Del(const string & name, const ADMIN * admin) +int CORPORATIONS_IMPL::Del(const std::string & name, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); const PRIV * priv = admin->GetPriv(); if (!priv->corpChg) { - string s = admin->GetLogStr() + " Delete corporation \'" + name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Delete corporation \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -101,7 +101,7 @@ if (si == data.end()) return -1; } -map::iterator csi; +std::map::iterator csi; csi = searchDescriptors.begin(); while (csi != searchDescriptors.end()) { @@ -130,7 +130,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->corpChg) { - string s = admin->GetLogStr() + " Change corporation \'" + corp.name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Change corporation \'" + corp.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -162,7 +162,7 @@ return 0; bool CORPORATIONS_IMPL::Read() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -vector corpsList; +std::vector corpsList; if (store->GetCorpsList(&corpsList) < 0) { WriteServLog(store->GetStrError().c_str()); @@ -184,7 +184,7 @@ for (size_t i = 0; i < corpsList.size(); i++) return false; } //----------------------------------------------------------------------------- -bool CORPORATIONS_IMPL::Find(const string & name, CORP_CONF * corp) +bool CORPORATIONS_IMPL::Find(const std::string & name, CORP_CONF * corp) { assert(corp != NULL && "Pointer to corporation is not null"); @@ -203,7 +203,7 @@ if (si != data.end()) return true; } //----------------------------------------------------------------------------- -bool CORPORATIONS_IMPL::Exists(const string & name) const +bool CORPORATIONS_IMPL::Exists(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (data.empty()) diff --git a/projects/stargazer/corps_impl.h b/projects/stargazer/corps_impl.h index e4552424..7bde401b 100644 --- a/projects/stargazer/corps_impl.h +++ b/projects/stargazer/corps_impl.h @@ -58,8 +58,8 @@ private: CORPORATIONS_IMPL(const CORPORATIONS_IMPL & rvalue); CORPORATIONS_IMPL & operator=(const CORPORATIONS_IMPL & rvalue); - typedef list::iterator crp_iter; - typedef list::const_iterator const_crp_iter; + typedef std::list::iterator crp_iter; + typedef std::list::const_iterator const_crp_iter; bool Read(); diff --git a/projects/stargazer/eventloop.h b/projects/stargazer/eventloop.h index 71602795..35de3675 100644 --- a/projects/stargazer/eventloop.h +++ b/projects/stargazer/eventloop.h @@ -12,7 +12,7 @@ class EVENT_LOOP : private NONCOPYABLE, public: bool Start(); bool Stop(); - bool IsRunning() const { return _running; }; + bool IsRunning() const { return _running; } template void Enqueue(ACTIVE_CLASS & ac, @@ -44,8 +44,8 @@ class EVENT_LOOP_SINGLETON : private NONCOPYABLE static EVENT_LOOP * _instance; static void CreateInstance(); - EVENT_LOOP_SINGLETON() {}; - ~EVENT_LOOP_SINGLETON() {}; + EVENT_LOOP_SINGLETON() {} + ~EVENT_LOOP_SINGLETON() {} }; template diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index cabd991b..eb61e2d5 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -60,8 +60,6 @@ #include "pidfile.h" #include "eventloop.h" -using namespace std; - #ifdef DEBUG #define MAIN_DEBUG (1) #define NO_DAEMON (1) @@ -69,7 +67,16 @@ using namespace std; #define START_FILE "/._ST_ART_ED_" -set executersPid; +namespace +{ +std::set executersPid; + +bool StartModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs); +bool StopModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs); +void StartTimer(); +int StartScriptExecuter(char * procName, int msgKey, int * msgID, SETTINGS_IMPL * settings); +int ForkAndWait(const std::string & confDir); +void KillExecuters(); //----------------------------------------------------------------------------- bool StartModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs) @@ -82,7 +89,7 @@ bool StopModCmp(const PLUGIN_RUNNER & lhs, const PLUGIN_RUNNER & rhs) return lhs.GetStopPosition() > rhs.GetStopPosition(); } //----------------------------------------------------------------------------- -static void StartTimer() +void StartTimer() { STG_LOGGER & WriteServLog = GetStgLogger(); @@ -165,14 +172,14 @@ return 0; } //----------------------------------------------------------------------------- #ifndef NO_DAEMON -int ForkAndWait(const string & confDir) +int ForkAndWait(const std::string & confDir) #else -int ForkAndWait(const string &) +int ForkAndWait(const std::string &) #endif { #ifndef NO_DAEMON pid_t childPid = fork(); -string startFile = confDir + START_FILE; +std::string startFile = confDir + START_FILE; unlink(startFile.c_str()); switch (childPid) @@ -209,7 +216,7 @@ return 0; //----------------------------------------------------------------------------- void KillExecuters() { -set::iterator pid; +std::set::iterator pid; pid = executersPid.begin(); while (pid != executersPid.end()) { @@ -219,6 +226,8 @@ while (pid != executersPid.end()) } } //----------------------------------------------------------------------------- +} // namespace anonymous +//----------------------------------------------------------------------------- int main(int argc, char * argv[]) { SETTINGS_IMPL * settings = NULL; @@ -236,10 +245,10 @@ int msgID = -11; WriteServLog.SetLogFileName("/var/log/stargazer.log"); } -vector modSettings; -list modules; +std::vector modSettings; +std::list modules; -list::iterator modIter; +std::list::iterator modIter; if (getuid()) { @@ -264,7 +273,7 @@ if (settings->ReadSettings()) } #ifndef NO_DAEMON -string startFile(settings->GetConfDir() + START_FILE); +std::string startFile(settings->GetConfDir() + START_FILE); #endif if (ForkAndWait(settings->GetConfDir()) < 0) @@ -338,7 +347,7 @@ modSettings = settings->GetModulesSettings(); for (size_t i = 0; i < modSettings.size(); i++) { - string modulePath = settings->GetModulesPath(); + std::string modulePath = settings->GetModulesPath(); modulePath += "/mod_"; modulePath += modSettings[i].moduleName; modulePath += ".so"; @@ -400,7 +409,7 @@ while (modIter != modules.end()) ++modIter; } -srandom(stgTime); +srandom(static_cast(stgTime)); WriteServLog("Stg started successfully."); WriteServLog("+++++++++++++++++++++++++++++++++++++++++++++"); @@ -417,7 +426,7 @@ while (true) bool stop = false; int status; pid_t childPid; - set::iterator it; + std::set::iterator it; switch (sig) { case SIGHUP: diff --git a/projects/stargazer/plugins/authorization/ao/ao.cpp b/projects/stargazer/plugins/authorization/ao/ao.cpp index e3bc192a..9640e2e8 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.cpp +++ b/projects/stargazer/plugins/authorization/ao/ao.cpp @@ -41,7 +41,7 @@ $Author: faust $ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PLUGIN_CREATOR aoc; +static PLUGIN_CREATOR aoc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -53,18 +53,18 @@ return aoc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- template -class IS_CONTAINS_USER: public binary_function +class IS_CONTAINS_USER: public std::binary_function { public: bool operator()(varType notifier, USER_PTR user) const { return notifier.GetUser() == user; - }; + } }; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const string AUTH_AO::GetVersion() const +std::string AUTH_AO::GetVersion() const { return "Always Online authorizator v.1.0"; } @@ -109,7 +109,7 @@ if (!isRunning) users->DelNotifierUserAdd(&onAddUserNotifier); users->DelNotifierUserDel(&onDelUserNotifier); -list::iterator users_iter; +std::list::iterator users_iter; users_iter = usersList.begin(); while (users_iter != usersList.end()) { @@ -153,8 +153,8 @@ void AUTH_AO::UnSetUserNotifiers(USER_PTR u) IS_CONTAINS_USER > IsContainsUserAOB; IS_CONTAINS_USER > IsContainsUserAOA; -list >::iterator aoBIter; -list >::iterator aoAIter; +std::list >::iterator aoBIter; +std::list >::iterator aoAIter; aoBIter = find_if(BeforeChgAONotifierList.begin(), BeforeChgAONotifierList.end(), @@ -181,12 +181,12 @@ if (aoAIter != AfterChgAONotifierList.end()) IS_CONTAINS_USER > IsContainsUserIPB; IS_CONTAINS_USER > IsContainsUserIPA; -list >::iterator ipBIter; -list >::iterator ipAIter; +std::list >::iterator ipBIter; +std::list >::iterator ipAIter; -ipBIter = find_if(BeforeChgIPNotifierList.begin(), - BeforeChgIPNotifierList.end(), - bind2nd(IsContainsUserIPB, u)); +ipBIter = std::find_if(BeforeChgIPNotifierList.begin(), + BeforeChgIPNotifierList.end(), + bind2nd(IsContainsUserIPB, u)); if (ipBIter != BeforeChgIPNotifierList.end()) { diff --git a/projects/stargazer/plugins/authorization/ao/ao.h b/projects/stargazer/plugins/authorization/ao/ao.h index 879c937c..d8b6dc88 100644 --- a/projects/stargazer/plugins/authorization/ao/ao.h +++ b/projects/stargazer/plugins/authorization/ao/ao.h @@ -83,7 +83,7 @@ private: class AUTH_AO : public AUTH { public: AUTH_AO(); - virtual ~AUTH_AO(){}; + virtual ~AUTH_AO(){} void SetUsers(USERS * u) { users = u; } @@ -94,7 +94,7 @@ public: void SetSettings(const MODULE_SETTINGS &) {} int ParseSettings() { return 0; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 30; } uint16_t GetStopPosition() const { return 30; } @@ -118,11 +118,11 @@ private: bool isRunning; MODULE_SETTINGS settings; - list > BeforeChgAONotifierList; - list > AfterChgAONotifierList; + std::list > BeforeChgAONotifierList; + std::list > AfterChgAONotifierList; - list > BeforeChgIPNotifierList; - list > AfterChgIPNotifierList; + std::list > BeforeChgIPNotifierList; + std::list > AfterChgIPNotifierList; class ADD_USER_NONIFIER: public NOTIFIER_BASE { public: diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp index 5a92cff5..dd0102b2 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.cpp @@ -47,16 +47,21 @@ #include "stg/plugin_creator.h" #include "inetaccess.h" -extern volatile const time_t stgTime; - -void InitEncrypt(BLOWFISH_CTX * ctx, const string & password); -void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); -void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); +extern volatile time_t stgTime; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR iac; + +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); +void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8); +void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8); +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -80,7 +85,7 @@ int AUTH_IA_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { int p; PARAM_VALUE pv; -vector::const_iterator pvi; +std::vector::const_iterator pvi; /////////////////////////// pv.param = "Port"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -96,7 +101,7 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) printfd(__FILE__, "Cannot parse parameter 'Port'\n"); return -1; } -port = p; +port = static_cast(p); /////////////////////////// pv.param = "UserDelay"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -130,7 +135,7 @@ if (ParseIntInRange(pvi->value[0], 15, 1200, &userTimeout)) return -1; } ///////////////////////////////////////////////////////////// -string freeMbType; +std::string freeMbType; int n = 0; pv.param = "FreeMb"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -477,7 +482,7 @@ while (ia->nonstop) if ((touchTime + MONITOR_TIME_DELAY_SEC <= stgTime) && ia->stgSettings->GetMonitoring()) { touchTime = stgTime; - string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_r"; + std::string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_r"; TouchFile(monFile.c_str()); } } @@ -497,7 +502,7 @@ AUTH_IA * ia = static_cast(d); ia->isRunningRunTimeouter = true; int a = -1; -string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_t"; +std::string monFile = ia->stgSettings->GetMonitorDir() + "/inetaccess_t"; while (ia->nonstop) { struct timespec ts = {0, 20000000}; @@ -536,7 +541,7 @@ if (listenSocket < 0) } listenAddr.sin_family = AF_INET; -listenAddr.sin_port = htons(iaSettings.GetUserPort()); +listenAddr.sin_port = htons(static_cast(iaSettings.GetUserPort())); listenAddr.sin_addr.s_addr = inet_addr("0.0.0.0"); if (bind(listenSocket, (struct sockaddr*)&listenAddr, sizeof(listenAddr)) < 0) @@ -564,7 +569,7 @@ if (!WaitPackets(listenSocket)) // Timeout struct sockaddr_in outerAddr; socklen_t outerAddrLen(sizeof(outerAddr)); -int dataLen = recvfrom(listenSocket, buffer, bufferSize, 0, (struct sockaddr *)&outerAddr, &outerAddrLen); +ssize_t dataLen = recvfrom(listenSocket, buffer, bufferSize, 0, (struct sockaddr *)&outerAddr, &outerAddrLen); if (!dataLen) // EOF { @@ -672,7 +677,7 @@ int AUTH_IA::Timeouter() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -map::iterator it; +std::map::iterator it; it = ip2user.begin(); uint32_t sip; @@ -747,13 +752,13 @@ while (it != ip2user.end()) return 0; } //----------------------------------------------------------------------------- -int AUTH_IA::PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user) +int AUTH_IA::PacketProcessor(void * buff, size_t dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user) { std::string login(user->GetLogin()); -const int offset = LOGIN_LEN + 2 + 6; // LOGIN_LEN + sizeOfMagic + sizeOfVer; +const size_t offset = LOGIN_LEN + 2 + 6; // LOGIN_LEN + sizeOfMagic + sizeOfVer; STG_LOCKER lock(&mutex, __FILE__, __LINE__); -map::iterator it(ip2user.find(sip)); +std::map::iterator it(ip2user.find(sip)); if (it == ip2user.end()) { @@ -807,14 +812,13 @@ if (iaUser->password != user->GetProperty().password.Get()) iaUser->password = user->GetProperty().password.Get(); } -buff += offset; -Decrypt(&iaUser->ctx, buff, buff, (dataLen - offset) / 8); +Decrypt(&iaUser->ctx, static_cast(buff) + offset, static_cast(buff) + offset, (dataLen - offset) / 8); char packetName[IA_MAX_TYPE_LEN]; -strncpy(packetName, buff + 4, IA_MAX_TYPE_LEN); +strncpy(packetName, static_cast(buff) + offset + 4, IA_MAX_TYPE_LEN); packetName[IA_MAX_TYPE_LEN - 1] = 0; -map::iterator pi(packetTypes.find(packetName)); +std::map::iterator pi(packetTypes.find(packetName)); if (pi == packetTypes.end()) { SendError(sip, sport, protoVer, "îÅÐÒÁ×ÉÌØÎÙÊ ÌÏÇÉÎ ÉÌÉ ÐÁÒÏÌØ!"); @@ -846,15 +850,15 @@ switch (pi->second) switch (protoVer) { case 6: - if (Process_CONN_SYN_6((CONN_SYN_6 *)(buff - offset), &(it->second), sip)) + if (Process_CONN_SYN_6(static_cast(buff), &(it->second), sip)) return -1; return Send_CONN_SYN_ACK_6(iaUser, sip); case 7: - if (Process_CONN_SYN_7((CONN_SYN_7 *)(buff - offset), &(it->second), sip)) + if (Process_CONN_SYN_7(static_cast(buff), &(it->second), sip)) return -1; return Send_CONN_SYN_ACK_7(iaUser, sip); case 8: - if (Process_CONN_SYN_8((CONN_SYN_8 *)(buff - offset), &(it->second), sip)) + if (Process_CONN_SYN_8(static_cast(buff), &(it->second), sip)) return -1; return Send_CONN_SYN_ACK_8(iaUser, sip); } @@ -864,15 +868,15 @@ switch (pi->second) switch (protoVer) { case 6: - if (Process_CONN_ACK_6((CONN_ACK_6 *)(buff - offset), iaUser, sip)) + if (Process_CONN_ACK_6(static_cast(buff), iaUser, sip)) return -1; return Send_ALIVE_SYN_6(iaUser, sip); case 7: - if (Process_CONN_ACK_7((CONN_ACK_6 *)(buff - offset), iaUser, sip)) + if (Process_CONN_ACK_7(static_cast(buff), iaUser, sip)) return -1; return Send_ALIVE_SYN_7(iaUser, sip); case 8: - if (Process_CONN_ACK_8((CONN_ACK_8 *)(buff - offset), iaUser, sip)) + if (Process_CONN_ACK_8(static_cast(buff), iaUser, sip)) return -1; return Send_ALIVE_SYN_8(iaUser, sip); } @@ -882,11 +886,11 @@ switch (pi->second) switch (protoVer) { case 6: - return Process_ALIVE_ACK_6((ALIVE_ACK_6 *)(buff - offset), iaUser, sip); + return Process_ALIVE_ACK_6(static_cast(buff), iaUser, sip); case 7: - return Process_ALIVE_ACK_7((ALIVE_ACK_6 *)(buff - offset), iaUser, sip); + return Process_ALIVE_ACK_7(static_cast(buff), iaUser, sip); case 8: - return Process_ALIVE_ACK_8((ALIVE_ACK_8 *)(buff - offset), iaUser, sip); + return Process_ALIVE_ACK_8(static_cast(buff), iaUser, sip); } break; @@ -894,15 +898,15 @@ switch (pi->second) switch (protoVer) { case 6: - if (Process_DISCONN_SYN_6((DISCONN_SYN_6 *)(buff - offset), iaUser, sip)) + if (Process_DISCONN_SYN_6(static_cast(buff), iaUser, sip)) return -1; return Send_DISCONN_SYN_ACK_6(iaUser, sip); case 7: - if (Process_DISCONN_SYN_7((DISCONN_SYN_6 *)(buff - offset), iaUser, sip)) + if (Process_DISCONN_SYN_7(static_cast(buff), iaUser, sip)) return -1; return Send_DISCONN_SYN_ACK_7(iaUser, sip); case 8: - if (Process_DISCONN_SYN_8((DISCONN_SYN_8 *)(buff - offset), iaUser, sip)) + if (Process_DISCONN_SYN_8(static_cast(buff), iaUser, sip)) return -1; return Send_DISCONN_SYN_ACK_8(iaUser, sip); } @@ -912,15 +916,15 @@ switch (pi->second) switch (protoVer) { case 6: - if (Process_DISCONN_ACK_6((DISCONN_ACK_6 *)(buff - offset), iaUser, sip, it)) + if (Process_DISCONN_ACK_6(static_cast(buff), iaUser, sip, it)) return -1; return Send_FIN_6(iaUser, sip, it); case 7: - if (Process_DISCONN_ACK_7((DISCONN_ACK_6 *)(buff - offset), iaUser, sip, it)) + if (Process_DISCONN_ACK_7(static_cast(buff), iaUser, sip, it)) return -1; return Send_FIN_7(iaUser, sip, it); case 8: - if (Process_DISCONN_ACK_8((DISCONN_ACK_8 *)(buff - offset), iaUser, sip, it)) + if (Process_DISCONN_ACK_8(static_cast(buff), iaUser, sip, it)) return -1; return Send_FIN_8(iaUser, sip, it); } @@ -938,7 +942,7 @@ uint32_t ip = u->GetCurrIP(); if (!ip) return; -map::iterator it; +std::map::iterator it; STG_LOCKER lock(&mutex, __FILE__, __LINE__); it = ip2user.find(ip); @@ -957,12 +961,12 @@ if (it->second.user == u) } } //----------------------------------------------------------------------------- -int AUTH_IA::SendError(uint32_t ip, uint16_t port, int protoVer, const string & text) +int AUTH_IA::SendError(uint32_t ip, uint16_t port, int protoVer, const std::string & text) { struct sockaddr_in sendAddr; +ssize_t res; switch (protoVer) { - int res; case 6: case 7: ERR err; @@ -1008,7 +1012,7 @@ switch (protoVer) return 0; } //----------------------------------------------------------------------------- -int AUTH_IA::Send(uint32_t ip, uint16_t port, const char * buffer, int len) +int AUTH_IA::Send(uint32_t ip, uint16_t port, const char * buffer, size_t len) { struct sockaddr_in sendAddr; @@ -1016,9 +1020,7 @@ sendAddr.sin_family = AF_INET; sendAddr.sin_port = htons(port); sendAddr.sin_addr.s_addr = ip; -int res = sendto(listenSocket, buffer, len, 0, (struct sockaddr*)&sendAddr, sizeof(sendAddr)); - -if (res == len) +if (sendto(listenSocket, buffer, len, 0, (struct sockaddr*)&sendAddr, sizeof(sendAddr)) == static_cast(len)) return 0; return -1; @@ -1028,7 +1030,7 @@ int AUTH_IA::SendMessage(const STG_MSG & msg, uint32_t ip) const { printfd(__FILE__, "SendMessage userIP=%s\n", inet_ntostring(ip).c_str()); -map::iterator it; +std::map::iterator it; STG_LOCKER lock(&mutex, __FILE__, __LINE__); it = ip2user.find(ip); @@ -1074,8 +1076,8 @@ memset(&info, 0, sizeof(INFO_7)); info.len = 264; strncpy((char*)info.type, "INFO_7", 16); -info.infoType = msg.header.type; -info.showTime = msg.header.showTime; +info.infoType = static_cast(msg.header.type); +info.showTime = static_cast(msg.header.showTime); info.sendTime = msg.header.creationTime; size_t len = info.len; @@ -1103,8 +1105,8 @@ memset(&info, 0, sizeof(INFO_8)); info.len = 1056; strncpy((char*)info.type, "INFO_8", 16); -info.infoType = msg.header.type; -info.showTime = msg.header.showTime; +info.infoType = static_cast(msg.header.type); +info.showTime = static_cast(msg.header.showTime); info.sendTime = msg.header.creationTime; strncpy((char*)info.text, msg.text.c_str(), IA_MAX_MSG_LEN_8 - 1); @@ -1296,7 +1298,7 @@ return 0; int AUTH_IA::Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnAck, IA_USER * iaUser, uint32_t, - map::iterator) + std::map::iterator) { #ifdef ARCH_BE SwapBytes(disconnAck->len); @@ -1312,12 +1314,12 @@ if (!((iaUser->phase.GetPhase() == 4) && (disconnAck->rnd == iaUser->rnd + 1))) return 0; } //----------------------------------------------------------------------------- -int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, uint32_t sip, map::iterator it) +int AUTH_IA::Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnAck, IA_USER * iaUser, uint32_t sip, std::map::iterator it) { return Process_DISCONN_ACK_6(disconnAck, iaUser, sip, it); } //----------------------------------------------------------------------------- -int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, map::iterator) +int AUTH_IA::Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnAck, IA_USER * iaUser, uint32_t, std::map::iterator) { #ifdef ARCH_BE SwapBytes(disconnAck->len); @@ -1349,7 +1351,7 @@ for (int j = 0; j < DIR_NUM; j++) } //--- Fill static data in connSynAck --- -iaUser->rnd = random(); +iaUser->rnd = static_cast(random()); connSynAck6.rnd = iaUser->rnd; connSynAck6.userTimeOut = iaSettings.GetUserTimeout(); @@ -1391,7 +1393,7 @@ for (int j = 0; j < DIR_NUM; j++) } //--- Fill static data in connSynAck --- -iaUser->rnd = random(); +iaUser->rnd = static_cast(random()); connSynAck8.rnd = iaUser->rnd; connSynAck8.userTimeOut = iaSettings.GetUserTimeout(); @@ -1411,7 +1413,7 @@ return Send(sip, iaUser->port, (char*)&connSynAck8, Min8(sizeof(CONN_SYN_ACK_8)) int AUTH_IA::Send_ALIVE_SYN_6(IA_USER * iaUser, uint32_t sip) { aliveSyn6.len = Min8(sizeof(ALIVE_SYN_6)); -aliveSyn6.rnd = iaUser->rnd = random(); +aliveSyn6.rnd = iaUser->rnd = static_cast(random()); strcpy((char*)aliveSyn6.type, "ALIVE_SYN"); @@ -1501,7 +1503,7 @@ aliveSyn8.hdr.protoVer[0] = 0; aliveSyn8.hdr.protoVer[1] = 8; aliveSyn8.len = Min8(sizeof(ALIVE_SYN_8)); -aliveSyn8.rnd = iaUser->rnd = random(); +aliveSyn8.rnd = iaUser->rnd = static_cast(random()); strcpy((char*)aliveSyn8.type, "ALIVE_SYN"); @@ -1586,7 +1588,7 @@ int AUTH_IA::Send_DISCONN_SYN_ACK_6(IA_USER * iaUser, uint32_t sip) { disconnSynAck6.len = Min8(sizeof(DISCONN_SYN_ACK_6)); strcpy((char*)disconnSynAck6.type, "DISCONN_SYN_ACK"); -disconnSynAck6.rnd = iaUser->rnd = random(); +disconnSynAck6.rnd = iaUser->rnd = static_cast(random()); #ifdef ARCH_BE SwapBytes(disconnSynAck6.len); @@ -1610,7 +1612,7 @@ disconnSynAck8.hdr.protoVer[1] = 8; disconnSynAck8.len = Min8(sizeof(DISCONN_SYN_ACK_8)); strcpy((char*)disconnSynAck8.type, "DISCONN_SYN_ACK"); -disconnSynAck8.rnd = iaUser->rnd = random(); +disconnSynAck8.rnd = iaUser->rnd = static_cast(random()); #ifdef ARCH_BE SwapBytes(disconnSynAck8.len); @@ -1621,7 +1623,7 @@ Encrypt(&iaUser->ctx, (char*)&disconnSynAck8, (char*)&disconnSynAck8, Min8(sizeo return Send(sip, iaUser->port, (char*)&disconnSynAck8, Min8(sizeof(disconnSynAck8))); } //----------------------------------------------------------------------------- -int AUTH_IA::Send_FIN_6(IA_USER * iaUser, uint32_t sip, map::iterator it) +int AUTH_IA::Send_FIN_6(IA_USER * iaUser, uint32_t sip, std::map::iterator it) { fin6.len = Min8(sizeof(FIN_6)); strcpy((char*)fin6.type, "FIN"); @@ -1642,12 +1644,12 @@ ip2user.erase(it); return res; } //----------------------------------------------------------------------------- -int AUTH_IA::Send_FIN_7(IA_USER * iaUser, uint32_t sip, map::iterator it) +int AUTH_IA::Send_FIN_7(IA_USER * iaUser, uint32_t sip, std::map::iterator it) { return Send_FIN_6(iaUser, sip, it); } //----------------------------------------------------------------------------- -int AUTH_IA::Send_FIN_8(IA_USER * iaUser, uint32_t sip, map::iterator it) +int AUTH_IA::Send_FIN_8(IA_USER * iaUser, uint32_t sip, std::map::iterator it) { strcpy((char*)fin8.hdr.magic, IA_ID); fin8.hdr.protoVer[0] = 0; @@ -1671,9 +1673,11 @@ ip2user.erase(it); return res; } +namespace +{ //----------------------------------------------------------------------------- inline -void InitEncrypt(BLOWFISH_CTX * ctx, const string & password) +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) { unsigned char keyL[PASSWD_LEN]; memset(keyL, 0, PASSWD_LEN); @@ -1682,15 +1686,17 @@ Blowfish_Init(ctx, keyL, PASSWD_LEN); } //----------------------------------------------------------------------------- inline -void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8) { -for (int i = 0; i < len8; i++) - DecodeString(dst + i * 8, src + i * 8, ctx); +for (size_t i = 0; i < len8; i++) + DecodeString(static_cast(dst) + i * 8, static_cast(src) + i * 8, ctx); } //----------------------------------------------------------------------------- inline -void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8) { -for (int i = 0; i < len8; i++) - EncodeString(dst + i * 8, src + i * 8, ctx); +for (size_t i = 0; i < len8; i++) + EncodeString(static_cast(dst) + i * 8, static_cast(src) + i * 8, ctx); +} +//----------------------------------------------------------------------------- } diff --git a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h index 08fd6512..a13a11db 100644 --- a/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h +++ b/projects/stargazer/plugins/authorization/inetaccess/inetaccess.h @@ -51,8 +51,6 @@ #include "stg/utime.h" #include "stg/logger.h" -extern "C" PLUGIN * GetPlugin(); - #define IA_PROTO_VER (6) //#define IA_DEBUG (1) @@ -123,7 +121,7 @@ struct IA_USER { user(NULL), phase(), lastSendAlive(0), - rnd(random()), + rnd(static_cast(random())), port(0), ctx(), messagesToSend(), @@ -138,7 +136,7 @@ struct IA_USER { #ifdef IA_DEBUG aliveSent = false; #endif - }; + } IA_USER(const IA_USER & u) : login(u.login), @@ -156,7 +154,7 @@ struct IA_USER { aliveSent = u.aliveSent; #endif memcpy(&ctx, &u.ctx, sizeof(BLOWFISH_CTX)); - }; + } IA_USER(const std::string & l, CONST_USER_PTR u, @@ -166,7 +164,7 @@ struct IA_USER { user(u), phase(), lastSendAlive(0), - rnd(random()), + rnd(static_cast(random())), port(p), ctx(), messagesToSend(), @@ -204,13 +202,13 @@ private: class AUTH_IA_SETTINGS { public: AUTH_IA_SETTINGS(); - virtual ~AUTH_IA_SETTINGS() {}; - const std::string & GetStrError() const { return errorStr; }; + virtual ~AUTH_IA_SETTINGS() {} + const std::string & GetStrError() const { return errorStr; } int ParseSettings(const MODULE_SETTINGS & s); - int GetUserDelay() const { return userDelay; }; - int GetUserTimeout() const { return userTimeout; }; - int GetUserPort() const { return port; }; - FREEMB GetFreeMbShowType() const { return freeMbShowType; }; + int GetUserDelay() const { return userDelay; } + int GetUserTimeout() const { return userTimeout; } + uint16_t GetUserPort() const { return port; } + FREEMB GetFreeMbShowType() const { return freeMbShowType; } private: int userDelay; @@ -252,7 +250,7 @@ public: bool IsRunning() { return isRunningRunTimeouter || isRunningRun; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return "InetAccess authorization plugin v.1.4"; } + std::string GetVersion() const { return "InetAccess authorization plugin v.1.4"; } uint16_t GetStartPosition() const { return 30; } uint16_t GetStopPosition() const { return 30; } @@ -269,7 +267,7 @@ private: void DelUser(USER_PTR u); int RecvData(char * buffer, int bufferSize); int CheckHeader(const char * buffer, int * protoVer); - int PacketProcessor(char * buff, int dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user); + int PacketProcessor(void * buff, size_t dataLen, uint32_t sip, uint16_t sport, int protoVer, USER_PTR user); int Process_CONN_SYN_6(CONN_SYN_6 * connSyn, IA_USER * iaUser, uint32_t sip); int Process_CONN_SYN_7(CONN_SYN_7 * connSyn, IA_USER * iaUser, uint32_t sip); @@ -290,15 +288,15 @@ private: int Process_DISCONN_ACK_6(DISCONN_ACK_6 * disconnSyn, IA_USER * iaUser, uint32_t sip, - map::iterator it); + std::map::iterator it); int Process_DISCONN_ACK_7(DISCONN_ACK_7 * disconnSyn, IA_USER * iaUser, uint32_t sip, - map::iterator it); + std::map::iterator it); int Process_DISCONN_ACK_8(DISCONN_ACK_8 * disconnSyn, IA_USER * iaUser, uint32_t sip, - map::iterator it); + std::map::iterator it); int Send_CONN_SYN_ACK_6(IA_USER * iaUser, uint32_t sip); int Send_CONN_SYN_ACK_7(IA_USER * iaUser, uint32_t sip); @@ -312,14 +310,14 @@ private: int Send_DISCONN_SYN_ACK_7(IA_USER * iaUser, uint32_t sip); int Send_DISCONN_SYN_ACK_8(IA_USER * iaUser, uint32_t sip); - int Send_FIN_6(IA_USER * iaUser, uint32_t sip, map::iterator it); - int Send_FIN_7(IA_USER * iaUser, uint32_t sip, map::iterator it); - int Send_FIN_8(IA_USER * iaUser, uint32_t sip, map::iterator it); + int Send_FIN_6(IA_USER * iaUser, uint32_t sip, std::map::iterator it); + int Send_FIN_7(IA_USER * iaUser, uint32_t sip, std::map::iterator it); + int Send_FIN_8(IA_USER * iaUser, uint32_t sip, std::map::iterator it); int Timeouter(); int SendError(uint32_t ip, uint16_t port, int protoVer, const std::string & text); - int Send(uint32_t ip, uint16_t port, const char * buffer, int len); + int Send(uint32_t ip, uint16_t port, const char * buffer, size_t len); int RealSendMessage6(const STG_MSG & msg, uint32_t ip, IA_USER & user); int RealSendMessage7(const STG_MSG & msg, uint32_t ip, IA_USER & user); int RealSendMessage8(const STG_MSG & msg, uint32_t ip, IA_USER & user); diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp index 85fd602b..6ec8c342 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.cpp @@ -56,7 +56,12 @@ fclose(f); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR cdc; +} + +extern "C" BASE_PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -74,7 +79,7 @@ RAW_PACKET MakeTCPPacket(const char * src, uint16_t sport, uint16_t dport, uint16_t len); -const string DEBUG_CAP::GetVersion() const +std::string DEBUG_CAP::GetVersion() const { return "Debug_cap v.0.01a"; } @@ -90,7 +95,7 @@ void DEBUG_CAP::SetTraffcounter(TRAFFCOUNTER * tc) traffCnt = tc; } //----------------------------------------------------------------------------- -const string & DEBUG_CAP::GetStrError() const +const std::string & DEBUG_CAP::GetStrError() const { return errorStr; } diff --git a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h index d0aad764..6bea457f 100644 --- a/projects/stargazer/plugins/capture/cap_debug/debug_cap.h +++ b/projects/stargazer/plugins/capture/cap_debug/debug_cap.h @@ -36,9 +36,6 @@ $Author: faust $ #include "stg/plugin.h" #include "stg/module_settings.h" -using namespace std; -extern "C" PLUGIN * GetPlugin(); - //----------------------------------------------------------------------------- struct iphdr_eth { uint8_t ihl:4, @@ -58,8 +55,8 @@ struct iphdr_eth { //----------------------------------------------------------------------------- class CAP_SETTINGS { public: - const string & GetStrError() const { static string s; return s; } - int ParseSettings(const MODULE_SETTINGS & s) { return 0; } + const std::string & GetStrError() const { static std::string s; return s; } + int ParseSettings(const MODULE_SETTINGS & s) { return 0; } }; //----------------------------------------------------------------------------- class DEBUG_CAP :public PLUGIN @@ -75,15 +72,15 @@ public: int Reload() { return 0; } int ParseSettings() { return 0; } bool IsRunning(); - const string & GetStrError() const; - const string GetVersion() const; + const std::string & GetStrError() const; + std::string GetVersion() const; uint16_t GetStartPosition() const; uint16_t GetStopPosition() const; private: static void * Run1(void *); static void * Run2(void *); static void * Run3(void *); - mutable string errorStr; + mutable std::string errorStr; CAP_SETTINGS capSettings; pthread_t thread; bool nonstop; diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp index 37af9720..41ad9fae 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.cpp @@ -45,7 +45,12 @@ $Author: faust $ #include "stg/plugin_creator.h" #include "cap_nf.h" +namespace +{ PLUGIN_CREATOR cnc; +} + +extern "C" PLUGIN * GetPlugin(); PLUGIN * GetPlugin() { @@ -261,10 +266,6 @@ sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); NF_CAP * cap = static_cast(c); -uint8_t buf[BUF_SIZE]; -int res; -struct sockaddr_in sin; -socklen_t slen; cap->stoppedUDP = false; while (cap->runningUDP) { @@ -274,8 +275,10 @@ while (cap->runningUDP) } // Data - slen = sizeof(sin); - res = recvfrom(cap->sockUDP, buf, BUF_SIZE, 0, reinterpret_cast(&sin), &slen); + struct sockaddr_in sin; + socklen_t slen = sizeof(sin); + uint8_t buf[BUF_SIZE]; + ssize_t res = recvfrom(cap->sockUDP, buf, BUF_SIZE, 0, reinterpret_cast(&sin), &slen); if (!cap->runningUDP) break; @@ -313,11 +316,6 @@ sigfillset(&signalSet); pthread_sigmask(SIG_BLOCK, &signalSet, NULL); NF_CAP * cap = static_cast(c); -uint8_t buf[BUF_SIZE]; -int res; -int sd; -struct sockaddr_in sin; -socklen_t slen; cap->stoppedTCP = false; while (cap->runningTCP) { @@ -327,8 +325,9 @@ while (cap->runningTCP) } // Data - slen = sizeof(sin); - sd = accept(cap->sockTCP, reinterpret_cast(&sin), &slen); + struct sockaddr_in sin; + socklen_t slen = sizeof(sin); + int sd = accept(cap->sockTCP, reinterpret_cast(&sin), &slen); if (!cap->runningTCP) break; @@ -345,7 +344,8 @@ while (cap->runningTCP) continue; } - res = recv(sd, buf, BUF_SIZE, MSG_WAITALL); + uint8_t buf[BUF_SIZE]; + ssize_t res = recv(sd, buf, BUF_SIZE, MSG_WAITALL); if (res < 0) cap->logger("recv error: %s", strerror(errno)); @@ -373,7 +373,7 @@ cap->stoppedTCP = true; return NULL; } -void NF_CAP::ParseBuffer(uint8_t * buf, int size) +void NF_CAP::ParseBuffer(uint8_t * buf, ssize_t size) { RAW_PACKET ip; NF_HEADER * hdr = reinterpret_cast(buf); diff --git a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h index bf45cfea..23f7d7db 100644 --- a/projects/stargazer/plugins/capture/cap_nf/cap_nf.h +++ b/projects/stargazer/plugins/capture/cap_nf/cap_nf.h @@ -61,7 +61,7 @@ struct NF_HEADER { uint8_t eType; // Engine type uint8_t eID; // Engine ID uint16_t sInterval; // Sampling mode and interval -} __attribute__ ((packed)); +}; struct NF_DATA { uint32_t srcAddr; // Flow source address @@ -84,7 +84,7 @@ struct NF_DATA { uint8_t srcMask; // Source address mask in "slash" notation uint8_t dstMask; // Destination address mask in "slash" notation uint16_t pad2; // 2-byte padding -} __attribute__ ((packed)); +}; #define BUF_SIZE (sizeof(NF_HEADER) + 30 * sizeof(NF_DATA)) @@ -102,7 +102,7 @@ public: int Reload() { return 0; } bool IsRunning() { return runningTCP || runningUDP; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return VERSION; } + std::string GetVersion() const { return VERSION; } uint16_t GetStartPosition() const { return START_POS; } uint16_t GetStopPosition() const { return STOP_POS; } @@ -127,7 +127,7 @@ private: static void * RunUDP(void *); static void * RunTCP(void *); - void ParseBuffer(uint8_t *, int); + void ParseBuffer(uint8_t * buf, ssize_t size); bool OpenTCP(); bool OpenUDP(); @@ -135,6 +135,4 @@ private: void CloseUDP() { close(sockUDP); } }; -extern "C" PLUGIN * GetPlugin(); - #endif diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp index 6bbfd7e8..96476d4e 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.cpp @@ -62,7 +62,12 @@ DIVERT_DATA cddiv; //capture data //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR dcc; +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -73,7 +78,7 @@ return dcc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const std::string DIVERT_CAP::GetVersion() const +std::string DIVERT_CAP::GetVersion() const { return "Divert_cap v.1.0"; } diff --git a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h index 25fd29c2..b34f832e 100644 --- a/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h +++ b/projects/stargazer/plugins/capture/divert_freebsd/divert_cap.h @@ -41,8 +41,6 @@ class ADMINS; class TRAFFCOUNTER; class SETTINGS; -extern "C" PLUGIN * GetPlugin(); - //----------------------------------------------------------------------------- class DIVERT_CAP : public PLUGIN { public: @@ -59,7 +57,7 @@ public: void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 40; } uint16_t GetStopPosition() const { return 40; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp index c217e22f..5177330e 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.cpp @@ -60,7 +60,12 @@ $Author: faust $ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR bcc; +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -110,7 +115,7 @@ return iface[num]; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const std::string BPF_CAP::GetVersion() const +std::string BPF_CAP::GetVersion() const { return "bpf_cap v.1.0"; } diff --git a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h index 0a00cb04..76785ed2 100644 --- a/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_freebsd/ether_cap.h @@ -37,8 +37,6 @@ #include "stg/module_settings.h" #include "stg/logger.h" -extern "C" PLUGIN * GetPlugin(); - #define BUFF_LEN (128) class TRAFFCOUNTER; @@ -107,7 +105,7 @@ public: int ParseSettings(); const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 40; } uint16_t GetStopPosition() const { return 40; } diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp index 6ed2e068..a97fa8e7 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.cpp @@ -56,7 +56,12 @@ $Date: 2009/12/13 13:45:13 $ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR ecc; +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -67,7 +72,7 @@ return ecc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const std::string ETHER_CAP::GetVersion() const +std::string ETHER_CAP::GetVersion() const { return "Ether_cap v.1.2"; } @@ -169,13 +174,11 @@ char padding[4]; char padding1[8]; }; -ETH_IP * ethIP; - char ethip[sizeof(ETH_IP)]; memset(ðip, 0, sizeof(ETH_IP)); -ethIP = (ETH_IP *)ðip; +ETH_IP * ethIP = static_cast(static_cast(ðip)); ethIP->rp.dataLen = -1; char * iface = NULL; @@ -214,7 +217,7 @@ return 0; int ETHER_CAP::EthCapRead(void * buffer, int blen, char **) { struct sockaddr_ll addr; -int addrLen, res; +int addrLen; if (!WaitPackets(capSock)) { @@ -223,9 +226,7 @@ if (!WaitPackets(capSock)) addrLen = sizeof(addr); -res = recvfrom(capSock, ((char*)buffer) + 2, blen, 0, (struct sockaddr *)&addr, (socklen_t*)&addrLen); - -if (res < 0) +if (recvfrom(capSock, ((char*)buffer) + 2, blen, 0, (struct sockaddr *)&addr, (socklen_t*)&addrLen) < 0) { logger("recvfrom error: %s", strerror(errno)); return ENODATA; diff --git a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h index c8de5522..8dfb6c04 100644 --- a/projects/stargazer/plugins/capture/ether_linux/ether_cap.h +++ b/projects/stargazer/plugins/capture/ether_linux/ether_cap.h @@ -40,8 +40,6 @@ class ADMINS; class TRAFFCOUNTER; class SETTINGS; -extern "C" PLUGIN * GetPlugin(); - class TRAFFCOUNTER; //----------------------------------------------------------------------------- @@ -59,7 +57,7 @@ public: int ParseSettings() { return 0; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 40; } uint16_t GetStopPosition() const { return 40; } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp index 9818378a..05599306 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.cpp @@ -40,7 +40,12 @@ extern "C" //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR icc; +} + +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -51,7 +56,7 @@ return icc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const std::string IPQ_CAP::GetVersion() const +std::string IPQ_CAP::GetVersion() const { return "ipq_cap v.1.2"; } diff --git a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h index 8b524d93..39ed5766 100644 --- a/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h +++ b/projects/stargazer/plugins/capture/ipq_linux/ipq_cap.h @@ -37,8 +37,6 @@ class ADMINS; class TRAFFCOUNTER; class SETTINGS; -extern "C" PLUGIN * GetPlugin(); - //----------------------------------------------------------------------------- class IPQ_CAP :public PLUGIN { public: @@ -54,7 +52,7 @@ public: int ParseSettings() { return 0; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 40; } uint16_t GetStopPosition() const { return 40; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp index 0016babe..ad9c0324 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/admins_methods.cpp @@ -223,14 +223,14 @@ void METHOD_ADMINS_GET::execute(xmlrpc_c::paramList const & paramList, std::string cookie = paramList.getString(0); paramList.verifyEnd(1); -std::map structVal; +std::map mainStructVal; std::vector retval; ADMIN_INFO adminInfo; if (config->GetAdminInfo(cookie, &adminInfo)) { - structVal["result"] = xmlrpc_c::value_boolean(false); - *retvalPtr = xmlrpc_c::value_struct(structVal); + mainStructVal["result"] = xmlrpc_c::value_boolean(false); + *retvalPtr = xmlrpc_c::value_struct(mainStructVal); return; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp index c4684c1b..895088dc 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/info_methods.cpp @@ -28,12 +28,12 @@ un += " "; un += utsn.nodename; structVal["version"] = xmlrpc_c::value_string(SERVER_VERSION); -structVal["tariff_num"] = xmlrpc_c::value_int(tariffs->Count()); +structVal["tariff_num"] = xmlrpc_c::value_int(static_cast(tariffs->Count())); structVal["tariff"] = xmlrpc_c::value_int(2); -structVal["users_num"] = xmlrpc_c::value_int(users->Count()); +structVal["users_num"] = xmlrpc_c::value_int(static_cast(users->Count())); structVal["uname"] = xmlrpc_c::value_string(un); structVal["dir_num"] = xmlrpc_c::value_int(DIR_NUM); -structVal["day_fee"] = xmlrpc_c::value_int(dayFee); +structVal["day_fee"] = xmlrpc_c::value_int(static_cast(dayFee)); std::vector dirnameVal; diff --git a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp index e6a4df6f..91796148 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/messages_methods.cpp @@ -5,7 +5,7 @@ #include "messages_methods.h" #include "rpcconfig.h" -extern const volatile time_t stgTime; +extern volatile time_t stgTime; //------------------------------------------------------------------------------ @@ -75,7 +75,7 @@ if ((it = msgInfo.find("text")) == msgInfo.end()) } message.text = IconvString(xmlrpc_c::value_string(it->second), "UTF-8", "CP1251"); -message.header.creationTime = stgTime; +message.header.creationTime = static_cast(stgTime); message.header.lastSendTime = 0; std::vector::iterator lit; diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp index 86072bcf..e84e9a0e 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.cpp @@ -25,7 +25,12 @@ #include "admins_methods.h" #include "messages_methods.h" +namespace +{ PLUGIN_CREATOR rpcc; +} + +extern "C" PLUGIN * GetPlugin(); RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS() : errorStr(), @@ -36,11 +41,9 @@ RPC_CONFIG_SETTINGS::RPC_CONFIG_SETTINGS() int RPC_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { -int p; PARAM_VALUE pv; -std::vector::const_iterator pvi; - pv.param = "Port"; +std::vector::const_iterator pvi; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); if (pvi == s.moduleParams.end()) { @@ -48,13 +51,14 @@ if (pvi == s.moduleParams.end()) printfd(__FILE__, "Parameter 'Port' not found\n"); return -1; } +int p; if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) { errorStr = "Cannot parse parameter \'Port\': " + errorStr; printfd(__FILE__, "Cannot parse parameter 'Port'\n"); return -1; } -port = p; +port = static_cast(p); pv.param = "CookieTimeout"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -117,12 +121,12 @@ if (ret) return ret; } -void RPC_CONFIG::SetStgSettings(const SETTINGS * settings) +void RPC_CONFIG::SetStgSettings(const SETTINGS * s) { - dayFee = settings->GetDayFee(); + dayFee = s->GetDayFee(); dirNames.erase(dirNames.begin(), dirNames.end()); for (size_t i = 0; i < DIR_NUM; ++i) { - dirNames.push_back(settings->GetDirName(i)); + dirNames.push_back(s->GetDirName(i)); } } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h index a58773a1..72a14f21 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h +++ b/projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h @@ -20,8 +20,6 @@ #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2" -extern "C" PLUGIN * GetPlugin(); - class ADMINS; class TARIFFS; class USERS; @@ -39,7 +37,7 @@ public: private: std::string errorStr; - int port; + uint16_t port; double cookieTimeout; }; @@ -76,7 +74,7 @@ public: bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return RPC_CONFIG_VERSION; } + std::string GetVersion() const { return RPC_CONFIG_VERSION; } uint16_t GetStartPosition() const { return 20; } uint16_t GetStopPosition() const { return 20; } diff --git a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp index e2cfb13a..665a04f4 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/user_helper.cpp @@ -74,7 +74,7 @@ structVal["group"] = xmlrpc_c::value_string(IconvString(ptr->GetProperty().group structVal["status"] = xmlrpc_c::value_boolean(ptr->GetConnected()); structVal["aonline"] = xmlrpc_c::value_boolean(ptr->GetProperty().alwaysOnline.Get()); structVal["currip"] = xmlrpc_c::value_string(inet_ntostring(ptr->GetCurrIP())); -structVal["pingtime"] = xmlrpc_c::value_int(ptr->GetPingTime()); +structVal["pingtime"] = xmlrpc_c::value_int(static_cast(ptr->GetPingTime())); structVal["ips"] = xmlrpc_c::value_string(ptr->GetProperty().ips.Get().GetIpStr()); std::map traffInfo; @@ -116,9 +116,9 @@ structVal["down"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabled.Get()); structVal["disableddetailstat"] = xmlrpc_c::value_boolean(ptr->GetProperty().disabledDetailStat.Get()); structVal["passive"] = xmlrpc_c::value_boolean(ptr->GetProperty().passive.Get()); structVal["lastcash"] = xmlrpc_c::value_double(ptr->GetProperty().lastCashAdd.Get()); -structVal["lasttimecash"] = xmlrpc_c::value_int(ptr->GetProperty().lastCashAddTime.Get()); -structVal["lastactivitytime"] = xmlrpc_c::value_int(ptr->GetProperty().lastActivityTime.Get()); -structVal["creditexpire"] = xmlrpc_c::value_int(ptr->GetProperty().creditExpire.Get()); +structVal["lasttimecash"] = xmlrpc_c::value_int(static_cast(ptr->GetProperty().lastCashAddTime.Get())); +structVal["lastactivitytime"] = xmlrpc_c::value_int(static_cast(ptr->GetProperty().lastActivityTime.Get())); +structVal["creditexpire"] = xmlrpc_c::value_int(static_cast(ptr->GetProperty().creditExpire.Get())); *info = xmlrpc_c::value_struct(structVal); } @@ -335,7 +335,7 @@ if ((it = structVal.find("note")) != structVal.end()) if ((it = structVal.find("userdata")) != structVal.end()) { - std::vector *> userdata; + std::vector *> userdata; userdata.push_back(ptr->GetProperty().userdata0.GetPointer()); userdata.push_back(ptr->GetProperty().userdata1.GetPointer()); userdata.push_back(ptr->GetProperty().userdata2.GetPointer()); diff --git a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp index 130051be..5b39cf1e 100644 --- a/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp +++ b/projects/stargazer/plugins/configuration/rpcconfig/users_methods.cpp @@ -404,14 +404,13 @@ void METHOD_GET_ONLINE_IPS::execute(xmlrpc_c::paramList const & paramList, xmlrpc_c::value * const retvalPtr) { std::string cookie = paramList.getString(0); -std::vector subnetsStr = paramList.getArray(1); +typedef std::vector ValueVector; +ValueVector subnetsStr = paramList.getArray(1); paramList.verifyEnd(2); std::vector subnets; -std::vector::iterator it; - -for (it = subnetsStr.begin(); it != subnetsStr.end(); ++it) +for (ValueVector::const_iterator it(subnetsStr.begin()); it != subnetsStr.end(); ++it) { IP_MASK ipm; if (ParseNet(xmlrpc_c::value_string(*it), ipm)) @@ -434,7 +433,7 @@ if (config->GetAdminInfo(cookie, &adminInfo)) return; } -std::vector ips; +ValueVector ips; USER_PTR u; @@ -457,8 +456,7 @@ while (1) { uint32_t ip = u->GetCurrIP(); - std::vector::iterator it; - for (it = subnets.begin(); it != subnets.end(); ++it) + for (std::vector::const_iterator it(subnets.begin()); it != subnets.end(); ++it) { if ((it->ip & it->mask) == (ip & it->mask)) { diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp index 7ca37b49..22facc61 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.cpp @@ -158,10 +158,9 @@ XML_ParserFree(xmlParser); //----------------------------------------------------------------------------- int CONFIGPROTO::ParseCommand() { -list::iterator n; +std::list::iterator n; int done = 0; char str[9]; -int len; if (requestList.empty()) return 0; @@ -179,14 +178,14 @@ while(nonstop) { strncpy(str, (*n).c_str(), 8); str[8] = 0; - len = strlen(str); + size_t len = strlen(str); ++n; if (n == requestList.end()) done = 1; --n; - if (XML_Parse(xmlParser, (*n).c_str(), len, done) == XML_STATUS_ERROR) + if (XML_Parse(xmlParser, (*n).c_str(), static_cast(len), done) == XML_STATUS_ERROR) { logger("Invalid configuration request"); printfd(__FILE__, "Parse error at line %d:\n%s\n", diff --git a/projects/stargazer/plugins/configuration/sgconfig/configproto.h b/projects/stargazer/plugins/configuration/sgconfig/configproto.h index 0de2b847..b8b01f02 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/configproto.h +++ b/projects/stargazer/plugins/configuration/sgconfig/configproto.h @@ -121,7 +121,7 @@ private: ADMINS * admins; BASE_PARSER * currParser; - vector dataParser; + std::vector dataParser; XML_Parser xmlParser; diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index bfe2f7bc..1f7757d2 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -64,13 +64,13 @@ answerList->push_back(""); sprintf(s, "", SERVER_VERSION); answerList->push_back(s); -sprintf(s, "", (unsigned long long)tariffs->Count()); +sprintf(s, "", static_cast(tariffs->Count())); answerList->push_back(s); sprintf(s, "", 2); answerList->push_back(s); -sprintf(s, "", (unsigned long long)users->Count()); +sprintf(s, "", static_cast(users->Count())); answerList->push_back(s); sprintf(s, "", un); @@ -84,7 +84,7 @@ answerList->push_back(s); for (int i = 0; i< DIR_NUM; i++) { - string dn2e; + std::string dn2e; Encode12str(dn2e, settings->GetDirName(i)); sprintf(s, "", i, dn2e.c_str()); answerList->push_back(s); @@ -124,8 +124,8 @@ return -1; //----------------------------------------------------------------------------- void PARSER_GET_USER::CreateAnswer() { -string s; -string enc; +std::string s; +std::string enc; USER_PTR u; @@ -190,7 +190,7 @@ s = ""; answerList->push_back(s); -vector *> userdata; +std::vector *> userdata; userdata.push_back(u->GetProperty().userdata0.GetPointer()); userdata.push_back(u->GetProperty().userdata1.GetPointer()); userdata.push_back(u->GetProperty().userdata2.GetPointer()); @@ -202,7 +202,7 @@ userdata.push_back(u->GetProperty().userdata7.GetPointer()); userdata.push_back(u->GetProperty().userdata8.GetPointer()); userdata.push_back(u->GetProperty().userdata9.GetPointer()); -string tmpI; +std::string tmpI; for (unsigned i = 0; i < userdata.size(); i++) { Encode12str(enc, userdata[i]->Get()); @@ -230,7 +230,7 @@ answerList->push_back(s); strprintf(&s, "", u->GetPingTime()); answerList->push_back(s); -stringstream sstr; +std::ostringstream sstr; sstr << u->GetProperty().ips.Get(); strprintf(&s, "", sstr.str().c_str()); answerList->push_back(s); @@ -246,7 +246,7 @@ upload = u->GetProperty().up.Get(); for (int j = 0; j < DIR_NUM; j++) { - string s; + std::string s; x2str(upload[j], s); sprintf(st, " MU%d=\"%s\"", j, s.c_str()); strcat(ss, st); @@ -342,16 +342,16 @@ void PARSER_GET_USERS::CreateAnswer() { answerList->erase(answerList->begin(), answerList->end()); -string s; -string userStart; -string traffStart; -string traffMiddle; -string traffFinish; -string middle; -string userFinish; +std::string s; +std::string userStart; +std::string traffStart; +std::string traffMiddle; +std::string traffFinish; +std::string middle; +std::string userFinish; -string enc; +std::string enc; USER_PTR u; @@ -362,7 +362,7 @@ if (!h) users->CloseSearch(h); return; } -string updateTime; +std::string updateTime; x2str(time(NULL), updateTime); if (lastUpdateFound) @@ -458,7 +458,7 @@ while (1) middle += s; } - vector *> userdata; + std::vector *> userdata; userdata.push_back(u->GetProperty().userdata0.GetPointer()); userdata.push_back(u->GetProperty().userdata1.GetPointer()); userdata.push_back(u->GetProperty().userdata2.GetPointer()); @@ -470,7 +470,7 @@ while (1) userdata.push_back(u->GetProperty().userdata8.GetPointer()); userdata.push_back(u->GetProperty().userdata9.GetPointer()); - string tmpI; + std::string tmpI; for (unsigned i = 0; i < userdata.size(); i++) { if (userdata[i]->ModificationTime() > lastUserUpdateTime) @@ -522,7 +522,7 @@ while (1) if (u->GetProperty().ips.ModificationTime() > lastUserUpdateTime) { - stringstream sstr; + std::ostringstream sstr; sstr << u->GetProperty().ips.Get(); strprintf(&s, "", sstr.str().c_str()); middle += s; @@ -540,7 +540,7 @@ while (1) { for (int j = 0; j < DIR_NUM; j++) { - string s; + std::string s; x2str(upload[j], s); sprintf(st, " MU%d=\"%s\" ", j, s.c_str()); traffMiddle += st; @@ -742,11 +742,11 @@ ucr = new USER_CONF_RES; upr = new RESETABLE[DIR_NUM]; downr = new RESETABLE[DIR_NUM]; -}; +} //----------------------------------------------------------------------------- -string PARSER_CHG_USER::EncChar2String(const char * strEnc) +std::string PARSER_CHG_USER::EncChar2String(const char * strEnc) { -string str; +std::string str; Decode21str(str, strEnc); return str; } @@ -917,7 +917,7 @@ else int dir; DIR_TRAFF dtu; DIR_TRAFF dtd; - unsigned long long t = 0; + uint64_t t = 0; while (attr[j]) { dir = attr[j][2] - '0'; @@ -1074,7 +1074,7 @@ if (!ucr->note.res_empty()) if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store)) res = -1; -vector *> userdata; +std::vector *> userdata; userdata.push_back(u->GetProperty().userdata0.GetPointer()); userdata.push_back(u->GetProperty().userdata1.GetPointer()); userdata.push_back(u->GetProperty().userdata2.GetPointer()); @@ -1288,7 +1288,7 @@ if (strcasecmp(el, "Message") == 0) printfd(__FILE__, "User not found. %s\n", logins[i].c_str()); continue; } - msg.header.creationTime = stgTime; + msg.header.creationTime = static_cast(stgTime); u->AddMessage(&msg); result = res_ok; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp index 5bc68d2a..9d87f300 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp @@ -37,7 +37,7 @@ if (!priv->adminChg) return; } -string s; +std::string s; //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); @@ -99,7 +99,7 @@ if (admins->Del(adminToDel, currAdmin) == 0) } else { - string s; + std::string s; strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); } @@ -155,7 +155,7 @@ if (admins->Add(adminToAdd, currAdmin) == 0) } else { - string s; + std::string s; strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); } @@ -242,7 +242,7 @@ if (!login.res_empty()) if (admins->Change(conf, currAdmin) != 0) { - string s; + std::string s; strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp index 9bac0294..7be1af96 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp @@ -29,7 +29,7 @@ return -1; //----------------------------------------------------------------------------- void PARSER_GET_TARIFFS::CreateAnswer() { -string s; +std::string s; char vs[100]; int hd, hn, md, mn; @@ -186,7 +186,7 @@ if (tariffs->Add(tariffToAdd, currAdmin) == 0) } else { - string s; + std::string s; strprintf(&s, "", tariffs->GetStrError().c_str()); answerList->push_back(s); } @@ -222,7 +222,7 @@ answerList->erase(answerList->begin(), answerList->end()); if (users->TariffInUse(tariffToDel)) { - string s; + std::string s; strprintf(&s, "", tariffToDel.c_str()); answerList->push_back(s); return; @@ -234,7 +234,7 @@ if (tariffs->Del(tariffToDel, currAdmin) == 0) } else { - string s; + std::string s; strprintf(&s, "", tariffs->GetStrError().c_str()); answerList->push_back(s); } @@ -244,7 +244,7 @@ else // CHG TARIFF //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const string & s, int * params) +int PARSER_CHG_TARIFF::ParseSlashedIntParams(int paramsNum, const std::string & s, int * params) { char * str = new char[s.size() + 1]; char * p; @@ -272,7 +272,7 @@ delete[] str; return 0; } //----------------------------------------------------------------------------- -int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const string & s, double * params) +int PARSER_CHG_TARIFF::ParseSlashedDoubleParams(int paramsNum, const std::string & s, double * params) { char * str = new char[s.size() + 1]; char * p; @@ -317,7 +317,7 @@ if (depth == 1) } else { - string s; + std::string s; if (strcasecmp(el, "PriceDayA") == 0) { @@ -485,7 +485,7 @@ if (!td.tariffConf.name.data().empty()) } else { - string s; + std::string s; strprintf(&s, "", tariffs->GetStrError().c_str()); answerList->push_back(s); return; diff --git a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp index a4915e39..9b448f6c 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/rsconf.cpp @@ -57,7 +57,7 @@ enum //----------------------------------------------------------------------------- int CONFIGPROTO::Prepare() { -list ansList; //óÀÄÁ ÂÕÄÅÔ ÐÏÍÅÝÅÎ ÏÔ×ÅÔ ÄÌÑ ÍÅÎÅÄÖÅÒÁ ËÌÉÅÎÔÏ× +std::list ansList; //óÀÄÁ ÂÕÄÅÔ ÐÏÍÅÝÅÎ ÏÔ×ÅÔ ÄÌÑ ÍÅÎÅÄÖÅÒÁ ËÌÉÅÎÔÏ× int res; struct sockaddr_in listenAddr; @@ -86,7 +86,7 @@ int lng = 1; if (0 != setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &lng, 4)) { - errorStr = "Setsockopt failed. " + string(strerror(errno)); + errorStr = "Setsockopt failed. " + std::string(strerror(errno)); logger("setsockopt error: %s", strerror(errno)); return -1; } @@ -253,7 +253,7 @@ while (pos < stgHdrLen) SendError("Bad request"); return -1; } - int ret = recv(sock, &buf[pos], stgHdrLen - pos, 0); + ssize_t ret = recv(sock, &buf[pos], static_cast(stgHdrLen) - static_cast(pos), 0); if (ret <= 0) { if (ret < 0) @@ -314,7 +314,7 @@ while (pos < ADM_LOGIN_LEN) { return ENODATA; } - int ret = recv(sock, &login[pos], ADM_LOGIN_LEN - pos, 0); + ssize_t ret = recv(sock, &login[pos], ADM_LOGIN_LEN - static_cast(pos), 0); if (ret <= 0) { @@ -364,7 +364,7 @@ while (pos < ADM_LOGIN_LEN) return ENODATA; } - int ret = recv(sock, &loginS[pos], ADM_LOGIN_LEN - pos, 0); + ssize_t ret = recv(sock, &loginS[pos], ADM_LOGIN_LEN - static_cast(pos), 0); if (ret <= 0) { @@ -452,7 +452,7 @@ while (1) break; } - int ret = recv(sock, &bufferS[pos], sizeof(bufferS) - pos, 0); + ssize_t ret = recv(sock, &bufferS[pos], sizeof(bufferS) - static_cast(pos), 0); if (ret < 0) { // Network error @@ -486,12 +486,12 @@ while (1) return SendDataAnswer(sock); } } -return 0; +//return 0; } //----------------------------------------------------------------------------- int CONFIGPROTO::SendDataAnswer(int sock) { -list::iterator li; +std::list::iterator li; li = answerList.begin(); BLOWFISH_CTX ctx; @@ -514,7 +514,7 @@ while (li != answerList.end()) if (n % 8 == 0) { EncodeString(buffS, buff, &ctx); - int ret = send(sock, buffS, 8, 0); + int ret = static_cast(send(sock, buffS, 8, 0)); if (ret < 0) { return -1; @@ -534,7 +534,7 @@ EncodeString(buffS, buff, &ctx); answerList.clear(); -return send(sock, buffS, 8, 0); +return static_cast(send(sock, buffS, 8, 0)); } //----------------------------------------------------------------------------- void CONFIGPROTO::SendError(const char * text) diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp index e3199047..06381144 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.cpp @@ -12,7 +12,7 @@ //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PLUGIN_CREATOR stgc; +static PLUGIN_CREATOR stgc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -20,7 +20,7 @@ int STG_CONFIG_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { int p; PARAM_VALUE pv; -vector::const_iterator pvi; +std::vector::const_iterator pvi; /////////////////////////// pv.param = "Port"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -36,7 +36,7 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } -port = p; +port = static_cast(p); return 0; } @@ -50,7 +50,7 @@ return stgc.GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -const std::string STG_CONFIG::GetVersion() const +std::string STG_CONFIG::GetVersion() const { return "Stg configurator v.0.08"; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h index 7e3ae69b..8fa4dc76 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h +++ b/projects/stargazer/plugins/configuration/sgconfig/stgconfig.h @@ -23,13 +23,13 @@ public: uint16_t GetPort() const { return port; } private: std::string errorStr; - int port; + uint16_t port; }; //----------------------------------------------------------------------------- class STG_CONFIG :public PLUGIN { public: STG_CONFIG(); - virtual ~STG_CONFIG(){}; + virtual ~STG_CONFIG(){} void SetUsers(USERS * u) { users = u; } void SetTariffs(TARIFFS * t) { tariffs = t; } @@ -45,7 +45,7 @@ public: bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const; + std::string GetVersion() const; uint16_t GetStartPosition() const { return 20; } uint16_t GetStopPosition() const { return 20; } diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index 7f47b7cf..7c4050ab 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -10,37 +10,43 @@ #include "stg/plugin_creator.h" #include "ping.h" -PLUGIN_CREATOR pc; -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -PLUGIN * GetPlugin() +namespace { -return pc.GetPlugin(); -} +PLUGIN_CREATOR pc; + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- // ëÌÁÓÓ ÄÌÑ ÐÏÉÓËÁ ÀÚÅÒÁ × ÓÐÉÓËÅ ÎÏÔÉÆÉËÁÔÏÒÏ× template -class IS_CONTAINS_USER: public binary_function +class IS_CONTAINS_USER: public std::binary_function { public: IS_CONTAINS_USER(const USER_PTR & u) : user(u) {} bool operator()(varType notifier) const { return notifier.GetUser() == user; - }; + } private: const USER_PTR & user; }; +} + +extern "C" PLUGIN * GetPlugin(); +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +PLUGIN * GetPlugin() +{ +return pc.GetPlugin(); +} //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- int PING_SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { PARAM_VALUE pv; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pv.param = "PingDelay"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -138,7 +144,7 @@ for (int i = 0; i < 25; i++) users->DelNotifierUserAdd(&onAddUserNotifier); users->DelNotifierUserDel(&onDelUserNotifier); -list::iterator users_iter; +std::list::iterator users_iter; users_iter = usersList.begin(); while (users_iter != usersList.end()) { @@ -170,7 +176,7 @@ long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000; while (ping->nonstop) { - list::iterator iter = ping->usersList.begin(); + std::list::iterator iter = ping->usersList.begin(); { STG_LOCKER lock(&ping->mutex, __FILE__, __LINE__); while (iter != ping->usersList.end()) @@ -233,8 +239,8 @@ void PING::UnSetUserNotifiers(USER_PTR u) IS_CONTAINS_USER IsContainsUserCurrIP(u); IS_CONTAINS_USER IsContainsUserIP(u); -list::iterator currIPter; -list::iterator IPIter; +std::list::iterator currIPter; +std::list::iterator IPIter; currIPter = find_if(ChgCurrIPNotifierList.begin(), ChgCurrIPNotifierList.end(), @@ -303,7 +309,7 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); UnSetUserNotifiers(u); -list::iterator users_iter; +std::list::iterator users_iter; users_iter = usersList.begin(); while (users_iter != usersList.end()) diff --git a/projects/stargazer/plugins/other/ping/ping.h b/projects/stargazer/plugins/other/ping/ping.h index 421b83da..29e4974e 100644 --- a/projects/stargazer/plugins/other/ping/ping.h +++ b/projects/stargazer/plugins/other/ping/ping.h @@ -116,7 +116,7 @@ public: bool IsRunning(); const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return "Pinger v.1.01"; } + std::string GetVersion() const { return "Pinger v.1.01"; } uint16_t GetStartPosition() const { return 10; } uint16_t GetStopPosition() const { return 10; } diff --git a/projects/stargazer/plugins/other/radius/radius.cpp b/projects/stargazer/plugins/other/radius/radius.cpp index 1c060b7f..90ec1891 100644 --- a/projects/stargazer/plugins/other/radius/radius.cpp +++ b/projects/stargazer/plugins/other/radius/radius.cpp @@ -37,16 +37,20 @@ #include "stg/plugin_creator.h" #include "radius.h" -extern volatile const time_t stgTime; - -void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); -void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); -void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8); +extern volatile time_t stgTime; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR radc; + +void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password); +void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8); +void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8); +} +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -89,7 +93,7 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) printfd(__FILE__, "Cannot parse parameter 'Port'\n"); return -1; } -port = p; +port = static_cast(p); /////////////////////////// pv.param = "Password"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -292,7 +296,7 @@ int RADIUS::RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr) { int8_t buf[RAD_MAX_PACKET_LEN]; socklen_t outerAddrLen = sizeof(struct sockaddr_in); - int dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast(outerAddr), &outerAddrLen); + ssize_t dataLen = recvfrom(sock, buf, RAD_MAX_PACKET_LEN, 0, reinterpret_cast(outerAddr), &outerAddrLen); if (dataLen < 0) { logger("recvfrom error: %s", strerror(errno)); @@ -312,13 +316,13 @@ int RADIUS::RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr) return 0; } //----------------------------------------------------------------------------- -int RADIUS::Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr) +ssize_t RADIUS::Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr) { size_t len = sizeof(RAD_PACKET); char buf[1032]; Encrypt(&ctx, buf, (char *)&packet, len / 8); -int res = sendto(sock, buf, len, 0, reinterpret_cast(outerAddr), sizeof(struct sockaddr_in)); +ssize_t res = sendto(sock, buf, len, 0, reinterpret_cast(outerAddr), sizeof(struct sockaddr_in)); if (res < 0) logger("sendto error: %s", strerror(errno)); return res; @@ -351,7 +355,6 @@ switch (packet->packetType) printfd(__FILE__, "RADIUS::ProcessData Unsupported packet type: %d\n", packet->packetType); return -1; }; -return 0; } //----------------------------------------------------------------------------- int RADIUS::ProcessAutzPacket(RAD_PACKET * packet) @@ -568,6 +571,9 @@ bool RADIUS::IsAllowedService(const std::string & svc) const return CanAuthService(svc) || CanAcctService(svc); } //----------------------------------------------------------------------------- +namespace +{ + inline void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) { @@ -578,23 +584,25 @@ Blowfish_Init(ctx, keyL, RAD_PASSWORD_LEN); } //----------------------------------------------------------------------------- inline -void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8) { // len8 - длина в 8-ми байтовых блоках if (dst != src) memcpy(dst, src, len8 * 8); -for (int i = 0; i < len8; i++) - Blowfish_Encrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); +for (size_t i = 0; i < len8; i++) + Blowfish_Encrypt(ctx, static_cast(dst) + i * 2, static_cast(dst) + i * 2 + 1); } //----------------------------------------------------------------------------- inline -void Decrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, int len8) +void Decrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, unsigned long len8) { // len8 - длина в 8-ми байтовых блоках if (dst != src) memcpy(dst, src, len8 * 8); -for (int i = 0; i < len8; i++) - Blowfish_Decrypt(ctx, (uint32_t *)(dst + i*8), (uint32_t *)(dst + i*8 + 4)); +for (size_t i = 0; i < len8; i++) + Blowfish_Decrypt(ctx, static_cast(dst) + i * 2, static_cast(dst) + i * 2 + 1); } + +} // namespace anonymous diff --git a/projects/stargazer/plugins/other/radius/radius.h b/projects/stargazer/plugins/other/radius/radius.h index 8281b1ae..c424c007 100644 --- a/projects/stargazer/plugins/other/radius/radius.h +++ b/projects/stargazer/plugins/other/radius/radius.h @@ -62,12 +62,12 @@ public: authServices(), acctServices() {} virtual ~RAD_SETTINGS() {} - const string & GetStrError() const { return errorStr; } + const std::string & GetStrError() const { return errorStr; } int ParseSettings(const MODULE_SETTINGS & s); uint16_t GetPort() const { return port; } const std::string & GetPassword() const { return password; } - const std::list & GetAuthServices() const { return authServices; } - const std::list & GetAcctServices() const { return acctServices; } + const std::list & GetAuthServices() const { return authServices; } + const std::list & GetAcctServices() const { return acctServices; } private: int ParseServices(const std::vector & str, std::list * lst); @@ -102,7 +102,7 @@ public: bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return "RADIUS data access plugin v 0.6"; } + std::string GetVersion() const { return "RADIUS data access plugin v 0.6"; } uint16_t GetStartPosition() const { return 30; } uint16_t GetStopPosition() const { return 30; } @@ -116,7 +116,7 @@ private: int PrepareNet(); int FinalizeNet(); - int Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr); + ssize_t Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr); int RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr); int ProcessData(RAD_PACKET * packet); @@ -135,19 +135,19 @@ private: void PrintServices(const std::list & svcs); - struct Printer : public unary_function + struct Printer : public std::unary_function { void operator()(const std::string & line) { printfd("radius.cpp", "'%s'\n", line.c_str()); - }; + } }; - struct SPrinter : public unary_function, void> + struct SPrinter : public std::unary_function, void> { void operator()(const std::pair & it) { printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str()); - }; + } }; BLOWFISH_CTX ctx; diff --git a/projects/stargazer/plugins/other/rscript/nrmap_parser.h b/projects/stargazer/plugins/other/rscript/nrmap_parser.h index e7cb44c2..240ce349 100644 --- a/projects/stargazer/plugins/other/rscript/nrmap_parser.h +++ b/projects/stargazer/plugins/other/rscript/nrmap_parser.h @@ -60,8 +60,8 @@ public: ~NRMapParser() {} bool ReadFile(const std::string & fileName); - const std::vector & GetMap() const { return nrmap; }; - const std::string & GetErrorStr() const { return errorStr; }; + const std::vector & GetMap() const { return nrmap; } + const std::string & GetErrorStr() const { return errorStr; } private: NRMapParser(const NRMapParser & rvalue); diff --git a/projects/stargazer/plugins/other/rscript/rscript.cpp b/projects/stargazer/plugins/other/rscript/rscript.cpp index f7f892e5..d5fab222 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.cpp +++ b/projects/stargazer/plugins/other/rscript/rscript.cpp @@ -38,9 +38,7 @@ #include "ur_functor.h" #include "send_functor.h" -extern volatile const time_t stgTime; - -#define RS_MAX_ROUTERS (100) +extern volatile time_t stgTime; using RS::REMOTE_SCRIPT; @@ -55,12 +53,14 @@ struct USER_IS USER_PTR user; }; +PLUGIN_CREATOR rsc; + } // namespace anonymous +extern "C" PLUGIN * GetPlugin(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -PLUGIN_CREATOR rsc; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -86,7 +86,7 @@ int RS::SETTINGS::ParseSettings(const MODULE_SETTINGS & s) { int p; PARAM_VALUE pv; -vector::const_iterator pvi; +std::vector::const_iterator pvi; netRouters.clear(); /////////////////////////// pv.param = "Port"; @@ -103,7 +103,7 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) printfd(__FILE__, "Cannot parse parameter 'Port'\n"); return -1; } -port = p; +port = static_cast(p); /////////////////////////// pv.param = "SendPeriod"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -352,7 +352,7 @@ void REMOTE_SCRIPT::PeriodicSend() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -map::iterator it(authorizedUsers.begin()); +std::map::iterator it(authorizedUsers.begin()); while (it != authorizedUsers.end()) { if (difftime(stgTime, it->second.lastSentTime) - (rand() % halfPeriod) > sendPeriod) @@ -420,7 +420,7 @@ RS::PACKET_TAIL packetTail; memset(packetTail.padding, 0, sizeof(packetTail.padding)); strcpy((char*)packetTail.magic, RS_ID); -vector::const_iterator it; +std::vector::const_iterator it; std::string params; for(it = rsSettings.GetUserParams().begin(); it != rsSettings.GetUserParams().end(); @@ -456,7 +456,7 @@ if (PreparePacket(buffer, sizeof(buffer), rsu, forceDisconnect)) std::for_each( rsu.routers.begin(), rsu.routers.end(), - PacketSender(sock, buffer, sizeof(buffer), htons(rsSettings.GetPort())) + PacketSender(sock, buffer, sizeof(buffer), static_cast(htons(rsSettings.GetPort()))) ); return false; @@ -475,10 +475,10 @@ if (PreparePacket(buffer, sizeof(buffer), rsu, forceDisconnect)) struct sockaddr_in sendAddr; sendAddr.sin_family = AF_INET; -sendAddr.sin_port = htons(rsSettings.GetPort()); +sendAddr.sin_port = static_cast(htons(rsSettings.GetPort())); sendAddr.sin_addr.s_addr = routerIP; -int res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr)); +ssize_t res = sendto(sock, buffer, sizeof(buffer), 0, (struct sockaddr *)&sendAddr, sizeof(sendAddr)); if (res < 0) logger("sendto error: %s", strerror(errno)); @@ -515,9 +515,9 @@ for (size_t i = 0; i < netRouters.size(); ++i) return std::vector(); } //----------------------------------------------------------------------------- -string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const string & paramName) const +std::string REMOTE_SCRIPT::GetUserParam(USER_PTR u, const std::string & paramName) const { -string value = ""; +std::string value = ""; if (strcasecmp(paramName.c_str(), "cash") == 0) strprintf(&value, "%f", u->GetProperty().cash.Get()); else @@ -626,7 +626,7 @@ authorizedUsers.insert(std::make_pair(user->GetCurrIP(), rsu)); void REMOTE_SCRIPT::DelRSU(USER_PTR user) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const map::iterator it( +const std::map::iterator it( authorizedUsers.find(user->GetCurrIP()) ); if (it != authorizedUsers.end()) @@ -652,7 +652,7 @@ else rs.DelRSU(user); } //----------------------------------------------------------------------------- -void REMOTE_SCRIPT::InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const +void REMOTE_SCRIPT::InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) const { unsigned char keyL[PASSWD_LEN]; // Пароль для шифровки memset(keyL, 0, PASSWD_LEN); @@ -660,11 +660,11 @@ strncpy((char *)keyL, password.c_str(), PASSWD_LEN); Blowfish_Init(ctx, keyL, PASSWD_LEN); } //----------------------------------------------------------------------------- -void REMOTE_SCRIPT::Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const +void REMOTE_SCRIPT::Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8) const { if (dst != src) memcpy(dst, src, len8 * 8); for (size_t i = 0; i < len8; ++i) - Blowfish_Encrypt(ctx, (uint32_t *)(dst + i * 8), (uint32_t *)(dst + i * 8 + 4)); + Blowfish_Encrypt(ctx, static_cast(dst) + i * 2, static_cast(dst) + i * 2 + 1); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/plugins/other/rscript/rscript.h b/projects/stargazer/plugins/other/rscript/rscript.h index cbb9f97f..8d22b458 100644 --- a/projects/stargazer/plugins/other/rscript/rscript.h +++ b/projects/stargazer/plugins/other/rscript/rscript.h @@ -157,7 +157,7 @@ public: const std::string & GetStrError() const { return errorStr; } int ParseSettings(const MODULE_SETTINGS & s); int GetSendPeriod() const { return sendPeriod; } - int GetPort() const { return port; } + uint16_t GetPort() const { return port; } const std::vector & GetSubnetsMap() const { return netRouters; } const std::vector & GetUserParams() const { return userParams; } const std::string & GetPassword() const { return password; } @@ -166,11 +166,11 @@ public: private: int sendPeriod; uint16_t port; - string errorStr; + std::string errorStr; std::vector netRouters; - std::vector userParams; - string password; - string subnetFile; + std::vector userParams; + std::string password; + std::string subnetFile; }; //----------------------------------------------------------------------------- class REMOTE_SCRIPT : public PLUGIN { @@ -188,7 +188,7 @@ public: bool IsRunning() { return isRunning; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return "Remote script v 0.3"; } + std::string GetVersion() const { return "Remote script v 0.3"; } uint16_t GetStartPosition() const { return 10; } uint16_t GetStopPosition() const { return 10; } @@ -218,8 +218,8 @@ private: void SetUserNotifiers(USER_PTR u); void UnSetUserNotifiers(USER_PTR u); - void InitEncrypt(BLOWFISH_CTX * ctx, const string & password) const; - void Encrypt(BLOWFISH_CTX * ctx, char * dst, const char * src, size_t len8) const; + void InitEncrypt(BLOWFISH_CTX * ctx, const std::string & password) const; + void Encrypt(BLOWFISH_CTX * ctx, void * dst, const void * src, size_t len8) const; mutable BLOWFISH_CTX ctx; diff --git a/projects/stargazer/plugins/other/rscript/send_functor.h b/projects/stargazer/plugins/other/rscript/send_functor.h index b9b789ea..a14fe20b 100644 --- a/projects/stargazer/plugins/other/rscript/send_functor.h +++ b/projects/stargazer/plugins/other/rscript/send_functor.h @@ -34,14 +34,14 @@ #include "stg/os_int.h" -class PacketSender : public std::unary_function { +class PacketSender : public std::unary_function { public: - PacketSender(int s, char * b, int l, uint16_t p) + PacketSender(int s, char * b, size_t l, uint16_t p) : sock(s), buffer(b), length(l), - port(p) {}; - int operator() (uint32_t ip) + port(p) {} + ssize_t operator() (uint32_t ip) { struct sockaddr_in sendAddr; @@ -54,7 +54,7 @@ class PacketSender : public std::unary_function { private: int sock; char * buffer; - int length; + size_t length; uint16_t port; }; diff --git a/projects/stargazer/plugins/other/rscript/ur_functor.h b/projects/stargazer/plugins/other/rscript/ur_functor.h index 5d02d9dc..95382400 100644 --- a/projects/stargazer/plugins/other/rscript/ur_functor.h +++ b/projects/stargazer/plugins/other/rscript/ur_functor.h @@ -37,7 +37,7 @@ class UpdateRouter : public std::unary_function & val) { diff --git a/projects/stargazer/plugins/other/smux/smux.cpp b/projects/stargazer/plugins/other/smux/smux.cpp index 81b9ccb5..31b91bb3 100644 --- a/projects/stargazer/plugins/other/smux/smux.cpp +++ b/projects/stargazer/plugins/other/smux/smux.cpp @@ -20,12 +20,12 @@ #include "smux.h" #include "utils.h" +namespace +{ PLUGIN_CREATOR smc; -PLUGIN * GetPlugin() -{ -return smc.GetPlugin(); -} +bool SPrefixLess(const Sensors::value_type & a, + const Sensors::value_type & b); bool SPrefixLess(const Sensors::value_type & a, const Sensors::value_type & b) @@ -33,6 +33,15 @@ bool SPrefixLess(const Sensors::value_type & a, return a.first.PrefixLess(b.first); } +} + +extern "C" PLUGIN * GetPlugin(); + +PLUGIN * GetPlugin() +{ +return smc.GetPlugin(); +} + SMUX_SETTINGS::SMUX_SETTINGS() : errorStr(), ip(0), @@ -60,7 +69,7 @@ if (ParseIntInRange(pvi->value[0], 2, 65535, &p)) printfd(__FILE__, "Cannot parse parameter 'Port'\n"); return -1; } -port = p; +port = static_cast(p); pv.param = "Password"; pvi = std::find(s.moduleParams.begin(), s.moduleParams.end(), pv); diff --git a/projects/stargazer/plugins/other/smux/smux.h b/projects/stargazer/plugins/other/smux/smux.h index a33f3b27..e379ea7f 100644 --- a/projects/stargazer/plugins/other/smux/smux.h +++ b/projects/stargazer/plugins/other/smux/smux.h @@ -120,7 +120,7 @@ public: bool IsRunning() { return running && !stopped; } const std::string & GetStrError() const { return errorStr; } - const std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; } + std::string GetVersion() const { return "Stg SMUX Plugin 1.1"; } uint16_t GetStartPosition() const { return 10; } uint16_t GetStopPosition() const { return 10; } diff --git a/projects/stargazer/plugins/other/smux/tables.cpp b/projects/stargazer/plugins/other/smux/tables.cpp index 25b2dd85..c3e3ef54 100644 --- a/projects/stargazer/plugins/other/smux/tables.cpp +++ b/projects/stargazer/plugins/other/smux/tables.cpp @@ -51,8 +51,8 @@ OID prefixOid(prefix); std::map::const_iterator it(data.begin()); while (it != data.end()) { - sensors[prefixOid.copyWithSuffix(2, idx)] = new ConstSensor(it->first); - sensors[prefixOid.copyWithSuffix(3, idx)] = new ConstSensor(it->second); + sensors[prefixOid.copyWithSuffix(2, static_cast(idx))] = new ConstSensor(it->first); + sensors[prefixOid.copyWithSuffix(3, static_cast(idx))] = new ConstSensor(it->second); ++idx; ++it; } diff --git a/projects/stargazer/plugins/other/smux/types.cpp b/projects/stargazer/plugins/other/smux/types.cpp index eb09a73c..4e547492 100644 --- a/projects/stargazer/plugins/other/smux/types.cpp +++ b/projects/stargazer/plugins/other/smux/types.cpp @@ -5,6 +5,13 @@ #include "types.h" +namespace +{ + +bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos); +bool StringToArcs(const char * str, size_t length, std::vector & arcs); +bool AppendToArcs(const char * str, size_t length, std::vector & arcs); + bool ParseArcs(const char * str, ptrdiff_t length, unsigned * a, size_t * pos) { if (length == 0) @@ -16,7 +23,7 @@ size_t arcPos = 0; while ((left - str) < length) { char * pos = NULL; - unsigned arc = strtoul(left, &pos, 10); + unsigned arc = static_cast(strtoul(left, &pos, 10)); if (pos == left) return false; a[arcPos++] = arc; @@ -52,6 +59,8 @@ std::copy(&a[0], &a[pos], std::back_inserter(arcs)); return true; } +} + OID::OID(const std::string & str) : arcs() { @@ -182,7 +191,7 @@ return stream.str(); void OID::ToOID(OBJECT_IDENTIFIER_t * oid) const { -OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), arcs.size()); +OBJECT_IDENTIFIER_set_arcs(oid, &arcs.front(), sizeof(unsigned), static_cast(arcs.size())); } OID & OID::operator=(const OID & rvalue) diff --git a/projects/stargazer/plugins/other/smux/utils.cpp b/projects/stargazer/plugins/other/smux/utils.cpp index 18e2bf31..3160bc5f 100644 --- a/projects/stargazer/plugins/other/smux/utils.cpp +++ b/projects/stargazer/plugins/other/smux/utils.cpp @@ -44,7 +44,7 @@ if (left < str.length()) } arcs[arcPos++] = arc; } -OBJECT_IDENTIFIER_set_arcs(oi, arcs, sizeof(arcs[0]), arcPos); +OBJECT_IDENTIFIER_set_arcs(oi, arcs, sizeof(arcs[0]), static_cast(arcPos)); return true; } diff --git a/projects/stargazer/plugins/other/smux/value2os.h b/projects/stargazer/plugins/other/smux/value2os.h index d17cb357..c069affd 100644 --- a/projects/stargazer/plugins/other/smux/value2os.h +++ b/projects/stargazer/plugins/other/smux/value2os.h @@ -57,7 +57,7 @@ bool ValueToOS(const std::string & value, ObjectSyntax * objectSynt objectSyntax->present = ObjectSyntax_PR_simple; SimpleSyntax_t * simpleSyntax = &objectSyntax->choice.simple; simpleSyntax->present = SimpleSyntax_PR_string; -OCTET_STRING_fromBuf(&simpleSyntax->choice.string, value.c_str(), value.length()); +OCTET_STRING_fromBuf(&simpleSyntax->choice.string, value.c_str(), static_cast(value.length())); return true; } diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 334824d9..4e4489ad 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -58,15 +58,18 @@ #define adm_enc_passwd "cjeifY8m3" -using namespace std; - -int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext); +int GetFileList(std::vector * fileList, const std::string & directory, mode_t mode, const std::string & ext); const int pt_mega = 1024 * 1024; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- +namespace +{ PLUGIN_CREATOR fsc; +} + +extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -96,11 +99,11 @@ FILES_STORE_SETTINGS::FILES_STORE_SETTINGS() { } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseOwner(const vector & moduleParams, const string & owner, uid_t * uid) +int FILES_STORE_SETTINGS::ParseOwner(const std::vector & moduleParams, const std::string & owner, uid_t * uid) { PARAM_VALUE pv; pv.param = owner; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -117,11 +120,11 @@ if (User2UID(pvi->value[0].c_str(), uid) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseGroup(const vector & moduleParams, const string & group, gid_t * gid) +int FILES_STORE_SETTINGS::ParseGroup(const std::vector & moduleParams, const std::string & group, gid_t * gid) { PARAM_VALUE pv; pv.param = group; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -138,7 +141,7 @@ if (Group2GID(pvi->value[0].c_str(), gid) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseYesNo(const string & value, bool * val) +int FILES_STORE_SETTINGS::ParseYesNo(const std::string & value, bool * val) { if (0 == strcasecmp(value.c_str(), "yes")) { @@ -155,11 +158,11 @@ errorStr = "Incorrect value \'" + value + "\'."; return -1; } //----------------------------------------------------------------------------- -int FILES_STORE_SETTINGS::ParseMode(const vector & moduleParams, const string & modeStr, mode_t * mode) +int FILES_STORE_SETTINGS::ParseMode(const std::vector & moduleParams, const std::string & modeStr, mode_t * mode) { PARAM_VALUE pv; pv.param = modeStr; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -199,7 +202,7 @@ if (ParseGroup(s.moduleParams, "UserLogGroup", &userLogGID) < 0) if (ParseMode(s.moduleParams, "UserLogMode", &userLogMode) < 0) return -1; -vector::const_iterator pvi; +std::vector::const_iterator pvi; PARAM_VALUE pv; pv.param = "RemoveBak"; pvi = find(s.moduleParams.begin(), s.moduleParams.end(), pv); @@ -252,7 +255,7 @@ adminsDir = workDir + "/admins/"; return 0; } //----------------------------------------------------------------------------- -const string & FILES_STORE_SETTINGS::GetStrError() const +const std::string & FILES_STORE_SETTINGS::GetStrError() const { return errorStr; } @@ -263,7 +266,7 @@ struct passwd * pw; pw = getpwnam(user); if (!pw) { - errorStr = string("User \'") + string(user) + string("\' not found in system."); + errorStr = std::string("User \'") + std::string(user) + std::string("\' not found in system."); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -278,7 +281,7 @@ struct group * grp; grp = getgrnam(gr); if (!grp) { - errorStr = string("Group \'") + string(gr) + string("\' not found in system."); + errorStr = std::string("Group \'") + std::string(gr) + std::string("\' not found in system."); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -294,7 +297,7 @@ char b; char c; if (strlen(str) > 3) { - errorStr = string("Error parsing mode \'") + str + string("\'"); + errorStr = std::string("Error parsing mode \'") + str + std::string("\'"); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -302,7 +305,7 @@ if (strlen(str) > 3) for (int i = 0; i < 3; i++) if (str[i] > '7' || str[i] < '0') { - errorStr = string("Error parsing mode \'") + str + string("\'"); + errorStr = std::string("Error parsing mode \'") + str + std::string("\'"); printfd(__FILE__, "%s\n", errorStr.c_str()); return -1; } @@ -348,7 +351,7 @@ pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mutex, &attr); -}; +} //----------------------------------------------------------------------------- int FILES_STORE::ParseSettings() { @@ -361,14 +364,14 @@ if (ret) return ret; } //----------------------------------------------------------------------------- -int FILES_STORE::GetUsersList(vector * userList) const +int FILES_STORE::GetUsersList(std::vector * userList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetUsersDir(), S_IFDIR, "")) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetUsersDir() + "': " + string(strerror(errno)); + errorStr = "Failed to open '" + storeSettings.GetUsersDir() + "': " + std::string(strerror(errno)); return -1; } @@ -379,14 +382,14 @@ userList->swap(files); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetAdminsList(vector * adminList) const +int FILES_STORE::GetAdminsList(std::vector * adminList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetAdminsDir(), S_IFREG, ".adm")) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetAdminsDir() + "': " + string(strerror(errno)); + errorStr = "Failed to open '" + storeSettings.GetAdminsDir() + "': " + std::string(strerror(errno)); return -1; } @@ -397,14 +400,14 @@ adminList->swap(files); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetTariffsList(vector * tariffList) const +int FILES_STORE::GetTariffsList(std::vector * tariffList) const { -vector files; +std::vector files; if (GetFileList(&files, storeSettings.GetTariffsDir(), S_IFREG, ".tf")) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Failed to open '" + storeSettings.GetTariffsDir() + "': " + string(strerror(errno)); + errorStr = "Failed to open '" + storeSettings.GetTariffsDir() + "': " + std::string(strerror(errno)); return -1; } @@ -434,8 +437,8 @@ while ((entry = readdir(d))) if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))) continue; - string str = path; - str += "/" + string(entry->d_name); + std::string str = path; + str += "/" + std::string(entry->d_name); struct stat st; if (stat(str.c_str(), &st)) @@ -481,16 +484,16 @@ if (rmdir(path)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddUser(const string & login) const +int FILES_STORE::AddUser(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s%s", storeSettings.GetUsersDir().c_str(), login.c_str()); if (mkdir(fileName.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("mkdir failed. Message: '") + strerror(errno) + "'"; + errorStr = std::string("mkdir failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::AddUser - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -515,12 +518,12 @@ if (Touch(fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::DelUser(const string & login) const +int FILES_STORE::DelUser(const std::string & login) const { -string dirName; -string dirName1; +std::string dirName; +std::string dirName1; -strprintf(&dirName, "%s/"DELETED_USERS_DIR, storeSettings.GetWorkDir().c_str()); +strprintf(&dirName, "%s/%s", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR); if (access(dirName.c_str(), F_OK) != 0) { if (mkdir(dirName.c_str(), 0700) != 0) @@ -534,7 +537,7 @@ if (access(dirName.c_str(), F_OK) != 0) if (access(dirName.c_str(), F_OK) == 0) { - strprintf(&dirName, "%s/"DELETED_USERS_DIR"/%s.%lu", storeSettings.GetWorkDir().c_str(), login.c_str(), time(NULL)); + strprintf(&dirName, "%s/%s/%s.%lu", storeSettings.GetWorkDir().c_str(), DELETED_USERS_DIR, login.c_str(), time(NULL)); strprintf(&dirName1, "%s/%s", storeSettings.GetUsersDir().c_str(), login.c_str()); if (rename(dirName1.c_str(), dirName.c_str())) { @@ -555,9 +558,9 @@ else return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserConf(USER_CONF * conf, const string & login) const +int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/conf"; if (RestoreUserConf(conf, login, fileName)) { @@ -570,11 +573,11 @@ if (RestoreUserConf(conf, login, fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserConf(USER_CONF * conf, const string & login, const string & fileName) const +int FILES_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const { CONFIGFILE cf(fileName); int e = cf.Error(); -string str; +std::string str; if (e) { @@ -614,21 +617,21 @@ if (conf->tariffName.empty()) return -1; } -string ipStr; +std::string ipStr; cf.ReadString("IP", &ipStr, "?"); -USER_IPS i; +USER_IPS ips; try { - i = StrToIPS(ipStr); + ips = StrToIPS(ipStr); } -catch (const string & s) +catch (const std::string & s) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s; printfd(__FILE__, "FILES_STORE::RestoreUserConf - ip read failed for user '%s'\n", login.c_str()); return -1; } -conf->ips = i; +conf->ips = ips; if (cf.ReadInt("alwaysOnline", &conf->alwaysOnline, 0) != 0) { @@ -682,9 +685,9 @@ if (cf.ReadDouble("Credit", &conf->credit, 0) != 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserStat(USER_STAT * stat, const string & login) const +int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; if (RestoreUserStat(stat, login, fileName)) @@ -698,7 +701,7 @@ if (RestoreUserStat(stat, login, fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreUserStat(USER_STAT * stat, const string & login, const string & fileName) const +int FILES_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const { CONFIGFILE cf(fileName); @@ -721,7 +724,7 @@ for (int i = 0; i < DIR_NUM; i++) if (cf.ReadULongLongInt(s, &traff, 0) != 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s); printfd(__FILE__, "FILES_STORE::RestoreUserStat - download stat read failed for user '%s'\n", login.c_str()); return -1; } @@ -731,7 +734,7 @@ for (int i = 0; i < DIR_NUM; i++) if (cf.ReadULongLongInt(s, &traff, 0) != 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s); printfd(__FILE__, "FILES_STORE::RestoreUserStat - upload stat read failed for user '%s'\n", login.c_str()); return -1; } @@ -789,9 +792,9 @@ if (cf.ReadTime("LastActivityTime", &stat->lastActivityTime, 0) != 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::SaveUserConf(const USER_CONF & conf, const string & login) const +int FILES_STORE::SaveUserConf(const USER_CONF & conf, const std::string & login) const { -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/conf"; CONFIGFILE cfstat(fileName, true); @@ -801,7 +804,7 @@ int e = cfstat.Error(); if (e) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("User \'") + login + "\' conf not written\n"; + errorStr = std::string("User \'") + login + "\' conf not written\n"; printfd(__FILE__, "FILES_STORE::SaveUserConf - conf write failed for user '%s'\n", login.c_str()); return -1; } @@ -838,17 +841,17 @@ for (int i = 0; i < USERDATA_NUM; i++) } cfstat.WriteInt("CreditExpire", conf.creditExpire); -stringstream ipStr; +std::ostringstream ipStr; ipStr << conf.ips; cfstat.WriteString("IP", ipStr.str()); return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::SaveUserStat(const USER_STAT & stat, const string & login) const +int FILES_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const { char s[22]; -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; { @@ -858,7 +861,7 @@ fileName = storeSettings.GetUsersDir() + "/" + login + "/stat"; if (e) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("User \'") + login + "\' stat not written\n"; + errorStr = std::string("User \'") + login + "\' stat not written\n"; printfd(__FILE__, "FILES_STORE::SaveUserStat - stat write failed for user '%s'\n", login.c_str()); return -1; } @@ -891,11 +894,11 @@ if (e) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteLogString(const string & str, const string & login) const +int FILES_STORE::WriteLogString(const std::string & str, const std::string & login) const { FILE * f; time_t tm = time(NULL); -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/log"; f = fopen(fileName.c_str(), "at"); @@ -927,11 +930,11 @@ if (e) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteLog2String(const string & str, const string & login) const +int FILES_STORE::WriteLog2String(const std::string & str, const std::string & login) const { FILE * f; time_t tm = time(NULL); -string fileName; +std::string fileName; fileName = storeSettings.GetUsersDir() + "/" + login + "/log2"; f = fopen(fileName.c_str(), "at"); @@ -963,30 +966,30 @@ if (e) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserChgLog(const string & login, - const string & admLogin, +int FILES_STORE::WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message) const + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message) const { -string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" +std::string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" + paramName + "\' parameter changed from \'" + oldValue + "\' to \'" + newValue + "\'. " + message; return WriteLogString(userLogMsg, login); } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserConnect(const string & login, uint32_t ip) const +int FILES_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { -string logStr = "Connect, " + inet_ntostring(ip); +std::string logStr = "Connect, " + inet_ntostring(ip); if (WriteLogString(logStr, login)) return -1; return WriteLog2String(logStr, login); } //----------------------------------------------------------------------------- -int FILES_STORE::WriteUserDisconnect(const string & login, +int FILES_STORE::WriteUserDisconnect(const std::string & login, const DIR_TRAFF & up, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, @@ -995,7 +998,7 @@ int FILES_STORE::WriteUserDisconnect(const string & login, double freeMb, const std::string & reason) const { -stringstream logStr; +std::ostringstream logStr; logStr << "Disconnect, " << " session upload: \'" << sessionUp @@ -1022,10 +1025,10 @@ logStr << " freeMb: \'" return WriteLog2String(logStr.str(), login); } //----------------------------------------------------------------------------- -int FILES_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const +int FILES_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const { // Classic stats -string stat1; +std::string stat1; strprintf(&stat1,"%s/%s/stat.%d.%02d", storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1); @@ -1040,7 +1043,7 @@ if (s.Error()) } // New stats -string stat2; +std::string stat2; strprintf(&stat2,"%s/%s/stat2.%d.%02d", storeSettings.GetUsersDir().c_str(), login.c_str(), year + 1900, month + 1); @@ -1079,9 +1082,9 @@ s2.WriteInt("LastActivityTime", stat.lastActivityTime); return 0; } //-----------------------------------------------------------------------------*/ -int FILES_STORE::AddAdmin(const string & login) const +int FILES_STORE::AddAdmin(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); if (Touch(fileName)) @@ -1095,9 +1098,9 @@ if (Touch(fileName)) return 0; } //-----------------------------------------------------------------------------*/ -int FILES_STORE::DelAdmin(const string & login) const +int FILES_STORE::DelAdmin(const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); if (unlink(fileName.c_str())) { @@ -1116,7 +1119,7 @@ char passwordE[2 * ADM_PASSWD_LEN + 2]; char pass[ADM_PASSWD_LEN + 1]; char adminPass[ADM_PASSWD_LEN + 1]; -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login.c_str()); @@ -1165,9 +1168,9 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const +int FILES_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), login.c_str()); CONFIGFILE cf(fileName); char pass[ADM_PASSWD_LEN + 1]; @@ -1175,7 +1178,7 @@ char password[ADM_PASSWD_LEN + 1]; char passwordE[2 * ADM_PASSWD_LEN + 2]; BLOWFISH_CTX ctx; -string p; +std::string p; if (cf.Error()) { @@ -1185,8 +1188,6 @@ if (cf.Error()) return -1; } -int a; - if (cf.ReadString("password", &p, "*")) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1217,7 +1218,9 @@ else ac->password = password; -if (cf.ReadInt("ChgConf", &a, 0) == 0) +uint16_t a; + +if (cf.ReadUShortInt("ChgConf", &a, 0) == 0) ac->priv.userConf = a; else { @@ -1227,7 +1230,7 @@ else return -1; } -if (cf.ReadInt("ChgPassword", &a, 0) == 0) +if (cf.ReadUShortInt("ChgPassword", &a, 0) == 0) ac->priv.userPasswd = a; else { @@ -1237,7 +1240,7 @@ else return -1; } -if (cf.ReadInt("ChgStat", &a, 0) == 0) +if (cf.ReadUShortInt("ChgStat", &a, 0) == 0) ac->priv.userStat = a; else { @@ -1247,7 +1250,7 @@ else return -1; } -if (cf.ReadInt("ChgCash", &a, 0) == 0) +if (cf.ReadUShortInt("ChgCash", &a, 0) == 0) ac->priv.userCash = a; else { @@ -1257,7 +1260,7 @@ else return -1; } -if (cf.ReadInt("UsrAddDel", &a, 0) == 0) +if (cf.ReadUShortInt("UsrAddDel", &a, 0) == 0) ac->priv.userAddDel = a; else { @@ -1267,7 +1270,7 @@ else return -1; } -if (cf.ReadInt("ChgAdmin", &a, 0) == 0) +if (cf.ReadUShortInt("ChgAdmin", &a, 0) == 0) ac->priv.adminChg = a; else { @@ -1277,7 +1280,7 @@ else return -1; } -if (cf.ReadInt("ChgTariff", &a, 0) == 0) +if (cf.ReadUShortInt("ChgTariff", &a, 0) == 0) ac->priv.tariffChg = a; else { @@ -1287,12 +1290,12 @@ else return -1; } -if (cf.ReadInt("ChgService", &a, 0) == 0) +if (cf.ReadUShortInt("ChgService", &a, 0) == 0) ac->priv.serviceChg = a; else ac->priv.serviceChg = 0; -if (cf.ReadInt("ChgCorp", &a, 0) == 0) +if (cf.ReadUShortInt("ChgCorp", &a, 0) == 0) ac->priv.corpChg = a; else ac->priv.corpChg = 0; @@ -1300,9 +1303,9 @@ else return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddTariff(const string & name) const +int FILES_STORE::AddTariff(const std::string & name) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str()); if (Touch(fileName)) { @@ -1314,9 +1317,9 @@ if (Touch(fileName)) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::DelTariff(const string & name) const +int FILES_STORE::DelTariff(const std::string & name) const { -string fileName; +std::string fileName; strprintf(&fileName, "%s/%s.tf", storeSettings.GetTariffsDir().c_str(), name.c_str()); if (unlink(fileName.c_str())) { @@ -1329,11 +1332,11 @@ if (unlink(fileName.c_str())) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::RestoreTariff(TARIFF_DATA * td, const string & tariffName) const +int FILES_STORE::RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const { -string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; +std::string fileName = storeSettings.GetTariffsDir() + "/" + tariffName + ".tf"; CONFIGFILE conf(fileName); -string str; +std::string str; td->tariffConf.name = tariffName; if (conf.Error() != 0) @@ -1344,7 +1347,7 @@ if (conf.Error() != 0) return -1; } -string param; +std::string param; for (int i = 0; i & statTree, +int FILES_STORE::WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const + const std::string & login) const { char fn[FN_STR_LEN]; char dn[FN_STR_LEN]; @@ -1578,7 +1581,7 @@ if (access(dn, F_OK) != 0) if (mkdir(dn, 0700) != 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1611,7 +1614,7 @@ if (access(dn, F_OK) != 0) if (mkdir(dn, 0700) != 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1637,7 +1640,7 @@ if (access(dn, F_OK) != 0) if (mkdir(dn, 0700) != 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Directory \'" + string(dn) + "\' cannot be created."; + errorStr = "Directory \'" + std::string(dn) + "\' cannot be created."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - mkdir failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1659,7 +1662,7 @@ statFile = fopen (fn, "at"); if (!statFile) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "File \'" + string(fn) + "\' cannot be written."; + errorStr = "File \'" + std::string(fn) + "\' cannot be written."; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1686,18 +1689,18 @@ if (fprintf(statFile, "-> %02d.%02d.%02d - %02d.%02d.%02d\n", h1, m1, s1, h2, m2, s2) < 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprint failed. Message: '") + strerror(errno) + "'"; + errorStr = std::string("fprint failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); fclose(statFile); return -1; } -map::const_iterator stIter; +std::map::const_iterator stIter; stIter = statTree.begin(); while (stIter != statTree.end()) { - string u, d; + std::string u, d; x2str(stIter->second.up, u); x2str(stIter->second.down, d); #ifdef TRAFF_STAT_WITH_PORTS @@ -1726,7 +1729,7 @@ while (stIter != statTree.end()) stIter->second.cash) < 0) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprint failed. Message: '"); + errorStr = std::string("fprint failed. Message: '"); errorStr += strerror(errno); errorStr += "'"; printfd(__FILE__, "FILES_STORE::WriteDetailStat - fprintf failed. Message: '%s'\n", strerror(errno)); @@ -1752,10 +1755,10 @@ if (e) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::AddMessage(STG_MSG * msg, const string & login) const +int FILES_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { -string fn; -string dn; +std::string fn; +std::string dn; struct timeval tv; strprintf(&dn, "%s/%s/messages", storeSettings.GetUsersDir().c_str(), login.c_str()); @@ -1792,16 +1795,16 @@ if (Touch(fn)) return EditMessage(*msg, login); } //----------------------------------------------------------------------------- -int FILES_STORE::EditMessage(const STG_MSG & msg, const string & login) const +int FILES_STORE::EditMessage(const STG_MSG & msg, const std::string & login) const { -string fileName; +std::string fileName; FILE * msgFile; strprintf(&fileName, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), msg.header.id); if (access(fileName.c_str(), F_OK) != 0) { - string idstr; + std::string idstr; x2str(msg.header.id, idstr); STG_LOCKER lock(&mutex, __FILE__, __LINE__); errorStr = "Message for user \'"; @@ -1834,7 +1837,7 @@ res &= (fprintf(msgFile, "%s", msg.text.c_str()) >= 0); if (!res) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("fprintf failed. Message: '") + strerror(errno) + "'"; + errorStr = std::string("fprintf failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::EditMessage - fprintf failed. Message: '%s'\n", strerror(errno)); fclose(msgFile); return -1; @@ -1855,32 +1858,32 @@ if (rename((fileName + ".new").c_str(), fileName.c_str()) < 0) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::GetMessage(uint64_t id, STG_MSG * msg, const string & login) const +int FILES_STORE::GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const { -string fn; +std::string fn; strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id); msg->header.id = id; return ReadMessage(fn, &msg->header, &msg->text); } //----------------------------------------------------------------------------- -int FILES_STORE::DelMessage(uint64_t id, const string & login) const +int FILES_STORE::DelMessage(uint64_t id, const std::string & login) const { -string fn; +std::string fn; strprintf(&fn, "%s/%s/messages/%lld", storeSettings.GetUsersDir().c_str(), login.c_str(), id); return unlink(fn.c_str()); } //----------------------------------------------------------------------------- -int FILES_STORE::GetMessageHdrs(vector * hdrsList, const string & login) const +int FILES_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { -string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); +std::string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); if (access(dn.c_str(), F_OK) != 0) { return 0; } -vector messages; +std::vector messages; GetFileList(&messages, dn, S_IFREG, ""); for (unsigned i = 0; i < messages.size(); i++) @@ -1892,7 +1895,7 @@ for (unsigned i = 0; i < messages.size(); i++) if (unlink((dn + messages[i]).c_str())) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("unlink failed. Message: '") + strerror(errno) + "'"; + errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1910,7 +1913,7 @@ for (unsigned i = 0; i < messages.size(); i++) if (unlink((dn + messages[i]).c_str())) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = string("unlink failed. Message: '") + strerror(errno) + "'"; + errorStr = std::string("unlink failed. Message: '") + strerror(errno) + "'"; printfd(__FILE__, "FILES_STORE::GetMessageHdrs - unlink failed. Message: '%s'\n", strerror(errno)); return -1; } @@ -1923,9 +1926,9 @@ for (unsigned i = 0; i < messages.size(); i++) return 0; } //----------------------------------------------------------------------------- -int FILES_STORE::ReadMessage(const string & fileName, +int FILES_STORE::ReadMessage(const std::string & fileName, STG_MSG_HDR * hdr, - string * text) const + std::string * text) const { FILE * msgFile; msgFile = fopen(fileName.c_str(), "rt"); @@ -2024,7 +2027,7 @@ if (f) return -1; } //----------------------------------------------------------------------------- -int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext) +int GetFileList(std::vector * fileList, const std::string & directory, mode_t mode, const std::string & ext) { DIR * d = opendir(directory.c_str()); @@ -2040,7 +2043,7 @@ while ((entry = readdir(d))) if (!(strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))) continue; - string str = directory + "/" + string(entry->d_name); + std::string str = directory + "/" + std::string(entry->d_name); struct stat st; if (stat(str.c_str(), &st)) diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index 2316398f..1d72f287 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -39,8 +39,6 @@ #include "stg/user_traff.h" #include "stg/logger.h" -//----------------------------------------------------------------------------- -extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- class FILES_STORE_SETTINGS { public: @@ -199,7 +197,7 @@ private: int RemoveDir(const char * path) const; int Touch(const std::string & path) const; - mutable string errorStr; + mutable std::string errorStr; std::string version; FILES_STORE_SETTINGS storeSettings; MODULE_SETTINGS settings; diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.cpp b/projects/stargazer/plugins/store/firebird/firebird_store.cpp index e5c7b0b1..9cc7c304 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store.cpp @@ -34,9 +34,12 @@ #include "stg/plugin_creator.h" #include "firebird_store.h" -using namespace std; - +namespace +{ PLUGIN_CREATOR frsc; +} + +extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- STORE * GetStore() { @@ -69,13 +72,13 @@ db->Disconnect(); //----------------------------------------------------------------------------- int FIREBIRD_STORE::ParseSettings() { -vector::iterator i; -string s; +std::vector::iterator i; +std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { s = i->param; - transform(s.begin(), s.end(), s.begin(), ToLower()); + std::transform(s.begin(), s.end(), s.begin(), ToLower()); if (s == "server") { db_server = *(i->value.begin()); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store.h b/projects/stargazer/plugins/store/firebird/firebird_store.h index 38ff457d..638067f2 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store.h +++ b/projects/stargazer/plugins/store/firebird/firebird_store.h @@ -32,7 +32,6 @@ #include #include #include -#include #include "stg/store.h" #include "stg/locker.h" @@ -40,11 +39,9 @@ #include "stg/logger.h" struct ToLower { - char operator() (char c) const { return std::tolower(c); } + char operator() (char c) const { return static_cast(std::tolower(c)); } }; -extern "C" STORE * GetStore(); - class FIREBIRD_STORE : public STORE { public: FIREBIRD_STORE(); @@ -93,7 +90,7 @@ public: int GetTariffsList(std::vector * tariffsList) const; int AddTariff(const std::string & name) const; - int DelTariff(const string & name) const; + int DelTariff(const std::string & name) const; int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const; int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const; @@ -103,12 +100,12 @@ public: int AddCorp(const std::string & name) const; int DelCorp(const std::string & name) const; - inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; }; + inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); - inline const string & GetStrError() const { return strError; }; + inline const std::string & GetStrError() const { return strError; } - inline const string & GetVersion() const { return version; }; + inline const std::string & GetVersion() const { return version; } int GetServicesList(std::vector * servicesList) const; int SaveService(const SERVICE_CONF & sc) const; diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_corporations.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_corporations.cpp index 026fef92..6b457de0 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_corporations.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_corporations.cpp @@ -30,14 +30,14 @@ #include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetCorpsList(vector * corpsList) const +int FIREBIRD_STORE::GetCorpsList(std::vector * corpsList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string name; +std::string name; try { @@ -90,7 +90,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::RestoreCorp(CORP_CONF * cc, const string & name) const +int FIREBIRD_STORE::RestoreCorp(CORP_CONF * cc, const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -128,7 +128,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddCorp(const string & name) const +int FIREBIRD_STORE::AddCorp(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -155,7 +155,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelCorp(const string & name) const +int FIREBIRD_STORE::DelCorp(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_messages.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_messages.cpp index c6180c26..e14ad356 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_messages.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_messages.cpp @@ -27,13 +27,11 @@ * */ -#include - #include "firebird_store.h" #include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddMessage(STG_MSG * msg, const string & login) const +int FIREBIRD_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -70,7 +68,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::EditMessage(const STG_MSG & msg, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -108,7 +106,7 @@ return 0; //----------------------------------------------------------------------------- int FIREBIRD_STORE::GetMessage(uint64_t id, STG_MSG * msg, - const string &) const + const std::string &) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -154,7 +152,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelMessage(uint64_t id, const string &) const +int FIREBIRD_STORE::DelMessage(uint64_t id, const std::string &) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -181,8 +179,8 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetMessageHdrs(vector * hdrsList, - const string & login) const +int FIREBIRD_STORE::GetMessageHdrs(std::vector * hdrsList, + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_services.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_services.cpp index 84eab5fa..6f6bee30 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_services.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_services.cpp @@ -31,14 +31,14 @@ #include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetServicesList(vector * servicesList) const +int FIREBIRD_STORE::GetServicesList(std::vector * servicesList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string name; +std::string name; try { @@ -98,7 +98,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::RestoreService(SERVICE_CONF * sc, - const string & name) const + const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -117,7 +117,7 @@ try st->Get(4, sc->cost); int16_t pd; st->Get(5, pd); - sc->payDay = pd; + sc->payDay = static_cast(pd); } else { @@ -140,7 +140,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddService(const string & name) const +int FIREBIRD_STORE::AddService(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -168,7 +168,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelService(const string & name) const +int FIREBIRD_STORE::DelService(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp index 0fd3f2cd..1d74cf07 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp @@ -32,14 +32,14 @@ #include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetTariffsList(vector * tariffsList) const +int FIREBIRD_STORE::GetTariffsList(std::vector * tariffsList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string name; +std::string name; try { @@ -64,7 +64,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddTariff(const string & name) const +int FIREBIRD_STORE::AddTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -92,7 +92,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelTariff(const string & name) const +int FIREBIRD_STORE::DelTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -120,7 +120,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveTariff(const TARIFF_DATA & td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -228,7 +228,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::RestoreTariff(TARIFF_DATA * td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index aaa44f6b..8b21907e 100644 --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@ -31,14 +31,14 @@ #include "stg/ibpp.h" //----------------------------------------------------------------------------- -int FIREBIRD_STORE::GetUsersList(vector * usersList) const +int FIREBIRD_STORE::GetUsersList(std::vector * usersList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr); IBPP::Statement st = IBPP::StatementFactory(db, tr); -string name; +std::string name; try { @@ -63,7 +63,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::AddUser(const string & name) const +int FIREBIRD_STORE::AddUser(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -91,7 +91,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::DelUser(const string & login) const +int FIREBIRD_STORE::DelUser(const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -119,7 +119,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveUserStat(const USER_STAT & stat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -127,7 +127,7 @@ return SaveStat(stat, login); } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveStat(const USER_STAT & stat, - const string & login, + const std::string & login, int year, int month) const { @@ -227,7 +227,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::SaveUserConf(const USER_CONF & conf, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -237,7 +237,7 @@ IBPP::Statement st = IBPP::StatementFactory(db, tr); int i; int32_t uid; IBPP::Timestamp creditExpire; -vector::const_iterator it; +std::vector::const_iterator it; try { @@ -359,7 +359,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::RestoreUserStat(USER_STAT * stat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -444,7 +444,7 @@ return 0; } //----------------------------------------------------------------------------- int FIREBIRD_STORE::RestoreUserConf(USER_CONF * conf, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -455,7 +455,7 @@ int32_t uid; int i; IBPP::Timestamp timestamp; IP_MASK im; -string name; +std::string name; bool test; try @@ -566,13 +566,13 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::WriteUserChgLog(const string & login, - const string & admLogin, +int FIREBIRD_STORE::WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message = "") const + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -581,7 +581,7 @@ IBPP::Statement st = IBPP::StatementFactory(db, tr); IBPP::Timestamp now; now.Now(); -string temp = ""; // Composed message for log +std::string temp = ""; // Composed message for log try { @@ -632,7 +632,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::WriteUserConnect(const string & login, uint32_t ip) const +int FIREBIRD_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -662,7 +662,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::WriteUserDisconnect(const string & login, +int FIREBIRD_STORE::WriteUserDisconnect(const std::string & login, const DIR_TRAFF & up, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, @@ -717,9 +717,9 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::WriteDetailedStat(const map & statTree, +int FIREBIRD_STORE::WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -734,7 +734,7 @@ time_t2ts(lastStat, &statTime); try { tr->Start(); - map::const_iterator it; + std::map::const_iterator it; it = statTree.begin(); st->Prepare("insert into tb_detail_stats \ (till_time, from_time, fk_user, dir_num, \ @@ -769,7 +769,7 @@ catch (IBPP::Exception & ex) return 0; } //----------------------------------------------------------------------------- -int FIREBIRD_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const +int FIREBIRD_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); diff --git a/projects/stargazer/plugins/store/mysql/mysql_store.cpp b/projects/stargazer/plugins/store/mysql/mysql_store.cpp index 79ec39e3..b4ac8715 100644 --- a/projects/stargazer/plugins/store/mysql/mysql_store.cpp +++ b/projects/stargazer/plugins/store/mysql/mysql_store.cpp @@ -2,7 +2,6 @@ #include #include #include -#include #include #include @@ -16,20 +15,22 @@ #include "mysql_store.h" #define adm_enc_passwd "cjeifY8m3" -char qbuf[4096]; -using namespace std; +namespace +{ +char qbuf[4096]; const int pt_mega = 1024 * 1024; -const string badSyms = "'`"; +const std::string badSyms = "'`"; const char repSym = '\"'; const int RepitTimes = 3; -int GetInt(const string & str, int * val, int defaultVal) +template +int GetInt(const std::string & str, T * val, T defaultVal = T()) { char *res; - *val = strtol(str.c_str(), &res, 10); + *val = static_cast(strtoll(str.c_str(), &res, 10)); if (*res != 0) { @@ -40,7 +41,7 @@ int GetInt(const string & str, int * val, int defaultVal) return 0; } -int GetDouble(const string & str, double * val, double defaultVal) +int GetDouble(const std::string & str, double * val, double defaultVal) { char *res; @@ -55,7 +56,7 @@ int GetDouble(const string & str, double * val, double defaultVal) return 0; } -int GetTime(const string & str, time_t * val, time_t defaultVal) +int GetTime(const std::string & str, time_t * val, time_t defaultVal) { char *res; @@ -71,17 +72,17 @@ int GetTime(const string & str, time_t * val, time_t defaultVal) } //----------------------------------------------------------------------------- -string ReplaceStr(string source, const string symlist, const char chgsym) +std::string ReplaceStr(std::string source, const std::string symlist, const char chgsym) { - string::size_type pos=0; + std::string::size_type pos=0; - while( (pos = source.find_first_of(symlist,pos)) != string::npos) + while( (pos = source.find_first_of(symlist,pos)) != std::string::npos) source.replace(pos, 1,1, chgsym); return source; } -int GetULongLongInt(const string & str, uint64_t * val, uint64_t defaultVal) +int GetULongLongInt(const std::string & str, uint64_t * val, uint64_t defaultVal) { char *res; @@ -97,6 +98,9 @@ int GetULongLongInt(const string & str, uint64_t * val, uint64_t defaultVal) } PLUGIN_CREATOR msc; +} + +extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- @@ -115,12 +119,12 @@ MYSQL_STORE_SETTINGS::MYSQL_STORE_SETTINGS() { } //----------------------------------------------------------------------------- -int MYSQL_STORE_SETTINGS::ParseParam(const vector & moduleParams, - const string & name, string & result) +int MYSQL_STORE_SETTINGS::ParseParam(const std::vector & moduleParams, + const std::string & name, std::string & result) { PARAM_VALUE pv; pv.param = name; -vector::const_iterator pvi; +std::vector::const_iterator pvi; pvi = find(moduleParams.begin(), moduleParams.end(), pv); if (pvi == moduleParams.end()) { @@ -160,7 +164,7 @@ MYSQL_STORE::MYSQL_STORE() settings(), logger(GetPluginLogger(GetStgLogger(), "store_mysql")) { -}; +} //----------------------------------------------------------------------------- int MYSQL_STORE::MysqlQuery(const char* sQuery,MYSQL * sock) const { @@ -211,7 +215,7 @@ else { if(mysql_select_db(sock, storeSettings.GetDBName().c_str())) { - string res = "CREATE DATABASE " + storeSettings.GetDBName(); + std::string res = "CREATE DATABASE " + storeSettings.GetDBName(); if(MysqlQuery(res.c_str(),sock)) { @@ -241,7 +245,7 @@ else return ret; } //----------------------------------------------------------------------------- -bool MYSQL_STORE::IsTablePresent(const string & str,MYSQL * sock) +bool MYSQL_STORE::IsTablePresent(const std::string & str,MYSQL * sock) { MYSQL_RES* result; @@ -253,12 +257,12 @@ if (!(result=mysql_list_tables(sock,str.c_str() ))) return -1; } -unsigned int num_rows = mysql_num_rows(result); +my_ulonglong num_rows = mysql_num_rows(result); if(result) mysql_free_result(result); -return (num_rows == 1); +return num_rows == 1; } //----------------------------------------------------------------------------- int MYSQL_STORE::CheckAllTables(MYSQL * sock) @@ -294,7 +298,7 @@ if(!IsTablePresent("admins",sock)) } //tariffs----------------------------------------------------------------------- -string param, res; +std::string param, res; if(!IsTablePresent("tariffs",sock)) { res = "CREATE TABLE tariffs (name VARCHAR(40) DEFAULT '' PRIMARY KEY,"; @@ -523,13 +527,13 @@ return 0; //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- -int MYSQL_STORE::GetAllParams(vector * ParamList, - const string & table, const string & name) const +int MYSQL_STORE::GetAllParams(std::vector * ParamList, + const std::string & table, const std::string & name) const { MYSQL_RES *res; MYSQL_ROW row; MYSQL * sock=NULL; -unsigned int num,i; +my_ulonglong num, i; ParamList->clear(); @@ -554,7 +558,7 @@ if (!(res=mysql_store_result(sock))) num = mysql_num_rows(res); -for(i=0;ipush_back(row[0]); @@ -567,7 +571,7 @@ return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetUsersList(vector * usersList) const +int MYSQL_STORE::GetUsersList(std::vector * usersList) const { if(GetAllParams(usersList, "users", "login")) return -1; @@ -575,7 +579,7 @@ if(GetAllParams(usersList, "users", "login")) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetAdminsList(vector * adminsList) const +int MYSQL_STORE::GetAdminsList(std::vector * adminsList) const { if(GetAllParams(adminsList, "admins", "login")) return -1; @@ -583,7 +587,7 @@ if(GetAllParams(adminsList, "admins", "login")) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetTariffsList(vector * tariffsList) const +int MYSQL_STORE::GetTariffsList(std::vector * tariffsList) const { if(GetAllParams(tariffsList, "tariffs", "name")) return -1; @@ -591,7 +595,7 @@ if(GetAllParams(tariffsList, "tariffs", "name")) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::AddUser(const string & login) const +int MYSQL_STORE::AddUser(const std::string & login) const { sprintf(qbuf,"INSERT INTO users SET login='%s'", login.c_str()); @@ -605,7 +609,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::DelUser(const string & login) const +int MYSQL_STORE::DelUser(const std::string & login) const { sprintf(qbuf,"DELETE FROM users WHERE login='%s' LIMIT 1", login.c_str()); @@ -619,12 +623,12 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::RestoreUserConf(USER_CONF * conf, const string & login) const +int MYSQL_STORE::RestoreUserConf(USER_CONF * conf, const std::string & login) const { MYSQL_RES *res; MYSQL_ROW row; MYSQL * sock; -string query; +std::string query; query = "SELECT login, Password, Passive, Down, DisabledDetailStat, \ AlwaysOnline, Tariff, Address, Phone, Email, Note, \ @@ -666,7 +670,7 @@ if (mysql_num_rows(res) != 1) row = mysql_fetch_row(res); -string param; +std::string param; conf->password = row[1]; @@ -678,7 +682,7 @@ if (conf->password.empty()) return -1; } -if (GetInt(row[2],&conf->passive, 0) != 0) +if (GetInt(row[2],&conf->passive) != 0) { mysql_free_result(res); errorStr = "User \'" + login + "\' data not read. Parameter Passive."; @@ -686,7 +690,7 @@ if (GetInt(row[2],&conf->passive, 0) != 0) return -1; } -if (GetInt(row[3], &conf->disabled, 0) != 0) +if (GetInt(row[3], &conf->disabled) != 0) { mysql_free_result(res); errorStr = "User \'" + login + "\' data not read. Parameter Down."; @@ -694,7 +698,7 @@ if (GetInt(row[3], &conf->disabled, 0) != 0) return -1; } -if (GetInt(row[4], &conf->disabledDetailStat, 0) != 0) +if (GetInt(row[4], &conf->disabledDetailStat) != 0) { mysql_free_result(res); errorStr = "User \'" + login + "\' data not read. Parameter DisabledDetailStat."; @@ -702,7 +706,7 @@ if (GetInt(row[4], &conf->disabledDetailStat, 0) != 0) return -1; } -if (GetInt(row[5], &conf->alwaysOnline, 0) != 0) +if (GetInt(row[5], &conf->alwaysOnline) != 0) { mysql_free_result(res); errorStr = "User \'" + login + "\' data not read. Parameter AlwaysOnline."; @@ -744,13 +748,13 @@ for (int i = 0; i < USERDATA_NUM; i++) GetTime(row[15+USERDATA_NUM], &conf->creditExpire, 0); -string ipStr = row[16+USERDATA_NUM]; +std::string ipStr = row[16+USERDATA_NUM]; USER_IPS i; try { i = StrToIPS(ipStr); } -catch (const string & s) +catch (const std::string & s) { mysql_free_result(res); errorStr = "User \'" + login + "\' data not read. Parameter IP address. " + s; @@ -765,13 +769,13 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::RestoreUserStat(USER_STAT * stat, const string & login) const +int MYSQL_STORE::RestoreUserStat(USER_STAT * stat, const std::string & login) const { MYSQL_RES *res; MYSQL_ROW row; MYSQL * sock; -string query; +std::string query; query = "SELECT "; @@ -816,7 +820,7 @@ for (int i = 0; i < DIR_NUM; i++) if (GetULongLongInt(row[startPos+i*2], &traff, 0) != 0) { mysql_free_result(res); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s); mysql_close(sock); return -1; } @@ -826,7 +830,7 @@ for (int i = 0; i < DIR_NUM; i++) if (GetULongLongInt(row[startPos+i*2+1], &traff, 0) != 0) { mysql_free_result(res); - errorStr = "User \'" + login + "\' stat not read. Parameter " + string(s); + errorStr = "User \'" + login + "\' stat not read. Parameter " + std::string(s); mysql_close(sock); return -1; } @@ -888,10 +892,10 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::SaveUserConf(const USER_CONF & conf, const string & login) const +int MYSQL_STORE::SaveUserConf(const USER_CONF & conf, const std::string & login) const { -string param; -string res; +std::string param; +std::string res; strprintf(&res,"UPDATE users SET Password='%s', Passive=%d, Down=%d, DisabledDetailStat = %d, "\ "AlwaysOnline=%d, Tariff='%s', Address='%s', Phone='%s', Email='%s', "\ @@ -922,7 +926,7 @@ for (int i = 0; i < USERDATA_NUM; i++) strprintf(¶m, " CreditExpire=%d,", conf.creditExpire); res += param; -stringstream ipStr; +std::ostringstream ipStr; ipStr << conf.ips; strprintf(¶m, " IP='%s'", ipStr.str().c_str()); @@ -941,10 +945,10 @@ if(MysqlSetQuery(res.c_str())) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::SaveUserStat(const USER_STAT & stat, const string & login) const +int MYSQL_STORE::SaveUserStat(const USER_STAT & stat, const std::string & login) const { -string param; -string res; +std::string param; +std::string res; res = "UPDATE users SET"; @@ -981,9 +985,9 @@ if(MysqlSetQuery(res.c_str())) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteLogString(const string & str, const string & login) const +int MYSQL_STORE::WriteLogString(const std::string & str, const std::string & login) const { -string res, tempStr; +std::string res, tempStr; time_t t; tm * lt; @@ -1005,7 +1009,7 @@ if (!(result=mysql_list_tables(sock,tempStr.c_str() ))) return -1; } -unsigned int num_rows = mysql_num_rows(result); +my_ulonglong num_rows = mysql_num_rows(result); mysql_free_result(result); @@ -1025,7 +1029,7 @@ if (num_rows < 1) strprintf(&res, "%s -- %s",LogDate(t), str.c_str()); -string send; +std::string send; strprintf(&send,"INSERT INTO logs_%02d_%4d SET login='%s', text='%s'", lt->tm_mon+1, lt->tm_year+1900, @@ -1043,28 +1047,28 @@ return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteUserChgLog(const string & login, - const string & admLogin, +int MYSQL_STORE::WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message) const + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message) const { -string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" +std::string userLogMsg = "Admin \'" + admLogin + "\', " + inet_ntostring(admIP) + ": \'" + paramName + "\' parameter changed from \'" + oldValue + "\' to \'" + newValue + "\'. " + message; return WriteLogString(userLogMsg, login); } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteUserConnect(const string & login, uint32_t ip) const +int MYSQL_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { -string logStr = "Connect, " + inet_ntostring(ip); +std::string logStr = "Connect, " + inet_ntostring(ip); return WriteLogString(logStr, login); } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteUserDisconnect(const string & login, +int MYSQL_STORE::WriteUserDisconnect(const std::string & login, const DIR_TRAFF & up, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, @@ -1073,12 +1077,12 @@ int MYSQL_STORE::WriteUserDisconnect(const string & login, double /*freeMb*/, const std::string & /*reason*/) const { -string logStr = "Disconnect, "; -stringstream sssu; -stringstream sssd; -stringstream ssmu; -stringstream ssmd; -stringstream sscash; +std::string logStr = "Disconnect, "; +std::ostringstream sssu; +std::ostringstream sssd; +std::ostringstream ssmu; +std::ostringstream ssmd; +std::ostringstream sscash; ssmu << up; ssmd << down; @@ -1104,9 +1108,9 @@ return WriteLogString(logStr, login); } //----------------------------------------------------------------------------- int MYSQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, - const string & login) const + const std::string & login) const { -string param, res; +std::string param, res; strprintf(&res, "INSERT INTO stat SET login='%s', month=%d, year=%d,", login.c_str(), month+1, year+1900); @@ -1133,7 +1137,7 @@ if(MysqlSetQuery(res.c_str())) return 0; } //-----------------------------------------------------------------------------*/ -int MYSQL_STORE::AddAdmin(const string & login) const +int MYSQL_STORE::AddAdmin(const std::string & login) const { sprintf(qbuf,"INSERT INTO admins SET login='%s'", login.c_str()); @@ -1147,7 +1151,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //-----------------------------------------------------------------------------*/ -int MYSQL_STORE::DelAdmin(const string & login) const +int MYSQL_STORE::DelAdmin(const std::string & login) const { sprintf(qbuf,"DELETE FROM admins where login='%s' LIMIT 1", login.c_str()); @@ -1208,7 +1212,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const +int MYSQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { char pass[ADM_PASSWD_LEN + 1]; char password[ADM_PASSWD_LEN + 1]; @@ -1219,7 +1223,7 @@ memset(pass, 0, sizeof(pass)); memset(password, 0, sizeof(password)); memset(passwordE, 0, sizeof(passwordE)); -string p; +std::string p; MYSQL_RES *res; MYSQL_ROW row; MYSQL * sock; @@ -1252,7 +1256,6 @@ if ( mysql_num_rows(res) == 0) row = mysql_fetch_row(res); p = row[1]; -int a; if(p.length() == 0) { @@ -1284,7 +1287,9 @@ else ac->password = password; -if (GetInt(row[2], &a, 0) == 0) +uint16_t a; + +if (GetInt(row[2], &a) == 0) ac->priv.userConf = a; else { @@ -1294,7 +1299,7 @@ else return -1; } -if (GetInt(row[3], &a, 0) == 0) +if (GetInt(row[3], &a) == 0) ac->priv.userPasswd = a; else { @@ -1304,7 +1309,7 @@ else return -1; } -if (GetInt(row[4], &a, 0) == 0) +if (GetInt(row[4], &a) == 0) ac->priv.userStat = a; else { @@ -1314,7 +1319,7 @@ else return -1; } -if (GetInt(row[5], &a, 0) == 0) +if (GetInt(row[5], &a) == 0) ac->priv.userCash = a; else { @@ -1324,7 +1329,7 @@ else return -1; } -if (GetInt(row[6], &a, 0) == 0) +if (GetInt(row[6], &a) == 0) ac->priv.userAddDel = a; else { @@ -1334,7 +1339,7 @@ else return -1; } -if (GetInt(row[7], &a, 0) == 0) +if (GetInt(row[7], &a) == 0) ac->priv.tariffChg = a; else { @@ -1344,7 +1349,7 @@ else return -1; } -if (GetInt(row[8], &a, 0) == 0) +if (GetInt(row[8], &a) == 0) ac->priv.adminChg = a; else { @@ -1359,7 +1364,7 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::AddTariff(const string & name) const +int MYSQL_STORE::AddTariff(const std::string & name) const { sprintf(qbuf,"INSERT INTO tariffs SET name='%s'", name.c_str()); @@ -1373,7 +1378,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::DelTariff(const string & name) const +int MYSQL_STORE::DelTariff(const std::string & name) const { sprintf(qbuf,"DELETE FROM tariffs WHERE name='%s' LIMIT 1", name.c_str()); @@ -1387,7 +1392,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::RestoreTariff(TARIFF_DATA * td, const string & tariffName) const +int MYSQL_STORE::RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const { MYSQL_RES *res; MYSQL_ROW row; @@ -1410,12 +1415,12 @@ if (!(res=mysql_store_result(sock))) return -1; } -string str; +std::string str; td->tariffConf.name = tariffName; row = mysql_fetch_row(res); -string param; +std::string param; for (int i = 0; idirPrice[i].priceNightB /= (1024*1024); strprintf(¶m, "Threshold%d", i); - if (GetInt(row[5+i*8], &td->dirPrice[i].threshold, 0) < 0) + if (GetInt(row[5+i*8], &td->dirPrice[i].threshold) < 0) { mysql_free_result(res); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; @@ -1484,7 +1489,7 @@ for (int i = 0; idirPrice[i].singlePrice, 0) < 0) + if (GetInt(row[8+i*8], &td->dirPrice[i].singlePrice) < 0) { mysql_free_result(res); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; @@ -1493,7 +1498,7 @@ for (int i = 0; idirPrice[i].noDiscount, 0) < 0) + if (GetInt(row[7+i*8], &td->dirPrice[i].noDiscount) < 0) { mysql_free_result(res); errorStr = "Cannot read tariff " + tariffName + ". Parameter " + param; @@ -1561,11 +1566,11 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::SaveTariff(const TARIFF_DATA & td, const string & tariffName) const +int MYSQL_STORE::SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const { -string param; +std::string param; -string res="UPDATE tariffs SET"; +std::string res="UPDATE tariffs SET"; for (int i = 0; i < DIR_NUM; i++) { @@ -1589,7 +1594,7 @@ for (int i = 0; i < DIR_NUM; i++) td.dirPrice[i].threshold); res += param; - string s; + std::string s; strprintf(¶m, " Time%d", i); strprintf(&s, "%0d:%0d-%0d:%0d", @@ -1646,11 +1651,11 @@ if(MysqlSetQuery(res.c_str())) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::WriteDetailedStat(const map & statTree, +int MYSQL_STORE::WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const + const std::string & login) const { -string res, stTime, endTime, tempStr; +std::string res, stTime, endTime, tempStr; time_t t; tm * lt; @@ -1680,7 +1685,7 @@ if (!(result=mysql_list_tables(sock,tempStr.c_str() ))) return -1; } -unsigned int num_rows = mysql_num_rows(result); +my_ulonglong num_rows = mysql_num_rows(result); mysql_free_result(result); @@ -1731,7 +1736,7 @@ strprintf(&res,"INSERT INTO detailstat_%02d_%4d SET login='%s',"\ endTime.c_str() ); -map::const_iterator stIter; +std::map::const_iterator stIter; stIter = statTree.begin(); while (stIter != statTree.end()) @@ -1762,17 +1767,17 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::AddMessage(STG_MSG * msg, const string & login) const +int MYSQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { struct timeval tv; gettimeofday(&tv, NULL); -msg->header.id = ((long long)tv.tv_sec) * 1000000 + ((long long)tv.tv_usec); +msg->header.id = static_cast(tv.tv_sec) * 1000000 + static_cast(tv.tv_usec); sprintf(qbuf,"INSERT INTO messages SET login='%s', id=%lld", login.c_str(), - (long long)msg->header.id + static_cast(msg->header.id) ); if(MysqlSetQuery(qbuf)) @@ -1785,9 +1790,9 @@ if(MysqlSetQuery(qbuf)) return EditMessage(*msg, login); } //----------------------------------------------------------------------------- -int MYSQL_STORE::EditMessage(const STG_MSG & msg, const string & login) const +int MYSQL_STORE::EditMessage(const STG_MSG & msg, const std::string & login) const { -string res; +std::string res; strprintf(&res,"UPDATE messages SET type=%d, lastSendTime=%u, creationTime=%u, "\ "showTime=%u, stgRepeat=%d, repeatPeriod=%u, text='%s' "\ @@ -1800,7 +1805,7 @@ strprintf(&res,"UPDATE messages SET type=%d, lastSendTime=%u, creationTime=%u, " msg.header.repeatPeriod, (ReplaceStr(msg.text,badSyms,repSym)).c_str(), login.c_str(), - (long long)msg.header.id + msg.header.id ); if(MysqlSetQuery(res.c_str())) @@ -1813,7 +1818,7 @@ if(MysqlSetQuery(res.c_str())) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetMessage(uint64_t id, STG_MSG * msg, const string & login) const +int MYSQL_STORE::GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const { MYSQL_RES *res; MYSQL_ROW row; @@ -1896,10 +1901,10 @@ mysql_close(sock); return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::DelMessage(uint64_t id, const string & login) const +int MYSQL_STORE::DelMessage(uint64_t id, const std::string & login) const { sprintf(qbuf,"DELETE FROM messages WHERE login='%s' AND id=%lld LIMIT 1", - login.c_str(),(long long)id); + login.c_str(), static_cast(id)); if(MysqlSetQuery(qbuf)) { @@ -1911,7 +1916,7 @@ if(MysqlSetQuery(qbuf)) return 0; } //----------------------------------------------------------------------------- -int MYSQL_STORE::GetMessageHdrs(vector * hdrsList, const string & login) const +int MYSQL_STORE::GetMessageHdrs(std::vector * hdrsList, const std::string & login) const { MYSQL_RES *res; MYSQL_ROW row; @@ -1934,10 +1939,11 @@ if (!(res=mysql_store_result(sock))) return -1; } -unsigned int i, num_rows = mysql_num_rows(res); -long long int unsigned id = 0; +unsigned int i; +my_ulonglong num_rows = mysql_num_rows(res); +uint64_t id = 0; -for (i=0; i #include +#include +#include #include "stg/module_settings.h" #include "stg/store.h" #include "stg/user_traff.h" #include "stg/logger.h" -using namespace std; -//----------------------------------------------------------------------------- -extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- class MYSQL_STORE_SETTINGS { @@ -26,12 +25,12 @@ public: MYSQL_STORE_SETTINGS(); virtual ~MYSQL_STORE_SETTINGS() {} virtual int ParseSettings(const MODULE_SETTINGS & s); - virtual const string & GetStrError() const { return errorStr; } + virtual const std::string & GetStrError() const { return errorStr; } - const string & GetDBUser() const { return dbUser; } - const string & GetDBPassword() const { return dbPass; } - const string & GetDBHost() const { return dbHost; } - const string & GetDBName() const { return dbName; } + const std::string & GetDBUser() const { return dbUser; } + const std::string & GetDBPassword() const { return dbPass; } + const std::string & GetDBHost() const { return dbHost; } + const std::string & GetDBName() const { return dbName; } private: MYSQL_STORE_SETTINGS(const MYSQL_STORE_SETTINGS & rvalue); @@ -39,15 +38,15 @@ private: const MODULE_SETTINGS * settings; - int ParseParam(const vector & moduleParams, - const string & name, string & result); + int ParseParam(const std::vector & moduleParams, + const std::string & name, std::string & result); - string errorStr; + std::string errorStr; - string dbUser; - string dbPass; - string dbName; - string dbHost; + std::string dbUser; + std::string dbPass; + std::string dbName; + std::string dbHost; }; //----------------------------------------------------------------------------- class MYSQL_STORE: public STORE @@ -55,25 +54,25 @@ class MYSQL_STORE: public STORE public: MYSQL_STORE(); virtual ~MYSQL_STORE() {} - virtual const string & GetStrError() const { return errorStr; } + virtual const std::string & GetStrError() const { return errorStr; } //User - virtual int GetUsersList(vector * usersList) const; - virtual int AddUser(const string & login) const; - virtual int DelUser(const string & login) const; - virtual int SaveUserStat(const USER_STAT & stat, const string & login) const; - virtual int SaveUserConf(const USER_CONF & conf, const string & login) const; - virtual int RestoreUserStat(USER_STAT * stat, const string & login) const; - virtual int RestoreUserConf(USER_CONF * conf, const string & login) const; - virtual int WriteUserChgLog(const string & login, - const string & admLogin, + virtual int GetUsersList(std::vector * usersList) const; + virtual int AddUser(const std::string & login) const; + virtual int DelUser(const std::string & login) const; + virtual int SaveUserStat(const USER_STAT & stat, const std::string & login) const; + virtual int SaveUserConf(const USER_CONF & conf, const std::string & login) const; + virtual int RestoreUserStat(USER_STAT * stat, const std::string & login) const; + virtual int RestoreUserConf(USER_CONF * conf, const std::string & login) const; + virtual int WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message = "") const; - virtual int WriteUserConnect(const string & login, uint32_t ip) const; - virtual int WriteUserDisconnect(const string & login, + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const; + virtual int WriteUserConnect(const std::string & login, uint32_t ip) const; + virtual int WriteUserDisconnect(const std::string & login, const DIR_TRAFF & up, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, @@ -82,64 +81,64 @@ public: double freeMb, const std::string & reason) const; - virtual int WriteDetailedStat(const map & statTree, + virtual int WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const; + const std::string & login) const; - virtual int AddMessage(STG_MSG * msg, const string & login) const; - virtual int EditMessage(const STG_MSG & msg, const string & login) const; - virtual int GetMessage(uint64_t id, STG_MSG * msg, const string & login) const; - virtual int DelMessage(uint64_t id, const string & login) const; - virtual int GetMessageHdrs(vector * hdrsList, const string & login) const; + virtual int AddMessage(STG_MSG * msg, const std::string & login) const; + virtual int EditMessage(const STG_MSG & msg, const std::string & login) const; + virtual int GetMessage(uint64_t id, STG_MSG * msg, const std::string & login) const; + virtual int DelMessage(uint64_t id, const std::string & login) const; + virtual int GetMessageHdrs(std::vector * hdrsList, const std::string & login) const; - virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const; + virtual int SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const; //Admin - virtual int GetAdminsList(vector * adminsList) const; - virtual int AddAdmin(const string & login) const; - virtual int DelAdmin(const string & login) const; - virtual int RestoreAdmin(ADMIN_CONF * ac, const string & login) const; + virtual int GetAdminsList(std::vector * adminsList) const; + virtual int AddAdmin(const std::string & login) const; + virtual int DelAdmin(const std::string & login) const; + virtual int RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const; virtual int SaveAdmin(const ADMIN_CONF & ac) const; //Tariff - virtual int GetTariffsList(vector * tariffsList) const; - virtual int AddTariff(const string & name) const; - virtual int DelTariff(const string & name) const; - virtual int SaveTariff(const TARIFF_DATA & td, const string & tariffName) const; - virtual int RestoreTariff(TARIFF_DATA * td, const string & tariffName) const; + virtual int GetTariffsList(std::vector * tariffsList) const; + virtual int AddTariff(const std::string & name) const; + virtual int DelTariff(const std::string & name) const; + virtual int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const; + virtual int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const; //Corparation - virtual int GetCorpsList(vector *) const {return 0;}; - virtual int SaveCorp(const CORP_CONF &) const {return 0;}; - virtual int RestoreCorp(CORP_CONF *, const string &) const {return 0;}; - virtual int AddCorp(const string &) const {return 0;}; - virtual int DelCorp(const string &) const {return 0;}; + virtual int GetCorpsList(std::vector *) const {return 0;} + virtual int SaveCorp(const CORP_CONF &) const {return 0;} + virtual int RestoreCorp(CORP_CONF *, const std::string &) const {return 0;} + virtual int AddCorp(const std::string &) const {return 0;} + virtual int DelCorp(const std::string &) const {return 0;} // Services - virtual int GetServicesList(vector *) const {return 0;}; - virtual int SaveService(const SERVICE_CONF &) const {return 0;}; - virtual int RestoreService(SERVICE_CONF *, const string &) const {return 0;}; - virtual int AddService(const string &) const {return 0;}; - virtual int DelService(const string &) const {return 0;}; + virtual int GetServicesList(std::vector *) const {return 0;} + virtual int SaveService(const SERVICE_CONF &) const {return 0;} + virtual int RestoreService(SERVICE_CONF *, const std::string &) const {return 0;} + virtual int AddService(const std::string &) const {return 0;} + virtual int DelService(const std::string &) const {return 0;} virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; } virtual int ParseSettings(); - virtual const string & GetVersion() const { return version; } + virtual const std::string & GetVersion() const { return version; } private: MYSQL_STORE(const MYSQL_STORE & rvalue); MYSQL_STORE & operator=(const MYSQL_STORE & rvalue); - virtual int WriteLogString(const string & str, const string & login) const; - int GetAllParams(vector * ParamList, const string & table, const string & name) const; + virtual int WriteLogString(const std::string & str, const std::string & login) const; + int GetAllParams(std::vector * ParamList, const std::string & table, const std::string & name) const; int CheckAllTables(MYSQL * sock); - bool IsTablePresent(const string & str,MYSQL * sock); - mutable string errorStr; + bool IsTablePresent(const std::string & str,MYSQL * sock); + mutable std::string errorStr; int MysqlQuery(const char* sQuery,MYSQL * sock) const; int MysqlGetQuery(const char * Query,MYSQL * & sock) const; int MysqlSetQuery(const char * Query) const; MYSQL * MysqlConnect() const ; - string version; + std::string version; MYSQL_STORE_SETTINGS storeSettings; MODULE_SETTINGS settings; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp index 7c79baff..dd2fbbab 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.cpp @@ -49,12 +49,17 @@ #include "postgresql_store_utils.h" #include "postgresql_store.h" -PLUGIN_CREATOR pqStoreeCreator; +namespace +{ +PLUGIN_CREATOR pgsc; +} + +extern "C" STORE * GetStore(); //----------------------------------------------------------------------------- STORE * GetStore() { -return pqStoreeCreator.GetPlugin(); +return pgsc.GetPlugin(); } //----------------------------------------------------------------------------- @@ -88,7 +93,7 @@ pthread_mutex_destroy(&mutex); int POSTGRESQL_STORE::ParseSettings() { std::vector::iterator i; -string s; +std::string s; for(i = settings.moduleParams.begin(); i != settings.moduleParams.end(); ++i) { diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store.h b/projects/stargazer/plugins/store/postgresql/postgresql_store.h index a30d3852..72a2c22c 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store.h +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store.h @@ -33,7 +33,6 @@ #include #include -#include #include "stg/store.h" #include "stg/logger.h" @@ -42,8 +41,6 @@ // Recommended DB version is 6 (support FreeMb logging on disconnects) #define DB_MIN_VERSION 5 -extern "C" STORE * GetStore(); - class POSTGRESQL_STORE : public STORE { public: POSTGRESQL_STORE(); @@ -97,7 +94,7 @@ public: // Tariffs int GetTariffsList(std::vector * tariffsList) const; int AddTariff(const std::string & name) const; - int DelTariff(const string & name) const; + int DelTariff(const std::string & name) const; int SaveTariff(const TARIFF_DATA & td, const std::string & tariffName) const; int RestoreTariff(TARIFF_DATA * td, const std::string & tariffName) const; @@ -116,11 +113,11 @@ public: int DelService(const std::string & name) const; // Settings - inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; }; + inline void SetSettings(const MODULE_SETTINGS & s) { settings = s; } int ParseSettings(); - inline const string & GetStrError() const { return strError; }; - inline const string & GetVersion() const { return versionString; }; + inline const std::string & GetStrError() const { return strError; } + inline const std::string & GetVersion() const { return versionString; } private: POSTGRESQL_STORE(const POSTGRESQL_STORE & rvalue); POSTGRESQL_STORE & operator=(const POSTGRESQL_STORE & rvalue); @@ -131,8 +128,8 @@ private: int EscapeString(std::string & value) const; - std::string Int2TS(uint32_t value) const; - uint32_t TS2Int(const std::string & value) const; + std::string Int2TS(time_t value) const; + time_t TS2Int(const std::string & value) const; int SaveStat(const USER_STAT & stat, const std::string & login, int year = 0, int month = 0) const; @@ -163,6 +160,4 @@ private: PLUGIN_LOGGER logger; }; -extern const volatile time_t stgTime; - #endif //POSTGRESQL_STORE_H diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp index 5b27cb80..1e9db12d 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp @@ -134,10 +134,10 @@ for (int i = 0; i < ADM_PASSWD_LEN / 8; i++) cryptedPass[ADM_PASSWD_LEN] = 0; Encode12(encodedPass, cryptedPass, ADM_PASSWD_LEN); -std::string password = encodedPass; +std::string pass = encodedPass; std::string login = ac.login; -if (EscapeString(password)) +if (EscapeString(pass)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape password'\n"); if (RollbackTransaction()) @@ -159,7 +159,7 @@ if (EscapeString(login)) std::stringstream query; query << "UPDATE tb_admins SET " - << "passwd = '" << password << "', " + << "passwd = '" << pass << "', " << "chg_conf = " << ac.priv.userConf << ", " << "chg_password = " << ac.priv.userPasswd << ", " << "chg_stat = " << ac.priv.userStat << ", " @@ -195,7 +195,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const +int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -234,7 +234,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT login, passwd, \ chg_conf, chg_password, chg_stat, \ chg_cash, usr_add_del, chg_tariff, \ @@ -316,7 +316,7 @@ ac->password = adminPass; return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddAdmin(const string & login) const +int POSTGRESQL_STORE::AddAdmin(const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -351,7 +351,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "INSERT INTO tb_admins \ (login, passwd, \ chg_conf, chg_password, chg_stat, \ @@ -386,7 +386,7 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelAdmin(const string & login) const +int POSTGRESQL_STORE::DelAdmin(const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -421,7 +421,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_admins WHERE login = '" << elogin << "'"; result = PQexec(connection, query.str().c_str()); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp index c358a4c5..1d33d5b0 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_corporations.cpp @@ -36,7 +36,7 @@ #include "stg/locker.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetCorpsList(vector * corpsList) const +int POSTGRESQL_STORE::GetCorpsList(std::vector * corpsList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -127,7 +127,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_corporations SET " << "cash = " << cc.cash << "WHERE name = '" << ename << "'"; @@ -158,7 +158,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreCorp(CORP_CONF * cc, const string & name) const +int POSTGRESQL_STORE::RestoreCorp(CORP_CONF * cc, const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -193,7 +193,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT cash FROM tb_corporations WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@ -241,7 +241,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddCorp(const string & name) const +int POSTGRESQL_STORE::AddCorp(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -276,7 +276,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "INSERT INTO tb_corporations \ (name, cash) \ VALUES \ @@ -308,7 +308,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelCorp(const string & name) const +int POSTGRESQL_STORE::DelCorp(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -343,7 +343,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_corporations WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp index 4260c3b4..bccef5aa 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_messages.cpp @@ -38,7 +38,7 @@ #include "stg/message.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const string & login) const +int POSTGRESQL_STORE::AddMessage(STG_MSG * msg, const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -84,7 +84,7 @@ if (EscapeString(etext)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT sp_add_message(" << "'" << elogin << "', " << "CAST(1 AS SMALLINT), " // Here need to be a version, but, it's uninitiated actually @@ -141,7 +141,7 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::EditMessage(const STG_MSG & msg, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -187,7 +187,7 @@ if (EscapeString(etext)) return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_messages SET " << "fk_user = (SELECT pk_user FROM tb_users WHERE name = '" << elogin << "'), " << "ver = " << msg.header.ver << ", " @@ -227,7 +227,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetMessage(uint64_t id, STG_MSG * msg, - const string &) const + const std::string &) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -242,7 +242,7 @@ if (PQstatus(connection) != CONNECTION_OK) } } -string login; +std::string login; PGresult * result; if (StartTransaction()) @@ -251,7 +251,7 @@ if (StartTransaction()) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT ver, msg_type, last_send_time, \ creation_time, show_time, repeat, \ repeat_period, msg_text \ @@ -286,17 +286,10 @@ if (tuples != 1) return -1; } -/*std::stringstream tuple; - -for (int i = 0; i < 8; ++i) - { - tuple << PQgetvalue(result, 0, i) << " "; - }*/ - str2x(PQgetvalue(result, 0, 0), msg->header.ver); str2x(PQgetvalue(result, 0, 1), msg->header.type); -msg->header.lastSendTime = TS2Int(PQgetvalue(result, 0, 2)); -msg->header.creationTime = TS2Int(PQgetvalue(result, 0, 3)); +msg->header.lastSendTime = static_cast(TS2Int(PQgetvalue(result, 0, 2))); +msg->header.creationTime = static_cast(TS2Int(PQgetvalue(result, 0, 3))); str2x(PQgetvalue(result, 0, 4), msg->header.showTime); str2x(PQgetvalue(result, 0, 5), msg->header.repeat); str2x(PQgetvalue(result, 0, 6), msg->header.repeatPeriod); @@ -304,15 +297,6 @@ msg->text = PQgetvalue(result, 0, 7); PQclear(result); -/*tuple >> msg->header.ver; -tuple >> msg->header.type; -tuple >> msg->header.lastSendTime; -tuple >> msg->header.creationTime; -tuple >> msg->header.showTime; -tuple >> msg->header.repeat; -tuple >> msg->header.repeatPeriod; -tuple >> msg->text;*/ - if (CommitTransaction()) { printfd(__FILE__, "POSTGRESQL_STORE::GetMessage(): 'Failed to commit transaction'\n"); @@ -322,7 +306,7 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelMessage(uint64_t id, const string &) const +int POSTGRESQL_STORE::DelMessage(uint64_t id, const std::string &) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -345,7 +329,7 @@ if (StartTransaction()) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_messages WHERE pk_message = " << id; result = PQexec(connection, query.str().c_str()); @@ -373,8 +357,8 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetMessageHdrs(vector * hdrsList, - const string & login) const +int POSTGRESQL_STORE::GetMessageHdrs(std::vector * hdrsList, + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -409,7 +393,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT pk_message, ver, msg_type, \ last_send_time, creation_time, show_time, \ repeat, repeat_period \ @@ -441,8 +425,8 @@ for (int i = 0; i < tuples; ++i) tuple << PQgetvalue(result, i, 0) << " "; tuple << PQgetvalue(result, i, 1) << " "; tuple << PQgetvalue(result, i, 2) << " "; - header.lastSendTime = TS2Int(PQgetvalue(result, i, 3)); - header.creationTime = TS2Int(PQgetvalue(result, i, 4)); + header.lastSendTime = static_cast(TS2Int(PQgetvalue(result, i, 3))); + header.creationTime = static_cast(TS2Int(PQgetvalue(result, i, 4))); tuple << PQgetvalue(result, i, 5) << " "; tuple << PQgetvalue(result, i, 6) << " "; tuple << PQgetvalue(result, i, 7) << " "; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp index b509c0f0..825f7982 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_services.cpp @@ -37,7 +37,7 @@ #include "stg/locker.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetServicesList(vector * servicesList) const +int POSTGRESQL_STORE::GetServicesList(std::vector * servicesList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -139,7 +139,7 @@ if (EscapeString(ecomment)) return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_services SET " << "comment = '" << ecomment << "', " << "cost = " << sc.cost << ", " @@ -173,7 +173,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::RestoreService(SERVICE_CONF * sc, - const string & name) const + const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -208,7 +208,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT comment, cost, pay_day FROM tb_services WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@ -260,7 +260,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddService(const string & name) const +int POSTGRESQL_STORE::AddService(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -295,7 +295,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "INSERT INTO tb_services \ (name, comment, cost, pay_day) \ VALUES \ @@ -327,7 +327,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelService(const string & name) const +int POSTGRESQL_STORE::DelService(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -362,7 +362,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_services WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp index 7d63b574..fb8caf9d 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_tariffs.cpp @@ -37,7 +37,7 @@ #include "stg/locker.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetTariffsList(vector * tariffsList) const +int POSTGRESQL_STORE::GetTariffsList(std::vector * tariffsList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -93,7 +93,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddTariff(const string & name) const +int POSTGRESQL_STORE::AddTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -128,7 +128,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT sp_add_tariff('" << ename << "', " << DIR_NUM << ")"; result = PQexec(connection, query.str().c_str()); @@ -156,7 +156,7 @@ if (CommitTransaction()) return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelTariff(const string & name) const +int POSTGRESQL_STORE::DelTariff(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -191,7 +191,7 @@ if (EscapeString(ename)) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_tariffs WHERE name = '" << ename << "'"; result = PQexec(connection, query.str().c_str()); @@ -220,7 +220,7 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveTariff(const TARIFF_DATA & td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -259,10 +259,12 @@ int32_t id, i; double pda, pdb, pna, pnb; int threshold; -std::stringstream query; -query << "SELECT pk_tariff FROM tb_tariffs WHERE name = '" << ename << "'"; + { + std::ostringstream query; + query << "SELECT pk_tariff FROM tb_tariffs WHERE name = '" << ename << "'"; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -290,22 +292,26 @@ if (tuples != 1) return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0); + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0); -PQclear(result); + PQclear(result); -tuple >> id; + tuple >> id; + } -query.str(""); -query << "UPDATE tb_tariffs SET \ - fee = " << td.tariffConf.fee << ", \ - free = " << td.tariffConf.free << ", \ - passive_cost = " << td.tariffConf.passiveCost << ", \ - traff_type = " << td.tariffConf.traffType << " \ - WHERE pk_tariff = " << id; + { + std::ostringstream query; + query << "UPDATE tb_tariffs SET \ + fee = " << td.tariffConf.fee << ", \ + free = " << td.tariffConf.free << ", \ + passive_cost = " << td.tariffConf.passiveCost << ", \ + traff_type = " << td.tariffConf.traffType << " \ + WHERE pk_tariff = " << id; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_COMMAND_OK) { @@ -347,22 +353,24 @@ for(i = 0; i < DIR_NUM; i++) threshold = td.dirPrice[i].threshold; } - std::stringstream query; - query << "UPDATE tb_tariffs_params SET \ - price_day_a = " << pda << ", \ - price_day_b = " << pdb << ", \ - price_night_a = " << pna << ", \ - price_night_b = " << pnb << ", \ - threshold = " << threshold << ", \ - time_day_begins = CAST('" << td.dirPrice[i].hDay - << ":" - << td.dirPrice[i].mDay << "' AS TIME), \ - time_day_ends = CAST('" << td.dirPrice[i].hNight - << ":" - << td.dirPrice[i].mNight << "' AS TIME) \ - WHERE fk_tariff = " << id << " AND dir_num = " << i; - - result = PQexec(connection, query.str().c_str()); + { + std::ostringstream query; + query << "UPDATE tb_tariffs_params SET \ + price_day_a = " << pda << ", \ + price_day_b = " << pdb << ", \ + price_night_a = " << pna << ", \ + price_night_b = " << pnb << ", \ + threshold = " << threshold << ", \ + time_day_begins = CAST('" << td.dirPrice[i].hDay + << ":" + << td.dirPrice[i].mDay << "' AS TIME), \ + time_day_ends = CAST('" << td.dirPrice[i].hNight + << ":" + << td.dirPrice[i].mNight << "' AS TIME) \ + WHERE fk_tariff = " << id << " AND dir_num = " << i; + + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_COMMAND_OK) { @@ -389,7 +397,7 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::RestoreTariff(TARIFF_DATA * td, - const string & tariffName) const + const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -426,7 +434,7 @@ if (EscapeString(ename)) td->tariffConf.name = tariffName; -std::stringstream query; +std::ostringstream query; query << "SELECT pk_tariff, \ fee, \ free, \ @@ -462,19 +470,22 @@ if (tuples != 1) return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0) << " "; -tuple << PQgetvalue(result, 0, 1) << " "; -tuple << PQgetvalue(result, 0, 2) << " "; -tuple << PQgetvalue(result, 0, 3) << " "; -tuple << PQgetvalue(result, 0, 4) << " "; - int id; -tuple >> id; -tuple >> td->tariffConf.fee; -tuple >> td->tariffConf.free; -tuple >> td->tariffConf.passiveCost; -tuple >> td->tariffConf.traffType; + + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0) << " "; + tuple << PQgetvalue(result, 0, 1) << " "; + tuple << PQgetvalue(result, 0, 2) << " "; + tuple << PQgetvalue(result, 0, 3) << " "; + tuple << PQgetvalue(result, 0, 4) << " "; + + tuple >> id; + tuple >> td->tariffConf.fee; + tuple >> td->tariffConf.free; + tuple >> td->tariffConf.passiveCost; + tuple >> td->tariffConf.traffType; + } PQclear(result); @@ -515,34 +526,36 @@ if (tuples != DIR_NUM) for (int i = 0; i < std::min(tuples, DIR_NUM); ++i) { - std::stringstream tuple; - tuple << PQgetvalue(result, i, 0) << " "; - tuple << PQgetvalue(result, i, 1) << " "; - tuple << PQgetvalue(result, i, 2) << " "; - tuple << PQgetvalue(result, i, 3) << " "; - tuple << PQgetvalue(result, i, 4) << " "; - tuple << PQgetvalue(result, i, 5) << " "; - tuple << PQgetvalue(result, i, 6) << " "; - tuple << PQgetvalue(result, i, 7) << " "; - tuple << PQgetvalue(result, i, 8) << " "; - tuple << PQgetvalue(result, i, 9) << " "; - int dir; - tuple >> dir; - tuple >> td->dirPrice[dir].priceDayA; - td->dirPrice[dir].priceDayA /= 1024 * 1024; - tuple >> td->dirPrice[dir].priceDayB; - td->dirPrice[dir].priceDayB /= 1024 * 1024; - tuple >> td->dirPrice[dir].priceNightA; - td->dirPrice[dir].priceNightA /= 1024 * 1024; - tuple >> td->dirPrice[dir].priceNightB; - td->dirPrice[dir].priceNightB /= 1024 * 1024; - tuple >> td->dirPrice[dir].threshold; - tuple >> td->dirPrice[dir].hDay; - tuple >> td->dirPrice[dir].mDay; - tuple >> td->dirPrice[dir].hNight; - tuple >> td->dirPrice[dir].mNight; + { + std::stringstream tuple; + tuple << PQgetvalue(result, i, 0) << " "; + tuple << PQgetvalue(result, i, 1) << " "; + tuple << PQgetvalue(result, i, 2) << " "; + tuple << PQgetvalue(result, i, 3) << " "; + tuple << PQgetvalue(result, i, 4) << " "; + tuple << PQgetvalue(result, i, 5) << " "; + tuple << PQgetvalue(result, i, 6) << " "; + tuple << PQgetvalue(result, i, 7) << " "; + tuple << PQgetvalue(result, i, 8) << " "; + tuple << PQgetvalue(result, i, 9) << " "; + + tuple >> dir; + tuple >> td->dirPrice[dir].priceDayA; + td->dirPrice[dir].priceDayA /= 1024 * 1024; + tuple >> td->dirPrice[dir].priceDayB; + td->dirPrice[dir].priceDayB /= 1024 * 1024; + tuple >> td->dirPrice[dir].priceNightA; + td->dirPrice[dir].priceNightA /= 1024 * 1024; + tuple >> td->dirPrice[dir].priceNightB; + td->dirPrice[dir].priceNightB /= 1024 * 1024; + tuple >> td->dirPrice[dir].threshold; + tuple >> td->dirPrice[dir].hDay; + tuple >> td->dirPrice[dir].mDay; + tuple >> td->dirPrice[dir].hNight; + tuple >> td->dirPrice[dir].mNight; + } if (std::fabs(td->dirPrice[dir].priceDayA - td->dirPrice[dir].priceNightA) > 1.0e-3 && std::fabs(td->dirPrice[dir].priceDayB - td->dirPrice[dir].priceNightB) > 1.0e-3) diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index 11c757f2..4cd64418 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@ -39,7 +39,7 @@ #include "postgresql_store.h" //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::GetUsersList(vector * usersList) const +int POSTGRESQL_STORE::GetUsersList(std::vector * usersList) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -95,7 +95,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::AddUser(const string & name) const +int POSTGRESQL_STORE::AddUser(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -130,7 +130,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT sp_add_user('" << elogin << "')"; result = PQexec(connection, query.str().c_str()); @@ -159,7 +159,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::DelUser(const string & login) const +int POSTGRESQL_STORE::DelUser(const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -194,7 +194,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "DELETE FROM tb_users WHERE name = '" << elogin << "'"; result = PQexec(connection, query.str().c_str()); @@ -223,7 +223,7 @@ return 0; } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveUserStat(const USER_STAT & stat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -231,7 +231,7 @@ return SaveStat(stat, login); } //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveStat(const USER_STAT & stat, - const string & login, + const std::string & login, int year, int month) const { @@ -266,7 +266,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "UPDATE tb_users SET " "cash = " << stat.cash << ", " "free_mb = " << stat.freeMb << ", " @@ -334,7 +334,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::SaveUserConf(const USER_CONF & conf, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -369,7 +369,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT pk_user FROM tb_users WHERE name = '" << elogin << "'"; result = PQexec(connection, query.str().c_str()); @@ -400,14 +400,16 @@ if (tuples != 1) return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0); +uint32_t uid; -PQclear(result); + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0); -uint32_t uid; + PQclear(result); -tuple >> uid; + tuple >> uid; + } std::string eaddress = conf.address; std::string eemail = conf.email; @@ -603,7 +605,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::RestoreUserStat(USER_STAT * stat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -638,14 +640,16 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; -query << "SELECT cash, free_mb, " - "last_activity_time, last_cash_add, " - "last_cash_add_time, passive_time " - "FROM tb_users " - "WHERE name = '" << elogin << "'"; + { + std::ostringstream query; + query << "SELECT cash, free_mb, " + "last_activity_time, last_cash_add, " + "last_cash_add_time, passive_time " + "FROM tb_users " + "WHERE name = '" << elogin << "'"; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -673,29 +677,32 @@ if (tuples != 1) return -1; } -std::stringstream tuple; -tuple << PQgetvalue(result, 0, 0) << " "; -tuple << PQgetvalue(result, 0, 1) << " "; -stat->lastActivityTime = TS2Int(PQgetvalue(result, 0, 2)); -tuple << PQgetvalue(result, 0, 3) << " "; -stat->lastCashAddTime = TS2Int(PQgetvalue(result, 0, 4)); -tuple << PQgetvalue(result, 0, 5) << " "; - -PQclear(result); + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0) << " "; + tuple << PQgetvalue(result, 0, 1) << " "; + stat->lastActivityTime = TS2Int(PQgetvalue(result, 0, 2)); + tuple << PQgetvalue(result, 0, 3) << " "; + stat->lastCashAddTime = TS2Int(PQgetvalue(result, 0, 4)); + tuple << PQgetvalue(result, 0, 5) << " "; -tuple >> stat->cash - >> stat->freeMb - >> stat->lastCashAdd - >> stat->passiveTime; + PQclear(result); -query.str(""); + tuple >> stat->cash + >> stat->freeMb + >> stat->lastCashAdd + >> stat->passiveTime; + } -query << "SELECT dir_num, upload, download " - "FROM tb_stats_traffic " - "WHERE fk_user IN (SELECT pk_user FROM tb_users WHERE name = '" << elogin << "') AND " - "DATE_TRUNC('month', stats_date) = DATE_TRUNC('month', CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP))"; + { + std::ostringstream query; + query << "SELECT dir_num, upload, download " + "FROM tb_stats_traffic " + "WHERE fk_user IN (SELECT pk_user FROM tb_users WHERE name = '" << elogin << "') AND " + "DATE_TRUNC('month', stats_date) = DATE_TRUNC('month', CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP))"; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -738,7 +745,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::RestoreUserConf(USER_CONF * conf, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -773,21 +780,23 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; -query << "SELECT tb_users.pk_user, tb_users.address, tb_users.always_online, " - "tb_users.credit, tb_users.credit_expire, tb_users.disabled, " - "tb_users.disabled_detail_stat, tb_users.email, tb_users.grp, " - "tb_users.note, tb_users.passive, tb_users.passwd, tb_users.phone, " - "tb_users.real_name, tf1.name, tf2.name, tb_corporations.name " - "FROM tb_users LEFT JOIN tb_tariffs AS tf1 " - "ON tf1.pk_tariff = tb_users.fk_tariff " - "LEFT JOIN tb_tariffs AS tf2 " - "ON tf2.pk_tariff = tb_users.fk_tariff_change " - "LEFT JOIN tb_corporations " - "ON tb_corporations.pk_corporation = tb_users.fk_corporation " - "WHERE tb_users.name = '" << elogin << "'"; + { + std::ostringstream query; + query << "SELECT tb_users.pk_user, tb_users.address, tb_users.always_online, " + "tb_users.credit, tb_users.credit_expire, tb_users.disabled, " + "tb_users.disabled_detail_stat, tb_users.email, tb_users.grp, " + "tb_users.note, tb_users.passive, tb_users.passwd, tb_users.phone, " + "tb_users.real_name, tf1.name, tf2.name, tb_corporations.name " + "FROM tb_users LEFT JOIN tb_tariffs AS tf1 " + "ON tf1.pk_tariff = tb_users.fk_tariff " + "LEFT JOIN tb_tariffs AS tf2 " + "ON tf2.pk_tariff = tb_users.fk_tariff_change " + "LEFT JOIN tb_corporations " + "ON tb_corporations.pk_corporation = tb_users.fk_corporation " + "WHERE tb_users.name = '" << elogin << "'"; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -817,43 +826,46 @@ if (tuples != 1) uint32_t uid; -std::stringstream tuple; - -tuple << PQgetvalue(result, 0, 0) << " "; // uid -conf->address = PQgetvalue(result, 0, 1); // address -conf->alwaysOnline = !strncmp(PQgetvalue(result, 0, 2), "t", 1); -tuple << PQgetvalue(result, 0, 3) << " "; // credit -conf->creditExpire = TS2Int(PQgetvalue(result, 0, 4)); // creditExpire -conf->disabled = !strncmp(PQgetvalue(result, 0, 5), "t", 1); -conf->disabledDetailStat = !strncmp(PQgetvalue(result, 0, 6), "t", 1); -conf->email = PQgetvalue(result, 0, 7); // email -conf->group = PQgetvalue(result, 0, 8); // group -conf->note = PQgetvalue(result, 0, 9); // note -conf->passive = !strncmp(PQgetvalue(result, 0, 10), "t", 1); -conf->password = PQgetvalue(result, 0, 11); // password -conf->phone = PQgetvalue(result, 0, 12); // phone -conf->realName = PQgetvalue(result, 0, 13); // realName -conf->tariffName = PQgetvalue(result, 0, 14); // tariffName -conf->nextTariff = PQgetvalue(result, 0, 15); // nextTariff -conf->corp = PQgetvalue(result, 0, 16); // corp + { + std::stringstream tuple; + tuple << PQgetvalue(result, 0, 0) << " "; // uid + conf->address = PQgetvalue(result, 0, 1); // address + conf->alwaysOnline = !strncmp(PQgetvalue(result, 0, 2), "t", 1); + tuple << PQgetvalue(result, 0, 3) << " "; // credit + conf->creditExpire = TS2Int(PQgetvalue(result, 0, 4)); // creditExpire + conf->disabled = !strncmp(PQgetvalue(result, 0, 5), "t", 1); + conf->disabledDetailStat = !strncmp(PQgetvalue(result, 0, 6), "t", 1); + conf->email = PQgetvalue(result, 0, 7); // email + conf->group = PQgetvalue(result, 0, 8); // group + conf->note = PQgetvalue(result, 0, 9); // note + conf->passive = !strncmp(PQgetvalue(result, 0, 10), "t", 1); + conf->password = PQgetvalue(result, 0, 11); // password + conf->phone = PQgetvalue(result, 0, 12); // phone + conf->realName = PQgetvalue(result, 0, 13); // realName + conf->tariffName = PQgetvalue(result, 0, 14); // tariffName + conf->nextTariff = PQgetvalue(result, 0, 15); // nextTariff + conf->corp = PQgetvalue(result, 0, 16); // corp -PQclear(result); + PQclear(result); -if (conf->tariffName == "") - conf->tariffName = NO_TARIFF_NAME; -if (conf->corp == "") - conf->corp = NO_CORP_NAME; + if (conf->tariffName == "") + conf->tariffName = NO_TARIFF_NAME; + if (conf->corp == "") + conf->corp = NO_CORP_NAME; -tuple >> uid - >> conf->credit; + tuple >> uid + >> conf->credit; + } -query.str(""); -query << "SELECT name FROM tb_services " - "WHERE pk_service IN (SELECT fk_service " - "FROM tb_users_services " - "WHERE fk_user = " << uid << ")"; + { + std::ostringstream query; + query << "SELECT name FROM tb_services " + "WHERE pk_service IN (SELECT fk_service " + "FROM tb_users_services " + "WHERE fk_user = " << uid << ")"; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -876,12 +888,14 @@ for (int i = 0; i < tuples; ++i) PQclear(result); -query.str(""); -query << "SELECT num, data " - "FROM tb_users_data " - "WHERE fk_user = " << uid; + { + std::ostringstream query; + query << "SELECT num, data " + "FROM tb_users_data " + "WHERE fk_user = " << uid; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -916,12 +930,14 @@ for (int i = 0; i < tuples; ++i) PQclear(result); -query.str(""); -query << "SELECT host(ip), masklen(ip) " - "FROM tb_allowed_ip " - "WHERE fk_user = " << uid; + { + std::ostringstream query; + query << "SELECT host(ip), masklen(ip) " + "FROM tb_allowed_ip " + "WHERE fk_user = " << uid; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -970,13 +986,13 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteUserChgLog(const string & login, - const string & admLogin, +int POSTGRESQL_STORE::WriteUserChgLog(const std::string & login, + const std::string & admLogin, uint32_t admIP, - const string & paramName, - const string & oldValue, - const string & newValue, - const string & message = "") const + const std::string & paramName, + const std::string & oldValue, + const std::string & newValue, + const std::string & message = "") const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1056,7 +1072,7 @@ if (EscapeString(enew)) return -1; } -std::stringstream query; +std::ostringstream query; query << "SELECT sp_add_param_log_entry(" "'" << elogin << "', " "'" << eadminLogin << "', CAST('" @@ -1093,7 +1109,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteUserConnect(const string & login, uint32_t ip) const +int POSTGRESQL_STORE::WriteUserConnect(const std::string & login, uint32_t ip) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1128,7 +1144,7 @@ if (EscapeString(elogin)) return -1; } -std::stringstream query; +std::ostringstream query; if (version < 6) { query << "SELECT sp_add_session_log_entry(" @@ -1172,7 +1188,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteUserDisconnect(const string & login, +int POSTGRESQL_STORE::WriteUserDisconnect(const std::string & login, const DIR_TRAFF & up, const DIR_TRAFF & down, const DIR_TRAFF & sessionUp, @@ -1226,26 +1242,28 @@ if (EscapeString(ereason)) return -1; } -std::stringstream query; -if (version < 6) { - // Old database version - no freeMb logging support - query << "SELECT sp_add_session_log_entry(" - "'" << elogin << "', " - "CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP), " - "'d', CAST('0.0.0.0/0' AS INET), " - << cash << ")"; - } -else - { - query << "SELECT sp_add_session_log_entry(" - "'" << elogin << "', " - "CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP), " - "'d', CAST('0.0.0.0/0' AS INET), " - << cash << ", " << freeMb << ", '" << ereason << "')"; - } + std::ostringstream query; + if (version < 6) + { + // Old database version - no freeMb logging support + query << "SELECT sp_add_session_log_entry(" + "'" << elogin << "', " + "CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP), " + "'d', CAST('0.0.0.0/0' AS INET), " + << cash << ")"; + } + else + { + query << "SELECT sp_add_session_log_entry(" + "'" << elogin << "', " + "CAST('" << Int2TS(stgTime) << "' AS TIMESTAMP), " + "'d', CAST('0.0.0.0/0' AS INET), " + << cash << ", " << freeMb << ", '" << ereason << "')"; + } -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_TUPLES_OK) { @@ -1291,7 +1309,7 @@ PQclear(result); for (int i = 0; i < DIR_NUM; ++i) { - std::stringstream query; + std::ostringstream query; query << "INSERT INTO tb_sessions_data " "(fk_session_log, " "dir_num, " @@ -1334,9 +1352,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::WriteDetailedStat(const map & statTree, +int POSTGRESQL_STORE::WriteDetailedStat(const std::map & statTree, time_t lastStat, - const string & login) const + const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1371,12 +1389,12 @@ if (EscapeString(elogin)) return -1; } -map::const_iterator it; +std::map::const_iterator it; time_t currTime = time(NULL); for (it = statTree.begin(); it != statTree.end(); ++it) { - std::stringstream query; + std::ostringstream query; query << "INSERT INTO tb_detail_stats " "(till_time, from_time, fk_user, " "dir_num, ip, download, upload, cost) " @@ -1417,7 +1435,7 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const string & login) const +int POSTGRESQL_STORE::SaveMonthStat(const USER_STAT & stat, int month, int year, const std::string & login) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -1430,21 +1448,23 @@ int POSTGRESQL_STORE::SaveUserServices(uint32_t uid, { PGresult * result; -std::stringstream query; -query << "DELETE FROM tb_users_services WHERE fk_user = " << uid; + { + std::ostringstream query; + query << "DELETE FROM tb_users_services WHERE fk_user = " << uid; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + + if (PQresultStatus(result) != PGRES_COMMAND_OK) + { + strError = PQresultErrorMessage(result); + PQclear(result); + printfd(__FILE__, "POSTGRESQL_STORE::SaveUserServices(): '%s'\n", strError.c_str()); + return -1; + } -if (PQresultStatus(result) != PGRES_COMMAND_OK) - { - strError = PQresultErrorMessage(result); PQclear(result); - printfd(__FILE__, "POSTGRESQL_STORE::SaveUserServices(): '%s'\n", strError.c_str()); - return -1; } -PQclear(result); - std::vector::const_iterator it; for (it = services.begin(); it != services.end(); ++it) @@ -1457,7 +1477,7 @@ for (it = services.begin(); it != services.end(); ++it) return -1; } - std::stringstream query; + std::ostringstream query; query << "INSERT INTO tb_users_services " "(fk_user, fk_service) " "VALUES " @@ -1488,10 +1508,12 @@ int POSTGRESQL_STORE::SaveUserIPs(uint32_t uid, { PGresult * result; -std::stringstream query; -query << "DELETE FROM tb_allowed_ip WHERE fk_user = " << uid; + { + std::ostringstream query; + query << "DELETE FROM tb_allowed_ip WHERE fk_user = " << uid; -result = PQexec(connection, query.str().c_str()); + result = PQexec(connection, query.str().c_str()); + } if (PQresultStatus(result) != PGRES_COMMAND_OK) { @@ -1505,7 +1527,7 @@ PQclear(result); for (int i = 0; i < ips.Count(); ++i) { - std::stringstream query; + std::ostringstream query; query << "INSERT INTO tb_allowed_ip " "(fk_user, ip) " "VALUES " @@ -1545,7 +1567,7 @@ for (unsigned i = 0; i < data.size(); ++i) PGresult * result; - std::stringstream query; + std::ostringstream query; query << "SELECT sp_set_user_data(" << uid << ", " << "CAST(" << i << " AS SMALLINT), " diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp index c36df0cd..f5dec89f 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp @@ -34,6 +34,8 @@ #include "stg/common.h" #include "postgresql_store.h" +extern volatile time_t stgTime; + int POSTGRESQL_STORE::StartTransaction() const { PGresult * result = PQexec(connection, "BEGIN"); @@ -110,24 +112,23 @@ delete[] buf; return 0; } -std::string POSTGRESQL_STORE::Int2TS(uint32_t ts) const +std::string POSTGRESQL_STORE::Int2TS(time_t ts) const { char buf[32]; struct tm brokenTime; -time_t tt = ts; brokenTime.tm_wday = 0; brokenTime.tm_yday = 0; brokenTime.tm_isdst = 0; -gmtime_r(&tt, &brokenTime); +gmtime_r(&ts, &brokenTime); strftime(buf, 32, "%Y-%m-%d %H:%M:%S", &brokenTime); return buf; } -uint32_t POSTGRESQL_STORE::TS2Int(const std::string & ts) const +time_t POSTGRESQL_STORE::TS2Int(const std::string & ts) const { struct tm brokenTime; diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h index e09cccd2..4ffa6ecf 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_utils.h @@ -5,7 +5,7 @@ struct ToLower : public std::unary_function { -char operator() (char c) const { return std::tolower(c); } +char operator() (char c) const { return static_cast(std::tolower(c)); } }; #endif diff --git a/projects/stargazer/services_impl.cpp b/projects/stargazer/services_impl.cpp index 85b0f4e5..832bf7e9 100644 --- a/projects/stargazer/services_impl.cpp +++ b/projects/stargazer/services_impl.cpp @@ -48,7 +48,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->serviceChg) { - string s = admin->GetLogStr() + " Add service \'" + service.name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Add service \'" + service.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -79,14 +79,14 @@ WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } //----------------------------------------------------------------------------- -int SERVICES_IMPL::Del(const string & name, const ADMIN * admin) +int SERVICES_IMPL::Del(const std::string & name, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); const PRIV * priv = admin->GetPriv(); if (!priv->serviceChg) { - string s = admin->GetLogStr() + " Delete service \'" + name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Delete service \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -101,7 +101,7 @@ if (si == data.end()) return -1; } -map::iterator csi; +std::map::iterator csi; csi = searchDescriptors.begin(); while (csi != searchDescriptors.end()) { @@ -130,7 +130,7 @@ const PRIV * priv = admin->GetPriv(); if (!priv->serviceChg) { - string s = admin->GetLogStr() + " Change service \'" + service.name + "\'. Access denied."; + std::string s = admin->GetLogStr() + " Change service \'" + service.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -162,7 +162,7 @@ return 0; bool SERVICES_IMPL::Read() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -vector servicesList; +std::vector servicesList; if (store->GetServicesList(&servicesList) < 0) { WriteServLog(store->GetStrError().c_str()); @@ -184,7 +184,7 @@ for (size_t i = 0; i < servicesList.size(); i++) return false; } //----------------------------------------------------------------------------- -bool SERVICES_IMPL::Find(const string & name, SERVICE_CONF * service) +bool SERVICES_IMPL::Find(const std::string & name, SERVICE_CONF * service) { assert(service != NULL && "Pointer to service is not null"); @@ -203,7 +203,7 @@ if (si != data.end()) return true; } //----------------------------------------------------------------------------- -bool SERVICES_IMPL::Exists(const string & name) const +bool SERVICES_IMPL::Exists(const std::string & name) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (data.empty()) diff --git a/projects/stargazer/services_impl.h b/projects/stargazer/services_impl.h index 2bb9c879..31aa72b2 100644 --- a/projects/stargazer/services_impl.h +++ b/projects/stargazer/services_impl.h @@ -58,8 +58,8 @@ private: SERVICES_IMPL(const SERVICES_IMPL & rvalue); SERVICES_IMPL & operator=(const SERVICES_IMPL & rvalue); - typedef list::iterator srv_iter; - typedef list::const_iterator const_srv_iter; + typedef std::list::iterator srv_iter; + typedef std::list::const_iterator const_srv_iter; bool Read(); diff --git a/projects/stargazer/settings_impl.h b/projects/stargazer/settings_impl.h index 739bbcc9..4a048333 100644 --- a/projects/stargazer/settings_impl.h +++ b/projects/stargazer/settings_impl.h @@ -85,7 +85,7 @@ public: bool GetFreeMbAllowInet() const { return freeMbAllowInet; } bool GetDayFeeIsLastDay() const { return dayFeeIsLastDay; } bool GetWriteFreeMbTraffCost() const - { return writeFreeMbTraffCost; }; + { return writeFreeMbTraffCost; } bool GetShowFeeInCash() const { return showFeeInCash; } const std::string & GetMonitorDir() const { return monitorDir; } bool GetMonitoring() const { return monitoring; } diff --git a/projects/stargazer/stg_timer.cpp b/projects/stargazer/stg_timer.cpp index 235c669e..81128c7a 100644 --- a/projects/stargazer/stg_timer.cpp +++ b/projects/stargazer/stg_timer.cpp @@ -6,6 +6,10 @@ #include "stg/common.h" +#include "stg_timer.h" + +void * StgTimer(void *); + static int nonstop; static pthread_t thrStgTimer; static bool isTimerRunning = false; @@ -88,7 +92,7 @@ static int a = 0; isTimerRunning = false; if (a == 0) - if (pthread_create(&thrStgTimer, NULL, StgTimer, NULL)) + if (pthread_create(&thrStgTimer, NULL, &StgTimer, NULL)) { isTimerRunning = false; return -1; @@ -113,10 +117,10 @@ return isTimerRunning; int stgUsleep(unsigned long t) { #ifdef STG_TIMER_DEBUG -struct timespec ts = {(t / TIME_SPEED) / 1000000, ((t / TIME_SPEED) % 1000000) * 1000}; +struct timespec ts = {static_cast((t / TIME_SPEED) / 1000000), static_cast(((t / TIME_SPEED) % 1000000) * 1000)}; return nanosleep(&ts, NULL); #else -struct timespec ts = {t / 1000000, (t % 1000000) * 1000}; +struct timespec ts = {static_cast(t / 1000000), static_cast((t % 1000000) * 1000)}; return nanosleep(&ts, NULL); #endif } diff --git a/projects/stargazer/stg_timer.h b/projects/stargazer/stg_timer.h index c57008e5..75553b3e 100644 --- a/projects/stargazer/stg_timer.h +++ b/projects/stargazer/stg_timer.h @@ -9,7 +9,7 @@ #include -extern volatile const time_t stgTime; +extern volatile time_t stgTime; int RunStgTimer(); void StopStgTimer(); void WaitTimer(); diff --git a/projects/stargazer/tariff_impl.cpp b/projects/stargazer/tariff_impl.cpp index bf272f31..c6785cea 100644 --- a/projects/stargazer/tariff_impl.cpp +++ b/projects/stargazer/tariff_impl.cpp @@ -119,7 +119,7 @@ else } } //----------------------------------------------------------------------------- -double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int mb, time_t t) const +double TARIFF_IMPL::GetPriceWithoutFreeMb(int dir, int64_t mb, time_t t) const { int interval = Interval(dir, t); @@ -143,45 +143,5 @@ else if (!sp && th) return tariffData.dirPrice[dir].priceNightA; else return tariffData.dirPrice[dir].priceDayA; - -/*if (tariffData.dirPrice[dir].noDiscount && tariffData.dirPrice[dir].singlePrice) - { - return tariffData.dirPrice[dir].priceDayA; - } -else - { - if (tariffData.dirPrice[dir].noDiscount) - { - // Without threshold - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceNightA; - } - - if (tariffData.dirPrice[dir].singlePrice) - { - // Without day/night - if (mb < tariffData.dirPrice[dir].threshold) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceDayB; - } - - if (mb < tariffData.dirPrice[dir].threshold) - { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayA; - else - return tariffData.dirPrice[dir].priceNightA; - } - else - { - if (interval == TARIFF_DAY) - return tariffData.dirPrice[dir].priceDayB; - else - return tariffData.dirPrice[dir].priceNightB; - } - }*/ } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/tariff_impl.h b/projects/stargazer/tariff_impl.h index f33c08af..122dabd0 100644 --- a/projects/stargazer/tariff_impl.h +++ b/projects/stargazer/tariff_impl.h @@ -48,20 +48,20 @@ public: TARIFF_IMPL() : TARIFF(), tariffData() - {}; + {} TARIFF_IMPL(const std::string & name) : TARIFF(), tariffData(name) - {}; + {} TARIFF_IMPL(const TARIFF_DATA & td) : TARIFF(), tariffData(td) - {}; + {} TARIFF_IMPL(const TARIFF_IMPL & t) : TARIFF(), tariffData(t.tariffData) - {}; - virtual ~TARIFF_IMPL() {}; + {} + virtual ~TARIFF_IMPL() {} double GetPriceWithTraffType(uint64_t up, uint64_t down, @@ -90,7 +90,7 @@ public: private: TARIFF_DATA tariffData; - double GetPriceWithoutFreeMb(int dir, int mb, time_t t) const; + double GetPriceWithoutFreeMb(int dir, int64_t mb, time_t t) const; int Interval(int dir, time_t t) const; }; diff --git a/projects/stargazer/tariffs_impl.cpp b/projects/stargazer/tariffs_impl.cpp index ab3d970f..dbd3d2e3 100644 --- a/projects/stargazer/tariffs_impl.cpp +++ b/projects/stargazer/tariffs_impl.cpp @@ -72,9 +72,9 @@ if (store->GetTariffsList(&tariffsList)) WriteServLog("%s", store->GetStrError().c_str()); } -int tariffsNum = tariffsList.size(); +Tariffs::size_type tariffsNum = tariffsList.size(); -for (int i = 0; i < tariffsNum; i++) +for (Tariffs::size_type i = 0; i < tariffsNum; i++) { TARIFF_DATA td; if (store->RestoreTariff(&td, tariffsList[i])) @@ -258,7 +258,7 @@ void TARIFFS_IMPL::GetTariffsData(std::list * tdl) assert(tdl != NULL && "Tariffs data list is not null"); STG_LOCKER lock(&mutex, __FILE__, __LINE__); -std::list::const_iterator it = tariffs.begin(); +Tariffs::const_iterator it = tariffs.begin(); for (; it != tariffs.end(); ++it) { tdl->push_back(it->GetTariffData()); diff --git a/projects/stargazer/tariffs_impl.h b/projects/stargazer/tariffs_impl.h index caeb811d..37c76fc4 100644 --- a/projects/stargazer/tariffs_impl.h +++ b/projects/stargazer/tariffs_impl.h @@ -45,15 +45,17 @@ class ADMIN; class TARIFFS_IMPL : public TARIFFS { public: + typedef std::list Tariffs; + TARIFFS_IMPL(STORE * store); virtual ~TARIFFS_IMPL(); - int ReadTariffs (); + int ReadTariffs (); const TARIFF * FindByName(const std::string & name) const; - const TARIFF * GetNoTariff() const { return &noTariff; }; - size_t Count() const; - int Del(const std::string & name, const ADMIN * admin); - int Add(const std::string & name, const ADMIN * admin); - int Chg(const TARIFF_DATA & td, const ADMIN * admin); + const TARIFF * GetNoTariff() const { return &noTariff; } + size_t Count() const; + int Del(const std::string & name, const ADMIN * admin); + int Add(const std::string & name, const ADMIN * admin); + int Chg(const TARIFF_DATA & td, const ADMIN * admin); void AddNotifierAdd(NOTIFIER_BASE * notifier); void DelNotifierAdd(NOTIFIER_BASE * notifier); @@ -61,7 +63,7 @@ public: void AddNotifierDel(NOTIFIER_BASE * notifier); void DelNotifierDel(NOTIFIER_BASE * notifier); - void GetTariffsData(std::list * tdl); + void GetTariffsData(std::list * tdl); const std::string & GetStrError() const { return strError; } @@ -69,7 +71,7 @@ private: TARIFFS_IMPL(const TARIFFS_IMPL & rvalue); TARIFFS_IMPL & operator=(const TARIFFS_IMPL & rvalue); - std::list tariffs; + Tariffs tariffs; STORE * store; STG_LOGGER & WriteServLog; mutable pthread_mutex_t mutex; diff --git a/projects/stargazer/traffcounter_impl.cpp b/projects/stargazer/traffcounter_impl.cpp index c2088e0f..6f16be9a 100644 --- a/projects/stargazer/traffcounter_impl.cpp +++ b/projects/stargazer/traffcounter_impl.cpp @@ -202,11 +202,11 @@ void TRAFFCOUNTER_IMPL::Process(const RAW_PACKET & rawPacket) if (!running) return; -static time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC; +time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC; if (monitoring && (touchTime + MONITOR_TIME_DELAY_SEC <= stgTime)) { - static std::string monFile = monitorDir + "/traffcounter_p"; + std::string monFile = monitorDir + "/traffcounter_p"; printfd(__FILE__, "Monitor=%d file TRAFFCOUNTER %s\n", monitoring, monFile.c_str()); touchTime = stgTime; TouchFile(monFile.c_str()); @@ -292,12 +292,12 @@ void TRAFFCOUNTER_IMPL::FlushAndRemove() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -int oldPacketsSize = packets.size(); -int oldIp2packetsSize = ip2packets.size(); +Packets::size_type oldPacketsSize = packets.size(); +Index::size_type oldIp2packetsSize = ip2packets.size(); pp_iter pi; pi = packets.begin(); -std::map newPackets; +Packets newPackets; ip2packets.erase(ip2packets.begin(), ip2packets.end()); while (pi != packets.end()) { @@ -673,13 +673,13 @@ while (fgets(str, 1023, f)) rul.proto = 0xff; rul.dir = 0xff; - for (size_t i = 0; i < PROTOMAX; i++) + for (uint8_t i = 0; i < PROTOMAX; i++) { if (strcasecmp(tp, protoName[i]) == 0) rul.proto = i; } - for (size_t i = 0; i < DIR_NUM + 1; i++) + for (uint32_t i = 0; i < DIR_NUM + 1; i++) { if (td == dirName[i]) rul.dir = i; @@ -747,9 +747,9 @@ bool TRAFFCOUNTER_IMPL::ParseAddress(const char * ta, RULE * rule) const { char addr[50], mask[20], port1[20], port2[20], ports[40]; -int len = strlen(ta); +size_t len = strlen(ta); char n = 0; -int i, p; +size_t i, p; memset(addr, 0, sizeof(addr)); for (i = 0; i < len; i++) { @@ -829,15 +829,15 @@ uint16_t prt1, prt2, msk; struct in_addr ipaddr; char *res; -msk = strtol(mask, &res, 10); +msk = static_cast(strtol(mask, &res, 10)); if (*res != 0) return true; -prt1 = strtol(port1, &res, 10); +prt1 = static_cast(strtol(port1, &res, 10)); if (*res != 0) return true; -prt2 = strtol(port2, &res, 10); +prt2 = static_cast(strtol(port2, &res, 10)); if (*res != 0) return true; @@ -902,9 +902,9 @@ switch (rule.proto) printf("dir=%u \n", static_cast(rule.dir)); } //----------------------------------------------------------------------------- -void TRAFFCOUNTER_IMPL::SetMonitorDir(const std::string & monitorDir) +void TRAFFCOUNTER_IMPL::SetMonitorDir(const std::string & dir) { -TRAFFCOUNTER_IMPL::monitorDir = monitorDir; -monitoring = (monitorDir != ""); +monitorDir = dir; +monitoring = !monitorDir.empty(); } //----------------------------------------------------------------------------- diff --git a/projects/stargazer/traffcounter_impl.h b/projects/stargazer/traffcounter_impl.h index 2a9fca5a..f4049433 100644 --- a/projects/stargazer/traffcounter_impl.h +++ b/projects/stargazer/traffcounter_impl.h @@ -221,15 +221,18 @@ private: void UnSetUserNotifiers(USER_IMPL * user); typedef std::list::iterator rule_iter; - typedef std::map::iterator pp_iter; - typedef std::multimap::iterator ip2p_iter; - typedef std::multimap::const_iterator ip2p_citer; std::list rules; - std::map packets; // Packets tree + typedef std::map Packets; + typedef Packets::iterator pp_iter; + typedef std::multimap Index; + typedef Index::iterator ip2p_iter; + typedef Index::const_iterator ip2p_citer; - std::multimap ip2packets; // IP-to-Packet index + Packets packets; // Packets tree + + Index ip2packets; // IP-to-Packet index std::string dirName[DIR_NUM + 1]; diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 80568561..ac8399ca 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -336,7 +336,7 @@ property.cash.DelBeforeNotifier(&cashNotifier); pthread_mutex_destroy(&mutex); } //----------------------------------------------------------------------------- -void USER_IMPL::SetLogin(string const & l) +void USER_IMPL::SetLogin(const std::string & l) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); assert(login.empty() && "Login is already set"); @@ -576,7 +576,7 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (!fakeConnect) { - string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect"; + std::string scriptOnConnect = settings->GetScriptsDir() + "/OnConnect"; if (access(scriptOnConnect.c_str(), X_OK) == 0) { @@ -587,7 +587,7 @@ if (!fakeConnect) dirsStr[i] = enabledDirs[i] ? '1' : '0'; } - string scriptOnConnectParams; + std::string scriptOnConnectParams; strprintf(&scriptOnConnectParams, "%s \"%s\" \"%s\" \"%f\" \"%d\" \"%s\"", scriptOnConnect.c_str(), @@ -633,7 +633,7 @@ if (!lastIPForDisconnect) if (!fakeDisconnect) { - string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; + std::string scriptOnDisonnect = settings->GetScriptsDir() + "/OnDisconnect"; if (access(scriptOnDisonnect.c_str(), X_OK) == 0) { @@ -644,7 +644,7 @@ if (!fakeDisconnect) dirsStr[i] = enabledDirs[i] ? '1' : '0'; } - string scriptOnDisonnectParams; + std::string scriptOnDisonnectParams; strprintf(&scriptOnDisonnectParams, "%s \"%s\" \"%s\" \"%f\" \"%d\" \"%s\"", scriptOnDisonnect.c_str(), @@ -683,37 +683,37 @@ void USER_IMPL::PrintUser() const { //return; STG_LOCKER lock(&mutex, __FILE__, __LINE__); -cout << "============================================================" << endl; -cout << "id=" << id << endl; -cout << "login=" << login << endl; -cout << "password=" << password << endl; -cout << "passive=" << passive << endl; -cout << "disabled=" << disabled << endl; -cout << "disabledDetailStat=" << disabledDetailStat << endl; -cout << "alwaysOnline=" << alwaysOnline << endl; -cout << "tariffName=" << tariffName << endl; -cout << "address=" << address << endl; -cout << "phone=" << phone << endl; -cout << "email=" << email << endl; -cout << "note=" << note << endl; -cout << "realName=" <GetShowFeeInCash() || tariff == NULL) return (cash - tariff->GetFee() >= -credit); } //----------------------------------------------------------------------------- -string USER_IMPL::GetEnabledDirs() +std::string USER_IMPL::GetEnabledDirs() { //STG_LOCKER lock(&mutex, __FILE__, __LINE__); -string dirs = ""; +std::string dirs = ""; for(int i = 0; i < DIR_NUM; i++) dirs += enabledDirs[i] ? "1" : "0"; return dirs; @@ -895,13 +895,13 @@ IP_DIR_PAIR idp(ip, dir, port); IP_DIR_PAIR idp(ip, dir); #endif -map::iterator lb; +std::map::iterator lb; lb = traffStat.lower_bound(idp); if (lb == traffStat.end() || lb->first != idp) { traffStat.insert(lb, - pair(idp, - STAT_NODE(len, 0, cost))); + std::make_pair(idp, + STAT_NODE(len, 0, cost))); } else { @@ -986,13 +986,13 @@ IP_DIR_PAIR idp(ip, dir, port); IP_DIR_PAIR idp(ip, dir); #endif -map::iterator lb; +std::map::iterator lb; lb = traffStat.lower_bound(idp); if (lb == traffStat.end() || lb->first != idp) { traffStat.insert(lb, - pair(idp, - STAT_NODE(0, len, cost))); + std::make_pair(idp, + STAT_NODE(0, len, cost))); } else { @@ -1053,11 +1053,11 @@ void USER_IMPL::OnAdd() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd"; +std::string scriptOnAdd = settings->GetScriptsDir() + "/OnUserAdd"; if (access(scriptOnAdd.c_str(), X_OK) == 0) { - string scriptOnAddParams; + std::string scriptOnAddParams; strprintf(&scriptOnAddParams, "%s \"%s\"", scriptOnAdd.c_str(), @@ -1075,11 +1075,11 @@ void USER_IMPL::OnDelete() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel"; +std::string scriptOnDel = settings->GetScriptsDir() + "/OnUserDel"; if (access(scriptOnDel.c_str(), X_OK) == 0) { - string scriptOnDelParams; + std::string scriptOnDelParams; strprintf(&scriptOnDelParams, "%s \"%s\"", scriptOnDel.c_str(), @@ -1160,12 +1160,12 @@ if (tms.tm_year % 4 == 0 && tms.tm_mon == 1) secMonth += 24 * 3600; } -int dt = secMonth - passiveTime; +time_t dt = secMonth - passiveTime; if (dt < 0) dt = 0; -return double(dt) / (secMonth); +return static_cast(dt) / secMonth; } //----------------------------------------------------------------------------- void USER_IMPL::SetPassiveTimeAsNewUser() @@ -1363,9 +1363,9 @@ else msg->header.repeat--; #ifndef DEBUG //TODO: gcc v. 4.x generate ICE on x86_64 - msg->header.lastSendTime = time(NULL); + msg->header.lastSendTime = static_cast(time(NULL)); #else - msg->header.lastSendTime = stgTime; + msg->header.lastSendTime = static_cast(stgTime); #endif if (store->AddMessage(msg, login)) { @@ -1384,7 +1384,7 @@ int USER_IMPL::SendMessage(STG_MSG & msg) const { // No lock `cause we are already locked from caller int ret = -1; -set::iterator it(authorizedBy.begin()); +std::set::iterator it(authorizedBy.begin()); while (it != authorizedBy.end()) { if (!(*it++)->SendMessage(msg, currIP)) @@ -1394,9 +1394,9 @@ if (!ret) { #ifndef DEBUG //TODO: gcc v. 4.x generate ICE on x86_64 - msg.header.lastSendTime = time(NULL); + msg.header.lastSendTime = static_cast(time(NULL)); #else - msg.header.lastSendTime = stgTime; + msg.header.lastSendTime = static_cast(stgTime); #endif msg.header.repeat--; } @@ -1482,7 +1482,7 @@ else if (!oldValue && newValue && user->IsInetable()) } //----------------------------------------------------------------------------- -void CHG_TARIFF_NOTIFIER::Notify(const string &, const string & newTariff) +void CHG_TARIFF_NOTIFIER::Notify(const std::string &, const std::string & newTariff) { if (user->settings->GetReconnectOnTariffChange() && user->connected) user->Disconnect(false, "Change tariff"); diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index 2fc563df..5e8f49db 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -182,7 +182,7 @@ public: bool GetConnected() const { return connected; } time_t GetConnectedModificationTime() const { return connected.ModificationTime(); } - int GetAuthorized() const { return authorizedBy.size(); } + int GetAuthorized() const { return static_cast(authorizedBy.size()); } int Authorize(uint32_t ip, uint32_t enabledDirs, const AUTH * auth); void Unauthorize(const AUTH * auth); bool IsAuthorizedBy(const AUTH * auth) const; @@ -197,8 +197,8 @@ public: const std::string & GetStrError() const { return errorStr; } - USER_PROPERTIES & GetProperty() { return property; }; - const USER_PROPERTIES & GetProperty() const { return property; }; + USER_PROPERTIES & GetProperty() { return property; } + const USER_PROPERTIES & GetProperty() const { return property; } void SetDeleted() { deleted = true; } bool GetDeleted() const { return deleted; } diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index fc2b8d2f..17d1e4f7 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -46,9 +46,7 @@ #include "users_impl.h" #include "stg_timer.h" -using namespace std; - -extern const volatile time_t stgTime; +extern volatile time_t stgTime; //#define USERS_DEBUG 1 @@ -88,9 +86,9 @@ USERS_IMPL::~USERS_IMPL() pthread_mutex_destroy(&mutex); } //----------------------------------------------------------------------------- -int USERS_IMPL::FindByNameNonLock(const string & login, user_iter * user) +int USERS_IMPL::FindByNameNonLock(const std::string & login, user_iter * user) { -map::iterator iter; +std::map::iterator iter; iter = loginIndex.find(login); if (iter != loginIndex.end()) { @@ -101,7 +99,7 @@ if (iter != loginIndex.end()) return -1; } //----------------------------------------------------------------------------- -int USERS_IMPL::FindByName(const string & login, USER_PTR * user) +int USERS_IMPL::FindByName(const std::string & login, USER_PTR * user) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); user_iter u; @@ -112,10 +110,10 @@ if (res) return 0; } //----------------------------------------------------------------------------- -bool USERS_IMPL::TariffInUse(const string & tariffName) const +bool USERS_IMPL::TariffInUse(const std::string & tariffName) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -list::const_iterator iter; +std::list::const_iterator iter; iter = users.begin(); while (iter != users.end()) { @@ -126,7 +124,7 @@ while (iter != users.end()) return false; } //----------------------------------------------------------------------------- -int USERS_IMPL::Add(const string & login, const ADMIN * admin) +int USERS_IMPL::Add(const std::string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); const PRIV * priv = admin->GetPriv(); @@ -184,7 +182,7 @@ AddUserIntoIndexes(users.begin()); { // Fire all "on add" notifiers - set *>::iterator ni = onAddNotifiers.begin(); + std::set *>::iterator ni = onAddNotifiers.begin(); while (ni != onAddNotifiers.end()) { (*ni)->Notify(&users.front()); @@ -194,7 +192,7 @@ AddUserIntoIndexes(users.begin()); { // Fire all "on add" implementation notifiers - set *>::iterator ni = onAddNotifiersImpl.begin(); + std::set *>::iterator ni = onAddNotifiersImpl.begin(); while (ni != onAddNotifiersImpl.end()) { (*ni)->Notify(&users.front()); @@ -205,7 +203,7 @@ AddUserIntoIndexes(users.begin()); return 0; } //----------------------------------------------------------------------------- -void USERS_IMPL::Del(const string & login, const ADMIN * admin) +void USERS_IMPL::Del(const std::string & login, const ADMIN * admin) { const PRIV * priv = admin->GetPriv(); user_iter u; @@ -233,7 +231,7 @@ if (!priv->userAddDel) } { - set *>::iterator ni = onDelNotifiers.begin(); + std::set *>::iterator ni = onDelNotifiers.begin(); while (ni != onDelNotifiers.end()) { (*ni)->Notify(&(*u)); @@ -242,7 +240,7 @@ if (!priv->userAddDel) } { - set *>::iterator ni = onDelNotifiersImpl.begin(); + std::set *>::iterator ni = onDelNotifiersImpl.begin(); while (ni != onDelNotifiersImpl.end()) { (*ni)->Notify(&(*u)); @@ -322,7 +320,7 @@ return true; //----------------------------------------------------------------------------- int USERS_IMPL::ReadUsers() { -vector usersList; +std::vector usersList; usersList.clear(); if (store->GetUsersList(&usersList) < 0) { @@ -371,7 +369,7 @@ int day = t.tm_mday; printfd(__FILE__,"Day = %d Min = %d\n", day, min); time_t touchTime = stgTime - MONITOR_TIME_DELAY_SEC; -string monFile = us->settings->GetMonitorDir() + "/users_r"; +std::string monFile = us->settings->GetMonitorDir() + "/users_r"; printfd(__FILE__, "Monitor=%d file USERS %s\n", us->settings->GetMonitoring(), monFile.c_str()); us->isRunning = true; @@ -380,7 +378,7 @@ while (us->nonstop) //printfd(__FILE__,"New Minute. old = %02d current = %02d\n", min, t->tm_min); //printfd(__FILE__,"New Day. old = %2d current = %2d\n", day, t->tm_mday); - for_each(us->users.begin(), us->users.end(), mem_fun_ref(&USER_IMPL::Run)); + for_each(us->users.begin(), us->users.end(), std::mem_fun_ref(&USER_IMPL::Run)); tt = stgTime; localtime_r(&tt, &t); @@ -419,7 +417,7 @@ while (ui != us->users.end()) ++ui; } -list::iterator iter; +std::list::iterator iter; iter = us->usersToDelete.begin(); while (iter != us->usersToDelete.end()) { @@ -439,7 +437,7 @@ void USERS_IMPL::NewMinute(const struct tm & t) if (t.tm_hour == 23 && t.tm_min == 59) { printfd(__FILE__,"MidnightResetSessionStat\n"); - for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::MidnightResetSessionStat)); + for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::MidnightResetSessionStat)); } if (TimeToWriteDetailStat(t)) @@ -448,14 +446,14 @@ if (TimeToWriteDetailStat(t)) int usersCnt = 0; // ðÉÛÅÍ ÀÚÅÒÏ× ÞÁÓÔÑÍÉ. ÷ ÐÅÒÅÒÙ×ÁÈ ×ÙÚÙ×ÁÅÍ USER::Run - list::iterator usr = users.begin(); + std::list::iterator usr = users.begin(); while (usr != users.end()) { usersCnt++; usr->WriteDetailStat(); ++usr; if (usersCnt % 10 == 0) - for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::Run)); + for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::Run)); } } @@ -486,14 +484,14 @@ if (!settings->GetDayFeeIsLastDay()) if (settings->GetSpreadFee()) { printfd(__FILE__, "Spread DayFee\n"); - for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessDayFeeSpread)); + for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::ProcessDayFeeSpread)); } else { if (t.tm_mday == dayFee) { printfd(__FILE__, "DayFee\n"); - for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessDayFee)); + for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::ProcessDayFee)); } } @@ -512,7 +510,7 @@ if (dayResetTraff == 0) if (t1.tm_mday == dayResetTraff) { printfd(__FILE__, "ResetTraff\n"); - for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::ProcessNewMonth)); + for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::ProcessNewMonth)); //for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::SetPrepaidTraff)); } } @@ -571,15 +569,15 @@ if (isRunning) } printfd(__FILE__, "Before USERS::Run()\n"); -for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::Run)); +for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::Run)); // 'cause bind2st accepts only constant first param -for (list::iterator it = users.begin(); +for (std::list::iterator it = users.begin(); it != users.end(); ++it) it->WriteDetailStat(true); -for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::WriteStat)); +for_each(users.begin(), users.end(), std::mem_fun_ref(&USER_IMPL::WriteStat)); //for_each(users.begin(), users.end(), mem_fun_ref(&USER_IMPL::WriteConf)); printfd(__FILE__, "USERS::Stop()\n"); @@ -592,7 +590,7 @@ STG_LOCKER lock(&mutex, __FILE__, __LINE__); printfd(__FILE__, "RealDelUser() users to del: %d\n", usersToDelete.size()); -list::iterator iter; +std::list::iterator iter; iter = usersToDelete.begin(); while (iter != usersToDelete.end()) { @@ -625,7 +623,7 @@ if (!ip) STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const map::iterator it( +const std::map::iterator it( ipIndex.lower_bound(ip) ); @@ -641,7 +639,7 @@ assert(ip && "User has non-null ip"); STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const map::iterator it( +const std::map::iterator it( ipIndex.find(ip) ); @@ -653,7 +651,7 @@ ipIndex.erase(it); //----------------------------------------------------------------------------- bool USERS_IMPL::FindByIPIdx(uint32_t ip, user_iter & iter) const { -map::const_iterator it(ipIndex.find(ip)); +std::map::const_iterator it(ipIndex.find(ip)); if (it == ipIndex.end()) return false; iter = it->second; @@ -692,7 +690,7 @@ bool USERS_IMPL::IsIPInIndex(uint32_t ip) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -map::const_iterator it(ipIndex.find(ip)); +std::map::const_iterator it(ipIndex.find(ip)); return it != ipIndex.end(); } diff --git a/stglibs/common.lib/common.cpp b/stglibs/common.lib/common.cpp index 2ea32c2b..787b813d 100644 --- a/stglibs/common.lib/common.cpp +++ b/stglibs/common.lib/common.cpp @@ -60,7 +60,78 @@ # define INET_ADDRSTRLEN 16 #endif -using namespace std; +namespace +{ +//--------------------------------------------------------------------------- +unsigned char koi2win[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xB8, 0xBA, 0xA5, 0xB3, 0xBF, + 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xB4, 0xAE, 0xAF, + 0xB0, 0xB1, 0xB2, 0xA8, 0xAA, 0xB5, 0xB2, 0xAF, + 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xA5, 0xBE, 0xBF, + 0xFE, 0xE0, 0xE1, 0xF6, 0xE4, 0xE5, 0xF4, 0xE3, + 0xF5, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, + 0xEF, 0xFF, 0xF0, 0xF1, 0xF2, 0xF3, 0xE6, 0xE2, + 0xFC, 0xFB, 0xE7, 0xF8, 0xFD, 0xF9, 0xF7, 0xFA, + 0xDE, 0xC0, 0xC1, 0xD6, 0xC4, 0xC5, 0xD4, 0xC3, + 0xD5, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, + 0xCF, 0xDF, 0xD0, 0xD1, 0xD2, 0xD3, 0xC6, 0xC2, + 0xDC, 0xDB, 0xC7, 0xD8, 0xDD, 0xD9, 0xD7, 0xDA}; + + +unsigned char win2koi[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, + 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xBD, 0xA6, 0xA7, + 0xB3, 0xA9, 0xB4, 0xAB, 0xAC, 0xAD, 0xAE, 0xB7, + 0xB0, 0xB1, 0xB6, 0xA6, 0xAD, 0xB5, 0xB6, 0xB7, + 0xA3, 0xB9, 0xA4, 0xBB, 0xBC, 0xBD, 0xBE, 0xA7, + 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA, + 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, + 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE, + 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1, + 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA, + 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, + 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE, + 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1}; +} #ifdef WIN32 //----------------------------------------------------------------------------- @@ -136,7 +207,7 @@ printf("%s", buff); return 0; } //----------------------------------------------------------------------------- -int strprintf(string * str, const char * fmt, ...) +int strprintf(std::string * str, const char * fmt, ...) { char buff[1024]; @@ -150,11 +221,13 @@ buff[1023] = 0; return n; } //----------------------------------------------------------------------------- -const char *IntToKMG(long long a, int stat) +const char *IntToKMG(int64_t a, int stat) { -static int64_t M = 1024*1024; -static int64_t G = 1024*1024*1024; +static const double K = 1024; +static const double M = 1024 * 1024; +static const double G = 1024 * 1024 * 1024; static char str[30]; +double value = a; switch (stat) { @@ -166,108 +239,39 @@ switch (stat) #endif break; case ST_KB: - sprintf(str, "%.2f kb", double(a)/1024.0); + sprintf(str, "%.2f kb", value / K); break; case ST_MB: - sprintf(str, "%.2f Mb", double(a)/(1024.0*1024.0)); + sprintf(str, "%.2f Mb", value / M); break; default: if (a > G) { - sprintf(str, "%.2f Gb", double(a)/double(G)); + sprintf(str, "%.2f Gb", value / G); return &str[0]; } if (a < -G) { - sprintf(str, "%.2f Gb", double(a)/double(G)); + sprintf(str, "%.2f Gb", value / G); return &str[0]; } if (a > M) { - sprintf(str, "%.2f Mb", double(a)/double(M)); + sprintf(str, "%.2f Mb", value / M); return &str[0]; } if (a < -M) { - sprintf(str, "%.2f Mb", double(a)/double(M)); + sprintf(str, "%.2f Mb", value / M); return &str[0]; } - sprintf(str, "%.2f kb", double(a)/1024.0); + sprintf(str, "%.2f kb", value / K); break; } return str; } //--------------------------------------------------------------------------- -unsigned char koi2win[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xB8, 0xBA, 0xA5, 0xB3, 0xBF, - 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xB4, 0xAE, 0xAF, - 0xB0, 0xB1, 0xB2, 0xA8, 0xAA, 0xB5, 0xB2, 0xAF, - 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xA5, 0xBE, 0xBF, - 0xFE, 0xE0, 0xE1, 0xF6, 0xE4, 0xE5, 0xF4, 0xE3, - 0xF5, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, - 0xEF, 0xFF, 0xF0, 0xF1, 0xF2, 0xF3, 0xE6, 0xE2, - 0xFC, 0xFB, 0xE7, 0xF8, 0xFD, 0xF9, 0xF7, 0xFA, - 0xDE, 0xC0, 0xC1, 0xD6, 0xC4, 0xC5, 0xD4, 0xC3, - 0xD5, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, - 0xCF, 0xDF, 0xD0, 0xD1, 0xD2, 0xD3, 0xC6, 0xC2, - 0xDC, 0xDB, 0xC7, 0xD8, 0xDD, 0xD9, 0xD7, 0xDA}; - - -unsigned char win2koi[] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, - 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, - 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, - 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, - 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, - 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, - 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, - 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, - 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, - 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, - 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xBD, 0xA6, 0xA7, - 0xB3, 0xA9, 0xB4, 0xAB, 0xAC, 0xAD, 0xAE, 0xB7, - 0xB0, 0xB1, 0xB6, 0xA6, 0xAD, 0xB5, 0xB6, 0xB7, - 0xA3, 0xB9, 0xA4, 0xBB, 0xBC, 0xBD, 0xBE, 0xA7, - 0xE1, 0xE2, 0xF7, 0xE7, 0xE4, 0xE5, 0xF6, 0xFA, - 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, - 0xF2, 0xF3, 0xF4, 0xF5, 0xE6, 0xE8, 0xE3, 0xFE, - 0xFB, 0xFD, 0xFF, 0xF9, 0xF8, 0xFC, 0xE0, 0xF1, - 0xC1, 0xC2, 0xD7, 0xC7, 0xC4, 0xC5, 0xD6, 0xDA, - 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, - 0xD2, 0xD3, 0xD4, 0xD5, 0xC6, 0xC8, 0xC3, 0xDE, - 0xDB, 0xDD, 0xDF, 0xD9, 0xD8, 0xDC, 0xC0, 0xD1}; -//--------------------------------------------------------------------------- void KOIToWin(const char * s1, char * s2, int l) { unsigned char t; @@ -294,7 +298,7 @@ for (int j = 0; j < l; j++) } } //--------------------------------------------------------------------------- -void KOIToWin(const string & s1, string * s2) +void KOIToWin(const std::string & s1, std::string * s2) { s2->erase(s2->begin(), s2->end()); unsigned char t; @@ -306,7 +310,7 @@ for (int j = 0; j < (int)s1.length(); j++) } } //--------------------------------------------------------------------------- -void WinToKOI(const string & s1, string * s2) +void WinToKOI(const std::string & s1, std::string * s2) { s2->erase(s2->begin(), s2->end()); unsigned char t; @@ -318,7 +322,7 @@ for (int j = 0; j < (int)s1.length(); j++) } } //--------------------------------------------------------------------------- -void Encode12str(string & dst, const string & src) +void Encode12str(std::string & dst, const std::string & src) { dst.erase(dst.begin(), dst.end()); for (size_t i = 0; i < src.length(); i++) @@ -339,7 +343,7 @@ for (size_t i = 0; i < src.length() / 2; i++) c1 -= 'a'; c2 -= 'a'; - dst.push_back(c1 + (c2 << 4)); + dst.push_back(static_cast(c1 + (c2 << 4))); } } //--------------------------------------------------------------------------- @@ -372,7 +376,7 @@ for (size_t i = 0; ; i++) c1 -= 'a'; c2 -= 'a'; - dst[i] = c1 + (c2 << 4); + dst[i] = static_cast(c1 + (c2 << 4)); } dst[strlen(src) / 2] = 0; } @@ -610,7 +614,7 @@ if (msk == 0) return 0; return htonl(0xFFffFFff << (32 - msk)); } //--------------------------------------------------------------------------- -void TouchFile(const string & fileName) +void TouchFile(const std::string & fileName) { FILE * f = fopen(fileName.c_str(), "w"); if (f) @@ -689,28 +693,28 @@ strcpy(str, strdc); #endif //WIN32 void SwapBytes(uint16_t & value) { - value = (value >> 8) | - (value << 8); + value = static_cast((value >> 8) | + (value << 8)); } //--------------------------------------------------------------------------- void SwapBytes(uint32_t & value) { - value = (value >> 24) | - ((value << 8) & 0x00FF0000L)| - ((value >> 8) & 0x0000FF00L)| - (value << 24); + value = static_cast((value >> 24) | + ((value << 8) & 0x00FF0000L) | + ((value >> 8) & 0x0000FF00L) | + (value << 24)); } //--------------------------------------------------------------------------- void SwapBytes(uint64_t & value) { - value = (value >> 56) | - ((value << 40) & 0x00FF000000000000LL) | - ((value << 24) & 0x0000FF0000000000LL) | - ((value << 8) & 0x000000FF00000000LL) | - ((value >> 8) & 0x00000000FF000000LL) | - ((value >> 24) & 0x0000000000FF0000LL) | - ((value >> 40) & 0x000000000000FF00LL) | - (value << 56); + value = static_cast((value >> 56) | + ((value << 40) & 0x00FF000000000000LL) | + ((value << 24) & 0x0000FF0000000000LL) | + ((value << 8) & 0x000000FF00000000LL) | + ((value >> 8) & 0x00000000FF000000LL) | + ((value >> 24) & 0x0000000000FF0000LL) | + ((value >> 40) & 0x000000000000FF00LL) | + (value << 56)); } //--------------------------------------------------------------------------- void SwapBytes(int16_t & value) @@ -734,9 +738,9 @@ void SwapBytes(int64_t & value) value = temp; } //--------------------------------------------------------------------------- -int str2x(const std::string & str, int & x) +int str2x(const std::string & str, int32_t & x) { -x = strtol(str.c_str(), NULL, 10); +x = static_cast(strtol(str.c_str(), NULL, 10)); if (errno == ERANGE) return -1; @@ -744,29 +748,9 @@ if (errno == ERANGE) return 0; } //--------------------------------------------------------------------------- -int str2x(const std::string & str, unsigned & x) +int str2x(const std::string & str, uint32_t & x) { -x = strtoul(str.c_str(), NULL, 10); - -if (errno == ERANGE) - return -1; - -return 0; -} -//--------------------------------------------------------------------------- -int str2x(const std::string & str, long & x) -{ -x = strtol(str.c_str(), NULL, 10); - -if (errno == ERANGE) - return -1; - -return 0; -} -//--------------------------------------------------------------------------- -int str2x(const std::string & str, unsigned long & x) -{ -x = strtoul(str.c_str(), NULL, 10); +x = static_cast(strtoul(str.c_str(), NULL, 10)); if (errno == ERANGE) return -1; @@ -775,7 +759,7 @@ return 0; } #ifndef WIN32 //--------------------------------------------------------------------------- -int str2x(const std::string & str, long long & x) +int str2x(const std::string & str, int64_t & x) { x = strtoll(str.c_str(), NULL, 10); @@ -785,7 +769,7 @@ if (errno == ERANGE) return 0; } //--------------------------------------------------------------------------- -int str2x(const std::string & str, unsigned long long & x) +int str2x(const std::string & str, uint64_t & x) { x = strtoull(str.c_str(), NULL, 10); @@ -796,17 +780,12 @@ return 0; } #endif //--------------------------------------------------------------------------- -const std::string & x2str(unsigned x, std::string & s) -{ -return unsigned2str(x, s); -} -//--------------------------------------------------------------------------- -const std::string & x2str(unsigned long x, std::string & s) +const std::string & x2str(uint32_t x, std::string & s) { return unsigned2str(x, s); } //--------------------------------------------------------------------------- -const std::string & x2str(unsigned long long x, std::string & s) +const std::string & x2str(uint64_t x, std::string & s) { return unsigned2str(x, s); } @@ -982,14 +961,14 @@ if (str2x(str, *val)) return 0; } -int ParseUnsigned(const string & str, unsigned * val) +int ParseUnsigned(const std::string & str, unsigned * val) { if (str2x(str, *val)) return -1; return 0; } -int ParseIntInRange(const string & str, int min, int max, int * val) +int ParseIntInRange(const std::string & str, int min, int max, int * val) { if (ParseInt(str, val) != 0) return -1; @@ -1000,7 +979,7 @@ if (*val < min || *val > max) return 0; } -int ParseUnsignedInRange(const string & str, unsigned min, +int ParseUnsignedInRange(const std::string & str, unsigned min, unsigned max, unsigned * val) { if (ParseUnsigned(str, val) != 0) diff --git a/stglibs/common.lib/include/stg/common.h b/stglibs/common.lib/include/stg/common.h index df938152..80d32aba 100644 --- a/stglibs/common.lib/include/stg/common.h +++ b/stglibs/common.lib/include/stg/common.h @@ -52,7 +52,7 @@ #define ST_MB 3 //----------------------------------------------------------------------------- -const char * IntToKMG(long long a, int statType = ST_F); +const char * IntToKMG(int64_t a, int statType = ST_F); const char * LogDate(time_t t); int ParesTimeStat(const char * str); int IsTimeStat(struct tm * t, int statTime); @@ -236,18 +236,15 @@ const std::string & unsigned2str(varT x, std::string & s) return s; } //----------------------------------------------------------------------------- -int str2x(const std::string & str, int & x); -int str2x(const std::string & str, unsigned & x); -int str2x(const std::string & str, long & x); -int str2x(const std::string & str, unsigned long & x); +int str2x(const std::string & str, int32_t & x); +int str2x(const std::string & str, uint32_t & x); #ifndef WIN32 -int str2x(const std::string & str, long long & x); -int str2x(const std::string & str, unsigned long long & x); +int str2x(const std::string & str, int64_t & x); +int str2x(const std::string & str, uint64_t & x); #endif //----------------------------------------------------------------------------- -const std::string & x2str(unsigned x, std::string & s); -const std::string & x2str(unsigned long x, std::string & s); -const std::string & x2str(unsigned long long x, std::string & s); +const std::string & x2str(uint32_t x, std::string & s); +const std::string & x2str(uint64_t x, std::string & s); //----------------------------------------------------------------------------- char * stg_strptime(const char *, const char *, struct tm *); time_t stg_timegm(struct tm *); diff --git a/stglibs/common.lib/strptime.cpp b/stglibs/common.lib/strptime.cpp index 0e1fde27..38b86b47 100644 --- a/stglibs/common.lib/strptime.cpp +++ b/stglibs/common.lib/strptime.cpp @@ -10,6 +10,8 @@ #define _XOPEN_SOURCE #include +#include "stg/common.h" + char * stg_strptime(const char * a, const char * b, struct tm * tm) { return strptime(a, b, tm); diff --git a/stglibs/conffiles.lib/conffiles.cpp b/stglibs/conffiles.lib/conffiles.cpp index 3c3f3917..4fb72f61 100644 --- a/stglibs/conffiles.lib/conffiles.cpp +++ b/stglibs/conffiles.lib/conffiles.cpp @@ -73,8 +73,9 @@ std::string Trim(std::string val) { return TrimR(TrimL(val)); } -//--------------------------------------------------------------------------- } +//--------------------------------------------------------------------------- +} // namespace anonymous //--------------------------------------------------------------------------- bool StringCaseCmp(const std::string & str1, const std::string & str2) @@ -114,8 +115,13 @@ while (getline(f, line)) return; } +<<<<<<< Updated upstream std::string parameter = Trim(line.substr(0, pos)); std::string value = Trim(line.substr(pos + 1)); +======= + std::string parameter = line.substr(0, pos); + std::string value = line.substr(pos + 1); +>>>>>>> Stashed changes param_val[parameter] = value; } } @@ -184,7 +190,7 @@ const std::map::const_iterator it(param_val.find(param if (it != param_val.end()) { char *res; - *val = strtol(it->second.c_str(), &res, 10); + *val = static_cast(strtol(it->second.c_str(), &res, 10)); if (*res != 0) { *val = defaultVal; //Error! @@ -204,7 +210,7 @@ const std::map::const_iterator it(param_val.find(param if (it != param_val.end()) { char *res; - *val = strtoul(it->second.c_str(), &res, 10); + *val = static_cast(strtoul(it->second.c_str(), &res, 10)); if (*res != 0) { *val = defaultVal; //Error! diff --git a/stglibs/conffiles.lib/include/stg/conffiles.h b/stglibs/conffiles.lib/include/stg/conffiles.h index be7acafe..bd78ae2d 100644 --- a/stglibs/conffiles.lib/include/stg/conffiles.h +++ b/stglibs/conffiles.lib/include/stg/conffiles.h @@ -64,7 +64,6 @@ public: int ReadDouble(const std::string & param, double * val, double defaultVal) const; void WriteString(const std::string & param, const char * val) { return WriteString(param, std::string(val)); } - void WriteString(const std::string & param, const std::string & val); void WriteInt(const std::string & param, int64_t val); void WriteDouble(const std::string & param, double val); diff --git a/stglibs/dotconfpp.lib/include/stg/dotconfpp.h b/stglibs/dotconfpp.lib/include/stg/dotconfpp.h index 8c2a82ad..93075013 100644 --- a/stglibs/dotconfpp.lib/include/stg/dotconfpp.h +++ b/stglibs/dotconfpp.lib/include/stg/dotconfpp.h @@ -110,7 +110,7 @@ public: DOTCONFDocument(CaseSensitive caseSensitivity = CASESENSITIVE); virtual ~DOTCONFDocument(); - void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; }; + void setErrorCallback(DOTCONFCallback _callback, void * _data) { errorCallback = _callback; errorCallbackData = _data; } int setContent(const char * _fileName); diff --git a/stglibs/ibpp.lib/_ibpp.h b/stglibs/ibpp.lib/_ibpp.h index 8284fe9b..27d368af 100644 --- a/stglibs/ibpp.lib/_ibpp.h +++ b/stglibs/ibpp.lib/_ibpp.h @@ -465,7 +465,7 @@ struct GDS #ifdef IBPP_WINDOWS mHandle = 0; #endif - }; + } }; extern GDS gds; diff --git a/stglibs/ibpp.lib/blob.cpp b/stglibs/ibpp.lib/blob.cpp index cfdd61fe..298fe706 100644 --- a/stglibs/ibpp.lib/blob.cpp +++ b/stglibs/ibpp.lib/blob.cpp @@ -118,7 +118,7 @@ int BlobImpl::Read(void* buffer, int size) IBS status; unsigned short bytesread; - int result = (*gds.Call()->m_get_segment)(status.Self(), &mHandle, &bytesread, + ISC_STATUS result = (*gds.Call()->m_get_segment)(status.Self(), &mHandle, &bytesread, (unsigned short)size, (char*)buffer); if (result == isc_segstr_eof) return 0; // Fin du blob if (result != isc_segment && status.Errors()) @@ -230,7 +230,7 @@ void BlobImpl::Load(std::string& data) { status.Reset(); unsigned short bytesread; - int result = (*gds.Call()->m_get_segment)(status.Self(), &mHandle, + ISC_STATUS result = (*gds.Call()->m_get_segment)(status.Self(), &mHandle, &bytesread, (unsigned short)blklen, const_cast(data.data()+pos)); if (result == isc_segstr_eof) break; // End of blob diff --git a/stglibs/ibpp.lib/ibase.h b/stglibs/ibpp.lib/ibase.h index c108aace..9c43ba20 100644 --- a/stglibs/ibpp.lib/ibase.h +++ b/stglibs/ibpp.lib/ibase.h @@ -104,8 +104,10 @@ typedef unsigned __int64 ISC_UINT64; #ifdef ISC_INT64_DEFINED #undef ISC_INT64_DEFINED #else -typedef long long int ISC_INT64; -typedef unsigned long long int ISC_UINT64; +//typedef long long int ISC_INT64; +//typedef unsigned long long int ISC_UINT64; +typedef int64_t ISC_INT64; +typedef uint64_t ISC_UINT64; #endif // Nickolay: it is easier to assume that integer is at least 32-bit. diff --git a/stglibs/ibpp.lib/include/stg/ibpp.h b/stglibs/ibpp.lib/include/stg/ibpp.h index 37a19add..0029094e 100644 --- a/stglibs/ibpp.lib/include/stg/ibpp.h +++ b/stglibs/ibpp.lib/include/stg/ibpp.h @@ -223,7 +223,7 @@ namespace IBPP int mDate; // The date : 1 == 1 Jan 1900 public: - void Clear() { mDate = MinDate - 1; }; + void Clear() { mDate = MinDate - 1; } void Today(); void SetDate(int year, int month, int day); void SetDate(int dt); @@ -236,7 +236,7 @@ namespace IBPP void StartOfMonth(); void EndOfMonth(); - Date() { Clear(); }; + Date() { Clear(); } Date(int dt) { SetDate(dt); } Date(int year, int month, int day); Date(const Date&); // Copy Constructor @@ -248,7 +248,7 @@ namespace IBPP bool operator<(const Date& rv) const { return mDate < rv.GetDate(); } bool operator>(const Date& rv) const { return mDate > rv.GetDate(); } - virtual ~Date() { }; + virtual ~Date() { } }; /* Class Time represent purely a Time. It is usefull in interactions @@ -283,7 +283,7 @@ namespace IBPP bool operator<(const Time& rv) const { return mTime < rv.GetTime(); } bool operator>(const Time& rv) const { return mTime > rv.GetTime(); } - virtual ~Time() { }; + virtual ~Time() { } }; /* Class Timestamp represent a date AND a time. It is usefull in @@ -386,7 +386,7 @@ namespace IBPP User& operator=(const User& r) { copyfrom(r); return *this; } User(const User& r) { copyfrom(r); } User() : userid(0), groupid(0) { } - ~User() { }; + ~User() { } }; // Interface Wrapper @@ -480,7 +480,7 @@ namespace IBPP virtual IBlob* AddRef() = 0; virtual void Release() = 0; - virtual ~IBlob() { }; + virtual ~IBlob() { } }; /* IArray is the interface to the array capabilities of IBPP. Array is the @@ -506,7 +506,7 @@ namespace IBPP virtual IArray* AddRef() = 0; virtual void Release() = 0; - virtual ~IArray() { }; + virtual ~IArray() { } }; /* IService is the interface to the service capabilities of IBPP. Service is @@ -551,7 +551,7 @@ namespace IBPP virtual IService* AddRef() = 0; virtual void Release() = 0; - virtual ~IService() { }; + virtual ~IService() { } }; /* IDatabase is the interface to the database connections in IBPP. Database @@ -591,7 +591,7 @@ namespace IBPP virtual IDatabase* AddRef() = 0; virtual void Release() = 0; - virtual ~IDatabase() { }; + virtual ~IDatabase() { } }; /* ITransaction is the interface to the transaction connections in IBPP. @@ -621,7 +621,7 @@ namespace IBPP virtual ITransaction* AddRef() = 0; virtual void Release() = 0; - virtual ~ITransaction() { }; + virtual ~ITransaction() { } }; /* @@ -700,7 +700,7 @@ namespace IBPP virtual IRow* AddRef() = 0; virtual void Release() = 0; - virtual ~IRow() {}; + virtual ~IRow() {} }; /* IStatement is the interface to the statements execution in IBPP. @@ -799,7 +799,7 @@ namespace IBPP virtual IStatement* AddRef() = 0; virtual void Release() = 0; - virtual ~IStatement() { }; + virtual ~IStatement() { } // DEPRECATED METHODS (WON'T BE AVAILABLE IN VERSIONS 3.x) virtual bool Get(int, char*) = 0; // DEPRECATED @@ -832,7 +832,7 @@ namespace IBPP virtual IEvents* AddRef() = 0; virtual void Release() = 0; - virtual ~IEvents() { }; + virtual ~IEvents() { } }; /* Class EventInterface is merely a pure interface. @@ -844,7 +844,7 @@ namespace IBPP { public: virtual void ibppEventHandler(Events, const std::string&, int) = 0; - virtual ~EventInterface() { }; + virtual ~EventInterface() { } }; // --- Factories --- diff --git a/stglibs/ibpp.lib/statement.cpp b/stglibs/ibpp.lib/statement.cpp index 1a3031fe..e2271cf4 100644 --- a/stglibs/ibpp.lib/statement.cpp +++ b/stglibs/ibpp.lib/statement.cpp @@ -422,7 +422,7 @@ bool StatementImpl::Fetch() _("No statement has been executed or no result set available.")); IBS status; - int code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, mOutRow->Self()); + ISC_STATUS code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, mOutRow->Self()); if (code == 100) // This special code means "no more rows" { mResultSetAvailable = false; @@ -452,7 +452,7 @@ bool StatementImpl::Fetch(IBPP::Row& row) row = rowimpl; IBS status; - int code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, + ISC_STATUS code = (*gds.Call()->m_dsql_fetch)(status.Self(), &mHandle, 1, rowimpl->Self()); if (code == 100) // This special code means "no more rows" { diff --git a/stglibs/ibpp.lib/transaction.cpp b/stglibs/ibpp.lib/transaction.cpp index c9a38774..47eb61c7 100644 --- a/stglibs/ibpp.lib/transaction.cpp +++ b/stglibs/ibpp.lib/transaction.cpp @@ -103,9 +103,9 @@ void TransactionImpl::AddReservation(IBPP::Database db, tpb->Insert(table); tpb->Insert(isc_tpb_protected); break; - default : + /*default : throw LogicExceptionImpl("Transaction::AddReservation", - _("Illegal TTR value detected.")); + _("Illegal TTR value detected."));*/ } } else throw LogicExceptionImpl("Transaction::AddReservation", @@ -306,7 +306,7 @@ void TransactionImpl::AttachDatabaseImpl(DatabaseImpl* dbi, tpb->Insert(isc_tpb_rec_version); break; case IBPP::ilReadCommitted : tpb->Insert(isc_tpb_read_committed); tpb->Insert(isc_tpb_no_rec_version); break; - default : tpb->Insert(isc_tpb_concurrency); break; + case IBPP::ilConcurrency : tpb->Insert(isc_tpb_concurrency); break; } if (lr == IBPP::lrNoWait) tpb->Insert(isc_tpb_nowait); diff --git a/stglibs/locker.lib/include/stg/locker.h b/stglibs/locker.lib/include/stg/locker.h index 7a8d0b8d..51ceb738 100644 --- a/stglibs/locker.lib/include/stg/locker.h +++ b/stglibs/locker.lib/include/stg/locker.h @@ -67,7 +67,7 @@ public: pthread_mutex_unlock(&lockerMutex); #endif pthread_mutex_lock(mutex); - }; + } ~STG_LOCKER() { @@ -77,7 +77,7 @@ public: std::cout << "Unlock: " << lockID << " " << file << ":" << line << " " << mutex << " " << pthread_self() << std::endl; pthread_mutex_unlock(&lockerMutex); #endif - }; + } private: STG_LOCKER(const STG_LOCKER & rvalue); STG_LOCKER & operator=(const STG_LOCKER & rvalue); diff --git a/stglibs/logger.lib/include/stg/logger.h b/stglibs/logger.lib/include/stg/logger.h index dc87178e..c55801ac 100644 --- a/stglibs/logger.lib/include/stg/logger.h +++ b/stglibs/logger.lib/include/stg/logger.h @@ -11,8 +11,8 @@ STG_LOGGER & GetStgLogger(); 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); }; + 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); diff --git a/stglibs/pinger.lib/include/stg/pinger.h b/stglibs/pinger.lib/include/stg/pinger.h index b1b77781..b25f6847 100644 --- a/stglibs/pinger.lib/include/stg/pinger.h +++ b/stglibs/pinger.lib/include/stg/pinger.h @@ -84,6 +84,9 @@ struct PING_MESSAGE class STG_PINGER { public: + typedef std::multimap PingIPs; + typedef PingIPs::size_type SizeType; + STG_PINGER(time_t delay = 15); ~STG_PINGER(); @@ -91,7 +94,7 @@ public: int Stop(); void AddIP(uint32_t ip); void DelIP(uint32_t ip); - int GetPingIPNum() const; + SizeType GetPingIPNum() const { return pingIP.size(); } void PrintAllIP(); int GetIPTime(uint32_t ip, time_t * t) const; void SetDelayTime(time_t d) { delay = d; } @@ -108,7 +111,7 @@ private: static void * RunSendPing(void * d); static void * RunRecvPing(void * d); - int delay; + time_t delay; bool nonstop; bool isRunningRecver; bool isRunningSender; diff --git a/stglibs/pinger.lib/pinger.cpp b/stglibs/pinger.lib/pinger.cpp index 664367e8..edc8c174 100644 --- a/stglibs/pinger.lib/pinger.cpp +++ b/stglibs/pinger.lib/pinger.cpp @@ -165,11 +165,6 @@ while (iter != ipToDel.end()) ipToDel.erase(ipToDel.begin(), ipToDel.end()); } //----------------------------------------------------------------------------- -int STG_PINGER::GetPingIPNum() const -{ -return pingIP.size(); -} -//----------------------------------------------------------------------------- void STG_PINGER::PrintAllIP() { STG_LOCKER lock(&mutex, __FILE__, __LINE__); @@ -202,20 +197,20 @@ return 0; //----------------------------------------------------------------------------- uint16_t STG_PINGER::PingCheckSum(void * data, int len) { -unsigned short * buf = (unsigned short *)data; -unsigned int sum = 0; -unsigned short result; +uint16_t * buf = static_cast(data); +uint32_t sum = 0; +uint32_t result; for ( sum = 0; len > 1; len -= 2 ) sum += *buf++; if ( len == 1 ) - sum += *(unsigned char*)buf; + sum += *reinterpret_cast(buf); sum = (sum >> 16) + (sum & 0xFFFF); sum += (sum >> 16); result = ~sum; -return result; +return static_cast(result); } //----------------------------------------------------------------------------- int STG_PINGER::SendPing(uint32_t ip) @@ -228,7 +223,7 @@ addr.sin_addr.s_addr = ip; memset(&pmSend, 0, sizeof(pmSend)); pmSend.hdr.type = ICMP_ECHO; -pmSend.hdr.un.echo.id = pid; +pmSend.hdr.un.echo.id = static_cast(pid); memcpy(pmSend.msg, &ip, sizeof(ip)); pmSend.hdr.checksum = PingCheckSum(&pmSend, sizeof(pmSend)); @@ -250,19 +245,17 @@ uint32_t ipAddr = 0; char buf[128]; memset(buf, 0, sizeof(buf)); -int bytes; socklen_t len = sizeof(addr); -bytes = recvfrom(recvSocket, &buf, sizeof(buf), 0, (struct sockaddr*)&addr, &len); -if (bytes > 0) +if (recvfrom(recvSocket, &buf, sizeof(buf), 0, reinterpret_cast(&addr), &len)) { - struct IP_HDR * ip = (struct IP_HDR *)buf; - struct ICMP_HDR *icmp = (struct ICMP_HDR *)(buf + ip->ihl * 4); + struct IP_HDR * ip = static_cast(static_cast(buf)); + struct ICMP_HDR *icmp = static_cast(static_cast(buf + ip->ihl * 4)); if (icmp->un.echo.id != pid) return 0; - ipAddr = *(uint32_t*)(buf + sizeof(ICMP_HDR) + ip->ihl * 4); + ipAddr = *static_cast(static_cast(buf + sizeof(ICMP_HDR) + ip->ihl * 4)); } return ipAddr;