ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/resv.c
Revision: 141
Committed: Sun Oct 16 06:29:10 2005 UTC (19 years, 10 months ago) by db
Content type: text/x-csrc
File size: 5260 byte(s)
Log Message:
- Make ->conf conf_ptr to be consistent in all places.


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 "common.h"
27 #include "ircd.h"
28 #include "send.h"
29 #include "client.h"
30 #include "numeric.h"
31 #include "resv.h"
32 #include "hash.h"
33 #include "ircd_defs.h"
34 #include "s_conf.h"
35
36 dlink_list resv_channel_list = { NULL, NULL, 0 };
37
38
39 /* create_channel_resv()
40 *
41 * inputs - name of channel to create resv for
42 * - reason for resv
43 * - flag, 1 for from ircd.conf 0 from elsehwere
44 * output - pointer to struct ResvChannel
45 * side effects -
46 */
47 struct ConfItem *
48 create_channel_resv(char *name, char *reason, int in_conf)
49 {
50 struct ConfItem *conf;
51 struct ResvChannel *resv_p;
52
53 if (name == NULL || reason == NULL)
54 return NULL;
55
56 if (hash_find_resv(name))
57 return NULL;
58
59 if (strlen(reason) > REASONLEN)
60 reason[REASONLEN] = '\0';
61
62 conf = make_conf_item(CRESV_TYPE);
63 resv_p = &conf->conf.ResvChannel;
64
65 strlcpy(resv_p->name, name, sizeof(resv_p->name));
66 DupString(resv_p->reason, reason);
67 resv_p->conf = in_conf;
68
69 dlinkAdd(resv_p, &resv_p->node, &resv_channel_list);
70 hash_add_resv(resv_p);
71
72 return conf;
73 }
74
75 /* create_nick_resv()
76 *
77 * inputs - name of nick to create resv for
78 * - reason for resv
79 * - 1 if from ircd.conf, 0 if from elsewhere
80 * output - pointer to struct ResvNick
81 * side effects -
82 */
83 struct ConfItem *
84 create_nick_resv(char *name, char *reason, int in_conf)
85 {
86 struct ConfItem *conf;
87 struct MatchItem *resv_p;
88
89 if (name == NULL || reason == NULL)
90 return NULL;
91
92 if (find_matching_name_conf(NRESV_TYPE, name, NULL, NULL, 0))
93 return NULL;
94
95 if (strlen(reason) > REASONLEN)
96 reason[REASONLEN] = '\0';
97
98 conf = make_conf_item(NRESV_TYPE);
99 resv_p = &conf->conf.MatchItem;
100
101 DupString(conf->name, name);
102 DupString(resv_p->reason, reason);
103 resv_p->action = in_conf;
104
105 return conf;
106 }
107
108 /* clear_conf_resv()
109 *
110 * inputs - none
111 * output - none
112 * side effects - All resvs are cleared out
113 */
114 void
115 clear_conf_resv(void)
116 {
117 dlink_node *ptr;
118 dlink_node *next_ptr;
119 struct ResvChannel *resv_cp;
120
121 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
122 {
123 resv_cp = ptr->data;
124 delete_channel_resv(resv_cp);
125 }
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 assert(resv_p != NULL);
138
139 hash_del_resv(resv_p);
140 dlinkDelete(&resv_p->node, &resv_channel_list);
141 MyFree(resv_p->reason);
142 delete_conf_item(resv_p->conf_ptr);
143
144 return 1;
145 }
146
147 /* match_find_resv()
148 *
149 * inputs - pointer to name
150 * output - pointer to a struct ResvChannel
151 * side effects - Finds a reserved channel whose name matches 'name',
152 * if can't find one returns NULL.
153 */
154 struct ResvChannel *
155 match_find_resv(const char *name)
156 {
157 dlink_node *ptr = NULL;
158
159 if (EmptyString(name))
160 return NULL;
161
162 DLINK_FOREACH(ptr, resv_channel_list.head)
163 {
164 struct ResvChannel *chptr = ptr->data;
165
166 if (match_chan(name, chptr->name))
167 return chptr;
168 }
169
170 return NULL;
171 }
172
173 /* report_resv()
174 *
175 * inputs - pointer to client pointer to report to.
176 * output - NONE
177 * side effects - report all resvs to client.
178 */
179 void
180 report_resv(struct Client *source_p)
181 {
182 dlink_node *ptr;
183 struct ConfItem *conf;
184 struct ResvChannel *resv_cp;
185 struct MatchItem *resv_np;
186
187 DLINK_FOREACH(ptr, resv_channel_list.head)
188 {
189 resv_cp = ptr->data;
190 sendto_one(source_p, form_str(RPL_STATSQLINE),
191 me.name, source_p->name,
192 resv_cp->conf ? 'Q' : 'q',
193 resv_cp->name, resv_cp->reason);
194 }
195
196 DLINK_FOREACH(ptr, nresv_items.head)
197 {
198 conf = ptr->data;
199 resv_np = &conf->conf.MatchItem;
200
201 sendto_one(source_p, form_str(RPL_STATSQLINE),
202 me.name, source_p->name,
203 resv_np->action ? 'Q' : 'q',
204 conf->name, resv_np->reason);
205 }
206 }
207
208 /* valid_wild_card_simple()
209 *
210 * inputs - data to check for sufficient non-wildcard characters
211 * outputs - 1 if valid, else 0
212 * side effects - none
213 */
214 int
215 valid_wild_card_simple(const char *data)
216 {
217 const unsigned char *p = (const unsigned char *)data;
218 int nonwild = 0;
219
220 while (*p != '\0')
221 {
222 if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
223 if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
224 return 1;
225 if (*p != '\0')
226 ++p;
227 }
228
229 return 0;
230 }

Properties

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