X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fbind.c;h=990e2ca7de4d0a17cc2c3c3ee25f8434d14c9e88;hp=fc1fd92f0385905638e2f750d882b930cdc55b10;hb=7111bb6df7628edce3a8e538b386fbe27633a191;hpb=e7a7be6760b7f79780e9e9ed10fa9e029a3faa38 diff --git a/src/bind.c b/src/bind.c index fc1fd92f..990e2ca7 100644 --- a/src/bind.c +++ b/src/bind.c @@ -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,7 +271,7 @@ 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; @@ -283,7 +279,7 @@ static size_t bind_curl_callback(void *buf, size_t size, /* {{{ */ 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 +289,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 +301,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 +312,7 @@ static int bind_xml_table_callback(const char *name, value_t value, /* {{{ */ break; } - return (0); + return 0; } /* }}} int bind_xml_table_callback */ /* @@ -329,12 +325,12 @@ 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, /* {{{ */ @@ -346,7 +342,7 @@ static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */ 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); @@ -354,12 +350,12 @@ static int bind_xml_read_derive(xmlDoc *doc, xmlNode *node, /* {{{ */ 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, /* {{{ */ @@ -370,7 +366,7 @@ static int bind_xml_read_gauge(xmlDoc *doc, xmlNode *node, /* {{{ */ 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; } errno = 0; @@ -383,11 +379,11 @@ 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, /* {{{ */ @@ -403,12 +399,12 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ 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) { @@ -423,14 +419,14 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ ERROR("bind plugin: bind_xml_read_timestamp: " "node->xmlChildrenNode == NULL"); xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } 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); @@ -438,7 +434,7 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ if (tmp == NULL) { ERROR("bind plugin: bind_xml_read_timestamp: strptime failed."); xmlXPathFreeObject(xpathObj); - return (-1); + return -1; } #if HAVE_TIMEGM @@ -447,7 +443,7 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ char errbuf[1024]; ERROR("bind plugin: timegm() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + return -1; } *ret_value = t; #else @@ -456,7 +452,7 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ char errbuf[1024]; ERROR("bind plugin: mktime() failed: %s", sstrerror(errno, errbuf, sizeof(errbuf))); - return (-1); + 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 +461,7 @@ static int bind_xml_read_timestamp(const char *xpath_expression, /* {{{ */ #endif xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_xml_read_timestamp */ /* @@ -489,7 +485,7 @@ static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */ if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); - return (-1); + return -1; } num_entries = 0; @@ -544,7 +540,7 @@ static int bind_parse_generic_name_value(const char *xpath_expression, /* {{{ */ xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_parse_generic_name_value */ /* @@ -570,7 +566,7 @@ static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */ if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); - return (-1); + return -1; } num_entries = 0; @@ -607,7 +603,7 @@ static int bind_parse_generic_value_list(const char *xpath_expression, /* {{{ */ xmlXPathFreeObject(xpathObj); - return (0); + return 0; } /* }}} int bind_parse_generic_value_list */ /* @@ -632,7 +628,7 @@ static int bind_parse_generic_name_attr_value_list( if (xpathObj == NULL) { ERROR("bind plugin: Unable to evaluate XPath expression `%s'.", xpath_expression); - return (-1); + return -1; } num_entries = 0; @@ -679,7 +675,7 @@ 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, /* {{{ */ @@ -702,7 +698,7 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ 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,7 +713,7 @@ 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; } for (j = 0; j < view->zones_num; j++) { @@ -729,7 +725,7 @@ static int bind_xml_stats_handle_zone(int version, xmlDoc *doc, /* {{{ */ zone_name = NULL; if (j >= view->zones_num) - return (0); + return 0; zone_name = view->zones[j]; @@ -741,8 +737,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,7 +761,7 @@ 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, /* {{{ */ @@ -777,14 +773,14 @@ static int bind_xml_stats_search_zones(int version, xmlDoc *doc, /* {{{ */ 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); 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 +795,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 +810,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++) { @@ -829,7 +825,7 @@ static int bind_xml_stats_handle_view(int version, xmlDoc *doc, /* {{{ */ 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 +839,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 +855,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 +868,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 +890,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 +913,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,7 +926,7 @@ 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, /* {{{ */ @@ -944,14 +939,14 @@ static int bind_xml_stats_search_views(int version, xmlDoc *doc, /* {{{ */ 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); 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++) { @@ -968,7 +963,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, /* {{{ */ @@ -1271,7 +1266,7 @@ static int bind_xml_stats(int version, xmlDoc *doc, /* {{{ */ ¤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); @@ -1320,14 +1315,14 @@ static int bind_xml(const char *data) /* {{{ */ doc = xmlParseMemory(data, strlen(data)); if (doc == NULL) { ERROR("bind plugin: xmlParseMemory failed."); - return (-1); + return -1; } xpathCtx = xmlXPathNewContext(doc); if (xpathCtx == NULL) { ERROR("bind plugin: xmlXPathNewContext failed."); xmlFreeDoc(doc); - return (-1); + return -1; } // @@ -1379,7 +1374,7 @@ static int bind_xml(const char *data) /* {{{ */ xmlXPathFreeContext(xpathCtx); xmlFreeDoc(doc); - return (ret); + return ret; } // @@ -1391,13 +1386,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 +1440,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 +1449,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) @@ -1471,24 +1466,24 @@ static int bind_config_add_view_zone(cb_view_t *view, /* {{{ */ 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)); 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) /* {{{ */ @@ -1497,13 +1492,13 @@ static int bind_config_add_view(oconfig_item_t *ci) /* {{{ */ 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)); if (tmp == NULL) { ERROR("bind plugin: realloc failed."); - return (-1); + return -1; } views = tmp; tmp = views + views_num; @@ -1519,7 +1514,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 +1536,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 +1549,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 +1579,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,7 +1605,7 @@ static int bind_init(void) /* {{{ */ plugin_get_interval())); #endif - return (0); + return 0; } /* }}} int bind_init */ static int bind_read(void) /* {{{ */ @@ -1619,7 +1614,7 @@ static int bind_read(void) /* {{{ */ if (curl == NULL) { ERROR("bind plugin: I don't have a CURL object."); - return (-1); + return -1; } bind_buffer_fill = 0; @@ -1628,14 +1623,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); if (status != 0) - return (-1); + return -1; else - return (0); + return 0; } /* }}} int bind_read */ static int bind_shutdown(void) /* {{{ */ @@ -1645,7 +1640,7 @@ static int bind_shutdown(void) /* {{{ */ curl = NULL; } - return (0); + return 0; } /* }}} int bind_shutdown */ void module_register(void) { @@ -1654,5 +1649,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 : */