summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c62262d)
raw | patch | inline | side by side (parent: c62262d)
author | Florian Forster <octo@huhu.verplant.org> | |
Tue, 14 Dec 2010 07:16:46 +0000 (08:16 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Tue, 14 Dec 2010 07:16:46 +0000 (08:16 +0100) |
src/curl_json.c | patch | blob | history |
diff --git a/src/curl_json.c b/src/curl_json.c
index 3ad80a224fcd1b7b07a25592f96e2f693eb7c8ff..f6bc512d9b86caea96331d90d7f14437e2237515 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
#define CJ_DEFAULT_HOST "localhost"
#define CJ_KEY_MAGIC 0x43484b59UL /* CHKY */
-#define CJ_IS_KEY(key) (key)->magic == CJ_KEY_MAGIC
+#define CJ_IS_KEY(key) ((key)->magic == CJ_KEY_MAGIC)
#define CJ_ANY "*"
#define COUCH_MIN(x,y) ((x) < (y) ? (x) : (y))
cj_t *db = (cj_t *)ctx;
cj_key_t *key = db->state[db->depth].key;
- char *endptr;
value_t vt;
int type;
+ int status;
- if (key == NULL)
+ if ((key == NULL) || !CJ_IS_KEY (key))
return (CJ_CB_CONTINUE);
memcpy (buffer, number, number_len);
buffer[sizeof (buffer) - 1] = 0;
type = cj_get_type (key);
-
- endptr = NULL;
- errno = 0;
-
- if (type == DS_TYPE_COUNTER)
- vt.counter = (counter_t) strtoull (buffer, &endptr, /* base = */ 0);
- else if (type == DS_TYPE_GAUGE)
- vt.gauge = (gauge_t) strtod (buffer, &endptr);
- else if (type == DS_TYPE_DERIVE)
- vt.derive = (derive_t) strtoll (buffer, &endptr, /* base = */ 0);
- else if (type == DS_TYPE_ABSOLUTE)
- vt.absolute = (absolute_t) strtoull (buffer, &endptr, /* base = */ 0);
- else
- {
- ERROR ("curl_json plugin: Unknown data source type: \"%s\"", key->type);
- return (CJ_CB_ABORT);
- }
-
- if ((endptr == &buffer[0]) || (errno != 0))
+ status = parse_value (buffer, &vt, type);
+ if (status != 0)
{
- NOTICE ("curl_json plugin: Overflow while parsing number. "
- "Ignoring this value.");
+ NOTICE ("curl_json plugin: Unable to parse number: \"%s\"", buffer);
return (CJ_CB_CONTINUE);
}