]> git.stg.codes - stg.git/blob - include/stg/users.h
More subscriptions, less notifiers.
[stg.git] / include / stg / users.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 : Maxim Mamontov <faust@stargazer.dp.ua>
19  */
20
21 #pragma once
22
23 #include "subscriptions.h"
24
25 #include <string>
26
27 #include <cstdint>
28
29 namespace STG
30 {
31
32 struct Admin;
33 struct User;
34 struct Auth;
35
36 class Users
37 {
38     public:
39         virtual ~Users() = default;
40
41         using UserPtr = User*;
42         using ConstUserPtr = const User*;
43
44         virtual int  FindByName(const std::string& login, UserPtr* user) = 0;
45         virtual int  FindByName(const std::string& login, ConstUserPtr* user) const = 0;
46         virtual bool Exists(const std::string& login) const = 0;
47
48         virtual bool TariffInUse(const std::string& tariffName) const = 0;
49
50         template <typename F>
51         auto onAdd(F&& f) { return m_onAddCallbacks.add(std::forward<F>(f)); }
52         template <typename F>
53         auto onDel(F&& f) { return m_onDelCallbacks.add(std::forward<F>(f)); }
54
55         virtual int  Add(const std::string& login, const Admin* admin) = 0;
56         virtual void Del(const std::string& login, const Admin* admin) = 0;
57
58         virtual bool Authorize(const std::string& login, uint32_t ip,
59                                uint32_t enabledDirs, const Auth* auth) = 0;
60         virtual bool Unauthorize(const std::string& login,
61                                  const Auth* auth,
62                                  const std::string& reason = {}) = 0;
63
64         virtual int  ReadUsers() = 0;
65         virtual size_t Count() const = 0;
66
67         virtual int  FindByIPIdx(uint32_t ip, User** user) const = 0;
68         virtual bool IsIPInIndex(uint32_t ip) const = 0;
69         virtual bool IsIPInUse(uint32_t ip, const std::string & login, const User** user) const = 0;
70
71         virtual unsigned int  OpenSearch() = 0;
72         virtual int  SearchNext(int handle, User** u) = 0;
73         virtual int  CloseSearch(int handle) = 0;
74
75         virtual int  Start() = 0;
76         virtual int  Stop() = 0;
77
78     protected:
79         Subscriptions<UserPtr> m_onAddCallbacks;
80         Subscriptions<UserPtr> m_onDelCallbacks;
81 };
82
83 }