mirror of
https://github.com/anope/anope.git
synced 2026-06-12 19:14:47 +02:00
Add the system.listMethods RPC method.
Still to implement: - system.getCapabilities - system.methodHelp - system.methodSignature
This commit is contained in:
@@ -824,3 +824,12 @@ module { name = "sasl" }
|
||||
* Requires xmlrpc.
|
||||
*/
|
||||
#module { name = "rpc_main" }
|
||||
|
||||
/*
|
||||
* rpc_system
|
||||
*
|
||||
* Adds support for the system.listMethods RPC method.
|
||||
*
|
||||
* Requires either the jsonrpc or xmlrpc module.
|
||||
*/
|
||||
#module { name = "rpc_system" }
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace RPC
|
||||
class ServiceInterface;
|
||||
class Value;
|
||||
|
||||
/** Represents a list of registered events. */
|
||||
using Events = Anope::map<Event *>;
|
||||
|
||||
/** Represents possible types of RPC value. */
|
||||
using ValueUnion = std::variant<Array, Map, Anope::string, std::nullptr_t, bool, double, int64_t, uint64_t>;
|
||||
|
||||
@@ -194,6 +197,8 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual const Events &GetEvents() = 0;
|
||||
|
||||
virtual bool Register(Event *event) = 0;
|
||||
|
||||
virtual bool Unregister(Event *event) = 0;
|
||||
|
||||
@@ -23,7 +23,7 @@ class MyXMLRPCServiceInterface final
|
||||
, public HTTPPage
|
||||
{
|
||||
private:
|
||||
Anope::map<RPC::Event *> events;
|
||||
RPC::Events events;
|
||||
|
||||
static void SendError(HTTPReply &reply, xmlrpc_env &env)
|
||||
{
|
||||
@@ -69,6 +69,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
const RPC::Events &GetEvents() override
|
||||
{
|
||||
return events;
|
||||
}
|
||||
|
||||
bool Register(RPC::Event *event) override
|
||||
{
|
||||
return this->events.emplace(event->GetEvent(), event).second;
|
||||
|
||||
@@ -26,7 +26,7 @@ class MyJSONRPCServiceInterface final
|
||||
, public HTTPPage
|
||||
{
|
||||
private:
|
||||
Anope::map<RPC::Event *> events;
|
||||
RPC::Events events;
|
||||
|
||||
static void SendError(HTTPReply &reply, int64_t code, const Anope::string &message, const Anope::string &id)
|
||||
{
|
||||
@@ -86,6 +86,11 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
const RPC::Events &GetEvents() override
|
||||
{
|
||||
return events;
|
||||
}
|
||||
|
||||
bool Register(RPC::Event *event) override
|
||||
{
|
||||
return this->events.emplace(event->GetEvent(), event).second;
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
*
|
||||
* (C) 2010-2025 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
*
|
||||
* Please read COPYING and README for further details.
|
||||
*/
|
||||
|
||||
#include "module.h"
|
||||
#include "modules/rpc.h"
|
||||
|
||||
// TODO:
|
||||
//
|
||||
// * system.getCapabilities
|
||||
// * system.methodHelp
|
||||
// * system.methodSignature
|
||||
|
||||
|
||||
class SystemListMethodsRPCEvent final
|
||||
: public RPC::Event
|
||||
{
|
||||
public:
|
||||
SystemListMethodsRPCEvent()
|
||||
: RPC::Event("system.listMethods")
|
||||
{
|
||||
}
|
||||
|
||||
bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
|
||||
{
|
||||
auto &root = request.Root<RPC::Array>();
|
||||
for (const auto &[event, _] : iface->GetEvents())
|
||||
root.Reply(event);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ModuleRPCSystem final
|
||||
: public Module
|
||||
{
|
||||
private:
|
||||
ServiceReference<RPC::ServiceInterface> rpc;
|
||||
SystemListMethodsRPCEvent systemlistmethodsrpcevent;
|
||||
|
||||
public:
|
||||
ModuleRPCSystem(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, EXTRA | VENDOR)
|
||||
, rpc("RPCServiceInterface", "rpc")
|
||||
{
|
||||
if (!rpc)
|
||||
throw ModuleException("Unable to find RPC interface, is jsonrpc/xmlrpc loaded?");
|
||||
|
||||
rpc->Register(&systemlistmethodsrpcevent);
|
||||
}
|
||||
|
||||
~ModuleRPCSystem() override
|
||||
{
|
||||
if (!rpc)
|
||||
return;
|
||||
|
||||
rpc->Unregister(&systemlistmethodsrpcevent);
|
||||
}
|
||||
};
|
||||
|
||||
MODULE_INIT(ModuleRPCSystem)
|
||||
Reference in New Issue
Block a user