diff options
author | Simon Rettberg | 2017-11-02 10:52:53 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-02 10:52:53 +0100 |
commit | e4f3e11a8e22db6fca08dba4290db39a2e1c0f4b (patch) | |
tree | 3a5b953a06cae2dcafbd2f2684a5fdd17bd88d49 /src/server/rpc.c | |
parent | [SERVER] Ignore invalid basePath in globals.c, do bailout in server.c (diff) | |
download | dnbd3-e4f3e11a8e22db6fca08dba4290db39a2e1c0f4b.tar.gz dnbd3-e4f3e11a8e22db6fca08dba4290db39a2e1c0f4b.tar.xz dnbd3-e4f3e11a8e22db6fca08dba4290db39a2e1c0f4b.zip |
[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.
Diffstat (limited to 'src/server/rpc.c')
-rw-r--r-- | src/server/rpc.c | 13 |
1 files changed, 13 insertions, 0 deletions
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; |