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