X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcurl_xml.c;h=39d6fd04b3c93f5ac9bec31df153f8093203e626;hb=6a1a62048b6d0d2ddf5c17295609d3ebf010f40b;hp=97b964bfbaa331cde2d991bbf8ea410771a8eeac;hpb=f995a5d563c2832553b7d172332028811a47db4a;p=collectd.git diff --git a/src/curl_xml.c b/src/curl_xml.c index 97b964bf..39d6fd04 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -50,7 +50,7 @@ struct cx_xpath_s /* {{{ */ char *path; char *type; cx_values_t *values; - int values_len; + size_t values_len; char *instance_prefix; char *instance; int is_table; @@ -240,7 +240,7 @@ static int cx_check_type (const data_set_t *ds, cx_xpath_t *xpath) /* {{{ */ if (ds->ds_num != xpath->values_len) { - WARNING ("curl_xml plugin: DataSet `%s' requires %i values, but config talks about %i", + WARNING ("curl_xml plugin: DataSet `%s' requires %zu values, but config talks about %zu", xpath->type, ds->ds_num, xpath->values_len); return (-1); } @@ -356,7 +356,7 @@ static int cx_handle_all_value_xpaths (xmlXPathContextPtr xpath_ctx, /* {{{ */ { value_t values[xpath->values_len]; int status; - int i; + size_t i; assert (xpath->values_len > 0); assert (xpath->values_len == vl->values_len); @@ -689,7 +689,7 @@ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */ xpath->values = (cx_values_t *) malloc (sizeof (cx_values_t) * ci->values_num); if (xpath->values == NULL) return (-1); - xpath->values_len = ci->values_num; + xpath->values_len = (size_t) ci->values_num; /* populate cx_values_t structure */ for (i = 0; i < ci->values_num; i++) @@ -698,17 +698,18 @@ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */ sstrncpy (xpath->values[i].path, ci->values[i].value.string, sizeof (xpath->values[i].path)); } - return (0); + return (0); } /* }}} cx_config_add_values */ -static int cx_config_add_xpath (cx_t *db, /* {{{ */ - oconfig_item_t *ci) +static int cx_config_add_xpath (cx_t *db, oconfig_item_t *ci) /* {{{ */ { cx_xpath_t *xpath; + char *name; + llentry_t *le; int status; int i; - xpath = (cx_xpath_t *) malloc (sizeof (*xpath)); + xpath = malloc (sizeof (*xpath)); if (xpath == NULL) { ERROR ("curl_xml plugin: malloc failed."); @@ -719,15 +720,16 @@ static int cx_config_add_xpath (cx_t *db, /* {{{ */ status = cf_util_get_string (ci, &xpath->path); if (status != 0) { - sfree (xpath); + cx_xpath_free (xpath); return (status); } /* error out if xpath->path is an empty string */ - if (*xpath->path == 0) + if (strlen (xpath->path) == 0) { ERROR ("curl_xml plugin: invalid xpath. " "xpath value can't be an empty string"); + cx_xpath_free (xpath); return (-1); } @@ -754,45 +756,49 @@ static int cx_config_add_xpath (cx_t *db, /* {{{ */ break; } /* for (i = 0; i < ci->children_num; i++) */ - if (status == 0 && xpath->type == NULL) + if (status != 0) { - WARNING ("curl_xml plugin: `Type' missing in `xpath' block."); - status = -1; + cx_xpath_free (xpath); + return status; } - if (status == 0) + if (xpath->type == NULL) { - char *name; - llentry_t *le; + WARNING ("curl_xml plugin: `Type' missing in `xpath' block."); + cx_xpath_free (xpath); + return -1; + } + if (db->list == NULL) + { + db->list = llist_create(); if (db->list == NULL) { - db->list = llist_create(); - if (db->list == NULL) - { - ERROR ("curl_xml plugin: list creation failed."); - return (-1); - } - } - - name = strdup(xpath->path); - if (name == NULL) - { - ERROR ("curl_xml plugin: strdup failed."); - return (-1); - } - - le = llentry_create (name, xpath); - if (le == NULL) - { - ERROR ("curl_xml plugin: llentry_create failed."); + ERROR ("curl_xml plugin: list creation failed."); + cx_xpath_free (xpath); return (-1); } + } + + name = strdup (xpath->path); + if (name == NULL) + { + ERROR ("curl_xml plugin: strdup failed."); + cx_xpath_free (xpath); + return (-1); + } - llist_append (db->list, le); + le = llentry_create (name, xpath); + if (le == NULL) + { + ERROR ("curl_xml plugin: llentry_create failed."); + cx_xpath_free (xpath); + sfree (name); + return (-1); } - return (status); + llist_append (db->list, le); + return (0); } /* }}} int cx_config_add_xpath */ static int cx_config_add_namespace (cx_t *db, /* {{{ */ @@ -897,8 +903,7 @@ static int cx_init_curl (cx_t *db) /* {{{ */ if (db->timeout >= 0) curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) db->timeout); else - curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, - CDTIME_T_TO_MS(plugin_get_interval())); + curl_easy_setopt (db->curl, CURLOPT_TIMEOUT_MS, (long) CDTIME_T_TO_MS(plugin_get_interval())); #endif return (0); @@ -941,6 +946,7 @@ static int cx_config_add_url (oconfig_item_t *ci) /* {{{ */ { ERROR ("curl_xml plugin: cx_config: " "Invalid key: %s", ci->key); + cx_free (db); return (-1); }