From e4f3e11a8e22db6fca08dba4290db39a2e1c0f4b Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 2 Nov 2017 10:52:53 +0100 Subject: [SERVER] Add --errormsg to only serve HTTP-JSON error code This could have been an external tool, but this didn't add much code and has the benefit of honoring the config file for port and bind address. --- src/server/rpc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/server/rpc.c') diff --git a/src/server/rpc.c b/src/server/rpc.c index 92aa249..ff4b0ab 100644 --- a/src/server/rpc.c +++ b/src/server/rpc.c @@ -233,6 +233,19 @@ func_return:; } while (0); } +void rpc_sendErrorMessage(int sock, const char* message) +{ + static const char *encoded = NULL; + static size_t len; + if ( encoded == NULL ) { + json_t *tmp = json_pack( "{ss}", "errorMsg", message ); + encoded = json_dumps( tmp, 0 ); + json_decref( tmp ); + len = strlen( encoded ); + } + sendReply( sock, "200 Somewhat OK", "application/json", encoded, len, HTTP_CLOSE ); +} + static bool handleStatus(int sock, int permissions, struct field *fields, size_t fields_num, int keepAlive) { bool ok; -- cgit v1.2.3-55-g7522