quota-dict.c (dovecot-2.3.16) | : | quota-dict.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 73 | skipping to change at line 73 | |||
if (*username == '\0') | if (*username == '\0') | |||
username = _root->quota->user->username; | username = _root->quota->user->username; | |||
e_debug(_root->backend.event, "user=%s, uri=%s, noenforcing=%d", | e_debug(_root->backend.event, "user=%s, uri=%s, noenforcing=%d", | |||
username, args, _root->no_enforcing ? 1 : 0); | username, args, _root->no_enforcing ? 1 : 0); | |||
/* FIXME: we should use 64bit integer as datatype instead but before | /* FIXME: we should use 64bit integer as datatype instead but before | |||
it can actually be used don't bother */ | it can actually be used don't bother */ | |||
i_zero(&set); | i_zero(&set); | |||
set.username = username; | ||||
set.base_dir = _root->quota->user->set->base_dir; | set.base_dir = _root->quota->user->set->base_dir; | |||
set.event_parent = _root->quota->user->event; | set.event_parent = _root->quota->user->event; | |||
if (mail_user_get_home(_root->quota->user, &set.home_dir) <= 0) | ||||
set.home_dir = NULL; | ||||
if (dict_init(args, &set, &root->dict, &error) < 0) { | if (dict_init(args, &set, &root->dict, &error) < 0) { | |||
*error_r = t_strdup_printf("dict_init(%s) failed: %s", args, erro r); | *error_r = t_strdup_printf("dict_init(%s) failed: %s", args, erro r); | |||
return -1; | return -1; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
static void dict_quota_deinit(struct quota_root *_root) | static void dict_quota_deinit(struct quota_root *_root) | |||
{ | { | |||
struct dict_quota_root *root = (struct dict_quota_root *)_root; | struct dict_quota_root *root = (struct dict_quota_root *)_root; | |||
skipping to change at line 116 | skipping to change at line 113 | |||
} | } | |||
static enum quota_get_result | static enum quota_get_result | |||
dict_quota_count(struct dict_quota_root *root, | dict_quota_count(struct dict_quota_root *root, | |||
bool want_bytes, uint64_t *value_r, | bool want_bytes, uint64_t *value_r, | |||
const char **error_r) | const char **error_r) | |||
{ | { | |||
struct dict_transaction_context *dt; | struct dict_transaction_context *dt; | |||
uint64_t bytes, count; | uint64_t bytes, count; | |||
enum quota_get_result error_res; | enum quota_get_result error_res; | |||
const struct dict_op_settings *set; | ||||
if (quota_count(&root->root, &bytes, &count, &error_res, error_r) < 0) | if (quota_count(&root->root, &bytes, &count, &error_res, error_r) < 0) | |||
return error_res; | return error_res; | |||
dt = dict_transaction_begin(root->dict); | set = mail_user_get_dict_op_settings(root->root.quota->user); | |||
dt = dict_transaction_begin(root->dict, set); | ||||
/* these unsets are mainly necessary for pgsql, because its | /* these unsets are mainly necessary for pgsql, because its | |||
trigger otherwise increases quota without deleting it. | trigger otherwise increases quota without deleting it. | |||
but some people with other databases want to store the | but some people with other databases want to store the | |||
quota usage among other data in the same row, which | quota usage among other data in the same row, which | |||
shouldn't be deleted. */ | shouldn't be deleted. */ | |||
if (!root->disable_unset) { | if (!root->disable_unset) { | |||
dict_unset(dt, DICT_QUOTA_CURRENT_BYTES_PATH); | dict_unset(dt, DICT_QUOTA_CURRENT_BYTES_PATH); | |||
dict_unset(dt, DICT_QUOTA_CURRENT_COUNT_PATH); | dict_unset(dt, DICT_QUOTA_CURRENT_COUNT_PATH); | |||
} | } | |||
dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes)); | dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes)); | |||
skipping to change at line 149 | skipping to change at line 148 | |||
} | } | |||
static enum quota_get_result | static enum quota_get_result | |||
dict_quota_get_resource(struct quota_root *_root, | dict_quota_get_resource(struct quota_root *_root, | |||
const char *name, uint64_t *value_r, | const char *name, uint64_t *value_r, | |||
const char **error_r) | const char **error_r) | |||
{ | { | |||
struct dict_quota_root *root = (struct dict_quota_root *)_root; | struct dict_quota_root *root = (struct dict_quota_root *)_root; | |||
bool want_bytes; | bool want_bytes; | |||
int ret; | int ret; | |||
const struct dict_op_settings *set; | ||||
if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) | if (strcmp(name, QUOTA_NAME_STORAGE_BYTES) == 0) | |||
want_bytes = TRUE; | want_bytes = TRUE; | |||
else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) | else if (strcmp(name, QUOTA_NAME_MESSAGES) == 0) | |||
want_bytes = FALSE; | want_bytes = FALSE; | |||
else { | else { | |||
*error_r = QUOTA_UNKNOWN_RESOURCE_ERROR_STRING; | *error_r = QUOTA_UNKNOWN_RESOURCE_ERROR_STRING; | |||
return QUOTA_GET_RESULT_UNKNOWN_RESOURCE; | return QUOTA_GET_RESULT_UNKNOWN_RESOURCE; | |||
} | } | |||
set = mail_user_get_dict_op_settings(root->root.quota->user); | ||||
const char *key, *value, *error; | const char *key, *value, *error; | |||
key = want_bytes ? DICT_QUOTA_CURRENT_BYTES_PATH : | key = want_bytes ? DICT_QUOTA_CURRENT_BYTES_PATH : | |||
DICT_QUOTA_CURRENT_COUNT_PATH; | DICT_QUOTA_CURRENT_COUNT_PATH; | |||
ret = dict_lookup(root->dict, unsafe_data_stack_pool, | ret = dict_lookup(root->dict, set, unsafe_data_stack_pool, | |||
key, &value, &error); | key, &value, &error); | |||
if (ret < 0) { | if (ret < 0) { | |||
*error_r = t_strdup_printf( | *error_r = t_strdup_printf( | |||
"dict_lookup(%s) failed: %s", key, error); | "dict_lookup(%s) failed: %s", key, error); | |||
*value_r = 0; | *value_r = 0; | |||
return QUOTA_GET_RESULT_INTERNAL_ERROR; | return QUOTA_GET_RESULT_INTERNAL_ERROR; | |||
} | } | |||
intmax_t tmp; | intmax_t tmp; | |||
/* recalculate quota if it's negative or if it wasn't found */ | /* recalculate quota if it's negative or if it wasn't found */ | |||
skipping to change at line 216 | skipping to change at line 217 | |||
} | } | |||
static int | static int | |||
dict_quota_update(struct quota_root *_root, | dict_quota_update(struct quota_root *_root, | |||
struct quota_transaction_context *ctx, | struct quota_transaction_context *ctx, | |||
const char **error_r) | const char **error_r) | |||
{ | { | |||
struct dict_quota_root *root = (struct dict_quota_root *) _root; | struct dict_quota_root *root = (struct dict_quota_root *) _root; | |||
struct dict_transaction_context *dt; | struct dict_transaction_context *dt; | |||
uint64_t value; | uint64_t value; | |||
const struct dict_op_settings *set; | ||||
if (ctx->recalculate != QUOTA_RECALCULATE_DONT) { | if (ctx->recalculate != QUOTA_RECALCULATE_DONT) { | |||
if (dict_quota_count(root, TRUE, &value, error_r) | if (dict_quota_count(root, TRUE, &value, error_r) | |||
<= QUOTA_GET_RESULT_INTERNAL_ERROR) | <= QUOTA_GET_RESULT_INTERNAL_ERROR) | |||
return -1; | return -1; | |||
} else { | } else { | |||
dt = dict_transaction_begin(root->dict); | set = mail_user_get_dict_op_settings(root->root.quota->user); | |||
dt = dict_transaction_begin(root->dict, set); | ||||
if (ctx->bytes_used != 0) { | if (ctx->bytes_used != 0) { | |||
dict_atomic_inc(dt, DICT_QUOTA_CURRENT_BYTES_PATH, | dict_atomic_inc(dt, DICT_QUOTA_CURRENT_BYTES_PATH, | |||
ctx->bytes_used); | ctx->bytes_used); | |||
} | } | |||
if (ctx->count_used != 0) { | if (ctx->count_used != 0) { | |||
dict_atomic_inc(dt, DICT_QUOTA_CURRENT_COUNT_PATH, | dict_atomic_inc(dt, DICT_QUOTA_CURRENT_COUNT_PATH, | |||
ctx->count_used); | ctx->count_used); | |||
} | } | |||
dict_transaction_no_slowness_warning(dt); | dict_transaction_no_slowness_warning(dt); | |||
dict_transaction_commit_async(&dt, dict_quota_update_callback, | dict_transaction_commit_async(&dt, dict_quota_update_callback, | |||
End of changes. 9 change blocks. | ||||
6 lines changed or deleted | 9 lines changed or added |