[prev in list] [next in list] [prev in thread] [next in thread] 

List:       prelude-cvslog
Subject:    [prelude-cvslog] r9867 -
From:       noreply () prelude-ids ! org
Date:       2007-08-29 14:34:43
Message-ID: 20070829143443.22FEAE19B5F () mail ! prelude-ids ! org
[Download RAW message or body]

Author: yoann
Date: 2007-08-29 16:34:41 +0200 (Wed, 29 Aug 2007)
New Revision: 9867

Modified:
   prelude-manager/trunk/plugins/filters/thresholding/thresholding.c
Log:
Do not share the tresholding hash accross thresholding plugin instance.

Previously, the shared hash would result in strange thresholding plugin
behavior if you had several instance of thresholding loaded.


Modified: prelude-manager/trunk/plugins/filters/thresholding/thresholding.c
===================================================================
--- prelude-manager/trunk/plugins/filters/thresholding/thresholding.c	2007-08-29 14:34:36 UTC (rev 9866)
+++ prelude-manager/trunk/plugins/filters/thresholding/thresholding.c	2007-08-29 14:34:41 UTC (rev 9867)
@@ -45,14 +45,9 @@
 
 
 typedef struct {
-        int count;
-        char *key;
-        prelude_timer_t timer;
-} hash_elem_t;
+        prelude_list_t path_list;
+        prelude_hash_t *path_value_hash;
 
-
-typedef struct {
-        prelude_list_t path_list;
         int threshold;
         int limit;
         int block;
@@ -61,8 +56,15 @@
 } filter_plugin_t;
 
 
-static int plugin_instance_no = 0;
-static prelude_hash_t *path_value_hash;
+typedef struct {
+        int count;
+        char *key;
+        prelude_timer_t timer;
+        filter_plugin_t *parent;
+} hash_elem_t;
+
+
+
 static manager_filter_plugin_t filter_plugin;
 
 
@@ -137,7 +139,7 @@
         hash_elem_t *helem = data;
 
         prelude_log_debug(3, "[%s]: release suppression.\n", helem->key);
-        prelude_hash_elem_destroy(path_value_hash, helem->key);
+        prelude_hash_elem_destroy(helem->parent->path_value_hash, helem->key);
 }
 
 
@@ -146,13 +148,14 @@
         int ret;
         hash_elem_t *helem;
 
-        helem = prelude_hash_get(path_value_hash, key);
+        helem = prelude_hash_get(plugin->path_value_hash, key);
         if ( ! helem ) {
                 helem = malloc(sizeof(*helem));
                 if ( ! helem )
                         return -1;
 
                 helem->count = 0;
+                helem->parent = plugin;
                 helem->key = strdup(key);
 
                 prelude_timer_init_list(&helem->timer);
@@ -160,7 +163,7 @@
                 prelude_timer_set_data(&helem->timer, helem);
                 prelude_timer_set_callback(&helem->timer, hash_entry_expire_cb);
 
-                ret = prelude_hash_set(path_value_hash, helem->key, helem);
+                ret = prelude_hash_set(plugin->path_value_hash, helem->key, helem);
         }
 
         helem->count++;
@@ -400,16 +403,16 @@
         int ret;
         filter_plugin_t *new;
 
-        if ( plugin_instance_no++ == 0 ) {
-                ret = prelude_hash_new(&path_value_hash, NULL, NULL, NULL, hash_entry_destroy);
-                if ( ret < 0 )
-                        return ret;
-        }
-
         new = calloc(1, sizeof(*new));
         if ( ! new )
                 return prelude_error_from_errno(errno);
 
+        ret = prelude_hash_new(&new->path_value_hash, NULL, NULL, NULL, hash_entry_destroy);
+        if ( ret < 0 ) {
+                free(new);
+                return ret;
+        }
+
         prelude_list_init(&new->path_list);
         prelude_plugin_instance_set_plugin_data(context, new);
 
@@ -430,8 +433,8 @@
         if ( plugin->hook_str )
                 free(plugin->hook_str);
 
-        if ( --plugin_instance_no == 0 )
-                prelude_hash_destroy(path_value_hash);
+        if ( plugin->path_value_hash )
+                prelude_hash_destroy(plugin->path_value_hash);
 
         free(plugin);
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic