X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Futils_curl_stats.c;h=0509ff43beaf58e8c646689b2992fddff628ece0;hb=c53c496b6db4e11fd8aed8df9556dad481220196;hp=0f2f56ead539bd0b12d7458d6948afb19cea1546;hpb=e410b00640d1c0bc3bf768eee01c8165cc5a8a30;p=collectd.git diff --git a/src/utils_curl_stats.c b/src/utils_curl_stats.c index 0f2f56ea..0509ff43 100644 --- a/src/utils_curl_stats.c +++ b/src/utils_curl_stats.c @@ -25,6 +25,7 @@ **/ #include "collectd.h" + #include "common.h" #include "utils_curl_stats.h" @@ -159,20 +160,21 @@ static bool field_enabled (curl_stats_t *s, size_t offset) curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) { curl_stats_t *s; - int i; if (ci == NULL) return NULL; - s = calloc (sizeof (*s), 1); + s = calloc (1, sizeof (*s)); if (s == NULL) return NULL; - for (i = 0; i < ci->children_num; ++i) + for (int i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; size_t field; + _Bool enabled = 0; + for (field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) { if (! strcasecmp (c->key, field_specs[field].config_key)) break; @@ -186,14 +188,12 @@ curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) return NULL; } - if ((c->values_num != 1) - || (c->values[0].type != OCONFIG_TYPE_BOOLEAN)) { - ERROR ("curl stats: `%s' expects a single boolean argument", c->key); + + if (cf_util_get_boolean (c, &enabled) != 0) { free (s); return NULL; } - - if (c->values[0].value.boolean) + if (enabled) enable_field (s, field_specs[field].offset); } @@ -210,7 +210,6 @@ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, const char *hostname, const char *plugin, const char *plugin_instance) { value_list_t vl = VALUE_LIST_INIT; - size_t field; if (s == NULL) return 0; @@ -228,7 +227,7 @@ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - for (field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) + for (size_t field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field) { int status;