More fixes to mu_cfg_field_map (see afbb33cf).
* libmailutils/cfg/driver.c (mu_cfg_field_map): Use correct enumeration function depending on the element type. Return meaningful error.
Showing
1 changed file
with
14 additions
and
9 deletions
... | @@ -614,19 +614,14 @@ struct mapping_closure | ... | @@ -614,19 +614,14 @@ struct mapping_closure |
614 | }; | 614 | }; |
615 | 615 | ||
616 | static int | 616 | static int |
617 | parse_mapping (void *item, void *data) | 617 | parse_mapping_str (void *item, void *data) |
618 | { | 618 | { |
619 | struct mapping_closure *clos = data; | 619 | struct mapping_closure *clos = data; |
620 | struct mu_config_value *cval = item; | 620 | char const *str = item; |
621 | char const *str; | ||
622 | size_t len; | 621 | size_t len; |
623 | char *key, *val; | 622 | char *key, *val; |
624 | int rc; | 623 | int rc; |
625 | 624 | ||
626 | if (mu_cfg_assert_value_type (cval, MU_CFG_STRING)) | ||
627 | return 1; | ||
628 | str = cval->v.string; | ||
629 | |||
630 | len = strcspn (str, "="); | 625 | len = strcspn (str, "="); |
631 | if (str[len] == 0) | 626 | if (str[len] == 0) |
632 | { | 627 | { |
... | @@ -644,6 +639,16 @@ parse_mapping (void *item, void *data) | ... | @@ -644,6 +639,16 @@ parse_mapping (void *item, void *data) |
644 | return rc; | 639 | return rc; |
645 | } | 640 | } |
646 | 641 | ||
642 | static int | ||
643 | parse_mapping_val (void *item, void *data) | ||
644 | { | ||
645 | struct mu_config_value *cval = item; | ||
646 | |||
647 | if (mu_cfg_assert_value_type (cval, MU_CFG_STRING)) | ||
648 | return MU_ERR_PARSE; | ||
649 | return parse_mapping_str ((void*) cval->v.string, data); | ||
650 | } | ||
651 | |||
647 | int | 652 | int |
648 | mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, | 653 | mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, |
649 | char **err_term) | 654 | char **err_term) |
... | @@ -665,12 +670,12 @@ mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, | ... | @@ -665,12 +670,12 @@ mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, |
665 | mu_list_set_destroy_item (list, mu_list_free_item); | 670 | mu_list_set_destroy_item (list, mu_list_free_item); |
666 | rc = mu_string_split (val->v.string, ":", list); | 671 | rc = mu_string_split (val->v.string, ":", list); |
667 | if (rc == 0) | 672 | if (rc == 0) |
668 | rc = mu_list_foreach (list, parse_mapping, &clos); | 673 | rc = mu_list_foreach (list, parse_mapping_str, &clos); |
669 | mu_list_destroy (&list); | 674 | mu_list_destroy (&list); |
670 | break; | 675 | break; |
671 | 676 | ||
672 | case MU_CFG_LIST: | 677 | case MU_CFG_LIST: |
673 | rc = mu_list_foreach (val->v.list, parse_mapping, &clos); | 678 | rc = mu_list_foreach (val->v.list, parse_mapping_val, &clos); |
674 | break; | 679 | break; |
675 | 680 | ||
676 | case MU_CFG_ARRAY: | 681 | case MU_CFG_ARRAY: | ... | ... |
-
Please register or sign in to post a comment