Commit 7dee238e 7dee238ebdc9bd8ec5e67dd995b916399a2122b1 by Sergey Poznyakoff

Implement mu_assoc_foreach function

* include/mailutils/assoc.h (mu_assoc_action_t): New typedef.
(mu_assoc_foreach): New function.
* libmailutils/base/assoc.c (mu_assoc_foreach): New function.
1 parent 622bc770
......@@ -43,6 +43,9 @@ int mu_assoc_remove (mu_assoc_t assoc, const char *name);
int mu_assoc_set_destroy_item (mu_assoc_t assoc, mu_deallocator_t fn);
int mu_assoc_count (mu_assoc_t assoc, size_t *pcount);
typedef int (*mu_assoc_action_t) (char const *, void *, void *);
int mu_assoc_foreach (mu_assoc_t assoc, mu_assoc_action_t action, void *data);
#ifdef __cplusplus
}
#endif
......
......@@ -622,8 +622,6 @@ mu_assoc_get_iterator (mu_assoc_t assoc, mu_iterator_t *piterator)
return 0;
}
int
mu_assoc_count (mu_assoc_t assoc, size_t *pcount)
{
......@@ -644,3 +642,31 @@ mu_assoc_count (mu_assoc_t assoc, size_t *pcount)
return 0;
}
int
mu_assoc_foreach (mu_assoc_t assoc, mu_assoc_action_t action, void *data)
{
mu_iterator_t itr;
int rc;
if (!assoc || !action)
return EINVAL;
rc = mu_assoc_get_iterator (assoc, &itr);
if (rc)
return rc;
for (mu_iterator_first (itr); !mu_iterator_is_done (itr);
mu_iterator_next (itr))
{
char *name;
void *value;
rc = mu_iterator_current_kv (itr, (const void **)&name, (void**)&value);
if (rc)
break;
rc = action (name, value, data);
if (rc)
break;
}
mu_iterator_destroy (&itr);
return rc;
}
......