]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/rpcconfig/rpcconfig.h
Reset delayed tariff change when setting new tariff immediately
[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 #include <vector>
10
11 #include <xmlrpc-c/base.hpp>
12 #include <xmlrpc-c/registry.hpp>
13 #include <xmlrpc-c/server_abyss.hpp>
14
15 #include "stg/os_int.h"
16 #include "stg/plugin.h"
17 #include "stg/admin_conf.h"
18 #include "stg/module_settings.h"
19
20 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
21
22 extern "C" PLUGIN * GetPlugin();
23
24 class ADMINS;
25 class TARIFFS;
26 class USERS;
27 class STORE;
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     std::string  errorStr;
40     int          port;
41     double       cookieTimeout;
42 };
43
44 struct ADMIN_INFO
45 {
46     std::string admin;
47     time_t      accessTime;
48     PRIV        priviledges;
49 };
50
51 class RPC_CONFIG :public PLUGIN
52 {
53 public:
54     RPC_CONFIG();
55     virtual ~RPC_CONFIG();
56
57     void                SetUsers(USERS * u) { users = u; }
58     void                SetTariffs(TARIFFS * t) { tariffs = t; }
59     void                SetAdmins(ADMINS * a) { admins = a; }
60     void                SetStore(STORE * s) { store = s; }
61     void                SetTraffcounter(TRAFFCOUNTER *) {}
62     void                SetStgSettings(const SETTINGS * s);
63     void                SetSettings(const MODULE_SETTINGS & s) { settings = s; }
64     int                 ParseSettings();
65
66     int                 Start();
67     int                 Stop();
68     int                 Reload() { return 0; }
69     bool                IsRunning() { return running && !stopped; }
70
71     const std::string & GetStrError() const { return errorStr; }
72     const std::string   GetVersion() const { return RPC_CONFIG_VERSION; }
73     uint16_t            GetStartPosition() const { return 220; }
74     uint16_t            GetStopPosition() const { return 220; }
75
76     bool                GetAdminInfo(const std::string & cookie,
77                                      ADMIN_INFO * info);
78     bool                CheckAdmin(const std::string & login,
79                                    const std::string & password,
80                                    std::string * cookie);
81     bool                LogoutAdmin(const std::string & cookie);
82
83 private:
84     static void *           Run(void *);
85     std::string             GetCookie() const;
86     void                    InitiateRegistry();
87
88     mutable std::string     errorStr;
89     RPC_CONFIG_SETTINGS     rpcConfigSettings;
90     USERS *                 users;
91     ADMINS *                admins;
92     TARIFFS *               tariffs;
93     STORE *                 store;
94     MODULE_SETTINGS         settings;
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     size_t                  dayFee;
103     std::vector<std::string> dirNames;
104 };
105
106 #endif