changeset 21520:b1c4db787e1c

quota: Remove quota_over_flag_* from quota_root. They are used only in one specific location and don't need to be stored permanently.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 07 Feb 2017 15:33:07 +0200
parents 9722a49567e0
children bfc81bb63199
files src/plugins/quota/quota-private.h src/plugins/quota/quota.c
diffstat 2 files changed, 18 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/quota/quota-private.h	Fri Feb 10 13:17:00 2017 +0200
+++ b/src/plugins/quota/quota-private.h	Tue Feb 07 15:33:07 2017 +0200
@@ -131,10 +131,6 @@
 	/* Module-specific contexts. See quota_module_id. */
 	ARRAY(void) quota_module_contexts;
 
-	/* Set to the current quota_over_flag, regardless of whether
-	   it matches quota_over_flag_value mask. */
-	const char *quota_over_flag;
-
 	/* don't enforce quota when saving */
 	unsigned int no_enforcing:1;
 	/* quota is automatically updated. update() should be called but the
@@ -146,10 +142,6 @@
 	unsigned int recounting:1;
 	/* Quota root is hidden (to e.g. IMAP GETQUOTAROOT) */
 	unsigned int hidden:1;
-	/* Is quota_over_flag* initialized yet? */
-	unsigned int quota_over_flag_initialized:1;
-	/* Is user currently over quota? */
-	unsigned int quota_over_flag_status:1;
 	/* Did we already check quota_over_flag correctness? */
 	unsigned int quota_over_flag_checked:1;
 };
--- a/src/plugins/quota/quota.c	Fri Feb 10 13:17:00 2017 +0200
+++ b/src/plugins/quota/quota.c	Tue Feb 07 15:33:07 2017 +0200
@@ -1020,13 +1020,14 @@
 	return ret;
 }
 
-static void quota_over_flag_init_root(struct quota_root *root)
+static void quota_over_flag_init_root(struct quota_root *root,
+				      const char **quota_over_flag_r,
+				      bool *status_r)
 {
 	const char *name, *flag_mask;
 
-	if (root->quota_over_flag_initialized)
-		return;
-	root->quota_over_flag_initialized = TRUE;
+	*quota_over_flag_r = NULL;
+	*status_r = FALSE;
 
 	/* e.g.: quota_over_flag_value=TRUE or quota_over_flag_value=*  */
 	name = t_strconcat(root->set->set_name, "_over_flag_value", NULL);
@@ -1034,22 +1035,22 @@
 	if (flag_mask == NULL)
 		return;
 
-	/* compare quota_over_flag's value to quota_over_flag_value and
-	   save the result. */
+	/* compare quota_over_flag's value (that comes from userdb) to
+	   quota_over_flag_value and save the result. */
 	name = t_strconcat(root->set->set_name, "_over_flag", NULL);
-	root->quota_over_flag = p_strdup_empty(root->pool,
-		mail_user_plugin_getenv(root->quota->user, name));
-	root->quota_over_flag_status = root->quota_over_flag != NULL &&
-		wildcard_match_icase(root->quota_over_flag, flag_mask);
+	*quota_over_flag_r = mail_user_plugin_getenv(root->quota->user, name);
+	*status_r = *quota_over_flag_r != NULL &&
+		wildcard_match_icase(*quota_over_flag_r, flag_mask);
 }
 
 static void quota_over_flag_check_root(struct quota_root *root)
 {
-	const char *name, *overquota_script;
+	const char *name, *overquota_script, *quota_over_flag;
 	const char *const *resources;
 	unsigned int i;
 	uint64_t value, limit;
 	bool cur_overquota = FALSE;
+	bool quota_over_status;
 	int ret;
 
 	if (root->quota_over_flag_checked)
@@ -1066,7 +1067,7 @@
 		return;
 	}
 	root->quota_over_flag_checked = TRUE;
-	quota_over_flag_init_root(root);
+	quota_over_flag_init_root(root, &quota_over_flag, &quota_over_status);
 
 	resources = quota_root_get_resources(root);
 	for (i = 0; resources[i] != NULL; i++) {
@@ -1090,16 +1091,16 @@
 	}
 	if (root->quota->set->debug) {
 		i_debug("quota: quota_over_flag=%d(%s) vs currently overquota=%d",
-			root->quota_over_flag_status,
-			root->quota_over_flag == NULL ? "(null)" : root->quota_over_flag,
-			cur_overquota);
+			quota_over_status ? 1 : 0,
+			quota_over_flag == NULL ? "(null)" : quota_over_flag,
+			cur_overquota ? 1 : 0);
 	}
-	if (cur_overquota != root->quota_over_flag_status) {
+	if (cur_overquota != quota_over_status) {
 		name = t_strconcat(root->set->set_name, "_over_script", NULL);
 		overquota_script = mail_user_plugin_getenv(root->quota->user, name);
 		if (overquota_script != NULL) {
 			quota_warning_execute(root, overquota_script,
-					      root->quota_over_flag,
+					      quota_over_flag,
 					      "quota_over_flag mismatch");
 		}
 	}