]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/authorization/ao/ao.h
Complete replacement notifiers with subscriptions.
[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 struct Users;
40
41 class AUTH_AO;
42
43 using UserPtr = User*;
44 using ConstUserPtr = const User*;
45 //-----------------------------------------------------------------------------
46 class AUTH_AO : public Auth
47 {
48     public:
49         AUTH_AO();
50
51         void                SetUsers(Users * u) override { users = u; }
52
53         int                 Start() override;
54         int                 Stop() override;
55         int                 Reload(const ModuleSettings & /*ms*/) override { return 0; }
56         bool                IsRunning() override { return isRunning; }
57         void                SetSettings(const ModuleSettings &) override {}
58         int                 ParseSettings() override { return 0; }
59         const std::string & GetStrError() const override { return errorStr; }
60         std::string         GetVersion() const override;
61         uint16_t            GetStartPosition() const override { return 30; }
62         uint16_t            GetStopPosition() const override { return 30; }
63
64         int                 SendMessage(const Message & msg, uint32_t ip) const override;
65
66     private:
67         AUTH_AO(const AUTH_AO & rvalue);
68         AUTH_AO & operator=(const AUTH_AO & rvalue);
69
70         void                AddUser(UserPtr u);
71         void                DelUser(UserPtr u);
72
73         void                GetUsers();
74         void                SetUserNotifiers(UserPtr u);
75         void                UnSetUserNotifiers(UserPtr u);
76         void                UpdateUserAuthorization(ConstUserPtr u) const;
77         void                Unauthorize(UserPtr u);
78
79         mutable std::string errorStr;
80         Users *             users;
81         std::vector<UserPtr> userList;
82         bool                isRunning;
83         ModuleSettings     settings;
84
85         using ConnHolder = std::tuple<int, ScopedConnection, ScopedConnection, ScopedConnection, ScopedConnection>;
86         std::vector<ConnHolder> m_conns;
87
88         ScopedConnection m_onAddUserConn;
89         ScopedConnection m_onDelUserConn;
90
91         PluginLogger logger;
92 };
93
94 }