From 19ad06653de8ff5946a2ef1d577cf42217b2e3e3 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Thu, 15 Sep 2011 22:11:03 +0300 Subject: [PATCH] Hide or add proper copy ctor and assignement operator, initialize members via initialization lists in radius code --- .../plugins/store/files/file_store.cpp | 175 ++---------------- .../plugins/store/files/file_store.h | 49 ++--- 2 files changed, 46 insertions(+), 178 deletions(-) diff --git a/projects/stargazer/plugins/store/files/file_store.cpp b/projects/stargazer/plugins/store/files/file_store.cpp index 62c2519b..0149f07c 100644 --- a/projects/stargazer/plugins/store/files/file_store.cpp +++ b/projects/stargazer/plugins/store/files/file_store.cpp @@ -77,15 +77,25 @@ return fsc.GetPlugin(); //----------------------------------------------------------------------------- FILES_STORE_SETTINGS::FILES_STORE_SETTINGS() : settings(NULL), + errorStr(), + workDir(), + usersDir(), + adminsDir(), + tariffsDir(), + statMode(0), + statUID(0), + statGID(0), + confMode(0), + confUID(0), + confGID(0), + userLogMode(0), + userLogUID(0), + userLogGID(0), removeBak(true), readBak(true) { } //----------------------------------------------------------------------------- -FILES_STORE_SETTINGS::~FILES_STORE_SETTINGS() -{ -} -//----------------------------------------------------------------------------- int FILES_STORE_SETTINGS::ParseOwner(const vector & moduleParams, const string & owner, uid_t * uid) { PARAM_VALUE pv; @@ -306,31 +316,6 @@ c = str[2] - '0'; return 0; } //----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetWorkDir() const -{ -return workDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetUsersDir() const -{ -return usersDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetAdminsDir() const -{ -return adminsDir; -} -//----------------------------------------------------------------------------- -string FILES_STORE_SETTINGS::GetTariffsDir() const -{ -return tariffsDir; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetStatMode() const -{ -return statMode; -} -//----------------------------------------------------------------------------- mode_t FILES_STORE_SETTINGS::GetStatModeDir() const { mode_t mode = statMode; @@ -340,21 +325,6 @@ if (statMode & S_IROTH) mode |= S_IXOTH; return mode; } //----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetStatUID() const -{ -return statUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetStatGID() const -{ -return statGID; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetConfMode() const -{ -return confMode; -} -//----------------------------------------------------------------------------- mode_t FILES_STORE_SETTINGS::GetConfModeDir() const { mode_t mode = confMode; @@ -364,63 +334,21 @@ if (confMode & S_IROTH) mode |= S_IXOTH; return mode; } //----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetConfUID() const -{ -return confUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetConfGID() const -{ -return confGID; -} -//----------------------------------------------------------------------------- -mode_t FILES_STORE_SETTINGS::GetLogMode() const -{ -return userLogMode; -} -//----------------------------------------------------------------------------- -uid_t FILES_STORE_SETTINGS::GetLogUID() const -{ -return userLogUID; -} -//----------------------------------------------------------------------------- -gid_t FILES_STORE_SETTINGS::GetLogGID() const -{ -return userLogGID; -} -//----------------------------------------------------------------------------- -bool FILES_STORE_SETTINGS::GetRemoveBak() const -{ -return removeBak; -} -//----------------------------------------------------------------------------- -bool FILES_STORE_SETTINGS::GetReadBak() const -{ -return readBak; -} -//----------------------------------------------------------------------------- //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- FILES_STORE::FILES_STORE() + : errorStr(), + version("file_store v.1.04"), + storeSettings(), + settings(), + mutex() { -version = "file_store v.1.04"; - pthread_mutexattr_t attr; pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); pthread_mutex_init(&mutex, &attr); }; //----------------------------------------------------------------------------- -FILES_STORE::~FILES_STORE() -{ - -}; -//----------------------------------------------------------------------------- -void FILES_STORE::SetSettings(const MODULE_SETTINGS & s) -{ -settings = s; -} -//----------------------------------------------------------------------------- int FILES_STORE::ParseSettings() { int ret = storeSettings.ParseSettings(settings); @@ -432,17 +360,6 @@ if (ret) return ret; } //----------------------------------------------------------------------------- -const string & FILES_STORE::GetStrError() const -{ -STG_LOCKER lock(&mutex, __FILE__, __LINE__); -return errorStr; -} -//----------------------------------------------------------------------------- -const string & FILES_STORE::GetVersion() const -{ -return version; -} -//----------------------------------------------------------------------------- int FILES_STORE::GetUsersList(vector * userList) const { vector files; @@ -585,27 +502,6 @@ if (Touch(fileName)) printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } -/*f = fopen(fileName.c_str(), "wt"); -if (f) - { - if (fprintf(f, "\n") < 0) - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "fprintf failed. Message: '"; - errorStr += strerror(errno); - errorStr += "'"; - printfd(__FILE__, "FILES_STORE::AddUser - fprintf failed. Message: '%s'\n", strerror(errno)); - return -1; - } - fclose(f); - } -else - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Cannot create file \"" + fileName + "\'"; - printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); - return -1; - }*/ strprintf(&fileName, "%s%s/stat", storeSettings.GetUsersDir().c_str(), login.c_str()); if (Touch(fileName)) @@ -615,27 +511,6 @@ if (Touch(fileName)) printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); return -1; } -/*f = fopen(fileName.c_str(), "wt"); -if (f) - { - if (fprintf(f, "\n") < 0) - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "fprintf failed. Message: '"; - errorStr += strerror(errno); - errorStr += "'"; - printfd(__FILE__, "FILES_STORE::AddUser - fprintf failed. Message: '%s'\n", strerror(errno)); - return -1; - } - fclose(f); - } -else - { - STG_LOCKER lock(&mutex, __FILE__, __LINE__); - errorStr = "Cannot create file \"" + fileName + "\'"; - printfd(__FILE__, "FILES_STORE::AddUser - fopen failed. Message: '%s'\n", strerror(errno)); - return -1; - }*/ return 0; } //----------------------------------------------------------------------------- @@ -1878,10 +1753,6 @@ return 0; //----------------------------------------------------------------------------- int FILES_STORE::AddMessage(STG_MSG * msg, const string & login) const { -//ðÒÏ×ÅÒÉÔØ ÅÓÔØ ÌÉ ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÓÏÏÂÝÅÎÉÊ. åÓÌÉ ÎÅÔ - ÓÏÚÄÁÔØ. -//úÁÔÅÍ ÐÏÌÏÖÉÔØ ÓÏÏÂÝÅÎÉÅ Ó ÉÍÅÎÅÍ ÆÁÊÌÁ - ×ÒÅÍÅÎÎOÊ ÍÅÔËÏÊ. úÁÐÉÓÁÔØ ÔÕÄÁ -//ÔÅËÓÔ É ÐÒÉÏÒÉÔÅÔ. - string fn; string dn; struct timeval tv; @@ -1922,10 +1793,6 @@ return EditMessage(*msg, login); //----------------------------------------------------------------------------- int FILES_STORE::EditMessage(const STG_MSG & msg, const string & login) const { -//ðÒÏ×ÅÒÉÔØ ÅÓÌÔØ ÌÉ ÄÉÒÅËÔÏÒÉÑ ÄÌÑ ÓÏÏÂÝÅÎÉÊ. åÓÌÉ ÎÅÔ - ÓÏÚÄÁÔØ. -//úÁÔÅÍ ÐÏÌÏÖÉÔØ ÓÏÏÂÝÅÎÉÅ Ó ÉÍÅÎÅÍ ÆÁÊÌÁ - ×ÒÅÍÅÎÎOÊ ÍÅÔËÏÊ. úÁÐÉÓÁÔØ ÔÕÄÁ -//ÔÅËÓÔ É ÐÒÉÏÒÉÔÅÔ. - string fileName; FILE * msgFile; @@ -2007,8 +1874,6 @@ int FILES_STORE::GetMessageHdrs(vector * hdrsList, const string & l { string dn(storeSettings.GetUsersDir() + "/" + login + "/messages/"); -//hdrsList->resize(messages.size()); - if (access(dn.c_str(), F_OK) != 0) { return 0; @@ -2160,8 +2025,6 @@ return -1; //----------------------------------------------------------------------------- int GetFileList(vector * fileList, const string & directory, mode_t mode, const string & ext) { -// æÕÎËÃÉÑ ÐÒÏÓÍÁÔÒÉ×ÁÅÔ ÓÏÄÅÒÖÉÍÏÅ ÄÉÒÅËÔÏÒÉÉ - DIR * d = opendir(directory.c_str()); if (!d) diff --git a/projects/stargazer/plugins/store/files/file_store.h b/projects/stargazer/plugins/store/files/file_store.h index cd81dcda..91fb7fa8 100644 --- a/projects/stargazer/plugins/store/files/file_store.h +++ b/projects/stargazer/plugins/store/files/file_store.h @@ -44,33 +44,35 @@ extern "C" STORE * GetStore(); class FILES_STORE_SETTINGS { public: FILES_STORE_SETTINGS(); - virtual ~FILES_STORE_SETTINGS(); - virtual int ParseSettings(const MODULE_SETTINGS & s); - virtual const std::string & GetStrError() const; + int ParseSettings(const MODULE_SETTINGS & s); + const std::string & GetStrError() const; - std::string GetWorkDir() const; - std::string GetUsersDir() const; - std::string GetAdminsDir() const; - std::string GetTariffsDir() const; + std::string GetWorkDir() const { return workDir; } + std::string GetUsersDir() const { return usersDir; } + std::string GetAdminsDir() const { return adminsDir; } + std::string GetTariffsDir() const { return tariffsDir; } - mode_t GetStatMode() const; + mode_t GetStatMode() const { return statMode; } mode_t GetStatModeDir() const; - uid_t GetStatUID() const; - gid_t GetStatGID() const; + uid_t GetStatUID() const { return statUID; } + gid_t GetStatGID() const { return statGID; } - mode_t GetConfMode() const; + mode_t GetConfMode() const { return confMode; } mode_t GetConfModeDir() const; - uid_t GetConfUID() const; - gid_t GetConfGID() const; + uid_t GetConfUID() const { return confUID; } + gid_t GetConfGID() const { return confGID; } - mode_t GetLogMode() const; - uid_t GetLogUID() const; - gid_t GetLogGID() const; + mode_t GetLogMode() const { return userLogMode; } + uid_t GetLogUID() const { return userLogUID; } + gid_t GetLogGID() const { return userLogGID; } - bool GetRemoveBak() const; - bool GetReadBak() const; + bool GetRemoveBak() const { return removeBak; } + bool GetReadBak() const { return readBak; } private: + FILES_STORE_SETTINGS(const FILES_STORE_SETTINGS & rvalue); + FILES_STORE_SETTINGS & operator=(const FILES_STORE_SETTINGS & rvalue); + const MODULE_SETTINGS * settings; int User2UID(const char * user, uid_t * uid); @@ -107,8 +109,8 @@ private: class FILES_STORE: public STORE { public: FILES_STORE(); - virtual ~FILES_STORE(); - virtual const std::string & GetStrError() const; + virtual ~FILES_STORE() {} + virtual const std::string & GetStrError() const { return errorStr; } //User virtual int GetUsersList(std::vector * usersList) const; @@ -180,11 +182,14 @@ public: 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); + virtual void SetSettings(const MODULE_SETTINGS & s) { settings = s; } virtual int ParseSettings(); - virtual const std::string & GetVersion() const; + virtual const std::string & GetVersion() const { return version; } private: + FILES_STORE(const FILES_STORE & rvalue); + FILES_STORE & operator=(const FILES_STORE & rvalue); + virtual int RestoreUserStat(USER_STAT * stat, const std::string & login, const std::string & fileName) const; virtual int RestoreUserConf(USER_CONF * conf, const std::string & login, const std::string & fileName) const; -- 2.44.2