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