Merge branch 'collectd-5.4' into collectd-5.5
authorFlorian Forster <octo@collectd.org>
Wed, 9 Dec 2015 08:49:55 +0000 (09:49 +0100)
committerFlorian Forster <octo@collectd.org>
Wed, 9 Dec 2015 08:49:55 +0000 (09:49 +0100)
src/curl_json.c
src/curl_xml.c

index 3ba5560..98ba0bb 100644 (file)
@@ -526,71 +526,68 @@ static int cj_config_add_key (cj_t *db, /* {{{ */
       break;
   } /* for (i = 0; i < ci->children_num; i++) */
 
-  while (status == 0)
+  if (status != 0)
   {
-    if (key->type == NULL)
-    {
-      WARNING ("curl_json plugin: `Type' missing in `Key' block.");
-      status = -1;
-    }
+    cj_key_free (key);
+    return (-1);
+  }
 
-    break;
-  } /* while (status == 0) */
+  if (key->type == NULL)
+  {
+    WARNING ("curl_json plugin: `Type' missing in `Key' block.");
+    cj_key_free (key);
+    return (-1);
+  }
 
   /* store path in a tree that will match the json map structure, example:
    * "httpd/requests/count",
    * "httpd/requests/current" ->
    * { "httpd": { "requests": { "count": $key, "current": $key } } }
    */
-  if (status == 0)
+  char *ptr;
+  char *name;
+  c_avl_tree_t *tree;
+
+  if (db->tree == NULL)
+    db->tree = cj_avl_create();
+
+  tree = db->tree;
+  ptr = key->path;
+  if (*ptr == '/')
+    ++ptr;
+
+  name = ptr;
+  while ((ptr = strchr (name, '/')) != NULL)
   {
-    char *ptr;
-    char *name;
     char ent[PATH_MAX];
-    c_avl_tree_t *tree;
+    c_avl_tree_t *value;
+    size_t len;
 
-    if (db->tree == NULL)
-      db->tree = cj_avl_create();
+    len = ptr - name;
+    if (len == 0)
+      break;
 
-    tree = db->tree;
-    ptr = key->path;
-    if (*ptr == '/')
-      ++ptr;
+    len = COUCH_MIN(len, sizeof (ent)-1);
+    sstrncpy (ent, name, len+1);
 
-    name = ptr;
-    while (*ptr)
+    if (c_avl_get (tree, ent, (void *) &value) != 0)
     {
-      if (*ptr == '/')
-      {
-        c_avl_tree_t *value;
-        int len;
-
-        len = ptr-name;
-        if (len == 0)
-          break;
-        len = COUCH_MIN(len, sizeof (ent)-1);
-        sstrncpy (ent, name, len+1);
-
-        if (c_avl_get (tree, ent, (void *) &value) != 0)
-        {
-          value = cj_avl_create ();
-          c_avl_insert (tree, strdup (ent), value);
-        }
-
-        tree = value;
-        name = ptr+1;
-      }
-      ++ptr;
-    }
-    if (*name)
-      c_avl_insert (tree, strdup(name), key);
-    else
-    {
-      ERROR ("curl_json plugin: invalid key: %s", key->path);
-      status = -1;
+      value = cj_avl_create ();
+      c_avl_insert (tree, strdup (ent), value);
     }
+
+    tree = value;
+    name = ptr + 1;
+  }
+
+  if (strlen (name) == 0)
+  {
+    ERROR ("curl_json plugin: invalid key: %s", key->path);
+    cj_key_free (key);
+    return (-1);
   }
 
+  c_avl_insert (tree, strdup (name), key);
   return (status);
 } /* }}} int cj_config_add_key */
 
index efaf290..3ffb71c 100644 (file)
@@ -701,14 +701,15 @@ static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */
   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,16 +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");
-    sfree (xpath);
+    cx_xpath_free (xpath);
     return (-1);
   }
 
@@ -755,51 +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.");
-        sfree (xpath->path);
-        sfree (xpath);
-        return (-1);
-      }
-    }
-
-    name = strdup(xpath->path);
-    if (name == NULL)
-    {
-        ERROR ("curl_xml plugin: strdup failed.");
-        sfree (xpath->path);
-        sfree (xpath);
-        return (-1);
-    }
-
-    le = llentry_create (name, xpath);
-    if (le == NULL)
-    {
-      ERROR ("curl_xml plugin: llentry_create failed.");
-      sfree (xpath->path);
-      sfree (xpath);
+      ERROR ("curl_xml plugin: list creation failed.");
+      cx_xpath_free (xpath);
       return (-1);
     }
+  }
 
-    llist_append (db->list, le);
+  name = strdup (xpath->path);
+  if (name == NULL)
+  {
+    ERROR ("curl_xml plugin: strdup failed.");
+    cx_xpath_free (xpath);
+    return (-1);
   }
 
-  return (status);
+  le = llentry_create (name, xpath);
+  if (le == NULL)
+  {
+    ERROR ("curl_xml plugin: llentry_create failed.");
+    cx_xpath_free (xpath);
+    sfree (name);
+    return (-1);
+  }
+
+  llist_append (db->list, le);
+  return (0);
 } /* }}} int cx_config_add_xpath */
 
 static int cx_config_add_namespace (cx_t *db, /* {{{ */