X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=ngircd-alex.git;a=blobdiff_plain;f=src%2Fngircd%2Flists.c;h=1101ea07421ed2f444583aac92f67297f5d7569c;hp=58c5d160df0913199c98547973a48cc97a4f69f0;hb=fea2194fc066af6f3b47fd94a93359dbd7aab8ff;hpb=4a5dfcc3ace54de033f16503065831ed62433b2d diff --git a/src/ngircd/lists.c b/src/ngircd/lists.c index 58c5d160..1101ea07 100644 --- a/src/ngircd/lists.c +++ b/src/ngircd/lists.c @@ -1,19 +1,21 @@ /* * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * Please read the file COPYING, README and AUTHORS for more information. - * - * Management of IRC lists: ban, invite, ... */ - #include "portab.h" +/** + * @file + * Management of IRC lists: ban, invite, etc. + */ + #include "imp.h" #include @@ -37,7 +39,7 @@ 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 */ }; @@ -63,7 +65,7 @@ Lists_GetNext(const struct list_elem *e) 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; @@ -81,7 +83,7 @@ Lists_Add(struct list_head *header, const char *Mask, bool OnlyOnce ) } strlcpy( newelem->mask, Mask, sizeof( newelem->mask )); - newelem->onlyonce = OnlyOnce; + newelem->valid_until = ValidUntil; newelem->next = e; header->first = newelem; @@ -208,27 +210,37 @@ Lists_MakeMask(const char *Pattern) } /* Lists_MakeMask */ - 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; - 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; - e = e->next; + e = next; } return false;