ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/conf_resv.c
Revision: 8656
Committed: Sun Nov 11 20:19:17 2018 UTC (6 years, 9 months ago) by michael
Content type: text/x-csrc
File size: 5579 byte(s)
Log Message:
- Make use of the bool data type in some places

File Contents

# User Rev Content
1 adx 30 /*
2 michael 2916 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 adx 30 *
4 michael 8279 * Copyright (c) 2001-2018 ircd-hybrid development team
5 adx 30 *
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 michael 4565 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 adx 30 * USA
20     */
21    
22 michael 7234 /*! \file conf_resv.c
23 michael 2916 * \brief Functions to reserve(jupe) a nick/channel.
24     * \version $Id$
25     */
26    
27 adx 30 #include "stdinc.h"
28 michael 1011 #include "list.h"
29 adx 30 #include "send.h"
30 michael 2916 #include "client.h"
31 adx 30 #include "memory.h"
32 michael 7282 #include "ircd.h"
33 adx 30 #include "irc_string.h"
34     #include "ircd_defs.h"
35 michael 3347 #include "misc.h"
36 michael 1309 #include "conf.h"
37 michael 7234 #include "conf_resv.h"
38 michael 1858 #include "hostmask.h"
39 adx 30
40    
41 michael 7282 static dlink_list resv_chan_list;
42     static dlink_list resv_nick_list;
43    
44    
45     const dlink_list *
46     resv_chan_get_list(void)
47     {
48     return &resv_chan_list;
49     }
50    
51     const dlink_list *
52     resv_nick_get_list(void)
53     {
54     return &resv_nick_list;
55     }
56    
57     void
58     resv_delete(struct ResvItem *resv)
59     {
60     while (resv->exempt_list.head)
61     {
62     struct ResvExemptItem *exempt = resv->exempt_list.head->data;
63    
64     dlinkDelete(&exempt->node, &resv->exempt_list);
65     xfree(exempt->name);
66     xfree(exempt->user);
67     xfree(exempt->host);
68     xfree(exempt);
69     }
70    
71     dlinkDelete(&resv->node, resv->list);
72     xfree(resv->mask);
73 michael 7288 xfree(resv->reason);
74 michael 7282 xfree(resv);
75     }
76    
77 michael 1858 /* create_resv()
78 adx 30 *
79 michael 1858 * inputs - name of nick to create resv for
80 adx 30 * - reason for resv
81 michael 1858 * - 1 if from ircd.conf, 0 if from elsewhere
82     * output - pointer to struct ResvNick
83 adx 30 * side effects -
84     */
85 michael 7282 struct ResvItem *
86     resv_make(const char *mask, const char *reason, const dlink_list *elist)
87 adx 30 {
88 michael 7282 dlink_list *list;
89 adx 30
90 michael 7290 if (resv_find(mask, irccmp))
91     return NULL;
92    
93 michael 7282 if (IsChanPrefix(*mask))
94     list = &resv_chan_list;
95 michael 1858 else
96 michael 7282 list = &resv_nick_list;
97 michael 1858
98 michael 7282 struct ResvItem *resv = xcalloc(sizeof(*resv));
99     resv->list = list;
100     resv->mask = xstrdup(mask);
101     resv->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
102 michael 7286 dlinkAdd(resv, &resv->node, resv->list);
103 adx 30
104 michael 7282 if (elist)
105 michael 1858 {
106 michael 7282 dlink_node *node;
107    
108     DLINK_FOREACH(node, elist->head)
109 michael 1858 {
110 michael 1860 char nick[NICKLEN + 1];
111     char user[USERLEN + 1];
112     char host[HOSTLEN + 1];
113     struct split_nuh_item nuh;
114 michael 4815 char *s = node->data;
115 michael 1858
116 michael 8314 nuh.nuhmask = s;
117     nuh.nickptr = nick;
118     nuh.userptr = user;
119     nuh.hostptr = host;
120 michael 1858
121 michael 8314 nuh.nicksize = sizeof(nick);
122     nuh.usersize = sizeof(user);
123     nuh.hostsize = sizeof(host);
124 michael 1858
125 michael 8314 split_nuh(&nuh);
126 michael 1858
127 michael 8314 struct ResvExemptItem *exempt = xcalloc(sizeof(*exempt));
128     exempt->name = xstrdup(nick);
129     exempt->user = xstrdup(user);
130     exempt->host = xstrdup(host);
131     exempt->type = parse_netmask(host, &exempt->addr, &exempt->bits);
132     dlinkAdd(exempt, &exempt->node, &resv->exempt_list);
133 michael 1858 }
134     }
135    
136 michael 7282 return resv;
137 adx 30 }
138    
139 michael 7282 struct ResvItem *
140     resv_find(const char *name, int (*compare)(const char *, const char *))
141     {
142 michael 7939 dlink_node *node;
143     dlink_list *list;
144 michael 7282
145     if (IsChanPrefix(*name))
146     list = &resv_chan_list;
147     else
148     list = &resv_nick_list;
149    
150     DLINK_FOREACH(node, list->head)
151     {
152     struct ResvItem *resv = node->data;
153    
154     if (!compare(resv->mask, name))
155     return resv;
156     }
157    
158     return NULL;
159     }
160    
161 michael 1858 int
162 michael 7282 resv_exempt_find(const struct Client *client_p, const struct ResvItem *resv)
163 adx 30 {
164 michael 7687 dlink_node *node;
165 adx 30
166 michael 7282 DLINK_FOREACH(node, resv->exempt_list.head)
167 michael 1858 {
168 michael 7282 const struct ResvExemptItem *exempt = node->data;
169 adx 30
170 michael 8314 if (!match(exempt->name, client_p->name) && !match(exempt->user, client_p->username))
171 michael 1858 {
172 michael 7282 switch (exempt->type)
173 michael 1858 {
174     case HM_HOST:
175 michael 7282 if (!match(exempt->host, client_p->host) || !match(exempt->host, client_p->sockhost))
176 michael 1858 return 1;
177     break;
178     case HM_IPV4:
179 michael 8500 if (client_p->ip.ss.ss_family == AF_INET)
180 michael 8496 if (match_ipv4(&client_p->ip, &exempt->addr, exempt->bits))
181 michael 1858 return 1;
182     break;
183     case HM_IPV6:
184 michael 8500 if (client_p->ip.ss.ss_family == AF_INET6)
185 michael 8496 if (match_ipv6(&client_p->ip, &exempt->addr, exempt->bits))
186 michael 1858 return 1;
187     break;
188     default:
189     assert(0);
190     }
191     }
192     }
193 adx 30
194 michael 1858 return 0;
195 adx 30 }
196    
197 michael 7282 void
198     resv_clear(void)
199 adx 30 {
200 michael 7282 dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
201 adx 30
202 michael 7282 for (dlink_list **list = tab; *list; ++list)
203     {
204 michael 8059 dlink_node *node, *node_next;
205 adx 30
206 michael 7282 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
207     {
208     struct ResvItem *resv = node->data;
209    
210 michael 8656 if (resv->in_database == false)
211 michael 7282 resv_delete(resv);
212     }
213     }
214     }
215    
216     void
217     resv_expire(void)
218     {
219     dlink_list *tab[] = { &resv_chan_list, &resv_nick_list, NULL };
220    
221     for (dlink_list **list = tab; *list; ++list)
222 adx 30 {
223 michael 8059 dlink_node *node, *node_next;
224 adx 30
225 michael 7282 DLINK_FOREACH_SAFE(node, node_next, (*list)->head)
226     {
227     struct ResvItem *resv = node->data;
228    
229 michael 8473 if (resv->expire == 0 || resv->expire > CurrentTime)
230 michael 7282 continue;
231    
232     if (ConfigGeneral.tkline_expire_notices)
233     sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE, "Temporary RESV for [%s] expired",
234     resv->mask);
235     resv_delete(resv);
236     }
237 adx 30 }
238     }

Properties

Name Value
svn:eol-style native
svn:keywords Id