1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
/*
mode-lists.c : irssi
Copyright (C) 1999-2000 Timo Sirainen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "misc.h"
#include "signals.h"
#include "irc-servers.h"
#include "irc-channels.h"
#include "mode-lists.h"
static void ban_free(GSList **list, BAN_REC *rec)
{
g_return_if_fail(list != NULL);
g_return_if_fail(rec != NULL);
g_free(rec->ban);
g_free_not_null(rec->setby);
g_free(rec);
*list = g_slist_remove(*list, rec);
}
void banlist_free(GSList *banlist)
{
while (banlist != NULL)
ban_free(&banlist, banlist->data);
}
BAN_REC *banlist_add(IRC_CHANNEL_REC *channel, const char *ban,
const char *nick, time_t time)
{
BAN_REC *rec;
g_return_val_if_fail(channel != NULL, NULL);
g_return_val_if_fail(ban != NULL, NULL);
rec = g_new(BAN_REC, 1);
rec->ban = g_strdup(ban);
rec->setby = nick == NULL || *nick == '\0' ? NULL :
g_strdup(nick);
rec->time = time;
channel->banlist = g_slist_append(channel->banlist, rec);
signal_emit("ban new", 2, channel, rec);
return rec;
}
static BAN_REC *banlist_find(GSList *list, const char *ban)
{
GSList *tmp;
g_return_val_if_fail(ban != NULL, NULL);
for (tmp = list; tmp != NULL; tmp = tmp->next) {
BAN_REC *rec = tmp->data;
if (g_strcasecmp(rec->ban, ban) == 0)
return rec;
}
return NULL;
}
void banlist_remove(IRC_CHANNEL_REC *channel, const char *ban)
{
BAN_REC *rec;
g_return_if_fail(channel != NULL);
g_return_if_fail(ban != NULL);
rec = banlist_find(channel->banlist, ban);
if (rec != NULL) {
signal_emit("ban remove", 2, channel, rec);
ban_free(&channel->banlist, rec);
}
}
BAN_REC *banlist_exception_add(IRC_CHANNEL_REC *channel, const char *ban,
const char *nick, time_t time)
{
BAN_REC *rec;
g_return_val_if_fail(channel != NULL, NULL);
g_return_val_if_fail(ban != NULL, NULL);
rec = g_new(BAN_REC, 1);
rec->ban = g_strdup(ban);
rec->setby = nick == NULL || *nick == '\0' ? NULL :
g_strdup(nick);
rec->time = time;
channel->ebanlist = g_slist_append(channel->ebanlist, rec);
signal_emit("ban exception new", 2, channel, rec);
return rec;
}
void banlist_exception_remove(IRC_CHANNEL_REC *channel, const char *ban)
{
BAN_REC *rec;
g_return_if_fail(channel != NULL);
g_return_if_fail(ban != NULL);
rec = banlist_find(channel->ebanlist, ban);
if (rec != NULL) {
signal_emit("ban exception remove", 2, channel, rec);
ban_free(&channel->ebanlist, rec);
}
}
static void invitelist_free(IRC_CHANNEL_REC *channel)
{
g_return_if_fail(channel != NULL);
g_slist_foreach(channel->invitelist, (GFunc) g_free, NULL);
g_slist_free(channel->invitelist);
}
void invitelist_add(IRC_CHANNEL_REC *channel, const char *mask)
{
g_return_if_fail(channel != NULL);
g_return_if_fail(mask != NULL);
channel->invitelist = g_slist_append(channel->invitelist, g_strdup(mask));
signal_emit("invitelist new", 2, channel, mask);
}
void invitelist_remove(IRC_CHANNEL_REC *channel, const char *mask)
{
GSList *tmp;
g_return_if_fail(channel != NULL);
g_return_if_fail(mask != NULL);
tmp = gslist_find_icase_string(channel->invitelist, mask);
if (tmp == NULL) return;
signal_emit("invitelist remove", 2, channel, tmp->data);
g_free(tmp->data);
channel->invitelist = g_slist_remove(channel->invitelist, tmp->data);
}
static void channel_destroyed(IRC_CHANNEL_REC *channel)
{
if (!IS_IRC_CHANNEL(channel))
return;
banlist_free(channel->banlist);
banlist_free(channel->ebanlist);
invitelist_free(channel);
}
static void event_banlist(IRC_SERVER_REC *server, const char *data)
{
IRC_CHANNEL_REC *chanrec;
char *params, *channel, *ban, *setby, *tims;
time_t tim;
g_return_if_fail(data != NULL);
params = event_get_params(data, 5, NULL, &channel, &ban, &setby, &tims);
chanrec = irc_channel_find(server, channel);
if (chanrec != NULL) {
tim = (time_t) atol(tims);
banlist_add(chanrec, ban, setby, tim);
}
g_free(params);
}
static void event_ebanlist(IRC_SERVER_REC *server, const char *data)
{
IRC_CHANNEL_REC *chanrec;
char *params, *channel, *ban, *setby, *tims;
time_t tim;
g_return_if_fail(data != NULL);
params = event_get_params(data, 5, NULL, &channel, &ban, &setby, &tims);
chanrec = irc_channel_find(server, channel);
if (chanrec != NULL) {
tim = (time_t) atol(tims);
banlist_exception_add(chanrec, ban, setby, tim);
}
g_free(params);
}
static void event_invite_list(IRC_SERVER_REC *server, const char *data)
{
IRC_CHANNEL_REC *chanrec;
char *params, *channel, *invite;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &channel, &invite);
chanrec = irc_channel_find(server, channel);
if (chanrec != NULL)
invitelist_add(chanrec, invite);
g_free(params);
}
void mode_lists_init(void)
{
signal_add("channel destroyed", (SIGNAL_FUNC) channel_destroyed);
signal_add("chanquery ban", (SIGNAL_FUNC) event_banlist);
signal_add("chanquery eban", (SIGNAL_FUNC) event_ebanlist);
signal_add("chanquery ilist", (SIGNAL_FUNC) event_invite_list);
}
void mode_lists_deinit(void)
{
signal_remove("channel destroyed", (SIGNAL_FUNC) channel_destroyed);
signal_remove("chanquery ban", (SIGNAL_FUNC) event_banlist);
signal_remove("chanquery eban", (SIGNAL_FUNC) event_ebanlist);
signal_remove("chanquery ilist", (SIGNAL_FUNC) event_invite_list);
}
|