dovecot-2.0: lib-imap: Changed imap_arg accessing APIs.

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 5 07:55:01 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/dbc864c0cff7
changeset: 11063:dbc864c0cff7
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 05 07:54:55 2010 +0300
description:
lib-imap: Changed imap_arg accessing APIs.
The new one is easier for both coders and static analyzers.

diffstat:

 src/imap-login/client-authenticate.c       |   33 ++---
 src/imap-login/client.c                    |    9 +-
 src/imap/cmd-append.c                      |   14 +-
 src/imap/cmd-cancelupdate.c                |   11 +-
 src/imap/cmd-enable.c                      |    6 +-
 src/imap/cmd-expunge.c                     |    3 +-
 src/imap/cmd-fetch.c                       |   35 ++---
 src/imap/cmd-list.c                        |   70 +++++------
 src/imap/cmd-search.c                      |   13 +-
 src/imap/cmd-select.c                      |  125 +++++++++++---------
 src/imap/cmd-sort.c                        |   22 +--
 src/imap/cmd-status.c                      |   11 +-
 src/imap/cmd-store.c                       |   37 +++---
 src/imap/cmd-thread.c                      |   19 +--
 src/imap/imap-client.c                     |    5 +-
 src/imap/imap-commands-util.c              |    5 +-
 src/imap/imap-fetch-body.c                 |   23 +--
 src/imap/imap-search-args.c                |    2 +-
 src/imap/imap-search.c                     |   21 +--
 src/imap/imap-status.c                     |    7 +-
 src/lib-imap/Makefile.am                   |   10 +-
 src/lib-imap/imap-arg.c                    |  130 +++++++++++++++++++++
 src/lib-imap/imap-arg.h                    |   87 ++++++++++++++
 src/lib-imap/imap-bodystructure.c          |   68 ++++++-----
 src/lib-imap/imap-envelope.c               |   39 ++---
 src/lib-imap/imap-id.c                     |   35 ++---
 src/lib-imap/imap-parser.c                 |   19 +---
 src/lib-imap/imap-parser.h                 |  100 +----------------
 src/lib-imap/imap-util.c                   |   14 +-
 src/lib-storage/mail-search-build.c        |  189 ++++++++++++++----------------
 src/plugins/imap-quota/imap-quota-plugin.c |   19 +-
 src/plugins/imap-zlib/imap-zlib-plugin.c   |    5 +-
 32 files changed, 615 insertions(+), 571 deletions(-)

diffs (truncated from 2459 to 300 lines):

diff -r 314f230b3a00 -r dbc864c0cff7 src/imap-login/client-authenticate.c
--- a/src/imap-login/client-authenticate.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap-login/client-authenticate.c	Mon Apr 05 07:54:55 2010 +0300
@@ -125,22 +125,18 @@
 int cmd_authenticate(struct imap_client *imap_client,
 		     const struct imap_arg *args)
 {
-	const char *mech_name, *init_resp = NULL;
+	const char *mech_name, *init_resp;
 
-	/* we want only one argument: authentication mechanism name */
-	if (args[0].type != IMAP_ARG_ATOM && args[0].type != IMAP_ARG_STRING)
+	/* <auth mechanism name> [<initial SASL response>] */
+	if (!imap_arg_get_atom(&args[0], &mech_name) || *mech_name == '\0')
 		return -1;
-	if (args[1].type != IMAP_ARG_EOL) {
-		/* optional SASL initial response */
-		if (args[1].type != IMAP_ARG_ATOM ||
-		    args[2].type != IMAP_ARG_EOL)
-			return -1;
-		init_resp = IMAP_ARG_STR(&args[1]);
-	}
+	if (imap_arg_get_atom(&args[1], &init_resp))
+		args++;
+	else
+		init_resp = NULL;
+	if (!IMAP_ARG_IS_EOL(&args[1]))
+		return -1;
 
-	mech_name = IMAP_ARG_STR(&args[0]);
-	if (*mech_name == '\0')
-		return -1;
 	return imap_client_auth_begin(imap_client, mech_name, init_resp);
 }
 
@@ -151,15 +147,10 @@
 	string_t *plain_login, *base64;
 
 	/* two arguments: username and password */
-	if (args[0].type != IMAP_ARG_ATOM && args[0].type != IMAP_ARG_STRING)
+	if (!imap_arg_get_astring(&args[0], &user) ||
+	    !imap_arg_get_astring(&args[1], &pass) ||
+	    !IMAP_ARG_IS_EOL(&args[2]))
 		return -1;
