#include <cassert>
#include <algorithm>
+#include "admins_impl.h"
#include "admins.h"
#include "admin.h"
+#include "admin_impl.h"
#include "common.h"
using namespace std;
//-----------------------------------------------------------------------------
-ADMINS::ADMINS(BASE_STORE * st)
+ADMINS_IMPL::ADMINS_IMPL(BASE_STORE * st)
: stg(0xFFFF, "@stargazer", ""),
noAdmin(0xFFFF, "NO-ADMIN", ""),
data(),
ReadAdmins();
}
//-----------------------------------------------------------------------------
-int ADMINS::Add(const string & login, const ADMIN & admin)
+int ADMINS_IMPL::Add(const string & login, const ADMIN & admin)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
const PRIV * priv = admin.GetPriv();
return -1;
}
-ADMIN adm(0, login, "");
+ADMIN_IMPL adm(0, login, "");
admin_iter ai(find(data.begin(), data.end(), adm));
if (ai != data.end())
}
data.push_back(adm);
-/*ADMIN_CONF ac;
-ac.login = login;*/
-if (store->AddAdmin(login) == 0 /*&& store->SaveAdmin(ac) == 0*/)
+
+if (store->AddAdmin(login) == 0)
{
WriteServLog("%s Administrator \'%s\' added.",
admin.GetLogStr().c_str(), login.c_str());
return -1;
}
//-----------------------------------------------------------------------------
-int ADMINS::Del(const string & login, const ADMIN & admin)
+int ADMINS_IMPL::Del(const string & login, const ADMIN & admin)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-ADMIN adm(0, login, "");
+ADMIN_IMPL adm(0, login, "");
const PRIV * priv = admin.GetPriv();
if (!priv->adminChg)
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS::Change(const ADMIN_CONF & ac, const ADMIN & admin)
+int ADMINS_IMPL::Change(const ADMIN_CONF & ac, const ADMIN & admin)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
const PRIV * priv = admin.GetPriv();
return -1;
}
-ADMIN adm(0, ac.login, "");
+ADMIN_IMPL adm(0, ac.login, "");
admin_iter ai(find(data.begin(), data.end(), adm));
if (ai == data.end())
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS::ReadAdmins()
+int ADMINS_IMPL::ReadAdmins()
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
vector<string> adminsList;
return -1;
}
- data.push_back(ADMIN(ac));
+ data.push_back(ADMIN_IMPL(ac));
}
return 0;
}
//-----------------------------------------------------------------------------
-void ADMINS::PrintAdmins() const
+void ADMINS_IMPL::PrintAdmins() const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
const_admin_iter ai(data.begin());
while (ai != data.end())
{
- ai->PrintAdmin();
+ ai->Print();
ai++;
}
}
//-----------------------------------------------------------------------------
-bool ADMINS::FindAdmin(const string & l, ADMIN * admin) const
+bool ADMINS_IMPL::FindAdmin(const string & l, ADMIN ** admin)
{
assert(admin != NULL && "Pointer to admin is not null");
if (data.empty())
{
printfd(__FILE__, "no admin in system!\n");
- *admin = noAdmin;
+ *admin = &noAdmin;
return false;
}
-ADMIN adm(0, l, "");
-const_admin_iter ai(find(data.begin(), data.end(), adm));
+ADMIN_IMPL adm(0, l, "");
+admin_iter ai(find(data.begin(), data.end(), adm));
if (ai != data.end())
{
- *admin = *ai;
+ *admin = &(*ai);
return false;
}
return true;
}
//-----------------------------------------------------------------------------
-bool ADMINS::AdminExists(const string & login) const
+bool ADMINS_IMPL::AdminExists(const string & login) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
return true;
}
-ADMIN adm(0, login, "");
+ADMIN_IMPL adm(0, login, "");
const_admin_iter ai(find(data.begin(), data.end(), adm));
if (ai != data.end())
return false;
}
//-----------------------------------------------------------------------------
-bool ADMINS::AdminCorrect(const string & login, const std::string & password, ADMIN * admin) const
+bool ADMINS_IMPL::AdminCorrect(const string & login, const std::string & password, ADMIN * admin) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
return true;
}
-ADMIN adm(0, login, "");
+ADMIN_IMPL adm(0, login, "");
const_admin_iter ai(find(data.begin(), data.end(), adm));
if (ai == data.end())
return true;
}
//-----------------------------------------------------------------------------
-int ADMINS::OpenSearch() const
+int ADMINS_IMPL::OpenSearch() const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
handle++;
return handle;
}
//-----------------------------------------------------------------------------
-int ADMINS::SearchNext(int h, ADMIN_CONF * ac) const
+int ADMINS_IMPL::SearchNext(int h, ADMIN_CONF * ac) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (searchDescriptors.find(h) == searchDescriptors.end())
if (searchDescriptors[h] == data.end())
return -1;
-ADMIN a = *searchDescriptors[h]++;
+ADMIN_IMPL a = *searchDescriptors[h]++;
*ac = a.GetConf();
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS::CloseSearch(int h) const
+int ADMINS_IMPL::CloseSearch(int h) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (searchDescriptors.find(h) != searchDescriptors.end())