dovecot-2.2: lib-dict: dict_init() now returns error string inst...

dovecot at dovecot.org dovecot at dovecot.org
Sat Oct 13 01:09:52 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/22c22d704422
changeset: 15218:22c22d704422
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Oct 13 01:09:37 2012 +0300
description:
lib-dict: dict_init() now returns error string instead of logging it

diffstat:

 src/auth/db-dict.c                          |   4 ++--
 src/dict/dict-connection.c                  |   7 ++++---
 src/lib-dict/dict-client.c                  |   7 ++++---
 src/lib-dict/dict-file.c                    |   5 +++--
 src/lib-dict/dict-memcached-ascii.c         |  14 +++++++++-----
 src/lib-dict/dict-memcached.c               |  15 ++++++++++-----
 src/lib-dict/dict-private.h                 |   2 +-
 src/lib-dict/dict-redis.c                   |  15 ++++++++++-----
 src/lib-dict/dict-sql-settings.c            |  13 ++++++-------
 src/lib-dict/dict-sql-settings.h            |   3 ++-
 src/lib-dict/dict-sql.c                     |   4 ++--
 src/lib-dict/dict.c                         |  28 ++++++++++++++++------------
 src/lib-dict/dict.h                         |   3 ++-
 src/lib-imap-urlauth/imap-urlauth-backend.c |   5 ++++-
 src/lib-storage/list/mailbox-list-fs-iter.c |   2 +-
 src/plugins/acl/acl-lookup-dict.c           |   6 +++---
 src/plugins/expire/doveadm-expire.c         |   7 ++++---
 src/plugins/expire/expire-plugin.c          |  10 ++++++----
 src/plugins/quota/quota-dict.c              |   7 +++++--
 19 files changed, 94 insertions(+), 63 deletions(-)

diffs (truncated from 504 to 300 lines):

diff -r 444a9921205a -r 22c22d704422 src/auth/db-dict.c
--- a/src/auth/db-dict.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/auth/db-dict.c	Sat Oct 13 01:09:37 2012 +0300
@@ -92,8 +92,8 @@
 			config_path, conn->set.value_format);
 	}
 	if (dict_init(conn->set.uri, DICT_DATA_TYPE_STRING, "",
-		      global_auth_settings->base_dir, &conn->dict) < 0)
-		i_fatal("dict %s: Failed to init dict", config_path);
+		      global_auth_settings->base_dir, &conn->dict, &error) < 0)
+		i_fatal("dict %s: Failed to init dict: %s", config_path, error);
 
 	conn->next = connections;
 	connections = conn;
diff -r 444a9921205a -r 22c22d704422 src/dict/dict-connection.c
--- a/src/dict/dict-connection.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/dict/dict-connection.c	Sat Oct 13 01:09:37 2012 +0300
@@ -68,7 +68,7 @@
 {
 	const char *const *strlist;
 	unsigned int i, count;
-	const char *uri;
+	const char *uri, *error;
 
 	strlist = array_get(&dict_settings->dicts, &count);
 	for (i = 0; i < count; i += 2) {
@@ -84,9 +84,10 @@
 	uri = strlist[i+1];
 
 	if (dict_init(uri, conn->value_type, conn->username,
-		      dict_settings->base_dir, &conn->dict) < 0) {
+		      dict_settings->base_dir, &conn->dict, &error) < 0) {
 		/* dictionary initialization failed */
-		i_error("Failed to initialize dictionary '%s'", conn->name);
+		i_error("Failed to initialize dictionary '%s': %s",
+			conn->name, error);
 		return -1;
 	}
 	return 0;
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-client.c
--- a/src/lib-dict/dict-client.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-client.c	Sat Oct 13 01:09:37 2012 +0300
@@ -466,7 +466,8 @@
 static int
 client_dict_init(struct dict *driver, const char *uri,
 		 enum dict_data_type value_type, const char *username,
-		 const char *base_dir, struct dict **dict_r)
+		 const char *base_dir, struct dict **dict_r,
+		 const char **error_r)
 {
 	struct client_dict *dict;
 	const char *dest_uri;
@@ -475,7 +476,7 @@
 	/* uri = [<path>] ":" <uri> */
 	dest_uri = strchr(uri, ':');
 	if (dest_uri == NULL) {
-		i_error("dict-client: Invalid URI: %s", uri);
+		*error_r = t_strdup_printf("Invalid URI: %s", uri);
 		return -1;
 	}
 
@@ -497,7 +498,7 @@
 	}
 	dict->uri = p_strdup(pool, dest_uri + 1);
 	*dict_r = &dict->dict;
