Commit Diff


commit - 5877bca4bcea97d50c6c2997ac2914d78552c6a6
commit + fa7bb2790a1588e49d05cf3404220c3a63669514
blob - d05095bb821f489bbc492b2541ce2626f15aa7de
blob + 777ba20fb764c76bee3b36531c9bd11733110ddb
--- src/ngircd/channel.c
+++ src/ngircd/channel.c
@@ -17,7 +17,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: channel.c,v 1.59 2006/10/06 21:32:58 fw Exp $";
+static char UNUSED id[] = "$Id: channel.c,v 1.60 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -68,6 +68,22 @@ Channel_Init( void )
 	My_Channels = NULL;
 	My_Cl2Chan = NULL;
 } /* Channel_Init */
+
+
+GLOBAL struct list_head *
+Channel_GetListBans(CHANNEL *c)
+{
+	assert(c != NULL);
+	return &c->list_bans;
+}
+
+
+GLOBAL struct list_head *
+Channel_GetListInvites(CHANNEL *c)
+{
+	assert(c != NULL);
+	return &c->list_invites;
+}
 
 
 GLOBAL void
@@ -716,7 +732,7 @@ Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Cl
 	if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = false;
 
 	/* Is the client banned? */
-	if( Lists_CheckBanned( From, Chan ))
+	if( Lists_Check(&Chan->list_bans, From))
 	{
 		/* Client is banned, but is he channel operator or has voice? */
 		if(( ! has_voice ) && ( ! is_op )) ok = false;
@@ -879,8 +895,70 @@ Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client
 		
 	return true;
 } /* Remove_Client */
+
+
+GLOBAL bool
+Channel_AddBan(CHANNEL *c, const char *mask )
+{
+	struct list_head *h = Channel_GetListBans(c);
+	return Lists_Add(h, mask, false);
+}
 
 
+GLOBAL bool
+Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
+{
+	struct list_head *h = Channel_GetListInvites(c);
+	return Lists_Add(h, mask, onlyonce);
+}
+
+
+static bool
+ShowInvitesBans(struct list_head *head, CLIENT *Client, CHANNEL *Channel, bool invite)
+{
+	struct list_elem *e;
+	char *msg = invite ? RPL_INVITELIST_MSG : RPL_BANLIST_MSG;
+	char *msg_end;
+
+	assert( Client != NULL );
+	assert( Channel != NULL );
+
+	e = Lists_GetFirst(head);
+	while (e) {
+		if( ! IRC_WriteStrClient( Client, msg, Client_ID( Client ),
+				Channel_Name( Channel ), Lists_GetMask(e) )) return DISCONNECTED;
+		e = Lists_GetNext(e);
+	}
+
+	msg_end = invite ? RPL_ENDOFINVITELIST_MSG : RPL_ENDOFBANLIST_MSG;
+	return IRC_WriteStrClient( Client, msg_end, Client_ID( Client ), Channel_Name( Channel ));
+}
+
+
+GLOBAL bool
+Channel_ShowBans( CLIENT *Client, CHANNEL *Channel )
+{
+	struct list_head *h;
+
+	assert( Channel != NULL );
+
+	h = Channel_GetListBans(Channel);
+	return ShowInvitesBans(h, Client, Channel, false);
+}
+
+
+GLOBAL bool
+Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel )
+{
+	struct list_head *h;
+
+	assert( Channel != NULL );
+
+	h = Channel_GetListInvites(Channel);
+	return ShowInvitesBans(h, Client, Channel, true);
+}
+
+
 static CL2CHAN *
 Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan )
 {
@@ -910,7 +988,7 @@ static bool
 Delete_Channel( CHANNEL *Chan )
 {
 	/* Channel-Struktur loeschen */
-	
+
 	CHANNEL *chan, *last_chan;
 
 	last_chan = NULL;
@@ -926,13 +1004,14 @@ Delete_Channel( CHANNEL *Chan )
 	Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name );
 
 	/* Invite- und Ban-Lists aufraeumen */
-	Lists_DeleteChannel( chan );
+	Lists_Free( &chan->list_bans );
+	Lists_Free( &chan->list_invites );
 
 	/* Neu verketten und freigeben */
 	if( last_chan ) last_chan->next = chan->next;
 	else My_Channels = chan->next;
 	free( chan );
-		
+
 	return true;
 } /* Delete_Channel */
 
blob - e6e3d40e51e32222376576f8d16d0eab05e8e1ed
blob + 6117c669121a0d3aa1ea06b604851c21732abce0
--- src/ngircd/channel.h
+++ src/ngircd/channel.h
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: channel.h,v 1.31 2006/10/06 21:32:58 fw Exp $
+ * $Id: channel.h,v 1.32 2006/12/07 17:57:20 fw Exp $
  *
  * Channel management (header)
  */
@@ -20,6 +20,7 @@
 
 #if defined(__channel_c__) | defined(S_SPLINT_S)
 
+#include "lists.h"
 #include "defines.h"
 #include "array.h"
 
@@ -36,6 +37,8 @@ typedef struct _CHANNEL
 #endif
 	char key[CLIENT_PASS_LEN];	/* Channel key ("password", mode "k" ) */
 	unsigned long maxusers;		/* Maximum number of members (mode "l") */
+	struct list_head list_bans;	/* list head of banned users */
+	struct list_head list_invites;	/* list head of invited users */
 } CHANNEL;
 
 typedef struct _CLIENT2CHAN
@@ -53,6 +56,8 @@ typedef POINTER CL2CHAN;
 
 #endif
 
+GLOBAL struct list_head *Channel_GetListBans PARAMS((CHANNEL *c));
+GLOBAL struct list_head *Channel_GetListInvites PARAMS((CHANNEL *c));
 
 GLOBAL void Channel_Init PARAMS(( void ));
 GLOBAL void Channel_InitPredefined PARAMS((  void ));
@@ -114,8 +119,10 @@ GLOBAL unsigned int Channel_TopicTime PARAMS(( CHANNEL
 GLOBAL char *Channel_TopicWho PARAMS(( CHANNEL *Chan ));
 #endif
 
+GLOBAL bool Channel_AddInvite PARAMS((CHANNEL *c, const char *Mask, bool OnlyOnce ));
+GLOBAL bool Channel_AddBan PARAMS((CHANNEL *c, const char *Mask ));
 
+GLOBAL bool Channel_ShowBans PARAMS((CLIENT *client, CHANNEL *c));
+GLOBAL bool Channel_ShowInvites PARAMS((CLIENT *client, CHANNEL *c));
 #endif
-
-
 /* -eof- */
blob - 5a19628525f972fa5bdea95601ad9002fb599235
blob + 7b92c2b009bd165594a3272d60428fcd4dea9af1
--- src/ngircd/irc-channel.c
+++ src/ngircd/irc-channel.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-channel.c,v 1.38 2006/11/05 13:03:48 fw Exp $";
+static char UNUSED id[] = "$Id: irc-channel.c,v 1.39 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -122,8 +122,8 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
 				chan = Channel_Search( channame );
 				assert( chan != NULL );
 
-				is_banned = Lists_CheckBanned( target, chan );
-				is_invited = Lists_CheckInvited( target, chan );
+				is_banned = Lists_Check(Channel_GetListBans(chan), target );
+				is_invited = Lists_Check(Channel_GetListInvites(chan), target );
 
 				/* Testen, ob Client gebanned ist */
 				if(( is_banned == true) &&  ( is_invited == false ))
@@ -178,7 +178,7 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req )
 			 * commands) in this list become deleted when a user
 			 * joins a channel this way. */
 			chan = Channel_Search( channame );
-			if( chan != NULL ) (void)Lists_CheckInvited( target, chan );
+			if( chan != NULL ) (void)Lists_Check(Channel_GetListInvites(chan), target);
 		}
 
 		/* Channel joinen (und ggf. anlegen) */
blob - 038e13dfa4f42319619f2def78ecaff9124f12bc
blob + 75f99d9eb7b465a2a8ca907823500e563be658b1
--- src/ngircd/irc-mode.c
+++ src/ngircd/irc-mode.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-mode.c,v 1.47 2006/10/06 21:32:58 fw Exp $";
+static char UNUSED id[] = "$Id: irc-mode.c,v 1.48 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -477,7 +477,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Or
 					Req->argv[arg_arg][0] = '\0';
 					arg_arg++;
 				}
-				else Lists_ShowInvites( Origin, Channel );
+				else Channel_ShowInvites( Origin, Channel );
 				break;
 
 			case 'b': /* Ban lists */
@@ -493,7 +493,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Or
 					Req->argv[arg_arg][0] = '\0';
 					arg_arg++;
 				}
-				else Lists_ShowBans( Origin, Channel );
+				else Channel_ShowBans( Origin, Channel );
 				break;
 
 			default:
@@ -644,11 +644,13 @@ Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *C
 
 	mask = Lists_MakeMask( Pattern );
 
-	already = Lists_IsInviteEntry( mask, Channel );
-	
-	if( ! Lists_AddInvited( mask, Channel, false )) return CONNECTED;
-	
-	if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
+	already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask );
+	if (!already) {
+		if( ! Channel_AddInvite(Channel, mask, false ))
+			return CONNECTED;
+	}
+	if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
+		return CONNECTED;
 
 	return Send_ListChange( "+I", Prefix, Client, Channel, mask );
 } /* Add_Invite */
@@ -666,12 +668,14 @@ Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Chan
 
 	mask = Lists_MakeMask( Pattern );
 
-	already = Lists_IsBanEntry( mask, Channel );
+	already = Lists_CheckDupeMask(Channel_GetListBans(Channel), mask );
+	if (!already) {
+		if( ! Channel_AddBan(Channel, mask))
+			return CONNECTED;
+	}
+	if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
+		return CONNECTED;
 
-	if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
-
-	if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
-
 	return Send_ListChange( "+b", Prefix, Client, Channel, mask );
 } /* Add_Ban */
 
@@ -686,7 +690,7 @@ Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *C
 	assert( Pattern != NULL );
 
 	mask = Lists_MakeMask( Pattern );
-	Lists_DelInvited( mask, Channel );
+	Lists_Del(Channel_GetListInvites(Channel), mask);
 	return Send_ListChange( "-I", Prefix, Client, Channel, mask );
 } /* Del_Invite */
 
@@ -701,7 +705,7 @@ Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Chan
 	assert( Pattern != NULL );
 
 	mask = Lists_MakeMask( Pattern );
-	Lists_DelBanned( mask, Channel );
+	Lists_Del(Channel_GetListBans(Channel), mask);
 	return Send_ListChange( "-b", Prefix, Client, Channel, mask );
 } /* Del_Ban */
 
blob - e3744a272b5da168ce8fb225cf981d043167a660
blob + ac477793c0ef1aad708607dce89dde74b3a93e47
--- src/ngircd/irc-op.c
+++ src/ngircd/irc-op.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-op.c,v 1.16 2006/08/12 11:58:21 fw Exp $";
+static char UNUSED id[] = "$Id: irc-op.c,v 1.17 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -99,11 +99,12 @@ IRC_INVITE( CLIENT *Client, REQUEST *Req )
 		if( Channel_IsMemberOf( chan, target )) return IRC_WriteStrClient( from, ERR_USERONCHANNEL_MSG, Client_ID( from ), Req->argv[0], Req->argv[1] );
 
 		/* If the target user is banned on that channel: remember invite */
-		if( Lists_CheckBanned( target, chan )) remember = true;
+		if( Lists_Check(Channel_GetListBans(chan), target )) remember = true;
 
 		if (remember) {
 			/* We must remember this invite */
-			if( ! Lists_AddInvited( Client_Mask( target ), chan, true)) return CONNECTED;
+			if( ! Channel_AddInvite(chan, Client_Mask( target ), true))
+				return CONNECTED;
 		}
 	}
 
blob - c58e7dcb565eafc71f205f2c476e9ea5bba7c8b5
blob + da9ba978b8b8b8ab442a05d259d474a5f3f2ac06
--- src/ngircd/irc-server.c
+++ src/ngircd/irc-server.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: irc-server.c,v 1.42 2006/12/02 14:10:48 fw Exp $";
+static char UNUSED id[] = "$Id: irc-server.c,v 1.43 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -39,8 +39,52 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.42 20
 
 #include "exp.h"
 #include "irc-server.h"
+
+
+#ifdef IRCPLUS
+static bool
+Synchronize_Lists( CLIENT *Client )
+{
+	CHANNEL *c;
+	struct list_head *head;
+	struct list_elem *elem;
+
+	assert( Client != NULL );
+
+	c = Channel_First();
+
+	while (c) {
+		head = Channel_GetListBans(c);
+
+		elem = Lists_GetFirst(head);
+		while (elem) {
+			if( ! IRC_WriteStrClient( Client, "MODE %s +b %s",
+					Channel_Name(c), Lists_GetMask(elem)))
+			{
+				return false;
+			}
+			elem = Lists_GetNext(elem);
+		}
+
+		head = Channel_GetListInvites(c);
+		elem = Lists_GetFirst(head);
+		while (elem) {
+			if( ! IRC_WriteStrClient( Client, "MODE %s +I %s",
+					Channel_Name( c ), Lists_GetMask(elem)))
+			{
+				return false;
+			}
+			elem = Lists_GetNext(elem);
+		}
+		c = Channel_Next(c);
+	}
+	return true;
+}
+#endif
 
 
+
+
 /**
  * Handler for the IRC command "SERVER".
  * See RFC 2813 section 4.1.2.
@@ -268,9 +312,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req )
 			    "Synchronizing INVITE- and BAN-lists ...");
 #endif
 			/* Synchronize INVITE- and BAN-lists */
-			if (! Lists_SendInvites(Client))
-				return DISCONNECTED;
-			if (! Lists_SendBans(Client))
+			if (!Synchronize_Lists(Client))
 				return DISCONNECTED;
 		}
 #endif
blob - 3caabbb374514faa710949e675e552360dbf37da
blob + 4f9a8855e043510df2c10a939ca115ef6743e6da
--- src/ngircd/lists.c
+++ src/ngircd/lists.c
@@ -14,7 +14,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: lists.c,v 1.19 2006/08/12 11:56:24 fw Exp $";
+static char UNUSED id[] = "$Id: lists.c,v 1.20 2006/12/07 17:57:20 fw Exp $";
 
 #include "imp.h"
 #include <assert.h>
@@ -35,328 +35,133 @@ static char UNUSED id[] = "$Id: lists.c,v 1.19 2006/08
 #include "exp.h"
 #include "lists.h"
 
-
 #define MASK_LEN	(2*CLIENT_HOST_LEN)
 
-
-typedef struct _C2C
-{
-	struct _C2C *next;
+struct list_elem {
+	struct list_elem *next;
 	char mask[MASK_LEN];
-	CHANNEL *channel;
 	bool onlyonce;
-} C2C;
+};
 
 
-static C2C *My_Invites, *My_Bans;
-
-
-static C2C *New_C2C PARAMS(( char *Mask, CHANNEL *Chan, bool OnlyOnce ));
-
-static bool Check_List PARAMS(( C2C **Cl2Chan, CLIENT *Client, CHANNEL *Chan ));
-static bool Already_Registered PARAMS(( C2C *Cl2Chan, char *Mask, CHANNEL *Chan ));
-
-
-
-GLOBAL void
-Lists_Init( void )
+GLOBAL const char *
+Lists_GetMask(const struct list_elem *e)
 {
-	/* Modul initialisieren */
+	return e->mask;
+}
 
-	My_Invites = My_Bans = NULL;
-} /* Lists_Init */
 
-
-GLOBAL void
-Lists_Exit( void )
+GLOBAL struct list_elem*
+Lists_GetFirst(const struct list_head *h)
 {
-	/* Modul abmelden */
+	return h->first;
+}
 
-	C2C *c2c, *next;
 
-	/* Invite-Lists freigeben */
-	c2c = My_Invites;
-	while( c2c )
-	{
-		next = c2c->next;
-		free( c2c );
-		c2c = next;
-	}
-
-	/* Ban-Lists freigeben */
-	c2c = My_Bans;
-	while( c2c )
-	{
-		next = c2c->next;
-		free( c2c );
-		c2c = next;
-	}
-} /* Lists_Exit */
-
-
-GLOBAL bool
-Lists_CheckInvited( CLIENT *Client, CHANNEL *Chan )
+GLOBAL struct list_elem*
+Lists_GetNext(const struct list_elem *e)
 {
-	return Check_List( &My_Invites, Client, Chan );
-} /* Lists_CheckInvited */
+	return e->next;
+}
 
 
-GLOBAL bool
-Lists_IsInviteEntry( char *Mask, CHANNEL *Chan )
+bool
+Lists_Add(struct list_head *header, const char *Mask, bool OnlyOnce )
 {
+	struct list_elem *e, *newelem;
+
+	assert( header != NULL );
 	assert( Mask != NULL );
-	assert( Chan != NULL );
 
-	return Already_Registered( My_Invites, Mask, Chan );
-} /* Lists_IsInviteEntry */
+	if (Lists_CheckDupeMask(header, Mask )) return true;
 
+	e = Lists_GetFirst(header);
 
-GLOBAL bool
-Lists_AddInvited( char *Mask, CHANNEL *Chan, bool OnlyOnce )
-{
-	C2C *c2c;
-
-	assert( Mask != NULL );
-	assert( Chan != NULL );
-
-	if( Already_Registered( My_Invites, Mask, Chan )) return true;
-	
-	c2c = New_C2C( Mask, Chan, OnlyOnce );
-	if( ! c2c )
-	{
-		Log( LOG_ERR, "Can't add new invite list entry!" );
-		return false;
+	newelem = malloc(sizeof(struct list_elem));
+	if( ! newelem ) {
+		Log( LOG_EMERG, "Can't allocate memory for new Ban/Invite entry!" );
+		return NULL;
 	}
 
-	/* verketten */
-	c2c->next = My_Invites;
-	My_Invites = c2c;
+	strlcpy( newelem->mask, Mask, sizeof( newelem->mask ));
+	newelem->onlyonce = OnlyOnce;
+	newelem->next = e;
+	header->first = newelem;
 
-	Log( LOG_DEBUG, "Added \"%s\" to invite list for \"%s\".", Mask, Channel_Name( Chan ));
+	LogDebug("Added \"%s\" to invite list", Mask);
 	return true;
-} /* Lists_AddInvited */
+}
 
 
-GLOBAL void
-Lists_DelInvited( char *Mask, CHANNEL *Chan )
+static void
+Lists_Unlink(struct list_head *header, struct list_elem *p, struct list_elem *victim)
 {
-	C2C *c2c, *last, *next;
+	assert(victim != NULL);
+	assert(header != NULL);
 
-	assert( Mask != NULL );
-	assert( Chan != NULL );
+	if (p) p->next = victim->next;
+	else header->first = victim->next;
 
-	last = NULL;
-	c2c = My_Invites;
-	while( c2c )
-	{
-		next = c2c->next;
-		if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 ))
-		{
-			/* dieser Eintrag muss geloescht werden */
-			Log( LOG_DEBUG, "Deleted \"%s\" from invite list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-			if( last ) last->next = next;
-			else My_Invites = next;
-			free( c2c );
-		}
-		else last = c2c;
-		c2c = next;
-	}
-} /* Lists_DelInvited */
+	free(victim);
+}
 
 
-GLOBAL bool
-Lists_ShowInvites( CLIENT *Client, CHANNEL *Channel )
+GLOBAL void
+Lists_Del(struct list_head *header, const char *Mask)
 {
-	C2C *c2c;
+	struct list_elem *e, *last, *victim;
 
-	assert( Client != NULL );
-	assert( Channel != NULL );
+	assert( header != NULL );
+	assert( Mask != NULL );
 
-	c2c = My_Invites;
-	while( c2c )
-	{
-		if( c2c->channel == Channel )
-		{
-			/* Eintrag fuer Channel gefunden; ausgeben: */
-			if( ! IRC_WriteStrClient( Client, RPL_INVITELIST_MSG, Client_ID( Client ), Channel_Name( Channel ), c2c->mask )) return DISCONNECTED;
+	last = NULL;
+	e = Lists_GetFirst(header);
+	while( e ) {
+		if(strcasecmp( e->mask, Mask ) == 0 ) {
+			LogDebug("Deleted \"%s\" from list", e->mask);
+			victim = e;
+			e = victim->next;
+			Lists_Unlink(header, last, victim);
+			continue;
 		}
-		c2c = c2c->next;
+		last = e;
+		e = e->next;
 	}
-	return IRC_WriteStrClient( Client, RPL_ENDOFINVITELIST_MSG, Client_ID( Client ), Channel_Name( Channel ));
-} /* Lists_ShowInvites */
+}
 
 
-GLOBAL bool
-Lists_SendInvites( CLIENT *Client )
+GLOBAL void
+Lists_Free(struct list_head *head)
 {
-	C2C *c2c;
-	
-	assert( Client != NULL );
-	
-	c2c = My_Invites;
-	while( c2c )
-	{
-		if( ! IRC_WriteStrClient( Client, "MODE %s +I %s", Channel_Name( c2c->channel ), c2c->mask )) return DISCONNECTED;
-		c2c = c2c->next;
-	}
-	return CONNECTED;
-} /* Lists_SendInvites */
+	struct list_elem *e, *victim;
 
+	assert(head != NULL);
 
-GLOBAL bool
-Lists_SendBans( CLIENT *Client )
-{
-	C2C *c2c;
-	
-	assert( Client != NULL );
-	
-	c2c = My_Bans;
-	while( c2c )
-	{
-		if( ! IRC_WriteStrClient( Client, "MODE %s +b %s", Channel_Name( c2c->channel ), c2c->mask )) return DISCONNECTED;
-		c2c = c2c->next;
+	e = head->first;
+	head->first = NULL;
+	while (e) {
+		LogDebug("Deleted \"%s\" from invite list" , e->mask);
+		victim = e;
+		e = e->next;
+		free( victim );
 	}
-	return CONNECTED;
-} /* Lists_SendBans */
+}
 
 
 GLOBAL bool
-Lists_CheckBanned( CLIENT *Client, CHANNEL *Chan )
+Lists_CheckDupeMask(const struct list_head *h, const char *Mask )
 {
-	return Check_List( &My_Bans, Client, Chan );
-} /* Lists_CheckBanned */
-
-
-GLOBAL bool
-Lists_IsBanEntry( char *Mask, CHANNEL *Chan )
-{
-	assert( Mask != NULL );
-	assert( Chan != NULL );
-	
-	return Already_Registered( My_Bans, Mask, Chan );
-} /* Lists_IsBanEntry */
-
-
-GLOBAL bool
-Lists_AddBanned( char *Mask, CHANNEL *Chan )
-{
-	C2C *c2c;
-
-	assert( Mask != NULL );
-	assert( Chan != NULL );
-
-	if( Already_Registered( My_Bans, Mask, Chan )) return true;
-
-	c2c = New_C2C( Mask, Chan, false );
-	if( ! c2c )
-	{
-		Log( LOG_ERR, "Can't add new ban list entry!" );
-		return false;
+	struct list_elem *e;
+	e = h->first;
+	while (e) {
+		if (strcasecmp( e->mask, Mask ) == 0 )
+			return true;
+		e = e->next;
 	}
+	return false;
+}
 
-	/* verketten */
-	c2c->next = My_Bans;
-	My_Bans = c2c;
 
-	Log( LOG_DEBUG, "Added \"%s\" to ban list for \"%s\".", Mask, Channel_Name( Chan ));
-	return true;
-} /* Lists_AddBanned */
-
-
-GLOBAL void
-Lists_DelBanned( char *Mask, CHANNEL *Chan )
-{
-	C2C *c2c, *last, *next;
-
-	assert( Mask != NULL );
-	assert( Chan != NULL );
-
-	last = NULL;
-	c2c = My_Bans;
-	while( c2c )
-	{
-		next = c2c->next;
-		if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 ))
-		{
-			/* dieser Eintrag muss geloescht werden */
-			Log( LOG_DEBUG, "Deleted \"%s\" from ban list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-			if( last ) last->next = next;
-			else My_Bans = next;
-			free( c2c );
-		}
-		else last = c2c;
-		c2c = next;
-	}
-} /* Lists_DelBanned */
-
-
-GLOBAL bool
-Lists_ShowBans( CLIENT *Client, CHANNEL *Channel )
-{
-	C2C *c2c;
-
-	assert( Client != NULL );
-	assert( Channel != NULL );
-
-	c2c = My_Bans;
-	while( c2c )
-	{
-		if( c2c->channel == Channel )
-		{
-			/* Eintrag fuer Channel gefunden; ausgeben: */
-			if( ! IRC_WriteStrClient( Client, RPL_BANLIST_MSG, Client_ID( Client ), Channel_Name( Channel ), c2c->mask )) return DISCONNECTED;
-		}
-		c2c = c2c->next;
-	}
-	return IRC_WriteStrClient( Client, RPL_ENDOFBANLIST_MSG, Client_ID( Client ), Channel_Name( Channel ));
-} /* Lists_ShowBans */
-
-
-GLOBAL void
-Lists_DeleteChannel( CHANNEL *Chan )
-{
-	/* Channel wurde geloescht, Invite- und Ban-Lists aufraeumen */
-
-	C2C *c2c, *last, *next;
-
-	/* Invite-List */
-	last = NULL;
-	c2c = My_Invites;
-	while( c2c )
-	{
-		next = c2c->next;
-		if( c2c->channel == Chan )
-		{
-			/* dieser Eintrag muss geloescht werden */
-			Log( LOG_DEBUG, "Deleted \"%s\" from invite list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-			if( last ) last->next = next;
-			else My_Invites = next;
-			free( c2c );
-		}
-		else last = c2c;
-		c2c = next;
-	}
-
-	/* Ban-List */
-	last = NULL;
-	c2c = My_Bans;
-	while( c2c )
-	{
-		next = c2c->next;
-		if( c2c->channel == Chan )
-		{
-			/* dieser Eintrag muss geloescht werden */
-			Log( LOG_DEBUG, "Deleted \"%s\" from ban list for \"%s\"." , c2c->mask, Channel_Name( Chan ));
-			if( last ) last->next = next;
-			else My_Bans = next;
-			free( c2c );
-		}
-		else last = c2c;
-		c2c = next;
-	}
-} /* Lists_DeleteChannel */
-
-
 GLOBAL char *
 Lists_MakeMask( char *Pattern )
 {
@@ -407,82 +212,30 @@ Lists_MakeMask( char *Pattern )
 } /* Lists_MakeMask */
 
 
-static C2C *
-New_C2C( char *Mask, CHANNEL *Chan, bool OnlyOnce )
-{
-	C2C *c2c;
-	
-	assert( Mask != NULL );
-	assert( Chan != NULL );
 
-	/* Speicher fuer Eintrag anfordern */
-	c2c = (C2C *)malloc( sizeof( C2C ));
-	if( ! c2c )
-	{
-		Log( LOG_EMERG, "Can't allocate memory! [New_C2C]" );
-		return NULL;
-	}
-
-	strlcpy( c2c->mask, Mask, sizeof( c2c->mask ));
-	c2c->channel = Chan;
-	c2c->onlyonce = OnlyOnce;
-
-	return c2c;
-} /* New_C2C */
-
-
-static bool
-Check_List( C2C **Cl2Chan, CLIENT *Client, CHANNEL *Chan )
+bool
+Lists_Check( struct list_head *header, CLIENT *Client)
 {
-	C2C *c2c, *last;
+	struct list_elem *e, *last;
 
-	assert( Cl2Chan != NULL );
-	assert( Client != NULL );
-	assert( Chan != NULL );
+	assert( header != NULL );
 
-	c2c = *Cl2Chan;
+	e = header->first;
 	last = NULL;
 
-	while( c2c )
-	{
-		if( c2c->channel == Chan )
-		{
-			/* Ok, richtiger Channel. Passt die Maske? */
-			if( Match( c2c->mask, Client_Mask( Client )))
-			{
-				/* Treffer! */
-				if( c2c->onlyonce )
-				{
-					/* Eintrag loeschen */
-					Log( LOG_DEBUG, "Deleted \"%s\" from %s list for \"%s\".", c2c->mask, *Cl2Chan == My_Invites ? "invite" : "ban", Channel_Name( Chan ));
-					if( last ) last->next = c2c->next;
-					else *Cl2Chan = c2c->next;
-					free( c2c );
-				}
-				return true;
+	while( e ) {
+		if( Match( e->mask, Client_Mask( Client ))) {
+			if( e->onlyonce ) { /* delete entry */
+				LogDebug("Deleted \"%s\" from list", e->mask);
+				Lists_Unlink(header, last, e);
 			}
+			return true;
 		}
-		last = c2c;
-		c2c = c2c->next;
+		last = e;
+		e = e->next;
 	}
 
 	return false;
-} /* Check_List */
+}
 
-
-static bool
-Already_Registered( C2C *List, char *Mask, CHANNEL *Chan )
-{
-	C2C *c2c;
-
-	c2c = List;
-	while( c2c )
-	{
-		if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 )) return true;
-		c2c = c2c->next;
-	}
-	return false;
-} /* Already_Registered */
-
-
 /* -eof- */
blob - 5a9740cd31cf0759f31c406fc3d085ade68304f1
blob + 420f7751431996823bc119bcd8179afd76f4070d
--- src/ngircd/lists.h
+++ src/ngircd/lists.h
@@ -8,7 +8,7 @@
  * (at your option) any later version.
  * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: lists.h,v 1.12 2005/03/19 18:43:49 fw Exp $
+ * $Id: lists.h,v 1.13 2006/12/07 17:57:20 fw Exp $
  *
  * Management of IRC lists: ban, invite, ... (header)
  */
@@ -16,31 +16,31 @@
 
 #ifndef __lists_h__
 #define __lists_h__
+#include "portab.h"
+#include "client.h"
 
+struct list_elem;
 
-GLOBAL void Lists_Init PARAMS(( void ));
-GLOBAL void Lists_Exit PARAMS(( void ));
+struct list_head {
+	struct list_elem *first;
+};
 
-GLOBAL bool Lists_CheckInvited PARAMS(( CLIENT *Client, CHANNEL *Chan ));
-GLOBAL bool Lists_AddInvited PARAMS(( char *Mask, CHANNEL *Chan, bool OnlyOnce ));
-GLOBAL void Lists_DelInvited PARAMS(( char *Mask, CHANNEL *Chan ));
-GLOBAL bool Lists_ShowInvites PARAMS(( CLIENT *Client, CHANNEL *Channel ));
-GLOBAL bool Lists_SendInvites PARAMS(( CLIENT *Client ));
-GLOBAL bool Lists_IsInviteEntry PARAMS(( char *Mask, CHANNEL *Chan ));
 
-GLOBAL bool Lists_CheckBanned PARAMS(( CLIENT *Client, CHANNEL *Chan ));
-GLOBAL bool Lists_AddBanned PARAMS(( char *Mask, CHANNEL *Chan ));
-GLOBAL void Lists_DelBanned PARAMS(( char *Mask, CHANNEL *Chan ));
-GLOBAL bool Lists_ShowBans PARAMS(( CLIENT *Client, CHANNEL *Channel ));
-GLOBAL bool Lists_SendBans PARAMS(( CLIENT *Client ));
-GLOBAL bool Lists_IsBanEntry PARAMS(( char *Mask, CHANNEL *Chan ));
+GLOBAL struct list_elem *Lists_GetFirst PARAMS((const struct list_head *));
+GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *));
 
-GLOBAL void Lists_DeleteChannel PARAMS(( CHANNEL *Chan ));
+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 char *Lists_MakeMask PARAMS(( char *Pattern ));
+GLOBAL bool Lists_Add PARAMS((struct list_head *header, const char *Mask, bool OnlyOnce ));
+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));
 
-#endif
+GLOBAL void Lists_Free PARAMS(( struct list_head *head ));
 
+GLOBAL char *Lists_MakeMask PARAMS(( char *Pattern ));
+GLOBAL const char *Lists_GetMask PARAMS(( const struct list_elem *e ));
 
+#endif
 /* -eof- */
blob - b3ab7c416dff10917d6ade9395af0541248708dd
blob + ba10c2045514473b886c5410352922ecfa26dba6
--- src/ngircd/ngircd.c
+++ src/ngircd/ngircd.c
@@ -12,7 +12,7 @@
 
 #include "portab.h"
 
-static char UNUSED id[] = "$Id: ngircd.c,v 1.113 2006/07/23 12:07:33 alex Exp $";
+static char UNUSED id[] = "$Id: ngircd.c,v 1.114 2006/12/07 17:57:20 fw Exp $";
 
 /**
  * @file
@@ -271,7 +271,6 @@ main( int argc, const char *argv[] )
 
 		/* Initialize modules, part II: these functions are eventually
 		 * called with already dropped privileges ... */
-		Lists_Init( );
 		Channel_Init( );
 		Client_Init( );
 #ifdef ZEROCONF
@@ -328,7 +327,6 @@ main( int argc, const char *argv[] )
 #endif
 		Client_Exit( );
 		Channel_Exit( );
-		Lists_Exit( );
 		Log_Exit( );
 	}
 	Pidfile_Delete( );