summaryrefslogtreecommitdiff
path: root/modules/rpc
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-03-10 13:03:29 +0000
committerSadie Powell <sadie@witchery.services>2025-03-10 13:03:29 +0000
commit64fd5a862a26687ddb436a1785d4d000c63e350d (patch)
tree7f64d590322cfdfb74258b384978dc24aa8fb8c4 /modules/rpc
parent0ff170c6716b5aa4c5d7a03a83c1513f7d990234 (diff)
Add an XML-RPC method to rpc_system for debugging RPC responses.
Diffstat (limited to 'modules/rpc')
-rw-r--r--modules/rpc/rpc_system.cpp67
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);
}
};