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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
|
/* Copyright (C) 1999-2004 Timo Sirainen */
#include "module.h"
#include "module-formats.h"
#include "signals.h"
#include "levels.h"
#include "misc.h"
#include "settings.h"
#include "irc-servers.h"
#include "printtext.h"
static void event_whois(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *user, *host, *realname;
g_return_if_fail(data != NULL);
params = event_get_params(data, 6, NULL, &nick, &user,
&host, NULL, &realname);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS, nick, user, host, realname);
g_free(params);
}
static void event_whois_special(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *str;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3 | PARAM_FLAG_GETREST, NULL, &nick, &str);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_SPECIAL, nick, str);
g_free(params);
}
static void event_whois_idle(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *secstr, *signonstr, *rest, *timestr;
long days, hours, mins, secs;
time_t signon;
g_return_if_fail(data != NULL);
params = event_get_params(data, 5 | PARAM_FLAG_GETREST, NULL,
&nick, &secstr, &signonstr, &rest);
secs = atol(secstr);
signon = strstr(rest, "signon time") == NULL ? 0 :
(time_t) atol(signonstr);
days = secs/3600/24;
hours = (secs%(3600*24))/3600;
mins = (secs%3600)/60;
secs %= 60;
if (signon == 0)
printformat(server, nick, MSGLEVEL_CRAP, IRCTXT_WHOIS_IDLE,
nick, days, hours, mins, secs);
else {
timestr = my_asctime(signon);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_IDLE_SIGNON,
nick, days, hours, mins, secs, timestr);
g_free(timestr);
}
g_free(params);
}
static void event_whois_server(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *whoserver, *desc;
g_return_if_fail(data != NULL);
params = event_get_params(data, 4, NULL, &nick, &whoserver, &desc);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_SERVER, nick, whoserver, desc);
g_free(params);
}
static void event_whois_oper(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *type;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &nick, &type);
/* Bugfix: http://bugs.irssi.org/?do=details&id=99
* Author: Geert Hauwaerts <geert@irssi.org>
* Date: Wed Sep 15 20:17:24 CEST 2004
*/
if ((!strncmp(type, "is an ", 6)) || (!strncmp(type, "is a ", 5))) {
type += 5;
if (*type == ' ') type++;
}
if (*type == '\0')
type = "IRC Operator";
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_OPER, nick, type);
g_free(params);
}
static void event_whois_modes(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *modes;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3 | PARAM_FLAG_GETREST,
NULL, &nick, &modes);
if (!strncmp(modes, "is using modes ", 15))
modes += 15;
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_MODES, nick, modes);
g_free(params);
}
static void event_whois_realhost(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *txt_real, *txt_hostname, *hostname;
g_return_if_fail(data != NULL);
/* <yournick> real hostname <nick> <hostname> */
params = event_get_params(data, 5, NULL, &nick, &txt_real,
&txt_hostname, &hostname);
if (strcmp(txt_real, "real") != 0 ||
strcmp(txt_hostname, "hostname") != 0) {
/* <yournick> <nick> :... from <hostname> */
g_free(params);
params = event_get_params(data, 3, NULL, &nick, &hostname);
hostname = strstr(hostname, "from ");
if (hostname != NULL) hostname += 5;
}
if (hostname != NULL) {
if (!strncmp(hostname, "*@", 2))
hostname += 2;
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_REALHOST, nick, hostname, "");
} else {
event_whois_special(server, data);
}
g_free(params);
}
static void event_whois_usermode326(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *usermode;
g_return_if_fail(data != NULL);
/* <yournick> <nick> :has oper privs: <mode> */
params = event_get_params(data, 3, NULL, &nick, &usermode);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_USERMODE, nick, usermode);
g_free(params);
}
static void event_whois_realhost327(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *hostname, *ip, *text;
g_return_if_fail(data != NULL);
/* <yournick> <hostname> <ip> :Real hostname/IP */
params = event_get_params(data, 5, NULL, &nick, &hostname, &ip, &text);
if (*text != '\0') {
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_REALHOST, nick, hostname, ip);
} else {
event_whois_special(server, data);
}
g_free(params);
}
static void event_whois_realhost338(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *arg1, *arg2, *arg3;
g_return_if_fail(data != NULL);
/*
* :<server> 338 <yournick> <nick> <user>@<host> <ip> :Actual user@host, actual IP
* (ircu) or
* :<server> 338 <yournick> <nick> <ip> :actually using host
* (ratbox)
*/
params = event_get_params(data, 5, NULL, &nick, &arg1, &arg2, &arg3);
if (*arg3 != '\0') {
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_REALHOST, nick, arg1, arg2);
} else if (*arg2 != '\0') {
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_REALHOST, nick, arg1, "");
} else {
event_whois_special(server, data);
}
g_free(params);
}
static void event_whois_usermode(IRC_SERVER_REC *server, const char *data)
{
char *params, *txt_usermodes, *nick, *usermode;
g_return_if_fail(data != NULL);
params = event_get_params(data, 4, NULL, &txt_usermodes,
&nick, &usermode);
if (strcmp(txt_usermodes, "usermodes") == 0) {
/* <yournick> usermodes <nick> usermode */
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_USERMODE, nick, usermode);
} else {
event_whois_special(server, data);
}
g_free(params);
}
static void hide_safe_channel_id(IRC_SERVER_REC *server, char *chans)
{
const char *idchan, *nick_flags;
char *p, *dest, *end, id;
int count, length, chanstart;
if (!server->isupport_sent)
idchan = "!:5";
else {
idchan = g_hash_table_lookup(server->isupport, "IDCHAN");
if (idchan == NULL)
return;
}
nick_flags = server->get_nick_flags(server);
while (*idchan != '\0') {
id = *idchan;
if (idchan[1] != ':')
return;
length = strtoul(idchan+2, &end, 10);
if (*end == ',')
end++;
else if (*end != '\0')
return;
idchan = end;
count = 0;
chanstart = TRUE;
for (dest = p = chans; *p != '\0'; p++) {
if (count > 0)
count--;
else {
if (*p == ' ')
chanstart = TRUE;
else {
if (chanstart && *p == id)
count = length;
chanstart = chanstart && strchr(nick_flags, *p);
}
*dest++ = *p;
}
}
*dest = '\0';
}
}
static void event_whois_channels(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *chans;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &nick, &chans);
/* sure - we COULD print the channel names as-is, but since the
colors, bolds, etc. are mostly just to fool people, I think we
should show the channel names as they REALLY are so they could
even be joined without any extra tricks. */
chans = show_lowascii(chans);
if (settings_get_bool("whois_hide_safe_channel_id"))
hide_safe_channel_id(server, chans);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_CHANNELS, nick, chans);
g_free(chans);
g_free(params);
}
static void event_whois_away(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *awaymsg;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &nick, &awaymsg);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_AWAY, nick, awaymsg);
g_free(params);
}
static void event_end_of_whois(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2, NULL, &nick);
if (server->whois_found) {
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_END_OF_WHOIS, nick);
}
g_free(params);
}
static void event_whois_auth(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *text;
g_return_if_fail(data != NULL);
params = event_get_params(data, 3, NULL, &nick, &text);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOIS_EXTRA, nick, text);
g_free(params);
}
static void event_whowas(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick, *user, *host, *realname;
g_return_if_fail(data != NULL);
params = event_get_params(data, 6, NULL, &nick, &user,
&host, NULL, &realname);
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_WHOWAS, nick, user, host, realname);
g_free(params);
}
static void event_end_of_whowas(IRC_SERVER_REC *server, const char *data)
{
char *params, *nick;
g_return_if_fail(data != NULL);
params = event_get_params(data, 2, NULL, &nick);
if (server->whowas_found) {
printformat(server, nick, MSGLEVEL_CRAP,
IRCTXT_END_OF_WHOWAS, nick);
}
g_free(params);
}
struct whois_event_table {
int num;
void (*func)(IRC_SERVER_REC *, const char *);
};
static struct whois_event_table events[] = {
{ 312, event_whois_server },
{ 326, event_whois_usermode326 },
{ 327, event_whois_realhost327 },
{ 338, event_whois_realhost338 },
{ 379, event_whois_modes },
{ 378, event_whois_realhost },
{ 377, event_whois_usermode },
{ 317, event_whois_idle },
{ 330, event_whois_auth },
{ 319, event_whois_channels },
{ 0, NULL }
};
static void event_whois_default(IRC_SERVER_REC *server, const char *data)
{
int i, num;
num = atoi(current_server_event);
for (i = 0; events[i].num != 0; i++) {
if (events[i].num == num) {
events[i].func(server, data);
return;
}
}
event_whois_special(server, data);
}
void fe_whois_init(void)
{
settings_add_bool("lookandfeel", "whois_hide_safe_channel_id", TRUE);
signal_add("event 311", (SIGNAL_FUNC) event_whois);
signal_add("event 312", (SIGNAL_FUNC) event_whois_server);
/* readding this events fixes the printing of /whois -yes *
Bug http://bugs.irssi.org/?do=details&id=123 */
signal_add("event 317", (SIGNAL_FUNC) event_whois_idle);
signal_add("event 319", (SIGNAL_FUNC) event_whois_channels);
signal_add("event 313", (SIGNAL_FUNC) event_whois_oper);
signal_add("event 330", (SIGNAL_FUNC) event_whois_auth);
signal_add("event 377", (SIGNAL_FUNC) event_whois_usermode);
signal_add("event 378", (SIGNAL_FUNC) event_whois_realhost);
signal_add("event 379", (SIGNAL_FUNC) event_whois_modes);
signal_add("event 327", (SIGNAL_FUNC) event_whois_realhost327);
signal_add("event 326", (SIGNAL_FUNC) event_whois_usermode326);
signal_add("event 338", (SIGNAL_FUNC) event_whois_realhost338);
signal_add("whois away", (SIGNAL_FUNC) event_whois_away);
signal_add("whois oper", (SIGNAL_FUNC) event_whois_oper);
signal_add("whowas away", (SIGNAL_FUNC) event_whois_away);
signal_add("whois default event", (SIGNAL_FUNC) event_whois_default);
signal_add("event 318", (SIGNAL_FUNC) event_end_of_whois);
signal_add("event 314", (SIGNAL_FUNC) event_whowas);
signal_add("event 369", (SIGNAL_FUNC) event_end_of_whowas);
}
void fe_whois_deinit(void)
{
signal_remove("event 311", (SIGNAL_FUNC) event_whois);
signal_remove("event 312", (SIGNAL_FUNC) event_whois_server);
signal_remove("event 317", (SIGNAL_FUNC) event_whois_idle);
signal_remove("event 319", (SIGNAL_FUNC) event_whois_channels);
signal_remove("event 313", (SIGNAL_FUNC) event_whois_oper);
signal_remove("event 330", (SIGNAL_FUNC) event_whois_auth);
signal_remove("event 377", (SIGNAL_FUNC) event_whois_usermode);
signal_remove("event 378", (SIGNAL_FUNC) event_whois_realhost);
signal_remove("event 379", (SIGNAL_FUNC) event_whois_modes);
signal_remove("event 327", (SIGNAL_FUNC) event_whois_realhost327);
signal_remove("event 326", (SIGNAL_FUNC) event_whois_usermode326);
signal_remove("event 338", (SIGNAL_FUNC) event_whois_realhost338);
signal_remove("whois away", (SIGNAL_FUNC) event_whois_away);
signal_remove("whois oper", (SIGNAL_FUNC) event_whois_oper);
signal_remove("whowas away", (SIGNAL_FUNC) event_whois_away);
signal_remove("whois default event", (SIGNAL_FUNC) event_whois_default);
signal_remove("event 318", (SIGNAL_FUNC) event_end_of_whois);
signal_remove("event 314", (SIGNAL_FUNC) event_whowas);
signal_remove("event 369", (SIGNAL_FUNC) event_end_of_whowas);
}
|