]> git.stg.codes - stg.git/blob - include/stg/admin_conf.h
Use std::lock_guard instead of STG_LOCKER.
[stg.git] / include / stg / admin_conf.h
1 #pragma once
2
3 #include <string>
4 #include <optional>
5
6 #include <cstdint>
7
8 #define ADM_LOGIN_LEN   (32)
9 #define ADM_PASSWD_LEN  (32)
10
11 namespace STG
12 {
13
14 struct Priv
15 {
16     Priv() noexcept : Priv(0) {}
17     explicit Priv(uint32_t p) noexcept
18         : userStat((p & 0x00000003) >> 0x00),
19           userConf((p & 0x0000000C) >> 0x02),
20           userCash((p & 0x00000030) >> 0x04),
21           userPasswd((p & 0x000000C0) >> 0x06),
22           userAddDel((p & 0x00000300) >> 0x08),
23           adminChg((p & 0x00000C00) >> 0x0A),
24           tariffChg((p & 0x00003000) >> 0x0C),
25           serviceChg((p & 0x0000C000) >> 0x0E),
26           corpChg((p & 0x00030000) >> 0x10)
27     {}
28
29     Priv(const Priv&) = default;
30     Priv& operator=(const Priv&) = default;
31     Priv(Priv&&) = default;
32     Priv& operator=(Priv&&) = default;
33
34     uint32_t toInt() const noexcept
35     {
36         uint32_t p = (userStat   << 0)  |
37                      (userConf   << 2)  |
38                      (userCash   << 4)  |
39                      (userPasswd << 6)  |
40                      (userAddDel << 8)  |
41                      (adminChg   << 10) |
42                      (tariffChg  << 12) |
43                      (serviceChg << 14) |
44                      (corpChg    << 16);
45         return p;
46     }
47
48     uint16_t userStat;
49     uint16_t userConf;
50     uint16_t userCash;
51     uint16_t userPasswd;
52     uint16_t userAddDel;
53     uint16_t adminChg;
54     uint16_t tariffChg;
55     uint16_t serviceChg;
56     uint16_t corpChg;
57 };
58 //-----------------------------------------------------------------------------
59 struct AdminConf
60 {
61     AdminConf() : AdminConf({}, {}, "* NO PASSWORD *") {}
62     AdminConf(const Priv& pr, const std::string& l, const std::string& p)
63         : priv(pr),
64           login(l),
65           password(p)
66     {}
67
68     AdminConf(const AdminConf&) = default;
69     AdminConf& operator=(const AdminConf&) = default;
70     AdminConf(AdminConf&&) = default;
71     AdminConf& operator=(AdminConf&&) = default;
72
73     Priv          priv;
74     std::string   login;
75     std::string   password;
76 };
77 //-----------------------------------------------------------------------------
78 struct AdminConfOpt
79 {
80     std::optional<Priv> priv;
81     std::optional<std::string> login;
82     std::optional<std::string> password;
83 };
84
85 }