]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: Cleanup - split quota_over_flag to init & run parts
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 15:58:53 +0000 (18:58 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 29 Apr 2016 16:25:23 +0000 (19:25 +0300)
In preparation for the next change.

src/plugins/quota/quota-private.h
src/plugins/quota/quota-storage.c
src/plugins/quota/quota.c
src/plugins/quota/quota.h

index 5f3e1100ab46697d2eae393fecfa5d2a49a4bb3d..f1e7a2e1b71eab5dfe9acec45f83b067abb4aa41 100644 (file)
@@ -131,6 +131,10 @@ struct quota_root {
        /* Module-specific contexts. See quota_module_id. */
        ARRAY(void) quota_module_contexts;
 
+       /* Set to the current quota_over_flag, regardless of whether
+          it matches quota_over_flag_value mask. */
+       const char *quota_over_flag;
+
        /* don't enforce quota when saving */
        unsigned int no_enforcing:1;
        /* If user has unlimited quota, disable quota tracking */
@@ -139,6 +143,8 @@ struct quota_root {
        unsigned int recounting:1;
        /* Quota root is hidden (to e.g. IMAP GETQUOTAROOT) */
        unsigned int hidden:1;
+       /* Is user currently over quota? */
+       unsigned int quota_over_flag_status:1;
 };
 
 struct quota_transaction_context {
index 52d0e2edaa4975f52eca3610ffd1bd4150412945..bc594f05823ac47d55e95a23ce938230f02f4a28 100644 (file)
@@ -663,5 +663,5 @@ void quota_mail_namespaces_created(struct mail_namespace *namespaces)
        for (i = 0; i < count; i++)
                quota_root_set_namespace(roots[i], namespaces);
 
-       quota_over_flag_check(namespaces->user, quota);
+       quota_over_flag_check(quota);
 }
index 34119b59e0a25074f275e8b22027fd003d3f6ba4..0b9799c20b681d8ccdc4664c40597ab2c8baee52 100644 (file)
@@ -46,6 +46,7 @@ static const struct quota_backend *quota_backends[] = {
 
 static int quota_default_test_alloc(struct quota_transaction_context *ctx,
                                    uoff_t size, bool *too_large_r);
+static void quota_over_flag_check_root(struct quota_root *root);
 
 static const struct quota_backend *quota_backend_find(const char *name)
 {
@@ -983,34 +984,35 @@ int quota_transaction_commit(struct quota_transaction_context **_ctx)
        return ret;
 }
 
-static void
-quota_over_flag_check_root(struct mail_user *user, struct quota_root *root)
+static void quota_over_flag_init_root(struct quota_root *root)
 {
-       const char *name, *flag_mask, *overquota_value, *overquota_script;
-       const char *const *resources;
-       unsigned int i;
-       uint64_t value, limit;
-       bool overquota_flag, cur_overquota = FALSE;
-       int ret;
-
-       name = t_strconcat(root->set->set_name, "_over_script", NULL);
-       overquota_script = mail_user_plugin_getenv(user, name);
-       if (overquota_script == NULL)
-               return;
+       const char *name, *flag_mask;
 
        /* e.g.: quota_over_flag_value=TRUE or quota_over_flag_value=*  */
        name = t_strconcat(root->set->set_name, "_over_flag_value", NULL);
-       flag_mask = mail_user_plugin_getenv(user, name);
+       flag_mask = mail_user_plugin_getenv(root->quota->user, name);
        if (flag_mask == NULL)
                return;
 
        /* compare quota_over_flag's value to quota_over_flag_value and
           save the result. */
        name = t_strconcat(root->set->set_name, "_over_flag", NULL);
-       overquota_value = mail_user_plugin_getenv(user, name);
-       overquota_flag = overquota_value != NULL &&
-               overquota_value[0] != '\0' &&
-               wildcard_match_icase(overquota_value, flag_mask);
+       root->quota_over_flag = p_strdup_empty(root->pool,
+               mail_user_plugin_getenv(root->quota->user, name));
+       root->quota_over_flag_status = root->quota_over_flag != NULL &&
+               wildcard_match_icase(root->quota_over_flag, flag_mask);
+}
+
+static void quota_over_flag_check_root(struct quota_root *root)
+{
+       const char *name, *overquota_script;
+       const char *const *resources;
+       unsigned int i;
+       uint64_t value, limit;
+       bool cur_overquota = FALSE;
+       int ret;
+
+       quota_over_flag_init_root(root);
 
        resources = quota_root_get_resources(root);
        for (i = 0; resources[i] != NULL; i++) {
@@ -1034,21 +1036,26 @@ quota_over_flag_check_root(struct mail_user *user, struct quota_root *root)
        }
        if (root->quota->set->debug) {
                i_debug("quota: quota_over_flag=%d(%s) vs currently overquota=%d",
-                       overquota_flag, overquota_value == NULL ? "(null)" : overquota_value,
+                       root->quota_over_flag_status,
+                       root->quota_over_flag == NULL ? "(null)" : root->quota_over_flag,
                        cur_overquota);
        }
-       if (cur_overquota != overquota_flag)
-               quota_warning_execute(root, overquota_script, overquota_value);
+       if (cur_overquota != root->quota_over_flag_status) {
+               name = t_strconcat(root->set->set_name, "_over_script", NULL);
+               overquota_script = mail_user_plugin_getenv(root->quota->user, name);
+               if (overquota_script != NULL)
+                       quota_warning_execute(root, overquota_script, root->quota_over_flag);
+       }
 }
 
-void quota_over_flag_check(struct mail_user *user, struct quota *quota)
+void quota_over_flag_check(struct quota *quota)
 {
        struct quota_root *const *roots;
        unsigned int i, count;
 
        roots = array_get(&quota->roots, &count);
        for (i = 0; i < count; i++)
-               quota_over_flag_check_root(user, roots[i]);
+               quota_over_flag_check_root(roots[i]);
 }
 
 void quota_transaction_rollback(struct quota_transaction_context **_ctx)
index 7b13f7bb788a18aedcdb3af19f261f1714cd9f87..460d5af7c6c26d7f7974096e453c2033088c7e04 100644 (file)
@@ -84,6 +84,6 @@ void quota_free_bytes(struct quota_transaction_context *ctx,
 void quota_recalculate(struct quota_transaction_context *ctx);
 
 /* Execute quota_over_scripts if needed. */
-void quota_over_flag_check(struct mail_user *user, struct quota *quota);
+void quota_over_flag_check(struct quota *quota);
 
 #endif