1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Message storage size kilobytes. */
e392fcb39a06609af20a9e79017683f194de3ddeTimo Sirainen/* Message storage size bytes. This is used only internally. */
e392fcb39a06609af20a9e79017683f194de3ddeTimo Sirainen#define QUOTA_NAME_STORAGE_BYTES "STORAGE_BYTES"
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Number of messages. */
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitov void (* param_handler)(struct quota_root *_root, const char *param_value);
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitovextern struct quota_param_parser quota_param_hidden;
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitovextern struct quota_param_parser quota_param_ignoreunlimited;
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitovextern struct quota_param_parser quota_param_noenforcing;
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitovextern struct quota_param_parser quota_param_ns;
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainen /* We may want to recalculate quota because we weren't able to call
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainen quota_free*() correctly for all mails. Quota needs to be
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainen recalculated unless the backend does the quota tracking
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainen internally. */
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainen /* doveadm quota recalc called - make sure the quota is correct */
38ce5769db11e7f52562610ee6e6fc4f0ea7888fMartti Rannanjärvi /* Mail size is larger than even the maximum allowed quota. */
b14f93ea4f7e9b78e5adbabcc78bd2f63d2bcd36Martti Rannanjärvi /* Blocked by ongoing background quota calculation. */
e78fe2531fd5cc3e3670a32fca6fbc238c960329Martti Rannanjärvi/* Anything <= QUOTA_GET_RESULT_INTERNAL_ERROR is an error. */
7ee626fd396f5549fb1fc6b0c320038638af9058Martti Rannanjärvi /* Ongoing background quota calculation */
e78fe2531fd5cc3e3670a32fca6fbc238c960329Martti Rannanjärvi /* Quota resource name doesn't exist */
e78fe2531fd5cc3e3670a32fca6fbc238c960329Martti Rannanjärvi /* Internal error */
2e07e3182f355cf04a1461dd7f893d0ebc818764Timo Sirainen /* Quota limit exists and was returned successfully */
2e07e3182f355cf04a1461dd7f893d0ebc818764Timo Sirainen /* Quota is unlimited, but its value was returned */
38ce5769db11e7f52562610ee6e6fc4f0ea7888fMartti Rannanjärviconst char *quota_alloc_result_errstr(enum quota_alloc_result res,
4316355ca8b7698516272520a972291378698140Timo Sirainenint quota_user_read_settings(struct mail_user *user,
4316355ca8b7698516272520a972291378698140Timo Sirainen const char **error_r);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenvoid quota_settings_deinit(struct quota_settings **quota_set);
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen/* Add a new rule too the quota root. Returns 0 if ok, -1 if rule is invalid. */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenint quota_root_add_rule(struct quota_root_settings *root_set,
503e5ef896c7b4a51cf73efb0d132860a8c747e6Timo Sirainen/* Add a new warning rule for the quota root. Returns 0 if ok, -1 if rule is
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenint quota_root_add_warning_rule(struct quota_root_settings *root_set,
c3785e2a5618182c3d7fb59f4888134e7ac834ccTimo Sirainen/* Initialize quota for the given user. Returns 0 and quota_r on success,
c3785e2a5618182c3d7fb59f4888134e7ac834ccTimo Sirainen -1 and error_r on failure. */
4316355ca8b7698516272520a972291378698140Timo Sirainenint quota_init(struct quota_settings *quota_set, struct mail_user *user,
4316355ca8b7698516272520a972291378698140Timo Sirainen struct quota **quota_r, const char **error_r);
c3785e2a5618182c3d7fb59f4888134e7ac834ccTimo Sirainen/* List all visible quota roots. They don't need to be freed. */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenstruct quota_root_iter *quota_root_iter_init(struct mailbox *box);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenstruct quota_root *quota_root_iter_next(struct quota_root_iter *iter);
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainenvoid quota_root_iter_deinit(struct quota_root_iter **iter);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Return quota root or NULL. */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenstruct quota_root *quota_root_lookup(struct mail_user *user, const char *name);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Returns name of the quota root. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenconst char *quota_root_get_name(struct quota_root *root);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Return a list of all resources set for the quota root. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenconst char *const *quota_root_get_resources(struct quota_root *root);
3f7583189249a28892cd5bd69e15681c7a8a619bTimo Sirainen/* Returns TRUE if quota root is marked as hidden (so it shouldn't be visible
3f7583189249a28892cd5bd69e15681c7a8a619bTimo Sirainen to users via IMAP GETQUOTAROOT command). */
3f7583189249a28892cd5bd69e15681c7a8a619bTimo Sirainenbool quota_root_is_hidden(struct quota_root *root);
c3785e2a5618182c3d7fb59f4888134e7ac834ccTimo Sirainen/* Returns 1 if values were successfully returned, 0 if resource name doesn't
c3785e2a5618182c3d7fb59f4888134e7ac834ccTimo Sirainen exist or isn't enabled, -1 if error. */
2e07e3182f355cf04a1461dd7f893d0ebc818764Timo Sirainenquota_get_resource(struct quota_root *root, const char *mailbox_name,
cf41318871bd42358df3420e50614f5310b08c77Martti Rannanjärvi const char *name, uint64_t *value_r, uint64_t *limit_r,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Returns 0 if OK, -1 if error (eg. permission denied, invalid name). */
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainenint quota_set_resource(struct quota_root *root, const char *name,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Start a new quota transaction. */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenstruct quota_transaction_context *quota_transaction_begin(struct mailbox *box);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Commit quota transaction. Returns 0 if ok, -1 if failed. */
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainenint quota_transaction_commit(struct quota_transaction_context **ctx);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Rollback quota transaction changes. */
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainenvoid quota_transaction_rollback(struct quota_transaction_context **ctx);
b62139aae0a0099d0ede35b164b2870479f9b027Martti Rannanjärvi/* Allocate from quota if there's space. error_r is set when result is not
b62139aae0a0099d0ede35b164b2870479f9b027Martti Rannanjärvi * QUOTA_ALLOC_RESULT_OK. */
38ce5769db11e7f52562610ee6e6fc4f0ea7888fMartti Rannanjärvienum quota_alloc_result quota_try_alloc(struct quota_transaction_context *ctx,
b62139aae0a0099d0ede35b164b2870479f9b027Martti Rannanjärvi struct mail *mail, const char **error_r);
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen/* Like quota_try_alloc(), but don't actually allocate anything. */
38ce5769db11e7f52562610ee6e6fc4f0ea7888fMartti Rannanjärvienum quota_alloc_result quota_test_alloc(struct quota_transaction_context *ctx,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Update quota by allocating/freeing space used by mail. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenvoid quota_alloc(struct quota_transaction_context *ctx, struct mail *mail);
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainenvoid quota_free_bytes(struct quota_transaction_context *ctx,
bd7b1a9000b12349e2a99bb43b3ce8b96a18e92bTimo Sirainen/* Mark the quota to be recalculated */
39dea5f2e78f6bfc3adc0655176f596ee211938fTimo Sirainenvoid quota_recalculate(struct quota_transaction_context *ctx,
666286d8ecc6c450b2232dcc628f79454215acfcTimo Sirainen/* Execute quota_over_scripts if needed. */
c16f2d0725a16559cdeedec7628ce616725000cbTimo Sirainenvoid quota_over_flag_check_startup(struct quota *quota);
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitov/* Common quota parameters parsing loop */
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitovint quota_parse_parameters(struct quota_root *root, const char **args, const char **error_r,
afbdaecd328f6c912293d713975856cbb2d75452Sergey Kitov const struct quota_param_parser *valid_params, bool fail_on_unknown);