Skip to content

Commit

Permalink
quota: Rename quota_set_resource() error_r to client_error_r
Browse files Browse the repository at this point in the history
Don't pass on the error from dict_init() to client, though.
  • Loading branch information
mrannanj committed Jan 21, 2019
1 parent 11c3b2e commit 9f91077
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/plugins/imap-quota/imap-quota-plugin.c
Expand Up @@ -192,7 +192,7 @@ static bool cmd_setquota(struct client_command_context *cmd)
struct quota_root *root;
struct mail_user *owner;
const struct imap_arg *args, *list_args;
const char *root_name, *name, *value_str, *error;
const char *root_name, *name, *value_str, *client_error;
uint64_t value;

/* <quota root> <resource limits> */
Expand Down Expand Up @@ -223,8 +223,8 @@ static bool cmd_setquota(struct client_command_context *cmd)
return TRUE;
}

if (quota_set_resource(root, name, value, &error) < 0) {
client_send_command_error(cmd, error);
if (quota_set_resource(root, name, value, &client_error) < 0) {
client_send_command_error(cmd, client_error);
return TRUE;
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/plugins/quota/quota.c
Expand Up @@ -816,13 +816,13 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
}

int quota_set_resource(struct quota_root *root, const char *name,
uint64_t value, const char **error_r)
uint64_t value, const char **client_error_r)
{
struct dict_transaction_context *trans;
const char *key, *error;

if (root->set->limit_set == NULL) {
*error_r = MAIL_ERRSTR_NO_PERMISSION;
*client_error_r = MAIL_ERRSTR_NO_PERMISSION;
return -1;
}
if (strcasecmp(name, QUOTA_NAME_STORAGE_KILOBYTES) == 0)
Expand All @@ -832,7 +832,8 @@ int quota_set_resource(struct quota_root *root, const char *name,
else if (strcasecmp(name, QUOTA_NAME_MESSAGES) == 0)
key = "messages";
else {
*error_r = t_strdup_printf("Unsupported resource name: %s", name);
*client_error_r = t_strdup_printf(
"Unsupported resource name: %s", name);
return -1;
}

Expand All @@ -845,16 +846,19 @@ int quota_set_resource(struct quota_root *root, const char *name,
if (mail_user_get_home(root->quota->user, &set.home_dir) <= 0)
set.home_dir = NULL;
if (dict_init(root->set->limit_set, &set,
&root->limit_set_dict, error_r) < 0)
&root->limit_set_dict, &error) < 0) {
i_error("dict_init() failed: %s", error);
*client_error_r = "Internal quota limit update error";
return -1;
}
}

trans = dict_transaction_begin(root->limit_set_dict);
key = t_strdup_printf(QUOTA_LIMIT_SET_PATH"%s", key);
dict_set(trans, key, dec2str(value));
if (dict_transaction_commit(&trans, &error) < 0) {
i_error("dict_transaction_commit() failed: %s", error);
*error_r = "Internal quota limit update error";
*client_error_r = "Internal quota limit update error";
return -1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/quota/quota.h
Expand Up @@ -113,7 +113,7 @@ quota_get_resource(struct quota_root *root, const char *mailbox_name,
const char **error_r);
/* Returns 0 if OK, -1 if error (eg. permission denied, invalid name). */
int quota_set_resource(struct quota_root *root, const char *name,
uint64_t value, const char **error_r);
uint64_t value, const char **client_error_r);

/* Start a new quota transaction. */
struct quota_transaction_context *quota_transaction_begin(struct mailbox *box);
Expand Down

0 comments on commit 9f91077

Please sign in to comment.