3 #include "stg/plugin.h"
4 #include "stg/admin_conf.h"
5 #include "stg/module_settings.h"
6 #include "stg/logger.h"
8 #include <xmlrpc-c/base.hpp>
9 #include <xmlrpc-c/registry.hpp>
10 #include <xmlrpc-c/server_abyss.hpp>
18 #pragma GCC diagnostic push
19 #pragma GCC diagnostic ignored "-Wshadow"
20 #include <jthread.hpp>
21 #pragma GCC diagnostic pop
23 #define RPC_CONFIG_VERSION "Stargazer RPC v. 0.2"
35 class RPC_CONFIG_SETTINGS
38 RPC_CONFIG_SETTINGS();
39 virtual ~RPC_CONFIG_SETTINGS() {}
40 const std::string & GetStrError() const { return errorStr; }
41 int ParseSettings(const STG::ModuleSettings & s);
42 uint16_t GetPort() const { return port; }
43 double GetCookieTimeout() const { return cookieTimeout; }
61 STG::Priv priviledges;
64 class RPC_CONFIG : public STG::Plugin
68 ~RPC_CONFIG() override;
70 void SetUsers(STG::Users * u) override { users = u; }
71 void SetTariffs(STG::Tariffs * t) override { tariffs = t; }
72 void SetAdmins(STG::Admins * a) override { admins = a; }
73 void SetStore(STG::Store * s) override { store = s; }
74 void SetStgSettings(const STG::Settings * s) override;
75 void SetSettings(const STG::ModuleSettings & s) override { settings = s; }
76 int ParseSettings() override;
80 int Reload(const STG::ModuleSettings & /*ms*/) override { return 0; }
81 bool IsRunning() override { return m_thread.joinable() && !stopped; }
83 const std::string & GetStrError() const override { return errorStr; }
84 std::string GetVersion() const override { return RPC_CONFIG_VERSION; }
85 uint16_t GetStartPosition() const override { return 20; }
86 uint16_t GetStopPosition() const override { return 20; }
88 bool GetAdminInfo(const std::string & cookie,
90 bool CheckAdmin(const std::string & login,
91 const std::string & password,
92 std::string * cookie);
93 bool LogoutAdmin(const std::string & cookie);
96 RPC_CONFIG(const RPC_CONFIG & rvalue);
97 RPC_CONFIG & operator=(const RPC_CONFIG & rvalue);
99 void Run(std::stop_token token);
100 std::string GetCookie() const;
101 void InitiateRegistry();
103 mutable std::string errorStr;
104 RPC_CONFIG_SETTINGS rpcConfigSettings;
106 STG::Admins * admins;
107 STG::Tariffs * tariffs;
109 STG::ModuleSettings settings;
111 xmlrpc_c::registry rpcRegistry;
112 xmlrpc_c::serverAbyss * rpcServer;
114 std::jthread m_thread;
115 std::map<std::string,
118 std::vector<std::string> dirNames;
119 STG::PluginLogger logger;