-	return -1;
+	return 0;
 }
 
 static void client_dict_deinit(struct dict *_dict)
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-file.c
--- a/src/lib-dict/dict-file.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-file.c	Sat Oct 13 01:09:37 2012 +0300
@@ -55,7 +55,8 @@
 file_dict_init(struct dict *driver, const char *uri,
 	       enum dict_data_type value_type ATTR_UNUSED,
 	       const char *username ATTR_UNUSED,
-	       const char *base_dir ATTR_UNUSED, struct dict **dict_r)
+	       const char *base_dir ATTR_UNUSED, struct dict **dict_r,
+	       const char **error_r)
 {
 	struct file_dict *dict;
 	const char *p;
@@ -74,7 +75,7 @@
 		else if (strcmp(p, "lock=flock") == 0)
 			dict->lock_method = FILE_LOCK_METHOD_FLOCK;
 		else {
-			i_error("dict file: Invalid parameter: %s", p+1);
+			*error_r = t_strdup_printf("Invalid parameter: %s", p+1);
 			i_free(dict->path);
 			i_free(dict);
 			return -1;
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-memcached-ascii.c
--- a/src/lib-dict/dict-memcached-ascii.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-memcached-ascii.c	Sat Oct 13 01:09:37 2012 +0300
@@ -335,7 +335,7 @@
 			  enum dict_data_type value_type ATTR_UNUSED,
 			  const char *username,
 			  const char *base_dir ATTR_UNUSED,
-			  struct dict **dict_r)
+			  struct dict **dict_r, const char **error_r)
 {
 	struct memcached_ascii_dict *dict;
 	const char *const *args;
@@ -359,12 +359,14 @@
 	for (; *args != NULL; args++) {
 		if (strncmp(*args, "host=", 5) == 0) {
 			if (net_addr2ip(*args+5, &dict->ip) < 0) {
-				i_error("Invalid IP: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid IP: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "port=", 5) == 0) {
 			if (str_to_uint(*args+5, &dict->port) < 0) {
-				i_error("Invalid port: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid port: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "prefix=", 7) == 0) {
@@ -372,11 +374,13 @@
 			dict->key_prefix = i_strdup(*args + 7);
 		} else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
 			if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
-				i_error("Invalid timeout_msecs: %s", *args+14);
+				*error_r = t_strdup_printf(
+					"Invalid timeout_msecs: %s", *args+14);
 				ret = -1;
 			}
 		} else {
-			i_error("Unknown parameter: %s", *args);
+			*error_r = t_strdup_printf("Unknown parameter: %s",
+						   *args);
 			ret = -1;
 		}
 	}
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-memcached.c
--- a/src/lib-dict/dict-memcached.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-memcached.c	Sat Oct 13 01:09:37 2012 +0300
@@ -171,7 +171,8 @@
 memcached_dict_init(struct dict *driver, const char *uri,
 		    enum dict_data_type value_type ATTR_UNUSED,
 		    const char *username ATTR_UNUSED,
-		    const char *base_dir ATTR_UNUSED, struct dict **dict_r)
+		    const char *base_dir ATTR_UNUSED, struct dict **dict_r,
+		    const char **error_r)
 {
 	struct memcached_dict *dict;
 	const char *const *args;
@@ -194,12 +195,14 @@
 	for (; *args != NULL; args++) {
 		if (strncmp(*args, "host=", 5) == 0) {
 			if (net_addr2ip(*args+5, &dict->ip) < 0) {
-				i_error("Invalid IP: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid IP: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "port=", 5) == 0) {
 			if (str_to_uint(*args+5, &dict->port) < 0) {
-				i_error("Invalid port: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid port: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "prefix=", 7) == 0) {
@@ -207,11 +210,13 @@
 			dict->key_prefix = i_strdup(*args + 7);
 		} else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
 			if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
-				i_error("Invalid timeout_msecs: %s", *args+14);
+				*error_r = t_strdup_printf(
+					"Invalid timeout_msecs: %s", *args+14);
 				ret = -1;
 			}
 		} else {
-			i_error("Unknown parameter: %s", *args);
+			*error_r = t_strdup_printf("Unknown parameter: %s",
+						   *args);
 			ret = -1;
 		}
 	}
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-private.h
--- a/src/lib-dict/dict-private.h	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-private.h	Sat Oct 13 01:09:37 2012 +0300
@@ -7,7 +7,7 @@
 	int (*init)(struct dict *dict_driver, const char *uri,
 		    enum dict_data_type value_type,
 		    const char *username, const char *base_dir,
-		    struct dict **dict_r);
+		    struct dict **dict_r, const char **error_r);
 	void (*deinit)(struct dict *dict);
 	int (*wait)(struct dict *dict);
 
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-redis.c
--- a/src/lib-dict/dict-redis.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-redis.c	Sat Oct 13 01:09:37 2012 +0300
@@ -302,7 +302,8 @@
 redis_dict_init(struct dict *driver, const char *uri,
 		enum dict_data_type value_type ATTR_UNUSED,
 		const char *username,
-		const char *base_dir ATTR_UNUSED, struct dict **dict_r)
+		const char *base_dir ATTR_UNUSED, struct dict **dict_r,
+		const char **error_r)
 {
 	struct redis_dict *dict;
 	const char *const *args;
@@ -325,12 +326,14 @@
 	for (; *args != NULL; args++) {
 		if (strncmp(*args, "host=", 5) == 0) {
 			if (net_addr2ip(*args+5, &dict->ip) < 0) {
-				i_error("Invalid IP: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid IP: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "port=", 5) == 0) {
 			if (str_to_uint(*args+5, &dict->port) < 0) {
-				i_error("Invalid port: %s", *args+5);
+				*error_r = t_strdup_printf("Invalid port: %s",
+							   *args+5);
 				ret = -1;
 			}
 		} else if (strncmp(*args, "prefix=", 7) == 0) {
@@ -338,11 +341,13 @@
 			dict->key_prefix = i_strdup(*args + 7);
 		} else if (strncmp(*args, "timeout_msecs=", 14) == 0) {
 			if (str_to_uint(*args+14, &dict->timeout_msecs) < 0) {
-				i_error("Invalid timeout_msecs: %s", *args+14);
+				*error_r = t_strdup_printf(
+					"Invalid timeout_msecs: %s", *args+14);
 				ret = -1;
 			}
 		} else {
-			i_error("Unknown parameter: %s", *args);
+			*error_r = t_strdup_printf("Unknown parameter: %s",
+						   *args);
 			ret = -1;
 		}
 	}
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-sql-settings.c
--- a/src/lib-dict/dict-sql-settings.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-sql-settings.c	Sat Oct 13 01:09:37 2012 +0300
@@ -210,10 +210,10 @@
 	return FALSE;
 }
 
-struct dict_sql_settings *dict_sql_settings_read(pool_t pool, const char *path)
+struct dict_sql_settings *
+dict_sql_settings_read(pool_t pool, const char *path, const char **error_r)
 {
 	struct setting_parser_ctx ctx;
-	const char *error;
 
 	memset(&ctx, 0, sizeof(ctx));
 	ctx.pool = pool;
@@ -221,14 +221,13 @@
 	t_array_init(&ctx.cur_fields, 16);
 	p_array_init(&ctx.set->maps, pool, 8);
 
-	if (!settings_read(path, NULL, parse_setting, parse_section, &ctx, &error)) {
-		i_error("Error in configuration file %s: %s", path, error);
+	if (!settings_read(path, NULL, parse_setting, parse_section,
+			   &ctx, error_r))
 		return NULL;
-	}
 
 	if (ctx.set->connect == NULL) {
-		i_error("Error in configuration file %s: "
-			"Missing connect setting", path);
+		*error_r = t_strdup_printf("Error in configuration file %s: "
+					   "Missing connect setting", path);
 		return NULL;
 	}
 
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-sql-settings.h
--- a/src/lib-dict/dict-sql-settings.h	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-sql-settings.h	Sat Oct 13 01:09:37 2012 +0300
@@ -19,6 +19,7 @@
 	ARRAY(struct dict_sql_map) maps;
 };
 
-struct dict_sql_settings *dict_sql_settings_read(pool_t pool, const char *path);
+struct dict_sql_settings *
+dict_sql_settings_read(pool_t pool, const char *path, const char **error_r);
 
 #endif
diff -r 444a9921205a -r 22c22d704422 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c	Sat Oct 13 01:03:13 2012 +0300
+++ b/src/lib-dict/dict-sql.c	Sat Oct 13 01:09:37 2012 +0300
@@ -75,7 +75,7 @@
 sql_dict_init(struct dict *driver, const char *uri,
 	      enum dict_data_type value_type ATTR_UNUSED,
 	      const char *username, const char *base_dir ATTR_UNUSED,
-	      struct dict **dict_r)
+	      struct dict **dict_r, const char **error_r)
 {
 	struct sql_dict *dict;
 	pool_t pool;


More information about the dovecot-cvs mailing list