]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/lists.c
d4b0a1430f17c8ef02ca093a80e5e312d919ff43
[ngircd-alex.git] / src / ngircd / lists.c
1 /*
2  * ngIRCd -- The Next Generation IRC Daemon
3  * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4  *
5  * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6  * der GNU General Public License (GPL), wie von der Free Software Foundation
7  * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8  * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9  * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10  * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11  *
12  * $Id: lists.c,v 1.3 2002/06/09 13:18:23 alex Exp $
13  *
14  * lists.c: Verwaltung der "IRC-Listen": Ban, Invite, ...
15  */
16
17
18 #include "portab.h"
19
20 #include "imp.h"
21 #include <assert.h>
22
23 #include "defines.h"
24 #include "conn.h"
25 #include "client.h"
26 #include "channel.h"
27 #include "log.h"
28
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "exp.h"
33 #include "lists.h"
34
35
36 #define MASK_LEN CLIENT_ID_LEN+CLIENT_HOST_LEN
37
38
39 typedef struct _C2C
40 {
41         struct _C2C *next;
42         CHAR mask[MASK_LEN];
43         CHANNEL *channel;
44         BOOLEAN onlyonce;
45 } C2C;
46
47
48 LOCAL C2C *My_Invites, *My_Bans;
49
50
51 LOCAL C2C *New_C2C PARAMS(( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce ));
52
53
54 GLOBAL VOID
55 Lists_Init( VOID )
56 {
57         /* Modul initialisieren */
58
59         My_Invites = My_Bans = NULL;
60 } /* Lists_Init */
61
62
63 GLOBAL VOID
64 Lists_Exit( VOID )
65 {
66         /* Modul abmelden */
67
68         C2C *c2c, *next;
69
70         /* Invite-Lists freigeben */
71         c2c = My_Invites;
72         while( c2c )
73         {
74                 next = c2c->next;
75                 free( c2c );
76                 c2c = next;
77         }
78
79         /* Ban-Lists freigeben */
80         c2c = My_Bans;
81         while( c2c )
82         {
83                 next = c2c->next;
84                 free( c2c );
85                 c2c = next;
86         }
87 } /* Lists_Exit */
88
89
90 GLOBAL BOOLEAN
91 Lists_CheckInvited( CLIENT *Client, CHANNEL *Chan )
92 {
93         C2C *c2c, *last;
94         
95         assert( Client != NULL );
96         assert( Chan != NULL );
97
98         last = NULL;
99         c2c = My_Invites;
100         while( c2c )
101         {
102                 if( c2c->channel == Chan )
103                 {
104                         /* Ok, richtiger Channel. Passt die Maske? */
105                         if( strcasecmp( Client_Mask( Client ), c2c->mask ) == 0 )
106                         {
107                                 /* Treffer! */
108                                 if( c2c->onlyonce )
109                                 {
110                                         /* Eintrag loeschen */
111                                         if( last ) last->next = c2c->next;
112                                         else My_Invites = c2c->next;
113                                         free( c2c );
114                                 }
115                                 return TRUE;
116                         }
117                 }
118                 last = c2c;
119                 c2c = c2c->next;
120         }
121         
122         return FALSE;
123 } /* Lists_CheckInvited */
124
125
126 GLOBAL VOID
127 Lists_AddInvited( CHAR *Pattern, CHANNEL *Chan, BOOLEAN OnlyOnce )
128 {
129         C2C *c2c;
130
131         assert( Pattern != NULL );
132         assert( Chan != NULL );
133
134         c2c = New_C2C( Pattern, Chan, OnlyOnce );
135         if( ! c2c )
136         {
137                 Log( LOG_ERR, "Can't add new invite list entry!" );
138                 return;
139         }
140
141         /* verketten */
142         c2c->next = My_Invites;
143         My_Invites = c2c;
144
145         Log( LOG_DEBUG, "Added \"%s\" to invite list for \"%s\".", Pattern, Channel_Name( Chan ));
146 } /* Lists_AddInvited */
147
148
149 GLOBAL BOOLEAN
150 Lists_CheckBanned( CLIENT *Client, CHANNEL *Chan )
151 {
152         assert( Client != NULL );
153         assert( Chan != NULL );
154
155         return FALSE;
156 } /* Lists_CheckBanned */
157
158
159 GLOBAL VOID
160 Lists_DeleteChannel( CHANNEL *Chan )
161 {
162         /* Channel wurde geloescht, Invite- und Ban-Lists aufraeumen */
163
164         C2C *c2c, *last, *next;
165
166         /* Invite-List */
167         last = NULL;
168         c2c = My_Invites;
169         while( c2c )
170         {
171                 next = c2c->next;
172                 if( c2c->channel == Chan )
173                 {
174                         /* dieser Eintrag muss geloescht werden */
175                         if( last ) last->next = next;
176                         else My_Invites = next;
177                         free( c2c );
178                 }
179                 else last = c2c;
180                 c2c = next;
181         }
182
183         /* Ban-List */
184         last = NULL;
185         c2c = My_Bans;
186         while( c2c )
187         {
188                 next = c2c->next;
189                 if( c2c->channel == Chan )
190                 {
191                         /* dieser Eintrag muss geloescht werden */
192                         if( last ) last->next = next;
193                         else My_Bans = next;
194                         free( c2c );
195                 }
196                 else last = c2c;
197                 c2c = next;
198         }
199 } /* Lists_DeleteChannel */
200
201
202 LOCAL C2C *
203 New_C2C( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce )
204 {
205         C2C *c2c;
206         
207         assert( Mask != NULL );
208         assert( Chan != NULL );
209
210         /* Speicher fuer Eintrag anfordern */
211         c2c = malloc( sizeof( C2C ));
212         if( ! c2c )
213         {
214                 Log( LOG_EMERG, "Can't allocate memory! [New_C2C]" );
215                 return NULL;
216         }
217
218         strncpy( c2c->mask, Mask, MASK_LEN );
219         c2c->channel = Chan;
220         c2c->onlyonce = OnlyOnce;
221         
222         return c2c;
223 } /* New_C2C */
224
225
226 /* -eof- */