]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/ao/ao.h
Use std::lock_guard instead of STG_LOCKER.
[stg.git] / projects / stargazer / plugins / authorization / ao / ao.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  *    Author : Boris Mikhailenko <stg34@stargazer.dp.ua>
19  */
20
21 #pragma once
22
23 #include "stg/auth.h"
24 #include "stg/module_settings.h"
25 #include "stg/store.h"
26 #include "stg/subscriptions.h"
27 #include "stg/user_ips.h"
28 #include "stg/user.h"
29 #include "stg/logger.h"
30
31 #include <string>
32 #include <vector>
33 #include <list>
34
35 #include <pthread.h>
36
37 namespace STG
38 {
39 class Users;
40
41 using UserPtr = User*;
42 using ConstUserPtr = const User*;
43 //-----------------------------------------------------------------------------
44 class AUTH_AO : public Auth
45 {
46     public:
47         AUTH_AO();
48
49         void                SetUsers(Users * u) override { users = u; }
50
51         int                 Start() override;
52         int                 Stop() override;
53         int                 Reload(const ModuleSettings & /*ms*/) override { return 0; }
54         bool                IsRunning() override { return isRunning; }
55         void                SetSettings(const ModuleSettings &) override {}
56         int                 ParseSettings() override { return 0; }
57         const std::string & GetStrError() const override { return errorStr; }
58         std::string         GetVersion() const override;
59         uint16_t            GetStartPosition() const override { return 30; }
60         uint16_t            GetStopPosition() const override { return 30; }
61
62         int                 SendMessage(const Message & msg, uint32_t ip) const override;
63
64     private:
65         AUTH_AO(const AUTH_AO & rvalue);
66         AUTH_AO & operator=(const AUTH_AO & rvalue);
67
68         void                AddUser(UserPtr u);
69         void                DelUser(UserPtr u);
70
71         void                GetUsers();
72         void                SetUserNotifiers(UserPtr u);
73         void                UnSetUserNotifiers(UserPtr u);
74         void                UpdateUserAuthorization(ConstUserPtr u) const;
75         void                Unauthorize(UserPtr u);
76
77         mutable std::string errorStr;
78         Users *             users;
79         std::vector<UserPtr> userList;
80         bool                isRunning;
81         ModuleSettings     settings;
82
83         using ConnHolder = std::tuple<int, ScopedConnection, ScopedConnection, ScopedConnection, ScopedConnection>;
84         std::vector<ConnHolder> m_conns;
85
86         ScopedConnection m_onAddUserConn;
87         ScopedConnection m_onDelUserConn;
88
89         PluginLogger logger;
90 };
91
92 }