dovecot-2.0-sslstream: Added "time" (interval) setting type, whi...

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:56:11 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/7215f4142901
changeset: 10283:7215f4142901
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 09 18:41:59 2009 -0500
description:
Added "time" (interval) setting type, which supports s/m/h/d/w suffixes.

diffstat:

10 files changed, 101 insertions(+), 32 deletions(-)
doc/example-config/conf.d/auth.conf        |   18 +++----
doc/example-config/conf.d/imap.conf        |    6 +-
doc/example-config/conf.d/mail.conf        |   14 ++---
src/auth/auth-settings.c                   |    8 +--
src/config/config-request.c                |    3 -
src/imap/imap-settings.c                   |    4 -
src/lib-settings/settings-parser.c         |   67 +++++++++++++++++++++++++++-
src/lib-settings/settings-parser.h         |    7 ++
src/lib-storage/index/mbox/mbox-settings.c |    4 -
src/lib-storage/mail-storage-settings.c    |    2 

diffs (truncated from 326 to 300 lines):

diff -r 4b663b9e63af -r 7215f4142901 doc/example-config/conf.d/auth.conf
--- a/doc/example-config/conf.d/auth.conf	Mon Nov 09 18:22:37 2009 -0500
+++ b/doc/example-config/conf.d/auth.conf	Mon Nov 09 18:41:59 2009 -0500
@@ -5,14 +5,14 @@
 # Authentication cache size (e.g. 10M). 0 means it's disabled. Note that
 # bsdauth, PAM and vpopmail require cache_key to be set for caching to be used.
 #auth_cache_size = 0
-# Time to live in seconds for cached data. After this many seconds the cached
-# record is no longer used, *except* if the main database lookup returns
-# internal failure. We also try to handle password changes automatically: If
-# user's previous authentication was successful, but this one wasn't, the
-# cache isn't used. For now this works only with plaintext authentication.
-#auth_cache_ttl = 3600
+# Time to live for cached data. After TTL expires the cached record is no
+# longer used, *except* if the main database lookup returns internal failure.
+# We also try to handle password changes automatically: If user's previous
+# authentication was successful, but this one wasn't, the cache isn't used.
+# For now this works only with plaintext authentication.
+#auth_cache_ttl = 1 hour
 # TTL for negative hits (user not found). 0 disables caching them completely.
-#auth_cache_negative_ttl = 3600
+#auth_cache_negative_ttl = 1 hour
 
 # Space separated list of realms for SASL authentication mechanisms that need
 # them. You can leave it empty if you don't want to support multiple realms.
@@ -72,8 +72,8 @@
 # Path for Samba's ntlm_auth helper binary.
 #auth_winbind_helper_path = /usr/bin/ntlm_auth
 
-# Number of seconds to delay before replying to failed authentications.
-#auth_failure_delay = 2
+# Time to delay before replying to failed authentications.
+#auth_failure_delay = 2 secs
 
 # Require a valid SSL client certificate or the authentication fails.
 #auth_ssl_require_client_cert = no
