summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/RPC/jsonrpc.php4
-rw-r--r--include/modules/rpc.h2
-rw-r--r--modules/extra/xmlrpc.cpp10
-rw-r--r--modules/rpc/jsonrpc.cpp15
-rw-r--r--modules/rpc/rpc_main.cpp40
5 files changed, 40 insertions, 31 deletions
diff --git a/docs/RPC/jsonrpc.php b/docs/RPC/jsonrpc.php
index dda1412b1..a4413b35c 100644
--- a/docs/RPC/jsonrpc.php
+++ b/docs/RPC/jsonrpc.php
@@ -90,8 +90,8 @@ class AnopeRPC
{
$ret = $this->run("checkAuthentication", [$account, $pass]);
- if ($ret && array_key_exists("account", $ret)) {
- return $ret["account"];
+ if ($ret && array_key_exists("result", $ret) && array_key_exists("account", $ret["result"])) {
+ return $ret["result"]["account"];
}
return null;
diff --git a/include/modules/rpc.h b/include/modules/rpc.h
index f7e361d5c..092f98f59 100644
--- a/include/modules/rpc.h
+++ b/include/modules/rpc.h
@@ -60,7 +60,7 @@ public:
const auto &GetEvent() const { return event; }
- virtual void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) = 0;
+ virtual bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) = 0;
};
class RPCServiceInterface
diff --git a/modules/extra/xmlrpc.cpp b/modules/extra/xmlrpc.cpp
index ca6856fd2..63ed55433 100644
--- a/modules/extra/xmlrpc.cpp
+++ b/modules/extra/xmlrpc.cpp
@@ -118,14 +118,8 @@ public:
}
xmlrpc_DECREF(params);
- event->second->Run(this, client, request);
-
- if (request.GetError())
- {
- xmlrpc_env_set_fault(&env, request.GetError()->first, request.GetError()->second.c_str());
- SendError(reply, env);
- return true;
- }
+ if (!event->second->Run(this, client, request))
+ return false;
this->Reply(request);
return true;
diff --git a/modules/rpc/jsonrpc.cpp b/modules/rpc/jsonrpc.cpp
index 8c16f4cc8..cd24dc55c 100644
--- a/modules/rpc/jsonrpc.cpp
+++ b/modules/rpc/jsonrpc.cpp
@@ -122,13 +122,8 @@ public:
return true;
}
- event->second->Run(this, client, request);
-
- if (request.GetError())
- {
- SendError(reply, request.GetError()->first, request.GetError()->second, id);
- return true;
- }
+ if (!event->second->Run(this, client, request))
+ return false;
this->Reply(request);
return true;
@@ -136,6 +131,12 @@ public:
void Reply(RPCRequest &request) override
{
+ if (request.GetError())
+ {
+ SendError(request.reply, request.GetError()->first, request.GetError()->second, request.id);
+ return;
+ }
+
// {"jsonrpc": "2.0", "method": "update", "params": [1,2,3,4,5]}
auto* doc = yyjson_mut_doc_new(nullptr);
diff --git a/modules/rpc/rpc_main.cpp b/modules/rpc/rpc_main.cpp
index b5c263be1..a634e783f 100644
--- a/modules/rpc/rpc_main.cpp
+++ b/modules/rpc/rpc_main.cpp
@@ -66,7 +66,7 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
Anope::string service = request.data.size() > 0 ? request.data[0] : "";
Anope::string user = request.data.size() > 1 ? request.data[1] : "";
@@ -75,14 +75,14 @@ public:
if (service.empty() || user.empty() || command.empty())
{
request.Error(-32602, "Invalid parameters");
- return;
+ return true;
}
BotInfo *bi = BotInfo::Find(service, true);
if (!bi)
{
request.Error(-32000, "Invalid service");
- return;
+ return true;
}
NickAlias *na = NickAlias::Find(user);
@@ -109,6 +109,8 @@ public:
if (!out.empty())
request.Reply("return", out);
+
+ return true;
}
};
@@ -121,7 +123,7 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
Anope::string username = request.data.size() > 0 ? request.data[0] : "";
Anope::string password = request.data.size() > 1 ? request.data[1] : "";
@@ -129,12 +131,13 @@ public:
if (username.empty() || password.empty())
{
request.Error(-32602, "Invalid parameters");
- return;
+ return true;
}
auto *req = new RPCIdentifyRequest(me, request, client, iface, username, password);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
+ return false;
}
};
@@ -147,7 +150,7 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
request.Reply("uptime", Anope::ToString(Anope::CurTime - Anope::StartTime));
request.Reply("uplinkname", Me->GetLinks().front()->GetName());
@@ -162,6 +165,7 @@ public:
request.Reply("usercount", Anope::ToString(UserListByNick.size()));
request.Reply("maxusercount", Anope::ToString(MaxUserCount));
request.Reply("channelcount", Anope::ToString(ChannelList.size()));
+ return true;
}
};
@@ -174,10 +178,13 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
if (request.data.empty())
- return;
+ {
+ request.Error(-32602, "Invalid parameters");
+ return true;
+ }
Channel *c = Channel::Find(request.data[0]);
@@ -221,6 +228,7 @@ public:
request.Reply("topictime", Anope::ToString(c->topic_time));
request.Reply("topicts", Anope::ToString(c->topic_ts));
}
+ return true;
}
};
@@ -233,10 +241,13 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
if (request.data.empty())
- return;
+ {
+ request.Error(-32602, "Invalid parameters");
+ return true;
+ }
User *u = User::Find(request.data[0]);
@@ -273,6 +284,7 @@ public:
request.Reply("channels", channels);
}
}
+ return true;
}
};
@@ -285,7 +297,7 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
for (auto *ot : Config->MyOperTypes)
{
@@ -296,6 +308,7 @@ public:
perms += " " + command;
request.Reply(ot->GetName(), perms);
}
+ return true;
}
};
@@ -308,7 +321,7 @@ public:
{
}
- void Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
+ bool Run(RPCServiceInterface *iface, HTTPClient *client, RPCRequest &request) override
{
Anope::string from = request.data.size() > 0 ? request.data[0] : "";
Anope::string to = request.data.size() > 1 ? request.data[1] : "";
@@ -320,10 +333,11 @@ public:
if (!bi || !u || message.empty())
{
request.Error(-32602, "Invalid parameters");
- return;
+ return true;
}
u->SendMessage(bi, message);
+ return true;
}
};