From: Jim Radford Date: Wed, 14 Aug 2013 00:57:58 +0000 (-0700) Subject: curl_json plugin: warn when config expects a map and a number is provided X-Git-Tag: collectd-5.4.0~3^2~2^3 X-Git-Url: https://git.tokkee.org/?p=collectd.git;a=commitdiff_plain;h=a5520423233b4ead083030661a256058db562564 curl_json plugin: warn when config expects a map and a number is provided Moves the warning for strings in the number callback which was being called anyway. This also serves to fix parsing numbers represented as JSON strings which was inadvertantly broken when adding array support. --- diff --git a/src/curl_json.c b/src/curl_json.c index 5bc3e419..ca604fc2 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -218,6 +218,10 @@ static int cj_cb_number (void *ctx, int status; if ((key == NULL) || !CJ_IS_KEY (key)) { + if (key != NULL) + NOTICE ("curl_json plugin: Found \"%.*s\", but the configuration expects" + " a map.", (int)number_len > number_len ? 0 : (int)number_len, + number); cj_cb_inc_array_index (ctx, 1); return (CJ_CB_CONTINUE); } else @@ -269,27 +273,6 @@ static int cj_cb_map_key (void *ctx, const unsigned char *val, static int cj_cb_string (void *ctx, const unsigned char *val, yajl_len_t len) { - cj_t *db = (cj_t *)ctx; - char str[len + 1]; - - cj_cb_inc_array_index (ctx, 1); - return (CJ_CB_CONTINUE); - - /* Create a null-terminated version of the string. */ - memcpy (str, val, len); - str[len] = 0; - - /* No configuration for this string -> simply return. */ - if (db->state[db->depth].key == NULL) - return (CJ_CB_CONTINUE); - - if (!CJ_IS_KEY (db->state[db->depth].key)) - { - NOTICE ("curl_json plugin: Found string \"%s\", but the configuration " - "expects a map here.", str); - return (CJ_CB_CONTINUE); - } - /* Handle the string as if it was a number. */ return (cj_cb_number (ctx, (const char *) val, len)); } /* int cj_cb_string */