a97ff6eecf2059ba94459816c1b2122be035b6f9
[srvx.git] / src / spamserv.h
1 /* spamserv.h - anti spam service
2  * Copyright 2004 feigling
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.  Important limitations are
8  * listed in the COPYING file that accompanies this software.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, email srvx-maintainers@srvx.net.
17  *
18  * $Id: spamserv.h,v 1.3 2004/06/27 22:20:00 feigling Exp $
19  */
20
21 #ifndef _spamserv_h
22 #define _spamserv_h
23
24 #ifdef HAVE_ARPA_INET_H
25 #include <arpa/inet.h>
26 #endif
27
28 /***********************************************/
29 /*                   Channel                   */
30 /***********************************************/
31
32 enum channelinfo
33 {
34     ci_SpamLimit = 0,
35     ci_AdvReaction,
36     ci_WarnReaction,
37     ci_Max
38 };
39
40 #define CHAN_INFO_SIZE          (ci_Max + 1)
41 #define CHAN_INFO_DEFAULT       "bls"
42
43 #define CHAN_SPAMSCAN           0x00000001
44 #define CHAN_FLOODSCAN          0x00000002
45 #define CHAN_JOINFLOOD          0x00000004
46 #define CHAN_ADV_SCAN           0x00000008
47 #define CHAN_SCAN_CHANOPS       0x00000010
48 #define CHAN_SCAN_VOICED        0x00000020
49 #define CHAN_SUSPENDED          0x00000040
50
51 #define CHAN_FLAGS_DEFAULT      (CHAN_SPAMSCAN | CHAN_FLOODSCAN | CHAN_JOINFLOOD)
52
53 #define CHECK_SPAM(x)           ((x)->flags & CHAN_SPAMSCAN)
54 #define CHECK_FLOOD(x)          ((x)->flags & CHAN_FLOODSCAN)
55 #define CHECK_JOINFLOOD(x)      ((x)->flags & CHAN_JOINFLOOD)
56 #define CHECK_ADV(x)            ((x)->flags & CHAN_ADV_SCAN)
57 #define CHECK_CHANOPS(x)        ((x)->flags & CHAN_SCAN_CHANOPS)
58 #define CHECK_VOICED(x)         ((x)->flags & CHAN_SCAN_VOICED)
59 #define CHECK_SUSPENDED(x)      ((x)->flags & CHAN_SUSPENDED)
60
61 struct chanInfo
62 {
63     struct chanNode        *channel;
64     struct string_list     *exceptions;
65     unsigned int           flags : 30;
66     unsigned int           exceptlevel;
67     char                   info[CHAN_INFO_SIZE];
68     time_t                 suspend_expiry;
69 };
70
71 /***********************************************/
72 /*                    User                     */
73 /***********************************************/
74
75 #define USER_KICK           0x00000001
76 #define USER_KICKBAN        0x00000002
77 #define USER_SHORT_TBAN     0x00000004
78 #define USER_LONG_TBAN      0x00000008
79 #define USER_KILL           0x00000010
80 #define USER_GLINE          0x00000020
81 #define USER_WARNED         0x00000040
82 #define USER_KILLED         0x00000080
83 #define USER_ADV_WARNED     0x00000100
84
85 #define CHECK_KICK(x)           ((x)->flags & USER_KICK)
86 #define CHECK_KICKBAN(x)        ((x)->flags & USER_KICKBAN)
87 #define CHECK_SHORT_TBAN(x)     ((x)->flags & USER_SHORT_TBAN)
88 #define CHECK_LONG_TBAN(x)      ((x)->flags & USER_LONG_TBAN)
89 #define CHECK_KILL(x)           ((x)->flags & USER_KILL)
90 #define CHECK_GLINE(x)          ((x)->flags & USER_GLINE)
91 #define CHECK_WARNED(x)         ((x)->flags & USER_WARNED)
92 #define CHECK_KILLED(x)         ((x)->flags & USER_KILLED)
93 #define CHECK_ADV_WARNED(x)     ((x)->flags & USER_ADV_WARNED)
94
95 #define SPAM_WARNLEVEL          1
96
97 #define FLOOD_TIMEQ_FREQ        5
98 #define FLOOD_EXPIRE            5
99 #define FLOOD_WARNLEVEL         1
100 #define FLOOD_MAX_LINES         8
101
102 #define JOINFLOOD_TIMEQ_FREQ    225
103 #define JOINFLOOD_EXPIRE        450
104 #define JOINFLOOD_MAX           3
105 #define JOINFLOOD_B_DURATION    900
106
107 #define ADV_TIMEQ_FREQ          300
108 #define ADV_EXPIRE              900
109 #define ADV_WARNLEVEL           2
110
111 #define WARNLEVEL_TIMEQ_FREQ    1800
112 #define MAX_WARNLEVEL           6
113
114 #define KILL_TIMEQ_FREQ         450
115 #define KILL_EXPIRE             1800
116 #define KILL_WARNLEVEL          3
117
118 struct spamNode
119 {
120         struct chanNode         *channel;
121         unsigned long           crc32;
122         unsigned int            count;
123         struct spamNode         *prev;
124         struct spamNode         *next;
125 };
126
127 struct floodNode
128 {
129         struct chanNode         *channel;
130         struct userNode         *owner;
131         unsigned int            count;
132         time_t                  time;
133         struct floodNode        *prev;
134         struct floodNode        *next;
135 };
136
137 struct killNode
138 {
139         unsigned int            warnlevel;
140         time_t                  time;
141 };
142
143 struct userInfo
144 {
145     struct userNode             *user;
146         struct spamNode         *spam;
147         struct floodNode        *flood;
148         struct floodNode        *joinflood;
149         unsigned int            flags : 30;
150         unsigned int            warnlevel;
151         time_t                  lastadv;
152 };
153
154 /***********************************************/
155 /*                 Other Stuff                 */
156 /***********************************************/
157
158 enum cs_unreg
159 {
160     manually,
161     expire,
162     lost_all_users
163 };
164
165 void init_spamserv(const char *nick);
166 struct chanInfo *get_chanInfo(const char *channelname);
167 void spamserv_channel_message(struct chanNode *channel, struct userNode *user, char *text);
168 void spamserv_cs_suspend(struct chanNode *channel, time_t expiry, int suspend, char *reason);
169 int  spamserv_cs_move_merge(struct userNode *user, struct chanNode *channel, struct chanNode *target, int move);
170 void spamserv_cs_unregister(struct userNode *user, struct chanNode *channel, enum cs_unreg type, char *reason);
171
172 #endif