diff options
author | Sadie Powell <sadie@witchery.services> | 2025-02-24 03:39:50 +0000 |
---|---|---|
committer | Sadie Powell <sadie@witchery.services> | 2025-02-24 03:59:52 +0000 |
commit | 801a748e256cb7c4952969103f2f2eaf5ee36552 (patch) | |
tree | 2dae96409362ee42b2591128a1ba42896226ecd2 /modules/rpc/rpc_system.cpp | |
parent | a111b40560bf305653b07d8f7289484793a32588 (diff) |
Add the system.listMethods RPC method.
Still to implement:
- system.getCapabilities
- system.methodHelp
- system.methodSignature
Diffstat (limited to 'modules/rpc/rpc_system.cpp')
-rw-r--r-- | modules/rpc/rpc_system.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/modules/rpc/rpc_system.cpp b/modules/rpc/rpc_system.cpp new file mode 100644 index 000000000..d1f49a1aa --- /dev/null +++ b/modules/rpc/rpc_system.cpp @@ -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) |