From 6b9c558abc1630de1f48069b519b35ced19e3fc2 Mon Sep 17 00:00:00 2001 From: ckolivas Date: Sun, 18 Jan 2015 09:36:47 +1100 Subject: [PATCH] Add a json_get_double helper --- src/ckpool.c | 20 ++++++++++++++++++++ src/ckpool.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/ckpool.c b/src/ckpool.c index bef14365..60374273 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -997,6 +997,26 @@ out: return ret; } +bool json_get_double(double *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); + goto out; + } + if (!json_is_real(entry)) { + LOGWARNING("Json entry %s is not a double", res); + goto out; + } + *store = json_real_value(entry); + LOGDEBUG("Json found entry %s: %f", res, *store); + ret = true; +out: + return ret; +} + static bool json_get_bool(bool *store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); diff --git a/src/ckpool.h b/src/ckpool.h index b8293474..0b28aa40 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -214,5 +214,6 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); bool json_get_string(char **store, json_t *val, const char *res); bool json_get_int(int *store, json_t *val, const char *res); +bool json_get_double(double *store, json_t *val, const char *res); #endif /* CKPOOL_H */