]> git.stg.codes - stg.git/blobdiff - projects/stargazer/plugins/store/files/file_store.cpp
Default constructor added in resetable structures
[stg.git] / projects / stargazer / plugins / store / files / file_store.cpp
index 5fadbd4d1457e54e2cef61a2c0c01bfab16d0d45..62c2519b976a343cdf88fe59847b93dbcc89623b 100644 (file)
@@ -51,6 +51,7 @@
 #include "stg/blowfish.h"
 #include "stg/logger.h"
 #include "stg/locker.h"
+#include "stg/plugin_creator.h"
 #include "file_store.h"
 
 #define DELETED_USERS_DIR   "deleted_users"
@@ -63,78 +64,15 @@ int GetFileList(vector<string> * fileList, const string & directory, mode_t mode
 
 const int pt_mega = 1024 * 1024;
 //-----------------------------------------------------------------------------
-class BAK_FILE
-{
-public:
-
-    //-------------------------------------------------------------------------
-    BAK_FILE(const string & fileName, bool removeBak)
-            : f(NULL),
-              removeBak(false)
-        {
-        bakSuccessed = false;
-        BAK_FILE::removeBak = removeBak;
-        fileNameBak = fileName + ".bak";
-        if (rename(fileName.c_str(), fileNameBak.c_str()))
-            {
-            printfd(__FILE__, "BAK_FILE::BAK_FILE - rename failed. Message: '%s'\n", strerror(errno));
-            }
-        else
-            {
-            bakSuccessed = true;
-            }
-
-        }
-    //-------------------------------------------------------------------------
-    ~BAK_FILE()
-        {
-        if(bakSuccessed && removeBak)
-            {
-            if (unlink(fileNameBak.c_str()))
-                {
-                printfd(__FILE__, "BAK_FILE::~BAK_FILE - unlink failed. Message: '%s'\n", strerror(errno));
-                }
-            }
-        }
-    //-------------------------------------------------------------------------
-
-private:
-    FILE * f;
-    bool bakSuccessed;
-    string fileNameBak;
-    bool removeBak;
-};
-//-----------------------------------------------------------------------------
-class FILES_STORE_CREATOR
-{
-private:
-    FILES_STORE * fs;
-
-public:
-    FILES_STORE_CREATOR()
-        : fs(new FILES_STORE())
-        {
-        };
-    ~FILES_STORE_CREATOR()
-        {
-        delete fs;
-        };
-
-    FILES_STORE * GetStore()
-    {
-        return fs;
-    };
-};
-//-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-FILES_STORE_CREATOR fsc;
+PLUGIN_CREATOR<FILES_STORE> fsc;
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 STORE * GetStore()
 {
-return fsc.GetStore();
+return fsc.GetPlugin();
 }
 //-----------------------------------------------------------------------------
 FILES_STORE_SETTINGS::FILES_STORE_SETTINGS()
@@ -594,6 +532,7 @@ while ((entry = readdir(d)))
             errorStr += strerror(errno);
             errorStr += "'";
             printfd(__FILE__, "FILES_STORE::RemoveDir() - unlink failed. Message: '%s'\n", strerror(errno));
+            closedir(d);
             return -1;
             }
         }
@@ -602,6 +541,7 @@ while ((entry = readdir(d)))
         {
         if (RemoveDir(str.c_str()))
             {
+            closedir(d);
             return -1;
             }
 
@@ -978,8 +918,6 @@ int FILES_STORE::SaveUserConf(const USER_CONF & conf, const string & login) cons
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/conf";
 
-//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-
 CONFIGFILE cfstat(fileName, true);
 
 int e = cfstat.Error();
@@ -1037,8 +975,6 @@ char s[22];
 string fileName;
 fileName = storeSettings.GetUsersDir() + "/" + login + "/stat";
 
-//BAK_FILE bakFile(fileName, storeSettings.GetRemoveBak());
-
     {
     CONFIGFILE cfstat(fileName, true);
     int e = cfstat.Error();
@@ -1245,10 +1181,10 @@ if (s2.Error())
 for (size_t i = 0; i < DIR_NUM; i++)
     {
     char dirName[3];
-    snprintf(dirName, 3, "U%d", i);
+    snprintf(dirName, 3, "U%llu", (unsigned long long)i);
     s.WriteInt(dirName, stat.up[i]); // Classic
     s2.WriteInt(dirName, stat.up[i]); // New
-    snprintf(dirName, 3, "D%d", i);
+    snprintf(dirName, 3, "D%llu", (unsigned long long)i);
     s.WriteInt(dirName, stat.down[i]); // Classic
     s2.WriteInt(dirName, stat.down[i]); // New
     }
@@ -1346,6 +1282,8 @@ strprintf(&fileName, "%s/%s.adm", storeSettings.GetAdminsDir().c_str(), ac.login
     cf.WriteInt("UsrAddDel",   ac.priv.userAddDel);
     cf.WriteInt("ChgTariff",   ac.priv.tariffChg);
     cf.WriteInt("ChgAdmin",    ac.priv.adminChg);
+    cf.WriteInt("ChgService",  ac.priv.serviceChg);
+    cf.WriteInt("ChgCorp",     ac.priv.corpChg);
     }
 
 return 0;
@@ -1473,6 +1411,16 @@ else
     return -1;
     }
 
+if (cf.ReadInt("ChgService", &a, 0) == 0)
+    ac->priv.serviceChg = a;
+else
+    ac->priv.serviceChg = 0;
+
+if (cf.ReadInt("ChgCorp", &a, 0) == 0)
+    ac->priv.corpChg = a;
+else
+    ac->priv.corpChg = 0;
+
 return 0;
 }
 //-----------------------------------------------------------------------------