Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/source/ignore.c
1069 views
1
/*
2
* ignore.c: handles the ingore command for irc
3
*
4
* Written By Michael Sandrof
5
*
6
* Copyright(c) 1990
7
*
8
* See the COPYRIGHT file, or do a HELP IRCII COPYRIGHT
9
*/
10
11
12
#include "irc.h"
13
static char cvsrevision[] = "$Id: ignore.c 3 2008-02-25 09:49:14Z keaston $";
14
CVS_REVISION(ignore_c)
15
#include "struct.h"
16
17
#include "ignore.h"
18
#include "ircaux.h"
19
#include "list.h"
20
#include "input.h"
21
#include "screen.h"
22
#include "misc.h"
23
#include "vars.h"
24
#include "output.h"
25
#define MAIN_SOURCE
26
#include "modval.h"
27
28
int ignore_usernames = 0;
29
char *highlight_char = NULL;
30
31
static int remove_ignore (char *);
32
static void ignore_list (char *);
33
static char *cut_n_fix_glob ( char *);
34
35
/* ignored_nicks: pointer to the head of the ignore list */
36
Ignore *ignored_nicks = NULL;
37
38
#define IGNORE_REMOVE 1
39
#define IGNORE_DONT 2
40
#define IGNORE_HIGH -1
41
#define IGNORE_CGREP -2
42
43
static Ignore *new_ignore = NULL;
44
45
void add_channel_grep(char *channel, char *what, int flag)
46
{
47
Ignore *new;
48
int count;
49
char *chan, *ptr;
50
char *new_str, *p;
51
while (channel)
52
{
53
new_str = p = m_strdup(what);
54
if ((ptr = strchr(channel, ',')) != NULL)
55
*ptr = '\0';
56
57
chan = make_channel(channel);
58
if (chan && !(new = (Ignore *) list_lookup((List **) &ignored_nicks, chan, !USE_WILDCARDS, !REMOVE_FROM_LIST)))
59
{
60
Ignore *tmp, *old;
61
char *s;
62
if ((new = (Ignore *) remove_from_list((List **) &ignored_nicks, channel)) != NULL)
63
{
64
new_free(&(new->nick));
65
for (tmp = new->except; tmp; tmp = old)
66
{
67
old = tmp->next;
68
new_free(&(tmp->nick));
69
new_free(&(tmp));
70
}
71
for (tmp = new->looking; tmp; tmp = old)
72
{
73
old = tmp->next;
74
new_free(&(tmp->nick));
75
new_free(&(tmp));
76
}
77
new_free((char **)&new);
78
}
79
new = (Ignore *) new_malloc(sizeof(Ignore));
80
new->nick = m_strdup(chan);
81
while ((s = new_next_arg(new_str, &new_str)))
82
{
83
tmp = (Ignore *) new_malloc(sizeof(Ignore));
84
tmp->nick = m_strdup(s);
85
add_to_list((List **)&new->looking, (List *)tmp);
86
}
87
add_to_list((List **) &ignored_nicks, (List *) new);
88
new->cgrep = flag;
89
}
90
if (ptr)
91
*(ptr++) = ',';
92
channel = ptr;
93
new_free(&p);
94
}
95
for (new = ignored_nicks, count = 1; new; new = new->next, count++)
96
new->num = count;
97
if (*what)
98
*what = 0;
99
}
100
101
/*
102
* ignore_nickname: adds nick to the ignore list, using type as the type of
103
* ignoring to take place.
104
*/
105
void ignore_nickname(char *nick, long type, int flag)
106
{
107
Ignore *new, *newc;
108
char *msg,
109
*ptr;
110
char *new_nick = NULL;
111
char buffer[BIG_BUFFER_SIZE + 1];
112
int count;
113
114
if (type == -1)
115
return;
116
while (nick)
117
{
118
if ((ptr = strchr(nick, ',')) != NULL)
119
*ptr = '\0';
120
121
if (*nick)
122
{
123
new_nick = is_channel(nick) ? m_strdup(nick) : cut_n_fix_glob(nick);
124
125
if (!(new = (Ignore *) list_lookup((List **) &ignored_nicks, new_nick, !USE_WILDCARDS, !REMOVE_FROM_LIST)))
126
{
127
if (flag == IGNORE_REMOVE)
128
{
129
say("%s is not on the ignore list", nick);
130
if (ptr)
131
*(ptr++) = ',';
132
nick = ptr;
133
continue;
134
}
135
else
136
{
137
if ((new = (Ignore *) remove_from_list((List **) &ignored_nicks, nick)) != NULL)
138
{
139
Ignore *tmp, *old;
140
new_free(&(new->nick));
141
new_free(&new->looking);
142
for (tmp = new->except; tmp; tmp = old)
143
{
144
old = tmp->next;
145
new_free(&(tmp->nick));
146
new_free(&(tmp));
147
}
148
for (tmp = new->looking; tmp; tmp = old)
149
{
150
old = tmp->next;
151
new_free(&(tmp->nick));
152
new_free(&(tmp));
153
}
154
new_free((char **)&new);
155
}
156
new = (Ignore *) new_malloc(sizeof(Ignore));
157
new->nick = new_nick;
158
add_to_list((List **) &ignored_nicks, (List *) new);
159
}
160
for (newc = ignored_nicks, count = 1; newc; newc = newc->next, count++)
161
newc->num = count;
162
163
}
164
new_ignore = new;
165
switch (flag)
166
{
167
case IGNORE_REMOVE:
168
new->type &= (~type);
169
new->high &= (~type);
170
new->dont &= (~type);
171
new->cgrep &= (~type);
172
msg = "Not ignoring";
173
break;
174
case IGNORE_DONT:
175
new->dont |= type;
176
new->type &= (~type);
177
new->high &= (~type);
178
new->cgrep &= (~type);
179
msg = "Never ignoring";
180
break;
181
case IGNORE_HIGH:
182
new->high |= type;
183
new->type &= (~type);
184
new->dont &= (~type);
185
new->cgrep &= (~type);
186
msg = "Highlighting";
187
break;
188
case IGNORE_CGREP:
189
new->cgrep |= type;
190
new->high &= (~type);
191
new->type &= (~type);
192
new->dont &= (~type);
193
msg = "Channel Grep";
194
break;
195
default:
196
new->type |= type;
197
new->high &= (~type);
198
new->dont &= (~type);
199
new->cgrep &= (~type);
200
msg = "Ignoring";
201
break;
202
}
203
if (type == IGNORE_ALL)
204
{
205
switch (flag)
206
{
207
case IGNORE_REMOVE:
208
remove_ignore(new->nick);
209
break;
210
case IGNORE_HIGH:
211
say("Highlighting ALL messages from %s", new->nick);
212
break;
213
case IGNORE_CGREP:
214
say("Grepping ALL messages from %s", new->nick);
215
break;
216
case IGNORE_DONT:
217
say("Never ignoring messages from %s", new->nick);
218
break;
219
default:
220
say("Ignoring ALL messages from %s", new->nick);
221
break;
222
}
223
return;
224
}
225
else if (type)
226
{
227
strcpy(buffer, msg);
228
if (type & IGNORE_MSGS)
229
strcat(buffer, " MSGS");
230
if (type & IGNORE_PUBLIC)
231
strcat(buffer, " PUBLIC");
232
if (type & IGNORE_WALLS)
233
strcat(buffer, " WALLS");
234
if (type & IGNORE_WALLOPS)
235
strcat(buffer, " WALLOPS");
236
if (type & IGNORE_INVITES)
237
strcat(buffer, " INVITES");
238
if (type & IGNORE_NOTICES)
239
strcat(buffer, " NOTICES");
240
if (type & IGNORE_NOTES)
241
strcat(buffer, " NOTES");
242
if (type & IGNORE_CTCPS)
243
strcat(buffer, " CTCPS");
244
if (type & IGNORE_CRAP)
245
strcat(buffer, " CRAP");
246
if (type & IGNORE_CDCC)
247
strcat(buffer, " CDCC");
248
if (type & IGNORE_KICKS)
249
strcat(buffer, " KICKS");
250
if (type & IGNORE_MODES)
251
strcat(buffer, " MODES");
252
if (type & IGNORE_SMODES)
253
strcat(buffer, " SMODES");
254
if (type & IGNORE_JOINS)
255
strcat(buffer, " JOINS");
256
if (type & IGNORE_TOPICS)
257
strcat(buffer, " TOPICS");
258
if (type & IGNORE_QUITS)
259
strcat(buffer, " QUITS");
260
if (type & IGNORE_PARTS)
261
strcat(buffer, " PARTS");
262
if (type & IGNORE_NICKS)
263
strcat(buffer, " NICKS");
264
if (type & IGNORE_PONGS)
265
strcat(buffer, " PONGS");
266
if (type & IGNORE_SPLITS)
267
strcat(buffer, " SPLITS");
268
say("%s from %s", buffer, new->nick);
269
}
270
}
271
if (ptr)
272
*(ptr++) = ',';
273
nick = ptr;
274
}
275
}
276
277
/*
278
* remove_ignore: removes the given nick from the ignore list and returns 0.
279
* If the nick wasn't in the ignore list to begin with, 1 is returned.
280
*/
281
static int remove_ignore(char *nick)
282
{
283
Ignore *tmp, *new, *old;
284
char *new_nick = NULL;
285
int count = 0;
286
287
new_nick = (is_channel(nick) ? m_strdup(nick) : cut_n_fix_glob(nick));
288
289
/*
290
* Look for an exact match first.
291
*/
292
if ((tmp = (Ignore *) list_lookup((List **)&ignored_nicks, new_nick, !USE_WILDCARDS, REMOVE_FROM_LIST)) != NULL)
293
{
294
say("%s removed from ignore list", tmp->nick);
295
new_free(&(tmp->nick));
296
for (new = tmp->except; new; new = old)
297
{
298
old = new->next;
299
new_free(&(new->nick));
300
new_free(&(new));
301
}
302
for (new = tmp->looking; new; new = old)
303
{
304
old = new->next;
305
new_free(&(new->nick));
306
new_free(&(new));
307
}
308
new_free((char **)&tmp);
309
count++;
310
}
311
312
/*
313
* Otherwise clear everything that matches.
314
*/
315
else while ((tmp = (Ignore *)list_lookup((List **)&ignored_nicks, new_nick, USE_WILDCARDS, REMOVE_FROM_LIST)) != NULL)
316
{
317
say("%s removed from ignore list", tmp->nick);
318
new_free(&(tmp->nick));
319
for (new = tmp->except; new; new = old)
320
{
321
old = new->next;
322
new_free(&(new->nick));
323
new_free(&(new));
324
}
325
for (new = tmp->looking; new; new = old)
326
{
327
old = new->next;
328
new_free(&(new->nick));
329
new_free(&(new));
330
}
331
new_free((char **)&tmp);
332
333
count++;
334
}
335
336
if (!count)
337
say("%s is not in the ignore list!", new_nick);
338
339
new_free(&new_nick);
340
return count;
341
}
342
343
/*
344
* is_ignored: checks to see if nick is being ignored (poor nick). Checks
345
* against type to see if ignoring is to take place. If nick is marked as
346
* IGNORE_ALL or ignorace types match, 1 is returned, otherwise 0 is
347
* returned.
348
*/
349
int is_ignored(char *nick, long type)
350
{
351
Ignore *tmp;
352
353
if (ignored_nicks)
354
{
355
if ((tmp = (Ignore *) list_lookup((List **) &ignored_nicks, nick, USE_WILDCARDS, !REMOVE_FROM_LIST)) != NULL)
356
{
357
if (tmp->dont & type)
358
return (DONT_IGNORE);
359
if (tmp->type & type)
360
return (IGNORED);
361
if (tmp->high & type)
362
return (HIGHLIGHTED);
363
if (tmp->high & type)
364
return (CHANNEL_GREP);
365
}
366
}
367
return (0);
368
}
369
370
int check_is_ignored(char *nick)
371
{
372
Ignore *tmp;
373
374
if (ignored_nicks)
375
{
376
if ((tmp = (Ignore *) list_lookup((List **) &ignored_nicks, nick, USE_WILDCARDS, !REMOVE_FROM_LIST)) != NULL)
377
return 1;
378
}
379
return 0;
380
}
381
382
/* ignore_list: shows the entired ignore list */
383
static void ignore_list(char *nick)
384
{
385
Ignore *tmp;
386
int len = 0;
387
char buffer[BIG_BUFFER_SIZE + 1];
388
if (ignored_nicks)
389
{
390
say("Ignore List:");
391
if (nick)
392
len = strlen(nick);
393
for (tmp = ignored_nicks; tmp; tmp = tmp->next)
394
{
395
396
if (nick)
397
{
398
if (strncmp(nick, tmp->nick, len))
399
continue;
400
}
401
*buffer = 0;
402
if (tmp->type == IGNORE_ALL)
403
strmopencat(buffer, BIG_BUFFER_SIZE, " ALL", NULL);
404
else if (tmp->high == IGNORE_ALL)
405
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "ALL", highlight_char, NULL);
406
else if (tmp->dont == IGNORE_ALL)
407
strmopencat(buffer, BIG_BUFFER_SIZE, " DONT-ALL", NULL);
408
else
409
{
410
if (tmp->type & IGNORE_PUBLIC)
411
strmcat(buffer, " PUBLIC", BIG_BUFFER_SIZE);
412
else if (tmp->high & IGNORE_PUBLIC)
413
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "PUBLIC", highlight_char, NULL);
414
else if (tmp->dont & IGNORE_PUBLIC)
415
strmcat(buffer, " DONT-PUBLIC", BIG_BUFFER_SIZE);
416
417
if (tmp->type & IGNORE_MSGS)
418
strmcat(buffer, " MSGS", BIG_BUFFER_SIZE);
419
else if (tmp->high & IGNORE_MSGS)
420
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "MSG", highlight_char, NULL);
421
else if (tmp->dont & IGNORE_MSGS)
422
strmcat(buffer, " DONT-MSGS", BIG_BUFFER_SIZE);
423
424
if (tmp->type & IGNORE_WALLS)
425
strmcat(buffer, " WALLS", BIG_BUFFER_SIZE);
426
else if (tmp->high & IGNORE_WALLS)
427
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "WALL", highlight_char, NULL);
428
else if (tmp->dont & IGNORE_WALLS)
429
strmcat(buffer, " DONT-WALLS", BIG_BUFFER_SIZE);
430
431
if (tmp->type & IGNORE_WALLOPS)
432
strmcat(buffer, " WALLOPS", BIG_BUFFER_SIZE);
433
else if (tmp->high & IGNORE_WALLOPS)
434
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "WALLOPS", highlight_char, NULL);
435
else if (tmp->dont & IGNORE_WALLOPS)
436
strmcat(buffer, " DONT-WALLOPS", BIG_BUFFER_SIZE);
437
438
if (tmp->type & IGNORE_INVITES)
439
strmcat(buffer, " INVITES", BIG_BUFFER_SIZE);
440
else if (tmp->high & IGNORE_INVITES)
441
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "INVITES", highlight_char, NULL);
442
else if (tmp->dont & IGNORE_INVITES)
443
strmcat(buffer, " DONT-INVITES", BIG_BUFFER_SIZE);
444
445
if (tmp->type & IGNORE_NOTICES)
446
strmcat(buffer, " NOTICES", BIG_BUFFER_SIZE);
447
else if (tmp->high & IGNORE_NOTICES)
448
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "NOTICES", highlight_char, NULL);
449
else if (tmp->dont & IGNORE_NOTICES)
450
strmcat(buffer, " DONT-NOTICES", BIG_BUFFER_SIZE);
451
452
if (tmp->type & IGNORE_NOTES)
453
strmcat(buffer, " NOTES", BIG_BUFFER_SIZE);
454
else if (tmp->high & IGNORE_NOTES)
455
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "NOTES", highlight_char, NULL);
456
else if (tmp->dont & IGNORE_NOTES)
457
strmcat(buffer, " DONT-NOTES", BIG_BUFFER_SIZE);
458
459
if (tmp->type & IGNORE_CTCPS)
460
strmcat(buffer, " CTCPS", BIG_BUFFER_SIZE);
461
else if (tmp->high & IGNORE_CTCPS)
462
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "CTCPS", highlight_char, NULL);
463
else if (tmp->dont & IGNORE_CTCPS)
464
strmcat(buffer, " DONT-CTCPS", BIG_BUFFER_SIZE);
465
466
if (tmp->type & IGNORE_CDCC)
467
strmcat(buffer, " CDCC", BIG_BUFFER_SIZE);
468
else if (tmp->high & IGNORE_CDCC)
469
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "CDCC", highlight_char, NULL);
470
else if (tmp->dont & IGNORE_CDCC)
471
strmcat(buffer, " DONT-CDCC", BIG_BUFFER_SIZE);
472
473
if (tmp->type & IGNORE_KICKS)
474
strmcat(buffer, " KICKS", BIG_BUFFER_SIZE);
475
else if (tmp->high & IGNORE_KICKS)
476
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "KICKS", highlight_char, NULL);
477
else if (tmp->dont & IGNORE_KICKS)
478
strmcat(buffer, " DONT-KICKS", BIG_BUFFER_SIZE);
479
480
if (tmp->type & IGNORE_MODES)
481
strmcat(buffer, " MODES", BIG_BUFFER_SIZE);
482
else if (tmp->high & IGNORE_MODES)
483
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "MODES", highlight_char, NULL);
484
else if (tmp->dont & IGNORE_MODES)
485
strmcat(buffer, " DONT-MODES", BIG_BUFFER_SIZE);
486
487
if (tmp->type & IGNORE_SMODES)
488
strmcat(buffer, " SMODES", BIG_BUFFER_SIZE);
489
else if (tmp->high & IGNORE_SMODES)
490
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "SMODES", highlight_char, NULL);
491
else if (tmp->dont & IGNORE_SMODES)
492
strmcat(buffer, " DONT-SMODES", BIG_BUFFER_SIZE);
493
494
if (tmp->type & IGNORE_JOINS)
495
strmcat(buffer, " JOINS", BIG_BUFFER_SIZE);
496
else if (tmp->high & IGNORE_JOINS)
497
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "JOINS", highlight_char, NULL);
498
else if (tmp->dont & IGNORE_JOINS)
499
strmcat(buffer, " DONT-JOINS", BIG_BUFFER_SIZE);
500
501
if (tmp->type & IGNORE_TOPICS)
502
strmcat(buffer, " TOPICS", BIG_BUFFER_SIZE);
503
else if (tmp->high & IGNORE_TOPICS)
504
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "TOPICS", highlight_char, NULL);
505
else if (tmp->dont & IGNORE_TOPICS)
506
strmcat(buffer, " DONT-TOPICS", BIG_BUFFER_SIZE);
507
508
if (tmp->type & IGNORE_QUITS)
509
strmcat(buffer, " QUITS", BIG_BUFFER_SIZE);
510
else if (tmp->high & IGNORE_QUITS)
511
strmopencat(buffer, BIG_BUFFER_SIZE,space, highlight_char, "QUITS", highlight_char, NULL);
512
else if (tmp->dont & IGNORE_QUITS)
513
strmcat(buffer, " DONT-QUITS", BIG_BUFFER_SIZE);
514
515
if (tmp->type & IGNORE_PARTS)
516
strmcat(buffer, " PARTS", BIG_BUFFER_SIZE);
517
else if (tmp->high & IGNORE_PARTS)
518
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "PARTS", highlight_char, NULL);
519
else if (tmp->dont & IGNORE_PARTS)
520
strmcat(buffer, " DONT-PARTS", BIG_BUFFER_SIZE);
521
522
if (tmp->type & IGNORE_NICKS)
523
strmcat(buffer, " NICKS", BIG_BUFFER_SIZE);
524
else if (tmp->high & IGNORE_NICKS)
525
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "NICKS", highlight_char, NULL);
526
else if (tmp->dont & IGNORE_NICKS)
527
strmcat(buffer, " DONT-NICKS", BIG_BUFFER_SIZE);
528
529
530
if (tmp->type & IGNORE_PONGS)
531
strmcat(buffer, " PONGS", BIG_BUFFER_SIZE);
532
else if (tmp->high & IGNORE_PONGS)
533
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "PONGS", highlight_char, NULL);
534
else if (tmp->dont & IGNORE_PONGS)
535
strmcat(buffer, " DONT-PONGS", BIG_BUFFER_SIZE);
536
537
538
if (tmp->type & IGNORE_SPLITS)
539
strmcat(buffer, " SPLITS", BIG_BUFFER_SIZE);
540
else if (tmp->high & IGNORE_SPLITS)
541
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "SPLITS", highlight_char, NULL);
542
else if (tmp->dont & IGNORE_SPLITS)
543
strmcat(buffer, " DONT-SPLITS", BIG_BUFFER_SIZE);
544
545
if (tmp->type & IGNORE_CRAP)
546
strmcat(buffer, " CRAP", BIG_BUFFER_SIZE);
547
else if (tmp->high & IGNORE_CRAP)
548
strmopencat(buffer, BIG_BUFFER_SIZE, space, highlight_char, "CRAP", highlight_char, NULL);
549
else if (tmp->dont & IGNORE_CRAP)
550
strmcat(buffer, " DONT-CRAP", BIG_BUFFER_SIZE);
551
552
}
553
if (tmp->except)
554
{
555
Ignore *new;
556
strmcat(buffer, " EXCEPT ", BIG_BUFFER_SIZE);
557
for (new = tmp->except; new; new = new->next)
558
strmopencat(buffer, BIG_BUFFER_SIZE, new->nick, space, NULL);
559
}
560
if (tmp->looking && tmp->cgrep)
561
{
562
Ignore *new;
563
strmcat(buffer, " CGREP ", BIG_BUFFER_SIZE);
564
for (new = tmp->looking; new; new = new->next)
565
strmopencat(buffer, BIG_BUFFER_SIZE, "[", new->nick, "] ", NULL);
566
}
567
put_it("%s", convert_output_format(" %K[%G$[-2]0%K] %C$[-25]1%W:%n $2-", "%d %s %s", tmp->num, tmp->nick, buffer));
568
}
569
}
570
else
571
bitchsay("There are no nicknames or channels being ignored");
572
}
573
574
long ignore_type (char *type, int len)
575
{
576
long ret = -1;
577
if (!type || !*type)
578
return -1;
579
if (!strncmp(type, "ALL", len))
580
ret = IGNORE_ALL;
581
else if (!strncmp(type, "MSGS", len))
582
ret = IGNORE_MSGS;
583
else if (!strncmp(type, "PUBLIC", len))
584
ret = IGNORE_PUBLIC;
585
else if (!strncmp(type, "WALLS", len))
586
ret = IGNORE_WALLS;
587
else if (!strncmp(type, "WALLOPS", len))
588
ret = IGNORE_WALLOPS;
589
else if (!strncmp(type, "INVITES", len))
590
ret = IGNORE_INVITES;
591
else if (!strncmp(type, "NOTICES", len))
592
ret = IGNORE_NOTICES;
593
else if (!strncmp(type, "NOTES", len))
594
ret = IGNORE_NOTES;
595
else if (!strncmp(type, "CTCPS", len))
596
ret = IGNORE_CTCPS;
597
else if (!strncmp(type, "CDCC", len))
598
ret = IGNORE_CDCC;
599
else if (!strncmp(type, "KICKS", len))
600
ret = IGNORE_KICKS;
601
else if (!strncmp(type, "MODES", len))
602
ret = IGNORE_MODES;
603
else if (!strncmp(type, "SMODES", len))
604
ret = IGNORE_SMODES;
605
else if (!strncmp(type, "JOINS", len))
606
ret = IGNORE_JOINS;
607
else if (!strncmp(type, "TOPICS", len))
608
ret = IGNORE_TOPICS;
609
else if (!strncmp(type, "QUITS", len))
610
ret = IGNORE_QUITS;
611
else if (!strncmp(type, "CRAP", len))
612
ret = IGNORE_CRAP;
613
else if (!strncmp(type, "PARTS", len))
614
ret = IGNORE_PARTS;
615
else if (!strncmp(type, "NICKS", len))
616
ret = IGNORE_NICKS;
617
else if (!strncmp(type, "PONGS", len))
618
ret = IGNORE_PONGS;
619
else if (!strncmp(type, "SPLITS", len))
620
ret = IGNORE_SPLITS;
621
else if (!strncmp(type, "NONE", len))
622
ret = 0;
623
return ret;
624
}
625
626
#define HANDLE_TYPE(x, y) \
627
if ((tmp->dont & x) == x) \
628
strmcat(buffer, " DONT-" y, BIG_BUFFER_SIZE); \
629
else if ((tmp->type & x) == x) \
630
strmcat(buffer, " " y, BIG_BUFFER_SIZE); \
631
else if ((tmp->high & x) == x) \
632
strmopencat(buffer, BIG_BUFFER_SIZE, space, high, y, high, NULL);
633
634
635
char *get_ignore_types (Ignore *tmp)
636
{
637
static char buffer[BIG_BUFFER_SIZE + 1];
638
char *high = highlight_char;
639
640
*buffer = 0;
641
HANDLE_TYPE(IGNORE_ALL, "ALL")
642
else
643
{
644
HANDLE_TYPE(IGNORE_MSGS, "MSGS")
645
HANDLE_TYPE(IGNORE_PUBLIC, "PUBLIC")
646
HANDLE_TYPE(IGNORE_WALLS, "WALLS")
647
HANDLE_TYPE(IGNORE_WALLOPS, "WALLOPS")
648
HANDLE_TYPE(IGNORE_INVITES, "INVITES")
649
HANDLE_TYPE(IGNORE_NOTICES, "NOTICES")
650
HANDLE_TYPE(IGNORE_NOTES, "NOTES")
651
HANDLE_TYPE(IGNORE_CTCPS, "CTCPS")
652
HANDLE_TYPE(IGNORE_TOPICS, "TOPICS")
653
HANDLE_TYPE(IGNORE_NICKS, "NICKS")
654
HANDLE_TYPE(IGNORE_JOINS, "JOINS")
655
HANDLE_TYPE(IGNORE_CRAP, "CRAP")
656
}
657
return buffer;
658
}
659
660
int ignore_exception(Ignore *old, char *args)
661
{
662
Ignore *new = NULL;
663
int flag = 0;
664
if (args && !(new = (Ignore *)list_lookup((List **)&old->except, args, !USE_WILDCARDS, !REMOVE_FROM_LIST)))
665
{
666
new = new_malloc(sizeof(Ignore));
667
malloc_strcpy(&new->nick, args);
668
add_to_list((List **)&old->except, (List *)new);
669
flag = DONT_IGNORE;
670
bitchsay(" EXCEPT %s", new->nick);
671
}
672
return flag;
673
}
674
675
/*
676
* ignore: does the /IGNORE command. Figures out what type of ignoring the
677
* user wants to do and calls the proper ignore command to do it.
678
*/
679
BUILT_IN_COMMAND(ignore)
680
{
681
char *nick,
682
*type;
683
int len,
684
flag,
685
no_flags;
686
long ret;
687
688
if ((nick = next_arg(args, &args)) != NULL)
689
{
690
no_flags = 1;
691
while ((type = next_arg(args, &args)) != NULL)
692
{
693
no_flags = 0;
694
upper(type);
695
switch (*type)
696
{
697
case '^':
698
flag = IGNORE_DONT;
699
type++;
700
break;
701
case '-':
702
flag = IGNORE_REMOVE;
703
type++;
704
break;
705
case '+':
706
flag = IGNORE_HIGH;
707
type++;
708
break;
709
case '%':
710
flag = IGNORE_CGREP;
711
type++;
712
break;
713
default:
714
flag = 0;
715
break;
716
}
717
if (!(len = strlen(type)))
718
{
719
say("You must specify one of the following:");
720
say("\tALL MSGS PUBLIC WALLS WALLOPS INVITES \
721
NOTICES NOTES CTCPS CDCC KICKS MODES SMODES JOINS TOPICS QUITS PARTS NICKS PONGS SQUITS CRAP NONE");
722
return;
723
}
724
if (!strncmp(type, "NONE", len))
725
{
726
char *ptr;
727
728
while (nick)
729
{
730
if ((ptr = strchr(nick, ',')) != NULL)
731
*ptr = 0;
732
if (*nick)
733
remove_ignore(nick);
734
if (ptr)
735
*(ptr++) = ',';
736
nick = ptr;
737
}
738
}
739
else if (!strncmp(type, "EXCEPT", len) && new_ignore)
740
{
741
while ((nick = next_arg(args, &args)))
742
flag = ignore_exception(new_ignore, nick);
743
}
744
else if ((flag == IGNORE_CGREP) && ((ret = ignore_type(type, len)) != -1))
745
add_channel_grep(nick, args, ret);
746
else if ((ret = ignore_type(type, len)) != -1)
747
ignore_nickname(nick, ret, flag);
748
else
749
{
750
bitchsay("You must specify one of the following:");
751
say("\tALL MSGS PUBLIC WALLS WALLOPS INVITES \
752
NOTICES NOTES CTCPS CDCC KICKS MODES SMODES JOINS TOPICS QUITS PARTS NICKS PONGS SQUITS CRAP NONE");
753
}
754
}
755
if (no_flags)
756
ignore_list(nick);
757
new_ignore = NULL;
758
} else
759
ignore_list(NULL);
760
}
761
762
/*
763
* set_highlight_char: what the name says.. the character to use
764
* for highlighting.. either BOLD, INVERSE, or UNDERLINE..
765
*/
766
void set_highlight_char(Window *win, char *s, int unused)
767
{
768
int len = strlen(s);
769
770
if (!my_strnicmp(s, "BOLD", len))
771
malloc_strcpy(&highlight_char, BOLD_TOG_STR);
772
else if (!my_strnicmp(s, "INVERSE", len))
773
malloc_strcpy(&highlight_char, REV_TOG_STR);
774
else if (!my_strnicmp(s, "UNDERLINE", len))
775
malloc_strcpy(&highlight_char, UND_TOG_STR);
776
else
777
malloc_strcpy(&highlight_char, s);
778
}
779
780
/* check_ignore -- replaces the old double_ignore
781
* Why did i change the name?
782
* * double_ignore isnt really applicable any more becuase it doesnt
783
* do two ignore lookups, it only does one.
784
* * This function doesnt look anything like the old double_ignore
785
* * This function works for the new *!*@* patterns stored by
786
* ignore instead of the old nick and userhost patterns.
787
* (jfn may 1995)
788
*/
789
int check_ignore (char *nick, char *userhost, char *channel, long type, char *str)
790
{
791
char *nickuserhost = NULL;
792
Ignore *tmp;
793
794
malloc_sprintf(&nickuserhost, "%s!%s", nick ? nick : "*", userhost ? userhost : "*");
795
796
if (ignored_nicks)
797
{
798
if ((tmp = (Ignore *) list_lookup((List **)&ignored_nicks, nickuserhost, USE_WILDCARDS, !REMOVE_FROM_LIST)))
799
{
800
if (tmp->except && list_lookup((List **)&tmp->except, nickuserhost, USE_WILDCARDS, !REMOVE_FROM_LIST))
801
{
802
new_free(&nickuserhost);
803
return(DONT_IGNORE);
804
}
805
806
new_free(&nickuserhost);
807
if (tmp->dont & type)
808
return(DONT_IGNORE);
809
if (tmp->type & type)
810
return (IGNORED);
811
if (tmp->high & type)
812
return (HIGHLIGHTED);
813
}
814
new_free(&nickuserhost);
815
if (channel && is_channel(channel) && (tmp = (Ignore *) list_lookup((List **)&ignored_nicks, channel, USE_WILDCARDS, !REMOVE_FROM_LIST)))
816
{
817
if (tmp->dont & type)
818
return(DONT_IGNORE);
819
if (tmp->type & type)
820
return (IGNORED);
821
if (tmp->high & type)
822
return (HIGHLIGHTED);
823
if ((tmp->cgrep & type) && str)
824
{
825
Ignore *t;
826
for (t = tmp->looking; t; t = t->next)
827
{
828
if (stristr(str, t->nick))
829
return DONT_IGNORE;
830
}
831
return IGNORED;
832
}
833
}
834
}
835
new_free(&nickuserhost);
836
return (DONT_IGNORE);
837
}
838
839
/* Written by hop in April 1995 -- taken from SIRP */
840
/* MALLOCED */
841
static char *cut_n_fix_glob ( char *nickuserhost )
842
{
843
char *nick, *userhost = NULL,
844
*user = NULL, *host = NULL;
845
char *copy = NULL;
846
847
/* patch by texaco makes this work right */
848
849
copy = LOCAL_COPY(nickuserhost);
850
nick = copy;
851
if ((userhost = strchr(copy, '!')))
852
{
853
/* NICK IS CORRECT HERE */
854
855
*userhost++ = 0;
856
857
/* doh! */
858
user = userhost;
859
860
if ((host = sindex(userhost, "@")))
861
/* USER IS CORRECT HERE */
862
*host++ = 0;
863
864
else if (sindex(userhost, "."))
865
{
866
user = "*";
867
host = userhost;
868
}
869
/* fixed by sheik */
870
if (!user)
871
user = "*";
872
if (!host)
873
host = "*";
874
}
875
else
876
{
877
user = copy;
878
if ((host = sindex(user, "@")))
879
{
880
nick = "*";
881
*host++ = 0;
882
}
883
else
884
{
885
if (sindex(user, "."))
886
{
887
nick = "*";
888
host = user;
889
user = "*";
890
}
891
else
892
{
893
nick = user;
894
user = "*";
895
host = "*";
896
}
897
}
898
}
899
return m_opendup(nick, "!", user, "@", host, NULL);
900
}
901
902
void tremove_ignore (char *stuff, char *line)
903
{
904
int count = 0;
905
Ignore *new, *newc, *ex;
906
char *p;
907
int except = 0;
908
if (!line || !*line)
909
return;
910
while ((p = next_arg(line, &line)))
911
{
912
for (new = ignored_nicks; new; new = newc)
913
{
914
newc = new->next;
915
if (matchmcommand(p, new->num) || !my_stricmp(new->nick, p))
916
{
917
for (ex = new->except; ex; ex = ex->next)
918
except++;
919
remove_ignore(new->nick);
920
count++;
921
}
922
}
923
}
924
if (count)
925
bitchsay("Removed %d ignores and %d exceptions", count, except);
926
else
927
bitchsay("No matching ignore");
928
for (new = ignored_nicks, count = 1; new; new = new->next, count++)
929
new->num = count;
930
}
931
932
BUILT_IN_COMMAND(tignore)
933
{
934
ignore_list(NULL);
935
if (ignored_nicks)
936
{
937
if (args && *args)
938
tremove_ignore(NULL, args);
939
else
940
add_wait_prompt("Which ignore to delete (-2, 2-5, ...) ? ", tremove_ignore, args, WAIT_PROMPT_LINE, 1);
941
}
942
}
943
944
/*
945
* get_ignores_by_pattern: Get all the ignores that match the pattern
946
* If "covered" is 0, then return all ignores matched by patterns
947
* If "covered" is 1, then return all ignores that would activate on patterns
948
* MALLOCED
949
*/
950
char *get_ignores_by_pattern (char *patterns, int covered)
951
{
952
Ignore *tmp;
953
char *pattern;
954
char *retval = NULL;
955
956
while ((pattern = new_next_arg(patterns, &patterns)))
957
{
958
for (tmp = ignored_nicks; tmp; tmp = tmp->next)
959
{
960
if (covered ? wild_match(tmp->nick, pattern)
961
: wild_match(pattern, tmp->nick))
962
m_s3cat(&retval, space, tmp->nick);
963
}
964
}
965
966
return retval ? retval : m_strdup(empty_string);
967
}
968
969
int get_type_by_desc (char *type, int *do_mask, int *dont_mask)
970
{
971
char *l1, *l2;
972
int len;
973
int *mask = NULL;
974
975
*do_mask = *dont_mask = 0;
976
977
while (type && *type)
978
{
979
l1 = new_next_arg(type, &type);
980
while (l1 && *l1)
981
{
982
l2 = l1;
983
if ((l1 = strchr(l1, ',')))
984
*l1++ = 0;
985
986
if (*l2 == '!')
987
{
988
l2++;
989
mask = dont_mask;
990
}
991
else
992
mask = do_mask;
993
994
if (!(len = strlen(l2)))
995
continue;
996
997
if (!strncmp(l2, "ALL", len))
998
*mask |= IGNORE_ALL;
999
else if (!strncmp(l2, "MSGS", len))
1000
*mask |= IGNORE_MSGS;
1001
else if (!strncmp(l2, "PUBLIC", len))
1002
*mask |= IGNORE_PUBLIC;
1003
else if (!strncmp(l2, "WALLS", len))
1004
*mask |= IGNORE_WALLS;
1005
else if (!strncmp(l2, "WALLOPS", len))
1006
*mask |= IGNORE_WALLOPS;
1007
else if (!strncmp(l2, "INVITES", len))
1008
*mask |= IGNORE_INVITES;
1009
else if (!strncmp(l2, "NOTICES", len))
1010
*mask |= IGNORE_NOTICES;
1011
else if (!strncmp(l2, "NOTES", len))
1012
*mask |= IGNORE_NOTES;
1013
else if (!strncmp(l2, "CTCPS", len))
1014
*mask |= IGNORE_CTCPS;
1015
else if (!strncmp(l2, "TOPICS", len))
1016
*mask |= IGNORE_TOPICS;
1017
else if (!strncmp(l2, "NICKS", len))
1018
*mask |= IGNORE_NICKS;
1019
else if (!strncmp(l2, "JOINS", len))
1020
*mask |= IGNORE_JOINS;
1021
else if (!strncmp(l2, "CRAP", len))
1022
*mask |= IGNORE_CRAP;
1023
}
1024
}
1025
1026
return 0;
1027
}
1028
1029
/*
1030
* This is nasty and should be done in a more generalized way, but until
1031
* then, this function just does what has to be done. Please note that
1032
* if you go to the pains to re-write the ignore handling, please do fix
1033
* this to work the right way, please? =)
1034
*/
1035
char *get_ignore_types_by_pattern (char *pattern)
1036
{
1037
Ignore *tmp;
1038
1039
upper(pattern);
1040
for (tmp = ignored_nicks; tmp; tmp = tmp->next)
1041
{
1042
if (!strcmp(tmp->nick, pattern))
1043
return get_ignore_types(tmp);
1044
}
1045
1046
return empty_string;
1047
}
1048
1049
char *get_ignore_patterns_by_type (char *ctype)
1050
{
1051
Ignore *tmp;
1052
int do_mask = 0, dont_mask = 0;
1053
char *result = NULL;
1054
1055
/*
1056
* Convert the user's input into something we can use.
1057
* If the user doesnt specify anything useful, then we
1058
* just punt right here.
1059
*/
1060
upper(ctype);
1061
get_type_by_desc(ctype, &do_mask, &dont_mask);
1062
if (do_mask == 0 && dont_mask == 0)
1063
return m_strdup(empty_string);
1064
1065
for (tmp = ignored_nicks; tmp; tmp = tmp->next)
1066
{
1067
/*
1068
* Any "negative ignore" bits, if any, must be present.
1069
*/
1070
if ((tmp->dont & dont_mask) != dont_mask)
1071
continue;
1072
1073
/*
1074
* Any "positive ignore" bits, if any, must be present,
1075
* but there must not be a corresponding "negative ignore"
1076
* bit for the levels as well. That is to say, the
1077
* negative ignore bits "turn off" any corresponding bits
1078
* in the positive ignore set.
1079
*/
1080
if (((tmp->type & ~tmp->dont) & do_mask) != do_mask)
1081
continue;
1082
1083
/* Add it to the fray */
1084
m_s3cat(&result, space, tmp->nick);
1085
}
1086
1087
return result;
1088
}
1089
1090