Commit f0cc7bda f0cc7bda9699c31f2c478928f78b16876db2fa25 by Sergey Poznyakoff

Bugfixes.

* mailbox/assoc.c (assoc_remove): Fix incorrect copying
between assoc slots.
* mailbox/cfg_parser.y (STRTONUM): Remove useless
dereferencing. Change the loop from `while' to `for'.
1 parent 50da8665
...@@ -173,7 +173,9 @@ assoc_remove (mu_assoc_t assoc, struct _mu_assoc_elem *elem) ...@@ -173,7 +173,9 @@ assoc_remove (mu_assoc_t assoc, struct _mu_assoc_elem *elem)
173 } 173 }
174 while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j)); 174 while ((j < r && r <= i) || (i < j && j < r) || (r <= i && i < j));
175 175
176 *ASSOC_ELEM (assoc, j) = *ASSOC_ELEM (assoc, i); 176 if (j != i)
177 memcpy (ASSOC_ELEM (assoc, j), ASSOC_ELEM (assoc, i),
178 assoc->elsize);
177 } 179 }
178 return 0; 180 return 0;
179 } 181 }
......
1 %{ 1 %{
2 /* cfg_parser.y -- general-purpose configuration file parser 2 /* cfg_parser.y -- general-purpose configuration file parser
3 Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc. 3 Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
4 4
5 GNU Mailutils is free software; you can redistribute it and/or 5 GNU Mailutils is free software; you can redistribute it and/or
...@@ -20,29 +20,29 @@ ...@@ -20,29 +20,29 @@
20 #endif 20 #endif
21 #include <stdio.h> 21 #include <stdio.h>
22 #include <stdlib.h> 22 #include <stdlib.h>
23 #include <stdarg.h> 23 #include <stdarg.h>
24 #include <string.h> 24 #include <string.h>
25 #include <netdb.h> 25 #include <netdb.h>
26 #include "intprops.h" 26 #include "intprops.h"
27 #include <mailutils/nls.h> 27 #include <mailutils/nls.h>
28 #include <mailutils/cfg.h> 28 #include <mailutils/cfg.h>
29 #include <mailutils/alloc.h> 29 #include <mailutils/alloc.h>
30 #include <mailutils/errno.h> 30 #include <mailutils/errno.h>
31 #include <mailutils/error.h> 31 #include <mailutils/error.h>
32 #include <mailutils/list.h> 32 #include <mailutils/list.h>
33 #include <mailutils/iterator.h> 33 #include <mailutils/iterator.h>
34 #include <mailutils/debug.h> 34 #include <mailutils/debug.h>
35 35
36 int mu_cfg_parser_verbose; 36 int mu_cfg_parser_verbose;
37 static mu_cfg_node_t *parse_tree; 37 static mu_cfg_node_t *parse_tree;
38 mu_cfg_locus_t mu_cfg_locus; 38 mu_cfg_locus_t mu_cfg_locus;
39 size_t mu_cfg_error_count; 39 size_t mu_cfg_error_count;
40 40
41 static int _mu_cfg_errcnt; 41 static int _mu_cfg_errcnt;
42 static mu_debug_t _mu_cfg_debug; 42 static mu_debug_t _mu_cfg_debug;
43 43
44 int yylex (); 44 int yylex ();
45 45
46 void _mu_line_begin (void); 46 void _mu_line_begin (void);
47 void _mu_line_add (char *text, size_t len); 47 void _mu_line_add (char *text, size_t len);
48 char *_mu_line_finish (void); 48 char *_mu_line_finish (void);
...@@ -62,12 +62,12 @@ config_value_dup (mu_config_value_t *src) ...@@ -62,12 +62,12 @@ config_value_dup (mu_config_value_t *src)
62 else 62 else
63 { 63 {
64 /* FIXME: Use mu_opool_alloc */ 64 /* FIXME: Use mu_opool_alloc */
65 mu_config_value_t *val = mu_alloc (sizeof (*val)); 65 mu_config_value_t *val = mu_alloc (sizeof (*val));
66 *val = *src; 66 *val = *src;
67 return val; 67 return val;
68 } 68 }
69 } 69 }
70 70
71 static mu_cfg_node_t * 71 static mu_cfg_node_t *
72 mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc, 72 mu_cfg_alloc_node (enum mu_cfg_node_type type, mu_cfg_locus_t *loc,
73 const char *tag, mu_config_value_t *label, 73 const char *tag, mu_config_value_t *label,
...@@ -92,7 +92,7 @@ void ...@@ -92,7 +92,7 @@ void
92 mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...) 92 mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...)
93 { 93 {
94 va_list ap; 94 va_list ap;
95 95
96 if (!debug) 96 if (!debug)
97 mu_diag_get_debug (&debug); 97 mu_diag_get_debug (&debug);
98 va_start (ap, fmt); 98 va_start (ap, fmt);
...@@ -101,7 +101,7 @@ mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...) ...@@ -101,7 +101,7 @@ mu_cfg_format_error (mu_debug_t debug, size_t level, const char *fmt, ...)
101 va_end (ap); 101 va_end (ap);
102 if (level <= MU_DEBUG_ERROR) 102 if (level <= MU_DEBUG_ERROR)
103 mu_cfg_error_count++; 103 mu_cfg_error_count++;
104 } 104 }
105 105
106 static void 106 static void
107 _mu_cfg_debug_set_locus (mu_debug_t debug, const mu_cfg_locus_t *loc) 107 _mu_cfg_debug_set_locus (mu_debug_t debug, const mu_cfg_locus_t *loc)
...@@ -128,7 +128,7 @@ _mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *loc, ...@@ -128,7 +128,7 @@ _mu_cfg_perror (mu_debug_t debug, const mu_cfg_locus_t *loc,
128 const char *fmt, ...) 128 const char *fmt, ...)
129 { 129 {
130 va_list ap; 130 va_list ap;
131 131
132 va_start (ap, fmt); 132 va_start (ap, fmt);
133 _mu_cfg_vperror (debug, loc, fmt, ap); 133 _mu_cfg_vperror (debug, loc, fmt, ap);
134 va_end (ap); 134 va_end (ap);
...@@ -138,7 +138,7 @@ void ...@@ -138,7 +138,7 @@ void
138 mu_cfg_perror (const mu_cfg_locus_t *loc, const char *fmt, ...) 138 mu_cfg_perror (const mu_cfg_locus_t *loc, const char *fmt, ...)
139 { 139 {
140 va_list ap; 140 va_list ap;
141 141
142 va_start (ap, fmt); 142 va_start (ap, fmt);
143 _mu_cfg_vperror (_mu_cfg_debug, loc, fmt, ap); 143 _mu_cfg_vperror (_mu_cfg_debug, loc, fmt, ap);
144 va_end (ap); 144 va_end (ap);
...@@ -163,11 +163,11 @@ debug_print_node (mu_cfg_node_t *node) ...@@ -163,11 +163,11 @@ debug_print_node (mu_cfg_node_t *node)
163 "statement: %s, id: %s", 163 "statement: %s, id: %s",
164 node_type_str (node->type), 164 node_type_str (node->type),
165 node->tag ? node->tag : "(null)"); 165 node->tag ? node->tag : "(null)");
166 166
167 mu_debug_set_locus (_mu_cfg_debug, NULL, 0); 167 mu_debug_set_locus (_mu_cfg_debug, NULL, 0);
168 } 168 }
169 } 169 }
170 170
171 %} 171 %}
172 172
173 %union { 173 %union {
...@@ -183,7 +183,7 @@ debug_print_node (mu_cfg_node_t *node) ...@@ -183,7 +183,7 @@ debug_print_node (mu_cfg_node_t *node)
183 %token <string> MU_TOK_IDENT MU_TOK_STRING MU_TOK_QSTRING MU_TOK_MSTRING 183 %token <string> MU_TOK_IDENT MU_TOK_STRING MU_TOK_QSTRING MU_TOK_MSTRING
184 %type <string> string slist 184 %type <string> string slist
185 %type <list> slist0 185 %type <list> slist0
186 %type <value> value 186 %type <value> value
187 %type <pvalue> tag vallist 187 %type <pvalue> tag vallist
188 %type <list> values list vlist 188 %type <list> values list vlist
189 %type <ident> ident 189 %type <ident> ident
...@@ -193,69 +193,69 @@ debug_print_node (mu_cfg_node_t *node) ...@@ -193,69 +193,69 @@ debug_print_node (mu_cfg_node_t *node)
193 %% 193 %%
194 194
195 input : stmtlist 195 input : stmtlist
196 { 196 {
197 parse_tree = $1.head; 197 parse_tree = $1.head;
198 } 198 }
199 ; 199 ;
200 200
201 stmtlist: stmt 201 stmtlist: stmt
202 { 202 {
203 $$.head = $$.tail = $1; 203 $$.head = $$.tail = $1;
204 debug_print_node ($1); 204 debug_print_node ($1);
205 } 205 }
206 | stmtlist stmt 206 | stmtlist stmt
207 { 207 {
208 $$ = $1; 208 $$ = $1;
209 $$.tail->next = $2; 209 $$.tail->next = $2;
210 $$.tail = $2; 210 $$.tail = $2;
211 debug_print_node ($2); 211 debug_print_node ($2);
212 } 212 }
213 ; 213 ;
214 214
215 stmt : simple 215 stmt : simple
216 | block 216 | block
217 ; 217 ;
218 218
219 simple : ident vallist ';' 219 simple : ident vallist ';'
220 { 220 {
221 $$ = mu_cfg_alloc_node (mu_cfg_node_param, &$1.locus, 221 $$ = mu_cfg_alloc_node (mu_cfg_node_param, &$1.locus,
222 $1.name, $2, 222 $1.name, $2,
223 NULL); 223 NULL);
224 } 224 }
225 ; 225 ;
226 226
227 block : ident tag '{' '}' opt_sc 227 block : ident tag '{' '}' opt_sc
228 { 228 {
229 $$ = mu_cfg_alloc_node (mu_cfg_node_tag, &$1.locus, 229 $$ = mu_cfg_alloc_node (mu_cfg_node_tag, &$1.locus,
230 $1.name, $2, 230 $1.name, $2,
231 NULL); 231 NULL);
232 232
233 } 233 }
234 | ident tag '{' stmtlist '}' opt_sc 234 | ident tag '{' stmtlist '}' opt_sc
235 { 235 {
236 $$ = mu_cfg_alloc_node (mu_cfg_node_tag, &$1.locus, 236 $$ = mu_cfg_alloc_node (mu_cfg_node_tag, &$1.locus,
237 $1.name, $2, 237 $1.name, $2,
238 $4.head); 238 $4.head);
239 239
240 } 240 }
241 ; 241 ;
242 242
243 ident : MU_TOK_IDENT 243 ident : MU_TOK_IDENT
244 { 244 {
245 $$.name = $1; 245 $$.name = $1;
246 $$.locus = mu_cfg_locus; 246 $$.locus = mu_cfg_locus;
247 } 247 }
248 ; 248 ;
249 249
250 tag : /* empty */ 250 tag : /* empty */
251 { 251 {
252 $$ = NULL; 252 $$ = NULL;
253 } 253 }
254 | vallist 254 | vallist
255 ; 255 ;
256 256
257 vallist : vlist 257 vallist : vlist
258 { 258 {
259 size_t n = 0; 259 size_t n = 0;
260 mu_list_count($1, &n); 260 mu_list_count($1, &n);
261 if (n == 1) 261 if (n == 1)
...@@ -266,7 +266,7 @@ vallist : vlist ...@@ -266,7 +266,7 @@ vallist : vlist
266 { 266 {
267 size_t i; 267 size_t i;
268 mu_config_value_t val; 268 mu_config_value_t val;
269 269
270 val.type = MU_CFG_ARRAY; 270 val.type = MU_CFG_ARRAY;
271 val.v.arg.c = n; 271 val.v.arg.c = n;
272 /* FIXME: Use mu_opool_alloc */ 272 /* FIXME: Use mu_opool_alloc */
...@@ -276,7 +276,7 @@ vallist : vlist ...@@ -276,7 +276,7 @@ vallist : vlist
276 mu_cfg_perror (&mu_cfg_locus, _("not enough memory")); 276 mu_cfg_perror (&mu_cfg_locus, _("not enough memory"));
277 abort(); 277 abort();
278 } 278 }
279 279
280 for (i = 0; i < n; i++) 280 for (i = 0; i < n; i++)
281 { 281 {
282 mu_config_value_t *v; 282 mu_config_value_t *v;
...@@ -285,7 +285,7 @@ vallist : vlist ...@@ -285,7 +285,7 @@ vallist : vlist
285 } 285 }
286 $$ = config_value_dup (&val); 286 $$ = config_value_dup (&val);
287 } 287 }
288 mu_list_destroy (&$1); 288 mu_list_destroy (&$1);
289 } 289 }
290 ; 290 ;
291 291
...@@ -300,36 +300,36 @@ vlist : value ...@@ -300,36 +300,36 @@ vlist : value
300 } 300 }
301 mu_list_append ($$, config_value_dup (&$1)); /* FIXME */ 301 mu_list_append ($$, config_value_dup (&$1)); /* FIXME */
302 } 302 }
303 | vlist value 303 | vlist value
304 { 304 {
305 mu_list_append ($1, config_value_dup (&$2)); 305 mu_list_append ($1, config_value_dup (&$2));
306 } 306 }
307 ; 307 ;
308 308
309 value : string 309 value : string
310 { 310 {
311 $$.type = MU_CFG_STRING; 311 $$.type = MU_CFG_STRING;
312 $$.v.string = $1; 312 $$.v.string = $1;
313 } 313 }
314 | list 314 | list
315 { 315 {
316 $$.type = MU_CFG_LIST; 316 $$.type = MU_CFG_LIST;
317 $$.v.list = $1; 317 $$.v.list = $1;
318 } 318 }
319 | MU_TOK_MSTRING 319 | MU_TOK_MSTRING
320 { 320 {
321 $$.type = MU_CFG_STRING; 321 $$.type = MU_CFG_STRING;
322 $$.v.string = $1; 322 $$.v.string = $1;
323 } 323 }
324 ; 324 ;
325 325
326 string : MU_TOK_STRING 326 string : MU_TOK_STRING
327 | MU_TOK_IDENT 327 | MU_TOK_IDENT
328 | slist 328 | slist
329 ; 329 ;
330 330
331 slist : slist0 331 slist : slist0
332 { 332 {
333 mu_iterator_t itr; 333 mu_iterator_t itr;
334 mu_list_get_iterator ($1, &itr); 334 mu_list_get_iterator ($1, &itr);
335 335
...@@ -347,48 +347,48 @@ slist : slist0 ...@@ -347,48 +347,48 @@ slist : slist0
347 } 347 }
348 ; 348 ;
349 349
350 slist0 : MU_TOK_QSTRING 350 slist0 : MU_TOK_QSTRING
351 { 351 {
352 mu_list_create (&$$); 352 mu_list_create (&$$);
353 mu_list_append ($$, $1); 353 mu_list_append ($$, $1);
354 } 354 }
355 | slist0 MU_TOK_QSTRING 355 | slist0 MU_TOK_QSTRING
356 { 356 {
357 mu_list_append ($1, $2); 357 mu_list_append ($1, $2);
358 $$ = $1; 358 $$ = $1;
359 } 359 }
360 ; 360 ;
361 361
362 list : '(' values ')' 362 list : '(' values ')'
363 { 363 {
364 $$ = $2; 364 $$ = $2;
365 } 365 }
366 | '(' values ',' ')' 366 | '(' values ',' ')'
367 { 367 {
368 $$ = $2; 368 $$ = $2;
369 } 369 }
370 ; 370 ;
371 371
372 values : value 372 values : value
373 { 373 {
374 mu_list_create (&$$); 374 mu_list_create (&$$);
375 mu_list_append ($$, config_value_dup (&$1)); 375 mu_list_append ($$, config_value_dup (&$1));
376 } 376 }
377 | values ',' value 377 | values ',' value
378 { 378 {
379 mu_list_append ($1, config_value_dup (&$3)); 379 mu_list_append ($1, config_value_dup (&$3));
380 $$ = $1; 380 $$ = $1;
381 } 381 }
382 ; 382 ;
383 383
384 opt_sc : /* empty */ 384 opt_sc : /* empty */
385 | ';' 385 | ';'
386 ; 386 ;
387 387
388 388
389 %% 389 %%
390 390
391 static int 391 static int
392 _cfg_default_printer (void *unused, mu_log_level_t level, const char *str) 392 _cfg_default_printer (void *unused, mu_log_level_t level, const char *str)
393 { 393 {
394 fprintf (stderr, "%s", str); 394 fprintf (stderr, "%s", str);
...@@ -421,7 +421,7 @@ mu_cfg_parse (mu_cfg_tree_t **ptree) ...@@ -421,7 +421,7 @@ mu_cfg_parse (mu_cfg_tree_t **ptree)
421 mu_cfg_tree_t *tree; 421 mu_cfg_tree_t *tree;
422 422
423 mu_cfg_set_debug (); 423 mu_cfg_set_debug ();
424 424
425 _mu_cfg_errcnt = 0; 425 _mu_cfg_errcnt = 0;
426 rc = yyparse (); 426 rc = yyparse ();
427 if (rc == 0 && _mu_cfg_errcnt) 427 if (rc == 0 && _mu_cfg_errcnt)
...@@ -436,7 +436,7 @@ mu_cfg_parse (mu_cfg_tree_t **ptree) ...@@ -436,7 +436,7 @@ mu_cfg_parse (mu_cfg_tree_t **ptree)
436 *ptree = tree; 436 *ptree = tree;
437 return rc; 437 return rc;
438 } 438 }
439 439
440 static int 440 static int
441 _mu_cfg_preorder_recursive (mu_cfg_node_t *node, 441 _mu_cfg_preorder_recursive (mu_cfg_node_t *node,
442 mu_cfg_iter_func_t beg, mu_cfg_iter_func_t end, 442 mu_cfg_iter_func_t beg, mu_cfg_iter_func_t end,
...@@ -456,10 +456,10 @@ _mu_cfg_preorder_recursive (mu_cfg_node_t *node, ...@@ -456,10 +456,10 @@ _mu_cfg_preorder_recursive (mu_cfg_node_t *node,
456 if (end && end (node, data) == MU_CFG_ITER_STOP) 456 if (end && end (node, data) == MU_CFG_ITER_STOP)
457 return MU_CFG_ITER_STOP; 457 return MU_CFG_ITER_STOP;
458 break; 458 break;
459 459
460 case MU_CFG_ITER_SKIP: 460 case MU_CFG_ITER_SKIP:
461 break; 461 break;
462 462
463 case MU_CFG_ITER_STOP: 463 case MU_CFG_ITER_STOP:
464 return MU_CFG_ITER_STOP; 464 return MU_CFG_ITER_STOP;
465 } 465 }
...@@ -500,15 +500,15 @@ _mu_cfg_postorder_recursive(mu_cfg_node_t *node, ...@@ -500,15 +500,15 @@ _mu_cfg_postorder_recursive(mu_cfg_node_t *node,
500 if (end && end (node, data) == MU_CFG_ITER_STOP) 500 if (end && end (node, data) == MU_CFG_ITER_STOP)
501 return MU_CFG_ITER_STOP; 501 return MU_CFG_ITER_STOP;
502 break; 502 break;
503 503
504 case MU_CFG_ITER_SKIP: 504 case MU_CFG_ITER_SKIP:
505 break; 505 break;
506 506
507 case MU_CFG_ITER_STOP: 507 case MU_CFG_ITER_STOP:
508 return MU_CFG_ITER_STOP; 508 return MU_CFG_ITER_STOP;
509 } 509 }
510 break; 510 break;
511 511
512 case mu_cfg_node_param: 512 case mu_cfg_node_param:
513 return beg (node, data); 513 return beg (node, data);
514 } 514 }
...@@ -525,7 +525,7 @@ mu_cfg_postorder (mu_cfg_node_t *node, ...@@ -525,7 +525,7 @@ mu_cfg_postorder (mu_cfg_node_t *node,
525 && mu_cfg_postorder (node->next, beg, end, data) == MU_CFG_ITER_STOP) 525 && mu_cfg_postorder (node->next, beg, end, data) == MU_CFG_ITER_STOP)
526 return 1; 526 return 1;
527 return _mu_cfg_postorder_recursive (node, beg, end, data) 527 return _mu_cfg_postorder_recursive (node, beg, end, data)
528 == MU_CFG_ITER_STOP; 528 == MU_CFG_ITER_STOP;
529 } 529 }
530 530
531 531
...@@ -580,7 +580,7 @@ find_container (mu_list_t list, enum mu_cfg_cont_type type, ...@@ -580,7 +580,7 @@ find_container (mu_list_t list, enum mu_cfg_cont_type type,
580 { 580 {
581 mu_iterator_t iter; 581 mu_iterator_t iter;
582 struct mu_cfg_cont *ret = NULL; 582 struct mu_cfg_cont *ret = NULL;
583 583
584 if (len == 0) 584 if (len == 0)
585 len = strlen (ident); 585 len = strlen (ident);
586 586
...@@ -665,8 +665,8 @@ pop_section (struct scan_tree_data *dat) ...@@ -665,8 +665,8 @@ pop_section (struct scan_tree_data *dat)
665 #define STRTONUM(s, type, base, res, limit, d, loc) \ 665 #define STRTONUM(s, type, base, res, limit, d, loc) \
666 { \ 666 { \
667 type sum = 0; \ 667 type sum = 0; \
668 \ 668 \
669 while (*s) \ 669 for (; *s; s++) \
670 { \ 670 { \
671 type x; \ 671 type x; \
672 \ 672 \
...@@ -690,7 +690,6 @@ pop_section (struct scan_tree_data *dat) ...@@ -690,7 +690,6 @@ pop_section (struct scan_tree_data *dat)
690 return 1; \ 690 return 1; \
691 } \ 691 } \
692 sum = x; \ 692 sum = x; \
693 *s++; \
694 } \ 693 } \
695 res = sum; \ 694 res = sum; \
696 } 695 }
...@@ -736,7 +735,7 @@ pop_section (struct scan_tree_data *dat) ...@@ -736,7 +735,7 @@ pop_section (struct scan_tree_data *dat)
736 const char *s = str; \ 735 const char *s = str; \
737 int sign; \ 736 int sign; \
738 unsigned type limit; \ 737 unsigned type limit; \
739 \ 738 \
740 if (*s == '-') \ 739 if (*s == '-') \
741 { \ 740 { \
742 sign++; \ 741 sign++; \
...@@ -749,7 +748,7 @@ pop_section (struct scan_tree_data *dat) ...@@ -749,7 +748,7 @@ pop_section (struct scan_tree_data *dat)
749 sign = 0; \ 748 sign = 0; \
750 limit = TYPE_MAXIMUM (type); \ 749 limit = TYPE_MAXIMUM (type); \
751 } \ 750 } \
752 \ 751 \
753 STRxTONUM (s, unsigned type, tmpres, limit, d, loc); \ 752 STRxTONUM (s, unsigned type, tmpres, limit, d, loc); \
754 if (*s) \ 753 if (*s) \
755 { \ 754 { \
...@@ -774,7 +773,7 @@ parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -774,7 +773,7 @@ parse_ipv4 (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
774 addr.s_addr = ntohl (addr.s_addr); 773 addr.s_addr = ntohl (addr.s_addr);
775 *res = addr; 774 *res = addr;
776 return 0; 775 return 0;
777 } 776 }
778 777
779 static int 778 static int
780 parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, 779 parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
...@@ -792,11 +791,11 @@ parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -792,11 +791,11 @@ parse_host (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
792 _("cannot resolve hostname `%s'"), 791 _("cannot resolve hostname `%s'"),
793 str); 792 str);
794 return 1; 793 return 1;
795 } 794 }
796 addr.s_addr = ntohl (addr.s_addr); 795 addr.s_addr = ntohl (addr.s_addr);
797 *res = addr; 796 *res = addr;
798 return 0; 797 return 0;
799 } 798 }
800 799
801 static int 800 static int
802 parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, 801 parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
...@@ -806,7 +805,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -806,7 +805,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
806 unsigned long mask; 805 unsigned long mask;
807 char astr[16]; 806 char astr[16];
808 const char *p, *s; 807 const char *p, *s;
809 808
810 p = strchr (str, '/'); 809 p = strchr (str, '/');
811 if (p) 810 if (p)
812 { 811 {
...@@ -867,7 +866,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -867,7 +866,7 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
867 break; 866 break;
868 addr.s_addr = (addr.s_addr << 8) + x; 867 addr.s_addr = (addr.s_addr << 8) + x;
869 } 868 }
870 869
871 if (*p) 870 if (*p)
872 { 871 {
873 _mu_cfg_perror (sdata->tree->debug, locus, 872 _mu_cfg_perror (sdata->tree->debug, locus,
...@@ -877,14 +876,14 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -877,14 +876,14 @@ parse_cidr (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
877 } 876 }
878 877
879 mask = i * 8; 878 mask = i * 8;
880 879
881 addr.s_addr <<= (4 - i) * 8; 880 addr.s_addr <<= (4 - i) * 8;
882 } 881 }
883 882
884 res->addr = addr; 883 res->addr = addr;
885 res->mask = mask; 884 res->mask = mask;
886 return 0; 885 return 0;
887 } 886 }
888 887
889 int 888 int
890 mu_cfg_parse_boolean (const char *str, int *res) 889 mu_cfg_parse_boolean (const char *str, int *res)
...@@ -938,40 +937,40 @@ valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -938,40 +937,40 @@ valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
938 *(char**)tgt = s; 937 *(char**)tgt = s;
939 break; 938 break;
940 } 939 }
941 940
942 case mu_cfg_short: 941 case mu_cfg_short:
943 GETSNUM (val->v.string, short, *(short*)tgt, sdata->tree->debug, locus); 942 GETSNUM (val->v.string, short, *(short*)tgt, sdata->tree->debug, locus);
944 break; 943 break;
945 944
946 case mu_cfg_ushort: 945 case mu_cfg_ushort:
947 GETUNUM (val->v.string, unsigned short, *(unsigned short*)tgt, 946 GETUNUM (val->v.string, unsigned short, *(unsigned short*)tgt,
948 sdata->tree->debug, locus); 947 sdata->tree->debug, locus);
949 break; 948 break;
950 949
951 case mu_cfg_int: 950 case mu_cfg_int:
952 GETSNUM (val->v.string, int, *(int*)tgt, sdata->tree->debug, locus); 951 GETSNUM (val->v.string, int, *(int*)tgt, sdata->tree->debug, locus);
953 break; 952 break;
954 953
955 case mu_cfg_uint: 954 case mu_cfg_uint:
956 GETUNUM (val->v.string, unsigned int, *(unsigned int*)tgt, 955 GETUNUM (val->v.string, unsigned int, *(unsigned int*)tgt,
957 sdata->tree->debug, locus); 956 sdata->tree->debug, locus);
958 break; 957 break;
959 958
960 case mu_cfg_long: 959 case mu_cfg_long:
961 GETSNUM (val->v.string, long, *(long*)tgt, 960 GETSNUM (val->v.string, long, *(long*)tgt,
962 sdata->tree->debug, locus); 961 sdata->tree->debug, locus);
963 break; 962 break;
964 963
965 case mu_cfg_ulong: 964 case mu_cfg_ulong:
966 GETUNUM (val->v.string, unsigned long, *(unsigned long*)tgt, 965 GETUNUM (val->v.string, unsigned long, *(unsigned long*)tgt,
967 sdata->tree->debug, locus); 966 sdata->tree->debug, locus);
968 break; 967 break;
969 968
970 case mu_cfg_size: 969 case mu_cfg_size:
971 GETUNUM (val->v.string, size_t, *(size_t*)tgt, 970 GETUNUM (val->v.string, size_t, *(size_t*)tgt,
972 sdata->tree->debug, locus); 971 sdata->tree->debug, locus);
973 break; 972 break;
974 973
975 case mu_cfg_off: 974 case mu_cfg_off:
976 _mu_cfg_perror (sdata->tree->debug, locus, 975 _mu_cfg_perror (sdata->tree->debug, locus,
977 _("not implemented yet")); 976 _("not implemented yet"));
...@@ -982,22 +981,22 @@ valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus, ...@@ -982,22 +981,22 @@ valcvt (struct scan_tree_data *sdata, const mu_cfg_locus_t *locus,
982 GETUNUM (val->v.string, time_t, *(time_t*)tgt, 981 GETUNUM (val->v.string, time_t, *(time_t*)tgt,
983 sdata->tree->debug, locus); 982 sdata->tree->debug, locus);
984 break; 983 break;
985 984
986 case mu_cfg_bool: 985 case mu_cfg_bool:
987 if (parse_bool (sdata, locus, val->v.string, (int*) tgt)) 986 if (parse_bool (sdata, locus, val->v.string, (int*) tgt))
988 return 1; 987 return 1;
989 break; 988 break;
990 989
991 case mu_cfg_ipv4: 990 case mu_cfg_ipv4:
992 if (parse_ipv4 (sdata, locus, val->v.string, (struct in_addr *)tgt)) 991 if (parse_ipv4 (sdata, locus, val->v.string, (struct in_addr *)tgt))
993 return 1; 992 return 1;
994 break; 993 break;
995 994
996 case mu_cfg_cidr: 995 case mu_cfg_cidr:
997 if (parse_cidr (sdata, locus, val->v.string, (mu_cfg_cidr_t *)tgt)) 996 if (parse_cidr (sdata, locus, val->v.string, (mu_cfg_cidr_t *)tgt))
998 return 1; 997 return 1;
999 break; 998 break;
1000 999
1001 case mu_cfg_host: 1000 case mu_cfg_host:
1002 if (parse_host (sdata, locus, val->v.string, (struct in_addr *)tgt)) 1001 if (parse_host (sdata, locus, val->v.string, (struct in_addr *)tgt))
1003 return 1; 1002 return 1;
...@@ -1060,12 +1059,12 @@ _set_fun (void *item, void *data) ...@@ -1060,12 +1059,12 @@ _set_fun (void *item, void *data)
1060 _("not enough memory")); 1059 _("not enough memory"));
1061 return 1; 1060 return 1;
1062 } 1061 }
1063 1062
1064 if (valcvt (clos->sdata, clos->locus, &tgt, clos->type, val) == 0) 1063 if (valcvt (clos->sdata, clos->locus, &tgt, clos->type, val) == 0)
1065 mu_list_append (clos->list, tgt); 1064 mu_list_append (clos->list, tgt);
1066 return 0; 1065 return 0;
1067 } 1066 }
1068 1067
1069 static int 1068 static int
1070 parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) 1069 parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
1071 { 1070 {
...@@ -1073,7 +1072,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -1073,7 +1072,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
1073 struct set_closure clos; 1072 struct set_closure clos;
1074 struct mu_cfg_param *param = find_param (sdata->list->sec, node->tag, 1073 struct mu_cfg_param *param = find_param (sdata->list->sec, node->tag,
1075 0); 1074 0);
1076 1075
1077 if (!param) 1076 if (!param)
1078 { 1077 {
1079 _mu_cfg_perror (sdata->tree->debug, &node->locus, 1078 _mu_cfg_perror (sdata->tree->debug, &node->locus,
...@@ -1108,7 +1107,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -1108,7 +1107,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
1108 { 1107 {
1109 case MU_CFG_LIST: 1108 case MU_CFG_LIST:
1110 break; 1109 break;
1111 1110
1112 case MU_CFG_STRING: 1111 case MU_CFG_STRING:
1113 { 1112 {
1114 mu_list_t list; 1113 mu_list_t list;
...@@ -1142,7 +1141,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node) ...@@ -1142,7 +1141,7 @@ parse_param (struct scan_tree_data *sdata, const mu_cfg_node_t *node)
1142 } 1141 }
1143 if (param->callback (sdata->tree->debug, tgt, node->label)) 1142 if (param->callback (sdata->tree->debug, tgt, node->label))
1144 return 1; 1143 return 1;
1145 1144
1146 } 1145 }
1147 else 1146 else
1148 return valcvt (sdata, &node->locus, tgt, clos.type, node->label); 1147 return valcvt (sdata, &node->locus, tgt, clos.type, node->label);
...@@ -1156,12 +1155,12 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) ...@@ -1156,12 +1155,12 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
1156 { 1155 {
1157 struct scan_tree_data *sdata = data; 1156 struct scan_tree_data *sdata = data;
1158 struct mu_cfg_section *sec; 1157 struct mu_cfg_section *sec;
1159 1158
1160 switch (node->type) 1159 switch (node->type)
1161 { 1160 {
1162 case mu_cfg_node_undefined: 1161 case mu_cfg_node_undefined:
1163 abort (); 1162 abort ();
1164 1163
1165 case mu_cfg_node_tag: 1164 case mu_cfg_node_tag:
1166 sec = find_subsection (sdata->list->sec, node->tag, 0); 1165 sec = find_subsection (sdata->list->sec, node->tag, 0);
1167 if (!sec) 1166 if (!sec)
...@@ -1185,7 +1184,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) ...@@ -1185,7 +1184,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
1185 { 1184 {
1186 mu_debug_set_locus (sdata->tree->debug, 1185 mu_debug_set_locus (sdata->tree->debug,
1187 node->locus.file ? 1186 node->locus.file ?
1188 node->locus.file : _("unknown file"), 1187 node->locus.file : _("unknown file"),
1189 node->locus.line); 1188 node->locus.line);
1190 if (sec->parser (mu_cfg_section_start, node, 1189 if (sec->parser (mu_cfg_section_start, node,
1191 sec->label, &sec->target, 1190 sec->label, &sec->target,
...@@ -1197,7 +1196,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data) ...@@ -1197,7 +1196,7 @@ _scan_tree_helper (const mu_cfg_node_t *node, void *data)
1197 } 1196 }
1198 push_section(sdata, sec); 1197 push_section(sdata, sec);
1199 break; 1198 break;
1200 1199
1201 case mu_cfg_node_param: 1200 case mu_cfg_node_param:
1202 if (parse_param (sdata, node)) 1201 if (parse_param (sdata, node))
1203 { 1202 {
...@@ -1214,12 +1213,12 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data) ...@@ -1214,12 +1213,12 @@ _scan_tree_end_helper (const mu_cfg_node_t *node, void *data)
1214 { 1213 {
1215 struct scan_tree_data *sdata = data; 1214 struct scan_tree_data *sdata = data;
1216 struct mu_cfg_section *sec; 1215 struct mu_cfg_section *sec;
1217 1216
1218 switch (node->type) 1217 switch (node->type)
1219 { 1218 {
1220 default: 1219 default:
1221 abort (); 1220 abort ();
1222 1221
1223 case mu_cfg_node_tag: 1222 case mu_cfg_node_tag:
1224 sec = pop_section (sdata); 1223 sec = pop_section (sdata);
1225 if (sec && sec->parser) 1224 if (sec && sec->parser)
...@@ -1273,19 +1272,19 @@ mu_cfg_find_section (struct mu_cfg_section *root_sec, ...@@ -1273,19 +1272,19 @@ mu_cfg_find_section (struct mu_cfg_section *root_sec,
1273 struct mu_cfg_section *sec; 1272 struct mu_cfg_section *sec;
1274 size_t len; 1273 size_t len;
1275 const char *p; 1274 const char *p;
1276 1275
1277 while (*path == '/') 1276 while (*path == '/')
1278 path++; 1277 path++;
1279 1278
1280 if (*path == 0) 1279 if (*path == 0)
1281 return MU_ERR_NOENT; 1280 return MU_ERR_NOENT;
1282 1281
1283 p = strchr (path, '/'); 1282 p = strchr (path, '/');
1284 if (p) 1283 if (p)
1285 len = p - path; 1284 len = p - path;
1286 else 1285 else
1287 len = strlen (path); 1286 len = strlen (path);
1288 1287
1289 sec = find_subsection (root_sec, path, len); 1288 sec = find_subsection (root_sec, path, len);
1290 if (!sec) 1289 if (!sec)
1291 return MU_ERR_NOENT; 1290 return MU_ERR_NOENT;
...@@ -1326,7 +1325,7 @@ mu_cfg_tree_create_node (struct mu_cfg_tree *tree, ...@@ -1326,7 +1325,7 @@ mu_cfg_tree_create_node (struct mu_cfg_tree *tree,
1326 mu_cfg_node_t *np; 1325 mu_cfg_node_t *np;
1327 size_t size = sizeof *np + strlen (tag) + 1; 1326 size_t size = sizeof *np + strlen (tag) + 1;
1328 mu_config_value_t val; 1327 mu_config_value_t val;
1329 1328
1330 np = mu_alloc (size); 1329 np = mu_alloc (size);
1331 np->type = type; 1330 np->type = type;
1332 if (loc) 1331 if (loc)
......