]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
b832ec92c3db0e29eee9e598c0e19e8088f0c680
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / rpcconfig.h
1 #ifndef __RPC_CONFIG_H__
2 #define __RPC_CONFIG_H__
3
4 #include <string>
5 #include <ctime>
6
7 #include <xmlrpc-c/base.hpp>
8 #include <xmlrpc-c/registry.hpp>
9 #include <xmlrpc-c/server_abyss.hpp>
10
11 #include <pthread.h>
12
13 #include "base_plugin.h"
14 #include "base_store.h"
15 #include "base_settings.h"
16 #include "admin_conf.h"
17 #include "../../../admin.h"
18 #include "../../../admins.h"
19 #include "../../../users.h"
20 #include "../../../tariffs.h"
21 #include "../../../traffcounter.h"
22 #include "../../../settings.h"
23
24 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
25
26 extern "C" BASE_PLUGIN * GetPlugin();
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 BASE_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(BASE_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 string      & GetStrError() const { return errorStr; };
75     const 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     mutable string          errorStr;
88     RPC_CONFIG_SETTINGS     rpcConfigSettings;
89     USERS *                 users;
90     ADMINS *                admins;
91     TARIFFS *               tariffs;
92     BASE_STORE *            store;
93     MODULE_SETTINGS         settings;
94     const SETTINGS *        stgSettings;
95     xmlrpc_c::registry      rpcRegistry;
96     xmlrpc_c::serverAbyss * rpcServer;
97     bool                    running;
98     bool                    stopped;
99     pthread_t               tid;
100     std::map<std::string,
101              ADMIN_INFO>    cookies;
102
103     static void *           Run(void *);
104     std::string             GetCookie() const;
105     void                    InitiateRegistry();
106 };
107
108 #endif