ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/resv.c
Revision: 867
Committed: Thu May 17 14:59:27 2007 UTC (16 years, 11 months ago) by michael
Content type: text/x-csrc
File size: 5381 byte(s)
Log Message:
- Fixed occasional core when placing RESVs on channel names as repoared
  by Christopher A. Bongaarts.


File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * resv.c: Functions to reserve(jupe) a nick/channel.
4 *
5 * Copyright (C) 2001-2002 Hybrid Development Team
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "tools.h"
27 #include "common.h"
28 #include "fdlist.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_conf.h"
39
40 dlink_list resv_channel_list = { NULL, NULL, 0 };
41
42
43 /* create_channel_resv()
44 *
45 * inputs - name of channel to create resv for
46 * - reason for resv
47 * - flag, 1 for from ircd.conf 0 from elsehwere
48 * output - pointer to struct ResvChannel
49 * side effects -
50 */
51 struct ConfItem *
52 create_channel_resv(char *name, char *reason, int in_conf)
53 {
54 struct ConfItem *conf = NULL;
55 struct ResvChannel *resv_p = NULL;
56
57 if (name == NULL || reason == NULL)
58 return NULL;
59
60 if (hash_find_resv(name))
61 return NULL;
62
63 if (strlen(reason) > REASONLEN)
64 reason[REASONLEN] = '\0';
65
66 conf = make_conf_item(CRESV_TYPE);
67 resv_p = map_to_conf(conf);
68
69 strlcpy(resv_p->name, name, sizeof(resv_p->name));
70 DupString(conf->name, name);
71 DupString(resv_p->reason, reason);
72 resv_p->conf = in_conf;
73
74 dlinkAdd(resv_p, &resv_p->node, &resv_channel_list);
75 hash_add_resv(resv_p);
76
77 return conf;
78 }
79
80 /* create_nick_resv()
81 *
82 * inputs - name of nick to create resv for
83 * - reason for resv
84 * - 1 if from ircd.conf, 0 if from elsewhere
85 * output - pointer to struct ResvNick
86 * side effects -
87 */
88 struct ConfItem *
89 create_nick_resv(char *name, char *reason, int in_conf)
90 {
91 struct ConfItem *conf = NULL;
92 struct MatchItem *resv_p = NULL;
93
94 if (name == NULL || reason == NULL)
95 return NULL;
96
97 if (find_matching_name_conf(NRESV_TYPE, name, NULL, NULL, 0))
98 return NULL;
99
100 if (strlen(reason) > REASONLEN)
101 reason[REASONLEN] = '\0';
102
103 conf = make_conf_item(NRESV_TYPE);
104 resv_p = map_to_conf(conf);
105
106 DupString(conf->name, name);
107 DupString(resv_p->reason, reason);
108 resv_p->action = in_conf;
109
110 return conf;
111 }
112
113 /* clear_conf_resv()
114 *
115 * inputs - none
116 * output - none
117 * side effects - All resvs are cleared out
118 */
119 void
120 clear_conf_resv(void)
121 {
122 dlink_node *ptr = NULL, *next_ptr = NULL;
123
124 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
125 delete_channel_resv(ptr->data);
126 }
127
128 /* delete_channel_resv()
129 *
130 * inputs - pointer to channel resv to delete
131 * output - none
132 * side effects - given struct ResvChannel * is removed
133 */
134 int
135 delete_channel_resv(struct ResvChannel *resv_p)
136 {
137 struct ConfItem *conf = NULL;
138 assert(resv_p != NULL);
139
140 hash_del_resv(resv_p);
141 dlinkDelete(&resv_p->node, &resv_channel_list);
142 MyFree(resv_p->reason);
143 conf = unmap_conf_item(resv_p);
144 delete_conf_item(conf);
145
146 return 1;
147 }
148
149 /* match_find_resv()
150 *
151 * inputs - pointer to name
152 * output - pointer to a struct ResvChannel
153 * side effects - Finds a reserved channel whose name matches 'name',
154 * if can't find one returns NULL.
155 */
156 struct ResvChannel *
157 match_find_resv(const char *name)
158 {
159 dlink_node *ptr = NULL;
160
161 if (EmptyString(name))
162 return NULL;
163
164 DLINK_FOREACH(ptr, resv_channel_list.head)
165 {
166 struct ResvChannel *chptr = ptr->data;
167
168 if (match_chan(name, chptr->name))
169 return chptr;
170 }
171
172 return NULL;
173 }
174
175 /* report_resv()
176 *
177 * inputs - pointer to client pointer to report to.
178 * output - NONE
179 * side effects - report all resvs to client.
180 */
181 void
182 report_resv(struct Client *source_p)
183 {
184 dlink_node *ptr;
185 struct ConfItem *conf;
186 struct ResvChannel *resv_cp;
187 struct MatchItem *resv_np;
188
189 DLINK_FOREACH(ptr, resv_channel_list.head)
190 {
191 resv_cp = ptr->data;
192 sendto_one(source_p, form_str(RPL_STATSQLINE),
193 me.name, source_p->name,
194 resv_cp->conf ? 'Q' : 'q',
195 resv_cp->name, resv_cp->reason);
196 }
197
198 DLINK_FOREACH(ptr, nresv_items.head)
199 {
200 conf = ptr->data;
201 resv_np = map_to_conf(conf);
202
203 sendto_one(source_p, form_str(RPL_STATSQLINE),
204 me.name, source_p->name,
205 resv_np->action ? 'Q' : 'q',
206 conf->name, resv_np->reason);
207 }
208 }
209
210 /* valid_wild_card_simple()
211 *
212 * inputs - data to check for sufficient non-wildcard characters
213 * outputs - 1 if valid, else 0
214 * side effects - none
215 */
216 int
217 valid_wild_card_simple(const char *data)
218 {
219 const unsigned char *p = (const unsigned char *)data;
220 int nonwild = 0;
221
222 while (*p != '\0')
223 {
224 if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
225 if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
226 return 1;
227 if (*p != '\0')
228 ++p;
229 }
230
231 return 0;
232 }

Properties

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