diff options
-rw-r--r-- | include/modules/rpc.h | 13 | ||||
-rw-r--r-- | modules/extra/xmlrpc.cpp | 4 | ||||
-rw-r--r-- | modules/rpc/jsonrpc.cpp | 8 | ||||
-rw-r--r-- | modules/rpc/rpc_main.cpp | 10 |
4 files changed, 24 insertions, 11 deletions
diff --git a/include/modules/rpc.h b/include/modules/rpc.h index 35db305c7..68523e5fa 100644 --- a/include/modules/rpc.h +++ b/include/modules/rpc.h @@ -12,6 +12,19 @@ #include <variant> +namespace RPC +{ + /** Represents standard RPC errors from the JSON-RPC and XML-RPC specifications. */ + enum Error + : int64_t + { + ERR_PARSE_ERROR = -32700, + ERR_INVALID_REQUEST = -32600, + ERR_METHOD_NOT_FOUND = -32601, + ERR_INVALID_PARAMS = -32602, + }; +} + class RPCBlock { public: diff --git a/modules/extra/xmlrpc.cpp b/modules/extra/xmlrpc.cpp index bc23621d0..cd51f5889 100644 --- a/modules/extra/xmlrpc.cpp +++ b/modules/extra/xmlrpc.cpp @@ -135,7 +135,7 @@ public: auto event = this->events.find(request.name); if (event == this->events.end()) { - xmlrpc_env_set_fault(&env, -32601, "Method not found"); + xmlrpc_env_set_fault(&env, RPC::ERR_METHOD_NOT_FOUND, "Method not found"); SendError(reply, env); return true; } @@ -150,7 +150,7 @@ public: if (xmlrpc_value_type(value) != XMLRPC_TYPE_STRING) { // TODO: error; - xmlrpc_env_set_fault(&env, 0, "Anope XML-RPC only supports strings"); + xmlrpc_env_set_fault(&env, RPC::ERR_INVALID_REQUEST, "Anope XML-RPC only supports strings"); SendError(reply, env); xmlrpc_DECREF(value); xmlrpc_DECREF(params); diff --git a/modules/rpc/jsonrpc.cpp b/modules/rpc/jsonrpc.cpp index 1442115b7..ab7617c4d 100644 --- a/modules/rpc/jsonrpc.cpp +++ b/modules/rpc/jsonrpc.cpp @@ -123,7 +123,7 @@ public: auto *doc = yyjson_read(message.content.c_str(), message.content.length(), YYJSON_READ_ALLOW_TRAILING_COMMAS | YYJSON_READ_ALLOW_INVALID_UNICODE); if (!doc) { - SendError(reply, -32700, "JSON parse error", ""); + SendError(reply, RPC::ERR_PARSE_ERROR, "JSON parse error", ""); return true; } @@ -132,7 +132,7 @@ public: { // TODO: handle an array of JSON-RPC requests yyjson_doc_free(doc); - SendError(reply, -32600, "Wrong JSON root element", ""); + SendError(reply, RPC::ERR_INVALID_REQUEST, "Wrong JSON root element", ""); return true; } @@ -141,7 +141,7 @@ public: if (!jsonrpc.empty() && jsonrpc != "2.0") { yyjson_doc_free(doc); - SendError(reply, -32600, "Unsupported JSON-RPC version", id); + SendError(reply, RPC::ERR_INVALID_REQUEST, "Unsupported JSON-RPC version", id); return true; } @@ -163,7 +163,7 @@ public: auto event = this->events.find(request.name); if (event == this->events.end()) { - SendError(reply, -32601, "Method not found", id); + SendError(reply, RPC::ERR_METHOD_NOT_FOUND, "Method not found", id); return true; } diff --git a/modules/rpc/rpc_main.cpp b/modules/rpc/rpc_main.cpp index 0cf8b8b0b..012010fcc 100644 --- a/modules/rpc/rpc_main.cpp +++ b/modules/rpc/rpc_main.cpp @@ -74,7 +74,7 @@ public: if (service.empty() || user.empty() || command.empty()) { - request.Error(-32602, "Invalid parameters"); + request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters"); return true; } @@ -130,7 +130,7 @@ public: if (username.empty() || password.empty()) { - request.Error(-32602, "Invalid parameters"); + request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters"); return true; } @@ -182,7 +182,7 @@ public: { if (request.data.empty()) { - request.Error(-32602, "Invalid parameters"); + request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters"); return true; } @@ -248,7 +248,7 @@ public: { if (request.data.empty()) { - request.Error(-32602, "Invalid parameters"); + request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters"); return true; } @@ -335,7 +335,7 @@ public: if (!bi || !u || message.empty()) { - request.Error(-32602, "Invalid parameters"); + request.Error(RPC::ERR_INVALID_PARAMS, "Invalid parameters"); return true; } |