Convert the ban parts of struct SLink into struct Ban.
[ircu2.10.12-pk.git] / include / channel.h
1 /*
2  * IRC - Internet Relay Chat, ircd/channel.h
3  * Copyright (C) 1990 Jarkko Oikarinen
4  * Copyright (C) 1996 - 1997 Carlo Wood
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, or (at your option)
9  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20 /** @file
21  * @brief Channel management and maintenance.
22  * @version $Id$
23  */
24 #ifndef INCLUDED_channel_h
25 #define INCLUDED_channel_h
26 #ifndef INCLUDED_ircd_defs_h
27 #include "ircd_defs.h"        /* NICKLEN */
28 #endif
29 #ifndef INCLUDED_sys_types_h
30 #include <sys/types.h>
31 #define INCLUDED_sys_types_h
32 #endif
33
34 struct SLink;
35 struct Client;
36
37 /*
38  * General defines
39  */
40
41 #define MAXMODEPARAMS   6       /**< Maximum number of mode parameters */
42 #define MODEBUFLEN      200     /**< Maximum length of a mode */
43
44 #define KEYLEN          23      /**< Maximum length of a key */
45 #define PASSLEN         23      /**< Maximum length of a password */
46 #define CHANNELLEN      200     /**< Maximum length of a channel */
47
48 #define MAXJOINARGS     15      /**< number of slots for join buffer */
49 #define STARTJOINLEN    10      /**< fuzzy numbers */
50 #define STARTCREATELEN  20
51
52 /*
53  * Macro's
54  */
55
56 #define ChannelExists(n)        (0 != FindChannel(n))
57
58 #define CHFL_CHANOP             0x0001  /**< Channel operator */
59 #define CHFL_VOICE              0x0002  /**< the power to speak */
60 #define CHFL_DEOPPED            0x0004  /**< Is de-opped by a server */
61 #define CHFL_SERVOPOK           0x0008  /**< Server op allowed */
62 #define CHFL_ZOMBIE             0x0010  /**< Kicked from channel */
63 #define CHFL_BAN                0x0020  /**< ban channel flag */
64 #define CHFL_BAN_IPMASK         0x0040  /**< ban mask is an IP-number mask */
65 #define CHFL_BAN_OVERLAPPED     0x0080  /**< ban overlapped, need bounce */
66 #define CHFL_BURST_JOINED       0x0100  /**< Just joined by net.junction */
67 #define CHFL_BURST_BAN          0x0200  /**< Ban part of last BURST */
68 #define CHFL_BURST_BAN_WIPEOUT  0x0400  /**< Ban will be wiped at EOB */
69 #define CHFL_BANVALID           0x0800  /**< CHFL_BANNED bit is valid */
70 #define CHFL_BANNED             0x1000  /**< Channel member is banned */
71 #define CHFL_SILENCE_IPMASK     0x2000  /**< silence mask is a CIDR */
72 #define CHFL_BURST_ALREADY_OPPED        0x04000  
73                                         /**< In oob BURST, but was already 
74                                          * joined and opped 
75                                          */
76 #define CHFL_BURST_ALREADY_VOICED       0x08000  
77                                         /**, In oob BURST, but was already 
78                                          * joined and voiced 
79                                          */
80 #define CHFL_CHANNEL_MANAGER    0x10000 /**< Set when creating channel or using 
81                                          * Apass 
82                                          */
83 #define CHFL_USER_PARTING       0x20000 /**< User is already parting that 
84                                          * channel 
85                                          */
86 #define CHFL_DELAYED            0x40000 /**< User's join message is delayed */
87
88 #define CHFL_OVERLAP         (CHFL_CHANOP | CHFL_VOICE)
89 #define CHFL_BANVALIDMASK    (CHFL_BANVALID | CHFL_BANNED)
90 #define CHFL_VOICED_OR_OPPED (CHFL_CHANOP | CHFL_VOICE)
91
92 /* Channel Visibility macros */
93
94 #define MODE_CHANOP     CHFL_CHANOP     /**< +o Chanop */
95 #define MODE_VOICE      CHFL_VOICE      /**< +v Voice */
96 #define MODE_PRIVATE    0x0004          /**< +p Private */
97 #define MODE_SECRET     0x0008          /**< +s Secret */
98 #define MODE_MODERATED  0x0010          /**< +m Moderated */
99 #define MODE_TOPICLIMIT 0x0020          /**< +t Topic Limited */
100 #define MODE_INVITEONLY 0x0040          /**< +i Invite only */
101 #define MODE_NOPRIVMSGS 0x0080          /**< +n No Private Messages */
102 #define MODE_KEY        0x0100          /**< +k Keyed */
103 #define MODE_BAN        0x0200          /**< +b Ban */
104 #define MODE_LIMIT      0x0400          /**< +l Limit */
105 #define MODE_REGONLY    0x0800          /**< Only +r users may join */
106 #define MODE_DELJOINS   0x1000          /**< New join messages are delayed */
107 #define MODE_SAVE       0x20000         /**< save this mode-with-arg 'til 
108                                          * later */
109 #define MODE_FREE       0x40000         /**< string needs to be passed to 
110                                          * MyFree() */
111 #define MODE_BURSTADDED 0x80000         /**< channel was created by a BURST */
112 #define MODE_UPASS      0x100000
113 #define MODE_APASS      0x200000
114 #define MODE_WASDELJOINS 0x400000       /**< Not DELJOINS, but some joins 
115                                          * pending */
116 /** mode flags which take another parameter (With PARAmeterS)
117  */
118 #define MODE_WPARAS     (MODE_CHANOP|MODE_VOICE|MODE_BAN|MODE_KEY|MODE_LIMIT|MODE_APASS|MODE_UPASS)
119
120 /** Available Channel modes */
121 #define infochanmodes feature_bool(FEAT_OPLEVELS) ? "AbiklmnopstUvrD" : "biklmnopstvrD"
122 /** Available Channel modes that take parameters */
123 #define infochanmodeswithparams feature_bool(FEAT_OPLEVELS) ? "AbkloUv" : "bklov"
124
125 #define HoldChannel(x)          (!(x))
126 /** name invisible */
127 #define SecretChannel(x)        ((x) && ((x)->mode.mode & MODE_SECRET))
128 /** channel not shown but names are */
129 #define HiddenChannel(x)        ((x) && ((x)->mode.mode & MODE_PRIVATE))
130 /** channel visible */
131 #define ShowChannel(v,c)        (PubChannel(c) || find_channel_member((v),(c)) || \
132                                  (IsAnOper(v) && HasPriv(v, PRIV_LIST_CHAN)))
133 #define PubChannel(x)           ((!x) || ((x)->mode.mode & \
134                                     (MODE_PRIVATE | MODE_SECRET)) == 0)
135
136 #define IsGlobalChannel(name)   (*(name) == '#')
137 #define IsLocalChannel(name)    (*(name) == '&')
138 #define IsChannelName(name)     (IsGlobalChannel(name) || IsLocalChannel(name))
139
140 typedef enum ChannelGetType {
141   CGT_NO_CREATE,
142   CGT_CREATE
143 } ChannelGetType;
144
145 /* used in SetMode() in channel.c and m_umode() in s_msg.c */
146
147 #define MODE_NULL      0
148 #define MODE_ADD       0x40000000
149 #define MODE_DEL       0x20000000
150
151 /* used in ListingArgs.flags */
152
153 #define LISTARG_TOPICLIMITS     0x0001
154 #define LISTARG_SHOWSECRET      0x0002
155
156 /**
157  * Maximum acceptable lag time in seconds: A channel younger than
158  * this is not protected against hacking admins.
159  * Mainly here to check if the TS clocks really sync (otherwise this
160  * will start causing HACK notices.
161  * This value must be the same on all servers.
162  *
163  * This value has been increased to 1 day in order to distinguish this
164  * "normal" type of HACK wallops / desyncs, from possiblity still
165  * existing bugs.
166  */
167 #define TS_LAG_TIME 86400
168
169 /**
170  * A Magic TS that is used for channels that are created by JOIN,
171  * a channel with this TS accepts all TS without complaining that
172  * it might receive later via MODE or CREATE.
173  *
174  * Part of the P9 compatibility, shouldn't occur on a P10 network.
175  */
176 #define MAGIC_REMOTE_JOIN_TS 1270080000
177
178 /**
179  * used in can_join to determine if an oper forced a join on a channel
180  */
181 #define MAGIC_OPER_OVERRIDE 1000
182
183
184 extern const char* const PartFmt1;
185 extern const char* const PartFmt2;
186 extern const char* const PartFmt1serv;
187 extern const char* const PartFmt2serv;
188
189
190 /*
191  * Structures
192  */
193
194 /** Information about a client on one channel
195  *
196  * This structure forms a sparse matrix with users down the side, and
197  * channels across the top.  This matrix holds all the information about
198  * which users are on what channels, and what modes that user has on that
199  * channel (if they are op'd, voice'd and cached information if they are
200  * banned or not)
201  */
202 struct Membership {
203   struct Client*     user;              /**< The user */
204   struct Channel*    channel;           /**< The channel */
205   struct Membership* next_member;       /**< The next user on this channel */
206   struct Membership* prev_member;       /**< The previous user on this channel*/
207   struct Membership* next_channel;      /**< Next channel this user is on */
208   struct Membership* prev_channel;      /**< Previous channel this user is on*/
209   unsigned int       status;            /**< Flags for op'd, voice'd, etc */
210   unsigned short     oplevel;           /**< Op level */
211 };
212
213 #define MAXOPLEVELDIGITS    3
214 #define MAXOPLEVEL          999
215
216 #define IsZombie(x)         ((x)->status & CHFL_ZOMBIE) /**< see \ref zombie */
217 #define IsDeopped(x)        ((x)->status & CHFL_DEOPPED)
218 #define IsBanned(x)         ((x)->status & CHFL_BANNED)
219 #define IsBanValid(x)       ((x)->status & CHFL_BANVALID)
220 #define IsChanOp(x)         ((x)->status & CHFL_CHANOP)
221 #define OpLevel(x)          ((x)->oplevel)
222 #define HasVoice(x)         ((x)->status & CHFL_VOICE)
223 #define IsServOpOk(x)       ((x)->status & CHFL_SERVOPOK)
224 #define IsBurstJoined(x)    ((x)->status & CHFL_BURST_JOINED)
225 #define IsVoicedOrOpped(x)  ((x)->status & CHFL_VOICED_OR_OPPED)
226 #define IsChannelManager(x) ((x)->status & CHFL_CHANNEL_MANAGER)
227 #define IsUserParting(x)    ((x)->status & CHFL_USER_PARTING)
228 #define IsDelayedJoin(x)    ((x)->status & CHFL_DELAYED)
229
230 #define SetBanned(x)        ((x)->status |= CHFL_BANNED)
231 #define SetBanValid(x)      ((x)->status |= CHFL_BANVALID)
232 #define SetDeopped(x)       ((x)->status |= CHFL_DEOPPED)
233 #define SetServOpOk(x)      ((x)->status |= CHFL_SERVOPOK)
234 #define SetBurstJoined(x)   ((x)->status |= CHFL_BURST_JOINED)
235 #define SetZombie(x)        ((x)->status |= CHFL_ZOMBIE)
236 #define SetChannelManager(x) ((x)->status |= CHFL_CHANNEL_MANAGER)
237 #define SetOpLevel(x, v)    (void)((x)->oplevel = (v))
238 #define SetUserParting(x)   ((x)->status |= CHFL_USER_PARTING)
239 #define SetDelayedJoin(x)   ((x)->status |= CHFL_DELAYED)
240
241 #define ClearBanned(x)      ((x)->status &= ~CHFL_BANNED)
242 #define ClearBanValid(x)    ((x)->status &= ~CHFL_BANVALID)
243 #define ClearDeopped(x)     ((x)->status &= ~CHFL_DEOPPED)
244 #define ClearServOpOk(x)    ((x)->status &= ~CHFL_SERVOPOK)
245 #define ClearBurstJoined(x) ((x)->status &= ~CHFL_BURST_JOINED)
246 #define ClearDelayedJoin(x) ((x)->status &= ~CHFL_DELAYED)
247
248 /** Mode information for a channel */
249 struct Mode {
250   unsigned int mode;
251   unsigned int limit;
252   char key[KEYLEN + 1];
253   char upass[PASSLEN + 1];
254   char apass[PASSLEN + 1];
255 };
256
257 /** A single ban for a channel. */
258 struct Ban {
259   struct Ban* next;   /**< next ban in the channel */
260   time_t when;        /**< timestamp when ban was added */
261   unsigned int flags; /**< modifier flags for the ban
262                        * Zero or more of CHFL_BURST_BAN_WIPEOUT,
263                        * CHFL_BAN_OVERLAPPED
264                        */
265   char *who;          /**< name of client that set the ban */
266   char *banstr;       /**< hostmask that the ban matches */
267 };
268
269 /** Information about a channel */
270 struct Channel {
271   struct Channel*    next;      /**< next channel in the global channel list */
272   struct Channel*    prev;      /**< previous channel */
273   struct Channel*    hnext;     /**< Next channel in the hash table */
274   struct DestructEvent* destruct_event; 
275   time_t             creationtime; /**< Creation time of this channel */
276   time_t             topic_time;   /**< Modification time of the topic */
277   unsigned int       users;        /**< Number of clients on this channel */
278   struct Membership* members;      /**< Pointer to the clients on this channel*/
279   struct SLink*      invites;      /**< List of invites on this channel */
280   struct Ban*        banlist;      /**< List of bans on this channel */
281   struct Mode        mode;         /**< This channels mode */
282   char               topic[TOPICLEN + 1]; /**< Channels topic */
283   char               topic_nick[NICKLEN + 1]; /**< Nick of the person who set
284                                                 *  The topic
285                                                 */
286   char               chname[1];    /**< Dynamically allocated string of the 
287                                      * channel name
288                                      */
289 };
290
291 /** Information about a /list in progress */
292 struct ListingArgs {
293   time_t max_time;
294   time_t min_time;
295   unsigned int max_users;
296   unsigned int min_users;
297   unsigned int flags;
298   time_t max_topic_time;
299   time_t min_topic_time;
300   unsigned int bucket;
301 };
302
303 struct ModeBuf {
304   unsigned int          mb_add;         /**< Modes to add */
305   unsigned int          mb_rem;         /**< Modes to remove */
306   struct Client        *mb_source;      /**< Source of MODE changes */
307   struct Client        *mb_connect;     /**< Connection of MODE changes */
308   struct Channel       *mb_channel;     /**< Channel they affect */
309   unsigned int          mb_dest;        /**< Destination of MODE changes */
310   unsigned int          mb_count;       /**< Number of modes w/args */
311   struct {
312     unsigned int        mbm_type;       /**< Type of argument */
313     union {
314       unsigned int      mbma_uint;      /**< A limit */
315       char             *mbma_string;    /**< A string */
316       struct Client    *mbma_client;    /**< A client */
317     }                   mbm_arg;        /**< The mode argument */
318   }                     mb_modeargs[MAXMODEPARAMS];
319                                         /**< A mode w/args */
320 };
321
322 #define MODEBUF_DEST_CHANNEL    0x00001 /**< Mode is flushed to channel */
323 #define MODEBUF_DEST_SERVER     0x00002 /**< Mode is flushed to server */
324
325 #define MODEBUF_DEST_OPMODE     0x00100 /**< Send server mode as OPMODE */
326 #define MODEBUF_DEST_DEOP       0x00200 /**< Deop the offender */
327 #define MODEBUF_DEST_BOUNCE     0x00400 /**< Bounce the modes */
328 #define MODEBUF_DEST_LOG        0x00800 /**< Log the mode changes to OPATH */
329
330 #define MODEBUF_DEST_HACK2      0x02000 /**< Send a HACK(2) notice, reverse */
331 #define MODEBUF_DEST_HACK3      0x04000 /**< Send a HACK(3) notice, TS == 0 */
332 #define MODEBUF_DEST_HACK4      0x08000 /**< Send a HACK(4) notice, TS == 0 */
333
334 #define MODEBUF_DEST_NOKEY      0x10000 /**< Don't send the real key */
335
336 #define MB_TYPE(mb, i)          ((mb)->mb_modeargs[(i)].mbm_type)
337 #define MB_UINT(mb, i)          ((mb)->mb_modeargs[(i)].mbm_arg.mbma_uint)
338 #define MB_STRING(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_string)
339 #define MB_CLIENT(mb, i)        ((mb)->mb_modeargs[(i)].mbm_arg.mbma_client)
340
341 /** A buffer represeting a list of joins to send */
342 struct JoinBuf {
343   struct Client        *jb_source;      /**< Source of joins (ie, joiner) */
344   struct Client        *jb_connect;     /**< Connection of joiner */
345   unsigned int          jb_type;        /**< Type of join (JOIN or CREATE) */
346   char                 *jb_comment;     /**< part comment */
347   time_t                jb_create;      /**< Creation timestamp */
348   unsigned int          jb_count;       /**< Number of channels */
349   unsigned int          jb_strlen;      /**< length so far */
350   struct Channel       *jb_channels[MAXJOINARGS];
351                                         /**< channels joined or whatever */
352 };
353
354 #define JOINBUF_TYPE_JOIN       0       /**< send JOINs */
355 #define JOINBUF_TYPE_CREATE     1       /**< send CREATEs */
356 #define JOINBUF_TYPE_PART       2       /**< send PARTs */
357 #define JOINBUF_TYPE_PARTALL    3       /**< send local PARTs, but not remote */
358
359 extern struct Channel* GlobalChannelList;
360 extern int             LocalChanOperMode;
361
362 /*
363  * Proto types
364  */
365 extern void clean_channelname(char* name);
366 extern void channel_modes(struct Client *cptr, char *mbuf, char *pbuf,
367                           int buflen, struct Channel *chptr,
368                           struct Membership *member);
369 extern int set_mode(struct Client* cptr, struct Client* sptr,
370                     struct Channel* chptr, int parc, char* parv[],
371                     char* mbuf, char* pbuf, char* npbuf, int* badop);
372 extern void send_hack_notice(struct Client *cptr, struct Client *sptr,
373                              int parc, char *parv[], int badop, int mtype);
374 extern struct Channel *get_channel(struct Client *cptr,
375                                    char *chname, ChannelGetType flag);
376 extern struct Membership* find_member_link(struct Channel * chptr,
377                                            const struct Client* cptr);
378 extern int sub1_from_channel(struct Channel* chptr);
379 extern int destruct_channel(struct Channel* chptr);
380 extern int can_join(struct Client *sptr, struct Channel *chptr, char *key);
381 extern void add_user_to_channel(struct Channel* chptr, struct Client* who,
382                                 unsigned int flags, int oplevel);
383 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
384                         const char *param, int *count);
385 extern void add_token_to_sendbuf(char *token, size_t *sblenp, int *firstp,
386                                  int *send_itp, char is_a_ban, int mode);
387 extern int add_banid(struct Client *cptr, struct Channel *chptr, char *banid,
388                      int change, int firsttime);
389 extern struct Ban *next_removed_overlapped_ban(void);
390 extern void cancel_mode(struct Client *sptr, struct Channel *chptr, char m,
391                         const char *param, int *count);
392 extern void make_zombie(struct Membership* member, struct Client* who,
393                         struct Client* cptr, struct Client* sptr,
394                         struct Channel* chptr);
395 extern struct Client* find_chasing(struct Client* sptr, const char* user, int* chasing);
396 void add_invite(struct Client *cptr, struct Channel *chptr);
397 int number_of_zombies(struct Channel *chptr);
398
399 extern const char* find_no_nickchange_channel(struct Client* cptr);
400 extern struct Membership* IsMember(struct Client *cptr, struct Channel *chptr);
401 extern struct Membership* find_channel_member(struct Client* cptr, struct Channel* chptr);
402 extern int member_can_send_to_channel(struct Membership* member, int reveal);
403 extern int client_can_send_to_channel(struct Client *cptr, struct Channel *chptr, int reveal);
404
405 extern void remove_user_from_channel(struct Client *sptr, struct Channel *chptr);
406 extern void remove_user_from_all_channels(struct Client* cptr);
407
408 extern int is_chan_op(struct Client *cptr, struct Channel *chptr);
409 extern int is_zombie(struct Client *cptr, struct Channel *chptr);
410 extern int has_voice(struct Client *cptr, struct Channel *chptr);
411 /*
412    NOTE: pointer is compared, and not dereferenced, called by
413    add_target with a void*, since targets could be anything,
414    this function can't make any assumptions that it has a channel
415 */
416 extern int IsInvited(struct Client* cptr, const void* chptr);
417 extern void send_channel_modes(struct Client *cptr, struct Channel *chptr);
418 extern char *pretty_mask(char *mask);
419 extern void del_invite(struct Client *cptr, struct Channel *chptr);
420 extern void list_set_default(void); /* this belongs elsewhere! */
421
422 extern void RevealDelayedJoin(struct Membership *member);
423 extern void CheckDelayedJoins(struct Channel *chan);
424
425 extern void modebuf_init(struct ModeBuf *mbuf, struct Client *source,
426                          struct Client *connect, struct Channel *chan,
427                          unsigned int dest);
428 extern void modebuf_mode(struct ModeBuf *mbuf, unsigned int mode);
429 extern void modebuf_mode_uint(struct ModeBuf *mbuf, unsigned int mode,
430                               unsigned int uint);
431 extern void modebuf_mode_string(struct ModeBuf *mbuf, unsigned int mode,
432                                 char *string, int free);
433 extern void modebuf_mode_client(struct ModeBuf *mbuf, unsigned int mode,
434                                 struct Client *client);
435 extern int modebuf_flush(struct ModeBuf *mbuf);
436 extern void modebuf_extract(struct ModeBuf *mbuf, char *buf);
437
438 extern void mode_ban_invalidate(struct Channel *chan);
439 extern void mode_invite_clear(struct Channel *chan);
440
441 extern int mode_parse(struct ModeBuf *mbuf, struct Client *cptr,
442                       struct Client *sptr, struct Channel *chptr,
443                       int parc, char *parv[], unsigned int flags,
444                       struct Membership* member);
445
446 #define MODE_PARSE_SET          0x01    /**< actually set channel modes */
447 #define MODE_PARSE_STRICT       0x02    /**< +m +n +t style not supported */
448 #define MODE_PARSE_FORCE        0x04    /**< force the mode to be applied */
449 #define MODE_PARSE_BOUNCE       0x08    /**< we will be bouncing the modes */
450 #define MODE_PARSE_NOTOPER      0x10    /**< send "not chanop" to user */
451 #define MODE_PARSE_NOTMEMBER    0x20    /**< send "not member" to user */
452 #define MODE_PARSE_WIPEOUT      0x40    /**< wipe out +k and +l during burst */
453 #define MODE_PARSE_BURST        0x80    /**< be even more strict w/extra args */
454
455 extern void joinbuf_init(struct JoinBuf *jbuf, struct Client *source,
456                          struct Client *connect, unsigned int type,
457                          char *comment, time_t create);
458 extern void joinbuf_join(struct JoinBuf *jbuf, struct Channel *chan,
459                          unsigned int flags);
460 extern int joinbuf_flush(struct JoinBuf *jbuf);
461 extern struct Ban *make_ban(const char *banstr);
462 extern void free_ban(struct Ban *ban);
463
464 #endif /* INCLUDED_channel_h */