Restore stats_spy hook that was removed in commit 401f2454671ca233e35b0e6e4f3fa4c43cd...
[seven-1.x.git] / src / kdparse.c
blobff1de72f2bd372c8e608015f8a3617530393fe71
1 /*
2 * ircd-ratbox: A slightly useful ircd.
3 * kdparse.c: Parses K and D lines.
5 * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center
6 * Copyright (C) 1996-2002 Hybrid Development Team
7 * Copyright (C) 2002-2005 ircd-ratbox development team
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
25 #include "stdinc.h"
26 #include "tools.h"
27 #include "s_log.h"
28 #include "s_conf.h"
29 #include "s_newconf.h"
30 #include "hostmask.h"
31 #include "client.h"
32 #include "irc_string.h"
33 #include "memory.h"
34 #include "hash.h"
36 /* conf_add_fields()
38 * inputs - pointer to config item, host/pass/user/operreason fields
39 * output - NONE
40 * side effects - update respective fields with pointers
42 static void
43 conf_add_fields(struct ConfItem *aconf, const char *host_field,
44 const char *pass_field, const char *user_field,
45 const char *operreason_field)
47 if(host_field != NULL)
48 DupString(aconf->host, host_field);
49 if(pass_field != NULL)
50 DupString(aconf->passwd, pass_field);
51 if(user_field != NULL)
52 DupString(aconf->user, user_field);
53 if(operreason_field != NULL)
54 DupString(aconf->spasswd, operreason_field);
58 * parse_k_file
59 * Inputs - pointer to line to parse
60 * Output - NONE
61 * Side Effects - Parse one new style K line
64 void
65 parse_k_file(FILE * file)
67 struct ConfItem *aconf;
68 char *user_field = NULL;
69 char *reason_field = NULL;
70 char *operreason_field = NULL;
71 char *host_field = NULL;
72 char line[BUFSIZE];
73 char *p;
75 while (fgets(line, sizeof(line), file))
77 if((p = strchr(line, '\n')) != NULL)
78 *p = '\0';
80 if((*line == '\0') || (*line == '#'))
81 continue;
83 user_field = getfield(line);
84 if(EmptyString(user_field))
85 continue;
87 host_field = getfield(NULL);
88 if(EmptyString(host_field))
89 continue;
91 reason_field = getfield(NULL);
92 if(EmptyString(reason_field))
93 continue;
95 operreason_field = getfield(NULL);
97 aconf = make_conf();
98 aconf->status = CONF_KILL;
99 conf_add_fields(aconf, host_field, reason_field,
100 user_field, operreason_field);
102 if(aconf->host != NULL)
103 add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf);
108 * parse_d_file
109 * Inputs - pointer to line to parse
110 * Output - NONE
111 * Side Effects - Parse one new style D line
114 void
115 parse_d_file(FILE * file)
117 struct ConfItem *aconf;
118 char *reason_field = NULL;
119 char *host_field = NULL;
120 char *operreason_field = NULL;
121 char line[BUFSIZE];
122 char *p;
124 while (fgets(line, sizeof(line), file))
126 if((p = strchr(line, '\n')))
127 *p = '\0';
129 if((*line == '\0') || (line[0] == '#'))
130 continue;
132 host_field = getfield(line);
133 if(EmptyString(host_field))
134 continue;
136 reason_field = getfield(NULL);
137 if(EmptyString(reason_field))
138 continue;
140 operreason_field = getfield(NULL);
142 aconf = make_conf();
143 aconf->status = CONF_DLINE;
144 conf_add_fields(aconf, host_field, reason_field, "", operreason_field);
145 conf_add_d_conf(aconf);
149 void
150 parse_x_file(FILE * file)
152 struct ConfItem *aconf;
153 char *gecos_field = NULL;
154 char *reason_field = NULL;
155 char line[BUFSIZE];
156 char *p;
158 while (fgets(line, sizeof(line), file))
160 if((p = strchr(line, '\n')))
161 *p = '\0';
163 if((*line == '\0') || (line[0] == '#'))
164 continue;
166 gecos_field = getfield(line);
167 if(EmptyString(gecos_field))
168 continue;
170 /* field for xline types, which no longer exist */
171 getfield(NULL);
173 reason_field = getfield(NULL);
174 if(EmptyString(reason_field))
175 continue;
177 /* sanity checking */
178 if((find_xline(gecos_field, 0) != NULL) ||
179 (strchr(reason_field, ':') != NULL))
180 continue;
182 aconf = make_conf();
183 aconf->status = CONF_XLINE;
185 DupString(aconf->name, gecos_field);
186 DupString(aconf->passwd, reason_field);
188 dlinkAddAlloc(aconf, &xline_conf_list);
192 void
193 parse_resv_file(FILE * file)
195 struct ConfItem *aconf;
196 char *reason_field;
197 char *host_field;
198 char line[BUFSIZE];
199 char *p;
201 while (fgets(line, sizeof(line), file))
203 if((p = strchr(line, '\n')))
204 *p = '\0';
206 if((*line == '\0') || (line[0] == '#'))
207 continue;
209 host_field = getfield(line);
210 if(EmptyString(host_field))
211 continue;
213 reason_field = getfield(NULL);
214 if(EmptyString(reason_field))
215 continue;
217 if(IsChannelName(host_field))
219 if(hash_find_resv(host_field))
220 continue;
222 aconf = make_conf();
223 aconf->status = CONF_RESV_CHANNEL;
224 aconf->port = 0;
226 DupString(aconf->name, host_field);
227 DupString(aconf->passwd, reason_field);
228 add_to_resv_hash(aconf->name, aconf);
230 else if(clean_resv_nick(host_field))
232 if(find_nick_resv(host_field))
233 continue;
235 aconf = make_conf();
236 aconf->status = CONF_RESV_NICK;
237 aconf->port = 0;
239 DupString(aconf->name, host_field);
240 DupString(aconf->passwd, reason_field);
241 dlinkAddAlloc(aconf, &resv_conf_list);
247 * getfield
249 * inputs - input buffer
250 * output - next field
251 * side effects - field breakup for ircd.conf file.
253 char *
254 getfield(char *newline)
256 static char *line = NULL;
257 char *end, *field;
259 if(newline != NULL)
260 line = newline;
262 if(line == NULL)
263 return (NULL);
265 field = line;
267 /* XXX make this skip to first " if present */
268 if(*field == '"')
269 field++;
270 else
271 return (NULL); /* mal-formed field */
273 end = strchr(line, ',');
275 while(1)
277 /* no trailing , - last field */
278 if(end == NULL)
280 end = line + strlen(line);
281 line = NULL;
283 if(*end == '"')
285 *end = '\0';
286 return field;
288 else
289 return NULL;
291 else
293 /* look for a ", to mark the end of a field.. */
294 if(*(end - 1) == '"')
296 line = end + 1;
297 end--;
298 *end = '\0';
299 return field;
302 /* search for the next ',' */
303 end++;
304 end = strchr(end, ',');
308 return NULL;