]> git.stg.codes - stg.git/commitdiff
Merge remote-tracking branch 'origin/master' into ticket37
authorElena Mamontova <helenh463@gmail.com>
Thu, 27 Oct 2016 15:55:36 +0000 (18:55 +0300)
committerElena Mamontova <helenh463@gmail.com>
Thu, 27 Oct 2016 15:55:36 +0000 (18:55 +0300)
1  2 
projects/stargazer/plugins/store/files/file_store.cpp
projects/stargazer/plugins/store/firebird/firebird_store_tariffs.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_utils.cpp
projects/stargazer/user_impl.cpp
stglibs/common.lib/common.cpp
stglibs/common.lib/include/stg/common.h

index 51c3707910c34bbd3bf087c638c341f5060fd5f0,96add48fe14a4b2de738ea617add82770e7fe265..f63d96869552c48b8cdcdaa85502c00445bf3b43
@@@ -1539,10 -1579,118 +1592,120 @@@ std::string fileName = storeSettings.Ge
      cf.WriteDouble("Free", td.tariffConf.free);
      cf.WriteString("TraffType", TARIFF::TraffTypeToString(td.tariffConf.traffType));
      cf.WriteString("Period", TARIFF::PeriodToString(td.tariffConf.period));
 +    cf.WriteString("ChangePolicy", TARIFF::ChangePolicyToString(td.tariffConf.changePolicy));
 +    cf.WriteTime("ChangePolicyTimeout", td.tariffConf.changePolicyTimeout);
      }
  
+ return 0;
+ }
+ //-----------------------------------------------------------------------------*/
+ int FILES_STORE::AddService(const std::string & name) const
+ {
+ std::string fileName;
+ strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+ if (Touch(fileName))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Cannot create file " + fileName;
+     printfd(__FILE__, "FILES_STORE::AddService - failed to add service '%s'\n", name.c_str());
+     return -1;
+     }
+ return 0;
+ }
+ //-----------------------------------------------------------------------------*/
+ int FILES_STORE::DelService(const std::string & name) const
+ {
+ std::string fileName;
+ strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+ if (unlink(fileName.c_str()))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "unlink failed. Message: '";
+     errorStr += strerror(errno);
+     errorStr += "'";
+     printfd(__FILE__, "FILES_STORE::DelAdmin - unlink failed. Message: '%s'\n", strerror(errno));
+     }
+ return 0;
+ }
+ //-----------------------------------------------------------------------------*/
+ int FILES_STORE::SaveService(const SERVICE_CONF & conf) const
+ {
+ std::string fileName;
+ strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), conf.name.c_str());
+     {
+     CONFIGFILE cf(fileName, true);
+     int e = cf.Error();
+     if (e)
+         {
+         STG_LOCKER lock(&mutex);
+         errorStr = "Cannot write service " + conf.name + ". " + fileName;
+         printfd(__FILE__, "FILES_STORE::SaveService - failed to save service '%s'\n", conf.name.c_str());
+         return -1;
+         }
+     cf.WriteString("name", conf.name);
+     cf.WriteString("comment", conf.comment);
+     cf.WriteDouble("cost", conf.cost);
+     cf.WriteInt("pay_day", conf.payDay);
+     }
+ return 0;
+ }
+ //-----------------------------------------------------------------------------
+ int FILES_STORE::RestoreService(SERVICE_CONF * conf, const std::string & name) const
+ {
+ std::string fileName;
+ strprintf(&fileName, "%s/%s.serv", storeSettings.GetServicesDir().c_str(), name.c_str());
+ CONFIGFILE cf(fileName);
+ if (cf.Error())
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Cannot open " + fileName;
+     printfd(__FILE__, "FILES_STORE::RestoreService - failed to restore service '%s'\n", name.c_str());
+     return -1;
+     }
+ if (cf.ReadString("name", &conf->name, name))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Error in parameter 'name'";
+     printfd(__FILE__, "FILES_STORE::RestoreService - name read failed for service '%s'\n", name.c_str());
+     return -1;
+     }
+ if (cf.ReadString("comment", &conf->comment, ""))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Error in parameter 'comment'";
+     printfd(__FILE__, "FILES_STORE::RestoreService - comment read failed for service '%s'\n", name.c_str());
+     return -1;
+     }
+ if (cf.ReadDouble("cost", &conf->cost, 0.0))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Error in parameter 'cost'";
+     printfd(__FILE__, "FILES_STORE::RestoreService - cost read failed for service '%s'\n", name.c_str());
+     return -1;
+     }
+ unsigned short value = 0;
+ if (cf.ReadUShortInt("pay_day", &value, 0))
+     {
+     STG_LOCKER lock(&mutex);
+     errorStr = "Error in parameter 'pay_day'";
+     printfd(__FILE__, "FILES_STORE::RestoreService - pay day read failed for service '%s'\n", name.c_str());
+     return -1;
+     }
+ conf->payDay = value;
  return 0;
  }
  //-----------------------------------------------------------------------------
Simple merge
Simple merge