]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
Include MODULE_SETTINGS definition in rpcconfig.h
[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
10 #include <xmlrpc-c/base.hpp>
11 #include <xmlrpc-c/registry.hpp>
12 #include <xmlrpc-c/server_abyss.hpp>
13
14 #include "os_int.h"
15 #include "plugin.h"
16 #include "admin_conf.h"
17 #include "module_settings.h"
18
19 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
20
21 extern "C" PLUGIN * GetPlugin();
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 private:
38     int     ParseIntInRange(const std::string & str,
39                             int min,
40                             int max,
41                             int * val);
42     std::string  errorStr;
43     int          port;
44     double       cookieTimeout;
45 };
46
47 struct ADMIN_INFO
48 {
49     std::string admin;
50     time_t      accessTime;
51     PRIV        priviledges;
52 };
53
54 class RPC_CONFIG :public PLUGIN
55 {
56 public:
57     RPC_CONFIG();
58     virtual ~RPC_CONFIG();
59
60     void                SetUsers(USERS * u) { users = u; }
61     void                SetTariffs(TARIFFS * t) { tariffs = t; }
62     void                SetAdmins(ADMINS * a) { admins = a; }
63     void                SetStore(STORE * s) { store = s; }
64     void                SetTraffcounter(TRAFFCOUNTER *) {}
65     void                SetStgSettings(const SETTINGS * s) { stgSettings = s; }
66     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
67     int                 ParseSettings();
68
69     int                 Start();
70     int                 Stop();
71     int                 Reload() { return 0; }
72     bool                IsRunning() { return running && !stopped; }
73
74     const std::string & GetStrError() const { return errorStr; }
75     const std::string   GetVersion() const { return RPC_CONFIG_VERSION; }
76     uint16_t            GetStartPosition() const { return 220; }
77     uint16_t            GetStopPosition() const { return 220; }
78
79     bool                GetAdminInfo(const std::string & cookie,
80                                      ADMIN_INFO * info);
81     bool                CheckAdmin(const std::string & login,
82                                    const std::string & password,
83                                    std::string * cookie);
84     bool                LogoutAdmin(const std::string & cookie);
85
86 private:
87     static void *           Run(void *);
88     std::string             GetCookie() const;
89     void                    InitiateRegistry();
90
91     mutable std::string     errorStr;
92     RPC_CONFIG_SETTINGS     rpcConfigSettings;
93     USERS *                 users;
94     ADMINS *                admins;
95     TARIFFS *               tariffs;
96     STORE *                 store;
97     MODULE_SETTINGS         settings;
98     const SETTINGS *        stgSettings;
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 };
107
108 #endif