/[svn]/ircd-hybrid/trunk/src/resv.c
ViewVC logotype

Contents of /ircd-hybrid/trunk/src/resv.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1625 - (show annotations)
Thu Nov 1 13:49:25 2012 UTC (7 years, 9 months ago) by michael
File MIME type: text/x-chdr
File size: 5359 byte(s)
- dbs are now periodically flushed on disc every 5 minutes

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 #include "conf_db.h"
38
39 dlink_list resv_channel_list = { NULL, NULL, 0 };
40
41
42 /* create_channel_resv()
43 *
44 * inputs - name of channel to create resv for
45 * - reason for resv
46 * - flag, 1 for from ircd.conf 0 from elsehwere
47 * output - pointer to struct ResvChannel
48 * side effects -
49 */
50 struct ConfItem *
51 create_channel_resv(char *name, char *reason, int in_conf)
52 {
53 struct ConfItem *conf = NULL;
54 struct ResvChannel *resv_p = NULL;
55
56 if (name == NULL || reason == NULL)
57 return NULL;
58
59 if (hash_find_resv(name))
60 return NULL;
61
62 if (strlen(reason) > REASONLEN)
63 reason[REASONLEN] = '\0';
64
65 conf = make_conf_item(CRESV_TYPE);
66 resv_p = map_to_conf(conf);
67
68 strlcpy(resv_p->name, name, sizeof(resv_p->name));
69 DupString(conf->name, 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 = NULL;
91 struct MatchItem *resv_p = NULL;
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 = NULL, *next_ptr = NULL;
122
123 DLINK_FOREACH_SAFE(ptr, next_ptr, resv_channel_list.head)
124 delete_channel_resv(ptr->data);
125 }
126
127 /* delete_channel_resv()
128 *
129 * inputs - pointer to channel resv to delete
130 * output - none
131 * side effects - given struct ResvChannel * is removed
132 */
133 int
134 delete_channel_resv(struct ResvChannel *resv_p)
135 {
136 struct ConfItem *conf = NULL;
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 conf = unmap_conf_item(resv_p);
143 delete_conf_item(conf);
144
145 return 1;
146 }
147
148 /* match_find_resv()
149 *
150 * inputs - pointer to name
151 * output - pointer to a struct ResvChannel
152 * side effects - Finds a reserved channel whose name matches 'name',
153 * if can't find one returns NULL.
154 */
155 struct ResvChannel *
156 match_find_resv(const char *name)
157 {
158 dlink_node *ptr = NULL;
159
160 if (EmptyString(name))
161 return NULL;
162
163 DLINK_FOREACH(ptr, resv_channel_list.head)
164 {
165 struct ResvChannel *chptr = ptr->data;
166
167 if (match_chan(name, chptr->name))
168 return chptr;
169 }
170
171 return NULL;
172 }
173
174 /* report_resv()
175 *
176 * inputs - pointer to client pointer to report to.
177 * output - NONE
178 * side effects - report all resvs to client.
179 */
180 void
181 report_resv(struct Client *source_p)
182 {
183 dlink_node *ptr;
184 struct ConfItem *conf;
185 struct ResvChannel *resv_cp;
186 struct MatchItem *resv_np;
187
188 DLINK_FOREACH(ptr, resv_channel_list.head)
189 {
190 resv_cp = ptr->data;
191 sendto_one(source_p, form_str(RPL_STATSQLINE),
192 me.name, source_p->name,
193 resv_cp->conf ? 'Q' : 'q',
194 resv_cp->name, resv_cp->reason);
195 }
196
197 DLINK_FOREACH(ptr, nresv_items.head)
198 {
199 conf = ptr->data;
200 resv_np = map_to_conf(conf);
201
202 sendto_one(source_p, form_str(RPL_STATSQLINE),
203 me.name, source_p->name,
204 resv_np->action ? 'Q' : 'q',
205 conf->name, resv_np->reason);
206 }
207 }
208
209 /* valid_wild_card_simple()
210 *
211 * inputs - data to check for sufficient non-wildcard characters
212 * outputs - 1 if valid, else 0
213 * side effects - none
214 */
215 int
216 valid_wild_card_simple(const char *data)
217 {
218 const unsigned char *p = (const unsigned char *)data;
219 int nonwild = 0;
220
221 while (*p != '\0')
222 {
223 if ((*p == '\\' && *++p) || (*p && !IsMWildChar(*p)))
224 if (++nonwild == ConfigFileEntry.min_nonwildcard_simple)
225 return 1;
226 if (*p != '\0')
227 ++p;
228 }
229
230 return 0;
231 }

Properties

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

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