/[svn]/ircd-hybrid/branches/8.0.x/src/resv.c
ViewVC logotype

Contents of /ircd-hybrid/branches/8.0.x/src/resv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1685 - (show annotations)
Wed Dec 19 20:24:52 2012 UTC (7 years, 7 months ago) by michael
File MIME type: text/x-chdr
File size: 5370 byte(s)
- STATS q|Q now shows how many times a resv{} block has been matched.
  (Just like STATS x|X)

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 "list.h"
27 #include "ircd.h"
28 #include "send.h"
29 #include "client.h"
30 #include "memory.h"
31 #include "numeric.h"
32 #include "resv.h"
33 #include "hash.h"
34 #include "irc_string.h"
35 #include "ircd_defs.h"
36 #include "conf.h"
37
38 dlink_list resv_channel_list = { NULL, NULL, 0 };
39
40
41 /* create_channel_resv()
42 *
43 * inputs - name of channel to create resv for
44 * - reason for resv
45 * - flag, 1 for from ircd.conf 0 from elsehwere
46 * output - pointer to struct ResvChannel
47 * side effects -
48 */
49 struct ConfItem *
50 create_channel_resv(char *name, char *reason, int in_conf)
51 {
52 struct ConfItem *conf = NULL;
53 struct ResvChannel *resv_p = NULL;
54
55 if (name == NULL || reason == NULL)
56 return NULL;
57
58 if (hash_find_resv(name))
59 return NULL;
60
61 if (strlen(reason) > REASONLEN)
62 reason[REASONLEN] = '\0';
63
64 conf = make_conf_item(CRESV_TYPE);
65 resv_p = map_to_conf(conf);
66
67 strlcpy(resv_p->name, name, sizeof(resv_p->name));
68 DupString(conf->name, name);
69 DupString(resv_p->reason, reason);
70 resv_p->conf = in_conf;
71
72 dlinkAdd(resv_p, &resv_p->node, &resv_channel_list);
73 hash_add_resv(resv_p);
74
75 return conf;
76 }
77
78 /* create_nick_resv()
79 *
80 * inputs - name of nick to create resv for
81 * - reason for resv
82 * - 1 if from ircd.conf, 0 if from elsewhere
83 * output - pointer to struct ResvNick
84 * side effects -
85 */
86 struct ConfItem *
87 create_nick_resv(char *name, char *reason, int in_conf)
88 {
89 struct ConfItem *conf = NULL;
90 struct MatchItem *resv_p = NULL;
91
92 if (name == NULL || reason == NULL)
93 return NULL;
94
95 if (find_matching_name_conf(NRESV_TYPE, name, NULL, NULL, 0))
96 return NULL;
97
98 if (strlen(reason) > REASONLEN)
99 reason[REASONLEN] = '\0';
100
101 conf = make_conf_item(NRESV_TYPE);
102 resv_p = map_to_conf(conf);
103
104 DupString(conf->name, name);
105 DupString(resv_p->reason, reason);
106 resv_p->action = in_conf;
107
108 return conf;
109 }
110
111 /* clear_conf_resv()
112 *
113 * inputs - none
114 * output - none
115 * side effects - All resvs are cleared out
116 */
117 void
118 clear_conf_resv(void)
119 {
120 dlink_node *ptr = NULL, *next_ptr = NULL;
121
122 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
123 delete_channel_resv(ptr->data);
124 }
125
126 /* delete_channel_resv()
127 *
128 * inputs - pointer to channel resv to delete
129 * output - none
130 * side effects - given struct ResvChannel * is removed
131 */
132 int
133 delete_channel_resv(struct ResvChannel *resv_p)
134 {
135 struct ConfItem *conf = NULL;
136 assert(resv_p != NULL);
137
138 hash_del_resv(resv_p);
139 dlinkDelete(&resv_p->node, &resv_channel_list);
140 MyFree(resv_p->reason);
141 conf = unmap_conf_item(resv_p);
142 delete_conf_item(conf);
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', resv_cp->count,
193 resv_cp->name, resv_cp->reason);
194 }
195
196 DLINK_FOREACH(ptr, nresv_items.head)
197 {
198 conf = ptr->data;
199 resv_np = map_to_conf(conf);
200
201 sendto_one(source_p, form_str(RPL_STATSQLINE),
202 me.name, source_p->name,
203 resv_np->action ? 'Q' : 'q', resv_np->count,
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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28