$Author: faust $
*/
-#include "stg/common.h"
#include "admins_impl.h"
#include "admin_impl.h"
+#include "stg/common.h"
+
+#include <algorithm>
#include <cerrno>
#include <cassert>
-#include <algorithm>
+
+using STG::AdminsImpl;
//-----------------------------------------------------------------------------
-ADMINS_IMPL::ADMINS_IMPL(STORE * st)
- : ADMINS(),
- stg(PRIV(0xFFFF), "@stargazer", ""),
- noAdmin(PRIV(0xFFFF), "NO-ADMIN", ""),
+AdminsImpl::AdminsImpl(Store * st)
+ : stg(Priv(0xFFFF), "@stargazer", ""),
+ noAdmin(Priv(0xFFFF), "NO-ADMIN", ""),
data(),
store(st),
- WriteServLog(GetStgLogger()),
+ WriteServLog(Logger::get()),
searchDescriptors(),
handle(0),
mutex(),
Read();
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::Add(const std::string & login, const ADMIN * admin)
+int AdminsImpl::Add(const std::string & login, const Admin * admin)
{
STG_LOCKER lock(&mutex);
-const PRIV * priv = admin->GetPriv();
+const Priv * priv = admin->GetPriv();
if (!priv->adminChg)
{
return -1;
}
-ADMIN_IMPL adm(PRIV(0), login, "");
+AdminImpl adm(Priv(0), login, "");
admin_iter ai(find(data.begin(), data.end(), adm));
if (ai != data.end())
return -1;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::Del(const std::string & login, const ADMIN * admin)
+int AdminsImpl::Del(const std::string & login, const Admin * admin)
{
STG_LOCKER lock(&mutex);
-const PRIV * priv = admin->GetPriv();
+const Priv * priv = admin->GetPriv();
if (!priv->adminChg)
{
return -1;
}
-admin_iter ai(find(data.begin(), data.end(), ADMIN_IMPL(PRIV(0), login, "")));
+admin_iter ai(find(data.begin(), data.end(), AdminImpl(Priv(0), login, "")));
if (ai == data.end())
{
++si;
}
-data.remove(*ai);
+data.erase(ai);
if (store->DelAdmin(login) < 0)
{
strError = "Administrator \'" + login + "\' was not deleted. Error: " + store->GetStrError();
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::Change(const ADMIN_CONF & ac, const ADMIN * admin)
+int AdminsImpl::Change(const AdminConf & ac, const Admin * admin)
{
STG_LOCKER lock(&mutex);
-const PRIV * priv = admin->GetPriv();
+const Priv * priv = admin->GetPriv();
if (!priv->adminChg)
{
return -1;
}
-admin_iter ai(find(data.begin(), data.end(), ADMIN_IMPL(PRIV(0), ac.login, "")));
+admin_iter ai(find(data.begin(), data.end(), AdminImpl(Priv(0), ac.login, "")));
if (ai == data.end())
{
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::Read()
+int AdminsImpl::Read()
{
STG_LOCKER lock(&mutex);
std::vector<std::string> adminsList;
for (unsigned int i = 0; i < adminsList.size(); i++)
{
- ADMIN_CONF ac(PRIV(0), adminsList[i], "");
+ AdminConf ac(Priv(0), adminsList[i], "");
if (store->RestoreAdmin(&ac, adminsList[i]))
{
return -1;
}
- data.push_back(ADMIN_IMPL(ac));
+ data.push_back(AdminImpl(ac));
}
return 0;
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::Find(const std::string & l, ADMIN ** admin)
+bool AdminsImpl::Find(const std::string & l, Admin ** admin)
{
assert(admin != NULL && "Pointer to admin is not null");
return false;
}
-admin_iter ai(find(data.begin(), data.end(), ADMIN_IMPL(PRIV(0), l, "")));
+admin_iter ai(find(data.begin(), data.end(), AdminImpl(Priv(0), l, "")));
if (ai != data.end())
{
return true;
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::Exists(const std::string & login) const
+bool AdminsImpl::Exists(const std::string & login) const
{
STG_LOCKER lock(&mutex);
if (data.empty())
return true;
}
-const_admin_iter ai(find(data.begin(), data.end(), ADMIN_IMPL(PRIV(0), login, "")));
+const_admin_iter ai(find(data.begin(), data.end(), AdminImpl(Priv(0), login, "")));
if (ai != data.end())
return true;
return false;
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::Correct(const std::string & login, const std::string & password, ADMIN ** admin)
+bool AdminsImpl::Correct(const std::string & login, const std::string & password, Admin ** admin)
{
STG_LOCKER lock(&mutex);
if (data.empty())
return true;
}
-admin_iter ai(find(data.begin(), data.end(), ADMIN_IMPL(PRIV(0), login, "")));
+admin_iter ai(find(data.begin(), data.end(), AdminImpl(Priv(0), login, "")));
if (ai == data.end())
{
return true;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::OpenSearch() const
+int AdminsImpl::OpenSearch() const
{
STG_LOCKER lock(&mutex);
handle++;
return handle;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::SearchNext(int h, ADMIN_CONF * ac) const
+int AdminsImpl::SearchNext(int h, AdminConf * ac) const
{
STG_LOCKER lock(&mutex);
if (searchDescriptors.find(h) == searchDescriptors.end())
if (searchDescriptors[h] == data.end())
return -1;
-ADMIN_IMPL a = *searchDescriptors[h]++;
+AdminImpl a = *searchDescriptors[h]++;
*ac = a.GetConf();
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::CloseSearch(int h) const
+int AdminsImpl::CloseSearch(int h) const
{
STG_LOCKER lock(&mutex);
if (searchDescriptors.find(h) != searchDescriptors.end())