]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
64f1182e178a70ac1b4f665162f356c2f1afcbe6
[stg.git] / projects / stargazer / plugins / configuration / rpcconfig / rpcconfig.h
1 #ifndef __RPC_CONFIG_H__
2 #define __RPC_CONFIG_H__
3
4 #include <string>
5
6 #include <xmlrpc-c/base.hpp>
7 #include <xmlrpc-c/registry.hpp>
8 #include <xmlrpc-c/server_abyss.hpp>
9
10 #include <pthread.h>
11
12 #include "base_plugin.h"
13 #include "base_store.h"
14 #include "base_settings.h"
15 #include "admin_conf.h"
16 #include "../../../admin.h"
17 #include "../../../admins.h"
18 #include "../../../users.h"
19 #include "../../../tariffs.h"
20 #include "../../../traffcounter.h"
21 #include "../../../settings.h"
22
23 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
24
25 extern "C" BASE_PLUGIN * GetPlugin();
26
27 class RPC_CONFIG_SETTINGS
28 {
29 public:
30                          RPC_CONFIG_SETTINGS();
31     virtual              ~RPC_CONFIG_SETTINGS() {};
32     const std::string &  GetStrError() const { return errorStr; };
33     int                  ParseSettings(const MODULE_SETTINGS & s);
34     uint16_t             GetPort() const { return port; };
35     double               GetCookieTimeout() const { return cookieTimeout; };
36 private:
37     int     ParseIntInRange(const std::string & str,
38                             int min,
39                             int max,
40                             int * val);
41     std::string  errorStr;
42     int          port;
43     double       cookieTimeout;
44 };
45
46 struct ADMIN_INFO
47 {
48     std::string admin;
49     time_t      accessTime;
50     PRIV        priviledges;
51 };
52
53 class RPC_CONFIG :public BASE_PLUGIN
54 {
55 public:
56     RPC_CONFIG();
57     virtual ~RPC_CONFIG();
58
59     void                SetUsers(USERS * u) { users = u; };
60     void                SetTariffs(TARIFFS * t) { tariffs = t; };
61     void                SetAdmins(ADMINS * a) { admins = a; };
62     void                SetStore(BASE_STORE * s) { store = s; };
63     void                SetTraffcounter(TRAFFCOUNTER *) {};
64     void                SetStgSettings(const SETTINGS * s) { stgSettings = s; };
65     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; };
66     int                 ParseSettings();
67
68     int                 Start();
69     int                 Stop();
70     int                 Reload() { return 0; };
71     bool                IsRunning() { return running && !stopped; };
72
73     const string      & GetStrError() const { return errorStr; };
74     const string        GetVersion() const { return RPC_CONFIG_VERSION; };
75     uint16_t            GetStartPosition() const { return 220; };
76     uint16_t            GetStopPosition() const { return 220; };
77
78     bool                GetAdminInfo(const std::string & cookie,
79                                      ADMIN_INFO * info);
80     bool                CheckAdmin(const std::string & login,
81                                    const std::string & password,
82                                    std::string * cookie);
83     bool                LogoutAdmin(const std::string & cookie);
84
85 private:
86     mutable string          errorStr;
87     RPC_CONFIG_SETTINGS     rpcConfigSettings;
88     USERS *                 users;
89     ADMINS *                admins;
90     TARIFFS *               tariffs;
91     BASE_STORE *            store;
92     MODULE_SETTINGS         settings;
93     const SETTINGS *        stgSettings;
94     xmlrpc_c::registry      rpcRegistry;
95     xmlrpc_c::serverAbyss * rpcServer;
96     bool                    running;
97     bool                    stopped;
98     pthread_t               tid;
99     std::map<std::string,
100              ADMIN_INFO>    cookies;
101
102     static void *           Run(void *);
103     std::string             GetCookie() const;
104     void                    InitiateRegistry();
105 };
106
107 #endif