dovecot-2.0-pigeonhole: ManageSieve: dump_capability: simplified...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Wed May 5 21:22:03 EEST 2010


details:   http://hg.rename-it.nl/dovecot-2.0-pigeonhole/rev/fbd34455f628
changeset: 1275:fbd34455f628
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Wed May 05 20:21:50 2010 +0200
description:
ManageSieve: dump_capability: simplified settings acquisition.

diffstat:

 src/managesieve-login/managesieve-login-settings.c |  27 ++++++++-----
 src/managesieve/managesieve-capabilities.c         |  47 +++--------------------
 2 files changed, 22 insertions(+), 52 deletions(-)

diffs (166 lines):

diff -r 0567bd2a6a38 -r fbd34455f628 src/managesieve-login/managesieve-login-settings.c
--- a/src/managesieve-login/managesieve-login-settings.c	Wed May 05 19:39:26 2010 +0200
+++ b/src/managesieve-login/managesieve-login-settings.c	Wed May 05 20:21:50 2010 +0200
@@ -183,7 +183,7 @@
 	}
 }
 
-static void capability_dump(void)
+static bool capability_dump(void)
 {
 	char buf[4096];
 	int fd[2], status;
@@ -193,7 +193,7 @@
 
 	if ( pipe(fd) < 0 ) {
 		i_error("managesieve-login: dump-capability pipe() failed: %m");
-		return;
+		return FALSE;
 	}
 	fd_close_on_exec(fd[0], TRUE);
 	fd_close_on_exec(fd[1], TRUE);
@@ -201,7 +201,7 @@
 	if ( (pid = fork()) == (pid_t)-1 ) {
 		(void)close(fd[0]); (void)close(fd[1]);
 		i_error("managesieve-login: dump-capability fork() failed: %m");
-		return;
+		return FALSE;
 	}
 
 	if ( pid == 0 ) {
@@ -228,7 +228,7 @@
 	if (wait(&status) == -1) {
 		i_error("managesieve-login: dump-capability failed: process %d got stuck", 
 			(int)pid);
-		return;
+		return FALSE;
 	}
 	alarm(0);
 
@@ -241,7 +241,7 @@
 			i_error("managesieve-login: dump-capability process returned %d",
 				WIFEXITED(status) ? WEXITSTATUS(status) : status);
 		}
-		return;
+		return FALSE;
 	}
 
 	pos = 0;
@@ -251,18 +251,20 @@
 	if (ret < 0) {
 		i_error("managesieve-login: read(dump-capability process) failed: %m");
 		(void)close(fd[0]);
-		return;
+		return FALSE;
 	}
 	(void)close(fd[0]);
 
 	if (pos == 0 || buf[pos-1] != '\n') {
 		i_error("managesieve-login: dump-capability: Couldn't read capability "
 			"(got %u bytes)", pos);
-		return;
+		return FALSE;
 	}
 	buf[pos-1] = '\0';
 
 	capability_parse(buf);
+
+	return TRUE;
 }
 
 /* <settings checks> */
@@ -271,13 +273,16 @@
 {
 	struct managesieve_login_settings *set = _set;
 
-	if ( capability_sieve == NULL )
-		capability_dump();
+	if ( capability_sieve == NULL ) {
+		if ( !capability_dump() ) {
+			capability_sieve = "";
+		}
+	}
 
-	if ( *set->managesieve_sieve_capability == '\0' )
+	if ( *set->managesieve_sieve_capability == '\0' && capability_sieve != NULL )
 		set->managesieve_sieve_capability = capability_sieve;
 
-	if ( *set->managesieve_notify_capability == '\0' )
+	if ( *set->managesieve_notify_capability == '\0' && capability_notify != NULL )
 		set->managesieve_notify_capability = capability_notify;
 	
 	return TRUE;
diff -r 0567bd2a6a38 -r fbd34455f628 src/managesieve/managesieve-capabilities.c
--- a/src/managesieve/managesieve-capabilities.c	Wed May 05 19:39:26 2010 +0200
+++ b/src/managesieve/managesieve-capabilities.c	Wed May 05 20:21:50 2010 +0200
@@ -57,45 +57,15 @@
 
 static struct master_service_settings_cache *set_cache;
 
-static struct plugin_settings *
-plugin_settings_read(pool_t pool, void ***other_settings_r)
+static struct plugin_settings *plugin_settings_read(void)
 {
-	struct master_service_settings_input input;
 	const char *error;
-	const struct setting_parser_context *parser;
-	void *const *cache_sets;
-	void **sets;
-	unsigned int i, count;
 
-	memset(&input, 0, sizeof(input));
-	input.roots = plugin_set_roots;
-	input.module = "managesieve";
-	input.service = "managesieve";
+	if (master_service_settings_read_simple(master_service, plugin_set_roots, &error) < 0)
+		i_fatal("Error reading configuration: %s", error);
 
-	if (set_cache == NULL) {
-		set_cache = master_service_settings_cache_init
-			(master_service, input.module, input.service);
-	}
-
-	if (master_service_settings_cache_read(set_cache, &input, NULL,
-					       &parser, &error) < 0)
-		i_fatal("dump-capability: Error reading configuration: %s", error);
-
-	cache_sets = settings_parser_get_list(parser) + 1;
-	for (count = 0; input.roots[count] != NULL; count++) ;
-	i_assert(cache_sets[count] == NULL);
-	sets = p_new(pool, void *, count + 1);
-	for (i = 0; i < count; i++) {
-		sets[i] = settings_dup(input.roots[i], cache_sets[i], pool);
-		if (!settings_check(input.roots[i], pool, sets[i], &error)) {
-			const char *name = input.roots[i]->module_name;
-			i_fatal("dump-capability: settings_check(%s) failed: %s",
-				name != NULL ? name : "unknown", error);
-		}
-	}
-
-	*other_settings_r = sets + 1;
-	return sets[0];
+	return (struct plugin_settings *)
+		master_service_settings_get_others(master_service)[0];
 }
 
 static const char *plugin_settings_get
@@ -150,18 +120,13 @@
 
 void managesieve_capabilities_dump(void)
 {
-	pool_t set_pool;
 	const struct plugin_settings *global_plugin_settings;
-	void **global_other_settings;
 	struct sieve_instance *svinst;
 	const char *extensions, *notify_cap;
 	
 	/* Read plugin settings */
 
-	set_pool = pool_alloconly_create("global plugin settings", 4096);
-
-	global_plugin_settings = plugin_settings_read
-		(set_pool, &global_other_settings);
+	global_plugin_settings = plugin_settings_read();
 
 	/* Initialize Sieve engine */
 


More information about the dovecot-cvs mailing list