ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/resv.c
Revision: 2916
Committed: Sat Jan 25 21:09:18 2014 UTC (11 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 4698 byte(s)
Log Message:
- Clean up all files in include/ (fixed indentation, removed whitespaces/tabs)
- Fixed copyright years

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2014 ircd-hybrid development team
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
19 * USA
20 */
21
22 /*! \file resv.c
23 * \brief Functions to reserve(jupe) a nick/channel.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "ircd.h"
30 #include "send.h"
31 #include "client.h"
32 #include "memory.h"
33 #include "numeric.h"
34 #include "resv.h"
35 #include "hash.h"
36 #include "irc_string.h"
37 #include "ircd_defs.h"
38 #include "s_misc.h"
39 #include "conf.h"
40 #include "conf_db.h"
41 #include "channel.h"
42 #include "hostmask.h"
43
44
45 /* create_resv()
46 *
47 * inputs - name of nick to create resv for
48 * - reason for resv
49 * - 1 if from ircd.conf, 0 if from elsewhere
50 * output - pointer to struct ResvNick
51 * side effects -
52 */
53 struct MaskItem *
54 create_resv(const char *name, const char *reason, const dlink_list *list)
55 {
56 dlink_node *ptr = NULL;
57 struct MaskItem *conf = NULL;
58 enum maskitem_type type;
59
60 if (name == NULL || reason == NULL)
61 return NULL;
62
63 if (IsChanPrefix(*name))
64 type = CONF_CRESV;
65 else
66 type = CONF_NRESV;
67
68 if (find_exact_name_conf(type, NULL, name, NULL, NULL))
69 return NULL;
70
71 conf = conf_make(type);
72 conf->name = xstrdup(name);
73 conf->reason = xstrndup(reason, IRCD_MIN(strlen(reason), REASONLEN));
74
75 if (list)
76 {
77 DLINK_FOREACH(ptr, list->head)
78 {
79 char nick[NICKLEN + 1];
80 char user[USERLEN + 1];
81 char host[HOSTLEN + 1];
82 struct split_nuh_item nuh;
83 struct exempt *exptr = NULL;
84 char *s = ptr->data;
85
86 if (strlen(s) == 2 && IsAlpha(*(s + 1) && IsAlpha(*(s + 2))))
87 {
88 #ifdef HAVE_LIBGEOIP
89 exptr = MyMalloc(sizeof(*exptr));
90 exptr->name = xstrdup(s);
91 exptr->coid = GeoIP_id_by_code(s);
92 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
93 #endif
94 }
95 else
96 {
97 nuh.nuhmask = s;
98 nuh.nickptr = nick;
99 nuh.userptr = user;
100 nuh.hostptr = host;
101
102 nuh.nicksize = sizeof(nick);
103 nuh.usersize = sizeof(user);
104 nuh.hostsize = sizeof(host);
105
106 split_nuh(&nuh);
107
108 exptr = MyMalloc(sizeof(*exptr));
109 exptr->name = xstrdup(nick);
110 exptr->user = xstrdup(user);
111 exptr->host = xstrdup(host);
112 exptr->type = parse_netmask(host, &exptr->addr, &exptr->bits);
113 dlinkAdd(exptr, &exptr->node, &conf->exempt_list);
114 }
115 }
116 }
117
118 return conf;
119 }
120
121 int
122 resv_find_exempt(const struct Client *who, const struct MaskItem *conf)
123 {
124 const dlink_node *ptr = NULL;
125
126 DLINK_FOREACH(ptr, conf->exempt_list.head)
127 {
128 const struct exempt *exptr = ptr->data;
129
130 if (exptr->coid)
131 {
132 if (exptr->coid == who->localClient->country_id)
133 return 1;
134 }
135 else if (!match(exptr->name, who->name) && !match(exptr->user, who->username))
136 {
137 switch (exptr->type)
138 {
139 case HM_HOST:
140 if (!match(exptr->host, who->host) || !match(exptr->host, who->sockhost))
141 return 1;
142 break;
143 case HM_IPV4:
144 if (who->localClient->aftype == AF_INET)
145 if (match_ipv4(&who->localClient->ip, &exptr->addr, exptr->bits))
146 return 1;
147 break;
148 #ifdef IPV6
149 case HM_IPV6:
150 if (who->localClient->aftype == AF_INET6)
151 if (match_ipv6(&who->localClient->ip, &exptr->addr, exptr->bits))
152 return 1;
153 break;
154 #endif
155 default:
156 assert(0);
157 }
158 }
159 }
160
161 return 0;
162 }
163
164 /* match_find_resv()
165 *
166 * inputs - pointer to name
167 * output - pointer to a struct ResvChannel
168 * side effects - Finds a reserved channel whose name matches 'name',
169 * if can't find one returns NULL.
170 */
171 struct MaskItem *
172 match_find_resv(const char *name)
173 {
174 dlink_node *ptr = NULL;
175
176 if (EmptyString(name))
177 return NULL;
178
179 DLINK_FOREACH(ptr, cresv_items.head)
180 {
181 struct MaskItem *conf = ptr->data;
182
183 if (!match(conf->name, name))
184 return conf;
185 }
186
187 return NULL;
188 }

Properties

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