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