]> git.stg.codes - stg.git/blob - stargazer/admins_impl.h
a533cf2ad526378d62fda60147e914c08eecd634
[stg.git] / stargazer / admins_impl.h
1 /*
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.
6  *
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.
11  *
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
15  */
16
17 /*
18  *    Date: 27.10.2002
19  */
20
21 /*
22  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
23  */
24
25 #pragma once
26
27 #include "admin_impl.h"
28
29 #include "stg/admins.h"
30 #include "stg/admin.h"
31 #include "stg/locker.h"
32 #include "stg/store.h"
33 #include "stg/noncopyable.h"
34 #include "stg/logger.h"
35
36 #include <vector>
37 #include <map>
38 #include <string>
39
40 #include <pthread.h>
41
42 namespace STG
43 {
44
45 class AdminsImpl : public Admins {
46     public:
47         explicit AdminsImpl(Store * st);
48         virtual ~AdminsImpl() {}
49
50         int           Add(const std::string & login, const Admin * admin);
51         int           Del(const std::string & login, const Admin * admin);
52         int           Change(const AdminConf & ac, const Admin * admin);
53         const Admin * GetSysAdmin() const { return &stg; }
54         const Admin * GetNoAdmin() const { return &noAdmin; }
55         bool          Find(const std::string & l, Admin ** admin);
56         bool          Exists(const std::string & login) const;
57         bool          Correct(const std::string & login,
58                               const std::string & password,
59                               Admin ** admin);
60         const std::string & GetStrError() const { return strError; }
61
62         size_t        Count() const { return data.size(); }
63
64         int OpenSearch() const;
65         int SearchNext(int, AdminConf * ac) const;
66         int CloseSearch(int) const;
67
68     private:
69         AdminsImpl(const AdminsImpl & rvalue);
70         AdminsImpl & operator=(const AdminsImpl & rvalue);
71
72         typedef std::vector<AdminImpl>::iterator admin_iter;
73         typedef std::vector<AdminImpl>::const_iterator const_admin_iter;
74
75         int             Read();
76
77         AdminImpl              stg;
78         AdminImpl              noAdmin;
79         std::vector<AdminImpl> data;
80         Store *                 store;
81         Logger &            WriteServLog;
82         mutable std::map<int, const_admin_iter> searchDescriptors;
83         mutable unsigned int    handle;
84         mutable pthread_mutex_t mutex;
85         std::string             strError;
86 };
87
88 }