1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-07 06:23:13 +02:00

JSON-RPC: Use proper error response with error codes according to

the official specification (one of JSON_RPC_ERROR_*).

Add proper rpc_error() and rpc_error_fmt()

Don't steal reference in rpc_response().
This commit is contained in:
Bram Matthys
2022-06-06 17:18:22 +02:00
parent 4cd520d327
commit 61ba3727df
6 changed files with 84 additions and 15 deletions
+4 -2
View File
@@ -839,7 +839,8 @@ extern MODVAR int (*unreal_match_iplist)(Client *client, NameList *l);
extern MODVAR void (*webserver_send_response)(Client *client, int status, char *msg);
extern MODVAR void (*webserver_close_client)(Client *client);
extern MODVAR void (*rpc_response)(Client *client, json_t *request, json_t *result);
extern MODVAR void (*rpc_error)(Client *client, json_t *request, const char *msg);
extern MODVAR void (*rpc_error)(Client *client, json_t *request, int error_code, const char *error_message);
extern MODVAR void (*rpc_error_fmt)(Client *client, json_t *request, int error_code, FORMAT_STRING(const char *fmt), ...) __attribute__((format(printf,4,5)));
/* /Efuncs */
/* TLS functions */
@@ -879,7 +880,8 @@ extern int make_oper_default_handler(Client *client, const char *operblock_name,
extern void webserver_send_response_default_handler(Client *client, int status, char *msg);
extern void webserver_close_client_default_handler(Client *client);
extern void rpc_response_default_handler(Client *client, json_t *request, json_t *result);
extern void rpc_error_default_handler(Client *client, json_t *request, const char *msg);
extern void rpc_error_default_handler(Client *client, json_t *request, int error_code, const char *error_message);
extern void rpc_error_fmt_default_handler(Client *client, json_t *request, int error_code, const char *fmt, ...);
/* End of default handlers for efunctions */
extern MODVAR MOTDFile opermotd, svsmotd, motd, botmotd, smotd, rules;
+1
View File
@@ -2481,6 +2481,7 @@ enum EfunctionType {
EFUNC_WEBSERVER_CLOSE_CLIENT,
EFUNC_RPC_RESPONSE,
EFUNC_RPC_ERROR,
EFUNC_RPC_ERROR_FMT,
};
/* Module flags */
+7
View File
@@ -2300,6 +2300,13 @@ typedef enum WhoisConfigDetails {
#define UNRL_STRIP_LOW_ASCII 0x1 /**< Strip all ASCII < 32 (control codes) */
#define UNRL_STRIP_KEEP_LF 0x2 /**< Do not strip LF (line feed, \n) */
/* JSON RPC API Errors, according to jsonrpc.org spec */
#define JSON_RPC_ERROR_PARSE_ERROR -32700
#define JSON_RPC_ERROR_INVALID_REQUEST -32600
#define JSON_RPC_ERROR_METHOD_NOT_FOUND -32601
#define JSON_RPC_ERROR_INVALID_PARAMS -32602
#define JSON_RPC_ERROR_INTERNAL_ERROR -32603
#endif /* __struct_include__ */
#include "dynconf.h"