]>
jfr.im git - solanum.git/blob - src/kdparse.c
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
24 * $Id: kdparse.c 254 2005-09-21 23:35:12Z nenolod $
31 #include "s_newconf.h"
34 #include "irc_string.h"
40 * inputs - pointer to config item, host/pass/user/operreason fields
42 * side effects - update respective fields with pointers
45 conf_add_fields(struct ConfItem
*aconf
, const char *host_field
,
46 const char *pass_field
, const char *user_field
,
47 const char *operreason_field
)
49 if(host_field
!= NULL
)
50 DupString(aconf
->host
, host_field
);
51 if(pass_field
!= NULL
)
52 DupString(aconf
->passwd
, pass_field
);
53 if(user_field
!= NULL
)
54 DupString(aconf
->user
, user_field
);
55 if(operreason_field
!= NULL
)
56 DupString(aconf
->spasswd
, operreason_field
);
61 * Inputs - pointer to line to parse
63 * Side Effects - Parse one new style K line
67 parse_k_file(FILE * file
)
69 struct ConfItem
*aconf
;
70 char *user_field
= NULL
;
71 char *reason_field
= NULL
;
72 char *operreason_field
= NULL
;
73 char *host_field
= NULL
;
77 while (fgets(line
, sizeof(line
), file
))
79 if((p
= strchr(line
, '\n')) != NULL
)
82 if((*line
== '\0') || (*line
== '#'))
85 user_field
= getfield(line
);
86 if(EmptyString(user_field
))
89 host_field
= getfield(NULL
);
90 if(EmptyString(host_field
))
93 reason_field
= getfield(NULL
);
94 if(EmptyString(reason_field
))
97 operreason_field
= getfield(NULL
);
100 aconf
->status
= CONF_KILL
;
101 conf_add_fields(aconf
, host_field
, reason_field
,
102 user_field
, operreason_field
);
104 if(aconf
->host
!= NULL
)
105 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
111 * Inputs - pointer to line to parse
113 * Side Effects - Parse one new style D line
117 parse_d_file(FILE * file
)
119 struct ConfItem
*aconf
;
120 char *reason_field
= NULL
;
121 char *host_field
= NULL
;
122 char *operreason_field
= NULL
;
126 while (fgets(line
, sizeof(line
), file
))
128 if((p
= strchr(line
, '\n')))
131 if((*line
== '\0') || (line
[0] == '#'))
134 host_field
= getfield(line
);
135 if(EmptyString(host_field
))
138 reason_field
= getfield(NULL
);
139 if(EmptyString(reason_field
))
142 operreason_field
= getfield(NULL
);
145 aconf
->status
= CONF_DLINE
;
146 conf_add_fields(aconf
, host_field
, reason_field
, "", operreason_field
);
147 conf_add_d_conf(aconf
);
152 parse_x_file(FILE * file
)
154 struct ConfItem
*aconf
;
155 char *gecos_field
= NULL
;
156 char *reason_field
= NULL
;
160 while (fgets(line
, sizeof(line
), file
))
162 if((p
= strchr(line
, '\n')))
165 if((*line
== '\0') || (line
[0] == '#'))
168 gecos_field
= getfield(line
);
169 if(EmptyString(gecos_field
))
172 /* field for xline types, which no longer exist */
175 reason_field
= getfield(NULL
);
176 if(EmptyString(reason_field
))
179 /* sanity checking */
180 if((find_xline_mask(gecos_field
) != NULL
) ||
181 (strchr(reason_field
, ':') != NULL
))
185 aconf
->status
= CONF_XLINE
;
187 DupString(aconf
->name
, gecos_field
);
188 DupString(aconf
->passwd
, reason_field
);
190 dlinkAddAlloc(aconf
, &xline_conf_list
);
195 parse_resv_file(FILE * file
)
197 struct ConfItem
*aconf
;
203 while (fgets(line
, sizeof(line
), file
))
205 if((p
= strchr(line
, '\n')))
208 if((*line
== '\0') || (line
[0] == '#'))
211 host_field
= getfield(line
);
212 if(EmptyString(host_field
))
215 reason_field
= getfield(NULL
);
216 if(EmptyString(reason_field
))
219 if(IsChannelName(host_field
))
221 if(hash_find_resv(host_field
))
225 aconf
->status
= CONF_RESV_CHANNEL
;
228 DupString(aconf
->name
, host_field
);
229 DupString(aconf
->passwd
, reason_field
);
230 add_to_resv_hash(aconf
->name
, aconf
);
232 else if(clean_resv_nick(host_field
))
234 if(find_nick_resv_mask(host_field
))
238 aconf
->status
= CONF_RESV_NICK
;
241 DupString(aconf
->name
, host_field
);
242 DupString(aconf
->passwd
, reason_field
);
243 dlinkAddAlloc(aconf
, &resv_conf_list
);
251 * inputs - input buffer
252 * output - next field
253 * side effects - field breakup for ircd.conf file.
256 getfield(char *newline
)
258 static char *line
= NULL
;
269 /* XXX make this skip to first " if present */
273 return (NULL
); /* mal-formed field */
275 end
= strchr(line
, ',');
279 /* no trailing , - last field */
282 end
= line
+ strlen(line
);
295 /* look for a ", to mark the end of a field.. */
296 if(*(end
- 1) == '"')
304 /* search for the next ',' */
306 end
= strchr(end
, ',');