]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Added doveadm quota plugin.
authorTimo Sirainen <tss@iki.fi>
Mon, 8 Mar 2010 15:28:48 +0000 (17:28 +0200)
committerTimo Sirainen <tss@iki.fi>
Mon, 8 Mar 2010 15:28:48 +0000 (17:28 +0200)
--HG--
branch : HEAD

src/plugins/quota/Makefile.am
src/plugins/quota/doveadm-quota.c [new file with mode: 0644]
src/plugins/quota/quota-plugin.h

index 3120e659d2e05ab7a97bc31fbfa44a871f3e370d..2ce2034fc8af5b365ba60598667a66202adaf19c 100644 (file)
@@ -1,3 +1,5 @@
+doveadm_moduledir = $(moduledir)/doveadm
+
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib \
        -I$(top_srcdir)/src/lib-dict \
@@ -5,7 +7,8 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib-mail \
        -I$(top_srcdir)/src/lib-storage \
        -I$(top_srcdir)/src/lib-storage/index \
-       -I$(top_srcdir)/src/lib-storage/index/maildir
+       -I$(top_srcdir)/src/lib-storage/index/maildir \
+       -I$(top_srcdir)/src/doveadm
 
 lib10_quota_plugin_la_LDFLAGS = -module -avoid-version
 
@@ -25,6 +28,12 @@ quota_dist_sources = \
 lib10_quota_plugin_la_SOURCES = $(quota_dist_sources)
 nodist_lib10_quota_plugin_la_SOURCES = $(RQUOTA_XDR)
 
+doveadm_module_LTLIBRARIES = \
+       lib10_doveadm_quota_plugin.la
+
+lib10_doveadm_quota_plugin_la_SOURCES = \
+       doveadm-quota.c
+
 if HAVE_RQUOTA
 RQUOTA_XDR = rquota_xdr.c
 #RQUOTA_X = /usr/include/rpcsvc/rquota.x
diff --git a/src/plugins/quota/doveadm-quota.c b/src/plugins/quota/doveadm-quota.c
new file mode 100644 (file)
index 0000000..e31ec5e
--- /dev/null
@@ -0,0 +1,88 @@
+/* Copyright (c) 2005-2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "module-dir.h"
+#include "quota-plugin.h"
+#include "quota-private.h"
+#include "doveadm-mail.h"
+
+#include <stdio.h>
+
+const char *doveadm_quota_plugin_version = DOVECOT_VERSION;
+
+void doveadm_quota_plugin_init(struct module *module);
+void doveadm_quota_plugin_deinit(void);
+
+static void cmd_quota_get_root(struct mail_user *user, struct quota_root *root)
+{
+       const char *const *res;
+       uint64_t value, limit;
+       int ret;
+
+       printf("%s(%s): ", user->username, root->set->name);
+       res = quota_root_get_resources(root);
+       for (; *res != NULL; res++) {
+               ret = quota_get_resource(root, "", *res, &value, &limit);
+               printf("%s %llu/%llu", *res,
+                      (unsigned long long)value,
+                      (unsigned long long)limit);
+               if (res[1] != NULL)
+                       printf(", ");
+       }
+       printf("\n");
+}
+
+static void cmd_quota_get(struct mail_user *user, struct quota *quota)
+{
+       struct quota_root *const *root;
+
+       array_foreach(&quota->roots, root)
+               cmd_quota_get_root(user, *root);
+}
+
+static void cmd_quota_recalc(struct quota *quota)
+{
+       struct quota_root *const *root;
+       struct quota_transaction_context trans;
+
+       memset(&trans, 0, sizeof(trans));
+       trans.quota = quota;
+       trans.recalculate = TRUE;
+
+       array_foreach(&quota->roots, root)
+               (void)(*root)->backend.v.update(*root, &trans);
+}
+
+static void cmd_quota(struct mail_user *user, const char *args[])
+{
+       struct quota_user *quser = QUOTA_USER_CONTEXT(user);
+       struct quota *quota;
+       const char *subcmd = args[0];
+
+       if (subcmd == NULL)
+               doveadm_mail_help_name("quota");
+
+       if (quser == NULL)
+               i_fatal("User has no quota");
+
+       quota = quser->quota;
+       if (strcmp(subcmd, "get") == 0)
+               cmd_quota_get(user, quota);
+       else if (strcmp(subcmd, "recalc") == 0)
+               cmd_quota_recalc(quota);
+       else
+               doveadm_mail_help_name("quota");
+}
+
+static struct doveadm_mail_cmd quota_cmd = {
+       cmd_quota, "quota", "get|recalc"
+};
+
+void doveadm_quota_plugin_init(struct module *module ATTR_UNUSED)
+{
+       doveadm_mail_register_cmd(&quota_cmd);
+}
+
+void doveadm_quota_plugin_deinit(void)
+{
+}
index b2d9d66d17efa80872312905cf2ed2efbcba5636..9ae4faa2bc5c1d669e0f013bb1f8e1b6f0cc691b 100644 (file)
@@ -2,8 +2,10 @@
 #define QUOTA_PLUGIN_H
 
 #include "module-context.h"
+#include "mail-user.h"
 
 struct module;
+struct mailbox;
 
 #define QUOTA_USER_CONTEXT(obj) \
        MODULE_CONTEXT(obj, quota_user_module)