ircu2.10.12 pk910 fork
[ircu2.10.12-pk.git] / include / gline.h
1 #ifndef INCLUDED_gline_h
2 #define INCLUDED_gline_h
3 /*
4  * IRC - Internet Relay Chat, include/gline.h
5  * Copyright (C) 1990 Jarkko Oikarinen and
6  *                    University of Oulu, Computing Center
7  * Copyright (C) 1996 -1997 Carlo Wood
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2, or (at your option)
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23 /** @file
24  * @brief Structures and APIs for G-line manipulation.
25  * @version $Id: gline.h 1904 2009-02-09 00:03:34Z entrope $
26  */
27 #ifndef INCLUDED_sys_types_h
28 #include <sys/types.h>
29 #define INCLUDED_sys_types_h
30 #endif
31
32 #ifndef INCLUDED_res_h
33 #include "res.h"
34 #endif
35
36 struct Client;
37 struct StatDesc;
38
39 #define GLINE_MAX_EXPIRE 31536000 /**< max expire: 1 year */
40
41 /** Local state of a G-line. */
42 enum GlineLocalState {
43   GLOCAL_GLOBAL,                /**< G-line state unmodified locally. */
44   GLOCAL_ACTIVATED,             /**< G-line state locally activated. */
45   GLOCAL_DEACTIVATED            /**< G-line state locally deactivated. */
46 };
47
48 /** Description of a G-line. */
49 struct Gline {
50   struct Gline *gl_next;        /**< Next G-line in linked list. */
51   struct Gline**gl_prev_p;      /**< Previous pointer to this G-line. */
52   char         *gl_user;        /**< Username mask (or channel/realname mask). */
53   char         *gl_host;        /**< Host portion of mask. */
54   char         *gl_reason;      /**< Reason for G-line. */
55   time_t        gl_expire;      /**< Expiration timestamp. */
56   time_t        gl_lastmod;     /**< Last modification timestamp. */
57   time_t        gl_lifetime;    /**< Record expiration timestamp. */
58   struct irc_in_addr gl_addr;   /**< IP address (for IP-based G-lines). */
59   unsigned char gl_bits;        /**< Bits in gl_addr used in the mask. */
60   unsigned int  gl_flags;       /**< G-line status flags. */
61   enum GlineLocalState gl_state;/**< G-line local state. */
62 };
63
64 /** Action to perform on a G-line. */
65 enum GlineAction {
66   GLINE_ACTIVATE,               /**< G-line should be activated. */
67   GLINE_DEACTIVATE,             /**< G-line should be deactivated. */
68   GLINE_LOCAL_ACTIVATE,         /**< G-line should be locally activated. */
69   GLINE_LOCAL_DEACTIVATE,       /**< G-line should be locally deactivated. */
70   GLINE_MODIFY                  /**< G-line should be modified. */
71 };
72
73 #define GLINE_ACTIVE    0x0001  /**< G-line is active. */
74 #define GLINE_IPMASK    0x0002  /**< gl_addr and gl_bits fields are valid. */
75 #define GLINE_BADCHAN   0x0004  /**< G-line prohibits users from joining a channel. */
76 #define GLINE_LOCAL     0x0008  /**< G-line only applies to this server. */
77 #define GLINE_ANY       0x0010  /**< Search flag: Find any G-line. */
78 #define GLINE_FORCE     0x0020  /**< Override normal limits on G-lines. */
79 #define GLINE_EXACT     0x0040  /**< Exact match only (no wildcards). */
80 #define GLINE_LDEACT    0x0080  /**< Locally deactivated. */
81 #define GLINE_GLOBAL    0x0100  /**< Find only global G-lines. */
82 #define GLINE_LASTMOD   0x0200  /**< Find only G-lines with non-zero lastmod. */
83 #define GLINE_OPERFORCE 0x0400  /**< Oper forcing G-line to be set. */
84 #define GLINE_REALNAME  0x0800  /**< G-line matches only the realname field. */
85
86 #define GLINE_EXPIRE    0x1000  /**< Expiration time update */
87 #define GLINE_LIFETIME  0x2000  /**< Record lifetime update */
88 #define GLINE_REASON    0x4000  /**< Reason update */
89
90 /** Controllable flags that can be set on an actual G-line. */
91 #define GLINE_MASK      (GLINE_ACTIVE | GLINE_BADCHAN | GLINE_LOCAL | GLINE_REALNAME)
92 /** Mask for G-line activity flags. */
93 #define GLINE_ACTMASK   (GLINE_ACTIVE | GLINE_LDEACT)
94
95 /** Mask for G-line update flags. */
96 #define GLINE_UPDATE    (GLINE_EXPIRE | GLINE_LIFETIME | GLINE_REASON)
97
98 /** Test whether \a g is active. */
99 #define GlineIsActive(g)        ((((g)->gl_flags & GLINE_ACTIVE) &&       \
100                                   (g)->gl_state != GLOCAL_DEACTIVATED) || \
101                                  (g)->gl_state == GLOCAL_ACTIVATED)
102 /** Test whether \a g is remotely (globally) active. */
103 #define GlineIsRemActive(g)     ((g)->gl_flags & GLINE_ACTIVE)
104 /** Test whether \a g is an IP-based G-line. */
105 #define GlineIsIpMask(g)        ((g)->gl_flags & GLINE_IPMASK)
106 /** Test whether \a g is a realname-based G-line. */
107 #define GlineIsRealName(g)      ((g)->gl_flags & GLINE_REALNAME)
108 /** Test whether \a g is a BADCHAN. */
109 #define GlineIsBadChan(g)       ((g)->gl_flags & GLINE_BADCHAN)
110 /** Test whether \a g is local to this server. */
111 #define GlineIsLocal(g)         ((g)->gl_flags & GLINE_LOCAL)
112
113 /** Return user mask of a G-line. */
114 #define GlineUser(g)            ((g)->gl_user)
115 /** Return host mask of a G-line. */
116 #define GlineHost(g)            ((g)->gl_host)
117 /** Return reason/message of a G-line. */
118 #define GlineReason(g)          ((g)->gl_reason)
119 /** Return last modification time of a G-line. */
120 #define GlineLastMod(g)         ((g)->gl_lastmod)
121
122 extern int gline_add(struct Client *cptr, struct Client *sptr, char *userhost,
123                      char *reason, time_t expire, time_t lastmod,
124                      time_t lifetime, unsigned int flags);
125 extern int gline_activate(struct Client *cptr, struct Client *sptr,
126                           struct Gline *gline, time_t lastmod,
127                           unsigned int flags);
128 extern int gline_deactivate(struct Client *cptr, struct Client *sptr,
129                             struct Gline *gline, time_t lastmod,
130                             unsigned int flags);
131 extern int gline_modify(struct Client *cptr, struct Client *sptr,
132                         struct Gline *gline, enum GlineAction action,
133                         char *reason, time_t expire, time_t lastmod,
134                         time_t lifetime, unsigned int flags);
135 extern int gline_destroy(struct Client *cptr, struct Client *sptr,
136                          struct Gline *gline);
137 extern struct Gline *gline_find(char *userhost, unsigned int flags);
138 extern struct Gline *gline_lookup(struct Client *cptr, unsigned int flags);
139 extern void gline_free(struct Gline *gline);
140 extern void gline_burst(struct Client *cptr);
141 extern int gline_resend(struct Client *cptr, struct Gline *gline);
142 extern int gline_list(struct Client *sptr, char *userhost);
143 extern void gline_stats(struct Client *sptr, const struct StatDesc *sd,
144                         char *param);
145 extern int gline_memory_count(size_t *gl_size);
146
147 #endif /* INCLUDED_gline_h */