X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbind.c;h=370ebc58dc0710afcc874c483a474b3be97aa3a8;hp=fc1fd92f0385905638e2f750d882b930cdc55b10;hb=ec51ddee94fa2ba1e01fe0e336ccc9c190a198ff;hpb=e7a7be6760b7f79780e9e9ed10fa9e029a3faa38 diff --git a/src/bind.c b/src/bind.c index fc1fd92f..370ebc58 100644 --- a/src/bind.c +++ b/src/bind.c @@ -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 bool config_parse_time = true; -static char *url = NULL; +static char *url; 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_resolver_stats; static int 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. */ @@ -138,7 +138,7 @@ static const translation_info_t nsstats_translation_table[] = /* {{{ */ {"ReqBadSIG", "dns_request", "BadSIG"}, {"ReqTCP", "dns_request", "TCP"}, /* Rejects */ - {"AuthQryRej", "dns_reject", "authorative"}, + {"AuthQryRej", "dns_reject", "authoritative"}, {"RecQryRej", "dns_reject", "recursive"}, {"XfrRej", "dns_reject", "transfer"}, {"UpdateRej", "dns_reject", "update"}, @@ -149,11 +149,11 @@ static const translation_info_t nsstats_translation_table[] = /* {{{ */ {"RespTSIG", "dns_response", "TSIG"}, {"RespSIG0", "dns_response", "SIG0"}, /* Queries */ - {"QryAuthAns", "dns_query", "authorative"}, + {"QryAuthAns", "dns_query", "authoritative"}, {"QryNoauthAns", "dns_query", "nonauth"}, {"QryReferral", "dns_query", "referral"}, {"QryRecursion", "dns_query", "recursion"}, - {"QryDuplicate", "dns_query", "dupliate"}, + {"QryDuplicate", "dns_query", "duplicate"}, {"QryDropped", "dns_query", "dropped"}, {"QryFailure", "dns_query", "failure"}, /* Response codes */ @@ -163,13 +163,13 @@ static const translation_info_t nsstats_translation_table[] = /* {{{ */ {"QryFORMERR", "dns_rcode", "tx-FORMERR"}, {"QryNXDOMAIN", "dns_rcode", "tx-NXDOMAIN"} #if 0 - { "XfrReqDone", "type", "type_instance" }, - { "UpdateReqFwd", "type", "type_instance" }, - { "UpdateRespFwd", "type", "type_instance" }, - { "UpdateFwdFail", "type", "type_instance" }, - { "UpdateDone", "type", "type_instance" }, - { "UpdateFail", "type", "type_instance" }, - { "UpdateBadPrereq", "type", "type_instance" }, + { "XfrReqDone", "type", "type_instance" }, + { "UpdateReqFwd", "type", "type_instance" }, + { "UpdateRespFwd", "type", "type_instance" }, + { "UpdateFwdFail", "type", "type_instance" }, + { "UpdateDone", "type", "type_instance" }, + { "UpdateFail", "type", "type_instance" }, + { "UpdateBadPrereq", "type", "type_instance" }, #endif }; static int nsstats_translation_table_length = @@ -246,16 +246,12 @@ static int memsummary_translation_table_length = static void submit(time_t ts, const char *plugin_instance, /* {{{ */ const char *type, const char *type_instance, value_t value) { - value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0] = value; - - vl.values = values; + vl.values = &value; vl.values_len = 1; if (config_parse_time) vl.time = TIME_T_TO_CDTIME_T(ts); - sstrncpy(vl.host, hostname_g, sizeof(vl.host)); sstrncpy(vl.plugin, "bind", sizeof(vl.plugin)); if (plugin_instance) { sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); @@ -275,15 +271,13 @@ static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */ size_t len = size * nmemb; if (len == 0) - return (len); + return len; if ((bind_buffer_fill + len) >= bind_buffer_size) { - char *temp; - - temp = realloc(bind_buffer, bind_buffer_fill + len + 1); + char *temp = realloc(bind_buffer, bind_buffer_fill + len + 1); if (temp == NULL) { ERROR("bind plugin: realloc failed."); - return (0); + return 0; } bind_buffer = temp; bind_buffer_size = bind_buffer_fill + len + 1; @@ -293,7 +287,7 @@ static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */ bind_buffer_fill += len; bind_buffer[bind_buffer_fill] = 0; - return (len); + return len; } /* }}} size_t bind_curl_callback */ /* @@ -305,7 +299,7 @@ static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */ translation_table_ptr_t *table = (translation_table_ptr_t *)user_data; if (table == NULL) - return (-1); + return -1; for (size_t i = 0; i < table->table_length; i++) { if (strcmp(table->table[i].xml_name, name) != 0) @@ -316,7 +310,7 @@ static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */ break; } - return (0); + return 0; } /* }}} int bind_xml_table_callback */ /* @@ -329,52 +323,48 @@ static int bind_xml_list_callback(const char *name, /* {{{ */ list_info_ptr_t *list_info = (list_info_ptr_t *)user_data; if (list_info == NULL) - return (-1); + return -1; submit(current_time, list_info->plugin_instance, list_info->type, /* type instance = */ name, value); - return (0); + return 0; } /* }}} int bind_xml_list_callback */ static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */ derive_t *ret_value) { - char *str_ptr; - value_t value; - int status; - - str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); + char *str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); if (str_ptr == NULL) { ERROR("bind plugin: bind_xml_read_derive: xmlNodeListGetString failed."); - return (-1); + return -1; } - status = parse_value(str_ptr, &value, DS_TYPE_DERIVE); + value_t value; + + 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); + return -1; } xmlFree(str_ptr); *ret_value = value.derive; - return (0); + return 0; } /* }}} int bind_xml_read_derive */ static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */ gauge_t *ret_value) { - char *str_ptr, *end_ptr; - double value; - - str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); + char *str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); if (str_ptr == NULL) { ERROR("bind plugin: bind_xml_read_gauge: xmlNodeListGetString failed."); - return (-1); + return -1; } + char *end_ptr; errno = 0; - value = strtod(str_ptr, &end_ptr); + double value = strtod(str_ptr, &end_ptr); xmlFree(str_ptr); if (str_ptr == end_ptr || errno) { if (errno && (value < 0)) @@ -383,32 +373,27 @@ static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */ ERROR("bind plugin: bind_xml_read_gauge: strtod failed with overflow."); else ERROR("bind plugin: bind_xml_read_gauge: strtod failed."); - return (-1); + return -1; } *ret_value = (gauge_t)value; - return (0); + return 0; } /* }}} int bind_xml_read_gauge */ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ xmlDoc *doc, xmlXPathContext *xpathCtx, time_t *ret_value) { - xmlXPathObject *xpathObj = NULL; - xmlNode *node; - char *str_ptr; - char *tmp; - struct tm tm = {0}; - - 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); - return (-1); + return -1; } if ((xpathObj->nodesetval == NULL) || (xpathObj->nodesetval->nodeNr < 1)) { xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } if (xpathObj->nodesetval->nodeNr != 1) { @@ -417,46 +402,43 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ xpath_expression, xpathObj->nodesetval->nodeNr); } - node = xpathObj->nodesetval->nodeTab[0]; + xmlNode *node = xpathObj->nodesetval->nodeTab[0]; if (node->xmlChildrenNode == NULL) { ERROR("bind plugin: bind_xml_read_timestamp: " "node->xmlChildrenNode == NULL"); xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } - str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); + char *str_ptr = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); if (str_ptr == NULL) { ERROR("bind plugin: bind_xml_read_timestamp: xmlNodeListGetString failed."); xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } - tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm); + struct tm tm = {0}; + char *tmp = strptime(str_ptr, "%Y-%m-%dT%T", &tm); xmlFree(str_ptr); if (tmp == NULL) { ERROR("bind plugin: bind_xml_read_timestamp: strptime failed."); xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } #if HAVE_TIMEGM time_t t = timegm(&tm); if (t == ((time_t)-1)) { - char errbuf[1024]; - ERROR("bind plugin: timegm() failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + ERROR("bind plugin: timegm() failed: %s", STRERRNO); + return -1; } *ret_value = t; #else time_t t = mktime(&tm); if (t == ((time_t)-1)) { - char errbuf[1024]; - ERROR("bind plugin: mktime() failed: %s", - sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + ERROR("bind plugin: mktime() failed: %s", STRERRNO); + return -1; } /* mktime assumes that tm is local time. Luckily, it also sets timezone to * the offset used for the conversion, and we undo the conversion to convert @@ -465,7 +447,7 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ #endif xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_xml_read_timestamp */ /* @@ -482,25 +464,23 @@ 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 = NULL; - int num_entries; - - 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); - return (-1); + return -1; } - num_entries = 0; + int num_entries = 0; /* Iterate over all matching nodes. */ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { + xmlNode *name_node = NULL; xmlNode *counter = NULL; - xmlNode *parent; - parent = xpathObj->nodesetval->nodeTab[i]; + xmlNode *parent = xpathObj->nodesetval->nodeTab[i]; DEBUG("bind plugin: bind_parse_generic_name_value: parent->name = %s;", (char *)parent->name); @@ -544,7 +524,7 @@ static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */ xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_parse_generic_name_value */ /* @@ -563,32 +543,29 @@ 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 = NULL; - int num_entries; - - 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); - return (-1); + return -1; } - num_entries = 0; + int num_entries = 0; /* Iterate over all matching nodes. */ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { /* Iterate over all child nodes. */ for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode; child != NULL; child = child->next) { - char *node_name; - value_t value; - int status; if (child->type != XML_ELEMENT_NODE) continue; - node_name = (char *)child->name; + char *node_name = (char *)child->name; + value_t value; + int status; if (ds_type == DS_TYPE_GAUGE) status = bind_xml_read_gauge(doc, child, &value.gauge); else @@ -607,7 +584,7 @@ static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */ xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_parse_generic_value_list */ /* @@ -625,17 +602,16 @@ static int bind_parse_generic_name_attr_value_list( const char *xpath_expression, /* {{{ */ list_callback_t list_callback, void *user_data, xmlDoc *doc, xmlXPathContext *xpathCtx, time_t current_time, int ds_type) { - xmlXPathObject *xpathObj = NULL; - int num_entries; - 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); - return (-1); + return -1; } - num_entries = 0; + int num_entries = 0; /* Iterate over all matching nodes. */ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++) { @@ -648,15 +624,15 @@ static int bind_parse_generic_name_attr_value_list( if (strncmp("counter", (char *)child->name, strlen("counter")) != 0) continue; - char *attr_name; - value_t value; - int status; - - attr_name = (char *)xmlGetProp(child, BAD_CAST "name"); + char *attr_name = (char *)xmlGetProp(child, BAD_CAST "name"); if (attr_name == NULL) { DEBUG("bind plugin: found without name."); continue; } + + value_t value; + int status; + if (ds_type == DS_TYPE_GAUGE) status = bind_xml_read_gauge(doc, child, &value.gauge); else @@ -679,15 +655,13 @@ static int bind_parse_generic_name_attr_value_list( xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_parse_generic_name_attr_value_list */ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view, time_t current_time) { - xmlXPathObject *path_obj; char *zone_name = NULL; - size_t j; if (version >= 3) { char *n = (char *)xmlGetProp(node, BAD_CAST "name"); @@ -699,10 +673,11 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ xmlFree(n); xmlFree(c); } else { - 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); + return -1; } for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); @@ -717,19 +692,19 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ if (zone_name == NULL) { ERROR("bind plugin: Could not determine zone name."); - return (-1); + return -1; } + size_t j; for (j = 0; j < view->zones_num; j++) { if (strcasecmp(zone_name, view->zones[j]) == 0) break; } xmlFree(zone_name); - zone_name = NULL; if (j >= view->zones_num) - return (0); + return 0; zone_name = view->zones[j]; @@ -741,8 +716,8 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ nsstats_translation_table_length, plugin_instance}; - ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s", - view->name, zone_name); + snprintf(plugin_instance, sizeof(plugin_instance), "%s-zone-%s", view->name, + zone_name); if (version == 3) { list_info_ptr_t list_info = {plugin_instance, @@ -765,26 +740,24 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ } } /* }}} */ - return (0); + return 0; } /* }}} int bind_xml_stats_handle_zone */ static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */ xmlXPathContext *path_ctx, xmlNode *node, cb_view_t *view, time_t current_time) { - xmlXPathObject *zone_nodes = NULL; - xmlXPathContext *zone_path_context; - - zone_path_context = xmlXPathNewContext(doc); + xmlXPathContext *zone_path_context = xmlXPathNewContext(doc); if (zone_path_context == NULL) { ERROR("bind plugin: xmlXPathNewContext failed."); - return (-1); + return -1; } - 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); - return (-1); + return -1; } for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++) { @@ -799,7 +772,7 @@ static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */ xmlXPathFreeObject(zone_nodes); xmlXPathFreeContext(zone_path_context); - return (0); + return 0; } /* }}} int bind_xml_stats_search_zones */ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ @@ -814,7 +787,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ if (view_name == NULL) { ERROR("bind plugin: Could not determine view name."); - return (-1); + return -1; } for (j = 0; j < views_num; j++) { @@ -825,11 +798,11 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ xmlFree(view_name); view_name = NULL; } else { - xmlXPathObject *path_obj; - 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); + return -1; } for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); @@ -843,7 +816,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ if (view_name == NULL) { ERROR("bind plugin: Could not determine view name."); xmlXPathFreeObject(path_obj); - return (-1); + return -1; } for (j = 0; j < views_num; j++) { @@ -859,7 +832,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ } if (j >= views_num) - return (0); + return 0; view = views + j; @@ -872,8 +845,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ list_info_ptr_t list_info = {plugin_instance, /* type = */ "dns_qtype"}; - ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes", - view->name); + snprintf(plugin_instance, sizeof(plugin_instance), "%s-qtypes", view->name); if (version == 3) { bind_parse_generic_name_attr_value_list( /* xpath = */ "counters[@type='resqtype']", @@ -895,8 +867,8 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ resstats_translation_table_length, plugin_instance}; - ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats", - view->name); + snprintf(plugin_instance, sizeof(plugin_instance), "%s-resolver_stats", + view->name); if (version == 3) { bind_parse_generic_name_attr_value_list( "counters[@type='resstats']", @@ -918,8 +890,8 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ list_info_ptr_t list_info = {plugin_instance, /* type = */ "dns_qtype_cached"}; - ssnprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets", - view->name); + snprintf(plugin_instance, sizeof(plugin_instance), "%s-cache_rr_sets", + view->name); bind_parse_generic_name_value(/* xpath = */ "cache/rrset", /* callback = */ bind_xml_list_callback, @@ -931,33 +903,29 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ bind_xml_stats_search_zones(version, doc, path_ctx, node, view, current_time); - return (0); + return 0; } /* }}} int bind_xml_stats_handle_view */ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ xmlXPathContext *xpathCtx, xmlNode *statsnode, time_t current_time) { - xmlXPathObject *view_nodes = NULL; - xmlXPathContext *view_path_context; - - view_path_context = xmlXPathNewContext(doc); + xmlXPathContext *view_path_context = xmlXPathNewContext(doc); if (view_path_context == NULL) { ERROR("bind plugin: xmlXPathNewContext failed."); - return (-1); + return -1; } - 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); - return (-1); + return -1; } for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++) { - xmlNode *node; - - node = view_nodes->nodesetval->nodeTab[i]; + xmlNode *node = view_nodes->nodesetval->nodeTab[i]; assert(node != NULL); view_path_context->node = node; @@ -968,7 +936,7 @@ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ xmlXPathFreeObject(view_nodes); xmlXPathFreeContext(view_path_context); - return (0); + return 0; } /* }}} int bind_xml_stats_search_views */ static void bind_xml_stats_v3(xmlDoc *doc, /* {{{ */ @@ -1261,17 +1229,16 @@ static void bind_xml_stats_v1_v2(int version, xmlDoc *doc, /* {{{ */ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ xmlXPathContext *xpathCtx, xmlNode *statsnode) { time_t current_time = 0; - int status; xpathCtx->node = statsnode; /* TODO: Check `server/boot-time' to recognize server restarts. */ - status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx, - ¤t_time); + int status = bind_xml_read_timestamp("server/current-time", doc, xpathCtx, + ¤t_time); if (status != 0) { ERROR("bind plugin: Reading `server/current-time' failed."); - return (-1); + return -1; } DEBUG("bind plugin: Current server time is %i.", (int)current_time); @@ -1312,29 +1279,27 @@ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ static int bind_xml(const char *data) /* {{{ */ { - xmlDoc *doc = NULL; - xmlXPathContext *xpathCtx = NULL; - xmlXPathObject *xpathObj = NULL; int ret = -1; - doc = xmlParseMemory(data, strlen(data)); + xmlDoc *doc = xmlParseMemory(data, strlen(data)); if (doc == NULL) { ERROR("bind plugin: xmlParseMemory failed."); - return (-1); + return -1; } - xpathCtx = xmlXPathNewContext(doc); + xmlXPathContext *xpathCtx = xmlXPathNewContext(doc); if (xpathCtx == NULL) { ERROR("bind plugin: xmlXPathNewContext failed."); xmlFreeDoc(doc); - return (-1); + return -1; } // // version 3.* of statistics XML (since BIND9.9) // - 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"); @@ -1379,7 +1344,7 @@ static int bind_xml(const char *data) /* {{{ */ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); - return (ret); + return ret; } // @@ -1391,13 +1356,13 @@ static int bind_xml(const char *data) /* {{{ */ ERROR("bind plugin: Cannot find the tag."); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); - return (-1); + return -1; } else if (xpathObj->nodesetval == NULL) { ERROR("bind plugin: xmlXPathEvalExpression failed."); xmlXPathFreeObject(xpathObj); xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); - return (-1); + return -1; } for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++) { @@ -1445,7 +1410,7 @@ static int bind_xml(const char *data) /* {{{ */ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); - return (ret); + return ret; } /* }}} int bind_xml */ static int bind_config_set_bool(const char *name, int *var, /* {{{ */ @@ -1454,7 +1419,7 @@ static int bind_config_set_bool(const char *name, int *var, /* {{{ */ WARNING("bind plugin: The `%s' option needs " "exactly one boolean argument.", name); - return (-1); + return -1; } if (ci->values[0].value.boolean) @@ -1466,44 +1431,40 @@ static int bind_config_set_bool(const char *name, int *var, /* {{{ */ static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */ oconfig_item_t *ci) { - char **tmp; - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("bind plugin: The `Zone' option needs " "exactly one string argument."); - return (-1); + return -1; } - tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1)); + char **tmp = realloc(view->zones, sizeof(char *) * (view->zones_num + 1)); if (tmp == NULL) { ERROR("bind plugin: realloc failed."); - return (-1); + return -1; } view->zones = tmp; view->zones[view->zones_num] = strdup(ci->values[0].value.string); if (view->zones[view->zones_num] == NULL) { ERROR("bind plugin: strdup failed."); - return (-1); + return -1; } view->zones_num++; - return (0); + return 0; } /* }}} int bind_config_add_view_zone */ static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */ { - cb_view_t *tmp; - if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("bind plugin: `View' blocks need exactly one string argument."); - return (-1); + return -1; } - tmp = realloc(views, sizeof(*views) * (views_num + 1)); + cb_view_t *tmp = realloc(views, sizeof(*views) * (views_num + 1)); if (tmp == NULL) { ERROR("bind plugin: realloc failed."); - return (-1); + return -1; } views = tmp; tmp = views + views_num; @@ -1519,7 +1480,7 @@ static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */ if (tmp->name == NULL) { ERROR("bind plugin: strdup failed."); sfree(views); - return (-1); + return -1; } for (int i = 0; i < ci->children_num; i++) { @@ -1541,7 +1502,7 @@ static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */ } /* for (i = 0; i < ci->children_num; i++) */ views_num++; - return (0); + return 0; } /* }}} int bind_config_add_view */ static int bind_config(oconfig_item_t *ci) /* {{{ */ @@ -1554,7 +1515,7 @@ static int bind_config(oconfig_item_t *ci) /* {{{ */ (child->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("bind plugin: The `Url' option needs " "exactly one string argument."); - return (-1); + return -1; } sfree(url); @@ -1584,18 +1545,18 @@ static int bind_config(oconfig_item_t *ci) /* {{{ */ } } - return (0); + return 0; } /* }}} int bind_config */ static int bind_init(void) /* {{{ */ { if (curl != NULL) - return (0); + return 0; curl = curl_easy_init(); if (curl == NULL) { ERROR("bind plugin: bind_init: curl_easy_init failed."); - return (-1); + return -1; } curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L); @@ -1610,16 +1571,14 @@ static int bind_init(void) /* {{{ */ plugin_get_interval())); #endif - return (0); + return 0; } /* }}} int bind_init */ static int bind_read(void) /* {{{ */ { - int status; - if (curl == NULL) { ERROR("bind plugin: I don't have a CURL object."); - return (-1); + return -1; } bind_buffer_fill = 0; @@ -1628,14 +1587,14 @@ static int bind_read(void) /* {{{ */ if (curl_easy_perform(curl) != CURLE_OK) { ERROR("bind plugin: curl_easy_perform failed: %s", bind_curl_error); - return (-1); + return -1; } - status = bind_xml(bind_buffer); + int status = bind_xml(bind_buffer); if (status != 0) - return (-1); + return -1; else - return (0); + return 0; } /* }}} int bind_read */ static int bind_shutdown(void) /* {{{ */ @@ -1645,7 +1604,7 @@ static int bind_shutdown(void) /* {{{ */ curl = NULL; } - return (0); + return 0; } /* }}} int bind_shutdown */ void module_register(void) { @@ -1654,5 +1613,3 @@ void module_register(void) { plugin_register_read("bind", bind_read); plugin_register_shutdown("bind", bind_shutdown); } /* void module_register */ - -/* vim: set sw=2 sts=2 ts=8 et fdm=marker : */