dovecot: Changed imap-parser API to use standard arrays for list...

dovecot at dovecot.org dovecot at dovecot.org
Sat Jun 30 00:48:20 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/9f869a7a3d73
changeset: 5836:9f869a7a3d73
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jun 29 19:15:39 2007 +0300
description:
Changed imap-parser API to use standard arrays for lists instead of its own
imap_arg_list struct.

diffstat:

13 files changed, 97 insertions(+), 126 deletions(-)
src/imap/cmd-append.c                      |    8 +-
src/imap/cmd-fetch.c                       |    2 
src/imap/cmd-list.c                        |    4 -
src/imap/cmd-sort.c                        |    2 
src/imap/cmd-status.c                      |    2 
src/imap/cmd-store.c                       |    2 
src/imap/imap-fetch-body.c                 |   26 ++++----
src/imap/imap-search.c                     |    2 
src/lib-imap/imap-bodystructure.c          |   18 ++---
src/lib-imap/imap-envelope.c               |   46 ++++++--------
src/lib-imap/imap-parser.c                 |   90 +++++++++-------------------
src/lib-imap/imap-parser.h                 |   19 +++--
src/plugins/imap-quota/imap-quota-plugin.c |    2 

diffs (truncated from 608 to 300 lines):

diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-append.c	Fri Jun 29 19:15:39 2007 +0300
@@ -84,7 +84,7 @@ static void client_input(struct client_c
    internal_date may be NULL as a result, but mailbox and msg_size are always
    set when successful. */
 static int validate_args(const struct imap_arg *args,
-			 const struct imap_arg_list **flags_r,
+			 const struct imap_arg **flags_r,
 			 const char **internal_date_r, uoff_t *msg_size_r,
 			 bool *nonsync_r)
 {
@@ -92,7 +92,7 @@ static int validate_args(const struct im
 	if (args->type != IMAP_ARG_LIST)
 		*flags_r = NULL;
 	else {
-		*flags_r = IMAP_ARG_LIST(args);
+		*flags_r = IMAP_ARG_LIST_ARGS(args);
 		args++;
 	}
 
@@ -201,7 +201,7 @@ static bool cmd_append_continue_parsing(
 	struct client *client = cmd->client;
 	struct cmd_append_context *ctx = cmd->context;
 	const struct imap_arg *args;
-	const struct imap_arg_list *flags_list;
+	const struct imap_arg *flags_list;
 	enum mail_flags flags;
 	const char *const *keywords_list;
 	struct mail_keywords *keywords;
@@ -294,7 +294,7 @@ static bool cmd_append_continue_parsing(
 	}
 
 	if (flags_list != NULL) {
-		if (!client_parse_mail_flags(cmd, flags_list->args,
+		if (!client_parse_mail_flags(cmd, flags_list,
 					     &flags, &keywords_list))
 			return cmd_append_cancel(ctx, nonsync);
 		keywords = keywords_list == NULL ? NULL :
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-fetch.c
--- a/src/imap/cmd-fetch.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-fetch.c	Fri Jun 29 19:15:39 2007 +0300
@@ -46,7 +46,7 @@ fetch_parse_args(struct imap_fetch_conte
 			}
 		}
 	} else {
-		arg = IMAP_ARG_LIST(arg)->args;
+		arg = IMAP_ARG_LIST_ARGS(arg);
 		while (arg->type == IMAP_ARG_ATOM) {
 			str = t_str_ucase(IMAP_ARG_STR(arg));
 			arg++;
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-list.c	Fri Jun 29 19:15:39 2007 +0300
@@ -721,7 +721,7 @@ bool _cmd_list_full(struct client_comman
 	if (args[0].type == IMAP_ARG_LIST && !lsub) {
 		/* LIST-EXTENDED selection options */
 		used_listext = TRUE;
-		if (!parse_select_flags(cmd, IMAP_ARG_LIST(&args[0])->args,
+		if (!parse_select_flags(cmd, IMAP_ARG_LIST_ARGS(&args[0]),
 					&list_flags))
 			return TRUE;
 		args++;
@@ -744,7 +744,7 @@ bool _cmd_list_full(struct client_comman
 	    strcasecmp(imap_arg_string(&args[0]), "RETURN") == 0) {
 		/* LIST-EXTENDED return options */
 		used_listext = TRUE;
-		if (!parse_return_flags(cmd, IMAP_ARG_LIST(&args[1])->args,
+		if (!parse_return_flags(cmd, IMAP_ARG_LIST_ARGS(&args[1]),
 					&list_flags))
 			return TRUE;
 		args += 2;
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-sort.c
--- a/src/imap/cmd-sort.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-sort.c	Fri Jun 29 19:15:39 2007 +0300
@@ -112,7 +112,7 @@ bool cmd_sort(struct client_command_cont
 		return TRUE;
 	}
 
-	if (get_sort_program(cmd, IMAP_ARG_LIST(args)->args, sorting) < 0)
+	if (get_sort_program(cmd, IMAP_ARG_LIST_ARGS(args), sorting) < 0)
 		return TRUE;
 	args++;
 
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-status.c
--- a/src/imap/cmd-status.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-status.c	Fri Jun 29 19:15:39 2007 +0300
@@ -99,7 +99,7 @@ bool cmd_status(struct client_command_co
 	}
 
 	/* get the items client wants */
-	items = get_status_items(cmd, IMAP_ARG_LIST(&args[1])->args);
+	items = get_status_items(cmd, IMAP_ARG_LIST_ARGS(&args[1]));
 	if (items == (enum mailbox_status_items)-1) {
 		/* error */
 		return TRUE;
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/cmd-store.c
--- a/src/imap/cmd-store.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/cmd-store.c	Fri Jun 29 19:15:39 2007 +0300
@@ -72,7 +72,7 @@ bool cmd_store(struct client_command_con
 
 	if (args[2].type == IMAP_ARG_LIST) {
 		if (!client_parse_mail_flags(cmd,
-					     IMAP_ARG_LIST(&args[2])->args,
+					     IMAP_ARG_LIST_ARGS(&args[2]),
 					     &flags, &keywords_list))
 			return TRUE;
 	} else {
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/imap-fetch-body.c
--- a/src/imap/imap-fetch-body.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/imap-fetch-body.c	Fri Jun 29 19:15:39 2007 +0300
@@ -724,7 +724,8 @@ static bool body_section_build(struct im
 static bool body_section_build(struct imap_fetch_context *ctx,
 			       struct imap_fetch_body_data *body,
 			       const char *prefix,
-			       const struct imap_arg_list *list)
+			       const struct imap_arg *args,
+			       unsigned int args_count)
 {
 	string_t *str;
 	const char **arr;
@@ -735,11 +736,11 @@ static bool body_section_build(struct im
 	str_append(str, " (");
 
 	/* @UNSAFE: NULL-terminated list of headers */
-	arr = p_new(ctx->cmd->pool, const char *, list->size + 1);
-
-	for (i = 0; i < list->size; i++) {
-		if (list->args[i].type != IMAP_ARG_ATOM &&
-		    list->args[i].type != IMAP_ARG_STRING) {
+	arr = p_new(ctx->cmd->pool, const char *, args_count + 1);
+
+	for (i = 0; i < args_count; i++) {
+		if (args[i].type != IMAP_ARG_ATOM &&
+		    args[i].type != IMAP_ARG_STRING) {
 			client_send_command_error(ctx->cmd,
 				"Invalid BODY[..] parameter: "
 				"Header list contains non-strings");
@@ -748,9 +749,9 @@ static bool body_section_build(struct im
 
 		if (i != 0)
 			str_append_c(str, ' ');
-		arr[i] = t_str_ucase(IMAP_ARG_STR(&list->args[i]));
-
-		if (list->args[i].type == IMAP_ARG_ATOM)
+		arr[i] = t_str_ucase(IMAP_ARG_STR(&args[i]));
+
+		if (args[i].type == IMAP_ARG_ATOM)
 			str_append(str, arr[i]);
 		else {
 			str_append_c(str, '"');
@@ -760,9 +761,9 @@ static bool body_section_build(struct im
 	}
 	str_append_c(str, ')');
 
-	qsort(arr, list->size, sizeof(*arr), strcasecmp_p);
+	qsort(arr, args_count, sizeof(*arr), strcasecmp_p);
 	body->fields = arr;
-	body->fields_count = list->size;
+	body->fields_count = args_count;
 	body->section = str_c(str);
 	return TRUE;
 }
@@ -799,7 +800,8 @@ bool fetch_body_section_init(struct imap
 			return FALSE;
 		}
 		if (!body_section_build(ctx, body, p+1,
-					IMAP_ARG_LIST(&(*args)[0])))
+					IMAP_ARG_LIST_ARGS(&(*args)[0]),
+					IMAP_ARG_LIST_COUNT(&(*args)[0])))
 			return FALSE;
 		p = IMAP_ARG_STR(&(*args)[1]);
 		*args += 2;
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/imap/imap-search.c
--- a/src/imap/imap-search.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/imap/imap-search.c	Fri Jun 29 19:15:39 2007 +0300
@@ -148,7 +148,7 @@ static bool search_arg_build(struct sear
 	}
 
 	if (arg->type == IMAP_ARG_LIST) {
-		const struct imap_arg *listargs = IMAP_ARG_LIST(arg)->args;
+		const struct imap_arg *listargs = IMAP_ARG_LIST_ARGS(arg);
 
 		if (listargs->type == IMAP_ARG_EOL) {
 			data->error = "Empty list not allowed";
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/lib-imap/imap-bodystructure.c
--- a/src/lib-imap/imap-bodystructure.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/lib-imap/imap-bodystructure.c	Fri Jun 29 19:15:39 2007 +0300
@@ -544,7 +544,7 @@ static bool imap_write_list(const struct
 			if (args->type != IMAP_ARG_LIST)
 				return FALSE;
 
-			if (!imap_write_list(IMAP_ARG_LIST(args)->args, str))
+			if (!imap_write_list(IMAP_ARG_LIST_ARGS(args), str))
 				return FALSE;
 		}
 		args++;
@@ -560,15 +560,15 @@ static bool imap_parse_bodystructure_arg
 					  string_t *str)
 {
 	const struct imap_arg *subargs;
-	const struct imap_arg_list *list;
+	const struct imap_arg *list_args;
 	bool multipart, text, message_rfc822;
 	int i;
 
 	multipart = FALSE;
 	while (args->type == IMAP_ARG_LIST) {
 		str_append_c(str, '(');
-		list = IMAP_ARG_LIST(args);
-		if (!imap_parse_bodystructure_args(list->args, str))
+		list_args = IMAP_ARG_LIST_ARGS(args);
+		if (!imap_parse_bodystructure_args(list_args, str))
 			return FALSE;
 		str_append_c(str, ')');
 
@@ -602,7 +602,7 @@ static bool imap_parse_bodystructure_arg
 	/* ("content type param key" "value" ...) | NIL */
 	if (args->type == IMAP_ARG_LIST) {
 		str_append(str, " (");
-                subargs = IMAP_ARG_LIST(args)->args;
+                subargs = IMAP_ARG_LIST_ARGS(args);
 		for (; subargs->type != IMAP_ARG_EOL; ) {
 			if (!str_append_imap_arg(str, &subargs[0]))
 				return FALSE;
@@ -647,14 +647,14 @@ static bool imap_parse_bodystructure_arg
 
 		str_append_c(str, ' ');
 
-		list = IMAP_ARG_LIST(&args[0]);
-		if (!imap_write_list(list->args, str))
+		list_args = IMAP_ARG_LIST_ARGS(&args[0]);
+		if (!imap_write_list(list_args, str))
 			return FALSE;
 
 		str_append(str, " (");
 
-		list = IMAP_ARG_LIST(&args[1]);
-		if (!imap_parse_bodystructure_args(list->args, str))
+		list_args = IMAP_ARG_LIST_ARGS(&args[1]);
+		if (!imap_parse_bodystructure_args(list_args, str))
 			return FALSE;
 
 		str_append(str, ") ");
diff -r d59ed6a31b66 -r 9f869a7a3d73 src/lib-imap/imap-envelope.c
--- a/src/lib-imap/imap-envelope.c	Fri Jun 29 19:03:45 2007 +0300
+++ b/src/lib-imap/imap-envelope.c	Fri Jun 29 19:15:39 2007 +0300
@@ -214,24 +214,26 @@ static bool imap_address_arg_append(cons
 static bool imap_address_arg_append(const struct imap_arg *arg, string_t *str,
 				    bool *in_group)
 {
-	const struct imap_arg_list *list;
+	const struct imap_arg *list_args;
+	unsigned int list_count;
 	const char *args[4];
 	int i;
 
 	if (arg->type != IMAP_ARG_LIST)
 		return FALSE;
-	list = IMAP_ARG_LIST(arg);
+	list_args = IMAP_ARG_LIST_ARGS(arg);
+	list_count = IMAP_ARG_LIST_COUNT(arg);
 
 	/* we require 4 arguments, strings or NILs */
-	if (list->size < 4)
+	if (list_count < 4)
 		return FALSE;
 
 	for (i = 0; i < 4; i++) {
-		if (list->args[i].type == IMAP_ARG_NIL)
+		if (list_args[i].type == IMAP_ARG_NIL)
 			args[i] = NULL;
-		else if (list->args[i].type == IMAP_ARG_STRING ||
-			 list->args[i].type == IMAP_ARG_ATOM)
-			args[i] = IMAP_ARG_STR(&list->args[i]);
+		else if (list_args[i].type == IMAP_ARG_STRING ||
+			 list_args[i].type == IMAP_ARG_ATOM)
+			args[i] = IMAP_ARG_STR(&list_args[i]);
 		else
 			return FALSE;
 	}
@@ -290,9 +292,8 @@ static bool imap_address_arg_append(cons
 
 static const char *imap_envelope_parse_address(const struct imap_arg *arg)
 {
-	const struct imap_arg_list *list;
+	const struct imap_arg *list_args;
 	string_t *str;
-	size_t i;
 	bool in_group;
 
 	if (arg->type != IMAP_ARG_LIST)
@@ -301,9 +302,9 @@ static const char *imap_envelope_parse_a
 	in_group = FALSE;
 	str = t_str_new(128);
 
-        list = IMAP_ARG_LIST(arg);
-	for (i = 0; i < list->size; i++) {
-		if (!imap_address_arg_append(&list->args[i], str, &in_group))
+	list_args = IMAP_ARG_LIST_ARGS(arg);


More information about the dovecot-cvs mailing list