From: Sebastian Harl Date: Mon, 30 May 2016 21:23:59 +0000 (+0200) Subject: curl stats: Simplified some error checks and removed unused code. X-Git-Tag: collectd-5.6.0~220^2~3 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=e410b00640d1c0bc3bf768eee01c8165cc5a8a30;p=collectd.git curl stats: Simplified some error checks and removed unused code. --- diff --git a/src/curl.c b/src/curl.c index 6377780c..cf2e816b 100644 --- a/src/curl.c +++ b/src/curl.c @@ -686,7 +686,7 @@ static int cc_read_page (web_page_t *wp) /* {{{ */ if (wp->response_time) cc_submit_response_time (wp, cdtime() - start); if (wp->stats != NULL) - curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance, NULL); + curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance); if(wp->response_code) { diff --git a/src/curl_json.c b/src/curl_json.c index 1cf6381a..deb8b6e9 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -922,7 +922,7 @@ static int cj_curl_perform(cj_t *db) /* {{{ */ return (-1); } if (db->stats != NULL) - curl_stats_dispatch (db->stats, db->curl, cj_host (db), "curl_json", db->instance, NULL); + curl_stats_dispatch (db->stats, db->curl, cj_host (db), "curl_json", db->instance); curl_easy_getinfo(db->curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(db->curl, CURLINFO_RESPONSE_CODE, &rc); diff --git a/src/curl_xml.c b/src/curl_xml.c index 21e09252..00a980cf 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -641,7 +641,7 @@ static int cx_curl_perform (cx_t *db, CURL *curl) /* {{{ */ return (-1); } if (db->stats != NULL) - curl_stats_dispatch (db->stats, db->curl, cx_host (db), "curl_xml", db->instance, NULL); + curl_stats_dispatch (db->stats, db->curl, cx_host (db), "curl_xml", db->instance); curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url); curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc); diff --git a/src/utils_curl_stats.c b/src/utils_curl_stats.c index b242a239..0f2f56ea 100644 --- a/src/utils_curl_stats.c +++ b/src/utils_curl_stats.c @@ -187,17 +187,13 @@ curl_stats_t *curl_stats_from_config (oconfig_item_t *ci) } if ((c->values_num != 1) - || ((c->values[0].type != OCONFIG_TYPE_STRING) - && (c->values[0].type != OCONFIG_TYPE_BOOLEAN))) { + || (c->values[0].type != OCONFIG_TYPE_BOOLEAN)) { ERROR ("curl stats: `%s' expects a single boolean argument", c->key); free (s); return NULL; } - if (((c->values[0].type == OCONFIG_TYPE_STRING) - && IS_TRUE (c->values[0].value.string)) - || ((c->values[0].type == OCONFIG_TYPE_BOOLEAN) - && c->values[0].value.boolean)) + if (c->values[0].value.boolean) enable_field (s, field_specs[field].offset); } @@ -211,21 +207,24 @@ void curl_stats_destroy (curl_stats_t *s) } /* curl_stats_destroy */ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, - const char *hostname, const char *plugin, const char *plugin_instance, - const char *instance_prefix) + 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; - if (curl == NULL) + if ((curl == NULL) || (hostname == NULL) || (plugin == NULL)) + { + ERROR ("curl stats: dispatch() called with missing arguments " + "(curl=%p; hostname=%s; plugin=%s)", curl, + hostname == NULL ? "" : hostname, + plugin == NULL ? "" : plugin); return -1; + } - if (hostname != NULL) - sstrncpy (vl.host, hostname, sizeof (vl.host)); - if (plugin != NULL) - sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); + sstrncpy (vl.host, hostname, sizeof (vl.host)); + sstrncpy (vl.plugin, plugin, sizeof (vl.plugin)); if (plugin_instance != NULL) sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); @@ -237,8 +236,7 @@ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, continue; sstrncpy (vl.type, field_specs[field].type, sizeof (vl.type)); - ssnprintf (vl.type_instance, sizeof (vl.type_instance), "%s%s", - instance_prefix ? instance_prefix : "", field_specs[field].name); + sstrncpy (vl.type_instance, field_specs[field].name, sizeof (vl.type_instance)); vl.values = NULL; vl.values_len = 0; diff --git a/src/utils_curl_stats.h b/src/utils_curl_stats.h index ef925605..69927f77 100644 --- a/src/utils_curl_stats.h +++ b/src/utils_curl_stats.h @@ -53,7 +53,6 @@ void curl_stats_destroy (curl_stats_t *s); * cURL session to the daemon. */ int curl_stats_dispatch (curl_stats_t *s, CURL *curl, - const char *hostname, const char *plugin, const char *plugin_instance, - const char *instance_prefix); + const char *hostname, const char *plugin, const char *plugin_instance); #endif /* UTILS_CURL_STATS_H */