Revise associative array API
* configure.ac (VI_REVISION): Increase. * include/mailutils/assoc.h (mu_assoc_create): Change prototype. (mu_assoc_ref,mu_assoc_ref_install) (mu_assoc_remove_ref): Remove. (mu_assoc_get): New proto. (mu_assoc_lookup,mu_assoc_lookup_ref): New proto. (mu_assoc_install_ref): New proto. (mu_assoc_set_free): Remove. (mu_assoc_set_destroy_item): Set proto. * include/mailutils/types.hin (mu_deallocator_t): New typedef. * include/mailutils/list.h (mu_list_destroy_item_t): Change definition. * libmailutils/base/assoc.c: Rewrite. Link all entries in a doubly-linked list to preserve natural ordering during iterations. * libmailutils/base/mutil.c (mutil_parse_field_map): Update calls to assoc API. * libmailutils/cfg/driver.c (alloc_section_tab) (mu_create_canned_section,mu_create_canned_param) (mu_get_canned_container,parse_mapping) (mu_cfg_field_map): Likewise. * libmailutils/mime/mimehdr.c (_mu_mime_param_free): Free the pointer itself. (flush_param,mu_mime_param_assoc_create) (mu_mime_param_assoc_add) (_mime_header_parse) (mu_mimehdr_aget_decoded_param): Update calls to assoc API. (mu_mime_param_free): New function. * libmailutils/property/assocprop.c: Likewise. * libmu_sieve/environment.c: Likewise. * libmu_sieve/variables.c: Likewise. * libproto/imap/id.c: Likewise. * mail/alias.c: Likewise. * mail/testsuite/mail/alias.exp: Update ordering of expected output. * mu/imap.c (com_id): Update. * include/mailutils/mime.h (mu_rfc2047_decode_param): Change prototype. * libmailutils/base/rfc2047.c (mu_rfc2047_decode_param): Allocate returned value, instead of filling an already allocated structure. * libproto/imap/fetch.c: Reflect changes.
Showing
18 changed files
with
201 additions
and
242 deletions
... | @@ -32,7 +32,7 @@ AB_INIT | ... | @@ -32,7 +32,7 @@ AB_INIT |
32 | 32 | ||
33 | dnl Library versioning | 33 | dnl Library versioning |
34 | AC_SUBST(VI_CURRENT, 5) | 34 | AC_SUBST(VI_CURRENT, 5) |
35 | AC_SUBST(VI_REVISION, 1) | 35 | AC_SUBST(VI_REVISION, 2) |
36 | AC_SUBST(VI_AGE, 0) | 36 | AC_SUBST(VI_AGE, 0) |
37 | 37 | ||
38 | dnl Library paths | 38 | dnl Library paths | ... | ... |
... | @@ -28,18 +28,19 @@ extern "C" { | ... | @@ -28,18 +28,19 @@ extern "C" { |
28 | #define MU_ASSOC_COPY_KEY 0x01 | 28 | #define MU_ASSOC_COPY_KEY 0x01 |
29 | #define MU_ASSOC_ICASE 0x02 | 29 | #define MU_ASSOC_ICASE 0x02 |
30 | 30 | ||
31 | typedef void (*mu_assoc_free_fn) (void *data); | 31 | int mu_assoc_create (mu_assoc_t *passoc, int flags); |
32 | |||
33 | int mu_assoc_create (mu_assoc_t *passoc, size_t elsize, int flags); | ||
34 | void mu_assoc_destroy (mu_assoc_t *passoc); | 32 | void mu_assoc_destroy (mu_assoc_t *passoc); |
35 | void mu_assoc_clear (mu_assoc_t assoc); | 33 | void mu_assoc_clear (mu_assoc_t assoc); |
36 | void *mu_assoc_ref (mu_assoc_t assoc, const char *name); | 34 | int mu_assoc_lookup (mu_assoc_t assoc, const char *name, void *dataptr); |
35 | void *mu_assoc_get (mu_assoc_t assoc, const char *name); | ||
37 | int mu_assoc_install (mu_assoc_t assoc, const char *name, void *value); | 36 | int mu_assoc_install (mu_assoc_t assoc, const char *name, void *value); |
38 | int mu_assoc_ref_install (mu_assoc_t assoc, const char *name, void **pval); | 37 | |
38 | int mu_assoc_lookup_ref (mu_assoc_t assoc, const char *name, void *dataptr); | ||
39 | int mu_assoc_install_ref (mu_assoc_t assoc, const char *name, void *pval); | ||
40 | |||
39 | int mu_assoc_get_iterator (mu_assoc_t assoc, mu_iterator_t *piterator); | 41 | int mu_assoc_get_iterator (mu_assoc_t assoc, mu_iterator_t *piterator); |
40 | int mu_assoc_remove_ref (mu_assoc_t assoc, void *data); | ||
41 | int mu_assoc_remove (mu_assoc_t assoc, const char *name); | 42 | int mu_assoc_remove (mu_assoc_t assoc, const char *name); |
42 | int mu_assoc_set_free (mu_assoc_t assoc, mu_assoc_free_fn fn); | 43 | int mu_assoc_set_destroy_item (mu_assoc_t assoc, mu_deallocator_t fn); |
43 | int mu_assoc_count (mu_assoc_t assoc, size_t *pcount); | 44 | int mu_assoc_count (mu_assoc_t assoc, size_t *pcount); |
44 | 45 | ||
45 | #ifdef __cplusplus | 46 | #ifdef __cplusplus | ... | ... |
... | @@ -59,7 +59,7 @@ int mu_list_get_comparator (mu_list_t _list, mu_list_comparator_t *_pcmp); | ... | @@ -59,7 +59,7 @@ int mu_list_get_comparator (mu_list_t _list, mu_list_comparator_t *_pcmp); |
59 | 59 | ||
60 | /* The destroy function is responsible for deallocating a list element. | 60 | /* The destroy function is responsible for deallocating a list element. |
61 | By default, it is not set. */ | 61 | By default, it is not set. */ |
62 | typedef void (*mu_list_destroy_item_t) (void *); | 62 | typedef mu_deallocator_t mu_list_destroy_item_t; |
63 | 63 | ||
64 | /* An often used destroy function. It simply calls free(3) over the | 64 | /* An often used destroy function. It simply calls free(3) over the |
65 | _item. */ | 65 | _item. */ | ... | ... |
... | @@ -57,7 +57,8 @@ int mu_rfc2047_decode (const char *tocode, const char *fromstr, | ... | @@ -57,7 +57,8 @@ int mu_rfc2047_decode (const char *tocode, const char *fromstr, |
57 | int mu_rfc2047_encode (const char *charset, const char *encoding, | 57 | int mu_rfc2047_encode (const char *charset, const char *encoding, |
58 | const char *text, char **result); | 58 | const char *text, char **result); |
59 | int mu_rfc2047_decode_param (const char *tocode, const char *input, | 59 | int mu_rfc2047_decode_param (const char *tocode, const char *input, |
60 | struct mu_mime_param *param); | 60 | struct mu_mime_param **param); |
61 | void mu_mime_param_free (struct mu_mime_param *p); | ||
61 | 62 | ||
62 | int mu_base64_encode (const unsigned char *input, size_t input_len, | 63 | int mu_base64_encode (const unsigned char *input, size_t input_len, |
63 | unsigned char **output, size_t * output_len); | 64 | unsigned char **output, size_t * output_len); | ... | ... |
... | @@ -129,6 +129,10 @@ typedef struct _mu_dbm_file *mu_dbm_file_t; | ... | @@ -129,6 +129,10 @@ typedef struct _mu_dbm_file *mu_dbm_file_t; |
129 | typedef struct _mu_imapio *mu_imapio_t; | 129 | typedef struct _mu_imapio *mu_imapio_t; |
130 | typedef struct _mu_msgset *mu_msgset_t; | 130 | typedef struct _mu_msgset *mu_msgset_t; |
131 | 131 | ||
132 | /* Pointer to a function responsible for freeing the memory resources | ||
133 | allocated for its argument. */ | ||
134 | typedef void (*mu_deallocator_t) (void *); | ||
135 | |||
132 | typedef void (*mu_onexit_t) (void*); | 136 | typedef void (*mu_onexit_t) (void*); |
133 | typedef unsigned int mu_debug_handle_t; | 137 | typedef unsigned int mu_debug_handle_t; |
134 | typedef unsigned int mu_debug_level_t; | 138 | typedef unsigned int mu_debug_level_t; | ... | ... |
This diff is collapsed.
Click to expand it.
... | @@ -29,6 +29,7 @@ | ... | @@ -29,6 +29,7 @@ |
29 | #include <mailutils/errno.h> | 29 | #include <mailutils/errno.h> |
30 | #include <mailutils/nls.h> | 30 | #include <mailutils/nls.h> |
31 | #include <mailutils/assoc.h> | 31 | #include <mailutils/assoc.h> |
32 | #include <mailutils/list.h> | ||
32 | #include <mailutils/stream.h> | 33 | #include <mailutils/stream.h> |
33 | #include <mailutils/sql.h> | 34 | #include <mailutils/sql.h> |
34 | 35 | ||
... | @@ -56,12 +57,6 @@ mu_mh_delim (const char *str) | ... | @@ -56,12 +57,6 @@ mu_mh_delim (const char *str) |
56 | return str[0] == '\n'; | 57 | return str[0] == '\n'; |
57 | } | 58 | } |
58 | 59 | ||
59 | static void | ||
60 | assoc_str_free (void *data) | ||
61 | { | ||
62 | free (data); | ||
63 | } | ||
64 | |||
65 | int | 60 | int |
66 | mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) | 61 | mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) |
67 | { | 62 | { |
... | @@ -91,10 +86,10 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) | ... | @@ -91,10 +86,10 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) |
91 | } | 86 | } |
92 | if (!assoc_tab) | 87 | if (!assoc_tab) |
93 | { | 88 | { |
94 | rc = mu_assoc_create (&assoc_tab, sizeof(char*), 0); | 89 | rc = mu_assoc_create (&assoc_tab, 0); |
95 | if (rc) | 90 | if (rc) |
96 | break; | 91 | break; |
97 | mu_assoc_set_free (assoc_tab, assoc_str_free); | 92 | mu_assoc_set_destroy_item (assoc_tab, mu_list_free_item); |
98 | *passoc_tab = assoc_tab; | 93 | *passoc_tab = assoc_tab; |
99 | } | 94 | } |
100 | *p++ = 0; | 95 | *p++ = 0; |
... | @@ -104,7 +99,7 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) | ... | @@ -104,7 +99,7 @@ mutil_parse_field_map (const char *map, mu_assoc_t *passoc_tab, int *perr) |
104 | rc = errno; | 99 | rc = errno; |
105 | break; | 100 | break; |
106 | } | 101 | } |
107 | rc = mu_assoc_install (assoc_tab, tok, &pptr); | 102 | rc = mu_assoc_install (assoc_tab, tok, pptr); |
108 | if (rc) | 103 | if (rc) |
109 | { | 104 | { |
110 | free (p); | 105 | free (p); | ... | ... |
... | @@ -234,18 +234,23 @@ _rfc2047_decode_param (const char *tocode, const char *input, | ... | @@ -234,18 +234,23 @@ _rfc2047_decode_param (const char *tocode, const char *input, |
234 | 234 | ||
235 | int | 235 | int |
236 | mu_rfc2047_decode_param (const char *tocode, const char *input, | 236 | mu_rfc2047_decode_param (const char *tocode, const char *input, |
237 | struct mu_mime_param *param) | 237 | struct mu_mime_param **param_ptr) |
238 | { | 238 | { |
239 | int rc; | 239 | int rc; |
240 | struct mu_mime_param tmp; | 240 | struct mu_mime_param *p; |
241 | 241 | ||
242 | if (!input) | 242 | if (!input) |
243 | return EINVAL; | 243 | return EINVAL; |
244 | if (!param) | 244 | if (!param_ptr) |
245 | return MU_ERR_OUT_PTR_NULL; | 245 | return MU_ERR_OUT_PTR_NULL; |
246 | rc = _rfc2047_decode_param (tocode, input, &tmp); | 246 | p = malloc (sizeof (*p)); |
247 | if (!p) | ||
248 | return errno; | ||
249 | rc = _rfc2047_decode_param (tocode, input, p); | ||
247 | if (rc == 0) | 250 | if (rc == 0) |
248 | *param = tmp; | 251 | *param_ptr = p; |
252 | else | ||
253 | mu_mime_param_free (p); | ||
249 | return rc; | 254 | return rc; |
250 | } | 255 | } |
251 | 256 | ... | ... |
... | @@ -46,8 +46,7 @@ static void | ... | @@ -46,8 +46,7 @@ static void |
46 | alloc_section_tab () | 46 | alloc_section_tab () |
47 | { | 47 | { |
48 | if (!section_tab) | 48 | if (!section_tab) |
49 | mu_assoc_create (§ion_tab, sizeof (struct mu_cfg_cont **), | 49 | mu_assoc_create (§ion_tab, MU_ASSOC_COPY_KEY); |
50 | MU_ASSOC_COPY_KEY); | ||
51 | } | 50 | } |
52 | 51 | ||
53 | int | 52 | int |
... | @@ -56,7 +55,7 @@ mu_create_canned_section (char *name, struct mu_cfg_section **psection) | ... | @@ -56,7 +55,7 @@ mu_create_canned_section (char *name, struct mu_cfg_section **psection) |
56 | int rc; | 55 | int rc; |
57 | struct mu_cfg_cont **pcont; | 56 | struct mu_cfg_cont **pcont; |
58 | alloc_section_tab (); | 57 | alloc_section_tab (); |
59 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); | 58 | rc = mu_assoc_install_ref (section_tab, name, &pcont); |
60 | if (rc == 0) | 59 | if (rc == 0) |
61 | { | 60 | { |
62 | mu_config_create_container (pcont, mu_cfg_cont_section); | 61 | mu_config_create_container (pcont, mu_cfg_cont_section); |
... | @@ -74,7 +73,7 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) | ... | @@ -74,7 +73,7 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) |
74 | int rc; | 73 | int rc; |
75 | struct mu_cfg_cont **pcont; | 74 | struct mu_cfg_cont **pcont; |
76 | alloc_section_tab (); | 75 | alloc_section_tab (); |
77 | rc = mu_assoc_ref_install (section_tab, name, (void **)&pcont); | 76 | rc = mu_assoc_install_ref (section_tab, name, &pcont); |
78 | if (rc == 0) | 77 | if (rc == 0) |
79 | { | 78 | { |
80 | mu_config_create_container (pcont, mu_cfg_cont_param); | 79 | mu_config_create_container (pcont, mu_cfg_cont_param); |
... | @@ -89,8 +88,7 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) | ... | @@ -89,8 +88,7 @@ mu_create_canned_param (char *name, struct mu_cfg_param **pparam) |
89 | struct mu_cfg_cont * | 88 | struct mu_cfg_cont * |
90 | mu_get_canned_container (const char *name) | 89 | mu_get_canned_container (const char *name) |
91 | { | 90 | { |
92 | struct mu_cfg_cont **pcont = mu_assoc_ref (section_tab, name); | 91 | return mu_assoc_get (section_tab, name); |
93 | return pcont ? *pcont : NULL; | ||
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
... | @@ -615,19 +613,13 @@ parse_mapping (void *item, void *data) | ... | @@ -615,19 +613,13 @@ parse_mapping (void *item, void *data) |
615 | val = mu_strdup (str + len + 1); | 613 | val = mu_strdup (str + len + 1); |
616 | if (!val) | 614 | if (!val) |
617 | return ENOMEM; | 615 | return ENOMEM; |
618 | clos->err = mu_assoc_install (clos->assoc, key, &val); | 616 | clos->err = mu_assoc_install (clos->assoc, key, val); |
619 | free (key); | 617 | free (key); |
620 | if (clos->err) | 618 | if (clos->err) |
621 | return 1; | 619 | return 1; |
622 | return 0; | 620 | return 0; |
623 | } | 621 | } |
624 | 622 | ||
625 | static void | ||
626 | assoc_str_free (void *data) | ||
627 | { | ||
628 | free (data); | ||
629 | } | ||
630 | |||
631 | int | 623 | int |
632 | mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, | 624 | mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, |
633 | char **err_term) | 625 | char **err_term) |
... | @@ -636,10 +628,10 @@ mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, | ... | @@ -636,10 +628,10 @@ mu_cfg_field_map (struct mu_config_value const *val, mu_assoc_t *passoc, |
636 | struct mapping_closure clos; | 628 | struct mapping_closure clos; |
637 | mu_list_t list = NULL; | 629 | mu_list_t list = NULL; |
638 | 630 | ||
639 | rc = mu_assoc_create (&clos.assoc, sizeof(char*), 0); | 631 | rc = mu_assoc_create (&clos.assoc, 0); |
640 | if (rc) | 632 | if (rc) |
641 | return rc; | 633 | return rc; |
642 | mu_assoc_set_free (clos.assoc, assoc_str_free); | 634 | mu_assoc_set_destroy_item (clos.assoc, mu_list_free_item); |
643 | clos.err_term = NULL; | 635 | clos.err_term = NULL; |
644 | 636 | ||
645 | switch (val->type) | 637 | switch (val->type) | ... | ... |
... | @@ -45,12 +45,13 @@ | ... | @@ -45,12 +45,13 @@ |
45 | info */ | 45 | info */ |
46 | 46 | ||
47 | /* Free members of struct mu_mime_param, but do not free it itself. */ | 47 | /* Free members of struct mu_mime_param, but do not free it itself. */ |
48 | static void | 48 | void |
49 | _mu_mime_param_free (struct mu_mime_param *p) | 49 | mu_mime_param_free (struct mu_mime_param *p) |
50 | { | 50 | { |
51 | free (p->lang); | 51 | free (p->lang); |
52 | free (p->cset); | 52 | free (p->cset); |
53 | free (p->value); | 53 | free (p->value); |
54 | free (p); | ||
54 | } | 55 | } |
55 | 56 | ||
56 | /* Treat ITEM as a pointer to struct mu_mime_param and reclaim all | 57 | /* Treat ITEM as a pointer to struct mu_mime_param and reclaim all |
... | @@ -60,7 +61,7 @@ _mu_mime_param_free (struct mu_mime_param *p) | ... | @@ -60,7 +61,7 @@ _mu_mime_param_free (struct mu_mime_param *p) |
60 | static void | 61 | static void |
61 | _mu_mime_param_free_item (void *item) | 62 | _mu_mime_param_free_item (void *item) |
62 | { | 63 | { |
63 | _mu_mime_param_free (item); | 64 | mu_mime_param_free (item); |
64 | } | 65 | } |
65 | 66 | ||
66 | /* Recode a string between two charsets. | 67 | /* Recode a string between two charsets. |
... | @@ -153,31 +154,38 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, | ... | @@ -153,31 +154,38 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, |
153 | const char *outcharset) | 154 | const char *outcharset) |
154 | { | 155 | { |
155 | int rc; | 156 | int rc; |
156 | struct mu_mime_param param, *param_slot = NULL; | 157 | struct mu_mime_param *param, **param_slot; |
157 | mu_off_t size; | 158 | mu_off_t size; |
158 | 159 | ||
159 | if (subset) | 160 | if (subset) |
160 | { | 161 | { |
161 | param_slot = mu_assoc_ref (assoc, cont->param_name); | 162 | rc = mu_assoc_lookup_ref (assoc, cont->param_name, ¶m_slot); |
162 | if (!param_slot) | 163 | if (rc) |
163 | return 0; | 164 | return 0; |
164 | } | 165 | } |
165 | 166 | ||
167 | param = calloc (1, sizeof *param); | ||
168 | if (!param) | ||
169 | return errno; | ||
170 | |||
166 | if (cont->param_lang) | 171 | if (cont->param_lang) |
167 | { | 172 | { |
168 | param.lang = strdup (cont->param_lang); | 173 | param->lang = strdup (cont->param_lang); |
169 | if (!param.lang) | 174 | if (!param->lang) |
175 | { | ||
176 | mu_mime_param_free (param); | ||
170 | return ENOMEM; | 177 | return ENOMEM; |
171 | } | 178 | } |
179 | } | ||
172 | else | 180 | else |
173 | param.lang = NULL; | 181 | param->lang = NULL; |
174 | 182 | ||
175 | if (outcharset || cont->param_cset) | 183 | if (outcharset || cont->param_cset) |
176 | { | 184 | { |
177 | param.cset = strdup (outcharset ? outcharset : cont->param_cset); | 185 | param->cset = strdup (outcharset ? outcharset : cont->param_cset); |
178 | if (!param.cset) | 186 | if (!param->cset) |
179 | { | 187 | { |
180 | free (param.lang); | 188 | mu_mime_param_free (param); |
181 | return ENOMEM; | 189 | return ENOMEM; |
182 | } | 190 | } |
183 | } | 191 | } |
... | @@ -185,23 +193,25 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, | ... | @@ -185,23 +193,25 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, |
185 | rc = mu_stream_size (cont->param_value, &size); | 193 | rc = mu_stream_size (cont->param_value, &size); |
186 | if (rc == 0) | 194 | if (rc == 0) |
187 | { | 195 | { |
188 | param.value = malloc (size + 1); | 196 | param->value = malloc (size + 1); |
189 | if (!param.value) | 197 | if (!param->value) |
198 | { | ||
199 | mu_mime_param_free (param); | ||
190 | rc = ENOMEM; | 200 | rc = ENOMEM; |
191 | } | 201 | } |
202 | } | ||
192 | 203 | ||
193 | if (rc == 0) | 204 | if (rc == 0) |
194 | { | 205 | { |
195 | rc = mu_stream_seek (cont->param_value, 0, MU_SEEK_SET, NULL); | 206 | rc = mu_stream_seek (cont->param_value, 0, MU_SEEK_SET, NULL); |
196 | if (rc == 0) | 207 | if (rc == 0) |
197 | rc = mu_stream_read (cont->param_value, param.value, size, NULL); | 208 | rc = mu_stream_read (cont->param_value, param->value, size, NULL); |
198 | param.value[size] = 0; | 209 | param->value[size] = 0; |
199 | } | 210 | } |
200 | 211 | ||
201 | if (rc) | 212 | if (rc) |
202 | { | 213 | { |
203 | free (param.lang); | 214 | mu_mime_param_free (param); |
204 | free (param.cset); | ||
205 | return rc; | 215 | return rc; |
206 | } | 216 | } |
207 | 217 | ||
... | @@ -209,26 +219,25 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, | ... | @@ -209,26 +219,25 @@ flush_param (struct param_continuation *cont, mu_assoc_t assoc, int subset, |
209 | mu_c_strcasecmp (cont->param_cset, outcharset)) | 219 | mu_c_strcasecmp (cont->param_cset, outcharset)) |
210 | { | 220 | { |
211 | char *tmp; | 221 | char *tmp; |
212 | rc = _recode_string (param.value, cont->param_cset, outcharset, &tmp); | 222 | rc = _recode_string (param->value, cont->param_cset, outcharset, &tmp); |
213 | free (param.value); | 223 | free (param->value); |
214 | if (rc) | 224 | if (rc) |
215 | { | 225 | { |
216 | free (param.lang); | 226 | mu_mime_param_free (param); |
217 | free (param.cset); | ||
218 | return rc; | 227 | return rc; |
219 | } | 228 | } |
220 | param.value = tmp; | 229 | param->value = tmp; |
221 | } | 230 | } |
222 | 231 | ||
223 | if (param_slot) | 232 | if (subset) |
224 | { | 233 | { |
225 | *param_slot = param; | 234 | *param_slot = param; |
226 | } | 235 | } |
227 | else | 236 | else |
228 | { | 237 | { |
229 | rc = mu_assoc_install (assoc, cont->param_name, ¶m); | 238 | rc = mu_assoc_install (assoc, cont->param_name, param); |
230 | if (rc) | 239 | if (rc) |
231 | _mu_mime_param_free (¶m); | 240 | mu_mime_param_free (param); |
232 | } | 241 | } |
233 | 242 | ||
234 | return rc; | 243 | return rc; |
... | @@ -239,10 +248,9 @@ int | ... | @@ -239,10 +248,9 @@ int |
239 | mu_mime_param_assoc_create (mu_assoc_t *paramtab) | 248 | mu_mime_param_assoc_create (mu_assoc_t *paramtab) |
240 | { | 249 | { |
241 | mu_assoc_t assoc; | 250 | mu_assoc_t assoc; |
242 | int rc = mu_assoc_create (&assoc, sizeof (struct mu_mime_param), | 251 | int rc = mu_assoc_create (&assoc, MU_ASSOC_ICASE); |
243 | MU_ASSOC_ICASE); | ||
244 | if (rc == 0) | 252 | if (rc == 0) |
245 | mu_assoc_set_free (assoc, _mu_mime_param_free_item); | 253 | mu_assoc_set_destroy_item (assoc, _mu_mime_param_free_item); |
246 | *paramtab = assoc; | 254 | *paramtab = assoc; |
247 | return rc; | 255 | return rc; |
248 | } | 256 | } |
... | @@ -251,20 +259,7 @@ mu_mime_param_assoc_create (mu_assoc_t *paramtab) | ... | @@ -251,20 +259,7 @@ mu_mime_param_assoc_create (mu_assoc_t *paramtab) |
251 | int | 259 | int |
252 | mu_mime_param_assoc_add (mu_assoc_t assoc, const char *name) | 260 | mu_mime_param_assoc_add (mu_assoc_t assoc, const char *name) |
253 | { | 261 | { |
254 | struct mu_mime_param param; | 262 | return mu_assoc_install (assoc, name, NULL); |
255 | |||
256 | memset (¶m, 0, sizeof param); | ||
257 | return mu_assoc_install (assoc, name, ¶m); | ||
258 | } | ||
259 | |||
260 | /* See FIXME near the end of _mime_header_parse, below. */ | ||
261 | static int | ||
262 | _remove_entry (void *item, void *data) | ||
263 | { | ||
264 | struct mu_mime_param *p = item; | ||
265 | mu_assoc_t assoc = data; | ||
266 | mu_assoc_remove_ref (assoc, p); | ||
267 | return 0; | ||
268 | } | 263 | } |
269 | 264 | ||
270 | /* A working horse of this module. Parses input string, which should | 265 | /* A working horse of this module. Parses input string, which should |
... | @@ -331,7 +326,7 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -331,7 +326,7 @@ _mime_header_parse (const char *text, char **pvalue, |
331 | char *p; | 326 | char *p; |
332 | char *decoded; | 327 | char *decoded; |
333 | int flags = 0; | 328 | int flags = 0; |
334 | struct mu_mime_param param; | 329 | struct mu_mime_param *param; |
335 | 330 | ||
336 | key = ws.ws_wordv[i]; | 331 | key = ws.ws_wordv[i]; |
337 | if (key[0] == ';') | 332 | if (key[0] == ';') |
... | @@ -484,19 +479,20 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -484,19 +479,20 @@ _mime_header_parse (const char *text, char **pvalue, |
484 | } | 479 | } |
485 | else | 480 | else |
486 | { | 481 | { |
482 | struct mu_mime_param *param; | ||
487 | rc = mu_rfc2047_decode_param (outcharset, val, ¶m); | 483 | rc = mu_rfc2047_decode_param (outcharset, val, ¶m); |
488 | if (rc) | 484 | if (rc) |
489 | return rc; | 485 | return rc; |
490 | cset = csetp = param.cset; | 486 | cset = csetp = param->cset; |
491 | lang = langp = param.lang; | 487 | lang = langp = param->lang; |
492 | decoded = param.value; | 488 | decoded = param->value; |
489 | free (param); | ||
493 | } | 490 | } |
494 | val = decoded; | 491 | val = decoded; |
495 | 492 | ||
496 | if (flags & MU_MIMEHDR_MULTILINE) | 493 | if (flags & MU_MIMEHDR_MULTILINE) |
497 | { | 494 | { |
498 | rc = mu_stream_write (cont.param_value, val, strlen (val), | 495 | rc = mu_stream_write (cont.param_value, val, strlen (val), NULL); |
499 | NULL); | ||
500 | free (decoded); | 496 | free (decoded); |
501 | free (csetp); | 497 | free (csetp); |
502 | free (langp); | 498 | free (langp); |
... | @@ -505,18 +501,22 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -505,18 +501,22 @@ _mime_header_parse (const char *text, char **pvalue, |
505 | continue; | 501 | continue; |
506 | } | 502 | } |
507 | 503 | ||
508 | memset (¶m, 0, sizeof (param)); | 504 | param = calloc (1, sizeof (*param)); |
505 | if (!param) | ||
506 | rc = ENOMEM; | ||
507 | else | ||
508 | { | ||
509 | if (lang) | 509 | if (lang) |
510 | { | 510 | { |
511 | param.lang = strdup (lang); | 511 | param->lang = strdup (lang); |
512 | if (!param.lang) | 512 | if (!param->lang) |
513 | rc = ENOMEM; | 513 | rc = ENOMEM; |
514 | else | 514 | else |
515 | { | 515 | { |
516 | param.cset = strdup (cset); | 516 | param->cset = strdup (cset); |
517 | if (!param.cset) | 517 | if (!param->cset) |
518 | { | 518 | { |
519 | free (param.lang); | 519 | free (param->lang); |
520 | rc = ENOMEM; | 520 | rc = ENOMEM; |
521 | } | 521 | } |
522 | } | 522 | } |
... | @@ -524,6 +524,7 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -524,6 +524,7 @@ _mime_header_parse (const char *text, char **pvalue, |
524 | 524 | ||
525 | free (csetp); | 525 | free (csetp); |
526 | free (langp); | 526 | free (langp); |
527 | } | ||
527 | 528 | ||
528 | if (rc) | 529 | if (rc) |
529 | { | 530 | { |
... | @@ -531,27 +532,29 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -531,27 +532,29 @@ _mime_header_parse (const char *text, char **pvalue, |
531 | break; | 532 | break; |
532 | } | 533 | } |
533 | 534 | ||
534 | param.value = strdup (val); | 535 | param->value = strdup (val); |
535 | free (decoded); | 536 | free (decoded); |
536 | if (!param.value) | 537 | if (!param->value) |
537 | { | 538 | { |
538 | _mu_mime_param_free (¶m); | 539 | mu_mime_param_free (param); |
539 | rc = ENOMEM; | 540 | rc = ENOMEM; |
540 | break; | 541 | break; |
541 | } | 542 | } |
542 | 543 | ||
543 | if (subset) | 544 | if (subset) |
544 | { | 545 | { |
545 | struct mu_mime_param *p = mu_assoc_ref (assoc, key); | 546 | struct mu_mime_param **p; |
546 | if (p) | 547 | if (mu_assoc_lookup_ref (assoc, key, &p) == 0) |
547 | *p = param; | 548 | *p = param; |
549 | else | ||
550 | mu_mime_param_free (param); | ||
548 | } | 551 | } |
549 | else | 552 | else |
550 | { | 553 | { |
551 | rc = mu_assoc_install (assoc, key, ¶m); | 554 | rc = mu_assoc_install (assoc, key, param); |
552 | if (rc) | 555 | if (rc) |
553 | { | 556 | { |
554 | _mu_mime_param_free (¶m); | 557 | mu_mime_param_free (param); |
555 | break; | 558 | break; |
556 | } | 559 | } |
557 | } | 560 | } |
... | @@ -574,12 +577,7 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -574,12 +577,7 @@ _mime_header_parse (const char *text, char **pvalue, |
574 | 577 | ||
575 | if (subset) | 578 | if (subset) |
576 | { | 579 | { |
577 | /* Eliminate empty elements. | 580 | /* Eliminate empty elements. */ |
578 | |||
579 | FIXME: What I wanted to do initially is commented out, because | ||
580 | unfortunately iterator_ctl is not defined for assoc tables... | ||
581 | */ | ||
582 | #if 0 | ||
583 | mu_iterator_t itr; | 581 | mu_iterator_t itr; |
584 | 582 | ||
585 | rc = mu_assoc_get_iterator (assoc, &itr); | 583 | rc = mu_assoc_get_iterator (assoc, &itr); |
... | @@ -592,38 +590,11 @@ _mime_header_parse (const char *text, char **pvalue, | ... | @@ -592,38 +590,11 @@ _mime_header_parse (const char *text, char **pvalue, |
592 | struct mu_mime_param *p; | 590 | struct mu_mime_param *p; |
593 | 591 | ||
594 | mu_iterator_current_kv (itr, (const void **)&name, (void**)&p); | 592 | mu_iterator_current_kv (itr, (const void **)&name, (void**)&p); |
595 | if (!p->value) | 593 | if (!p) |
596 | mu_iterator_ctl (itr, mu_itrctl_delete, NULL); | 594 | mu_iterator_ctl (itr, mu_itrctl_delete, NULL); |
597 | } | 595 | } |
598 | mu_iterator_destroy (&itr); | 596 | mu_iterator_destroy (&itr); |
599 | } | 597 | } |
600 | #else | ||
601 | /* ... Instead, the following kludgy approach is taken: */ | ||
602 | mu_iterator_t itr; | ||
603 | mu_list_t elist; | ||
604 | |||
605 | rc = mu_list_create (&elist); | ||
606 | if (rc) | ||
607 | return rc; | ||
608 | rc = mu_assoc_get_iterator (assoc, &itr); | ||
609 | if (rc == 0) | ||
610 | { | ||
611 | for (mu_iterator_first (itr); rc == 0 && !mu_iterator_is_done (itr); | ||
612 | mu_iterator_next (itr)) | ||
613 | { | ||
614 | const char *name; | ||
615 | struct mu_mime_param *p; | ||
616 | |||
617 | mu_iterator_current_kv (itr, (const void **)&name, (void**)&p); | ||
618 | if (!p->value) | ||
619 | rc = mu_list_append (elist, p); | ||
620 | } | ||
621 | mu_iterator_destroy (&itr); | ||
622 | } | ||
623 | if (rc == 0) | ||
624 | mu_list_foreach (elist, _remove_entry, assoc); | ||
625 | mu_list_destroy (&elist); | ||
626 | #endif | ||
627 | } | 598 | } |
628 | 599 | ||
629 | return rc; | 600 | return rc; |
... | @@ -782,7 +753,7 @@ mu_mimehdr_aget_decoded_param (const char *str, const char *name, | ... | @@ -782,7 +753,7 @@ mu_mimehdr_aget_decoded_param (const char *str, const char *name, |
782 | rc = mu_mime_header_parse_subset (str, charset, NULL, assoc); | 753 | rc = mu_mime_header_parse_subset (str, charset, NULL, assoc); |
783 | if (rc == 0) | 754 | if (rc == 0) |
784 | { | 755 | { |
785 | struct mu_mime_param *param = mu_assoc_ref (assoc, name); | 756 | struct mu_mime_param *param = mu_assoc_get (assoc, name); |
786 | if (!param) | 757 | if (!param) |
787 | rc = MU_ERR_NOENT; | 758 | rc = MU_ERR_NOENT; |
788 | else | 759 | else |
... | @@ -852,7 +823,7 @@ _get_attachment_name (mu_message_t msg, const char *charset, | ... | @@ -852,7 +823,7 @@ _get_attachment_name (mu_message_t msg, const char *charset, |
852 | { | 823 | { |
853 | struct mu_mime_param *param; | 824 | struct mu_mime_param *param; |
854 | if (mu_c_strcasecmp (disp, "attachment") == 0 && | 825 | if (mu_c_strcasecmp (disp, "attachment") == 0 && |
855 | (param = mu_assoc_ref (assoc, "filename"))) | 826 | (param = mu_assoc_get (assoc, "filename"))) |
856 | { | 827 | { |
857 | *pbuf = param->value; | 828 | *pbuf = param->value; |
858 | if (psz) | 829 | if (psz) |
... | @@ -893,7 +864,7 @@ _get_attachment_name (mu_message_t msg, const char *charset, | ... | @@ -893,7 +864,7 @@ _get_attachment_name (mu_message_t msg, const char *charset, |
893 | if (ret == 0) | 864 | if (ret == 0) |
894 | { | 865 | { |
895 | struct mu_mime_param *param; | 866 | struct mu_mime_param *param; |
896 | if ((param = mu_assoc_ref (assoc, "name"))) | 867 | if ((param = mu_assoc_get (assoc, "name"))) |
897 | { | 868 | { |
898 | *pbuf = param->value; | 869 | *pbuf = param->value; |
899 | if (psz) | 870 | if (psz) | ... | ... |
... | @@ -25,13 +25,9 @@ | ... | @@ -25,13 +25,9 @@ |
25 | #include <mailutils/assoc.h> | 25 | #include <mailutils/assoc.h> |
26 | #include <mailutils/stream.h> | 26 | #include <mailutils/stream.h> |
27 | #include <mailutils/iterator.h> | 27 | #include <mailutils/iterator.h> |
28 | #include <mailutils/list.h> | ||
28 | #include <stdlib.h> | 29 | #include <stdlib.h> |
29 | 30 | ||
30 | struct property_item | ||
31 | { | ||
32 | char *value; | ||
33 | }; | ||
34 | |||
35 | static void | 31 | static void |
36 | _assoc_prop_done (struct _mu_property *prop) | 32 | _assoc_prop_done (struct _mu_property *prop) |
37 | { | 33 | { |
... | @@ -46,13 +42,13 @@ _assoc_prop_getval (struct _mu_property *prop, | ... | @@ -46,13 +42,13 @@ _assoc_prop_getval (struct _mu_property *prop, |
46 | const char *key, const char **pval) | 42 | const char *key, const char **pval) |
47 | { | 43 | { |
48 | mu_assoc_t assoc = prop->_prop_data; | 44 | mu_assoc_t assoc = prop->_prop_data; |
49 | struct property_item *item; | 45 | char *item; |
50 | 46 | ||
51 | item = mu_assoc_ref (assoc, key); | 47 | item = mu_assoc_get (assoc, key); |
52 | if (item == NULL) | 48 | if (item == NULL) |
53 | return MU_ERR_NOENT; | 49 | return MU_ERR_NOENT; |
54 | if (pval) | 50 | if (pval) |
55 | *pval = item->value; | 51 | *pval = item; |
56 | return 0; | 52 | return 0; |
57 | 53 | ||
58 | } | 54 | } |
... | @@ -62,14 +58,14 @@ _assoc_prop_setval (struct _mu_property *prop, const char *key, | ... | @@ -62,14 +58,14 @@ _assoc_prop_setval (struct _mu_property *prop, const char *key, |
62 | const char *val, int overwrite) | 58 | const char *val, int overwrite) |
63 | { | 59 | { |
64 | mu_assoc_t assoc = prop->_prop_data; | 60 | mu_assoc_t assoc = prop->_prop_data; |
65 | struct property_item *item; | 61 | char **item; |
66 | int rc; | 62 | int rc; |
67 | 63 | ||
68 | rc = mu_assoc_ref_install (assoc, key, (void **)&item); | 64 | rc = mu_assoc_install_ref (assoc, key, &item); |
69 | if (rc == 0) | 65 | if (rc == 0) |
70 | { | 66 | { |
71 | item->value = strdup (val); | 67 | *item = strdup (val); |
72 | if (!item->value) | 68 | if (!*item) |
73 | { | 69 | { |
74 | mu_assoc_remove (assoc, key); | 70 | mu_assoc_remove (assoc, key); |
75 | return ENOMEM; | 71 | return ENOMEM; |
... | @@ -80,8 +76,8 @@ _assoc_prop_setval (struct _mu_property *prop, const char *key, | ... | @@ -80,8 +76,8 @@ _assoc_prop_setval (struct _mu_property *prop, const char *key, |
80 | char *newval = strdup (val); | 76 | char *newval = strdup (val); |
81 | if (!newval) | 77 | if (!newval) |
82 | return ENOMEM; | 78 | return ENOMEM; |
83 | free (item->value); | 79 | free (*item); |
84 | item->value = newval; | 80 | *item = newval; |
85 | } | 81 | } |
86 | else | 82 | else |
87 | return rc; | 83 | return rc; |
... | @@ -105,13 +101,6 @@ _assoc_prop_clear (struct _mu_property *prop) | ... | @@ -105,13 +101,6 @@ _assoc_prop_clear (struct _mu_property *prop) |
105 | } | 101 | } |
106 | 102 | ||
107 | 103 | ||
108 | static void * | ||
109 | _assoc_prop_dataptr (void *in) | ||
110 | { | ||
111 | struct property_item *item = in; | ||
112 | return item->value; | ||
113 | } | ||
114 | |||
115 | static int | 104 | static int |
116 | _assoc_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr) | 105 | _assoc_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr) |
117 | { | 106 | { |
... | @@ -121,20 +110,11 @@ _assoc_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr) | ... | @@ -121,20 +110,11 @@ _assoc_prop_getitr (struct _mu_property *prop, mu_iterator_t *pitr) |
121 | rc = mu_assoc_get_iterator ((mu_assoc_t)prop->_prop_data, &itr); | 110 | rc = mu_assoc_get_iterator ((mu_assoc_t)prop->_prop_data, &itr); |
122 | if (rc) | 111 | if (rc) |
123 | return rc; | 112 | return rc; |
124 | mu_iterator_set_dataptr (itr, _assoc_prop_dataptr); | ||
125 | *pitr = itr; | 113 | *pitr = itr; |
126 | return 0; | 114 | return 0; |
127 | } | 115 | } |
128 | 116 | ||
129 | 117 | ||
130 | static void | ||
131 | prop_free_value (void *data) | ||
132 | { | ||
133 | struct property_item *item = data; | ||
134 | free (item->value); | ||
135 | } | ||
136 | |||
137 | |||
138 | static int | 118 | static int |
139 | _assoc_prop_fill (struct _mu_property *prop) | 119 | _assoc_prop_fill (struct _mu_property *prop) |
140 | { | 120 | { |
... | @@ -201,10 +181,10 @@ mu_assoc_property_init (struct _mu_property *prop) | ... | @@ -201,10 +181,10 @@ mu_assoc_property_init (struct _mu_property *prop) |
201 | mu_assoc_t assoc; | 181 | mu_assoc_t assoc; |
202 | int rc; | 182 | int rc; |
203 | 183 | ||
204 | rc = mu_assoc_create (&assoc, sizeof (struct property_item), 0); | 184 | rc = mu_assoc_create (&assoc, 0); |
205 | if (rc) | 185 | if (rc) |
206 | return rc; | 186 | return rc; |
207 | mu_assoc_set_free (assoc, prop_free_value); | 187 | mu_assoc_set_destroy_item (assoc, mu_list_free_item); |
208 | prop->_prop_data = assoc; | 188 | prop->_prop_data = assoc; |
209 | 189 | ||
210 | prop->_prop_done = _assoc_prop_done; | 190 | prop->_prop_done = _assoc_prop_done; | ... | ... |
... | @@ -179,10 +179,10 @@ mu_sieve_get_environ (mu_sieve_machine_t mach, char const *name, char **retval) | ... | @@ -179,10 +179,10 @@ mu_sieve_get_environ (mu_sieve_machine_t mach, char const *name, char **retval) |
179 | if (!mach->exenv) | 179 | if (!mach->exenv) |
180 | return MU_ERR_NOENT; | 180 | return MU_ERR_NOENT; |
181 | 181 | ||
182 | p = mu_assoc_ref (mach->exenv, name); | 182 | p = mu_assoc_get (mach->exenv, name); |
183 | if (p) | 183 | if (p) |
184 | { | 184 | { |
185 | *retval = strdup (*(char**)p); | 185 | *retval = strdup (p); |
186 | if (!*retval) | 186 | if (!*retval) |
187 | return errno; | 187 | return errno; |
188 | } | 188 | } |
... | @@ -204,11 +204,11 @@ mu_sieve_set_environ (mu_sieve_machine_t mach, char const *name, | ... | @@ -204,11 +204,11 @@ mu_sieve_set_environ (mu_sieve_machine_t mach, char const *name, |
204 | 204 | ||
205 | if (!mach->exenv) | 205 | if (!mach->exenv) |
206 | { | 206 | { |
207 | int rc = mu_assoc_create (&mach->exenv, sizeof (char *), 0); | 207 | int rc = mu_assoc_create (&mach->exenv, 0); |
208 | if (rc) | 208 | if (rc) |
209 | return rc; | 209 | return rc; |
210 | } | 210 | } |
211 | rc = mu_assoc_ref_install (mach->exenv, name, (void **) &pptr); | 211 | rc = mu_assoc_install_ref (mach->exenv, name, &pptr); |
212 | if (rc == 0 || rc == MU_ERR_EXISTS) | 212 | if (rc == 0 || rc == MU_ERR_EXISTS) |
213 | { | 213 | { |
214 | char *copy = strdup (value); | 214 | char *copy = strdup (value); | ... | ... |
... | @@ -166,7 +166,7 @@ sieve_action_set (mu_sieve_machine_t mach) | ... | @@ -166,7 +166,7 @@ sieve_action_set (mu_sieve_machine_t mach) |
166 | size_t i; | 166 | size_t i; |
167 | char *name; | 167 | char *name; |
168 | char *value; | 168 | char *value; |
169 | struct sieve_variable *vptr; | 169 | struct sieve_variable *var, **vptr; |
170 | int rc; | 170 | int rc; |
171 | 171 | ||
172 | mu_sieve_get_arg (mach, 0, SVT_STRING, &name); | 172 | mu_sieve_get_arg (mach, 0, SVT_STRING, &name); |
... | @@ -181,21 +181,29 @@ sieve_action_set (mu_sieve_machine_t mach) | ... | @@ -181,21 +181,29 @@ sieve_action_set (mu_sieve_machine_t mach) |
181 | value = str; | 181 | value = str; |
182 | } | 182 | } |
183 | 183 | ||
184 | rc = mu_assoc_ref_install (mach->vartab, name, (void **)&vptr); | 184 | rc = mu_assoc_install_ref (mach->vartab, name, &vptr); |
185 | switch (rc) | 185 | switch (rc) |
186 | { | 186 | { |
187 | case 0: | 187 | case 0: |
188 | var = malloc (sizeof (*var)); | ||
189 | if (!var) | ||
190 | { | ||
191 | mu_sieve_error (mach, "%s", mu_strerror (errno)); | ||
192 | mu_sieve_abort (mach); | ||
193 | } | ||
194 | *vptr = var; | ||
188 | break; | 195 | break; |
189 | 196 | ||
190 | case MU_ERR_EXISTS: | 197 | case MU_ERR_EXISTS: |
191 | mu_sieve_free (mach, vptr->value); | 198 | var = *vptr; |
199 | mu_sieve_free (mach, var->value); | ||
192 | break; | 200 | break; |
193 | 201 | ||
194 | default: | 202 | default: |
195 | mu_sieve_error (mach, "mu_assoc_ref_install: %s", mu_strerror (rc)); | 203 | mu_sieve_error (mach, "mu_assoc_ref_install: %s", mu_strerror (rc)); |
196 | mu_sieve_abort (mach); | 204 | mu_sieve_abort (mach); |
197 | } | 205 | } |
198 | vptr->value = value; | 206 | var->value = value; |
199 | return 0; | 207 | return 0; |
200 | } | 208 | } |
201 | 209 | ||
... | @@ -354,7 +362,7 @@ mu_i_sv_expand_variables (char const *input, size_t len, | ... | @@ -354,7 +362,7 @@ mu_i_sv_expand_variables (char const *input, size_t len, |
354 | memcpy (name, input, len); | 362 | memcpy (name, input, len); |
355 | name[len] = 0; | 363 | name[len] = 0; |
356 | 364 | ||
357 | var = mu_assoc_ref (mach->vartab, name); | 365 | var = mu_assoc_get (mach->vartab, name); |
358 | 366 | ||
359 | free (name); | 367 | free (name); |
360 | 368 | ||
... | @@ -383,11 +391,10 @@ mu_sieve_require_variables (mu_sieve_machine_t mach) | ... | @@ -383,11 +391,10 @@ mu_sieve_require_variables (mu_sieve_machine_t mach) |
383 | if (mach->vartab) | 391 | if (mach->vartab) |
384 | return 0; | 392 | return 0; |
385 | 393 | ||
386 | rc = mu_assoc_create (&mach->vartab, sizeof (struct sieve_variable), | 394 | rc = mu_assoc_create (&mach->vartab, MU_ASSOC_ICASE); |
387 | MU_ASSOC_ICASE); | ||
388 | if (rc) | 395 | if (rc) |
389 | mu_sieve_error (mach, "mu_assoc_create: %s", mu_strerror (rc)); | 396 | mu_sieve_error (mach, "mu_assoc_create: %s", mu_strerror (rc)); |
390 | 397 | mu_assoc_set_destroy_item (mach->vartab, mu_list_free_item); | |
391 | if (rc == 0) | 398 | if (rc == 0) |
392 | { | 399 | { |
393 | mu_sieve_register_action (mach, "set", sieve_action_set, | 400 | mu_sieve_register_action (mach, "set", sieve_action_set, |
... | @@ -418,11 +425,14 @@ mu_i_sv_copy_variables (mu_sieve_machine_t child, mu_sieve_machine_t parent) | ... | @@ -418,11 +425,14 @@ mu_i_sv_copy_variables (mu_sieve_machine_t child, mu_sieve_machine_t parent) |
418 | { | 425 | { |
419 | const char *name; | 426 | const char *name; |
420 | struct sieve_variable const *val; | 427 | struct sieve_variable const *val; |
421 | struct sieve_variable newval; | 428 | struct sieve_variable *newval; |
422 | 429 | ||
423 | mu_iterator_current_kv (itr, (const void **)&name, (void**)&val); | 430 | mu_iterator_current_kv (itr, (const void **)&name, (void**)&val); |
424 | newval.value = mu_sieve_strdup (child, val->value); | 431 | newval = malloc (sizeof (*newval)); |
425 | mu_assoc_install (child->vartab, name, &newval); | 432 | if (!newval) |
433 | mu_sieve_abort (child); | ||
434 | newval->value = mu_sieve_strdup (child, val->value); | ||
435 | mu_assoc_install (child->vartab, name, newval); | ||
426 | } | 436 | } |
427 | 437 | ||
428 | mu_iterator_destroy (&itr); | 438 | mu_iterator_destroy (&itr); | ... | ... |
... | @@ -362,7 +362,7 @@ static int | ... | @@ -362,7 +362,7 @@ static int |
362 | _map_body_param (void **itmv, size_t itmc, void *call_data) | 362 | _map_body_param (void **itmv, size_t itmc, void *call_data) |
363 | { | 363 | { |
364 | mu_assoc_t assoc = call_data; | 364 | mu_assoc_t assoc = call_data; |
365 | struct mu_mime_param param; | 365 | struct mu_mime_param *param; |
366 | struct imap_list_element *key, *val; | 366 | struct imap_list_element *key, *val; |
367 | int rc; | 367 | int rc; |
368 | 368 | ||
... | @@ -377,12 +377,18 @@ _map_body_param (void **itmv, size_t itmc, void *call_data) | ... | @@ -377,12 +377,18 @@ _map_body_param (void **itmv, size_t itmc, void *call_data) |
377 | rc = mu_rfc2047_decode_param ("UTF-8", val->v.string, ¶m); | 377 | rc = mu_rfc2047_decode_param ("UTF-8", val->v.string, ¶m); |
378 | if (rc) | 378 | if (rc) |
379 | { | 379 | { |
380 | param.lang = param.cset = NULL; | 380 | param = malloc (sizeof (*param)); |
381 | param.value = strdup (val->v.string); | 381 | if (!param) |
382 | if (!param.value) | ||
383 | return ENOMEM; | 382 | return ENOMEM; |
383 | param->lang = param->cset = NULL; | ||
384 | param->value = strdup (val->v.string); | ||
385 | if (!param->value) | ||
386 | { | ||
387 | free (param); | ||
388 | return ENOMEM; | ||
389 | } | ||
384 | } | 390 | } |
385 | return mu_assoc_install (assoc, key->v.string, ¶m); | 391 | return mu_assoc_install (assoc, key->v.string, param); |
386 | } | 392 | } |
387 | 393 | ||
388 | static int | 394 | static int | ... | ... |
... | @@ -27,22 +27,19 @@ | ... | @@ -27,22 +27,19 @@ |
27 | #include <mailutils/imap.h> | 27 | #include <mailutils/imap.h> |
28 | #include <mailutils/sys/imap.h> | 28 | #include <mailutils/sys/imap.h> |
29 | 29 | ||
30 | void | ||
31 | _id_free (void *data) | ||
32 | { | ||
33 | char *s = *(char**)data; | ||
34 | free (s); | ||
35 | } | ||
36 | |||
37 | static int | 30 | static int |
38 | _id_mapper (void **itmv, size_t itmc, void *call_data) | 31 | _id_mapper (void **itmv, size_t itmc, void *call_data) |
39 | { | 32 | { |
40 | int rc; | 33 | int rc; |
34 | char *copy; | ||
41 | mu_assoc_t assoc = call_data; | 35 | mu_assoc_t assoc = call_data; |
42 | struct imap_list_element *key = itmv[0], *val = itmv[1]; | 36 | struct imap_list_element *key = itmv[0], *val = itmv[1]; |
43 | if (key->type != imap_eltype_string || val->type != imap_eltype_string) | 37 | if (key->type != imap_eltype_string || val->type != imap_eltype_string) |
44 | return MU_ERR_FAILURE; | 38 | return MU_ERR_FAILURE; |
45 | rc = mu_assoc_install (assoc, key->v.string, &val->v.string); | 39 | copy = strdup (val->v.string); |
40 | if (!copy) | ||
41 | return errno; | ||
42 | rc = mu_assoc_install (assoc, key->v.string, copy); | ||
46 | if (rc == 0) | 43 | if (rc == 0) |
47 | val->v.string = NULL; | 44 | val->v.string = NULL; |
48 | return rc; | 45 | return rc; |
... | @@ -52,10 +49,10 @@ static mu_assoc_t | ... | @@ -52,10 +49,10 @@ static mu_assoc_t |
52 | create_id_assoc (void) | 49 | create_id_assoc (void) |
53 | { | 50 | { |
54 | mu_assoc_t assoc; | 51 | mu_assoc_t assoc; |
55 | int rc = mu_assoc_create (&assoc, sizeof (char**), MU_ASSOC_ICASE); | 52 | int rc = mu_assoc_create (&assoc, MU_ASSOC_ICASE); |
56 | if (rc) | 53 | if (rc) |
57 | return NULL; | 54 | return NULL; |
58 | mu_assoc_set_free (assoc, _id_free); | 55 | mu_assoc_set_destroy_item (assoc, mu_list_free_item); |
59 | return assoc; | 56 | return assoc; |
60 | } | 57 | } |
61 | 58 | ... | ... |
... | @@ -17,34 +17,27 @@ | ... | @@ -17,34 +17,27 @@ |
17 | 17 | ||
18 | #include "mail.h" | 18 | #include "mail.h" |
19 | 19 | ||
20 | typedef struct _alias *alias_t; | ||
21 | |||
22 | struct _alias | ||
23 | { | ||
24 | mu_list_t list; | ||
25 | }; | ||
26 | |||
27 | static mu_assoc_t aliases; | 20 | static mu_assoc_t aliases; |
28 | 21 | ||
29 | static void | 22 | static void |
30 | alias_free (void *data) | 23 | alias_free (void *data) |
31 | { | 24 | { |
32 | alias_t al = data; | 25 | mu_list_t al = data; |
33 | util_slist_destroy (&al->list); | 26 | util_slist_destroy (&al); |
34 | } | 27 | } |
35 | 28 | ||
36 | static void | 29 | static void |
37 | alias_print_group (const char *name, alias_t al) | 30 | alias_print_group (const char *name, mu_list_t al) |
38 | { | 31 | { |
39 | mu_printf ("%s ", name); | 32 | mu_printf ("%s ", name); |
40 | util_slist_print (al->list, 0); | 33 | util_slist_print (al, 0); |
41 | mu_printf ("\n"); | 34 | mu_printf ("\n"); |
42 | } | 35 | } |
43 | 36 | ||
44 | static alias_t | 37 | static mu_list_t |
45 | alias_lookup (const char *name) | 38 | alias_lookup (const char *name) |
46 | { | 39 | { |
47 | return mu_assoc_ref (aliases, name); | 40 | return mu_assoc_get (aliases, name); |
48 | } | 41 | } |
49 | 42 | ||
50 | static void | 43 | static void |
... | @@ -62,7 +55,7 @@ alias_print (char *name) | ... | @@ -62,7 +55,7 @@ alias_print (char *name) |
62 | mu_iterator_next (itr)) | 55 | mu_iterator_next (itr)) |
63 | { | 56 | { |
64 | const char *name; | 57 | const char *name; |
65 | alias_t al; | 58 | mu_list_t al; |
66 | if (mu_iterator_current_kv (itr, (const void **)&name, (void**)&al)) | 59 | if (mu_iterator_current_kv (itr, (const void **)&name, (void**)&al)) |
67 | continue; | 60 | continue; |
68 | alias_print_group (name, al); | 61 | alias_print_group (name, al); |
... | @@ -70,7 +63,7 @@ alias_print (char *name) | ... | @@ -70,7 +63,7 @@ alias_print (char *name) |
70 | } | 63 | } |
71 | else | 64 | else |
72 | { | 65 | { |
73 | alias_t al; | 66 | mu_list_t al; |
74 | 67 | ||
75 | al = alias_lookup (name); | 68 | al = alias_lookup (name); |
76 | if (!al) | 69 | if (!al) |
... | @@ -83,21 +76,25 @@ alias_print (char *name) | ... | @@ -83,21 +76,25 @@ alias_print (char *name) |
83 | } | 76 | } |
84 | 77 | ||
85 | static int | 78 | static int |
86 | alias_create (const char *name, alias_t *al) | 79 | alias_create (const char *name, mu_list_t *al) |
87 | { | 80 | { |
88 | int rc; | 81 | int rc; |
82 | mu_list_t l; | ||
89 | 83 | ||
90 | if (!aliases) | 84 | if (!aliases) |
91 | { | 85 | { |
92 | mu_assoc_create (&aliases, sizeof (struct _alias), 0); | 86 | mu_assoc_create (&aliases, 0); |
93 | mu_assoc_set_free (aliases, alias_free); | 87 | mu_assoc_set_destroy_item (aliases, alias_free); |
94 | } | 88 | } |
95 | 89 | if (mu_assoc_lookup_ref (aliases, name, al)) | |
96 | rc = mu_assoc_ref_install (aliases, name, (void**) al); | 90 | { |
97 | if (rc == MU_ERR_EXISTS) | 91 | rc = mu_list_create (&l); |
92 | if (rc) | ||
93 | return rc; | ||
94 | mu_assoc_install (aliases, name, l); | ||
95 | *al = l; | ||
98 | return 0; | 96 | return 0; |
99 | if (rc == 0) | 97 | } |
100 | return mu_list_create (&(*al)->list); | ||
101 | return 1; | 98 | return 1; |
102 | } | 99 | } |
103 | 100 | ||
... | @@ -111,7 +108,7 @@ alias_destroy (const char *name) | ... | @@ -111,7 +108,7 @@ alias_destroy (const char *name) |
111 | static void | 108 | static void |
112 | recursive_alias_expand (const char *name, mu_list_t exlist, mu_list_t origlist) | 109 | recursive_alias_expand (const char *name, mu_list_t exlist, mu_list_t origlist) |
113 | { | 110 | { |
114 | alias_t al; | 111 | mu_list_t al; |
115 | mu_iterator_t itr; | 112 | mu_iterator_t itr; |
116 | 113 | ||
117 | if ((al = alias_lookup (name)) == NULL) | 114 | if ((al = alias_lookup (name)) == NULL) |
... | @@ -121,7 +118,7 @@ recursive_alias_expand (const char *name, mu_list_t exlist, mu_list_t origlist) | ... | @@ -121,7 +118,7 @@ recursive_alias_expand (const char *name, mu_list_t exlist, mu_list_t origlist) |
121 | return; | 118 | return; |
122 | } | 119 | } |
123 | 120 | ||
124 | mu_list_get_iterator (al->list, &itr); | 121 | mu_list_get_iterator (al, &itr); |
125 | for (mu_iterator_first (itr); | 122 | for (mu_iterator_first (itr); |
126 | !mu_iterator_is_done (itr); | 123 | !mu_iterator_is_done (itr); |
127 | mu_iterator_next (itr)) | 124 | mu_iterator_next (itr)) |
... | @@ -148,7 +145,7 @@ string_comp (const void *item, const void *value) | ... | @@ -148,7 +145,7 @@ string_comp (const void *item, const void *value) |
148 | char * | 145 | char * |
149 | alias_expand (const char *name) | 146 | alias_expand (const char *name) |
150 | { | 147 | { |
151 | alias_t al; | 148 | mu_list_t al; |
152 | mu_list_t list; | 149 | mu_list_t list; |
153 | 150 | ||
154 | if (mailvar_get (NULL, "recursivealiases", mailvar_type_boolean, 0) == 0) | 151 | if (mailvar_get (NULL, "recursivealiases", mailvar_type_boolean, 0) == 0) |
... | @@ -180,7 +177,7 @@ alias_expand (const char *name) | ... | @@ -180,7 +177,7 @@ alias_expand (const char *name) |
180 | 177 | ||
181 | if ((al = alias_lookup (name)) == NULL) | 178 | if ((al = alias_lookup (name)) == NULL) |
182 | return NULL; | 179 | return NULL; |
183 | return util_slist_to_string (al->list, ","); | 180 | return util_slist_to_string (al, ","); |
184 | } | 181 | } |
185 | 182 | ||
186 | 183 | ||
... | @@ -198,7 +195,7 @@ alias_iterate_next (alias_iterator_t atr) | ... | @@ -198,7 +195,7 @@ alias_iterate_next (alias_iterator_t atr) |
198 | while (!mu_iterator_is_done (atr->itr)) | 195 | while (!mu_iterator_is_done (atr->itr)) |
199 | { | 196 | { |
200 | const char *name; | 197 | const char *name; |
201 | alias_t al; | 198 | mu_list_t al; |
202 | 199 | ||
203 | if (mu_iterator_current_kv (atr->itr, (const void **)&name, (void**)&al)) | 200 | if (mu_iterator_current_kv (atr->itr, (const void **)&name, (void**)&al)) |
204 | continue; | 201 | continue; |
... | @@ -259,7 +256,7 @@ mail_alias (int argc, char **argv) | ... | @@ -259,7 +256,7 @@ mail_alias (int argc, char **argv) |
259 | alias_print (argv[1]); | 256 | alias_print (argv[1]); |
260 | else | 257 | else |
261 | { | 258 | { |
262 | alias_t al; | 259 | mu_list_t al; |
263 | 260 | ||
264 | if (alias_create (argv[1], &al)) | 261 | if (alias_create (argv[1], &al)) |
265 | return 1; | 262 | return 1; |
... | @@ -267,7 +264,7 @@ mail_alias (int argc, char **argv) | ... | @@ -267,7 +264,7 @@ mail_alias (int argc, char **argv) |
267 | argc--; | 264 | argc--; |
268 | argv++; | 265 | argv++; |
269 | while (--argc) | 266 | while (--argc) |
270 | util_slist_add (&al->list, *++argv); | 267 | util_slist_add (&al, *++argv); |
271 | } | 268 | } |
272 | return 0; | 269 | return 0; |
273 | } | 270 | } | ... | ... |
... | @@ -24,13 +24,13 @@ mail_test -message "alias staff" "alias" \ | ... | @@ -24,13 +24,13 @@ mail_test -message "alias staff" "alias" \ |
24 | 24 | ||
25 | mail_command "alias teeparty alice march.hare hatter" | 25 | mail_command "alias teeparty alice march.hare hatter" |
26 | mail_test -message "alias teeparty" "alias" \ | 26 | mail_test -message "alias teeparty" "alias" \ |
27 | "teeparty alice march.hare hatter"\ | 27 | "staff alice tweedledum tweedledee" \ |
28 | "staff alice tweedledum tweedledee" | 28 | "teeparty alice march.hare hatter" |
29 | 29 | ||
30 | mail_command "alias messengers haigha hatta" | 30 | mail_command "alias messengers haigha hatta" |
31 | mail_test -message "alias messengers" "alias" \ | 31 | mail_test -message "alias messengers" "alias" \ |
32 | "teeparty alice march.hare hatter"\ | 32 | "staff alice tweedledum tweedledee" \ |
33 | "staff alice tweedledum tweedledee"\ | 33 | "teeparty alice march.hare hatter" \ |
34 | "messengers haigha hatta" | 34 | "messengers haigha hatta" |
35 | 35 | ||
36 | mail_command "unalias teeparty" | 36 | mail_command "unalias teeparty" |
... | @@ -46,9 +46,9 @@ mail_test -message "alias teeparty output" \ | ... | @@ -46,9 +46,9 @@ mail_test -message "alias teeparty output" \ |
46 | 46 | ||
47 | mail_command "alias pretenders lion unicorn" | 47 | mail_command "alias pretenders lion unicorn" |
48 | mail_test -message "alias pretenders" "alias"\ | 48 | mail_test -message "alias pretenders" "alias"\ |
49 | "pretenders lion unicorn "\ | ||
50 | "staff alice tweedledum tweedledee"\ | 49 | "staff alice tweedledum tweedledee"\ |
51 | "messengers haigha hatta" | 50 | "messengers haigha hatta"\ |
51 | "pretenders lion unicorn" | ||
52 | 52 | ||
53 | mail_stop | 53 | mail_stop |
54 | 54 | ... | ... |
... | @@ -755,10 +755,10 @@ com_id (int argc, char **argv) | ... | @@ -755,10 +755,10 @@ com_id (int argc, char **argv) |
755 | { | 755 | { |
756 | if (test) | 756 | if (test) |
757 | { | 757 | { |
758 | void *res = mu_assoc_ref (assoc, test); | 758 | char *val = mu_assoc_get (assoc, test); |
759 | if (res) | 759 | if (val) |
760 | { | 760 | { |
761 | mu_printf ("%s: %s\n", test, *(char **)res); | 761 | mu_printf ("%s: %s\n", test, val); |
762 | } | 762 | } |
763 | else | 763 | else |
764 | mu_printf (_("%s is not set\n"), test); | 764 | mu_printf (_("%s is not set\n"), test); |
... | @@ -772,10 +772,10 @@ com_id (int argc, char **argv) | ... | @@ -772,10 +772,10 @@ com_id (int argc, char **argv) |
772 | !mu_iterator_is_done (itr); mu_iterator_next (itr)) | 772 | !mu_iterator_is_done (itr); mu_iterator_next (itr)) |
773 | { | 773 | { |
774 | char *key; | 774 | char *key; |
775 | void *val; | 775 | char *val; |
776 | 776 | ||
777 | mu_iterator_current_kv (itr, (const void**)&key, &val); | 777 | mu_iterator_current_kv (itr, (const void**)&key, (void**)&val); |
778 | mu_printf ("ID: %s %s\n", key, *(char**)val); | 778 | mu_printf ("ID: %s %s\n", key, val); |
779 | } | 779 | } |
780 | mu_iterator_destroy (&itr); | 780 | mu_iterator_destroy (&itr); |
781 | } | 781 | } | ... | ... |
-
Please register or sign in to post a comment