X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbind.c;h=a246f1aacfb10fc87e3e25d87b52513293e2ea82;hp=d123e14468f40fe1152d41121264df4928eb1e87;hb=48efd3deb4c9139fd060ff3d289896e9031bcc7c;hpb=3c96be5e1ae3dbca6d42be0f24ae17b6c94d6a32 diff --git a/src/bind.c b/src/bind.c index d123e144..a246f1aa 100644 --- a/src/bind.c +++ b/src/bind.c @@ -43,8 +43,8 @@ #include "collectd.h" -#include "common.h" #include "plugin.h" +#include "utils/common/common.h" #include @@ -73,9 +73,9 @@ typedef int (*list_callback_t)(const char *name, value_t value, struct cb_view_s { char *name; - int qtypes; - int resolver_stats; - int cacherrsets; + _Bool qtypes; + _Bool resolver_stats; + _Bool cacherrsets; char **zones; size_t zones_num; @@ -104,25 +104,25 @@ typedef struct list_info_ptr_s list_info_ptr_t; /* FIXME: Enabled by default for backwards compatibility. */ /* TODO: Remove time parsing code. */ -static _Bool config_parse_time = 1; - -static char *url = NULL; -static int global_opcodes = 1; -static int global_qtypes = 1; -static int global_server_stats = 1; -static int global_zone_maint_stats = 1; -static int global_resolver_stats = 0; -static int global_memory_stats = 1; +static bool config_parse_time = true; + +static char *url; +static _Bool global_opcodes = 1; +static _Bool global_qtypes = 1; +static _Bool global_server_stats = 1; +static _Bool global_zone_maint_stats = 1; +static _Bool global_resolver_stats; +static _Bool global_memory_stats = 1; static int timeout = -1; -static cb_view_t *views = NULL; -static size_t views_num = 0; +static cb_view_t *views; +static size_t views_num; -static CURL *curl = NULL; +static CURL *curl; -static char *bind_buffer = NULL; -static size_t bind_buffer_size = 0; -static size_t bind_buffer_fill = 0; +static char *bind_buffer; +static size_t bind_buffer_size; +static size_t bind_buffer_fill; static char bind_curl_error[CURL_ERROR_SIZE]; /* Translation table for the `nsstats' values. */ @@ -343,8 +343,6 @@ static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */ int status = parse_value(str_ptr, &value, DS_TYPE_DERIVE); if (status != 0) { - ERROR("bind plugin: Parsing string \"%s\" to derive value failed.", - str_ptr); xmlFree(str_ptr); return -1; } @@ -383,7 +381,8 @@ static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value) { - xmlXPathObject *xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); + xmlXPathObject *xpathObj = + xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); @@ -410,7 +409,6 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ return -1; } - char *str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); if (str_ptr == NULL) { ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed."); @@ -464,7 +462,8 @@ static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */ void *user_data, xmlDoc *doc, xmlXPathContext *xpathCtx, time_t current_time, int ds_type) { - xmlXPathObject *xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); + xmlXPathObject *xpathObj = + xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); @@ -542,7 +541,8 @@ static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */ void *user_data, xmlDoc *doc, xmlXPathContext *xpathCtx, time_t current_time, int ds_type) { - xmlXPathObject *xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); + xmlXPathObject *xpathObj = + xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); @@ -601,7 +601,8 @@ static int bind_parse_generic_name_attr_value_list( list_callback_t list_callback, void *user_data, xmlDoc *doc, xmlXPathContext *xpathCtx, time_t current_time, int ds_type) { - xmlXPathObject *xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); + xmlXPathObject *xpathObj = + xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx); if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); @@ -670,7 +671,8 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ xmlFree(n); xmlFree(c); } else { - xmlXPathObject *path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx); + xmlXPathObject *path_obj = + xmlXPathEvalExpression(BAD_CAST "name", path_ctx); if (path_obj == NULL) { ERROR("bind plugin: xmlXPathEvalExpression failed."); return -1; @@ -748,7 +750,8 @@ static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */ return -1; } - xmlXPathObject *zone_nodes = xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx); + xmlXPathObject *zone_nodes = + xmlXPathEvalExpression(BAD_CAST "zones/zone", path_ctx); if (zone_nodes == NULL) { ERROR("bind plugin: Cannot find any tags."); xmlXPathFreeContext(zone_path_context); @@ -793,7 +796,8 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ xmlFree(view_name); view_name = NULL; } else { - xmlXPathObject *path_obj = xmlXPathEvalExpression(BAD_CAST "name", path_ctx); + xmlXPathObject *path_obj = + xmlXPathEvalExpression(BAD_CAST "name", path_ctx); if (path_obj == NULL) { ERROR("bind plugin: xmlXPathEvalExpression failed."); return -1; @@ -902,7 +906,6 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ xmlXPathContext *xpathCtx, - xmlNode *statsnode, time_t current_time) { xmlXPathContext *view_path_context = xmlXPathNewContext(doc); if (view_path_context == NULL) { @@ -910,7 +913,8 @@ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ return -1; } - xmlXPathObject *view_nodes = xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx); + xmlXPathObject *view_nodes = + xmlXPathEvalExpression(BAD_CAST "views/view", xpathCtx); if (view_nodes == NULL) { ERROR("bind plugin: Cannot find any tags."); xmlXPathFreeContext(view_path_context); @@ -933,8 +937,7 @@ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ } /* }}} int bind_xml_stats_search_views */ static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */ - xmlXPathContext *xpathCtx, xmlNode *statsnode, - time_t current_time) { + xmlXPathContext *xpathCtx, time_t current_time) { /* XPath: server/counters[@type='opcode'] * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ... * Layout v3: @@ -1052,7 +1055,7 @@ static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */ } /* }}} bind_xml_stats_v3 */ static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */ - xmlXPathContext *xpathCtx, xmlNode *statsnode, + xmlXPathContext *xpathCtx, time_t current_time) { /* XPath: server/requests/opcode, server/counters[@type='opcode'] * Variables: QUERY, IQUERY, NOTIFY, UPDATE, ... @@ -1228,7 +1231,7 @@ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ /* TODO: Check `server/boot-time' to recognize server restarts. */ int status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx, - ¤t_time); + ¤t_time); if (status != 0) { ERROR("bind plugin: Reading `server/current-time' failed."); return -1; @@ -1236,9 +1239,9 @@ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ DEBUG("bind plugin: Current server time is %i.", (int)current_time); if (version == 3) { - bind_xml_stats_v3(doc, xpathCtx, statsnode, current_time); + bind_xml_stats_v3(doc, xpathCtx, current_time); } else { - bind_xml_stats_v1_v2(version, doc, xpathCtx, statsnode, current_time); + bind_xml_stats_v1_v2(version, doc, xpathCtx, current_time); } /* XPath: memory/summary @@ -1264,8 +1267,7 @@ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ } if (views_num > 0) - bind_xml_stats_search_views(version, doc, xpathCtx, statsnode, - current_time); + bind_xml_stats_search_views(version, doc, xpathCtx, current_time); return 0; } /* }}} int bind_xml_stats */ @@ -1291,7 +1293,8 @@ static int bind_xml(const char *data) /* {{{ */ // version 3.* of statistics XML (since BIND9.9) // - xmlXPathObject *xpathObj = xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx); + xmlXPathObject *xpathObj = + xmlXPathEvalExpression(BAD_CAST "/statistics", xpathCtx); if (xpathObj == NULL || xpathObj->nodesetval == NULL || xpathObj->nodesetval->nodeNr == 0) { DEBUG("bind plugin: Statistics appears not to be v3"); @@ -1405,22 +1408,6 @@ static int bind_xml(const char *data) /* {{{ */ return ret; } /* }}} int bind_xml */ -static int bind_config_set_bool(const char *name, int *var, /* {{{ */ - oconfig_item_t *ci) { - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_BOOLEAN)) { - WARNING("bind plugin: The `%s' option needs " - "exactly one boolean argument.", - name); - return -1; - } - - if (ci->values[0].value.boolean) - *var = 1; - else - *var = 0; - return 0; -} /* }}} int bind_config_set_bool */ - static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */ oconfig_item_t *ci) { if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { @@ -1479,11 +1466,11 @@ static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp("QTypes", child->key) == 0) - bind_config_set_bool("QTypes", &tmp->qtypes, child); + cf_util_get_boolean(child, &tmp->qtypes); else if (strcasecmp("ResolverStats", child->key) == 0) - bind_config_set_bool("ResolverStats", &tmp->resolver_stats, child); + cf_util_get_boolean(child, &tmp->resolver_stats); else if (strcasecmp("CacheRRSets", child->key) == 0) - bind_config_set_bool("CacheRRSets", &tmp->cacherrsets, child); + cf_util_get_boolean(child, &tmp->cacherrsets); else if (strcasecmp("Zone", child->key) == 0) bind_config_add_view_zone(tmp, child); else { @@ -1503,27 +1490,19 @@ static int bind_config(oconfig_item_t *ci) /* {{{ */ oconfig_item_t *child = ci->children + i; if (strcasecmp("Url", child->key) == 0) { - if ((child->values_num != 1) || - (child->values[0].type != OCONFIG_TYPE_STRING)) { - WARNING("bind plugin: The `Url' option needs " - "exactly one string argument."); - return -1; - } - - sfree(url); - url = strdup(child->values[0].value.string); + cf_util_get_string(child, &url); } else if (strcasecmp("OpCodes", child->key) == 0) - bind_config_set_bool("OpCodes", &global_opcodes, child); + cf_util_get_boolean(child, &global_opcodes); else if (strcasecmp("QTypes", child->key) == 0) - bind_config_set_bool("QTypes", &global_qtypes, child); + cf_util_get_boolean(child, &global_qtypes); else if (strcasecmp("ServerStats", child->key) == 0) - bind_config_set_bool("ServerStats", &global_server_stats, child); + cf_util_get_boolean(child, &global_server_stats); else if (strcasecmp("ZoneMaintStats", child->key) == 0) - bind_config_set_bool("ZoneMaintStats", &global_zone_maint_stats, child); + cf_util_get_boolean(child, &global_zone_maint_stats); else if (strcasecmp("ResolverStats", child->key) == 0) - bind_config_set_bool("ResolverStats", &global_resolver_stats, child); + cf_util_get_boolean(child, &global_resolver_stats); else if (strcasecmp("MemoryStats", child->key) == 0) - bind_config_set_bool("MemoryStats", &global_memory_stats, child); + cf_util_get_boolean(child, &global_memory_stats); else if (strcasecmp("View", child->key) == 0) bind_config_add_view(child); else if (strcasecmp("ParseTime", child->key) == 0) @@ -1559,8 +1538,9 @@ static int bind_init(void) /* {{{ */ curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 50L); #ifdef HAVE_CURLOPT_TIMEOUT_MS curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, - (timeout >= 0) ? (long)timeout : (long)CDTIME_T_TO_MS( - plugin_get_interval())); + (timeout >= 0) + ? (long)timeout + : (long)CDTIME_T_TO_MS(plugin_get_interval())); #endif return 0;