[dovecot-cvs] dovecot/src/lib-imap imap-parser.c,1.46,1.47 imap-parser.h,1.14,1.15 imap-bodystructure.c,1.39,1.40

cras at procontrol.fi cras at procontrol.fi
Wed Aug 6 03:10:36 EEST 2003


Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv15074

Modified Files:
	imap-parser.c imap-parser.h imap-bodystructure.c 
Log Message:
Fixes for parsing BODYSTRUCTURE



Index: imap-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-parser.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- imap-parser.c	2 Jul 2003 00:57:25 -0000	1.46
+++ imap-parser.c	5 Aug 2003 23:10:33 -0000	1.47
@@ -563,6 +563,32 @@
         ((parser)->cur_type != ARG_PARSE_NONE || \
 	 (parser)->cur_list != parser->root_list)
 
+static int finish_line(struct imap_parser *parser, unsigned int count,
+		       struct imap_arg **args)
+{
+	parser->line_size += parser->cur_pos;
+	i_stream_skip(parser->input, parser->cur_pos);
+	parser->cur_pos = 0;
+
+	if (parser->list_arg != NULL) {
+		parser->error = "Missing ')'";
+		*args = NULL;
+		return -1;
+	}
+
+	if (count >= parser->root_list->alloc) {
+		/* unused arguments must be NIL-filled. */
+		parser->root_list =
+			LIST_REALLOC(parser, parser->root_list, count+1);
+		parser->root_list->alloc = count+1;
+	}
+
+	parser->root_list->args[parser->root_list->size].type = IMAP_ARG_EOL;
+
+	*args = parser->root_list->args;
+	return parser->root_list->size;
+}
+
 int imap_parser_read_args(struct imap_parser *parser, unsigned int count,
 			  enum imap_parser_flags flags, struct imap_arg **args)
 {
@@ -589,34 +615,31 @@
 	} else if ((!IS_UNFINISHED(parser) && count > 0 &&
 		    parser->root_list->size >= count) || parser->eol) {
 		/* all arguments read / end of line. */
-		parser->line_size += parser->cur_pos;
- 		i_stream_skip(parser->input, parser->cur_pos);
-		parser->cur_pos = 0;
-
-		if (parser->list_arg != NULL) {
-			parser->error = "Missing ')'";
-			*args = NULL;
-			return -1;
-		}
-
-		if (count >= parser->root_list->alloc) {
-			/* unused arguments must be NIL-filled. */
-			parser->root_list = LIST_REALLOC(parser,
-							 parser->root_list,
-							 count+1);
-			parser->root_list->alloc = count+1;
-		}
-
-		parser->root_list->args[parser->root_list->size].type =
-			IMAP_ARG_EOL;
-
-		*args = parser->root_list->args;
-		return parser->root_list->size;
+                return finish_line(parser, count, args);
 	} else {
 		/* need more data */
 		*args = NULL;
 		return -2;
 	}
+}
+
+int imap_parser_finish_line(struct imap_parser *parser, unsigned int count,
+			    enum imap_parser_flags flags,
+			    struct imap_arg **args)
+{
+	const unsigned char *data;
+	size_t data_size;
+	int ret;
+
+	ret = imap_parser_read_args(parser, count, flags, args);
+	if (ret == -2) {
+		/* we should have noticed end of everything except atom */
+		if (parser->cur_type == ARG_PARSE_ATOM) {
+			data = i_stream_get_data(parser->input, &data_size);
+			imap_parser_save_arg(parser, data, data_size);
+		}
+	}
+	return finish_line(parser, count, args);
 }
 
 const char *imap_parser_read_word(struct imap_parser *parser)

Index: imap-parser.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-parser.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- imap-parser.h	2 Jul 2003 00:57:25 -0000	1.14
+++ imap-parser.h	5 Aug 2003 23:10:33 -0000	1.15
@@ -95,6 +95,12 @@
 int imap_parser_read_args(struct imap_parser *parser, unsigned int count,
 			  enum imap_parser_flags flags, struct imap_arg **args);
 
+/* just like imap_parser_read_args(), but assume \n at end of data in
+   input stream. */
+int imap_parser_finish_line(struct imap_parser *parser, unsigned int count,
+			    enum imap_parser_flags flags,
+			    struct imap_arg **args);
+
 /* Read one word - used for reading tag and command name.
    Returns NULL if more data is needed. */
 const char *imap_parser_read_word(struct imap_parser *parser);

Index: imap-bodystructure.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-bodystructure.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- imap-bodystructure.c	13 Jul 2003 23:01:06 -0000	1.39
+++ imap-bodystructure.c	5 Aug 2003 23:10:33 -0000	1.40
@@ -614,10 +614,6 @@
 		str_append(str, " (");
                 subargs = IMAP_ARG_LIST(args)->args;
 		for (; subargs->type != IMAP_ARG_EOL; ) {
-			if (subargs[0].type != IMAP_ARG_STRING ||
-			    subargs[1].type != IMAP_ARG_STRING)
-				return FALSE;
-
 			if (!str_append_imap_arg(str, &subargs[0]))
 				return FALSE;
 			str_append_c(str, ' ');
@@ -695,9 +691,8 @@
 	(void)i_stream_read(input);
 
 	parser = imap_parser_create(input, NULL, (size_t)-1);
-	ret = imap_parser_read_args(parser, 0, IMAP_PARSE_FLAG_NO_UNESCAPE |
-				    IMAP_PARSE_FLAG_LITERAL_TYPE, &args);
-
+	ret = imap_parser_finish_line(parser, 0, IMAP_PARSE_FLAG_NO_UNESCAPE |
+				      IMAP_PARSE_FLAG_LITERAL_TYPE, &args);
 	if (ret <= 0 || !imap_parse_bodystructure_args(args, str))
 		value = NULL;
 	else



More information about the dovecot-cvs mailing list