mirror of
https://github.com/anope/anope.git
synced 2026-06-26 07:36:39 +02:00
Add the system.listMethods RPC method.
Still to implement: - system.getCapabilities - system.methodHelp - system.methodSignature
This commit is contained in:
@@ -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