dovecot: Allow non-default rule limits to be percentages of the ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 16 02:41:44 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/b272eff19a18
changeset: 6031:b272eff19a18
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jul 16 02:00:35 2007 +0300
description:
Allow non-default rule limits to be percentages of the default rule limit.

diffstat:

1 file changed, 32 insertions(+)
src/plugins/quota/quota.c |   32 ++++++++++++++++++++++++++++++++

diffs (49 lines):

diff -r d22be94225b1 -r b272eff19a18 src/plugins/quota/quota.c
--- a/src/plugins/quota/quota.c	Mon Jul 16 01:53:18 2007 +0300
+++ b/src/plugins/quota/quota.c	Mon Jul 16 02:00:35 2007 +0300
@@ -171,6 +171,32 @@ quota_root_rule_find(struct quota_root *
 			return &rules[i];
 	}
 	return NULL;
+}
+
+static int
+quota_rule_parse_percentage(struct quota_root *root, struct quota_rule *rule,
+			    int64_t *limit, const char **error_r)
+{
+	int64_t percentage = *limit;
+
+	if (percentage < 0) {
+		*error_r = p_strdup_printf(root->pool,
+			"Invalid rule percentage: %lld", (long long)percentage);
+		return -1;
+	}
+
+	if (rule == &root->default_rule) {
+		*error_r = "Default rule can't be a percentage";
+		return -1;
+	}
+
+	if (limit == &rule->bytes_limit)
+		*limit = rule->bytes_limit * percentage / 100;
+	else if (limit == &rule->count_limit)
+		*limit = rule->count_limit * percentage / 100;
+	else
+		i_unreached();
+	return 0;
 }
 
 static int
@@ -221,6 +247,12 @@ quota_rule_parse_limits(struct quota_roo
 		case 'T':
 			multiply = 1024ULL*1024*1024*1024;
 			break;
+		case '%':
+			multiply = 1;
+			if (quota_rule_parse_percentage(root, rule, limit,
+							error_r) < 0)
+				return -1;
+			break;
 		default:
 			*error_r = p_strdup_printf(root->pool,
 					"Invalid rule limit value: %s", *args);


More information about the dovecot-cvs mailing list