*
*/
-#include <string>
-#include <vector>
-
-using namespace std;
-
#include "firebird_store.h"
-#include "stg/ibpp.h"
+
+#include "stg/admin_conf.h"
#include "stg/blowfish.h"
+#include "stg/common.h"
+
+#include <string>
+#include <vector>
#define adm_enc_passwd "cjeifY8m3"
//-----------------------------------------------------------------------------
-int FIREBIRD_STORE::GetAdminsList(vector<string> * adminsList) const
+int FIREBIRD_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
-string login;
-
try
{
tr->Start();
st->Execute("select login from tb_admins");
while (st->Fetch())
{
+ std::string login;
st->Get(1, login);
adminsList->push_back(login);
}
return 0;
}
//-----------------------------------------------------------------------------
-int FIREBIRD_STORE::SaveAdmin(const ADMIN_CONF & ac) const
+int FIREBIRD_STORE::SaveAdmin(const STG::AdminConf & ac) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
memset(cryptedPass, 0, ADM_PASSWD_LEN + 1);
strncpy(adminPass, ac.password.c_str(), ADM_PASSWD_LEN);
-EnDecodeInit(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx);
+InitContext(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx);
for (int i = 0; i < ADM_PASSWD_LEN / 8; i++)
- EncodeString(cryptedPass + 8 * i, adminPass + 8 * i, &ctx);
+ EncryptBlock(cryptedPass + 8 * i, adminPass + 8 * i, &ctx);
cryptedPass[ADM_PASSWD_LEN] = 0;
Encode12(encodedPass, cryptedPass, ADM_PASSWD_LEN);
return 0;
}
//-----------------------------------------------------------------------------
-int FIREBIRD_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const
+int FIREBIRD_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amRead, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
{
st->Get(2, ac->login);
st->Get(3, ac->password);
- st->Get(4, (int16_t &)ac->priv.userConf);
- st->Get(5, (int16_t &)ac->priv.userPasswd);
- st->Get(6, (int16_t &)ac->priv.userStat);
- st->Get(7, (int16_t &)ac->priv.userCash);
- st->Get(8, (int16_t &)ac->priv.userAddDel);
- st->Get(9, (int16_t &)ac->priv.tariffChg);
- st->Get(10, (int16_t &)ac->priv.adminChg);
+ st->Get(4, reinterpret_cast<int16_t &>(ac->priv.userConf));
+ st->Get(5, reinterpret_cast<int16_t &>(ac->priv.userPasswd));
+ st->Get(6, reinterpret_cast<int16_t &>(ac->priv.userStat));
+ st->Get(7, reinterpret_cast<int16_t &>(ac->priv.userCash));
+ st->Get(8, reinterpret_cast<int16_t &>(ac->priv.userAddDel));
+ st->Get(9, reinterpret_cast<int16_t &>(ac->priv.tariffChg));
+ st->Get(10, reinterpret_cast<int16_t &>(ac->priv.adminChg));
}
else
{
}
Decode21(cryptedPass, ac->password.c_str());
-EnDecodeInit(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx);
+InitContext(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx);
for (int i = 0; i < ADM_PASSWD_LEN / 8; i++)
{
- DecodeString(adminPass + 8 * i, cryptedPass + 8 * i, &ctx);
+ DecryptBlock(adminPass + 8 * i, cryptedPass + 8 * i, &ctx);
}
ac->password = adminPass;
return 0;
}
//-----------------------------------------------------------------------------
-int FIREBIRD_STORE::AddAdmin(const string & login) const
+int FIREBIRD_STORE::AddAdmin(const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);
return 0;
}
//-----------------------------------------------------------------------------
-int FIREBIRD_STORE::DelAdmin(const string & login) const
+int FIREBIRD_STORE::DelAdmin(const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::lock_guard lock(m_mutex);
IBPP::Transaction tr = IBPP::TransactionFactory(db, IBPP::amWrite, til, tlr);
IBPP::Statement st = IBPP::StatementFactory(db, tr);