changeset 10093:fdfe0236d50a HEAD

imap, pop3: Moved imap/pop3_client_workarounds setting parsing to config checking.
author Timo Sirainen <tss@iki.fi>
date Fri, 16 Oct 2009 17:46:31 -0400
parents 4d21bb0fff3a
children 634588d51ae6
files src/imap/cmd-subscribe.c src/imap/imap-client.h src/imap/imap-commands-util.c src/imap/imap-common.h src/imap/imap-fetch-body.c src/imap/imap-settings.c src/imap/imap-settings.h src/imap/imap-sync.c src/imap/main.c src/pop3/pop3-client.c src/pop3/pop3-client.h src/pop3/pop3-commands.c src/pop3/pop3-common.h src/pop3/pop3-settings.c src/pop3/pop3-settings.h
diffstat 15 files changed, 138 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-subscribe.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/cmd-subscribe.c	Fri Oct 16 17:46:31 2009 -0400
@@ -60,7 +60,8 @@
 		mailbox += strlen(ns->prefix);
 	}
 
-	if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+	if ((cmd->client->set->parsed_workarounds &
+	     		WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
 	    *mailbox != '\0' && mailbox[strlen(mailbox)-1] ==
 	    mailbox_list_get_hierarchy_sep(ns->list)) {
 		/* verify the validity without the trailing '/' */
--- a/src/imap/imap-client.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-client.h	Fri Oct 16 17:46:31 2009 -0400
@@ -95,7 +95,6 @@
 	struct timeout *to_idle, *to_idle_output;
 
         const struct imap_settings *set;
-	enum client_workarounds workarounds;
 	string_t *capability_string;
 
         struct mail_user *user;
--- a/src/imap/imap-commands-util.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-commands-util.c	Fri Oct 16 17:46:31 2009 -0400
@@ -46,7 +46,8 @@
 	}
 
 	mailbox_len = strlen(mailbox);
-	if ((cmd->client->workarounds & WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
+	if ((cmd->client->set->parsed_workarounds &
+	     		WORKAROUND_TB_EXTRA_MAILBOX_SEP) != 0 &&
 	    mailbox[mailbox_len-1] == mailbox_list_get_hierarchy_sep(ns->list)) {
 		/* drop the extra trailing hierarchy separator */
 		mailbox = t_strndup(mailbox, mailbox_len-1);
--- a/src/imap/imap-common.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-common.h	Fri Oct 16 17:46:31 2009 -0400
@@ -13,12 +13,6 @@
 /* Disconnect client when it sends too many bad commands in a row */
 #define CLIENT_MAX_BAD_COMMANDS 20
 
-enum client_workarounds {
-	WORKAROUND_DELAY_NEWMAIL		= 0x01,
-	WORKAROUND_NETSCAPE_EOH			= 0x04,
-	WORKAROUND_TB_EXTRA_MAILBOX_SEP		= 0x08
-};
-
 #include "lib.h"
 #include "imap-client.h"
 #include "imap-settings.h"
--- a/src/imap/imap-fetch-body.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-fetch-body.c	Fri Oct 16 17:46:31 2009 -0400
@@ -433,7 +433,7 @@
 	i_stream_seek(ctx->cur_input, old_offset);
 
 	if (!ctx->cur_have_eoh &&
-	    (ctx->client->workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
+	    (ctx->client->set->parsed_workarounds & WORKAROUND_NETSCAPE_EOH) != 0) {
 		/* Netscape 4.x doesn't like if end of headers line is
 		   missing. */
 		msg_size.virtual_size += 2;
--- a/src/imap/imap-settings.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-settings.c	Fri Oct 16 17:46:31 2009 -0400
@@ -9,6 +9,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+static bool imap_settings_verify(void *_set, pool_t pool,
+				 const char **error_r);
+
 #undef DEF
 #undef DEFLIST
 #define DEF(type, name) \
@@ -62,6 +65,59 @@
 	MEMBER(parent_offset) (size_t)-1,
 	MEMBER(type_offset) (size_t)-1,
 	MEMBER(struct_size) sizeof(struct imap_settings),
-	MEMBER(check_func) NULL,
+	MEMBER(check_func) imap_settings_verify,
 	MEMBER(dependencies) imap_setting_dependencies
 };
+
+/* <settings checks> */
+struct imap_client_workaround_list {
+	const char *name;
+	enum imap_client_workarounds num;
+};
+
+static struct imap_client_workaround_list imap_client_workaround_list[] = {
+	{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
+	{ "outlook-idle", 0 }, /* only for backwards compatibility */
+	{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
+	{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
+	{ NULL, 0 }
+};
+
+static int
+imap_settings_parse_workarounds(struct imap_settings *set,
+				const char **error_r)
+{
+        enum imap_client_workarounds client_workarounds = 0;
+        struct imap_client_workaround_list *list;
+	const char *const *str;
+
+        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
+	for (; *str != NULL; str++) {
+		list = imap_client_workaround_list;
+		for (; list->name != NULL; list++) {
+			if (strcasecmp(*str, list->name) == 0) {
+				client_workarounds |= list->num;
+				break;
+			}
+		}
+		if (list->name == NULL) {
+			*error_r = t_strdup_printf("imap_client_workarounds: "
+				"Unknown workaround: %s", *str);
+			return -1;
+		}
+	}
+	set->parsed_workarounds = client_workarounds;
+	return 0;
+}
+
+
+static bool
+imap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
+{
+	struct imap_settings *set = _set;
+
+	if (imap_settings_parse_workarounds(set, error_r) < 0)
+		return FALSE;
+	return TRUE;
+}
+/* </settings checks> */
--- a/src/imap/imap-settings.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-settings.h	Fri Oct 16 17:46:31 2009 -0400
@@ -3,6 +3,14 @@
 
 struct mail_user_settings;
 
+/* <settings checks> */
+enum imap_client_workarounds {
+	WORKAROUND_DELAY_NEWMAIL		= 0x01,
+	WORKAROUND_NETSCAPE_EOH			= 0x04,
+	WORKAROUND_TB_EXTRA_MAILBOX_SEP		= 0x08
+};
+/* </settings checks> */
+
 struct imap_settings {
 	bool mail_debug;
 	bool shutdown_clients;
@@ -15,6 +23,8 @@
 	const char *imap_logout_format;
 	const char *imap_id_send;
 	const char *imap_id_log;
+
+	enum imap_client_workarounds parsed_workarounds;
 };
 
 extern struct setting_parser_info imap_setting_parser_info;
--- a/src/imap/imap-sync.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/imap-sync.c	Fri Oct 16 17:46:31 2009 -0400
@@ -579,7 +579,7 @@
 	get_common_sync_flags(client, &flags, &imap_flags);
 	client->sync_counter++;
 
-	no_newmail = (client->workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
+	no_newmail = (client->set->parsed_workarounds & WORKAROUND_DELAY_NEWMAIL) != 0 &&
 		(imap_flags & IMAP_SYNC_FLAG_SAFE) == 0;
 	if (no_newmail) {
 		/* expunges might break the client just as badly as new mail
--- a/src/imap/main.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/imap/main.c	Fri Oct 16 17:46:31 2009 -0400
@@ -23,44 +23,8 @@
 #define IS_STANDALONE() \
         (getenv("CLIENT_INPUT") == NULL)
 
-struct client_workaround_list {
-	const char *name;
-	enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-	{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
-	{ "outlook-idle", 0 }, /* only for backwards compatibility */
-	{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
-	{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
-	{ NULL, 0 }
-};
-
 void (*hook_client_created)(struct client **client) = NULL;
 
-static enum client_workarounds
-parse_workarounds(const struct imap_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-        struct client_workaround_list *list;
-	const char *const *str;
-
-        str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
-	for (; *str != NULL; str++) {
-		list = client_workaround_list;
-		for (; list->name != NULL; list++) {
-			if (strcasecmp(*str, list->name) == 0) {
-				client_workarounds |= list->num;
-				break;
-			}
-		}
-		if (list->name == NULL)
-			i_fatal("Unknown client workaround: %s", *str);
-	}
-
-	return client_workarounds;
-}
-
 static void client_add_input(struct client *client, const char *input)
 {
 	buffer_t *buf;
@@ -122,7 +86,6 @@
 		master_service_set_die_with_master(master_service, TRUE);
 
 	client = client_create(0, 1, user, set);
-        client->workarounds = parse_workarounds(set);
 
 	if (dump_capability) {
 		printf("%s\n", str_c(client->capability_string));
--- a/src/pop3/pop3-client.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-client.c	Fri Oct 16 17:46:31 2009 -0400
@@ -35,17 +35,6 @@
    transaction. This allows the mailbox to become unlocked. */
 #define CLIENT_COMMIT_TIMEOUT_MSECS (10*1000)
 
-struct client_workaround_list {
-	const char *name;
-	enum client_workarounds num;
-};
-
-static struct client_workaround_list client_workaround_list[] = {
-	{ "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
-	{ "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
-	{ NULL, 0 }
-};
-
 static struct client *pop3_clients;
 
 static void client_input(struct client *client);
@@ -167,28 +156,6 @@
 	return FALSE;
 }
 
-static enum client_workarounds
-parse_workarounds(const struct pop3_settings *set)
-{
-        enum client_workarounds client_workarounds = 0;
-	struct client_workaround_list *list;
-	const char *const *str;
-
-        str = t_strsplit_spaces(set->pop3_client_workarounds, " ,");
-	for (; *str != NULL; str++) {
-		list = client_workaround_list;
-		for (; list->name != NULL; list++) {
-			if (strcasecmp(*str, list->name) == 0) {
-				client_workarounds |= list->num;
-				break;
-			}
-		}
-		if (list->name == NULL)
-			i_fatal("Unknown client workaround: %s", *str);
-	}
-	return client_workarounds;
-}
-
 static enum uidl_keys parse_uidl_keymask(const char *format)
 {
 	enum uidl_keys mask = 0;
@@ -281,7 +248,6 @@
 		return NULL;
 	}
 
-	client->workarounds = parse_workarounds(set);
 	client->uidl_keymask =
 		parse_uidl_keymask(client->mail_set->pop3_uidl_format);
 	if (client->uidl_keymask == 0)
--- a/src/pop3/pop3-client.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-client.h	Fri Oct 16 17:46:31 2009 -0400
@@ -52,7 +52,6 @@
 	/* settings: */
 	const struct pop3_settings *set;
 	const struct mail_storage_settings *mail_set;
-	enum client_workarounds workarounds;
 	enum uidl_keys uidl_keymask;
 
 	unsigned int disconnected:1;
--- a/src/pop3/pop3-commands.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-commands.c	Fri Oct 16 17:46:31 2009 -0400
@@ -321,7 +321,7 @@
 				add = '.';
 				break;
 			} else if (data[i] == '\0' &&
-				   (client->workarounds &
+				   (client->set->parsed_workarounds &
 				    WORKAROUND_OUTLOOK_NO_NULS) != 0) {
 				add = 0x80;
 				break;
@@ -360,7 +360,7 @@
 	}
 
 	if (!ctx->in_body &&
-	    (client->workarounds & WORKAROUND_OE_NS_EOH) != 0) {
+	    (client->set->parsed_workarounds & WORKAROUND_OE_NS_EOH) != 0) {
 		/* Add the missing end of headers line. */
 		(void)o_stream_send(client->output, "\r\n", 2);
 	}
--- a/src/pop3/pop3-common.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-common.h	Fri Oct 16 17:46:31 2009 -0400
@@ -1,11 +1,6 @@
 #ifndef POP3_COMMON_H
 #define POP3_COMMON_H
 
-enum client_workarounds {
-	WORKAROUND_OUTLOOK_NO_NULS		= 0x01,
-	WORKAROUND_OE_NS_EOH			= 0x02
-};
-
 enum uidl_keys {
 	UIDL_UIDVALIDITY	= 0x01,
 	UIDL_UID		= 0x02,
--- a/src/pop3/pop3-settings.c	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-settings.c	Fri Oct 16 17:46:31 2009 -0400
@@ -9,6 +9,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+static bool pop3_settings_verify(void *_set, pool_t pool,
+				 const char **error_r);
+
 #undef DEF
 #undef DEFLIST
 #define DEF(type, name) \
@@ -59,6 +62,56 @@
 	MEMBER(parent_offset) (size_t)-1,
 	MEMBER(type_offset) (size_t)-1,
 	MEMBER(struct_size) sizeof(struct pop3_settings),
-	MEMBER(check_func) NULL,
+	MEMBER(check_func) pop3_settings_verify,
 	MEMBER(dependencies) pop3_setting_dependencies
 };
+
+/* <settings checks> */
+struct pop3_client_workaround_list {
+	const char *name;
+	enum pop3_client_workarounds num;
+};
+
+static struct pop3_client_workaround_list pop3_client_workaround_list[] = {
+	{ "outlook-no-nuls", WORKAROUND_OUTLOOK_NO_NULS },
+	{ "oe-ns-eoh", WORKAROUND_OE_NS_EOH },
+	{ NULL, 0 }
+};
+
+static int
+pop3_settings_parse_workarounds(struct pop3_settings *set,
+				const char **error_r)
+{
+        enum pop3_client_workarounds client_workarounds = 0;
+	struct pop3_client_workaround_list *list;
+	const char *const *str;
+
+        str = t_strsplit_spaces(set->pop3_client_workarounds, " ,");
+	for (; *str != NULL; str++) {
+		list = pop3_client_workaround_list;
+		for (; list->name != NULL; list++) {
+			if (strcasecmp(*str, list->name) == 0) {
+				client_workarounds |= list->num;
+				break;
+			}
+		}
+		if (list->name == NULL) {
+			*error_r = t_strdup_printf("pop3_client_workarounds: "
+				"Unknown workaround: %s", *str);
+			return -1;
+		}
+	}
+	set->parsed_workarounds = client_workarounds;
+	return 0;
+}
+
+static bool
+pop3_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
+{
+	struct pop3_settings *set = _set;
+
+	if (pop3_settings_parse_workarounds(set, error_r) < 0)
+		return FALSE;
+	return TRUE;
+}
+/* </settings checks> */
--- a/src/pop3/pop3-settings.h	Sun Oct 18 15:33:13 2009 -0400
+++ b/src/pop3/pop3-settings.h	Fri Oct 16 17:46:31 2009 -0400
@@ -3,6 +3,13 @@
 
 struct mail_user_settings;
 
+/* <settings checks> */
+enum pop3_client_workarounds {
+	WORKAROUND_OUTLOOK_NO_NULS		= 0x01,
+	WORKAROUND_OE_NS_EOH			= 0x02
+};
+/* </settings checks> */
+
 struct pop3_settings {
 	bool mail_debug;
 	bool shutdown_clients;
@@ -15,6 +22,8 @@
 	bool pop3_lock_session;
 	const char *pop3_client_workarounds;
 	const char *pop3_logout_format;
+
+	enum pop3_client_workarounds parsed_workarounds;
 };
 
 extern struct setting_parser_info pop3_setting_parser_info;