diff -r 4b663b9e63af -r 7215f4142901 doc/example-config/conf.d/imap.conf
--- a/doc/example-config/conf.d/imap.conf	Mon Nov 09 18:22:37 2009 -0500
+++ b/doc/example-config/conf.d/imap.conf	Mon Nov 09 18:41:59 2009 -0500
@@ -23,9 +23,9 @@ protocol imap {
   # Override the IMAP CAPABILITY response.
   #imap_capability = 
 
-  # How many seconds to wait between "OK Still here" notifications when
-  # client is IDLEing.
-  #imap_idle_notify_interval = 120
+  # How long to wait between "OK Still here" notifications when client is
+  # IDLEing.
+  #imap_idle_notify_interval = 2 mins
 
   # ID field names and values to send to clients. Using * as the value makes
   # Dovecot use the default value. The following fields have default values
diff -r 4b663b9e63af -r 7215f4142901 doc/example-config/conf.d/mail.conf
--- a/doc/example-config/conf.d/mail.conf	Mon Nov 09 18:22:37 2009 -0500
+++ b/doc/example-config/conf.d/mail.conf	Mon Nov 09 18:41:59 2009 -0500
@@ -208,9 +208,9 @@
 
 # When IDLE command is running, mailbox is checked once in a while to see if
 # there are any new mails or other changes. This setting defines the minimum
-# time in seconds to wait between those checks. Dovecot can also use dnotify,
-# inotify and kqueue to find out immediately when changes occur.
-#mailbox_idle_check_interval = 30
+# time to wait between those checks. Dovecot can also use dnotify, inotify and
+# kqueue to find out immediately when changes occur.
+#mailbox_idle_check_interval = 30 secs
 
 # Save mails with CR+LF instead of plain LF. This makes sending those mails
 # take less CPU, especially with sendfile() syscall with Linux and FreeBSD.
@@ -267,12 +267,12 @@
 #mbox_read_locks = fcntl
 #mbox_write_locks = dotlock fcntl
 
-# Maximum time in seconds to wait for lock (all of them) before aborting.
-#mbox_lock_timeout = 300
+# Maximum time to wait for lock (all of them) before aborting.
+#mbox_lock_timeout = 5 mins
 
 # If dotlock exists but the mailbox isn't modified in any way, override the
-# lock file after this many seconds.
-#mbox_dotlock_change_timeout = 120
+# lock file after this much time.
+#mbox_dotlock_change_timeout = 2 mins
 
 # When mbox changes unexpectedly we have to fully read it to find out what
 # changed. If the mbox is large this can take a long time. Since the change
diff -r 4b663b9e63af -r 7215f4142901 src/auth/auth-settings.c
--- a/src/auth/auth-settings.c	Mon Nov 09 18:22:37 2009 -0500
+++ b/src/auth/auth-settings.c	Mon Nov 09 18:41:59 2009 -0500
@@ -152,8 +152,8 @@ static const struct setting_define auth_
 	DEF(SET_STR, realms),
 	DEF(SET_STR, default_realm),
 	DEF(SET_SIZE, cache_size),
-	DEF(SET_UINT, cache_ttl),
-	DEF(SET_UINT, cache_negative_ttl),
+	DEF(SET_TIME, cache_ttl),
+	DEF(SET_TIME, cache_negative_ttl),
 	DEF(SET_STR, username_chars),
 	DEF(SET_STR, username_translation),
 	DEF(SET_STR, username_format),
@@ -162,7 +162,7 @@ static const struct setting_define auth_
 	DEF(SET_STR, krb5_keytab),
 	DEF(SET_STR, gssapi_hostname),
 	DEF(SET_STR, winbind_helper_path),
-	DEF(SET_UINT, failure_delay),
+	DEF(SET_TIME, failure_delay),
 
 	DEF(SET_BOOL, verbose),
 	DEF(SET_BOOL, debug),
@@ -184,7 +184,7 @@ static const struct auth_settings auth_d
 	MEMBER(realms) "",
 	MEMBER(default_realm) "",
 	MEMBER(cache_size) 0,
-	MEMBER(cache_ttl) 3600,
+	MEMBER(cache_ttl) 60*60,
 	MEMBER(cache_negative_ttl) 0,
 	MEMBER(username_chars) "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@",
 	MEMBER(username_translation) "",
diff -r 4b663b9e63af -r 7215f4142901 src/config/config-request.c
--- a/src/config/config-request.c	Mon Nov 09 18:22:37 2009 -0500
+++ b/src/config/config-request.c	Mon Nov 09 18:41:59 2009 -0500
@@ -136,7 +136,8 @@ settings_export(struct settings_export_c
 			}
 			break;
 		}
