]> git.stg.codes - stg.git/blob - stargazer/plugins/configuration/rpcconfig/rpcconfig.h
Public interfaces: part 4
[stg.git] / stargazer / plugins / configuration / rpcconfig / rpcconfig.h
1 #pragma once
2
3 #include "stg/plugin.h"
4 #include "stg/admin_conf.h"
5 #include "stg/module_settings.h"
6 #include "stg/logger.h"
7
8 #include <xmlrpc-c/base.hpp>
9 #include <xmlrpc-c/registry.hpp>
10 #include <xmlrpc-c/server_abyss.hpp>
11
12 #include <ctime>
13 #include <cstdint>
14 #include <string>
15 #include <map>
16 #include <vector>
17
18 #include <pthread.h>
19
20 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
21
22 namespace STG
23 {
24
25 struct Admins;
26 struct Tariffs;
27 struct Users;
28 struct Store;
29
30 }
31
32 class RPC_CONFIG_SETTINGS
33 {
34 public:
35                          RPC_CONFIG_SETTINGS();
36     virtual              ~RPC_CONFIG_SETTINGS() {}
37     const std::string &  GetStrError() const { return errorStr; }
38     int                  ParseSettings(const STG::ModuleSettings & s);
39     uint16_t             GetPort() const { return port; }
40     double               GetCookieTimeout() const { return cookieTimeout; }
41
42 private:
43     std::string  errorStr;
44     uint16_t     port;
45     double       cookieTimeout;
46 };
47
48 struct ADMIN_INFO
49 {
50     ADMIN_INFO()
51         : admin(),
52           accessTime(0),
53           priviledges()
54     {}
55
56     std::string admin;
57     time_t      accessTime;
58     STG::Priv        priviledges;
59 };
60
61 class RPC_CONFIG : public STG::Plugin
62 {
63 public:
64     RPC_CONFIG();
65     ~RPC_CONFIG() override;
66
67     void                SetUsers(STG::Users * u) override { users = u; }
68     void                SetTariffs(STG::Tariffs * t) override { tariffs = t; }
69     void                SetAdmins(STG::Admins * a) override { admins = a; }
70     void                SetStore(STG::Store * s) override { store = s; }
71     void                SetStgSettings(const STG::Settings * s) override;
72     void                SetSettings(const STG::ModuleSettings & s) override { settings = s; }
73     int                 ParseSettings() override;
74
75     int                 Start() override;
76     int                 Stop() override;
77     int                 Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
78     bool                IsRunning() override { return running && !stopped; }
79
80     const std::string & GetStrError() const override { return errorStr; }
81     std::string         GetVersion() const override { return RPC_CONFIG_VERSION; }
82     uint16_t            GetStartPosition() const override { return 20; }
83     uint16_t            GetStopPosition() const override { return 20; }
84
85     bool                GetAdminInfo(const std::string & cookie,
86                                      ADMIN_INFO * info);
87     bool                CheckAdmin(const std::string & login,
88                                    const std::string & password,
89                                    std::string * cookie);
90     bool                LogoutAdmin(const std::string & cookie);
91
92 private:
93     RPC_CONFIG(const RPC_CONFIG & rvalue);
94     RPC_CONFIG & operator=(const RPC_CONFIG & rvalue);
95
96     static void *           Run(void *);
97     std::string             GetCookie() const;
98     void                    InitiateRegistry();
99
100     mutable std::string     errorStr;
101     RPC_CONFIG_SETTINGS     rpcConfigSettings;
102     STG::Users *                 users;
103     STG::Admins *                admins;
104     STG::Tariffs *               tariffs;
105     STG::Store *                 store;
106     STG::ModuleSettings         settings;
107     int                     fd;
108     xmlrpc_c::registry      rpcRegistry;
109     xmlrpc_c::serverAbyss * rpcServer;
110     bool                    running;
111     bool                    stopped;
112     pthread_t               tid;
113     std::map<std::string,
114              ADMIN_INFO>    cookies;
115     size_t                  dayFee;
116     std::vector<std::string> dirNames;
117     STG::PluginLogger           logger;
118 };