comparison src/conf.c @ 333:0bd27f603910

Added debug level 9 for msgs to stderr during reading config See changes to man page, included in this changeset.
author markus schnalke <meillo@marmaro.de>
date Sat, 27 Aug 2011 16:54:14 +0200
parents f899ca0835a8
children 08932c629849
comparison
equal deleted inserted replaced
332:63efd381e27b 333:0bd27f603910
60 static gboolean 60 static gboolean
61 parse_boolean(gchar * rval) 61 parse_boolean(gchar * rval)
62 { 62 {
63 gchar **str; 63 gchar **str;
64 64
65 DEBUG(6) fprintf(stderr, "parse_boolean: %s\n", rval); 65 DEBUG(9) fprintf(stderr, "parse_boolean: %s\n", rval);
66 66
67 str = true_strings; 67 str = true_strings;
68 while (*str) { 68 while (*str) {
69 if (strncasecmp(*str, rval, strlen(*str)) == 0) 69 if (strncasecmp(*str, rval, strlen(*str)) == 0)
70 return TRUE; 70 return TRUE;
98 98
99 while (!feof(fptr)) { 99 while (!feof(fptr)) {
100 fgets(buf, 255, fptr); 100 fgets(buf, 255, fptr);
101 if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) { 101 if (buf[0] && (buf[0] != '#') && (buf[0] != '\n')) {
102 g_strchomp(buf); 102 g_strchomp(buf);
103 DEBUG(6) fprintf(stderr,"parse_list_file: item = %s\n", buf); 103 DEBUG(9) fprintf(stderr,"parse_list_file: item = %s\n", buf);
104 list = g_list_append(list, g_strdup(buf)); 104 list = g_list_append(list, g_strdup(buf));
105 } 105 }
106 } 106 }
107 fclose(fptr); 107 fclose(fptr);
108 108
115 { 115 {
116 GList *list = NULL; 116 GList *list = NULL;
117 gchar buf[256]; 117 gchar buf[256];
118 gchar *p, *q; 118 gchar *p, *q;
119 119
120 DEBUG(6) fprintf(stderr, "parsing list %s, file?:%d\n", line, read_file); 120 DEBUG(9) fprintf(stderr, "parsing list %s, file?:%d\n", line, read_file);
121 121
122 p = line; 122 p = line;
123 while (*p != '\0') { 123 while (*p != '\0') {
124 q = buf; 124 q = buf;
125 125
132 list = g_list_concat(list, parse_list_file(buf)); 132 list = g_list_concat(list, parse_list_file(buf));
133 else 133 else
134 /* just a normal item */ 134 /* just a normal item */
135 list = g_list_append(list, g_strdup(buf)); 135 list = g_list_append(list, g_strdup(buf));
136 136
137 DEBUG(6) fprintf(stderr, "item = %s\n", buf); 137 DEBUG(9) fprintf(stderr, "item = %s\n", buf);
138 138
139 if (*p) 139 if (*p)
140 p++; 140 p++;
141 } 141 }
142 return list; 142 return list;
224 { 224 {
225 gchar buf[256]; 225 gchar buf[256];
226 gchar *p, *q; 226 gchar *p, *q;
227 interface *iface; 227 interface *iface;
228 228
229 DEBUG(6) fprintf(stderr, "parse_interface: %s\n", line); 229 DEBUG(9) fprintf(stderr, "parse_interface: %s\n", line);
230 230
231 p = line; 231 p = line;
232 q = buf; 232 q = buf;
233 while ((*p != '\0') && (*p != ':') && (q < buf + 255)) 233 while ((*p != '\0') && (*p != ':') && (q < buf + 255))
234 *(q++) = *(p++); 234 *(q++) = *(p++);
240 if (*p) { 240 if (*p) {
241 p++; 241 p++;
242 iface->port = atoi(p); 242 iface->port = atoi(p);
243 } else 243 } else
244 iface->port = def_port; 244 iface->port = def_port;
245 DEBUG(6) fprintf(stderr,"rval=%s, address:port=%s:%i\n",line, iface->address, iface->port); 245 DEBUG(9) fprintf(stderr,"rval=%s, address:port=%s:%i\n",line, iface->address, iface->port);
246 246
247 return iface; 247 return iface;
248 } 248 }
249 249
250 #ifdef ENABLE_IDENT /* so far used for that only */ 250 #ifdef ENABLE_IDENT /* so far used for that only */
254 gchar buf[256]; 254 gchar buf[256];
255 gchar *p, *q; 255 gchar *p, *q;
256 struct in_addr addr, mask_addr, net_addr, *p_net_addr; 256 struct in_addr addr, mask_addr, net_addr, *p_net_addr;
257 guint n; 257 guint n;
258 258
259 DEBUG(6) fprintf(stderr, "parse_network: %s\n", line); 259 DEBUG(9) fprintf(stderr, "parse_network: %s\n", line);
260 260
261 p = line; 261 p = line;
262 q = buf; 262 q = buf;
263 while ((*p != '\0') && (*p != '/') && (q < buf + 255)) 263 while ((*p != '\0') && (*p != '/') && (q < buf + 255))
264 *(q++) = *(p++); 264 *(q++) = *(p++);
339 read_lval(FILE * in, gchar * buf, gint size) 339 read_lval(FILE * in, gchar * buf, gint size)
340 { 340 {
341 gint c; 341 gint c;
342 gchar *ptr = buf; 342 gchar *ptr = buf;
343 343
344 DEBUG(6) fprintf(stderr, "read_lval()\n"); 344 DEBUG(9) fprintf(stderr, "read_lval()\n");
345 345
346 if (!eat_spaces(in)) 346 if (!eat_spaces(in))
347 return FALSE; 347 return FALSE;
348 348
349 c = fgetc(in); 349 c = fgetc(in);
350 DEBUG(6) fprintf(stderr, "read_lval() 2\n"); 350 DEBUG(9) fprintf(stderr, "read_lval() 2\n");
351 while ((isalnum(c) || c == '_' || c == '-' || c == '.') 351 while ((isalnum(c) || c == '_' || c == '-' || c == '.')
352 && (ptr < buf + size - 1) 352 && (ptr < buf + size - 1)
353 && (c != EOF)) { 353 && (c != EOF)) {
354 *ptr = c; 354 *ptr = c;
355 ptr++; 355 ptr++;
365 fprintf(stderr, "lval too long\n"); 365 fprintf(stderr, "lval too long\n");
366 } 366 }
367 367
368 eat_spaces(in); 368 eat_spaces(in);
369 369
370 DEBUG(6) fprintf(stderr, "lval = %s\n", buf); 370 DEBUG(9) fprintf(stderr, "lval = %s\n", buf);
371 371
372 return buf[0] != '\0'; 372 return buf[0] != '\0';
373 } 373 }
374 374
375 static gboolean 375 static gboolean
376 read_rval(FILE * in, gchar * buf, gint size) 376 read_rval(FILE * in, gchar * buf, gint size)
377 { 377 {
378 gint c; 378 gint c;
379 gchar *ptr = buf; 379 gchar *ptr = buf;
380 380
381 DEBUG(6) fprintf(stderr, "read_rval()\n"); 381 DEBUG(9) fprintf(stderr, "read_rval()\n");
382 382
383 if (!eat_spaces(in)) 383 if (!eat_spaces(in))
384 return FALSE; 384 return FALSE;
385 385
386 c = fgetc(in); 386 c = fgetc(in);
413 *ptr = '\0'; 413 *ptr = '\0';
414 } 414 }
415 415
416 eat_line_trailing(in); 416 eat_line_trailing(in);
417 417
418 DEBUG(6) fprintf(stderr, "rval = %s\n", buf); 418 DEBUG(9) fprintf(stderr, "rval = %s\n", buf);
419 419
420 return TRUE; 420 return TRUE;
421 } 421 }
422 422
423 static gboolean 423 static gboolean
424 read_statement(FILE * in, gchar * lval, gint lsize, gchar * rval, gint rsize) 424 read_statement(FILE * in, gchar * lval, gint lsize, gchar * rval, gint rsize)
425 { 425 {
426 gint c; 426 gint c;
427 427
428 DEBUG(6) fprintf(stderr, "read_statement()\n"); 428 DEBUG(9) fprintf(stderr, "read_statement()\n");
429 429
430 /* eat comments and empty lines: */ 430 /* eat comments and empty lines: */
431 if (!eat_comments(in)) 431 if (!eat_comments(in))
432 return FALSE; 432 return FALSE;
433 433
434 if (!read_lval(in, lval, lsize)) { 434 if (!read_lval(in, lval, lsize)) {
435 return FALSE; 435 return FALSE;
436 } 436 }
437 437
438 DEBUG(6) fprintf(stderr, " lval = %s\n", lval); 438 DEBUG(9) fprintf(stderr, " lval = %s\n", lval);
439 if ((c = fgetc(in) == '=')) { 439 if ((c = fgetc(in) == '=')) {
440 if (read_rval(in, rval, rsize)) { 440 if (read_rval(in, rval, rsize)) {
441 DEBUG(6) fprintf(stderr, " rval = %s\n", rval); 441 DEBUG(9) fprintf(stderr, " rval = %s\n", rval);
442 return TRUE; 442 return TRUE;
443 } 443 }
444 } else { 444 } else {
445 DEBUG(6) fprintf(stderr," '=' expected after %s, char was '%c'\n", lval, c); 445 DEBUG(9) fprintf(stderr," '=' expected after %s, char was '%c'\n", lval, c);
446 fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c); 446 fprintf(stderr, "'=' expected after %s, char was '%c'\n", lval, c);
447 } 447 }
448 return FALSE; 448 return FALSE;
449 } 449 }
450 450
467 return FALSE; 467 return FALSE;
468 } 468 }
469 469
470 gchar lval[256], rval[2048]; 470 gchar lval[256], rval[2048];
471 while (read_statement(in, lval, 256, rval, 2048)) { 471 while (read_statement(in, lval, 256, rval, 2048)) {
472 DEBUG(6) fprintf(stderr,"read_conf(): lval=%s\n", lval); 472 DEBUG(9) fprintf(stderr,"read_conf(): lval=%s\n", lval);
473 if (strcmp(lval, "debug_level") == 0) 473 if (strcmp(lval, "debug_level") == 0)
474 conf.debug_level = atoi(rval); 474 conf.debug_level = atoi(rval);
475 else if (strcmp(lval, "run_as_user") == 0) { 475 else if (strcmp(lval, "run_as_user") == 0) {
476 if (!conf.run_as_user) /* you should not be able to reset that flag */ 476 if (!conf.run_as_user) /* you should not be able to reset that flag */
477 conf.run_as_user = parse_boolean(rval); 477 conf.run_as_user = parse_boolean(rval);
583 conf.max_defer_time = ival; 583 conf.max_defer_time = ival;
584 } else if (strcmp(lval, "log_user") == 0) 584 } else if (strcmp(lval, "log_user") == 0)
585 conf.log_user = g_strdup(rval); 585 conf.log_user = g_strdup(rval);
586 else if(strcmp(lval, "max_msg_size") == 0) { 586 else if(strcmp(lval, "max_msg_size") == 0) {
587 conf.max_msg_size = atol(rval); 587 conf.max_msg_size = atol(rval);
588 DEBUG(6) fprintf(stderr,"rval=%s, conf.max_msg_size=%ld\n", 588 DEBUG(9) fprintf(stderr,"rval=%s, conf.max_msg_size=%ld\n",
589 rval, conf.max_msg_size); 589 rval, conf.max_msg_size);
590 } 590 }
591 else 591 else
592 logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval); 592 logwrite(LOG_WARNING, "var '%s' not (yet) known, ignored\n", lval);
593 } 593 }