]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota, imap_quota: quota_get_resource() - Changed mailbox_name parameter to struct...
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 15 Aug 2024 21:13:02 +0000 (00:13 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
src/plugins/imap-quota/imap-quota-plugin.c
src/plugins/quota/doveadm-quota.c
src/plugins/quota/quota.c
src/plugins/quota/quota.h

index eb8cf423e5dc5b0c0f71ed00b558139e270f2c42..601fdbc2c38d2e66464c39241d2dd287ee2024ad 100644 (file)
@@ -50,7 +50,7 @@ quota_reply_write(string_t *str, struct mail_user *user,
        prefix_len = str_len(str);
        list = quota_root_get_resources(root);
        for (i = 0; *list != NULL; list++) {
-               ret = quota_get_resource(root, "", *list, &value, &limit, &error);
+               ret = quota_get_resource(root, NULL, *list, &value, &limit, &error);
                if (ret == QUOTA_GET_RESULT_INTERNAL_ERROR) {
                        e_error(user->event,
                                "Failed to get quota resource %s: %s",
index 21449d32aab6e798b79f3cb7014e6d9ce9509f23..ff544fc9bb75a8f8bfbb47137ad70995ea436202 100644 (file)
@@ -23,7 +23,7 @@ static int cmd_quota_get_root(struct quota_root *root, struct mail_user *user)
 
        res = quota_root_get_resources(root);
        for (; *res != NULL; res++) {
-               qret = quota_get_resource(root, "", *res, &value, &limit, &error);
+               qret = quota_get_resource(root, NULL, *res, &value, &limit, &error);
                doveadm_print(root->set->name);
                doveadm_print(*res);
                if (qret == QUOTA_GET_RESULT_LIMITED) {
index 57f69c5f578eafc7574bcbd2d77fb7d6e4e21fe6..9c082cb4ae20a973be78efa2c8138544b966a386 100644 (file)
@@ -439,7 +439,7 @@ void quota_deinit(struct quota **_quota)
 }
 
 static void
-quota_root_get_rule_limits(struct quota_root *root, const char *mailbox_name,
+quota_root_get_rule_limits(struct quota_root *root, struct mailbox *box,
                           uint64_t *bytes_limit_r, uint64_t *count_limit_r,
                           bool *ignored_r)
 {
@@ -454,6 +454,7 @@ quota_root_get_rule_limits(struct quota_root *root, const char *mailbox_name,
        /* if default rule limits are 0, user has unlimited quota.
           ignore any specific quota rules */
        if (bytes_limit != 0 || count_limit != 0) {
+               const char *mailbox_name = mailbox_get_vname(box);
                (void)mail_namespace_find_unalias(root->quota->user->namespaces,
                                                  &mailbox_name);
                rule = quota_root_rule_find(root->set, mailbox_name);
@@ -714,7 +715,7 @@ bool quota_root_is_hidden(struct quota_root *root)
 }
 
 enum quota_get_result
-quota_get_resource(struct quota_root *root, const char *mailbox_name,
+quota_get_resource(struct quota_root *root, struct mailbox *box,
                   const char *name, uint64_t *value_r, uint64_t *limit_r,
                   const char **error_r)
 {
@@ -736,14 +737,15 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
        if (ret == QUOTA_GET_RESULT_UNLIMITED)
                i_panic("Quota backend %s returned QUOTA_GET_RESULT_UNLIMITED "
                        "while getting resource %s from box %s",
-                       root->backend.name, name, mailbox_name);
+                       root->backend.name, name, box == NULL ? "" :
+                       mailbox_get_vname(box));
        else if (ret != QUOTA_GET_RESULT_LIMITED) {
                *error_r = t_strdup_printf(
                        "quota-%s: %s", root->set->backend->name, error);
                return ret;
        }
 
-       quota_root_get_rule_limits(root, mailbox_name,
+       quota_root_get_rule_limits(root, box,
                                   &bytes_limit, &count_limit, &ignored);
 
        if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0)
@@ -828,7 +830,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                                 const char **error_r)
 {
        struct quota_root *const *roots;
-       const char *mailbox_name, *error;
+       const char *error;
        unsigned int i, count;
        uint64_t bytes_limit, count_limit, current, limit, diff;
        bool use_grace, ignored;
@@ -837,7 +839,6 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
        if (ctx->limits_set)
                return 0;
        ctx->limits_set = TRUE;
-       mailbox_name = mailbox_get_vname(ctx->box);
        /* use quota_grace only for LDA/LMTP */
        use_grace = (ctx->box->flags & MAILBOX_FLAG_POST_SESSION) != 0;
        ctx->no_quota_updates = TRUE;
@@ -860,7 +861,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                else if (roots[i]->no_enforcing) {
                        ignored = FALSE;
                } else {
-                       quota_root_get_rule_limits(roots[i], mailbox_name,
+                       quota_root_get_rule_limits(roots[i], ctx->box,
                                                   &bytes_limit, &count_limit,
                                                   &ignored);
                }
@@ -868,7 +869,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                        ctx->no_quota_updates = FALSE;
 
                if (bytes_limit > 0) {
-                       ret = quota_get_resource(roots[i], mailbox_name,
+                       ret = quota_get_resource(roots[i], ctx->box,
                                                 QUOTA_NAME_STORAGE_BYTES,
                                                 &current, &limit, &error);
                        if (ret == QUOTA_GET_RESULT_LIMITED) {
@@ -894,13 +895,13 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                                *error_r = t_strdup_printf(
                                        "Failed to get quota resource "
                                        QUOTA_NAME_STORAGE_BYTES" for %s: %s",
-                                       mailbox_name, error);
+                                       mailbox_get_vname(ctx->box), error);
                                return -1;
                        }
                }
 
                if (count_limit > 0) {
-                       ret = quota_get_resource(roots[i], mailbox_name,
+                       ret = quota_get_resource(roots[i], ctx->box,
                                                 QUOTA_NAME_MESSAGES,
                                                 &current, &limit, &error);
                        if (ret == QUOTA_GET_RESULT_LIMITED) {
@@ -921,7 +922,7 @@ int quota_transaction_set_limits(struct quota_transaction_context *ctx,
                                *error_r = t_strdup_printf(
                                        "Failed to get quota resource "
                                        QUOTA_NAME_MESSAGES" for %s: %s",
-                                       mailbox_name, error);
+                                       mailbox_get_vname(ctx->box), error);
                                return -1;
                        }
                }
@@ -1012,14 +1013,14 @@ static void quota_warnings_execute(struct quota_transaction_context *ctx,
        if (count == 0)
                return;
 
-       if (quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
+       if (quota_get_resource(root, NULL, QUOTA_NAME_STORAGE_BYTES,
                               &bytes_current, &bytes_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) {
                e_error(root->quota->event,
                        "Failed to get quota resource "QUOTA_NAME_STORAGE_BYTES
                        ": %s", error);
                return;
        }
-       if (quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
+       if (quota_get_resource(root, NULL, QUOTA_NAME_MESSAGES,
                               &count_current, &count_limit, &error) == QUOTA_GET_RESULT_INTERNAL_ERROR) {
                e_error(root->quota->event,
                        "Failed to get quota resource "QUOTA_NAME_MESSAGES
@@ -1177,7 +1178,7 @@ static void quota_over_flag_check_root(struct quota_root *root)
 
        resources = quota_root_get_resources(root);
        for (i = 0; resources[i] != NULL; i++) {
-               ret = quota_get_resource(root, "", resources[i], &value,
+               ret = quota_get_resource(root, NULL, resources[i], &value,
                                         &limit, &error);
                if (ret == QUOTA_GET_RESULT_INTERNAL_ERROR) {
                        /* can't reliably verify this */
@@ -1344,8 +1345,7 @@ static enum quota_alloc_result quota_default_test_alloc(
                    roots[i]->no_enforcing)
                        continue;
 
-               quota_root_get_rule_limits(roots[i],
-                                          mailbox_get_vname(ctx->box),
+               quota_root_get_rule_limits(roots[i], ctx->box,
                                           &bytes_limit, &count_limit,
                                           &ignore);
 
index 5828c07619e90c599b94e751f1172eac0a451247..839e54906e25c9fc19627bf98ed153d1fb0d796b 100644 (file)
@@ -112,7 +112,7 @@ bool quota_root_is_hidden(struct quota_root *root);
 /* Returns 1 if values were successfully returned, 0 if resource name doesn't
    exist or isn't enabled, -1 if error. */
 enum quota_get_result
-quota_get_resource(struct quota_root *root, const char *mailbox_name,
+quota_get_resource(struct quota_root *root, struct mailbox *box,
                   const char *name, uint64_t *value_r, uint64_t *limit_r,
                   const char **error_r);