1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file
*/
#include "lib.h"
#include "strfuncs.h"
#include "sieve-storage.h"
#include "sieve-storage-quota.h"
#include "managesieve-client.h"
#include "managesieve-quota.h"
uint64_t managesieve_quota_max_script_size(struct client *client)
{
return sieve_storage_quota_max_script_size(client->storage);
}
bool managesieve_quota_check_validsize(struct client *client, size_t size)
{
uint64_t limit;
if ( !sieve_storage_quota_validsize
(client->storage, size, &limit) ) {
client_send_noresp(client, "QUOTA/MAXSIZE",
t_strdup_printf("Script is too large (max %llu bytes).",
(unsigned long long int) limit));
return FALSE;
}
return TRUE;
}
bool managesieve_quota_check_all
(struct client *client, const char *scriptname, size_t size)
{
enum sieve_storage_quota quota;
uint64_t limit;
int ret;
if ( (ret=sieve_storage_quota_havespace
(client->storage, scriptname, size, "a, &limit)) <= 0 ) {
if ( ret == 0 ) {
switch ( quota ) {
case SIEVE_STORAGE_QUOTA_MAXSIZE:
client_send_noresp(client, "QUOTA/MAXSIZE", t_strdup_printf(
"Script is too large (max %llu bytes).",
(unsigned long long int) limit));
break;
case SIEVE_STORAGE_QUOTA_MAXSCRIPTS:
client_send_noresp(client, "QUOTA/MAXSCRIPTS", t_strdup_printf(
"Script count quota exceeded (max %llu scripts).",
(unsigned long long int) limit));
break;
case SIEVE_STORAGE_QUOTA_MAXSTORAGE:
client_send_noresp(client, "QUOTA/MAXSTORAGE", t_strdup_printf(
"Script storage quota exceeded (max %llu bytes).",
(unsigned long long int) limit));
break;
default:
client_send_noresp(client, "QUOTA", "Quota exceeded.");
break;
}
} else {
client_send_storage_error(client, client->storage);
}
return FALSE;
}
return TRUE;
}
|