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