moved invite/ban lists to channel structure

This commit is contained in:
Florian Westphal 2006-12-07 17:57:20 +00:00
parent 5877bca4bc
commit fa7bb2790a
9 changed files with 282 additions and 398 deletions

View File

@ -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>
@ -70,6 +70,22 @@ Channel_Init( void )
} /* 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
Channel_InitPredefined( void )
{
@ -716,7 +732,7 @@ Channel_Write( CHANNEL *Chan, CLIENT *From, CLIENT *Client, char *Text )
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;
@ -881,6 +897,68 @@ Remove_Client( int Type, CHANNEL *Chan, CLIENT *Client, CLIENT *Origin, char *Re
} /* 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 */

View File

@ -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 *Chan ));
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- */

View File

@ -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) */

View File

@ -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 *Origin, CHANNEL *Channel )
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 *Origin, CHANNEL *Channel )
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 *Channel, char *Pattern )
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,11 +668,13 @@ Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
mask = Lists_MakeMask( Pattern );
already = Lists_IsBanEntry( mask, Channel );
if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
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;
return Send_ListChange( "+b", Prefix, Client, Channel, mask );
} /* Add_Ban */
@ -686,7 +690,7 @@ Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
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 *Channel, char *Pattern )
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 */

View File

@ -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;
}
}

View File

@ -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>
@ -41,6 +41,50 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.42 2006/12/02 14:10:48 fw Exp $
#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

View File

@ -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,326 +35,131 @@ static char UNUSED id[] = "$Id: lists.c,v 1.19 2006/08/12 11:56:24 fw Exp $";
#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 */
My_Invites = My_Bans = NULL;
} /* Lists_Init */
return e->mask;
}
GLOBAL void
Lists_Exit( void )
GLOBAL struct list_elem*
Lists_GetFirst(const struct list_head *h)
{
/* Modul abmelden */
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 */
return h->first;
}
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 */
}
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
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( Chan != NULL );
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 );
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;
}
else last = c2c;
c2c = next;
last = e;
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
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( Chan != NULL );
assert(head != 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;
e = head->first;
head->first = NULL;
while (e) {
LogDebug("Deleted \"%s\" from invite list" , e->mask);
victim = e;
e = e->next;
free( victim );
}
} /* Lists_DelBanned */
}
GLOBAL bool
Lists_ShowBans( CLIENT *Client, CHANNEL *Channel )
Lists_CheckDupeMask(const struct list_head *h, const char *Mask )
{
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;
struct list_elem *e;
e = h->first;
while (e) {
if (strcasecmp( e->mask, Mask ) == 0 )
return true;
e = e->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 */
return false;
}
GLOBAL char *
@ -407,82 +212,30 @@ Lists_MakeMask( char *Pattern )
} /* Lists_MakeMask */
static C2C *
New_C2C( char *Mask, CHANNEL *Chan, bool OnlyOnce )
bool
Lists_Check( struct list_head *header, CLIENT *Client)
{
C2C *c2c;
assert( Mask != NULL );
assert( Chan != NULL );
struct list_elem *e, *last;
/* Speicher fuer Eintrag anfordern */
c2c = (C2C *)malloc( sizeof( C2C ));
if( ! c2c )
{
Log( LOG_EMERG, "Can't allocate memory! [New_C2C]" );
return NULL;
}
assert( header != 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 )
{
C2C *c2c, *last;
assert( Cl2Chan != NULL );
assert( Client != NULL );
assert( Chan != 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- */

View File

@ -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;
struct list_head {
struct list_elem *first;
};
GLOBAL void Lists_Init PARAMS(( void ));
GLOBAL void Lists_Exit PARAMS(( void ));
GLOBAL struct list_elem *Lists_GetFirst PARAMS((const struct list_head *));
GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *));
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_Check PARAMS((struct list_head *head, CLIENT *client ));
GLOBAL bool Lists_CheckDupeMask PARAMS((const struct list_head *head, const char *mask ));
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 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 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 const char *Lists_GetMask PARAMS(( const struct list_elem *e ));
#endif
/* -eof- */

View File

@ -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( );