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