collectd.conf(5): Added a note about that trailing whitespace bug.
[collectd.git] / src / utils_ignorelist.c
index 1adfbc6..d002c7a 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * collectd - src/config_list.c
+ * collectd - src/utils_ignorelist.c
  * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
  *
  * This program is free software; you can redistribute it and/
  *     return;
  **/
 
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
 #include "common.h"
 #include "utils_debug.h"
 #include "utils_ignorelist.h"
@@ -67,7 +71,6 @@ typedef struct ignorelist_item_s ignorelist_item_t;
 struct ignorelist_s
 {
        int ignore;             /* ignore entries */
-       int num;                /* number of entries */
        ignorelist_item_t *head;        /* pointer to the first entry */
 };
 
@@ -81,8 +84,6 @@ static inline void ignorelist_append (ignorelist_t *il, ignorelist_item_t *item)
 
        item->next = il->head;
        il->head = item;
-
-       il->num++;
 }
 
 #if HAVE_REGEX_H
@@ -246,9 +247,7 @@ void ignorelist_free (ignorelist_t *il)
 
        for (this = il->head; this != NULL; this = next)
        {
-               DBG ("free - item = 0x%p, numlist %i", (void *) this, il->num);
                next = this->next;
-               il->num--;
 #if HAVE_REGEX_H
                if (this->rmatch != NULL)
                {
@@ -263,11 +262,7 @@ void ignorelist_free (ignorelist_t *il)
                }
                sfree (this);
        }
-#if COLLECTD_DEBUG
-       if (il->num != 0)
-               DBG ("after free numlist: %i", il->num);
-#endif
-       il->num = 0;
+
        sfree (il);
        il = NULL;
 } /* void ignorelist_destroy (ignorelist_t *il) */
@@ -287,21 +282,6 @@ void ignorelist_set_invert (ignorelist_t *il, int invert)
 } /* void ignorelist_set_invert (ignorelist_t *il, int ignore) */
 
 /*
- * get number of entries in the ignorelist_t
- * return int number
- */
-int ignorelist_num (ignorelist_t *il)
-{
-       if (il == NULL)
-       {
-               DBG("get num called with ignorelist_t == NULL");
-               return (0);
-       }
-
-       return (il->num);
-} /* int ignorelist_num (ignorelist_t *il) */
-
-/*
  * append entry into ignorelist_t
  * return 1 for success
  */
@@ -309,7 +289,6 @@ int ignorelist_add (ignorelist_t *il, const char *entry)
 {
        int ret;
        size_t entry_len;
-       char *entry_copy;
 
        if (il == NULL)
        {
@@ -330,6 +309,8 @@ int ignorelist_add (ignorelist_t *il, const char *entry)
        /* regex string is enclosed in "/.../" */
        if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
        {
+               char *entry_copy;
+
                /* We need to copy `entry' since it's const */
                entry_copy = smalloc (entry_len);
                memset (entry_copy, '\0', entry_len);
@@ -357,8 +338,13 @@ int ignorelist_match (ignorelist_t *il, const char *entry)
 {
        ignorelist_item_t *traverse;
 
+       assert (il != NULL);
+
        /* if no entries, collect all */
-       if (ignorelist_num(il) == 0)
+       if (il->head == NULL)
+               return (0);
+
+       if ((entry == NULL) || (strlen (entry) == 0))
                return (0);
 
        /* traverse list and check entries */