1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen/* Modules should use do "my_id = quota_module_id++" and
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen use quota_module_contexts[id] for their own purposes. */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainenextern unsigned int quota_module_id;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct quota_root_settings *) root_sets;
b62139aae0a0099d0ede35b164b2870479f9b027Martti Rannanjärvi struct quota_transaction_context *ctx, uoff_t size,
3851ad9fcb25635f02b46d44586742ef1081876bTimo Sirainen /* relative to default_rule */
2b682d8d3661800f16aceaa45fa4de9b6b140a59Timo Sirainen /* Don't include this mailbox in quota */
9b61a6db87c026656f8d2ae214e4486b98a069c0Timo Sirainen int (*init)(struct quota_root *root, const char *args,
9b61a6db87c026656f8d2ae214e4486b98a069c0Timo Sirainen const char **error_r);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen bool (*parse_rule)(struct quota_root_settings *root_set,
e83a11eb1dc0dea31754396e1d07c5205d810104Martti Rannanjärvi int (*init_limits)(struct quota_root *root, const char **error_r);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen /* called once for each namespace */
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen const char *const *(*get_resources)(struct quota_root *root);
1379bb74c2855aaf3415fdfe965164a44ac3c001Martti Rannanjärvi /* Backends return success as QUOTA_GET_RESULT_LIMITED, and returning
1379bb74c2855aaf3415fdfe965164a44ac3c001Martti Rannanjärvi QUOTA_GET_RESULT_UNLIMITED is prohibited by quota_get_resource(),
1379bb74c2855aaf3415fdfe965164a44ac3c001Martti Rannanjärvi which is the only caller of this vfunc. */
1379bb74c2855aaf3415fdfe965164a44ac3c001Martti Rannanjärvi enum quota_get_result (*get_resource)(struct quota_root *root,
6d6bbe8787354bbb69d0c03187adfe0f497d70b8Timo Sirainen bool (*match_box)(struct quota_root *root, struct mailbox *box);
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen /* quota backends equal if backend1.name == backend2.name */
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen /* Unique quota root name. */
666286d8ecc6c450b2232dcc628f79454215acfcTimo Sirainen /* Name in settings, e.g. "quota", "quota2", .. */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct quota_warning_rule) warning_rules;
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen /* If user is under quota before saving a mail, allow the last mail to
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen bring the user over quota by this many bytes. */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen /* Limits in default_rule override backend's quota limits */
10207755f33a4cf1a1e901968137ae4f2bc93bbfTimo Sirainen /* TRUE if any of the warning_rules have reverse==TRUE */
2d8b23805db6f06b8b38174fb6e135386694f429Timo Sirainen /* this quota root applies only to this namespace. it may also be
2d8b23805db6f06b8b38174fb6e135386694f429Timo Sirainen a public namespace without an owner. */
766115d2b2e6dbcf59f90d3b3866851cf6f740feTimo Sirainen /* this is set in quota init(), because namespaces aren't known yet.
766115d2b2e6dbcf59f90d3b3866851cf6f740feTimo Sirainen when accessing shared users the ns_prefix may be non-NULL but
766115d2b2e6dbcf59f90d3b3866851cf6f740feTimo Sirainen ns=NULL, so when checking if quota root applies only to a specific
766115d2b2e6dbcf59f90d3b3866851cf6f740feTimo Sirainen namespace use the ns_prefix!=NULL check. */
b1678954f83e1059b981e2def52a70054fa71399Timo Sirainen /* initially the same as set->default_rule.*_limit, but some backends
b1678954f83e1059b981e2def52a70054fa71399Timo Sirainen may change these by reading the limits elsewhere (e.g. Maildir++,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* Module-specific contexts. See quota_module_id. */
d5d23d5ff8b7a06d2ead489ddcf55ee8fb5ca7b6Timo Sirainen /* don't enforce quota when saving */
e2e64c109827f782e9e20b50a15c7489479bcadaTimo Sirainen /* quota is automatically updated. update() should be called but the
f9362223346d10a5866b376ed227b77b26ea4292Timo Sirainen bytes won't be changed. count is still changed, because it's cheap
f9362223346d10a5866b376ed227b77b26ea4292Timo Sirainen to do and it's internally used to figure out whether there have
f9362223346d10a5866b376ed227b77b26ea4292Timo Sirainen been some changes and that quota_warnings should be checked. */
d19d3aa4eafa34b48b7d7d311c9db31e1898576aTimo Sirainen /* If user has unlimited quota, disable quota tracking */
8eb223b84389a7b75a39d46484f5166d221305ebTimo Sirainen /* Set while quota is being recalculated to avoid recursion. */
3f7583189249a28892cd5bd69e15681c7a8a619bTimo Sirainen /* Quota root is hidden (to e.g. IMAP GETQUOTAROOT) */
c16f2d0725a16559cdeedec7628ce616725000cbTimo Sirainen /* Did we already check quota_over_flag correctness? */
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen union mailbox_transaction_module_context module_ctx;
30ad2b0309119501efad06c72ec9b1561b90d4afTimo Sirainen /* how many bytes/mails can be saved until limit is reached.
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen (set once, not updated by bytes_used/count_used).
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen if last_mail_max_extra_bytes>0, the bytes_ceil is initially
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen increased by that much, while bytes_ceil2 contains the real ceiling.
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen after the first allocation is done, bytes_ceil is set to
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen bytes_ceil2. */
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen /* How many bytes/mails we are over quota. Like *_ceil, these are set
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen only once and not updated by bytes_used/count_used. (Either *_ceil
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen or *_over is always zero.) */
e2e64c109827f782e9e20b50a15c7489479bcadaTimo Sirainen /* TRUE if all roots have auto_updating=TRUE */
ad759d5e8971dd3dae17f40087bcb50f7bc4599eTimo Sirainen /* Quota doesn't need to be updated within this transaction. */
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen/* Register storage to all user's quota roots. */
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenvoid quota_add_user_namespace(struct quota *quota, struct mail_namespace *ns);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenvoid quota_remove_user_namespace(struct mail_namespace *ns);
a4922fa0c7de2aa332bc1361abf6f93f001fc02eTimo Sirainenint quota_root_default_init(struct quota_root *root, const char *args,
a4922fa0c7de2aa332bc1361abf6f93f001fc02eTimo Sirainen const char **error_r);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenstruct quota *quota_get_mail_user_quota(struct mail_user *user);
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainenbool quota_root_is_namespace_visible(struct quota_root *root,
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainenquota_root_rule_find(struct quota_root_settings *root_set, const char *name);
d761c26f2bbf514e0fc0c6ed9bc52627a4179eabTimo Sirainenvoid quota_root_recalculate_relative_rules(struct quota_root_settings *root_set,
92c671c1667ea1bea90030a2b69298bf8c541623Timo Sirainen/* Returns 1 if values were returned successfully, 0 if we're recursing into
92c671c1667ea1bea90030a2b69298bf8c541623Timo Sirainen the same function, -1 if error. */
d2cbbecf76de3f4eb945895fab5760ed0a28281cMartti Rannanjärviint quota_count(struct quota_root *root, uint64_t *bytes_r, uint64_t *count_r,
4f52de745cf26ee9dcbde7ca4500d442116226cfMartti Rannanjärvi enum quota_get_result *error_result_r, const char **error_r);
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainenint quota_root_parse_grace(struct quota_root_settings *root_set,
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainenbool quota_warning_match(const struct quota_warning_rule *w,
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen uint64_t bytes_before, uint64_t bytes_current,
f97866381675fe12cdab0f2d56a059fe7b88457aTimo Sirainen uint64_t count_before, uint64_t count_current,
f97866381675fe12cdab0f2d56a059fe7b88457aTimo Sirainen const char **reason_r);
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainenbool quota_transaction_is_over(struct quota_transaction_context *ctx, uoff_t size);
efd291767a612b2cf3421f3d4ff1c3d8abd78484Martti Rannanjärviint quota_transaction_set_limits(struct quota_transaction_context *ctx,
bd2a176b573f9679e7e45339c20ef71704f071c0Aki Tuomivoid quota_backend_register(const struct quota_backend *backend);
bd2a176b573f9679e7e45339c20ef71704f071c0Aki Tuomivoid quota_backend_unregister(const struct quota_backend *backend);
1379bb74c2855aaf3415fdfe965164a44ac3c001Martti Rannanjärvi#define QUOTA_UNKNOWN_RESOURCE_ERROR_STRING "Unknown quota resource"