]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
6fc41e202df499aff395a372990aa809d456448d
[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 "os_int.h"
14 #include "base_plugin.h"
15 #include "base_store.h"
16 #include "base_settings.h"
17 #include "admin_conf.h"
18 #include "../../../admin.h"
19 #include "../../../admins.h"
20 #include "../../../users.h"
21 #include "../../../tariffs.h"
22 #include "../../../traffcounter.h"
23 #include "../../../settings.h"
24
25 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
26
27 extern "C" BASE_PLUGIN * GetPlugin();
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 BASE_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(BASE_STORE * s) { store = s; };
65     void                SetTraffcounter(TRAFFCOUNTER *) {};
66     void                SetStgSettings(const SETTINGS * s) { stgSettings = 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 string      & GetStrError() const { return errorStr; };
76     const 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     mutable string          errorStr;
89     RPC_CONFIG_SETTINGS     rpcConfigSettings;
90     USERS *                 users;
91     ADMINS *                admins;
92     TARIFFS *               tariffs;
93     BASE_STORE *            store;
94     MODULE_SETTINGS         settings;
95     const SETTINGS *        stgSettings;
96     xmlrpc_c::registry      rpcRegistry;
97     xmlrpc_c::serverAbyss * rpcServer;
98     bool                    running;
99     bool                    stopped;
100     pthread_t               tid;
101     std::map<std::string,
102              ADMIN_INFO>    cookies;
103
104     static void *           Run(void *);
105     std::string             GetCookie() const;
106     void                    InitiateRegistry();
107 };
108
109 #endif