dovecot-2.0: lib-settings: settings_get_time/size() are now public.

dovecot at dovecot.org dovecot at dovecot.org
Mon Dec 14 02:54:25 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/3bcd4697a7cc
changeset: 10466:3bcd4697a7cc
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Dec 13 19:54:20 2009 -0500
description:
lib-settings: settings_get_time/size() are now public.

diffstat:

2 files changed, 26 insertions(+), 22 deletions(-)
src/lib-settings/settings-parser.c |   42 +++++++++++++++++-------------------
src/lib-settings/settings-parser.h |    6 +++++

diffs (120 lines):

diff -r 46691becc45e -r 3bcd4697a7cc src/lib-settings/settings-parser.c
--- a/src/lib-settings/settings-parser.c	Sun Dec 13 19:50:58 2009 -0500
+++ b/src/lib-settings/settings-parser.c	Sun Dec 13 19:54:20 2009 -0500
@@ -309,14 +309,13 @@ get_uint(struct setting_parser_context *
 	return 0;
 }
 
-static int
-get_time(struct setting_parser_context *ctx, const char *value,
-	 unsigned int *result_r)
+int settings_get_time(const char *str, unsigned int *secs_r,
+		      const char **error_r)
 {
 	unsigned int num, multiply = 1;
 	char *p;
 
-	num = strtoull(value, &p, 10);
+	num = strtoull(str, &p, 10);
 	while (*p == ' ') p++;
 	switch (i_toupper(*p)) {
 	case 'S':
@@ -347,29 +346,25 @@ get_time(struct setting_parser_context *
 	}
 
 	if (*p != '\0') {
-		ctx->error = p_strconcat(ctx->parser_pool,
-					 "Invalid time interval: ",
-					 value, NULL);
+		*error_r = t_strconcat("Invalid time interval: ", str, NULL);
 		return -1;
 	}
 	if (num > -1U / multiply) {
-		ctx->error = p_strconcat(ctx->parser_pool,
-					 "Time interval is too large: ",
-					 value, NULL);
+		*error_r = t_strconcat("Time interval is too large: ",
+				       str, NULL);
 		return -1;
 	}
-	*result_r = num * multiply;
+	*secs_r = num * multiply;
 	return 0;
 }
 
-static int
-get_size(struct setting_parser_context *ctx, const char *value,
-	 uoff_t *result_r)
+int settings_get_size(const char *str, uoff_t *bytes_r,
+		      const char **error_r)
 {
 	unsigned long long num, multiply = 1;
 	char *p;
 
-	num = strtoull(value, &p, 10);
+	num = strtoull(str, &p, 10);
 	while (*p == ' ') p++;
 	switch (i_toupper(*p)) {
 	case 'B':
@@ -402,16 +397,14 @@ get_size(struct setting_parser_context *
 			p++;
 	}
 	if (*p != '\0') {
-		ctx->error = p_strconcat(ctx->parser_pool, "Invalid size: ",
-					 value, NULL);
+		*error_r = t_strconcat("Invalid size: ", str, NULL);
 		return -1;
 	}
 	if (num > -1ULL / multiply) {
-		ctx->error = p_strconcat(ctx->parser_pool,
-					 "Size is too large: ", value, NULL);
+		*error_r = t_strconcat("Size is too large: ", str, NULL);
 		return -1;
 	}
-	*result_r = num * multiply;
+	*bytes_r = num * multiply;
 	return 0;
 }
 
@@ -518,6 +511,7 @@ settings_parse(struct setting_parser_con
 	       const char *key, const char *value)
 {
         void *ptr, *ptr2, *change_ptr;
+	const char *error;
 
 	ctx->prev_info = link->info;
 
@@ -556,12 +550,16 @@ settings_parse(struct setting_parser_con
 			return -1;
 		break;
 	case SET_TIME:
-		if (get_time(ctx, value, (unsigned int *)ptr) < 0)
+		if (settings_get_time(value, (unsigned int *)ptr, &error) < 0) {
+			ctx->error = p_strdup(ctx->parser_pool, error);
 			return -1;
+		}
 		break;
 	case SET_SIZE:
-		if (get_size(ctx, value, (uoff_t *)ptr) < 0)
+		if (settings_get_size(value, (uoff_t *)ptr, &error) < 0) {
+			ctx->error = p_strdup(ctx->parser_pool, error);
 			return -1;
+		}
 		break;
 	case SET_STR:
 		*((char **)ptr) = p_strdup(ctx->set_pool, value);
diff -r 46691becc45e -r 3bcd4697a7cc src/lib-settings/settings-parser.h
--- a/src/lib-settings/settings-parser.h	Sun Dec 13 19:50:58 2009 -0500
+++ b/src/lib-settings/settings-parser.h	Sun Dec 13 19:54:20 2009 -0500
@@ -195,5 +195,11 @@ int settings_parser_apply_changes(struct
 
 /* Return section name escaped */
 const char *settings_section_escape(const char *name);
+/* Parse time interval string, return as seconds. */
+int settings_get_time(const char *str, unsigned int *secs_r,
+		      const char **error_r);
+/* Parse size string, return as bytes. */
+int settings_get_size(const char *str, uoff_t *bytes_r,
+		      const char **error_r);
 
 #endif


More information about the dovecot-cvs mailing list