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
29 #include "s_newconf.h"
32 #include "irc_string.h"
38 * inputs - pointer to config item, host/pass/user/operreason fields
40 * side effects - update respective fields with pointers
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
);
59 * Inputs - pointer to line to parse
61 * Side Effects - Parse one new style K line
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
;
75 while (fgets(line
, sizeof(line
), file
))
77 if((p
= strchr(line
, '\n')) != NULL
)
80 if((*line
== '\0') || (*line
== '#'))
83 user_field
= getfield(line
);
84 if(EmptyString(user_field
))
87 host_field
= getfield(NULL
);
88 if(EmptyString(host_field
))
91 reason_field
= getfield(NULL
);
92 if(EmptyString(reason_field
))
95 operreason_field
= getfield(NULL
);
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
);
109 * Inputs - pointer to line to parse
111 * Side Effects - Parse one new style D line
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
;
124 while (fgets(line
, sizeof(line
), file
))
126 if((p
= strchr(line
, '\n')))
129 if((*line
== '\0') || (line
[0] == '#'))
132 host_field
= getfield(line
);
133 if(EmptyString(host_field
))
136 reason_field
= getfield(NULL
);
137 if(EmptyString(reason_field
))
140 operreason_field
= getfield(NULL
);
143 aconf
->status
= CONF_DLINE
;
144 conf_add_fields(aconf
, host_field
, reason_field
, "", operreason_field
);
145 conf_add_d_conf(aconf
);
150 parse_x_file(FILE * file
)
152 struct ConfItem
*aconf
;
153 char *gecos_field
= NULL
;
154 char *reason_field
= NULL
;
158 while (fgets(line
, sizeof(line
), file
))
160 if((p
= strchr(line
, '\n')))
163 if((*line
== '\0') || (line
[0] == '#'))
166 gecos_field
= getfield(line
);
167 if(EmptyString(gecos_field
))
170 /* field for xline types, which no longer exist */
173 reason_field
= getfield(NULL
);
174 if(EmptyString(reason_field
))
177 /* sanity checking */
178 if((find_xline(gecos_field
, 0) != NULL
) ||
179 (strchr(reason_field
, ':') != NULL
))
183 aconf
->status
= CONF_XLINE
;
185 DupString(aconf
->name
, gecos_field
);
186 DupString(aconf
->passwd
, reason_field
);
188 dlinkAddAlloc(aconf
, &xline_conf_list
);
193 parse_resv_file(FILE * file
)
195 struct ConfItem
*aconf
;
201 while (fgets(line
, sizeof(line
), file
))
203 if((p
= strchr(line
, '\n')))
206 if((*line
== '\0') || (line
[0] == '#'))
209 host_field
= getfield(line
);
210 if(EmptyString(host_field
))
213 reason_field
= getfield(NULL
);
214 if(EmptyString(reason_field
))
217 if(IsChannelName(host_field
))
219 if(hash_find_resv(host_field
))
223 aconf
->status
= CONF_RESV_CHANNEL
;
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
))
236 aconf
->status
= CONF_RESV_NICK
;
239 DupString(aconf
->name
, host_field
);
240 DupString(aconf
->passwd
, reason_field
);
241 dlinkAddAlloc(aconf
, &resv_conf_list
);
249 * inputs - input buffer
250 * output - next field
251 * side effects - field breakup for ircd.conf file.
254 getfield(char *newline
)
256 static char *line
= NULL
;
267 /* XXX make this skip to first " if present */
271 return (NULL
); /* mal-formed field */
273 end
= strchr(line
, ',');
277 /* no trailing , - last field */
280 end
= line
+ strlen(line
);
293 /* look for a ", to mark the end of a field.. */
294 if(*(end
- 1) == '"')
302 /* search for the next ',' */
304 end
= strchr(end
, ',');