dovecot-2.0: doveconf: Quote output values when necessary.

dovecot at dovecot.org dovecot at dovecot.org
Thu Sep 2 19:01:04 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/31387c9d5b88
changeset: 12067:31387c9d5b88
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Sep 02 17:01:00 2010 +0100
description:
doveconf: Quote output values when necessary.

diffstat:

 src/config/config-parser.c |   2 --
 src/config/config-parser.h |   2 ++
 src/config/doveconf.c      |  23 ++++++++++++++++++++++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diffs (71 lines):

diff -r 4d8b54fc4ef5 -r 31387c9d5b88 src/config/config-parser.c
--- a/src/config/config-parser.c	Thu Sep 02 15:53:08 2010 +0100
+++ b/src/config/config-parser.c	Thu Sep 02 17:01:00 2010 +0100
@@ -26,8 +26,6 @@
 #  define GLOB_BRACE 0
 #endif
 
-#define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
-
 static const enum settings_parser_flags settings_parser_flags =
 	SETTINGS_PARSER_FLAG_IGNORE_UNKNOWN_KEYS |
 	SETTINGS_PARSER_FLAG_TRACK_CHANGES;
diff -r 4d8b54fc4ef5 -r 31387c9d5b88 src/config/config-parser.h
--- a/src/config/config-parser.h	Thu Sep 02 15:53:08 2010 +0100
+++ b/src/config/config-parser.h	Thu Sep 02 17:01:00 2010 +0100
@@ -3,6 +3,8 @@
 
 #define CONFIG_MODULE_DIR MODULEDIR"/settings"
 
+#define IS_WHITE(c) ((c) == ' ' || (c) == '\t')
+
 struct config_module_parser {
 	const struct setting_parser_info *root;
 	struct setting_parser_context *parser;
diff -r 4d8b54fc4ef5 -r 31387c9d5b88 src/config/doveconf.c
--- a/src/config/doveconf.c	Thu Sep 02 15:53:08 2010 +0100
+++ b/src/config/doveconf.c	Thu Sep 02 17:01:00 2010 +0100
@@ -7,6 +7,7 @@
 #include "env-util.h"
 #include "ostream.h"
 #include "str.h"
+#include "strescape.h"
 #include "settings-parser.h"
 #include "master-service.h"
 #include "all-settings.h"
@@ -146,6 +147,20 @@
 	pool_unref(&ctx->pool);
 }
 
+static bool value_need_quote(const char *value)
+{
+	unsigned int len = strlen(value);
+
+	if (len == 0)
+		return FALSE;
+
+	if (strchr(value, '#') != NULL)
+		return TRUE;
+	if (IS_WHITE(value[0]) || IS_WHITE(value[len-1]))
+		return TRUE;
+	return FALSE;
+}
+
 static int
 config_dump_human_output(struct config_dump_human_context *ctx,
 			 struct ostream *output, unsigned int indent,
@@ -271,7 +286,13 @@
 		value = strchr(key, '=');
 		o_stream_send(output, key, value-key);
 		o_stream_send_str(output, " = ");
-		o_stream_send_str(output, value+1);
+		if (!value_need_quote(value+1))
+			o_stream_send_str(output, value+1);
+		else {
+			o_stream_send(output, "\"", 1);
+			o_stream_send_str(output, str_escape(value+1));
+			o_stream_send(output, "\"", 1);
+		}
 		o_stream_send(output, "\n", 1);
 	end: ;
 	} T_END;


More information about the dovecot-cvs mailing list