]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/lists.c
- Hmpf. "Verfruehtes" CVS-Update einiger Source-Files zurueckgenommen ...
[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.6 2002/08/26 23:47:58 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 BOOLEAN
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 FALSE;
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         return TRUE;
147 } /* Lists_AddInvited */
148
149
150 GLOBAL BOOLEAN
151 Lists_CheckBanned( CLIENT *Client, CHANNEL *Chan )
152 {
153         assert( Client != NULL );
154         assert( Chan != NULL );
155
156         return FALSE;
157 } /* Lists_CheckBanned */
158
159
160 GLOBAL VOID
161 Lists_DeleteChannel( CHANNEL *Chan )
162 {
163         /* Channel wurde geloescht, Invite- und Ban-Lists aufraeumen */
164
165         C2C *c2c, *last, *next;
166
167         /* Invite-List */
168         last = NULL;
169         c2c = My_Invites;
170         while( c2c )
171         {
172                 next = c2c->next;
173                 if( c2c->channel == Chan )
174                 {
175                         /* dieser Eintrag muss geloescht werden */
176                         if( last ) last->next = next;
177                         else My_Invites = next;
178                         free( c2c );
179                 }
180                 else last = c2c;
181                 c2c = next;
182         }
183
184         /* Ban-List */
185         last = NULL;
186         c2c = My_Bans;
187         while( c2c )
188         {
189                 next = c2c->next;
190                 if( c2c->channel == Chan )
191                 {
192                         /* dieser Eintrag muss geloescht werden */
193                         if( last ) last->next = next;
194                         else My_Bans = next;
195                         free( c2c );
196                 }
197                 else last = c2c;
198                 c2c = next;
199         }
200 } /* Lists_DeleteChannel */
201
202
203 LOCAL C2C *
204 New_C2C( CHAR *Mask, CHANNEL *Chan, BOOLEAN OnlyOnce )
205 {
206         C2C *c2c;
207         
208         assert( Mask != NULL );
209         assert( Chan != NULL );
210
211         /* Speicher fuer Eintrag anfordern */
212         c2c = malloc( sizeof( C2C ));
213         if( ! c2c )
214         {
215                 Log( LOG_EMERG, "Can't allocate memory! [New_C2C]" );
216                 return NULL;
217         }
218
219         strncpy( c2c->mask, Mask, MASK_LEN );
220         c2c->channel = Chan;
221         c2c->onlyonce = OnlyOnce;
222         
223         return c2c;
224 } /* New_C2C */
225
226
227 /* -eof- */