[dovecot-cvs] dovecot/src/lib-storage mail-storage.c,1.38,1.39
cras at dovecot.org
cras at dovecot.org
Fri Apr 8 18:17:53 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib-storage
In directory talvi:/tmp/cvs-serv27119/lib-storage
Modified Files:
mail-storage.c
Log Message:
Linked list -> array
Index: mail-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/mail-storage.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -d -r1.38 -r1.39
--- mail-storage.c 3 Apr 2005 11:36:15 -0000 1.38
+++ mail-storage.c 8 Apr 2005 15:17:51 -0000 1.39
@@ -13,59 +13,54 @@
"Internal error occured. Refer to server log for more information."
#define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
-struct mail_storage_list {
- struct mail_storage_list *next;
- struct mail_storage *storage;
-};
-
unsigned int mail_storage_module_id = 0;
-static struct mail_storage_list *storages = NULL;
+static array_t ARRAY_DEFINE(storages, struct mail_storage *);
void mail_storage_init(void)
{
+ ARRAY_CREATE(&storages, default_pool, struct mail_storage *, 8);
}
void mail_storage_deinit(void)
{
- struct mail_storage_list *next;
-
- while (storages != NULL) {
- next = storages->next;
-
- i_free(storages);
- storages = next;
- }
+ if (array_is_created(&storages))
+ array_free(&storages);
}
void mail_storage_class_register(struct mail_storage *storage_class)
{
- struct mail_storage_list *list, **pos;
-
- list = i_new(struct mail_storage_list, 1);
- list->storage = storage_class;
-
/* append it after the list, so the autodetection order is correct */
- pos = &storages;
- while (*pos != NULL)
- pos = &(*pos)->next;
- *pos = list;
+ array_append(&storages, &storage_class, 1);
}
void mail_storage_class_unregister(struct mail_storage *storage_class)
{
- struct mail_storage_list **list, *next;
+ struct mail_storage *const *classes;
+ unsigned int i, count;
- for (list = &storages; *list != NULL; list = &(*list)->next) {
- if ((*list)->storage == storage_class) {
- next = (*list)->next;
+ classes = array_get(&storages, &count);
+ for (i = 0; i < count; i++) {
+ if (classes[i] == storage_class) {
+ array_delete(&storages, i, 1);
+ break;
+ }
+ }
+}
- mail_storage_destroy((*list)->storage);
- i_free(*list);
+static struct mail_storage *mail_storage_find(const char *name)
+{
+ struct mail_storage *const *classes;
+ unsigned int i, count;
- *list = next;
- }
+ i_assert(name != NULL);
+
+ classes = array_get(&storages, &count);
+ for (i = 0; i < count; i++) {
+ if (strcasecmp(classes[i]->name, name) == 0)
+ return classes[i];
}
+ return NULL;
}
struct mail_storage *
@@ -73,46 +68,43 @@
enum mail_storage_flags flags,
enum mail_storage_lock_method lock_method)
{
- struct mail_storage_list *list;
-
- i_assert(name != NULL);
-
- for (list = storages; list != NULL; list = list->next) {
- if (strcasecmp(list->storage->name, name) == 0)
- return list->storage->v.create(data, user, flags,
- lock_method);
- }
+ struct mail_storage *storage;
- return NULL;
+ storage = mail_storage_find(name);
+ if (storage != NULL)
+ return storage->v.create(data, user, flags, lock_method);
+ else
+ return NULL;
}
struct mail_storage *
mail_storage_create_default(const char *user, enum mail_storage_flags flags,
enum mail_storage_lock_method lock_method)
{
- struct mail_storage_list *list;
+ struct mail_storage *const *classes;
struct mail_storage *storage;
+ unsigned int i, count;
- for (list = storages; list != NULL; list = list->next) {
- storage = list->storage->v.create(NULL, user, flags,
- lock_method);
+ classes = array_get(&storages, &count);
+ for (i = 0; i < count; i++) {
+ storage = classes[i]->v.create(NULL, user, flags, lock_method);
if (storage != NULL)
return storage;
}
-
return NULL;
}
static struct mail_storage *
mail_storage_autodetect(const char *data, enum mail_storage_flags flags)
{
- struct mail_storage_list *list;
+ struct mail_storage *const *classes;
+ unsigned int i, count;
- for (list = storages; list != NULL; list = list->next) {
- if (list->storage->v.autodetect(data, flags))
- return list->storage;
+ classes = array_get(&storages, &count);
+ for (i = 0; i < count; i++) {
+ if (classes[i]->v.autodetect(data, flags))
+ return classes[i];
}
-
return NULL;
}
More information about the dovecot-cvs
mailing list