]>
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 $
30 #include "s_newconf.h"
33 #include "irc_string.h"
38 * inputs - pointer to config item, host/pass/user/operreason/date 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
, const char *date_field
)
47 if(host_field
!= NULL
)
48 aconf
->host
= rb_strdup(host_field
);
49 if(pass_field
!= NULL
)
51 if(!EmptyString(date_field
))
53 aconf
->passwd
= rb_malloc(strlen(pass_field
) + strlen(date_field
) + 4);
54 rb_sprintf(aconf
->passwd
, "%s (%s)", pass_field
, date_field
);
57 aconf
->passwd
= rb_strdup(pass_field
);
59 if(user_field
!= NULL
)
60 aconf
->user
= rb_strdup(user_field
);
61 if(operreason_field
!= NULL
)
62 aconf
->spasswd
= rb_strdup(operreason_field
);
67 * Inputs - pointer to line to parse
69 * Side Effects - Parse one new style K line
73 parse_k_file(FILE * file
)
75 struct ConfItem
*aconf
;
76 char *user_field
= NULL
;
77 char *reason_field
= NULL
;
78 char *operreason_field
= NULL
;
79 char *host_field
= NULL
;
80 char *date_field
= NULL
;
84 while (fgets(line
, sizeof(line
), file
))
86 if((p
= strchr(line
, '\n')) != NULL
)
89 if((*line
== '\0') || (*line
== '#'))
92 user_field
= getfield(line
);
93 if(EmptyString(user_field
))
96 host_field
= getfield(NULL
);
97 if(EmptyString(host_field
))
100 reason_field
= getfield(NULL
);
101 if(EmptyString(reason_field
))
104 operreason_field
= getfield(NULL
);
105 date_field
= getfield(NULL
);
108 aconf
->status
= CONF_KILL
;
109 conf_add_fields(aconf
, host_field
, reason_field
,
110 user_field
, operreason_field
, date_field
);
112 if(aconf
->host
!= NULL
)
113 add_conf_by_address(aconf
->host
, CONF_KILL
, aconf
->user
, aconf
);
119 * Inputs - pointer to line to parse
121 * Side Effects - Parse one new style D line
125 parse_d_file(FILE * file
)
127 struct ConfItem
*aconf
;
128 char *reason_field
= NULL
;
129 char *host_field
= NULL
;
130 char *operreason_field
= NULL
;
131 char *date_field
= NULL
;
135 while (fgets(line
, sizeof(line
), file
))
137 if((p
= strchr(line
, '\n')))
140 if((*line
== '\0') || (line
[0] == '#'))
143 host_field
= getfield(line
);
144 if(EmptyString(host_field
))
147 reason_field
= getfield(NULL
);
148 if(EmptyString(reason_field
))
151 operreason_field
= getfield(NULL
);
152 date_field
= getfield(NULL
);
155 aconf
->status
= CONF_DLINE
;
156 conf_add_fields(aconf
, host_field
, reason_field
, "", operreason_field
, date_field
);
157 conf_add_d_conf(aconf
);
162 parse_x_file(FILE * file
)
164 struct ConfItem
*aconf
;
165 char *gecos_field
= NULL
;
166 char *reason_field
= NULL
;
170 while (fgets(line
, sizeof(line
), file
))
172 if((p
= strchr(line
, '\n')))
175 if((*line
== '\0') || (line
[0] == '#'))
178 gecos_field
= getfield(line
);
179 if(EmptyString(gecos_field
))
182 /* field for xline types, which no longer exist */
185 reason_field
= getfield(NULL
);
186 if(EmptyString(reason_field
))
189 /* sanity checking */
190 if((find_xline_mask(gecos_field
) != NULL
) ||
191 (strchr(reason_field
, ':') != NULL
))
195 aconf
->status
= CONF_XLINE
;
197 aconf
->name
= rb_strdup(gecos_field
);
198 aconf
->passwd
= rb_strdup(reason_field
);
200 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
205 parse_resv_file(FILE * file
)
207 struct ConfItem
*aconf
;
213 while (fgets(line
, sizeof(line
), file
))
215 if((p
= strchr(line
, '\n')))
218 if((*line
== '\0') || (line
[0] == '#'))
221 host_field
= getfield(line
);
222 if(EmptyString(host_field
))
225 reason_field
= getfield(NULL
);
226 if(EmptyString(reason_field
))
229 if(IsChannelName(host_field
))
231 if(hash_find_resv(host_field
))
235 aconf
->status
= CONF_RESV_CHANNEL
;
238 aconf
->name
= rb_strdup(host_field
);
239 aconf
->passwd
= rb_strdup(reason_field
);
240 add_to_resv_hash(aconf
->name
, aconf
);
242 else if(clean_resv_nick(host_field
))
244 if(find_nick_resv_mask(host_field
))
248 aconf
->status
= CONF_RESV_NICK
;
251 aconf
->name
= rb_strdup(host_field
);
252 aconf
->passwd
= rb_strdup(reason_field
);
253 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
261 * inputs - input buffer
262 * output - next field
263 * side effects - field breakup for ircd.conf file.
266 getfield(char *newline
)
268 static char *line
= NULL
;
279 /* XXX make this skip to first " if present */
283 return (NULL
); /* mal-formed field */
285 end
= strchr(line
, ',');
289 /* no trailing , - last field */
292 end
= line
+ strlen(line
);
305 /* look for a ", to mark the end of a field.. */
306 if(*(end
- 1) == '"')
314 /* search for the next ',' */
316 end
= strchr(end
, ',');