aboutsummaryrefslogtreecommitdiff
path: root/jabberd/main.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2007-06-02 18:45:53 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2007-06-02 18:45:53 +0000
commit2c26c67fae94e783d5cc5ee634273b639aa405e5 (patch)
tree2a06b7393fa97e5ce6a4b5e166ae412de063f1ad /jabberd/main.c
parent2a37423d019dbfdfd8c11072dd6abe624aa5c286 (diff)
downloadgsc-2c26c67fae94e783d5cc5ee634273b639aa405e5.tar.gz
gsc-2c26c67fae94e783d5cc5ee634273b639aa405e5.tar.bz2
Update
git-svn-id: file:///svnroot/gsc/trunk@250 d2de0444-eb31-0410-8365-af798a554d48
Diffstat (limited to 'jabberd/main.c')
-rw-r--r--jabberd/main.c341
1 files changed, 243 insertions, 98 deletions
diff --git a/jabberd/main.c b/jabberd/main.c
index f195f72..f073e1e 100644
--- a/jabberd/main.c
+++ b/jabberd/main.c
@@ -145,24 +145,33 @@ usage ()
145} 145}
146 146
147 147
148/* Configuration file handling */ 148struct kw_int
149 149{
150typedef void (*cfg_fun) (unsigned line, char *kw, char *val); 150 char *name;
151 int tok;
152};
151 153
152void 154int
153cfg_syslog_tag (unsigned line, char *kw, char *val) 155syslog_to_n (struct kw_int *kw, char *str, int *pint)
154{ 156{
155 syslog_tag = strdup (val); 157 int i;
158
159 if (strncasecmp (str, "LOG_", 4) == 0)
160 str += 4;
161
162 for (; kw->name; kw++)
163 if (strcasecmp (kw->name, str) == 0)
164 {
165 *pint = kw->tok;
166 return 0;
167 }
168 return 1;
156} 169}
157 170
158void 171int
159cfg_syslog_facility (unsigned line, char *kw, char *val) 172str_to_facility (char *str, int *pfacility)
160{ 173{
161 int i; 174 static struct kw_int kw_facility[] = {
162 static struct {
163 char *name;
164 int facility;
165 } syslog_kw[] = {
166 { "USER", LOG_USER }, 175 { "USER", LOG_USER },
167 { "DAEMON", LOG_DAEMON }, 176 { "DAEMON", LOG_DAEMON },
168 { "AUTH", LOG_AUTH }, 177 { "AUTH", LOG_AUTH },
@@ -174,29 +183,141 @@ cfg_syslog_facility (unsigned line, char *kw, char *val)
174 { "LOCAL5", LOG_LOCAL5 }, 183 { "LOCAL5", LOG_LOCAL5 },
175 { "LOCAL6", LOG_LOCAL6 }, 184 { "LOCAL6", LOG_LOCAL6 },
176 { "LOCAL7", LOG_LOCAL7 }, 185 { "LOCAL7", LOG_LOCAL7 },
177 { "MAIL", LOG_MAIL } 186 { "MAIL", LOG_MAIL },
187 { NULL }
178 }; 188 };
189 return syslog_to_n (kw_facility, str, pfacility);
190}
179 191
180 if (strncasecmp (val, "LOG_", 4) == 0) 192int
181 val += 4; 193str_to_priority (char *str, int *pprio)
194{
195 static struct kw_int kw_prio[] = {
196 { "EMERG", LOG_EMERG },
197 { "ALERT", LOG_ALERT },
198 { "CRIT", LOG_CRIT },
199 { "ERR", LOG_ERR },
200 { "WARNING", LOG_WARNING },
201 { "NOTICE", LOG_NOTICE },
202 { "INFO", LOG_INFO },
203 { "DEBUG", LOG_DEBUG },
204 { NULL }
205 };
206 return syslog_to_n (kw_prio, str, pprio);
207}
182 208
183 for (i = 0; i < sizeof (syslog_kw) / sizeof (syslog_kw[0]); i++) 209
184 if (strcasecmp (syslog_kw[i].name, val) == 0) 210
185 { 211/* Configuration file handling */
186 log_facility = syslog_kw[i].facility; 212
187 return; 213struct cfg_file
188 } 214{
189 logmsg (LOG_ERR, "%s:%u: Unknown facility `%s'", config_file, line, val); 215 FILE *fp;
216 unsigned line;
217 char *buf;
218 size_t size;
219};
220
221typedef void (*cfg_fun) (struct cfg_file *file, char *kw, char *val, void *data);
222
223struct kw_handler
224{
225 char *kw;
226 cfg_fun handler;
227};
228
229static cfg_fun
230find_cfg_fun (struct kw_handler *kwtab, char *kw)
231{
232 for (; kwtab->kw; kwtab++)
233 if (strcmp (kwtab->kw, kw) == 0)
234 return kwtab->handler;
235 return NULL;
236}
237
238void
239parse_block (struct cfg_file *file, void *data,
240 struct kw_handler *kwtab, const char *end)
241{
242 while (getline (&file->buf, &file->size, file->fp) > 0)
243 {
244 size_t len;
245 char *p, *kw, *val = NULL;
246 cfg_fun fun;
247
248 file->line++;
249 for (p = file->buf; *p && isspace (*p); p++)
250 ;
251 if (*p == '#' || *p == 0)
252 continue;
253
254 len = strlen (p);
255 if (p[len-1] == '\n')
256 p[--len] = 0;
257
258 for (;len > 0 && isspace (p[len-1]); len--)
259 ;
260
261 if (len > 0)
262 p[len] = 0;
263 else
264 continue;
265
266 kw = p;
267 for (; *p && !isspace (*p); p++)
268 ;
269
270 if (*p)
271 {
272 *p++ = 0;
273 for (; *p && isspace (*p); p++)
274 ;
275
276 val = p;
277 }
278
279 if (end && val == NULL && strcmp (kw, end) == 0)
280 break;
281
282 fun = find_cfg_fun (kwtab, kw);
283 if (fun)
284 fun (file, kw, val, data);
285 else
286 {
287#ifdef ALLOW_LEGACY_CONFIG
288 logmsg (LOG_WARNING, "%s:%u: legacy line", config_file, file->line);
289 register_jabber_process (kw, val);
290#else
291 logmsg (LOG_ERR, "%s:%u: unrecognized line", config_file, file->line);
292#endif
293 }
294 }
295}
296
297void
298cfg_syslog_tag (struct cfg_file *file, char *kw, char *val, void *unused)
299{
300 syslog_tag = strdup (val);
190} 301}
191 302
192void 303void
193cfg_user (unsigned line, char *kw, char *val) 304cfg_syslog_facility (struct cfg_file *file, char *kw, char *val, void *unused)
305{
306 if (str_to_facility (val, &log_facility))
307 logmsg (LOG_ERR, "%s:%u: Unknown facility `%s'",
308 config_file, file->line, val);
309}
310
311void
312cfg_user (struct cfg_file *file, char *kw, char *val, void *unused)
194{ 313{
195 struct passwd *pwd = getpwnam (val); 314 struct passwd *pwd = getpwnam (val);
196 if (!pwd) 315 if (!pwd)
197 logmsg (LOG_ERR, "%s:%u: no such user `%s'", config_file, line, val); 316 logmsg (LOG_ERR, "%s:%u: no such user `%s'",
317 config_file, file->line, val);
198 else if (pwd->pw_uid == 0) 318 else if (pwd->pw_uid == 0)
199 logmsg (LOG_ERR, "%s:%u: user `%s' has zero UID", config_file, line, val); 319 logmsg (LOG_ERR, "%s:%u: user `%s' has zero UID", config_file,
320 file->line, val);
200 else 321 else
201 user = strdup (val); 322 user = strdup (val);
202} 323}
@@ -210,7 +331,7 @@ struct group_list
210static struct group_list *group_list; 331static struct group_list *group_list;
211 332
212void 333void
213cfg_group (unsigned line, char *kw, char *val) 334cfg_group (struct cfg_file *file, char *kw, char *val, void *unused)
214{ 335{
215 struct group *group = getgrnam (val); 336 struct group *group = getgrnam (val);
216 if (group) 337 if (group)
@@ -222,17 +343,17 @@ cfg_group (unsigned line, char *kw, char *val)
222 } 343 }
223 else 344 else
224 logmsg(LOG_ERR, "%s:%u: unknown group `%s'", config_file, 345 logmsg(LOG_ERR, "%s:%u: unknown group `%s'", config_file,
225 line, val); 346 file->line, val);
226} 347}
227 348
228void 349void
229cfg_pidfile (unsigned line, char *kw, char *val) 350cfg_pidfile (struct cfg_file *file, char *kw, char *val, void *unused)
230{ 351{
231 pidfile = strdup (val); 352 pidfile = strdup (val);
232} 353}
233 354
234void 355void
235cfg_prog (unsigned line, char *kw, char *val) 356cfg_prog (struct cfg_file *file, char *kw, char *val, void *unused)
236{ 357{
237 char *prog = val; 358 char *prog = val;
238 char *p = val;