]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
Added note about waiting rscriptd until message queue becomes empty
[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 private:
39     int     ParseIntInRange(const std::string & str,
40                             int min,
41                             int max,
42                             int * val);
43     std::string  errorStr;
44     int          port;
45     double       cookieTimeout;
46 };
47
48 struct ADMIN_INFO
49 {
50     std::string admin;
51     time_t      accessTime;
52     PRIV        priviledges;
53 };
54
55 class RPC_CONFIG :public PLUGIN
56 {
57 public:
58     RPC_CONFIG();
59     virtual ~RPC_CONFIG();
60
61     void                SetUsers(USERS * u) { users = u; }
62     void                SetTariffs(TARIFFS * t) { tariffs = t; }
63     void                SetAdmins(ADMINS * a) { admins = a; }
64     void                SetStore(STORE * s) { store = s; }
65     void                SetTraffcounter(TRAFFCOUNTER *) {}
66     void                SetStgSettings(const SETTINGS * s);
67     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
68     int                 ParseSettings();
69
70     int                 Start();
71     int                 Stop();
72     int                 Reload() { return 0; }
73     bool                IsRunning() { return running && !stopped; }
74
75     const std::string & GetStrError() const { return errorStr; }
76     const std::string   GetVersion() const { return RPC_CONFIG_VERSION; }
77     uint16_t            GetStartPosition() const { return 220; }
78     uint16_t            GetStopPosition() const { return 220; }
79
80     bool                GetAdminInfo(const std::string & cookie,
81                                      ADMIN_INFO * info);
82     bool                CheckAdmin(const std::string & login,
83                                    const std::string & password,
84                                    std::string * cookie);
85     bool                LogoutAdmin(const std::string & cookie);
86
87 private:
88     static void *           Run(void *);
89     std::string             GetCookie() const;
90     void                    InitiateRegistry();
91
92     mutable std::string     errorStr;
93     RPC_CONFIG_SETTINGS     rpcConfigSettings;
94     USERS *                 users;
95     ADMINS *                admins;
96     TARIFFS *               tariffs;
97     STORE *                 store;
98     MODULE_SETTINGS         settings;
99     xmlrpc_c::registry      rpcRegistry;
100     xmlrpc_c::serverAbyss * rpcServer;
101     bool                    running;
102     bool                    stopped;
103     pthread_t               tid;
104     std::map<std::string,
105              ADMIN_INFO>    cookies;
106     size_t                  dayFee;
107     std::vector<std::string> dirNames;
108 };
109
110 #endif