#include "mail-storage-hooks.h"
#include "quota-plugin.h"
+void quota_backends_register(void);
+void quota_backends_unregister(void);
const char *quota_plugin_version = DOVECOT_ABI_VERSION;
void quota_plugin_init(struct module *module)
{
mail_storage_hooks_add(module, "a_mail_storage_hooks);
+ quota_backends_register();
}
void quota_plugin_deinit(void)
{
mail_storage_hooks_remove("a_mail_storage_hooks);
+ quota_backends_unregister();
}
extern struct quota_backend quota_backend_fs;
extern struct quota_backend quota_backend_maildir;
-static const struct quota_backend *quota_backends[] = {
+static const struct quota_backend *quota_internal_backends[] = {
#ifdef HAVE_FS_QUOTA
"a_backend_fs,
#endif
"a_backend_maildir
};
+static ARRAY(const struct quota_backend*) quota_backends;
+
static enum quota_alloc_result quota_default_test_alloc(
struct quota_transaction_context *ctx, uoff_t size);
static void quota_over_flag_check_root(struct quota_root *root);
static const struct quota_backend *quota_backend_find(const char *name)
{
- unsigned int i;
+ const struct quota_backend *const *backend;
- for (i = 0; i < N_ELEMENTS(quota_backends); i++) {
- if (strcmp(quota_backends[i]->name, name) == 0)
- return quota_backends[i];
+ array_foreach("a_backends, backend) {
+ if (strcmp((*backend)->name, name) == 0)
+ return *backend;
}
return NULL;
}
+void quota_backend_register(const struct quota_backend *backend)
+{
+ i_assert(quota_backend_find(backend->name) == NULL);
+ array_append("a_backends, &backend, 1);
+}
+
+void quota_backend_unregister(const struct quota_backend *backend)
+{
+ for(unsigned int i = 0; i < array_count("a_backends); i++) {
+ const struct quota_backend *const *be =
+ array_idx("a_backends, i);
+ if (strcmp((*be)->name, backend->name) == 0) {
+ array_delete("a_backends, i, 1);
+ return;
+ }
+ }
+
+ i_unreached();
+}
+
+void quota_backends_register(void);
+void quota_backends_unregister(void);
+
+void quota_backends_register(void)
+{
+ i_array_init("a_backends, 8);
+ array_append("a_backends, quota_internal_backends,
+ N_ELEMENTS(quota_internal_backends));
+}
+
+void quota_backends_unregister(void)
+{
+ for(size_t i = 0; i < N_ELEMENTS(quota_internal_backends); i++) {
+ quota_backend_unregister(quota_internal_backends[i]);
+ }
+
+ i_assert(array_count("a_backends) == 0);
+ array_free("a_backends);
+
+}
+
static int quota_root_add_rules(struct mail_user *user, const char *root_name,
struct quota_root_settings *root_set,
const char **error_r)