Added SILC Thread Queue API
[runtime.git] / apps / irssi / src / fe-common / core / fe-ignore-messages.c
1 /*
2  fe-ignore-messages.c : irssi
3
4     Copyright (C) 2000 Timo Sirainen
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 #include "module.h"
22 #include "signals.h"
23 #include "levels.h"
24 #include "ignore.h"
25 #include "servers.h"
26
27 static void sig_message_public(SERVER_REC *server, const char *msg,
28                                const char *nick, const char *address,
29                                const char *target)
30 {
31         if (ignore_check(server, nick, address, target, msg, MSGLEVEL_PUBLIC))
32                 signal_stop();
33 }
34
35 static void sig_message_private(SERVER_REC *server, const char *msg,
36                                 const char *nick, const char *address)
37 {
38         if (ignore_check(server, nick, address, NULL, msg, MSGLEVEL_MSGS))
39                 signal_stop();
40 }
41
42 static void sig_message_join(SERVER_REC *server, const char *channel,
43                              const char *nick, const char *address)
44 {
45         if (ignore_check(server, nick, address, channel, NULL, MSGLEVEL_JOINS))
46                 signal_stop();
47 }
48
49 static void sig_message_part(SERVER_REC *server, const char *channel,
50                              const char *nick, const char *address,
51                              const char *reason)
52 {
53         if (ignore_check(server, nick, address, channel, NULL, MSGLEVEL_PARTS))
54                 signal_stop();
55 }
56
57 static void sig_message_quit(SERVER_REC *server, const char *nick,
58                              const char *address, const char *reason)
59 {
60         if (ignore_check(server, nick, address, NULL, reason, MSGLEVEL_QUITS))
61                 signal_stop();
62 }
63
64 static void sig_message_kick(SERVER_REC *server, const char *channel,
65                              const char *nick, const char *kicker,
66                              const char *address, const char *reason)
67 {
68         /* never ignore if you were kicked */
69         if (g_strcasecmp(nick, server->nick) != 0 &&
70             ignore_check(server, kicker, address,
71                          channel, reason, MSGLEVEL_KICKS))
72                 signal_stop();
73 }
74
75 static void sig_message_nick(SERVER_REC *server, const char *newnick,
76                              const char *oldnick, const char *address)
77 {
78         if (ignore_check(server, oldnick, address,
79                          NULL, NULL, MSGLEVEL_NICKS) ||
80             ignore_check(server, newnick, address,
81                          NULL, NULL, MSGLEVEL_NICKS))
82                 signal_stop();
83 }
84
85 static void sig_message_own_nick(SERVER_REC *server, const char *newnick,
86                                  const char *oldnick, const char *address)
87 {
88         if (ignore_check(server, oldnick, address, NULL, NULL, MSGLEVEL_NICKS))
89                 signal_stop();
90 }
91
92 static void sig_message_invite(SERVER_REC *server, const char *channel,
93                                const char *nick, const char *address)
94 {
95         if (*channel == '\0' ||
96             ignore_check(server, nick, address,
97                          channel, NULL, MSGLEVEL_INVITES))
98                 signal_stop();
99 }
100
101 static void sig_message_topic(SERVER_REC *server, const char *channel,
102                               const char *topic,
103                               const char *nick, const char *address)
104 {
105         if (ignore_check(server, nick, address,
106                          channel, topic, MSGLEVEL_TOPICS))
107                 signal_stop();
108 }
109
110 void fe_ignore_messages_init(void)
111 {
112         signal_add_first("message public", (SIGNAL_FUNC) sig_message_public);
113         signal_add_first("message private", (SIGNAL_FUNC) sig_message_private);
114         signal_add_first("message join", (SIGNAL_FUNC) sig_message_join);
115         signal_add_first("message part", (SIGNAL_FUNC) sig_message_part);
116         signal_add_first("message quit", (SIGNAL_FUNC) sig_message_quit);
117         signal_add_first("message kick", (SIGNAL_FUNC) sig_message_kick);
118         signal_add_first("message nick", (SIGNAL_FUNC) sig_message_nick);
119         signal_add_first("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
120         signal_add_first("message invite", (SIGNAL_FUNC) sig_message_invite);
121         signal_add_first("message topic", (SIGNAL_FUNC) sig_message_topic);
122 }
123
124 void fe_ignore_messages_deinit(void)
125 {
126         signal_remove("message public", (SIGNAL_FUNC) sig_message_public);
127         signal_remove("message private", (SIGNAL_FUNC) sig_message_private);
128         signal_remove("message join", (SIGNAL_FUNC) sig_message_join);
129         signal_remove("message part", (SIGNAL_FUNC) sig_message_part);
130         signal_remove("message quit", (SIGNAL_FUNC) sig_message_quit);
131         signal_remove("message kick", (SIGNAL_FUNC) sig_message_kick);
132         signal_remove("message nick", (SIGNAL_FUNC) sig_message_nick);
133         signal_remove("message own_nick", (SIGNAL_FUNC) sig_message_own_nick);
134         signal_remove("message invite", (SIGNAL_FUNC) sig_message_invite);
135         signal_remove("message topic", (SIGNAL_FUNC) sig_message_topic);
136 }