dovecot-2.0: doveadm dump: Allow plugins to add more dump types
dovecot at dovecot.org
dovecot at dovecot.org
Wed Nov 3 18:27:10 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/708fd6faca39
changeset: 12377:708fd6faca39
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 03 16:24:31 2010 +0000
description:
doveadm dump: Allow plugins to add more dump types
diffstat:
src/doveadm/doveadm-dump.c | 52 +++++++++++++++++++++++++++++++++++++---------------
src/doveadm/doveadm-dump.h | 5 +++++
src/doveadm/doveadm.c | 3 +++
3 files changed, 45 insertions(+), 15 deletions(-)
diffs (124 lines):
diff -r 97b286b6ec45 -r 708fd6faca39 src/doveadm/doveadm-dump.c
--- a/src/doveadm/doveadm-dump.c Wed Nov 03 15:31:48 2010 +0000
+++ b/src/doveadm/doveadm-dump.c Wed Nov 03 16:24:31 2010 +0000
@@ -1,27 +1,28 @@
-/* Copyright (C) 2004 Joshua Goodall */
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
#include "lib.h"
+#include "array.h"
#include "doveadm.h"
#include "doveadm-dump.h"
#include <stdio.h>
#include <unistd.h>
-static const struct doveadm_cmd_dump *dumps[] = {
- &doveadm_cmd_dump_index,
- &doveadm_cmd_dump_log,
- &doveadm_cmd_dump_mailboxlog,
- &doveadm_cmd_dump_thread
-};
+static ARRAY_DEFINE(dumps, const struct doveadm_cmd_dump *);
+
+void doveadm_dump_register(const struct doveadm_cmd_dump *dump)
+{
+ array_append(&dumps, &dump, 1);
+}
static const struct doveadm_cmd_dump *
dump_find_name(const char *name)
{
- unsigned int i;
+ const struct doveadm_cmd_dump *const *dumpp;
- for (i = 0; i < N_ELEMENTS(dumps); i++) {
- if (strcmp(dumps[i]->name, name) == 0)
- return dumps[i];
+ array_foreach(&dumps, dumpp) {
+ if (strcmp((*dumpp)->name, name) == 0)
+ return *dumpp;
}
return NULL;
}
@@ -29,11 +30,11 @@
static const struct doveadm_cmd_dump *
dump_find_test(const char *path)
{
- unsigned int i;
+ const struct doveadm_cmd_dump *const *dumpp;
- for (i = 0; i < N_ELEMENTS(dumps); i++) {
- if (dumps[i]->test(path))
- return dumps[i];
+ array_foreach(&dumps, dumpp) {
+ if ((*dumpp)->test(path))
+ return *dumpp;
}
return NULL;
}
@@ -76,3 +77,24 @@
struct doveadm_cmd doveadm_cmd_dump = {
cmd_dump, "dump", "[-t <type>] <path>"
};
+
+static const struct doveadm_cmd_dump *dumps_builtin[] = {
+ &doveadm_cmd_dump_index,
+ &doveadm_cmd_dump_log,
+ &doveadm_cmd_dump_mailboxlog,
+ &doveadm_cmd_dump_thread
+};
+
+void doveadm_dump_init(void)
+{
+ unsigned int i;
+
+ i_array_init(&dumps, N_ELEMENTS(dumps_builtin) + 8);
+ for (i = 0; i < N_ELEMENTS(dumps_builtin); i++)
+ doveadm_dump_register(dumps_builtin[i]);
+}
+
+void doveadm_dump_deinit(void)
+{
+ array_free(&dumps);
+}
diff -r 97b286b6ec45 -r 708fd6faca39 src/doveadm/doveadm-dump.h
--- a/src/doveadm/doveadm-dump.h Wed Nov 03 15:31:48 2010 +0000
+++ b/src/doveadm/doveadm-dump.h Wed Nov 03 16:24:31 2010 +0000
@@ -14,4 +14,9 @@
extern struct doveadm_cmd_dump doveadm_cmd_dump_mailboxlog;
extern struct doveadm_cmd_dump doveadm_cmd_dump_thread;
+void doveadm_dump_register(const struct doveadm_cmd_dump *dump);
+
+void doveadm_dump_init(void);
+void doveadm_dump_deinit(void);
+
#endif
diff -r 97b286b6ec45 -r 708fd6faca39 src/doveadm/doveadm.c
--- a/src/doveadm/doveadm.c Wed Nov 03 15:31:48 2010 +0000
+++ b/src/doveadm/doveadm.c Wed Nov 03 16:24:31 2010 +0000
@@ -9,6 +9,7 @@
#include "master-service-settings.h"
#include "settings-parser.h"
#include "doveadm-print-private.h"
+#include "doveadm-dump.h"
#include "doveadm-mail.h"
#include "doveadm-settings.h"
#include "doveadm.h"
@@ -315,6 +316,7 @@
quick_init = FALSE;
doveadm_register_director_commands();
doveadm_register_log_commands();
+ doveadm_dump_init();
doveadm_mail_init();
doveadm_load_modules();
@@ -353,6 +355,7 @@
if (!quick_init) {
doveadm_mail_deinit();
+ doveadm_dump_deinit();
doveadm_unload_modules();
doveadm_print_deinit();
}
More information about the dovecot-cvs
mailing list