quota.c revision 94e1adead9faddec88a623485b9999a87b1684fa
/* Copyright (C) 2005 Timo Sirainen */
#include "lib.h"
#include "array.h"
#include "hash.h"
#include "mailbox-list-private.h"
#include "quota-private.h"
#include "quota-fs.h"
#include <ctype.h>
#include <stdlib.h>
#define RULE_NAME_ALL_MAILBOXES "*"
struct quota_root_iter {
unsigned int i;
};
unsigned int quota_module_id = 0;
extern struct quota_backend quota_backend_dict;
extern struct quota_backend quota_backend_dirsize;
extern struct quota_backend quota_backend_fs;
extern struct quota_backend quota_backend_maildir;
static const struct quota_backend *quota_backends[] = {
#ifdef HAVE_FS_QUOTA
#endif
};
struct quota *quota_init(void)
{
return quota;
}
{
struct quota_root **root;
}
}
{
unsigned int i;
for (i = 0; i < QUOTA_CLASS_COUNT; i++) {
return quota_backends[i];
}
return NULL;
}
{
struct quota_root *root;
const struct quota_backend *backend;
const char *p, *args, *backend_name;
t_push();
/* <backend>[:<quota root name>[:<backend args>]] */
if (p == NULL) {
} else {
args = p + 1;
}
t_pop();
/* save root's name */
if (p == NULL) {
} else {
args = p + 1;
}
} else {
}
sizeof(void *), 5);
return NULL;
}
}
return root;
}
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++) {
}
}
static struct quota_rule *
{
struct quota_rule *rules;
unsigned int i, count;
for (i = 0; i < count; i++) {
return &rules[i];
}
return NULL;
}
static int
{
const char **args;
char *p;
multiply = 1;
multiply = 1024;
} else {
"Unknown rule limit name: %s", *args);
return -1;
}
switch (i_toupper(*p)) {
case '\0':
/* default */
break;
case 'B':
multiply = 1;
break;
case 'K':
multiply = 1024;
break;
case 'M':
break;
case 'G':
break;
case 'T':
break;
default:
"Invalid rule limit value: %s", *args);
return -1;
}
}
return 0;
}
const char **error_r)
{
struct quota_rule *rule;
const char *p, *mailbox_name;
int ret = 0;
if (p == NULL) {
*error_r = "Invalid rule";
return -1;
}
/* <mailbox name>:<quota limits> */
t_push();
else {
}
}
ret = -1;
} else {
ret = -1;
}
i_info("Quota rule: root=%s mailbox=%s "
(long long)rule->count_limit);
}
t_pop();
return ret;
}
const char *mailbox_name,
{
struct quota_rule *rule;
bool found;
/* if default rule limits are 0, this rule applies only to specific
mailboxes */
}
return found;
}
{
struct quota_root *const *roots;
struct mail_storage *const *storages;
struct quota_backend **backends;
unsigned int i, j, count;
bool is_file;
/* first check if there already exists a storage with the exact same
path. we don't want to count them twice. */
for (i = 0; i < count; i++) {
&is_file);
/* duplicate */
return;
}
}
}
/* @UNSAFE: get different backends into one array */
for (i = 0; i < count; i++) {
break;
}
}
}
}
struct mail_storage *storage)
{
struct mail_storage *const *storages;
unsigned int i, count;
for (i = 0; i < count; i++) {
break;
}
}
}
struct quota_root_iter *
{
struct quota_root_iter *iter;
return iter;
}
{
unsigned int count;
int ret;
return NULL;
if (ret == 0) {
}
if (ret > 0) {
break;
}
}
iter->i++;
return root;
}
{
}
{
struct quota_root *const *roots;
unsigned int i, count;
for (i = 0; i < count; i++) {
return roots[i];
}
return NULL;
}
{
}
{
}
{
int ret;
}
&bytes_limit, &count_limit);
*limit_r = bytes_limit;
*limit_r = count_limit;
else
*limit_r = 0;
*value_r /= 1024;
*limit_r /= 1024;
}
(*limit_r == 0 ? 0 : 1);
}
const char *name __attr_unused__,
{
/* the quota information comes from userdb (or even config file),
so there's really no way to support this until some major changes
are done */
return -1;
}
{
struct quota_transaction_context *ctx;
return ctx;
}
{
struct quota_root *const *roots;
unsigned int i, count;
int ret = 0;
ret = -1;
ctx->recalculate) {
for (i = 0; i < count; i++) {
ret = -1;
}
}
return ret;
}
{
}
{
struct quota_root *const *roots;
const char *mailbox_name;
unsigned int i, count;
int ret;
/* find the lowest quota limits from all roots and use them */
for (i = 0; i < count; i++) {
if (ret > 0) {
} else if (ret < 0) {
return -1;
}
if (ret > 0) {
} else if (ret < 0) {
return -1;
}
}
return 0;
}
{
int ret;
if (ret <= 0)
return ret;
return 1;
}
{
return -1;
if (!ctx->limits_set) {
if (quota_transaction_set_limits(ctx) < 0)
return -1;
}
}
{
struct quota_root *const *roots;
unsigned int i, count;
*too_large_r = FALSE;
return 1;
for (i = 0; i < count; i++) {
if (!quota_root_get_rule_limits(roots[i],
&bytes_limit, &count_limit))
continue;
/* if size is bigger than any limit, then
it is bigger than the lowest limit */
if (size > bytes_limit) {
*too_large_r = TRUE;
break;
}
}
return 0;
}
{
ctx->count_used++;
}
{
else
}
{
ctx->count_used--;
}
{
}