diff options
| author | Sadie Powell <sadie@witchery.services> | 2025-02-13 01:28:28 +0000 |
|---|---|---|
| committer | Sadie Powell <sadie@witchery.services> | 2025-02-13 01:45:20 +0000 |
| commit | f8c1b8f4f9bcb06242aa7d7360ea610764565c75 (patch) | |
| tree | 84eed97fb3781ff3b8c0ecbbd8f304cc3e7997ff /modules | |
| parent | eaa00c7c9e38f7f5633544a767876f2f6d57185d (diff) | |
Rework the RPC modules in preparation for the new JSON-RPC module.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/rpc/rpc_main.cpp (renamed from modules/xmlrpc_main.cpp) | 58 | ||||
| -rw-r--r-- | modules/rpc/xmlrpc.cpp (renamed from modules/xmlrpc.cpp) | 20 |
2 files changed, 39 insertions, 39 deletions
diff --git a/modules/xmlrpc_main.cpp b/modules/rpc/rpc_main.cpp index 3cfec74e8..4a87d9e05 100644 --- a/modules/xmlrpc_main.cpp +++ b/modules/rpc/rpc_main.cpp @@ -7,21 +7,21 @@ */ #include "module.h" -#include "modules/xmlrpc.h" +#include "modules/rpc.h" static Module *me; -class XMLRPCIdentifyRequest final +class RPCIdentifyRequest final : public IdentifyRequest { - XMLRPCRequest request; + RPCRequest request; HTTPReply repl; /* Request holds a reference to the HTTPReply, because we might exist long enough to invalidate it we'll copy it here then reset the reference before we use it */ Reference<HTTPClient> client; - Reference<XMLRPCServiceInterface> xinterface; + Reference<RPCServiceInterface> xinterface; public: - XMLRPCIdentifyRequest(Module *m, XMLRPCRequest &req, HTTPClient *c, XMLRPCServiceInterface *iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { } + RPCIdentifyRequest(Module *m, RPCRequest &req, HTTPClient *c, RPCServiceInterface *iface, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), request(req), repl(request.r), client(c), xinterface(iface) { } void OnSuccess() override { @@ -51,11 +51,11 @@ public: } }; -class MyXMLRPCEvent final - : public XMLRPCEvent +class MyRPCEvent final + : public RPCEvent { public: - bool Run(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) override + bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override { if (request.name == "command") this->DoCommand(iface, client, request); @@ -76,7 +76,7 @@ public: } private: - void DoCommand(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + void DoCommand(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { Anope::string service = request.data.size() > 0 ? request.data[0] : ""; Anope::string user = request.data.size() > 1 ? request.data[1] : ""; @@ -97,12 +97,12 @@ private: Anope::string out; - struct XMLRPCommandReply final + struct RPCommandReply final : CommandReply { Anope::string &str; - XMLRPCommandReply(Anope::string &s) : str(s) { } + RPCommandReply(Anope::string &s) : str(s) { } void SendMessage(BotInfo *source, const Anope::string &msg) override { @@ -121,7 +121,7 @@ private: } } - static bool DoCheckAuthentication(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static bool DoCheckAuthentication(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { Anope::string username = request.data.size() > 0 ? request.data[0] : ""; Anope::string password = request.data.size() > 1 ? request.data[1] : ""; @@ -130,7 +130,7 @@ private: request.reply("error", "Invalid parameters"); else { - auto *req = new XMLRPCIdentifyRequest(me, request, client, iface, username, password); + auto *req = new RPCIdentifyRequest(me, request, client, iface, username, password); FOREACH_MOD(OnCheckAuthentication, (NULL, req)); req->Dispatch(); return false; @@ -139,7 +139,7 @@ private: return true; } - static void DoStats(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static void DoStats(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { request.reply("uptime", Anope::ToString(Anope::CurTime - Anope::StartTime)); request.reply("uplinkname", Me->GetLinks().front()->GetName()); @@ -156,7 +156,7 @@ private: request.reply("channelcount", Anope::ToString(ChannelList.size())); } - static void DoChannel(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static void DoChannel(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { if (request.data.empty()) return; @@ -205,7 +205,7 @@ private: } } - static void DoUser(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static void DoUser(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { if (request.data.empty()) return; @@ -247,7 +247,7 @@ private: } } - static void DoOperType(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static void DoOperType(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { for (auto *ot : Config->MyOperTypes) { @@ -260,7 +260,7 @@ private: } } - static void DoNotice(XMLRPCServiceInterface *iface, HTTPClient *client, XMLRPCRequest &request) + static void DoNotice(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) { Anope::string from = request.data.size() > 0 ? request.data[0] : ""; Anope::string to = request.data.size() > 1 ? request.data[1] : ""; @@ -278,29 +278,29 @@ private: } }; -class ModuleXMLRPCMain final +class ModuleRPCMain final : public Module { - ServiceReference<XMLRPCServiceInterface> xmlrpc; + ServiceReference<RPCServiceInterface> rpc; - MyXMLRPCEvent stats; + MyRPCEvent stats; public: - ModuleXMLRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), xmlrpc("XMLRPCServiceInterface", "xmlrpc") + ModuleRPCMain(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), rpc("RPCServiceInterface", "rpc") { me = this; - if (!xmlrpc) - throw ModuleException("Unable to find xmlrpc reference, is xmlrpc loaded?"); + if (!rpc) + throw ModuleException("Unable to find RPC interface, is xmlrpc loaded?"); - xmlrpc->Register(&stats); + rpc->Register(&stats); } - ~ModuleXMLRPCMain() override + ~ModuleRPCMain() override { - if (xmlrpc) - xmlrpc->Unregister(&stats); + if (rpc) + rpc->Unregister(&stats); } }; -MODULE_INIT(ModuleXMLRPCMain) +MODULE_INIT(ModuleRPCMain) diff --git a/modules/xmlrpc.cpp b/modules/rpc/xmlrpc.cpp index 480c248bf..f1db6efba 100644 --- a/modules/xmlrpc.cpp +++ b/modules/rpc/xmlrpc.cpp @@ -7,7 +7,7 @@ */ #include "module.h" -#include "modules/xmlrpc.h" +#include "modules/rpc.h" #include "modules/httpd.h" static struct special_chars final @@ -33,22 +33,22 @@ special[] = { }; class MyXMLRPCServiceInterface final - : public XMLRPCServiceInterface + : public RPCServiceInterface , public HTTPPage { - std::deque<XMLRPCEvent *> events; + std::deque<RPCEvent *> events; public: - MyXMLRPCServiceInterface(Module *creator, const Anope::string &sname) : XMLRPCServiceInterface(creator, sname), HTTPPage("/xmlrpc", "text/xml") { } + MyXMLRPCServiceInterface(Module *creator, const Anope::string &sname) : RPCServiceInterface(creator, sname), HTTPPage("/xmlrpc", "text/xml") { } - void Register(XMLRPCEvent *event) override + void Register(RPCEvent *event) override { this->events.push_back(event); } - void Unregister(XMLRPCEvent *event) override + void Unregister(RPCEvent *event) override { - std::deque<XMLRPCEvent *>::iterator it = std::find(this->events.begin(), this->events.end(), event); + std::deque<RPCEvent *>::iterator it = std::find(this->events.begin(), this->events.end(), event); if (it != this->events.end()) this->events.erase(it); @@ -150,7 +150,7 @@ public: bool OnRequest(HTTPProvider *provider, const Anope::string &page_name, HTTPClient *client, HTTPMessage &message, HTTPReply &reply) override { Anope::string content = message.content, tname, data; - XMLRPCRequest request(reply); + RPCRequest request(reply); while (GetData(content, tname, data)) { @@ -182,7 +182,7 @@ public: return true; } - void Reply(XMLRPCRequest &request) override + void Reply(RPCRequest &request) override { if (!request.id.empty()) request.reply("id", request.id); @@ -204,7 +204,7 @@ public: MyXMLRPCServiceInterface xmlrpcinterface; ModuleXMLRPC(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR), - xmlrpcinterface(this, "xmlrpc") + xmlrpcinterface(this, "rpc") { } |
