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