]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Lists: change "only once" property into "valid until"
authorAlexander Barton <alex@barton.de>
Sat, 24 Dec 2011 12:34:25 +0000 (13:34 +0100)
committerAlexander Barton <alex@barton.de>
Sat, 24 Dec 2011 12:34:25 +0000 (13:34 +0100)
The old "only once" true/false behavior is still supported, so there
are no other code changes required.

src/ngircd/lists.c
src/ngircd/lists.h

index b30326dea331b43d24b6951fba6eb1427f6de04c..1101ea07421ed2f444583aac92f67297f5d7569c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2005 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,7 +39,7 @@
 struct list_elem {
        struct list_elem *next;
        char mask[MASK_LEN];
 struct list_elem {
        struct list_elem *next;
        char mask[MASK_LEN];
-       bool onlyonce;
+       time_t valid_until;     /** 0: unlimited; 1: once; t(>1): until t */
 };
 
 
 };
 
 
@@ -65,7 +65,7 @@ Lists_GetNext(const struct list_elem *e)
 
 
 bool
 
 
 bool
-Lists_Add(struct list_head *header, const char *Mask, bool OnlyOnce )
+Lists_Add(struct list_head *header, const char *Mask, time_t ValidUntil )
 {
        struct list_elem *e, *newelem;
 
 {
        struct list_elem *e, *newelem;
 
@@ -83,7 +83,7 @@ Lists_Add(struct list_head *header, const char *Mask, bool OnlyOnce )
        }
 
        strlcpy( newelem->mask, Mask, sizeof( newelem->mask ));
        }
 
        strlcpy( newelem->mask, Mask, sizeof( newelem->mask ));
-       newelem->onlyonce = OnlyOnce;
+       newelem->valid_until = ValidUntil;
        newelem->next = e;
        header->first = newelem;
 
        newelem->next = e;
        header->first = newelem;
 
@@ -213,23 +213,34 @@ Lists_MakeMask(const char *Pattern)
 bool
 Lists_Check( struct list_head *header, CLIENT *Client)
 {
 bool
 Lists_Check( struct list_head *header, CLIENT *Client)
 {
-       struct list_elem *e, *last;
+       struct list_elem *e, *last, *next;
 
        assert( header != NULL );
 
        e = header->first;
        last = NULL;
 
 
        assert( header != NULL );
 
        e = header->first;
        last = NULL;
 
-       while( e ) {
-               if( Match( e->mask, Client_Mask( Client ))) {
-                       if( e->onlyonce ) { /* delete entry */
-                               LogDebug("Deleted \"%s\" from list", e->mask);
+       while (e) {
+               next = e->next;
+               if (e->valid_until > 1 && e->valid_until < time(NULL)) {
+                       /* Entry is expired, delete it */
+                       LogDebug("Deleted \"%s\" from list (expired).",
+                                e->mask);
+                       Lists_Unlink(header, last, e);
+                       e = next;
+                       continue;
+               }
+               if (Match(e->mask, Client_Mask(Client))) {
+                       if (e->valid_until == 1 ) {
+                               /* Entry is valid only once, delete it */
+                               LogDebug("Deleted \"%s\" from list (used).",
+                                        e->mask);
                                Lists_Unlink(header, last, e);
                        }
                        return true;
                }
                last = e;
                                Lists_Unlink(header, last, e);
                        }
                        return true;
                }
                last = e;
-               e = e->next;
+               e = next;
        }
 
        return false;
        }
 
        return false;
index 28f5478d083ccfb30dc9de0cc24331e01fa6371b..7422d601d7acdaf0af0dd9353736d7c2756e218b 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,7 +32,7 @@ GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *));
 GLOBAL bool Lists_Check PARAMS((struct list_head *head, CLIENT *client ));
 GLOBAL bool Lists_CheckDupeMask PARAMS((const struct list_head *head, const char *mask ));
 
 GLOBAL bool Lists_Check PARAMS((struct list_head *head, CLIENT *client ));
 GLOBAL bool Lists_CheckDupeMask PARAMS((const struct list_head *head, const char *mask ));
 
-GLOBAL bool Lists_Add PARAMS((struct list_head *header, const char *Mask, bool OnlyOnce ));
+GLOBAL bool Lists_Add PARAMS((struct list_head *header, const char *Mask, time_t ValidUntil ));
 GLOBAL void Lists_Del PARAMS((struct list_head *head, const char *Mask ));
 
 GLOBAL bool Lists_AlreadyRegistered PARAMS(( const struct list_head *head, const char *Mask));
 GLOBAL void Lists_Del PARAMS((struct list_head *head, const char *Mask ));
 
 GLOBAL bool Lists_AlreadyRegistered PARAMS(( const struct list_head *head, const char *Mask));