# HG changeset patch # User Timo Sirainen # Date 1242925157 14400 # Node ID 43f15920dbaa22c7f80479d474f808a9a6b7f02c # Parent 106e4e3dccbc5e90fbac9df7e81c4cf90f39a5b8 imap code cleanup: Use array instead of buffer for storing fetch handlers. diff -r 106e4e3dccbc -r 43f15920dbaa src/imap/imap-fetch.c --- a/src/imap/imap-fetch.c Thu May 21 12:55:06 2009 -0400 +++ b/src/imap/imap-fetch.c Thu May 21 12:59:17 2009 -0400 @@ -22,7 +22,7 @@ #define ENVELOPE_NIL_REPLY \ "(NIL NIL NIL NIL NIL NIL NIL NIL NIL NIL)" -static buffer_t *fetch_handlers; +static ARRAY_DEFINE(fetch_handlers, struct imap_fetch_handler); static int imap_fetch_handler_cmp(const void *p1, const void *p2) { @@ -34,13 +34,13 @@ void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers, size_t count) { - void *data; - size_t size; + struct imap_fetch_handler *all_handlers; + unsigned int all_count; - buffer_append(fetch_handlers, handlers, sizeof(*handlers) * count); + array_append(&fetch_handlers, handlers, count); - data = buffer_get_modifiable_data(fetch_handlers, &size); - qsort(data, size / sizeof(*handlers), sizeof(*handlers), + all_handlers = array_get_modifiable(&fetch_handlers, &all_count); + qsort(all_handlers, all_count, sizeof(*all_handlers), imap_fetch_handler_cmp); } @@ -64,12 +64,12 @@ bool imap_fetch_init_handler(struct imap_fetch_context *ctx, const char *name, const struct imap_arg **args) { - const struct imap_fetch_handler *handler; + const struct imap_fetch_handler *handler, *handlers; + unsigned int count; - handler = bsearch(name, fetch_handlers->data, - fetch_handlers->used / + handlers = array_get_modifiable(&fetch_handlers, &count); + handler = bsearch(name, handlers, count, sizeof(struct imap_fetch_handler), - sizeof(struct imap_fetch_handler), imap_fetch_handler_bsearch); if (handler == NULL) { client_send_command_error(ctx->cmd, @@ -852,12 +852,12 @@ void imap_fetch_handlers_init(void) { - fetch_handlers = buffer_create_dynamic(default_pool, 128); + i_array_init(&fetch_handlers, 32); imap_fetch_handlers_register(imap_fetch_default_handlers, N_ELEMENTS(imap_fetch_default_handlers)); } void imap_fetch_handlers_deinit(void) { - buffer_free(&fetch_handlers); + array_free(&fetch_handlers); }