]>
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"
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
, NULL
, 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 xline_encode_spaces(const char *mask
)
169 for (i
= 0; mask
[i
] != '\0'; i
++)
172 encoded
= rb_malloc(i
+ spaces
+ 1);
173 for (i
= 0, j
= 0; mask
[i
] != '\0'; i
++)
176 backslash
= !backslash
;
177 else if (mask
[i
] == ' ')
187 encoded
[j
++] = mask
[i
];
193 parse_x_file(FILE * file
)
195 struct ConfItem
*aconf
;
196 char *gecos_field
= NULL
;
197 char *reason_field
= NULL
;
202 while (fgets(line
, sizeof(line
), file
))
204 if((p
= strchr(line
, '\n')))
207 if((*line
== '\0') || (line
[0] == '#'))
210 gecos_field
= getfield(line
);
211 if(EmptyString(gecos_field
))
214 /* field for xline types, which no longer exist */
217 reason_field
= getfield(NULL
);
218 if(EmptyString(reason_field
))
221 /* sanity checking */
222 if((find_xline_mask(gecos_field
) != NULL
) ||
223 (strchr(reason_field
, ':') != NULL
))
226 encoded
= xline_encode_spaces(gecos_field
);
227 if (find_xline_mask(encoded
) != NULL
)
234 aconf
->status
= CONF_XLINE
;
236 aconf
->name
= encoded
;
237 aconf
->passwd
= rb_strdup(reason_field
);
239 rb_dlinkAddAlloc(aconf
, &xline_conf_list
);
244 parse_resv_file(FILE * file
)
246 struct ConfItem
*aconf
;
252 while (fgets(line
, sizeof(line
), file
))
254 if((p
= strchr(line
, '\n')))
257 if((*line
== '\0') || (line
[0] == '#'))
260 host_field
= getfield(line
);
261 if(EmptyString(host_field
))
264 reason_field
= getfield(NULL
);
265 if(EmptyString(reason_field
))
268 if(IsChannelName(host_field
))
270 if(hash_find_resv(host_field
))
274 aconf
->status
= CONF_RESV_CHANNEL
;
277 aconf
->name
= rb_strdup(host_field
);
278 aconf
->passwd
= rb_strdup(reason_field
);
279 add_to_resv_hash(aconf
->name
, aconf
);
281 else if(clean_resv_nick(host_field
))
283 if(find_nick_resv_mask(host_field
))
287 aconf
->status
= CONF_RESV_NICK
;
290 aconf
->name
= rb_strdup(host_field
);
291 aconf
->passwd
= rb_strdup(reason_field
);
292 rb_dlinkAddAlloc(aconf
, &resv_conf_list
);
300 * inputs - input buffer
301 * output - next field
302 * side effects - field breakup for ircd.conf file.
305 getfield(char *newline
)
307 static char *line
= NULL
;
318 /* XXX make this skip to first " if present */
322 return (NULL
); /* mal-formed field */
324 end
= strchr(line
, ',');
328 /* no trailing , - last field */
331 end
= line
+ strlen(line
);
344 /* look for a ", to mark the end of a field.. */
345 if(*(end
- 1) == '"')
353 /* search for the next ',' */
355 end
= strchr(end
, ',');