-	if (args[1].type != IMAP_ARG_ATOM && args[1].type != IMAP_ARG_STRING)
-		return -1;
-	if (args[2].type != IMAP_ARG_EOL)
-		return -1;
-
-	user = IMAP_ARG_STR(&args[0]);
-	pass = IMAP_ARG_STR(&args[1]);
 
 	if (!client_check_plaintext_auth(client, TRUE))
 		return 1;
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap-login/client.c
--- a/src/imap-login/client.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap-login/client.c	Mon Apr 05 07:54:55 2010 +0300
@@ -97,14 +97,11 @@
 {
 	const char *key, *value;
 
-	if (args->type != IMAP_ARG_LIST)
+	if (!imap_arg_get_list(args, &args))
 		return;
-	args = IMAP_ARG_LIST_ARGS(args);
 
-	while (args->type == IMAP_ARG_STRING &&
-	       args[1].type == IMAP_ARG_STRING) {
-		key = IMAP_ARG_STR_NONULL(&args[0]);
-		value = IMAP_ARG_STR_NONULL(&args[1]);
+	while (imap_arg_get_string(&args[0], &key) &&
+	       imap_arg_get_nstring(&args[1], &value)) {
 		if (strcasecmp(key, "x-originating-ip") == 0)
 			(void)net_addr2ip(value, &client->common.ip);
 		else if (strcasecmp(key, "x-originating-port") == 0)
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-append.c
--- a/src/imap/cmd-append.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-append.c	Mon Apr 05 07:54:55 2010 +0300
@@ -103,29 +103,25 @@
 			 bool *nonsync_r)
 {
 	/* [<flags>] */
-	if (args->type != IMAP_ARG_LIST)
+	if (!imap_arg_get_list(args, flags_r))
 		*flags_r = NULL;
-	else {
-		*flags_r = IMAP_ARG_LIST_ARGS(args);
+	else
 		args++;
-	}
 
 	/* [<internal date>] */
 	if (args->type != IMAP_ARG_STRING)
 		*internal_date_r = NULL;
 	else {
-		*internal_date_r = IMAP_ARG_STR(args);
+		*internal_date_r = imap_arg_as_astring(args);
 		args++;
 	}
 
-	if (args->type != IMAP_ARG_LITERAL_SIZE &&
-	    args->type != IMAP_ARG_LITERAL_SIZE_NONSYNC) {
+	if (!imap_arg_get_literal_size(args, msg_size_r)) {
 		*nonsync_r = FALSE;
 		return FALSE;
 	}
 
 	*nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC;
-	*msg_size_r = IMAP_ARG_LITERAL_SIZE(args);
 	return TRUE;
 }
 
@@ -241,7 +237,7 @@
 		return FALSE;
 	}
 
-	if (args->type == IMAP_ARG_EOL) {
+	if (IMAP_ARG_IS_EOL(args)) {
 		/* last message */
 		enum mailbox_sync_flags sync_flags;
 		enum imap_sync_flags imap_flags;
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-cancelupdate.c
--- a/src/imap/cmd-cancelupdate.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-cancelupdate.c	Mon Apr 05 07:54:55 2010 +0300
@@ -21,23 +21,24 @@
 bool cmd_cancelupdate(struct client_command_context *cmd)
 {
 	const struct imap_arg *args;
-	const char *str;
+	const char *tag;
 	unsigned int i;
 
 	if (!client_read_args(cmd, 0, 0, &args))
 		return FALSE;
 
 	for (i = 0; args[i].type == IMAP_ARG_STRING; i++) ;
-	if (args[i].type != IMAP_ARG_EOL || i == 0) {
+	if (!IMAP_ARG_IS_EOL(&args[i]) || i == 0) {
 		client_send_tagline(cmd, "BAD Invalid parameters.");
 		return TRUE;
 	}
-	for (i = 0; args[i].type == IMAP_ARG_STRING; i++) {
-		str = IMAP_ARG_STR_NONULL(&args[i]);
-		if (!client_search_update_cancel(cmd->client, str)) {
+
+	while (imap_arg_get_quoted(args, &tag)) {
+		if (!client_search_update_cancel(cmd->client, tag)) {
 			client_send_tagline(cmd, "BAD Unknown tag.");
 			return TRUE;
 		}
+		args++;
 	}
 	client_send_tagline(cmd, "OK Updates cancelled.");
 	return TRUE;
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-enable.c
--- a/src/imap/cmd-enable.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-enable.c	Mon Apr 05 07:54:55 2010 +0300
@@ -14,12 +14,12 @@
 
 	reply = t_str_new(64);
 	str_append(reply, "* ENABLED");
-	for (; args->type != IMAP_ARG_EOL; args++) {
-		if (args->type != IMAP_ARG_ATOM) {
+	for (; !IMAP_ARG_IS_EOL(args); args++) {
+		if (!imap_arg_get_atom(args, &str)) {
 			client_send_command_error(cmd, "Invalid arguments.");
 			return TRUE;
 		}
-		str = t_str_ucase(IMAP_ARG_STR(args));
+		str = t_str_ucase(str);
 		if (strcmp(str, "CONDSTORE") == 0) {
 			client_enable(cmd->client, MAILBOX_FEATURE_CONDSTORE);
 			str_append(reply, " CONDSTORE");
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-expunge.c
--- a/src/imap/cmd-expunge.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-expunge.c	Mon Apr 05 07:54:55 2010 +0300
@@ -58,8 +58,7 @@
 	if (!client_verify_open_mailbox(cmd))
 		return TRUE;
 
-	uidset = imap_arg_string(&args[0]);
-	if (uidset == NULL) {
+	if (!imap_arg_get_astring(&args[0], &uidset)) {
 		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-fetch.c
--- a/src/imap/cmd-fetch.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-fetch.c	Mon Apr 05 07:54:55 2010 +0300
@@ -30,8 +30,8 @@
 		if (!imap_fetch_init_handler(ctx, "UID", &arg))
 			return FALSE;
 	}
-	if (arg->type == IMAP_ARG_ATOM) {
-		str = t_str_ucase(IMAP_ARG_STR(arg));
+	if (imap_arg_get_atom(arg, &str)) {
+		str = t_str_ucase(str);
 		arg++;
 
 		/* handle macros first */
@@ -56,14 +56,14 @@
 		*next_arg_r = arg;
 	} else {
 		*next_arg_r = arg + 1;
-		arg = IMAP_ARG_LIST_ARGS(arg);
-		while (arg->type == IMAP_ARG_ATOM) {
-			str = t_str_ucase(IMAP_ARG_STR(arg));
+		arg = imap_arg_as_list(arg);
+		while (imap_arg_get_atom(arg, &str)) {
+			str = t_str_ucase(str);
 			arg++;
 			if (!imap_fetch_init_handler(ctx, str, &arg))
 				return FALSE;
 		}
-		if (arg->type != IMAP_ARG_EOL) {
+		if (!IMAP_ARG_IS_EOL(arg)) {
 			client_send_command_error(ctx->cmd,
 				"FETCH list contains non-atoms.");
 			return FALSE;
@@ -76,15 +76,16 @@
 fetch_parse_modifier(struct imap_fetch_context *ctx,
 		     const char *name, const struct imap_arg **args)
 {
+	const char *str;
 	unsigned long long num;
 
 	if (strcmp(name, "CHANGEDSINCE") == 0) {
-		if ((*args)->type != IMAP_ARG_ATOM) {
+		if (!imap_arg_get_atom(*args, &str)) {
 			client_send_command_error(ctx->cmd,
 				"Invalid CHANGEDSINCE modseq.");
 			return FALSE;
 		}
-		num = strtoull(imap_arg_string(*args), NULL, 10);
+		num = strtoull(str, NULL, 10);
 		*args += 1;
 		return imap_fetch_add_changed_since(ctx, num);
 	}
@@ -109,15 +110,14 @@
 {
 	const char *name;
 
-	while (args->type != IMAP_ARG_EOL) {
-		if (args->type != IMAP_ARG_ATOM) {
+	while (!IMAP_ARG_IS_EOL(args)) {
+		if (!imap_arg_get_atom(args, &name)) {
 			client_send_command_error(ctx->cmd,
 				"FETCH modifiers contain non-atoms.");
 			return FALSE;
 		}
-		name = t_str_ucase(IMAP_ARG_STR(args));
 		args++;
-		if (!fetch_parse_modifier(ctx, name, &args))
+		if (!fetch_parse_modifier(ctx, t_str_ucase(name), &args))
 			return FALSE;
 	}
 	if (ctx->send_vanished &&
@@ -184,7 +184,7 @@
 {
 	struct client *client = cmd->client;
 	struct imap_fetch_context *ctx;
-	const struct imap_arg *args, *next_arg;
+	const struct imap_arg *args, *next_arg, *list_arg;
 	struct mail_search_args *search_args;
 	const char *messageset;
 	int ret;
@@ -196,10 +196,9 @@
 		return TRUE;
 
 	/* <messageset> <field(s)> [(modifiers)] */
-	messageset = imap_arg_string(&args[0]);
-	if (messageset == NULL ||
+	if (!imap_arg_get_atom(&args[0], &messageset) ||
 	    (args[1].type != IMAP_ARG_LIST && args[1].type != IMAP_ARG_ATOM) ||
-	    (args[2].type != IMAP_ARG_EOL && args[2].type != IMAP_ARG_LIST)) {
+	    (!IMAP_ARG_IS_EOL(&args[2]) && args[2].type != IMAP_ARG_LIST)) {
 		client_send_command_error(cmd, "Invalid arguments.");
 		return TRUE;
 	}
@@ -218,8 +217,8 @@
 	ctx->search_args = search_args;
 
 	if (!fetch_parse_args(ctx, &args[1], &next_arg) ||
-	    (next_arg->type == IMAP_ARG_LIST &&
-	     !fetch_parse_modifiers(ctx, IMAP_ARG_LIST_ARGS(next_arg)))) {
+	    (imap_arg_get_list(next_arg, &list_arg) &&
+	     !fetch_parse_modifiers(ctx, list_arg))) {
 		imap_fetch_deinit(ctx);
 		return TRUE;
 	}
diff -r 314f230b3a00 -r dbc864c0cff7 src/imap/cmd-list.c
--- a/src/imap/cmd-list.c	Mon Apr 05 05:19:24 2010 +0300
+++ b/src/imap/cmd-list.c	Mon Apr 05 07:54:55 2010 +0300
@@ -93,23 +93,21 @@
 parse_select_flags(struct cmd_list_context *ctx, const struct imap_arg *args)
 {
 	enum mailbox_list_iter_flags list_flags = 0;
-	const char *atom;
+	const char *str;
 


More information about the dovecot-cvs mailing list