ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/src/resv.c
Revision: 34
Committed: Sun Oct 2 21:05:51 2005 UTC (18 years, 5 months ago) by lusky
Content type: text/x-csrc
File size: 5376 byte(s)
Log Message:
create 7.2 branch, we can move/rename it as needed.


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;
55 struct ResvChannel *resv_p;
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(resv_p->reason, reason);
71 resv_p->conf = in_conf;
72
73 dlinkAdd(resv_p, &resv_p->node, &resv_channel_list);
74 hash_add_resv(resv_p);
75
76 return conf;
77 }
78
79 /* create_nick_resv()
80 *
81 * inputs - name of nick to create resv for
82 * - reason for resv
83 * - 1 if from ircd.conf, 0 if from elsewhere
84 * output - pointer to struct ResvNick
85 * side effects -
86 */
87 struct ConfItem *
88 create_nick_resv(char *name, char *reason, int in_conf)
89 {
90 struct ConfItem *conf;
91 struct MatchItem *resv_p;
92
93 if (name == NULL || reason == NULL)
94 return NULL;
95
96 if (find_matching_name_conf(NRESV_TYPE, name, NULL, NULL, 0))
97 return NULL;
98
99 if (strlen(reason) > REASONLEN)
100 reason[REASONLEN] = '\0';
101
102 conf = make_conf_item(NRESV_TYPE);
103 resv_p = map_to_conf(conf);
104
105 DupString(conf->name, name);
106 DupString(resv_p->reason, reason);
107 resv_p->action = in_conf;
108
109 return conf;
110 }
111
112 /* clear_conf_resv()
113 *
114 * inputs - none
115 * output - none
116 * side effects - All resvs are cleared out
117 */
118 void
119 clear_conf_resv(void)
120 {
121 dlink_node *ptr;
122 dlink_node *next_ptr;
123 struct ResvChannel *resv_cp;
124
125 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
126 {
127 resv_cp = ptr->data;
128 delete_channel_resv(resv_cp);
129 }
130 }
131
132 /* delete_channel_resv()
133 *
134 * inputs - pointer to channel resv to delete
135 * output - none
136 * side effects - given struct ResvChannel * is removed
137 */
138 int
139 delete_channel_resv(struct ResvChannel *resv_p)
140 {
141 struct ConfItem *conf;
142 assert(resv_p != NULL);
143
144 hash_del_resv(resv_p);
145 dlinkDelete(&resv_p->node, &resv_channel_list);
146 MyFree(resv_p->reason);
147 conf = unmap_conf_item(resv_p);
148 delete_conf_item(conf);
149
150 return 1;
151 }
152
153 /* match_find_resv()
154 *
155 * inputs - pointer to name
156 * output - pointer to a struct ResvChannel
157 * side effects - Finds a reserved channel whose name matches 'name',
158 * if can't find one returns NULL.
159 */
160 struct ResvChannel *
161 match_find_resv(const char *name)
162 {
163 dlink_node *ptr = NULL;
164
165 if (EmptyString(name))
166 return NULL;
167
168 DLINK_FOREACH(ptr, resv_channel_list.head)
169 {
170 struct ResvChannel *chptr = ptr->data;
171
172 if (match_chan(name, chptr->name))
173 return chptr;
174 }
175
176 return NULL;
177 }
178
179 /* report_resv()
180 *
181 * inputs - pointer to client pointer to report to.
182 * output - NONE
183 * side effects - report all resvs to client.
184 */
185 void
186 report_resv(struct Client *source_p)
187 {
188 dlink_node *ptr;
189 struct ConfItem *conf;
190 struct ResvChannel *resv_cp;
191 struct MatchItem *resv_np;
192
193 DLINK_FOREACH(ptr, resv_channel_list.head)
194 {
195 resv_cp = ptr->data;
196 sendto_one(source_p, form_str(RPL_STATSQLINE),
197 me.name, source_p->name,
198 resv_cp->conf ? 'Q' : 'q',
199 resv_cp->name, resv_cp->reason);
200 }
201
202 DLINK_FOREACH(ptr, nresv_items.head)
203 {
204 conf = ptr->data;
205 resv_np = map_to_conf(conf);
206
207 sendto_one(source_p, form_str(RPL_STATSQLINE),
208 me.name, source_p->name,
209 resv_np->action ? 'Q' : 'q',
210 conf->name, resv_np->reason);
211 }
212 }
213
214 /* valid_wild_card_simple()
215 *
216 * inputs - data to check for sufficient non-wildcard characters
217 * outputs - 1 if valid, else 0
218 * side effects - none
219 */
220 int
221 valid_wild_card_simple(const char *data)
222 {
223 const unsigned char *p = (const unsigned char *)data;
224 int nonwild = 0;
225
226 while (*p != '\0')
227 {
228 if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
229 if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
230 return 1;
231 if (*p != '\0')
232 ++p;
233 }
234
235 return 0;
236 }

Properties

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