2  *    This program is free software; you can redistribute it and/or modify
 
   3  *    it under the terms of the GNU General Public License as published by
 
   4  *    the Free Software Foundation; either version 2 of the License, or
 
   5  *    (at your option) any later version.
 
   7  *    This program is distributed in the hope that it will be useful,
 
   8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  10  *    GNU General Public License for more details.
 
  12  *    You should have received a copy of the GNU General Public License
 
  13  *    along with this program; if not, write to the Free Software
 
  14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
 
  27 #include "stg/admins.h"
 
  28 #include "stg/admin.h"
 
  29 #include "stg/store.h"
 
  30 #include "stg/logger.h"
 
  40 class AdminsImpl : public Admins
 
  43         explicit AdminsImpl(Store& st);
 
  45         AdminsImpl(const AdminsImpl&) = delete;
 
  46         AdminsImpl& operator=(const AdminsImpl&) = delete;
 
  48         int          add(const std::string& login, const Admin& admin) override;
 
  49         int          del(const std::string& login, const Admin& admin) override;
 
  50         int          change(const AdminConf& ac, const Admin& admin) override;
 
  51         const Admin& sysAdmin() const override { return m_stg; }
 
  52         const Admin& noAdmin() const override { return m_noAdmin; }
 
  53         bool         find(const std::string& login, Admin** admin) override;
 
  54         bool         exists(const std::string& login) const override;
 
  55         bool         correct(const std::string& login,
 
  56                              const std::string& password,
 
  57                              Admin** admin) override;
 
  59         const std::string& strError() const override { return m_strError; }
 
  61         size_t       count() const override { return m_data.size(); }
 
  63         void fmap(std::function<void (const Admin&)> callback) const override
 
  65             for (const auto& admin : m_data)
 
  71         auto         find(const std::string& login) { return std::find(m_data.begin(), m_data.end(), Admin(Priv(0), login, "")); }
 
  72         auto         find(const std::string& login) const { return std::find(m_data.begin(), m_data.end(), Admin(Priv(0), login, "")); }
 
  76         std::vector<Admin> m_data;
 
  79         mutable std::mutex m_mutex;
 
  80         std::string        m_strError;