X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl_xml.c;h=074a2d199999ae1c60f12775fa5267a253d12e74;hb=75f6e826ccd930ac9834c55a208be2a194e38911;hp=43561a8379183cdfc8a7f609ef97c3656176e528;hpb=9655d4a6d9fa2c4f02032759b831e93933d68bd9;p=collectd.git diff --git a/src/curl_xml.c b/src/curl_xml.c index 43561a83..074a2d19 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -71,6 +71,7 @@ typedef struct cx_namespace_s cx_namespace_t; struct cx_s /* {{{ */ { char *instance; + char *plugin_name; char *host; char *url; @@ -188,6 +189,7 @@ static void cx_free(void *arg) /* {{{ */ sfree(db->buffer); sfree(db->instance); + sfree(db->plugin_name); sfree(db->host); sfree(db->url); @@ -208,7 +210,7 @@ static void cx_free(void *arg) /* {{{ */ sfree(db); } /* }}} void cx_free */ -static const char *cx_host(cx_t *db) /* {{{ */ +static const char *cx_host(const cx_t *db) /* {{{ */ { if (db->host == NULL) return hostname_g; @@ -369,7 +371,7 @@ static int cx_handle_all_value_xpaths(xmlXPathContextPtr xpath_ctx, /* {{{ */ status = cx_handle_single_value_xpath(xpath_ctx, xpath, ds, vl, i); if (status != 0) return -1; /* An error has been printed. */ - } /* for (i = 0; i < xpath->values_len; i++) */ + } /* for (i = 0; i < xpath->values_len; i++) */ plugin_dispatch_values(vl); vl->values = NULL; @@ -441,8 +443,8 @@ static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */ if (xpath->instance_prefix != NULL) { if (instance_node != NULL) { char *node_value = (char *)xmlNodeGetContent(instance_node->nodeTab[0]); - ssnprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s", - xpath->instance_prefix, node_value); + snprintf(vl->type_instance, sizeof(vl->type_instance), "%s%s", + xpath->instance_prefix, node_value); sfree(node_value); } else sstrncpy(vl->type_instance, xpath->instance_prefix, @@ -464,8 +466,8 @@ static int cx_handle_instance_xpath(xmlXPathContextPtr xpath_ctx, /* {{{ */ return 0; } /* }}} int cx_handle_instance_xpath */ -static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */ - char const *host, xmlXPathContextPtr xpath_ctx, +static int cx_handle_base_xpath(const cx_t *db, /* {{{ */ + xmlXPathContextPtr xpath_ctx, const data_set_t *ds, char *base_xpath, cx_xpath_t *xpath) { int total_nodes; @@ -505,10 +507,11 @@ static int cx_handle_base_xpath(char const *plugin_instance, /* {{{ */ /* set the values for the value_list */ vl.values_len = ds->ds_num; sstrncpy(vl.type, xpath->type, sizeof(vl.type)); - sstrncpy(vl.plugin, "curl_xml", sizeof(vl.plugin)); - sstrncpy(vl.host, host, sizeof(vl.host)); - if (plugin_instance != NULL) - sstrncpy(vl.plugin_instance, plugin_instance, sizeof(vl.plugin_instance)); + sstrncpy(vl.plugin, (db->plugin_name != NULL) ? db->plugin_name : "curl_xml", + sizeof(vl.plugin)); + sstrncpy(vl.host, cx_host(db), sizeof(vl.host)); + if (db->instance != NULL) + sstrncpy(vl.plugin_instance, db->instance, sizeof(vl.plugin_instance)); for (int i = 0; i < total_nodes; i++) { int status; @@ -545,8 +548,7 @@ static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */ ds = plugin_get_ds(xpath->type); if ((cx_check_type(ds, xpath) == 0) && - (cx_handle_base_xpath(db->instance, cx_host(db), xpath_ctx, ds, le->key, - xpath) == 0)) + (cx_handle_base_xpath(db, xpath_ctx, ds, le->key, xpath) == 0)) status = 0; /* we got atleast one success */ le = le->next; @@ -840,8 +842,8 @@ static int cx_init_curl(cx_t *db) /* {{{ */ return -1; } - ssnprintf(db->credentials, credentials_size, "%s:%s", db->user, - (db->pass == NULL) ? "" : db->pass); + snprintf(db->credentials, credentials_size, "%s:%s", db->user, + (db->pass == NULL) ? "" : db->pass); curl_easy_setopt(db->curl, CURLOPT_USERPWD, db->credentials); #endif @@ -908,6 +910,8 @@ static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */ if (strcasecmp("Instance", child->key) == 0) status = cf_util_get_string(child, &db->instance); + else if (strcasecmp("PluginName", child->key) == 0) + status = cf_util_get_string(child, &db->plugin_name); else if (strcasecmp("Host", child->key) == 0) status = cf_util_get_string(child, &db->host); else if (strcasecmp("User", child->key) == 0)