diff options
| author | Sadie Powell <sadie@witchery.services> | 2025-03-10 13:03:29 +0000 |
|---|---|---|
| committer | Sadie Powell <sadie@witchery.services> | 2025-03-10 13:03:29 +0000 |
| commit | 64fd5a862a26687ddb436a1785d4d000c63e350d (patch) | |
| tree | 7f64d590322cfdfb74258b384978dc24aa8fb8c4 /modules | |
| parent | 0ff170c6716b5aa4c5d7a03a83c1513f7d990234 (diff) | |
Add an XML-RPC method to rpc_system for debugging RPC responses.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/rpc/rpc_system.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/modules/rpc/rpc_system.cpp b/modules/rpc/rpc_system.cpp index d1f49a1aa..ede4b770e 100644 --- a/modules/rpc/rpc_system.cpp +++ b/modules/rpc/rpc_system.cpp @@ -15,6 +15,66 @@ // * system.methodHelp // * system.methodSignature +class AnopeDebugTypesRPCEvent final + : public RPC::Event +{ +public: + AnopeDebugTypesRPCEvent() + : RPC::Event("anope.debugTypes") + { + } + + bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override + { + // For both the map type and array type we test that we can handle: + // + // * Arrays + // * Maps + // * Strings + // * Null + // * Boolean true + // * Boolean false + // * Doubles + // * Signed integer that can fit into a 32-bit type. + // * Signed integer that needs a 64-bit type (not supported by some + // XML-RPC clients). + // * Unsigned integer that can fit into a 32-bit signed type. + // * Unsigned integer that needs a 64-bit signed type (not supported by + // some XML-RPC clients). + // * Unsigned integer that needs a 64-bit unsigned type (converted to a + // string when using the xmlrpc module). + + auto &root = request.Root(); + + auto &array = root.ReplyArray("array"); + array.ReplyArray(); + array.ReplyMap(); + array.Reply("string"); + array.Reply(nullptr); + array.Reply(true); + array.Reply(false); + array.Reply(42.42); + array.Reply(int64_t(42)); + array.Reply(int64_t(INT32_MAX) + 42); + array.Reply(uint64_t(42)); + array.Reply(uint64_t(INT32_MAX) + 42); + array.Reply(uint64_t(INT64_MAX) + 42); + + root.ReplyMap("map"); + root.Reply("string", "string"); + root.Reply("null", nullptr); + root.Reply("true", true); + root.Reply("false", false); + root.Reply("double", 42.42); + root.Reply("int-small", int64_t(42)); + root.Reply("int-large", int64_t(INT32_MAX) + 42); + root.Reply("uint-small", uint64_t(42)); + root.Reply("uint-medium", uint64_t(INT32_MAX) + 42); + root.Reply("uint-large", uint64_t(INT64_MAX) + 42); + + return true; + } +}; class SystemListMethodsRPCEvent final : public RPC::Event @@ -39,6 +99,7 @@ class ModuleRPCSystem final { private: ServiceReference<RPC::ServiceInterface> rpc; + AnopeDebugTypesRPCEvent anopedebugtypesrpcevent; SystemListMethodsRPCEvent systemlistmethodsrpcevent; public: @@ -49,6 +110,9 @@ public: if (!rpc) throw ModuleException("Unable to find RPC interface, is jsonrpc/xmlrpc loaded?"); +#if DEBUG_BUILD + rpc->Register(&anopedebugtypesrpcevent); +#endif rpc->Register(&systemlistmethodsrpcevent); } @@ -57,6 +121,9 @@ public: if (!rpc) return; +#if DEBUG_BUILD + rpc->Unregister(&anopedebugtypesrpcevent); +#endif rpc->Unregister(&systemlistmethodsrpcevent); } }; |
