prelude-correlator/master: Update context directly from the __new__() method

[email protected] Fri, 18 Dec 2009 16:58:31 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit a55f1b4f2c7d89cebca62c34e02ad48d4dbab24d
Author: Yoann Vandoorselaere <[email protected]>
Date:   Thu Dec 17 11:01:30 2009 +0100

    Update context directly from the __new__() method


========================================

 PreludeCorrelator/context.py |   29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

========================================

diff --git a/PreludeCorrelator/context.py b/PreludeCorrelator/context.py
index a6be826..1d5075a 100644
--- a/PreludeCorrelator/context.py
+++ b/PreludeCorrelator/context.py
@@ -80,17 +80,11 @@ class Context(IDMEF, Timer):
                 IDMEF.__setstate__(self, dict)
 
         def __init__(self, name, options={}, update=False, idmef=None):
-                if update and _CONTEXT_TABLE.has_key(name):
-                        self._update_count += 1
-
-                        if idmef:
-                                self.addAlertReference(idmef)
-
-                        if Timer.running(self):
-                                Timer.reset(self)
-
+                if update and hasattr(self, "_name"):
                         return
 
+                self._expire = options.get("expire", 0)
+
                 self._update_count = 0
                 self._threshold = options.get("threshold", -1)
                 self._alert_on_expire = options.get("alert_on_expire", False)
@@ -104,13 +98,22 @@ class Context(IDMEF, Timer):
                 if idmef:
                         self.addAlertReference(idmef)
 
-                if options.has_key("expire"):
-                        Timer.setExpire(self, options["expire"])
+                if self._expire != 0:
+                        Timer.setExpire(self, self._expire)
                         Timer.start(self)
 
         def __new__(cls, name, options={}, update=False, idmef=None):
-                if update and _CONTEXT_TABLE.has_key(name):
-                        return _CONTEXT_TABLE[name]
+                if update:
+                        ctx = search(name)
+                        if ctx:
+                                ctx._update_count += 1
+                                if idmef:
+                                        ctx.addAlertReference(idmef)
+
+                                if ctx.running():
+                                        ctx.reset()
+
+                                return ctx
 
                 return super(Context, cls).__new__(cls)
 
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog