mirror of
				https://github.com/osmarks/ngircd.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	re-arranged invite and ban list-handling (from HEAD)
This commit is contained in:
		| @@ -10,6 +10,9 @@ | |||||||
|                                -- ChangeLog -- |                                -- ChangeLog -- | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ngIRCd 0.10.2 | ||||||
|  |   - Reorganized internal handling of invite and ban lists. | ||||||
|  |  | ||||||
| ngIRCd 0.10.1 (2006-12-17) | ngIRCd 0.10.1 (2006-12-17) | ||||||
|  |  | ||||||
|   - Fixed validation of server names containing digits. |   - Fixed validation of server names containing digits. | ||||||
| @@ -673,4 +676,4 @@ ngIRCd 0.0.1, 31.12.2001 | |||||||
|  |  | ||||||
|  |  | ||||||
| --  | --  | ||||||
| $Id: ChangeLog,v 1.302.2.9 2006/12/17 13:55:29 alex Exp $ | $Id: ChangeLog,v 1.302.2.10 2007/04/03 20:23:30 fw Exp $ | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: channel.c,v 1.56.2.1 2006/12/02 13:08:02 fw Exp $"; | static char UNUSED id[] = "$Id: channel.c,v 1.56.2.2 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| @@ -70,6 +70,22 @@ Channel_Init( void ) | |||||||
| } /* Channel_Init */ | } /* 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 | GLOBAL void | ||||||
| Channel_InitPredefined( void ) | Channel_InitPredefined( void ) | ||||||
| { | { | ||||||
| @@ -320,24 +336,6 @@ Channel_CountForUser( CLIENT *Client ) | |||||||
| } /* Channel_CountForUser */ | } /* Channel_CountForUser */ | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL int |  | ||||||
| Channel_PCount( void ) |  | ||||||
| { |  | ||||||
| 	/* Count the number of persistent (mode 'P') channels */ |  | ||||||
|  |  | ||||||
| 	CHANNEL *chan; |  | ||||||
| 	int count = 0; |  | ||||||
|  |  | ||||||
| 	chan = My_Channels; |  | ||||||
| 	while( chan ) |  | ||||||
| 	{ |  | ||||||
| 		if( strchr( chan->modes, 'P' )) count++; |  | ||||||
| 		chan = chan->next; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return count; |  | ||||||
| } /* Channel_PCount */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL const char * | GLOBAL const char * | ||||||
| Channel_Name( const CHANNEL *Chan ) | Channel_Name( const CHANNEL *Chan ) | ||||||
| @@ -601,9 +599,7 @@ Channel_IsMemberOf( CHANNEL *Chan, CLIENT *Client ) | |||||||
|  |  | ||||||
| 	assert( Chan != NULL ); | 	assert( Chan != NULL ); | ||||||
| 	assert( Client != NULL ); | 	assert( Client != NULL ); | ||||||
|  | 	return Get_Cl2Chan(Chan, Client); | ||||||
| 	if( Get_Cl2Chan( Chan, Client )) return true; |  | ||||||
| 	else return false; |  | ||||||
| } /* Channel_IsMemberOf */ | } /* Channel_IsMemberOf */ | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -716,7 +712,7 @@ Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, char *Text ) | |||||||
| 	if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = false; | 	if( strchr( Channel_Modes( Chan ), 'm' ) && ( ! is_op ) && ( ! has_voice )) ok = false; | ||||||
|  |  | ||||||
| 	/* Is the client banned? */ | 	/* 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? */ | 		/* Client is banned, but is he channel operator or has voice? */ | ||||||
| 		if(( ! has_voice ) && ( ! is_op )) ok = false; | 		if(( ! has_voice ) && ( ! is_op )) ok = false; | ||||||
| @@ -881,6 +877,68 @@ Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, char *Re | |||||||
| } /* Remove_Client */ | } /* 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 * | static CL2CHAN * | ||||||
| Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan ) | Get_First_Cl2Chan( CLIENT *Client, CHANNEL *Chan ) | ||||||
| { | { | ||||||
| @@ -910,7 +968,7 @@ static bool | |||||||
| Delete_Channel( CHANNEL *Chan ) | Delete_Channel( CHANNEL *Chan ) | ||||||
| { | { | ||||||
| 	/* Channel-Struktur loeschen */ | 	/* Channel-Struktur loeschen */ | ||||||
| 	 |  | ||||||
| 	CHANNEL *chan, *last_chan; | 	CHANNEL *chan, *last_chan; | ||||||
|  |  | ||||||
| 	last_chan = NULL; | 	last_chan = NULL; | ||||||
| @@ -926,13 +984,14 @@ Delete_Channel( CHANNEL *Chan ) | |||||||
| 	Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name ); | 	Log( LOG_DEBUG, "Freed channel structure for \"%s\".", Chan->name ); | ||||||
|  |  | ||||||
| 	/* Invite- und Ban-Lists aufraeumen */ | 	/* Invite- und Ban-Lists aufraeumen */ | ||||||
| 	Lists_DeleteChannel( chan ); | 	Lists_Free( &chan->list_bans ); | ||||||
|  | 	Lists_Free( &chan->list_invites ); | ||||||
|  |  | ||||||
| 	/* Neu verketten und freigeben */ | 	/* Neu verketten und freigeben */ | ||||||
| 	if( last_chan ) last_chan->next = chan->next; | 	if( last_chan ) last_chan->next = chan->next; | ||||||
| 	else My_Channels = chan->next; | 	else My_Channels = chan->next; | ||||||
| 	free( chan ); | 	free( chan ); | ||||||
| 		 |  | ||||||
| 	return true; | 	return true; | ||||||
| } /* Delete_Channel */ | } /* Delete_Channel */ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  * (at your option) any later version. |  * (at your option) any later version. | ||||||
|  * Please read the file COPYING, README and AUTHORS for more information. |  * Please read the file COPYING, README and AUTHORS for more information. | ||||||
|  * |  * | ||||||
|  * $Id: channel.h,v 1.29.2.1 2006/12/02 13:08:02 fw Exp $ |  * $Id: channel.h,v 1.29.2.2 2007/04/03 20:23:31 fw Exp $ | ||||||
|  * |  * | ||||||
|  * Channel management (header) |  * Channel management (header) | ||||||
|  */ |  */ | ||||||
| @@ -20,6 +20,7 @@ | |||||||
|  |  | ||||||
| #if defined(__channel_c__) | defined(S_SPLINT_S) | #if defined(__channel_c__) | defined(S_SPLINT_S) | ||||||
|  |  | ||||||
|  | #include "lists.h" | ||||||
| #include "defines.h" | #include "defines.h" | ||||||
| #include "array.h" | #include "array.h" | ||||||
|  |  | ||||||
| @@ -36,6 +37,8 @@ typedef struct _CHANNEL | |||||||
| #endif | #endif | ||||||
| 	char key[CLIENT_PASS_LEN];	/* Channel key ("password", mode "k" ) */ | 	char key[CLIENT_PASS_LEN];	/* Channel key ("password", mode "k" ) */ | ||||||
| 	unsigned long maxusers;		/* Maximum number of members (mode "l") */ | 	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; | } CHANNEL; | ||||||
|  |  | ||||||
| typedef struct _CLIENT2CHAN | typedef struct _CLIENT2CHAN | ||||||
| @@ -53,6 +56,8 @@ typedef POINTER CL2CHAN; | |||||||
|  |  | ||||||
| #endif | #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_Init PARAMS(( void )); | ||||||
| GLOBAL void Channel_InitPredefined PARAMS((  void )); | GLOBAL void Channel_InitPredefined PARAMS((  void )); | ||||||
| @@ -68,7 +73,6 @@ GLOBAL void Channel_Kick PARAMS((  CLIENT *Client, CLIENT *Origin, char *Name, c | |||||||
| GLOBAL unsigned long Channel_Count PARAMS(( void )); | GLOBAL unsigned long Channel_Count PARAMS(( void )); | ||||||
| GLOBAL unsigned long Channel_MemberCount PARAMS(( CHANNEL *Chan )); | GLOBAL unsigned long Channel_MemberCount PARAMS(( CHANNEL *Chan )); | ||||||
| GLOBAL int Channel_CountForUser PARAMS(( CLIENT *Client )); | GLOBAL int Channel_CountForUser PARAMS(( CLIENT *Client )); | ||||||
| GLOBAL int Channel_PCount PARAMS(( void )); |  | ||||||
|  |  | ||||||
| GLOBAL const char *Channel_Name PARAMS(( const CHANNEL *Chan )); | GLOBAL const char *Channel_Name PARAMS(( const CHANNEL *Chan )); | ||||||
| GLOBAL char *Channel_Modes PARAMS(( CHANNEL *Chan )); | GLOBAL char *Channel_Modes PARAMS(( CHANNEL *Chan )); | ||||||
| @@ -114,8 +118,10 @@ GLOBAL unsigned int Channel_TopicTime PARAMS(( CHANNEL *Chan )); | |||||||
| GLOBAL char *Channel_TopicWho PARAMS(( CHANNEL *Chan )); | GLOBAL char *Channel_TopicWho PARAMS(( CHANNEL *Chan )); | ||||||
| #endif | #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 | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| /* -eof- */ | /* -eof- */ | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: irc-channel.c,v 1.35.2.2 2006/12/02 13:33:52 fw Exp $"; | static char UNUSED id[] = "$Id: irc-channel.c,v 1.35.2.3 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| @@ -122,8 +122,8 @@ IRC_JOIN( CLIENT *Client, REQUEST *Req ) | |||||||
| 				chan = Channel_Search( channame ); | 				chan = Channel_Search( channame ); | ||||||
| 				assert( chan != NULL ); | 				assert( chan != NULL ); | ||||||
|  |  | ||||||
| 				is_banned = Lists_CheckBanned( target, chan ); | 				is_banned = Lists_Check(Channel_GetListBans(chan), target ); | ||||||
| 				is_invited = Lists_CheckInvited( target, chan ); | 				is_invited = Lists_Check(Channel_GetListInvites(chan), target ); | ||||||
|  |  | ||||||
| 				/* Testen, ob Client gebanned ist */ | 				/* Testen, ob Client gebanned ist */ | ||||||
| 				if(( is_banned == true) &&  ( is_invited == false )) | 				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 | 			 * commands) in this list become deleted when a user | ||||||
| 			 * joins a channel this way. */ | 			 * joins a channel this way. */ | ||||||
| 			chan = Channel_Search( channame ); | 			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) */ | 		/* Channel joinen (und ggf. anlegen) */ | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: irc-mode.c,v 1.45.2.1 2006/12/02 14:21:26 fw Exp $"; | static char UNUSED id[] = "$Id: irc-mode.c,v 1.45.2.2 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| @@ -477,7 +477,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) | |||||||
| 					Req->argv[arg_arg][0] = '\0'; | 					Req->argv[arg_arg][0] = '\0'; | ||||||
| 					arg_arg++; | 					arg_arg++; | ||||||
| 				} | 				} | ||||||
| 				else Lists_ShowInvites( Origin, Channel ); | 				else Channel_ShowInvites( Origin, Channel ); | ||||||
| 				break; | 				break; | ||||||
|  |  | ||||||
| 			case 'b': /* Ban lists */ | 			case 'b': /* Ban lists */ | ||||||
| @@ -493,7 +493,7 @@ Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ) | |||||||
| 					Req->argv[arg_arg][0] = '\0'; | 					Req->argv[arg_arg][0] = '\0'; | ||||||
| 					arg_arg++; | 					arg_arg++; | ||||||
| 				} | 				} | ||||||
| 				else Lists_ShowBans( Origin, Channel ); | 				else Channel_ShowBans( Origin, Channel ); | ||||||
| 				break; | 				break; | ||||||
|  |  | ||||||
| 			default: | 			default: | ||||||
| @@ -644,11 +644,13 @@ Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ) | |||||||
|  |  | ||||||
| 	mask = Lists_MakeMask( Pattern ); | 	mask = Lists_MakeMask( Pattern ); | ||||||
|  |  | ||||||
| 	already = Lists_IsInviteEntry( mask, Channel ); | 	already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask ); | ||||||
| 	 | 	if (!already) { | ||||||
| 	if( ! Lists_AddInvited( mask, Channel, false )) return CONNECTED; | 		if( ! Channel_AddInvite(Channel, mask, false )) | ||||||
| 	 | 			return CONNECTED; | ||||||
| 	if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED; | 	} | ||||||
|  | 	if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER )) | ||||||
|  | 		return CONNECTED; | ||||||
|  |  | ||||||
| 	return Send_ListChange( "+I", Prefix, Client, Channel, mask ); | 	return Send_ListChange( "+I", Prefix, Client, Channel, mask ); | ||||||
| } /* Add_Invite */ | } /* Add_Invite */ | ||||||
| @@ -666,11 +668,13 @@ Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ) | |||||||
|  |  | ||||||
| 	mask = Lists_MakeMask( Pattern ); | 	mask = Lists_MakeMask( Pattern ); | ||||||
|  |  | ||||||
| 	already = Lists_IsBanEntry( mask, Channel ); | 	already = Lists_CheckDupeMask(Channel_GetListBans(Channel), mask ); | ||||||
|  | 	if (!already) { | ||||||
| 	if( ! Lists_AddBanned( mask, Channel )) return CONNECTED; | 		if( ! Channel_AddBan(Channel, mask)) | ||||||
|  | 			return CONNECTED; | ||||||
| 	if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED; | 	} | ||||||
|  | 	if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER )) | ||||||
|  | 		return CONNECTED; | ||||||
|  |  | ||||||
| 	return Send_ListChange( "+b", Prefix, Client, Channel, mask ); | 	return Send_ListChange( "+b", Prefix, Client, Channel, mask ); | ||||||
| } /* Add_Ban */ | } /* Add_Ban */ | ||||||
| @@ -686,7 +690,7 @@ Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ) | |||||||
| 	assert( Pattern != NULL ); | 	assert( Pattern != NULL ); | ||||||
|  |  | ||||||
| 	mask = Lists_MakeMask( Pattern ); | 	mask = Lists_MakeMask( Pattern ); | ||||||
| 	Lists_DelInvited( mask, Channel ); | 	Lists_Del(Channel_GetListInvites(Channel), mask); | ||||||
| 	return Send_ListChange( "-I", Prefix, Client, Channel, mask ); | 	return Send_ListChange( "-I", Prefix, Client, Channel, mask ); | ||||||
| } /* Del_Invite */ | } /* Del_Invite */ | ||||||
|  |  | ||||||
| @@ -701,7 +705,7 @@ Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ) | |||||||
| 	assert( Pattern != NULL ); | 	assert( Pattern != NULL ); | ||||||
|  |  | ||||||
| 	mask = Lists_MakeMask( Pattern ); | 	mask = Lists_MakeMask( Pattern ); | ||||||
| 	Lists_DelBanned( mask, Channel ); | 	Lists_Del(Channel_GetListBans(Channel), mask); | ||||||
| 	return Send_ListChange( "-b", Prefix, Client, Channel, mask ); | 	return Send_ListChange( "-b", Prefix, Client, Channel, mask ); | ||||||
| } /* Del_Ban */ | } /* Del_Ban */ | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: irc-op.c,v 1.15.4.1 2006/12/02 14:21:26 fw Exp $"; | static char UNUSED id[] = "$Id: irc-op.c,v 1.15.4.2 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.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( 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 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) { | 		if (remember) { | ||||||
| 			/* We must remember this invite */ | 			/* 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; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: irc-server.c,v 1.39.2.2 2006/12/02 14:26:53 fw Exp $"; | static char UNUSED id[] = "$Id: irc-server.c,v 1.39.2.3 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| @@ -41,6 +41,50 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.39.2.2 2006/12/02 14:26:53 fw E | |||||||
| #include "irc-server.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". |  * Handler for the IRC command "SERVER". | ||||||
|  * See RFC 2813 section 4.1.2. |  * See RFC 2813 section 4.1.2. | ||||||
| @@ -268,9 +312,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) | |||||||
| 			    "Synchronizing INVITE- and BAN-lists ..."); | 			    "Synchronizing INVITE- and BAN-lists ..."); | ||||||
| #endif | #endif | ||||||
| 			/* Synchronize INVITE- and BAN-lists */ | 			/* Synchronize INVITE- and BAN-lists */ | ||||||
| 			if (! Lists_SendInvites(Client)) | 			if (!Synchronize_Lists(Client)) | ||||||
| 				return DISCONNECTED; |  | ||||||
| 			if (! Lists_SendBans(Client)) |  | ||||||
| 				return DISCONNECTED; | 				return DISCONNECTED; | ||||||
| 		} | 		} | ||||||
| #endif | #endif | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #include "portab.h" | ||||||
|  |  | ||||||
| static char UNUSED id[] = "$Id: lists.c,v 1.18.2.1 2006/12/02 13:05:38 fw Exp $"; | static char UNUSED id[] = "$Id: lists.c,v 1.18.2.2 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| #include "imp.h" | #include "imp.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| @@ -35,326 +35,131 @@ static char UNUSED id[] = "$Id: lists.c,v 1.18.2.1 2006/12/02 13:05:38 fw Exp $" | |||||||
| #include "exp.h" | #include "exp.h" | ||||||
| #include "lists.h" | #include "lists.h" | ||||||
|  |  | ||||||
|  |  | ||||||
| #define MASK_LEN	(2*CLIENT_HOST_LEN) | #define MASK_LEN	(2*CLIENT_HOST_LEN) | ||||||
|  |  | ||||||
|  | struct list_elem { | ||||||
| typedef struct _C2C | 	struct list_elem *next; | ||||||
| { |  | ||||||
| 	struct _C2C *next; |  | ||||||
| 	char mask[MASK_LEN]; | 	char mask[MASK_LEN]; | ||||||
| 	CHANNEL *channel; |  | ||||||
| 	bool onlyonce; | 	bool onlyonce; | ||||||
| } C2C; | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| static C2C *My_Invites, *My_Bans; | GLOBAL const char * | ||||||
|  | Lists_GetMask(const struct list_elem *e) | ||||||
|  |  | ||||||
| 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 ) |  | ||||||
| { | { | ||||||
| 	/* Modul initialisieren */ | 	return e->mask; | ||||||
|  | } | ||||||
| 	My_Invites = My_Bans = NULL; |  | ||||||
| } /* Lists_Init */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL void | GLOBAL struct list_elem* | ||||||
| Lists_Exit( void ) | 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 | GLOBAL struct list_elem* | ||||||
| Lists_CheckInvited( CLIENT *Client, CHANNEL *Chan ) | Lists_GetNext(const struct list_elem *e) | ||||||
| { | { | ||||||
| 	return Check_List( &My_Invites, Client, Chan ); | 	return e->next; | ||||||
| } /* Lists_CheckInvited */ | } | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL bool | bool | ||||||
| Lists_IsInviteEntry( char *Mask, CHANNEL *Chan ) | Lists_Add(struct list_head *header, const char *Mask, bool OnlyOnce ) | ||||||
| { | { | ||||||
|  | 	struct list_elem *e, *newelem; | ||||||
|  |  | ||||||
|  | 	assert( header != NULL ); | ||||||
| 	assert( Mask != NULL ); | 	assert( Mask != NULL ); | ||||||
| 	assert( Chan != NULL ); |  | ||||||
|  |  | ||||||
| 	return Already_Registered( My_Invites, Mask, Chan ); | 	if (Lists_CheckDupeMask(header, Mask )) return true; | ||||||
| } /* Lists_IsInviteEntry */ |  | ||||||
|  |  | ||||||
|  | 	e = Lists_GetFirst(header); | ||||||
|  |  | ||||||
| GLOBAL bool | 	newelem = malloc(sizeof(struct list_elem)); | ||||||
| Lists_AddInvited( char *Mask, CHANNEL *Chan, bool OnlyOnce ) | 	if( ! newelem ) { | ||||||
| { | 		Log( LOG_EMERG, "Can't allocate memory for new Ban/Invite entry!" ); | ||||||
| 	C2C *c2c; | 		return NULL; | ||||||
|  |  | ||||||
| 	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; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/* verketten */ | 	strlcpy( newelem->mask, Mask, sizeof( newelem->mask )); | ||||||
| 	c2c->next = My_Invites; | 	newelem->onlyonce = OnlyOnce; | ||||||
| 	My_Invites = c2c; | 	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; | 	return true; | ||||||
| } /* Lists_AddInvited */ | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | static void | ||||||
|  | Lists_Unlink(struct list_head *header, struct list_elem *p, struct list_elem *victim) | ||||||
|  | { | ||||||
|  | 	assert(victim != NULL); | ||||||
|  | 	assert(header != NULL); | ||||||
|  |  | ||||||
|  | 	if (p) p->next = victim->next; | ||||||
|  | 	else header->first = victim->next; | ||||||
|  |  | ||||||
|  | 	free(victim); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL void | GLOBAL void | ||||||
| Lists_DelInvited( char *Mask, CHANNEL *Chan ) | Lists_Del(struct list_head *header, const char *Mask) | ||||||
| { | { | ||||||
| 	C2C *c2c, *last, *next; | 	struct list_elem *e, *last, *victim; | ||||||
|  |  | ||||||
|  | 	assert( header != NULL ); | ||||||
| 	assert( Mask != NULL ); | 	assert( Mask != NULL ); | ||||||
| 	assert( Chan != NULL ); |  | ||||||
|  |  | ||||||
| 	last = NULL; | 	last = NULL; | ||||||
| 	c2c = My_Invites; | 	e = Lists_GetFirst(header); | ||||||
| 	while( c2c ) | 	while( e ) { | ||||||
| 	{ | 		if(strcasecmp( e->mask, Mask ) == 0 ) { | ||||||
| 		next = c2c->next; | 			LogDebug("Deleted \"%s\" from list", e->mask); | ||||||
| 		if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 )) | 			victim = e; | ||||||
| 		{ | 			e = victim->next; | ||||||
| 			/* dieser Eintrag muss geloescht werden */ | 			Lists_Unlink(header, last, victim); | ||||||
| 			Log( LOG_DEBUG, "Deleted \"%s\" from invite list for \"%s\"." , c2c->mask, Channel_Name( Chan )); | 			continue; | ||||||
| 			if( last ) last->next = next; |  | ||||||
| 			else My_Invites = next; |  | ||||||
| 			free( c2c ); |  | ||||||
| 		} | 		} | ||||||
| 		else last = c2c; | 		last = e; | ||||||
| 		c2c = next; | 		e = e->next; | ||||||
| 	} | 	} | ||||||
| } /* Lists_DelInvited */ | } | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL bool |  | ||||||
| Lists_ShowInvites( CLIENT *Client, CHANNEL *Channel ) |  | ||||||
| { |  | ||||||
| 	C2C *c2c; |  | ||||||
|  |  | ||||||
| 	assert( Client != NULL ); |  | ||||||
| 	assert( Channel != 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; |  | ||||||
| 		} |  | ||||||
| 		c2c = c2c->next; |  | ||||||
| 	} |  | ||||||
| 	return IRC_WriteStrClient( Client, RPL_ENDOFINVITELIST_MSG, Client_ID( Client ), Channel_Name( Channel )); |  | ||||||
| } /* Lists_ShowInvites */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL bool |  | ||||||
| Lists_SendInvites( CLIENT *Client ) |  | ||||||
| { |  | ||||||
| 	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 */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| 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; |  | ||||||
| 	} |  | ||||||
| 	return CONNECTED; |  | ||||||
| } /* Lists_SendBans */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL bool |  | ||||||
| Lists_CheckBanned( CLIENT *Client, CHANNEL *Chan ) |  | ||||||
| { |  | ||||||
| 	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; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/* 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 | GLOBAL void | ||||||
| Lists_DelBanned( char *Mask, CHANNEL *Chan ) | Lists_Free(struct list_head *head) | ||||||
| { | { | ||||||
| 	C2C *c2c, *last, *next; | 	struct list_elem *e, *victim; | ||||||
|  |  | ||||||
| 	assert( Mask != NULL ); | 	assert(head != NULL); | ||||||
| 	assert( Chan != NULL ); |  | ||||||
|  |  | ||||||
| 	last = NULL; | 	e = head->first; | ||||||
| 	c2c = My_Bans; | 	head->first = NULL; | ||||||
| 	while( c2c ) | 	while (e) { | ||||||
| 	{ | 		LogDebug("Deleted \"%s\" from invite list" , e->mask); | ||||||
| 		next = c2c->next; | 		victim = e; | ||||||
| 		if(( c2c->channel == Chan ) && ( strcasecmp( c2c->mask, Mask ) == 0 )) | 		e = e->next; | ||||||
| 		{ | 		free( victim ); | ||||||
| 			/* 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 | GLOBAL bool | ||||||
| Lists_ShowBans( CLIENT *Client, CHANNEL *Channel ) | Lists_CheckDupeMask(const struct list_head *h, const char *Mask ) | ||||||
| { | { | ||||||
| 	C2C *c2c; | 	struct list_elem *e; | ||||||
|  | 	e = h->first; | ||||||
| 	assert( Client != NULL ); | 	while (e) { | ||||||
| 	assert( Channel != NULL ); | 		if (strcasecmp( e->mask, Mask ) == 0 ) | ||||||
|  | 			return true; | ||||||
| 	c2c = My_Bans; | 		e = e->next; | ||||||
| 	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 )); | 	return false; | ||||||
| } /* 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 * | GLOBAL char * | ||||||
| @@ -407,82 +212,30 @@ Lists_MakeMask( char *Pattern ) | |||||||
| } /* Lists_MakeMask */ | } /* Lists_MakeMask */ | ||||||
|  |  | ||||||
|  |  | ||||||
| static C2C * |  | ||||||
| New_C2C( char *Mask, CHANNEL *Chan, bool OnlyOnce ) | bool | ||||||
|  | Lists_Check( struct list_head *header, CLIENT *Client) | ||||||
| { | { | ||||||
| 	C2C *c2c; | 	struct list_elem *e, *last; | ||||||
| 	 |  | ||||||
| 	assert( Mask != NULL ); |  | ||||||
| 	assert( Chan != NULL ); |  | ||||||
|  |  | ||||||
| 	/* Speicher fuer Eintrag anfordern */ | 	assert( header != NULL ); | ||||||
| 	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 )); | 	e = header->first; | ||||||
| 	c2c->channel = Chan; |  | ||||||
| 	c2c->onlyonce = OnlyOnce; |  | ||||||
|  |  | ||||||
| 	return c2c; |  | ||||||
| } /* New_C2C */ |  | ||||||
|  |  | ||||||
|  |  | ||||||
| static bool |  | ||||||
| Check_List( C2C **Cl2Chan, CLIENT *Client, CHANNEL *Chan ) |  | ||||||
| { |  | ||||||
| 	C2C *c2c, *last; |  | ||||||
|  |  | ||||||
| 	assert( Cl2Chan != NULL ); |  | ||||||
| 	assert( Client != NULL ); |  | ||||||
| 	assert( Chan != NULL ); |  | ||||||
|  |  | ||||||
| 	c2c = *Cl2Chan; |  | ||||||
| 	last = NULL; | 	last = NULL; | ||||||
|  |  | ||||||
| 	while( c2c ) | 	while( e ) { | ||||||
| 	{ | 		if( Match( e->mask, Client_Mask( Client ))) { | ||||||
| 		if( c2c->channel == Chan ) | 			if( e->onlyonce ) { /* delete entry */ | ||||||
| 		{ | 				LogDebug("Deleted \"%s\" from list", e->mask); | ||||||
| 			/* Ok, richtiger Channel. Passt die Maske? */ | 				Lists_Unlink(header, last, e); | ||||||
| 			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; |  | ||||||
| 			} | 			} | ||||||
|  | 			return true; | ||||||
| 		} | 		} | ||||||
| 		last = c2c; | 		last = e; | ||||||
| 		c2c = c2c->next; | 		e = e->next; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return false; | 	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- */ | /* -eof- */ | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ | |||||||
|  * (at your option) any later version. |  * (at your option) any later version. | ||||||
|  * Please read the file COPYING, README and AUTHORS for more information. |  * 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.12.4.1 2007/04/03 20:23:31 fw Exp $ | ||||||
|  * |  * | ||||||
|  * Management of IRC lists: ban, invite, ... (header) |  * Management of IRC lists: ban, invite, ... (header) | ||||||
|  */ |  */ | ||||||
| @@ -16,31 +16,31 @@ | |||||||
|  |  | ||||||
| #ifndef __lists_h__ | #ifndef __lists_h__ | ||||||
| #define __lists_h__ | #define __lists_h__ | ||||||
|  | #include "portab.h" | ||||||
|  | #include "client.h" | ||||||
|  |  | ||||||
|  | struct list_elem; | ||||||
|  |  | ||||||
|  | struct list_head { | ||||||
|  | 	struct list_elem *first; | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| GLOBAL void Lists_Init PARAMS(( void )); | GLOBAL struct list_elem *Lists_GetFirst PARAMS((const struct list_head *)); | ||||||
| GLOBAL void Lists_Exit PARAMS(( void )); | GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *)); | ||||||
|  |  | ||||||
| GLOBAL bool Lists_CheckInvited PARAMS(( CLIENT *Client, CHANNEL *Chan )); | GLOBAL bool Lists_Check PARAMS((struct list_head *head, CLIENT *client )); | ||||||
| GLOBAL bool Lists_AddInvited PARAMS(( char *Mask, CHANNEL *Chan, bool OnlyOnce )); | GLOBAL bool Lists_CheckDupeMask PARAMS((const struct list_head *head, const char *mask )); | ||||||
| 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_Add PARAMS((struct list_head *header, const char *Mask, bool OnlyOnce )); | ||||||
| GLOBAL bool Lists_AddBanned PARAMS(( char *Mask, CHANNEL *Chan )); | GLOBAL void Lists_Del PARAMS((struct list_head *head, const char *Mask )); | ||||||
| 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 void Lists_DeleteChannel PARAMS(( CHANNEL *Chan )); | GLOBAL bool Lists_AlreadyRegistered PARAMS(( const struct list_head *head, const char *Mask)); | ||||||
|  |  | ||||||
|  | GLOBAL void Lists_Free PARAMS(( struct list_head *head )); | ||||||
|  |  | ||||||
| GLOBAL char *Lists_MakeMask PARAMS(( char *Pattern )); | GLOBAL char *Lists_MakeMask PARAMS(( char *Pattern )); | ||||||
|  | GLOBAL const char *Lists_GetMask PARAMS(( const struct list_elem *e )); | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  |  | ||||||
| /* -eof- */ | /* -eof- */ | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ | |||||||
|  |  | ||||||
| #include "portab.h" | #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.113.2.1 2007/04/03 20:23:31 fw Exp $"; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * @file |  * @file | ||||||
| @@ -271,7 +271,6 @@ main( int argc, const char *argv[] ) | |||||||
|  |  | ||||||
| 		/* Initialize modules, part II: these functions are eventually | 		/* Initialize modules, part II: these functions are eventually | ||||||
| 		 * called with already dropped privileges ... */ | 		 * called with already dropped privileges ... */ | ||||||
| 		Lists_Init( ); |  | ||||||
| 		Channel_Init( ); | 		Channel_Init( ); | ||||||
| 		Client_Init( ); | 		Client_Init( ); | ||||||
| #ifdef ZEROCONF | #ifdef ZEROCONF | ||||||
| @@ -328,7 +327,6 @@ main( int argc, const char *argv[] ) | |||||||
| #endif | #endif | ||||||
| 		Client_Exit( ); | 		Client_Exit( ); | ||||||
| 		Channel_Exit( ); | 		Channel_Exit( ); | ||||||
| 		Lists_Exit( ); |  | ||||||
| 		Log_Exit( ); | 		Log_Exit( ); | ||||||
| 	} | 	} | ||||||
| 	Pidfile_Delete( ); | 	Pidfile_Delete( ); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Florian Westphal
					Florian Westphal