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 */