summaryrefslogtreecommitdiff
path: root/modules/rpc
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-02-25 23:13:54 +0000
committerSadie Powell <sadie@witchery.services>2025-02-25 23:13:54 +0000
commit752f5e269e99acdd0c2795a2c2eedc44875d5fed (patch)
treeb4b4ef22c9b5d8407612887b89051f9270f7c780 /modules/rpc
parentbb3e124bdb07cc12d51a0483b6cf913e4af58b8a (diff)
Deduplicate RPC parameter count checks.
Diffstat (limited to 'modules/rpc')
-rw-r--r--modules/rpc/jsonrpc.cpp11
-rw-r--r--modules/rpc/rpc_data.cpp30
2 files changed, 13 insertions, 28 deletions
diff --git a/modules/rpc/jsonrpc.cpp b/modules/rpc/jsonrpc.cpp
index fc4c40e83..1e7315984 100644
--- a/modules/rpc/jsonrpc.cpp
+++ b/modules/rpc/jsonrpc.cpp
@@ -150,7 +150,16 @@ public:
return true;
}
- if (!event->second->Run(this, client, request))
+ auto *eh = event->second;
+ if (request.data.size() < eh->GetMinParams())
+ {
+ auto error = Anope::printf("Not enough parameters (given %zu, expected %zu)",
+ request.data.size(), eh->GetMinParams());
+ SendError(reply, RPC::ERR_INVALID_PARAMS, error, id);
+ return true;
+ }
+
+ if (!eh->Run(this, client, request))
return false;
this->Reply(request);
diff --git a/modules/rpc/rpc_data.cpp b/modules/rpc/rpc_data.cpp
index 670b4c57e..059468fa0 100644
--- a/modules/rpc/rpc_data.cpp
+++ b/modules/rpc/rpc_data.cpp
@@ -38,18 +38,12 @@ class AnopeChannelRPCEvent final
{
public:
AnopeChannelRPCEvent()
- : RPC::Event("anope.channel")
+ : RPC::Event("anope.channel", 1)
{
}
bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
{
- if (request.data.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Not enough parameters");
- return true;
- }
-
auto *c = Channel::Find(request.data[0]);
if (!c)
{
@@ -137,18 +131,12 @@ class AnopeOperRPCEvent final
{
public:
AnopeOperRPCEvent()
- : RPC::Event("anope.oper")
+ : RPC::Event("anope.oper", 1)
{
}
bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
{
- if (request.data.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Not enough parameters");
- return true;
- }
-
auto *o = Oper::Find(request.data[0]);
if (!o)
{
@@ -230,12 +218,6 @@ public:
bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
{
- if (request.data.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Not enough parameters");
- return true;
- }
-
auto *s = Server::Find(request.data[0]);
if (!s)
{
@@ -291,18 +273,12 @@ class AnopeUserRPCEvent final
{
public:
AnopeUserRPCEvent()
- : RPC::Event("anope.user")
+ : RPC::Event("anope.user", 1)
{
}
bool Run(RPC::ServiceInterface *iface, HTTPClient *client, RPC::Request &request) override
{
- if (request.data.empty())
- {
- request.Error(RPC::ERR_INVALID_PARAMS, "Not enough parameters");
- return true;
- }
-
auto *u = User::Find(request.data[0]);
if (!u)
{