From 00fa820c3b272df21fde06c4e3ea37e97cfdac61 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 21 Nov 2014 10:39:04 +1100 Subject: [PATCH] Make the json_get functions return boolean for success or failure --- src/ckpool.c | 30 +++++++++++++++++++++--------- src/ckpool.h | 4 ++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/ckpool.c b/src/ckpool.c index c7ff6fee..0a87c430 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -890,23 +890,27 @@ static void sighandler(int sig) exit(0); } -void json_get_string(char **store, json_t *val, const char *res) +bool json_get_string(char **store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); + bool ret = false; const char *buf; *store = NULL; if (!entry || json_is_null(entry)) { LOGDEBUG("Json did not find entry %s", res); - return; + goto out; } if (!json_is_string(entry)) { LOGWARNING("Json entry %s is not a string", res); - return; + goto out; } buf = json_string_value(entry); LOGDEBUG("Json found entry %s: %s", res, buf); *store = strdup(buf); + ret = true; +out: + return ret; } static void json_get_int64(int64_t *store, json_t *val, const char *res) @@ -925,36 +929,44 @@ static void json_get_int64(int64_t *store, json_t *val, const char *res) LOGDEBUG("Json found entry %s: %ld", res, *store); } -void json_get_int(int *store, json_t *val, const char *res) +bool json_get_int(int *store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); + bool ret = false; if (!entry) { LOGDEBUG("Json did not find entry %s", res); - return; + goto out; } if (!json_is_integer(entry)) { LOGWARNING("Json entry %s is not an integer", res); - return; + goto out; } *store = json_integer_value(entry); LOGDEBUG("Json found entry %s: %d", res, *store); + ret = true; +out: + return ret; } -static void json_get_bool(bool *store, json_t *val, const char *res) +static bool json_get_bool(bool *store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); + bool ret = false; if (!entry) { LOGDEBUG("Json did not find entry %s", res); - return; + goto out; } if (!json_is_boolean(entry)) { LOGWARNING("Json entry %s is not a boolean", res); - return; + goto out; } *store = json_is_true(entry); LOGDEBUG("Json found entry %s: %s", res, *store ? "true" : "false"); + ret = true; +out: + return ret; } static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size) diff --git a/src/ckpool.h b/src/ckpool.h index d06820a0..f7bcc85a 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -208,7 +208,7 @@ char *_ckdb_msg_call(const ckpool_t *ckp, char *msg, const char *file, const ch json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); -void json_get_string(char **store, json_t *val, const char *res); -void json_get_int(int *store, json_t *val, const char *res); +bool json_get_string(char **store, json_t *val, const char *res); +bool json_get_int(int *store, json_t *val, const char *res); #endif /* CKPOOL_H */