-		case SET_UINT: {
+		case SET_UINT:
+		case SET_TIME: {
 			const unsigned int *val = value, *dval = default_value;
 			if (dump_default || dval == NULL || *val != *dval)
 				str_printfa(ctx->value, "%u", *val);
diff -r 4b663b9e63af -r 7215f4142901 src/imap/imap-settings.c
--- a/src/imap/imap-settings.c	Mon Nov 09 18:22:37 2009 -0500
+++ b/src/imap/imap-settings.c	Mon Nov 09 18:41:59 2009 -0500
@@ -63,7 +63,7 @@ static const struct setting_define imap_
 	DEF(SET_BOOL, verbose_proctitle),
 
 	DEF(SET_SIZE, imap_max_line_length),
-	DEF(SET_UINT, imap_idle_notify_interval),
+	DEF(SET_TIME, imap_idle_notify_interval),
 	DEF(SET_STR, imap_capability),
 	DEF(SET_STR, imap_client_workarounds),
 	DEF(SET_STR, imap_logout_format),
@@ -81,7 +81,7 @@ static const struct imap_settings imap_d
 	   break large message sets to multiple commands, so we're pretty
 	   liberal by default. */
 	MEMBER(imap_max_line_length) 64*1024,
-	MEMBER(imap_idle_notify_interval) 120,
+	MEMBER(imap_idle_notify_interval) 2*60,
 	MEMBER(imap_capability) "",
 	MEMBER(imap_client_workarounds) "outlook-idle",
 	MEMBER(imap_logout_format) "bytes=%i/%o",
diff -r 4b663b9e63af -r 7215f4142901 src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Mon Nov 09 18:22:37 2009 -0500
+++ b/src/lib-settings/settings-parser.c	Mon Nov 09 18:41:59 2009 -0500
@@ -310,6 +310,62 @@ get_uint(struct setting_parser_context *
 }
 
 static int
+get_time(struct setting_parser_context *ctx, const char *value,
+	 unsigned int *result_r)
+{
+	unsigned int num, multiply;
+	char *p;
+
+	num = strtoull(value, &p, 10);
+	while (*p == ' ') p++;
+	switch (i_toupper(*p)) {
+	case '\0':
+		multiply = 1;
+		break;
+	case 'S':
+		multiply = 1;
+		if (strncasecmp(p, "secs", strlen(p)) == 0)
+			p = "";
+		break;
+	case 'M':
+		multiply = 60;
+		if (strncasecmp(p, "mins", strlen(p)) == 0)
+			p = "";
+		break;
+	case 'H':
+		multiply = 60*60;
+		if (strncasecmp(p, "hours", strlen(p)) == 0)
+			p = "";
+		break;
+	case 'D':
+		multiply = 60*60*24;
+		if (strncasecmp(p, "days", strlen(p)) == 0)
+			p = "";
+		break;
+	case 'W':
+		multiply = 60*60*24*7;
+		if (strncasecmp(p, "weeks", strlen(p)) == 0)
+			p = "";
+		break;
+	}
+
+	if (*p != '\0') {
+		ctx->error = p_strconcat(ctx->parser_pool,
+					 "Invalid time interval: ",
+					 value, NULL);
+		return -1;
+	}
+	if (num > -1U / multiply) {
+		ctx->error = p_strconcat(ctx->parser_pool,
+					 "Time interval is too large: ",
+					 value, NULL);
+		return -1;
+	}
+	*result_r = num * multiply;
+	return 0;
+}
+
+static int
 get_size(struct setting_parser_context *ctx, const char *value,
 	 uoff_t *result_r)
 {
@@ -317,6 +373,7 @@ get_size(struct setting_parser_context *
 	char *p;
 
 	num = strtoull(value, &p, 10);
+	while (*p == ' ') p++;
 	switch (i_toupper(*p)) {
 	case '\0':
 		multiply = 1;
@@ -502,6 +559,10 @@ settings_parse(struct setting_parser_con
 		break;
 	case SET_UINT:
 		if (get_uint(ctx, value, (unsigned int *)ptr) < 0)
+			return -1;
+		break;
+	case SET_TIME:
+		if (get_time(ctx, value, (unsigned int *)ptr) < 0)
 			return -1;
 		break;
 	case SET_SIZE:
@@ -962,6 +1023,7 @@ settings_var_expand_info(const struct se
 		switch (def->type) {
 		case SET_BOOL:
 		case SET_UINT:
+		case SET_TIME:
 		case SET_SIZE:
 		case SET_STR:
 		case SET_ENUM:
@@ -1032,6 +1094,7 @@ bool settings_vars_have_key(const struct
 		switch (def->type) {
 		case SET_BOOL:
 		case SET_UINT:
+		case SET_TIME:
 		case SET_SIZE:
 		case SET_STR:
 		case SET_ENUM:
@@ -1100,7 +1163,8 @@ setting_copy(enum setting_type type, con
 		*dest_bool = *src_bool;
 		break;
 	}
-	case SET_UINT: {
+	case SET_UINT:
+	case SET_TIME: {
 		const unsigned int *src_uint = src;
 		unsigned int *dest_uint = dest;
 
@@ -1208,6 +1272,7 @@ settings_changes_dup(const struct settin
 		switch (def->type) {
 		case SET_BOOL:
 		case SET_UINT:
+		case SET_TIME:
 		case SET_SIZE:
 		case SET_STR_VARS:
 		case SET_STR:
diff -r 4b663b9e63af -r 7215f4142901 src/lib-settings/settings-parser.h
--- a/src/lib-settings/settings-parser.h	Mon Nov 09 18:22:37 2009 -0500
+++ b/src/lib-settings/settings-parser.h	Mon Nov 09 18:41:59 2009 -0500
@@ -19,6 +19,7 @@ enum setting_type {
 enum setting_type {
 	SET_BOOL,
 	SET_UINT,
+	SET_TIME,
 	SET_SIZE,
 	SET_STR,
 	SET_STR_VARS, /* string with %variables */
@@ -51,6 +52,10 @@ struct setting_define {
 #define SETTING_DEFINE_STRUCT_SIZE(name, struct_name) \
 	{ SET_SIZE + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \
 		((struct struct_name *)0)->name, uoff_t), \
+	  #name, offsetof(struct struct_name, name), NULL }
+#define SETTING_DEFINE_STRUCT_TIME(name, struct_name) \
+	{ SET_TIME + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \
+		((struct struct_name *)0)->name, unsigned int), \
 	  #name, offsetof(struct struct_name, name), NULL }
 #define SETTING_DEFINE_STRUCT_STR(name, struct_name) \
 	{ SET_STR + COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE( \
@@ -190,7 +195,5 @@ int settings_parser_apply_changes(struct
 
 /* Return section name escaped */
 const char *settings_section_escape(const char *name);
-/* Parse a size string to actual size. */
-int settings_parse_size(const char *str, uoff_t *size_r, const char **error_r);
 
 #endif


More information about the dovecot-cvs mailing list