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