]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
Rename BASE_AUTH and BASE_STORE to AUTH and STORE
[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
18 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
19
20 extern "C" PLUGIN * GetPlugin();
21
22 class ADMINS;
23 class TARIFFS;
24 class USERS;
25 class STORE;
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 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(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     static void *           Run(void *);
87     std::string             GetCookie() const;
88     void                    InitiateRegistry();
89
90     mutable string          errorStr;
91     RPC_CONFIG_SETTINGS     rpcConfigSettings;
92     USERS *                 users;
93     ADMINS *                admins;
94     TARIFFS *               tariffs;
95     STORE *                 store;
96     MODULE_SETTINGS         settings;
97     const SETTINGS *        stgSettings;
98     xmlrpc_c::registry      rpcRegistry;
99     xmlrpc_c::serverAbyss * rpcServer;
100     bool                    running;
101     bool                    stopped;
102     pthread_t               tid;
103     std::map<std::string,
104              ADMIN_INFO>    cookies;
105 };
106
107 #endif