[dovecot-cvs] dovecot/src/lib-mail message-body-search.c,1.7,1.8 message-content-parser.c,1.5,1.6 message-content-parser.h,1.4,1.5 message-header-search.c,1.10,1.11 message-parser.c,1.30,1.31 message-parser.h,1.13,1.14 rfc822-address.c,1.7,1.8 Message-Id: <20030104172632.99F3D238C7@danu.procontrol.fi>

cras at procontrol.fi cras at procontrol.fi
Sat Jan 4 19:26:32 EET 2003


Update of /home/cvs/dovecot/src/lib-mail
In directory danu:/tmp/cvs-serv386/lib-mail

Modified Files:
	message-body-search.c message-content-parser.c 
	message-content-parser.h message-header-search.c 
	message-parser.c message-parser.h rfc822-address.c 
	rfc822-address.h rfc822-date.c rfc822-tokenize.c 
	rfc822-tokenize.h 
Log Message:
Use unsigned char* when accessing non-NUL terminating strings. Compiler
warnings would then notify about accidentally passing them to functions which
require them NUL-terminated. Changed a few functions to use void* to avoid
unneeded casting.



Index: message-body-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-body-search.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- message-body-search.c	3 Jan 2003 15:57:12 -0000	1.7
+++ message-body-search.c	4 Jan 2003 17:26:30 -0000	1.8
@@ -45,7 +45,7 @@
 	unsigned int found:1;
 } PartSearchContext;
 
-static void parse_content_type(const char *value, size_t value_len,
+static void parse_content_type(const unsigned char *value, size_t value_len,
 			       void *context)
 {
 	PartSearchContext *ctx = context;
@@ -58,38 +58,39 @@
 	}
 }
 
-static void parse_content_type_param(const char *name, size_t name_len,
-				     const char *value, size_t value_len,
-				     int value_quoted, void *context)
+static void
+parse_content_type_param(const unsigned char *name, size_t name_len,
+			 const unsigned char *value, size_t value_len,
+			 int value_quoted, void *context)
 {
 	PartSearchContext *ctx = context;
 
-	if (name_len == 7 && strncasecmp(name, "charset", 7) == 0 &&
+	if (name_len == 7 && memcasecmp(name, "charset", 7) == 0 &&
 	    ctx->content_charset == NULL) {
 		ctx->content_charset = i_strndup(value, value_len);
 		if (value_quoted) str_unescape(ctx->content_charset);
 	}
 }
 
-static void parse_content_encoding(const char *value, size_t value_len,
+static void parse_content_encoding(const unsigned char *value, size_t value_len,
 				   void *context)
 {
 	PartSearchContext *ctx = context;
 
 	switch (value_len) {
 	case 4:
-		if (strncasecmp(value, "7bit", 4) != 0 &&
-		    strncasecmp(value, "8bit", 4) != 0)
+		if (memcasecmp(value, "7bit", 4) != 0 &&
+		    memcasecmp(value, "8bit", 4) != 0)
 			ctx->content_unknown = TRUE;
 		break;
 	case 6:
-		if (strncasecmp(value, "base64", 6) == 0)
+		if (memcasecmp(value, "base64", 6) == 0)
 			ctx->content_base64 = TRUE;
-		else if (strncasecmp(value, "binary", 6) != 0)
+		else if (memcasecmp(value, "binary", 6) != 0)
 			ctx->content_unknown = TRUE;
 		break;
 	case 16:
-		if (strncasecmp(value, "quoted-printable", 16) == 0)
+		if (memcasecmp(value, "quoted-printable", 16) == 0)
 			ctx->content_qp = TRUE;
 		else
 			ctx->content_unknown = TRUE;
@@ -101,8 +102,9 @@
 }
 
 static void header_find(MessagePart *part __attr_unused__,
-			const char *name, size_t name_len,
-			const char *value, size_t value_len, void *context)
+			const unsigned char *name, size_t name_len,
+			const unsigned char *value, size_t value_len,
+			void *context)
 {
 	PartSearchContext *ctx = context;
 
@@ -114,13 +116,13 @@
 						   ctx->hdr_search_ctx);
 	}
 
-	if (name_len == 12 && strncasecmp(name, "Content-Type", 12) == 0) {
+	if (name_len == 12 && memcasecmp(name, "Content-Type", 12) == 0) {
 		message_content_parse_header(value, value_len,
 					     parse_content_type,
 					     parse_content_type_param,
 					     ctx);
 	} else if (name_len == 25 &&
-		   strncasecmp(name, "Content-Transfer-Encoding", 25) == 0) {
+		   memcasecmp(name, "Content-Transfer-Encoding", 25) == 0) {
 		message_content_parse_header(value, value_len,
 					     parse_content_encoding,
 					     NULL, ctx);
@@ -344,7 +346,8 @@
 
 	/* get the key uppercased */
 	key = charset_to_ucase_utf8_string(charset, unknown_charset,
-					   key, strlen(key), &key_len);
+					   (const unsigned char *) key,
+					   strlen(key), &key_len);
 	if (key == NULL)
 		return FALSE;
 

Index: message-content-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-content-parser.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- message-content-parser.c	4 Jan 2003 13:22:29 -0000	1.5
+++ message-content-parser.c	4 Jan 2003 17:26:30 -0000	1.6
@@ -5,7 +5,7 @@
 #include "rfc822-tokenize.h"
 #include "message-content-parser.h"
 
-void message_content_parse_header(const char *data, size_t size,
+void message_content_parse_header(const unsigned char *data, size_t size,
 				  ParseContentFunc func,
 				  ParseContentParamFunc param_func,
 				  void *context)
@@ -14,7 +14,7 @@
 	Rfc822TokenizeContext *ctx;
 	Rfc822Token token;
 	String *str;
-	const char *key, *value;
+	const unsigned char *key, *value;
 	size_t key_len, value_len;
 
 	ctx = rfc822_tokenize_init(data, size, NULL, NULL);
@@ -27,7 +27,7 @@
 	rfc822_tokenize_get_string(ctx, str, NULL, stop_tokens);
 
 	if (func != NULL)
-		func(str_c(str), str_len(str), context);
+		func(str_data(str), str_len(str), context);
 
 	t_pop();
 

Index: message-content-parser.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-content-parser.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- message-content-parser.h	3 Jan 2003 15:57:12 -0000	1.4
+++ message-content-parser.h	4 Jan 2003 17:26:30 -0000	1.5
@@ -2,13 +2,15 @@
 #define __MESSAGE_CONTENT_PARSER_H
 
 /* NOTE: name and value aren't \0-terminated. */
-typedef void (*ParseContentFunc)(const char *value, size_t value_len,
+typedef void (*ParseContentFunc)(const unsigned char *value, size_t value_len,
 				 void *context);
-typedef void (*ParseContentParamFunc)(const char *name, size_t name_len,
-				      const char *value, size_t value_len,
+typedef void (*ParseContentParamFunc)(const unsigned char *name,
+				      size_t name_len,
+				      const unsigned char *value,
+				      size_t value_len,
 				      int value_quoted, void *context);
 
-void message_content_parse_header(const char *data, size_t size,
+void message_content_parse_header(const unsigned char *data, size_t size,
 				  ParseContentFunc func,
 				  ParseContentParamFunc param_func,
 				  void *context);

Index: message-header-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-header-search.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- message-header-search.c	3 Jan 2003 15:57:12 -0000	1.10
+++ message-header-search.c	4 Jan 2003 17:26:30 -0000	1.11
@@ -36,21 +36,22 @@
 {
 	HeaderSearchContext *ctx;
 	size_t key_len;
-	const char *p;
+	const unsigned char *p;
 
 	ctx = p_new(pool, HeaderSearchContext, 1);
 	ctx->pool = pool;
 
 	/* get the key uppercased */
 	key = charset_to_ucase_utf8_string(charset, unknown_charset,
-					   key, strlen(key), &key_len);
+					   (const unsigned char *) key,
+					   strlen(key), &key_len);
 
 	if (key == NULL) {
 		/* invalid key */
 		return NULL;
 	}
 
-	ctx->key = p_strdup(pool, key);
+	ctx->key = (unsigned char *) p_strdup(pool, key);
 	ctx->key_len = key_len;
 	ctx->key_charset = p_strdup(pool, charset);
 	ctx->unknown_charset = charset == NULL;
@@ -104,7 +105,7 @@
 		/* unknown character set, or invalid data */
 	} else {
 		ctx->submatch = TRUE;
-		search_loop(utf8_data, utf8_size, ctx);
+		search_loop((const unsigned char *) utf8_data, utf8_size, ctx);
 		ctx->submatch = FALSE;
 	}
 }

Index: message-parser.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-parser.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- message-parser.c	3 Jan 2003 15:57:12 -0000	1.30
+++ message-parser.c	4 Jan 2003 17:26:30 -0000	1.31
@@ -68,7 +68,7 @@
 	return part;
 }
 
-static void parse_content_type(const char *value, size_t value_len,
+static void parse_content_type(const unsigned char *value, size_t value_len,
 			       void *context)
 {
 	MessageParseContext *parse_ctx = context;
@@ -94,14 +94,15 @@
 	}
 }
 
-static void parse_content_type_param(const char *name, size_t name_len,
-				     const char *value, size_t value_len,
-				     int value_quoted, void *context)
+static void
+parse_content_type_param(const unsigned char *name, size_t name_len,
+			 const unsigned char *value, size_t value_len,
+			 int value_quoted, void *context)
 {
 	MessageParseContext *parse_ctx = context;
 
 	if ((parse_ctx->part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0 ||
-	    name_len != 8 || strncasecmp(name, "boundary", 8) != 0)
+	    name_len != 8 || memcasecmp(name, "boundary", 8) != 0)
 		return;
 
 	if (parse_ctx->last_boundary == NULL) {
@@ -113,8 +114,8 @@
 }
 
 static void parse_header_field(MessagePart *part,
-			       const char *name, size_t name_len,
-			       const char *value, size_t value_len,
+			       const unsigned char *name, size_t name_len,
+			       const unsigned char *value, size_t value_len,
 			       void *context)
 {
 	MessageParseContext *parse_ctx = context;
@@ -125,7 +126,7 @@
 				parse_ctx->context);
 	}
 
-	if (name_len == 12 && strncasecmp(name, "Content-Type", 12) == 0) {
+	if (name_len == 12 && memcasecmp(name, "Content-Type", 12) == 0) {
 		/* we need to know the boundary */
 		message_content_parse_header(value, value_len,
 					     parse_content_type,
@@ -390,11 +391,9 @@
 					if (msg[i-1] == '\r') value_len--;
 
 					/* and finally call the function */
-					func(part,
-					     (const char *) msg + line_start,
-					     name_len,
-					     (const char *) msg + colon_pos,
-					     value_len, context);
+					func(part, msg + line_start, name_len,
+					     msg + colon_pos, value_len,
+					     context);
 				}
 
 				colon_pos = UINT_MAX;
@@ -430,16 +429,16 @@
 
 	if (func != NULL) {
 		/* "end of headers" notify */
-		func(part, "", 0, "", 0, context);
+		func(part, NULL, 0, NULL, 0, context);
 	}
 }
 
 static MessageBoundary *boundary_find(MessageBoundary *boundaries,
-				      const char *msg, size_t len)
+				      const unsigned char *msg, size_t len)
 {
 	while (boundaries != NULL) {
 		if (boundaries->len <= len &&
-		    strncmp(boundaries->boundary, msg, boundaries->len) == 0)
+		    memcmp(boundaries->boundary, msg, boundaries->len) == 0)
 			return boundaries;
 
 		boundaries = boundaries->next;
@@ -471,8 +470,8 @@
 			    msg[line_start+1] == '-') {
 				/* possible boundary */
 				boundary = boundary_find(boundaries,
-					(const char *) msg + line_start + 2,
-					i - line_start - 2);
+							 msg + line_start + 2,
+							 i - line_start - 2);
 				if (boundary != NULL)
 					break;
 			}
@@ -496,8 +495,8 @@
 			   70 chars without "--" or less. We allow
 			   a bit larger.. */
 			boundary = boundary_find(boundaries,
-					(const char *) msg + line_start + 2,
-					i - line_start - 2);
+						 msg + line_start + 2,
+						 i - line_start - 2);
 			if (boundary != NULL)
 				break;
 

Index: message-parser.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/message-parser.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- message-parser.h	3 Jan 2003 15:57:12 -0000	1.13
+++ message-parser.h	4 Jan 2003 17:26:30 -0000	1.14
@@ -42,8 +42,8 @@
 /* NOTE: name and value aren't \0-terminated. Also called once at end of
    headers with name_len = value_len = 0. */
 typedef void (*MessageHeaderFunc)(MessagePart *part,
-				  const char *name, size_t name_len,
-				  const char *value, size_t value_len,
+				  const unsigned char *name, size_t name_len,
+				  const unsigned char *value, size_t value_len,
 				  void *context);
 
 /* func is called for each field in message header. */

Index: rfc822-address.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-address.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rfc822-address.c	4 Jan 2003 13:22:29 -0000	1.7
+++ rfc822-address.c	4 Jan 2003 17:26:30 -0000	1.8
@@ -17,7 +17,8 @@
 	return addr;
 }
 
-Rfc822Address *rfc822_address_parse(Pool pool, const char *str)
+Rfc822Address *rfc822_address_parse(Pool pool, const unsigned char *data,
+				    size_t size)
 {
 	static const Rfc822Token stop_tokens_init[] =
 		{ ',', '@', '<', ':', TOKEN_LAST };
@@ -46,7 +47,7 @@
 	size_t len;
 	int ingroup, stop;
 
-	if (str == NULL || *str == '\0')
+	if (size == 0)
 		return NULL;
 
 	first_addr = NULL;
@@ -59,7 +60,7 @@
 	   ENVELOPE wants groups to be stored like (NIL, NIL, group, NIL),
 	   ..., (NIL, NIL, NIL, NIL)
 	*/
-	ctx = rfc822_tokenize_init(str, (size_t)-1, NULL, NULL);
+	ctx = rfc822_tokenize_init(data, size, NULL, NULL);
 	rfc822_tokenize_skip_comments(ctx, FALSE);
 
 	t_push();

Index: rfc822-address.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-address.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- rfc822-address.h	9 Aug 2002 09:16:07 -0000	1.1.1.1
+++ rfc822-address.h	4 Jan 2003 17:26:30 -0000	1.2
@@ -9,6 +9,7 @@
 	char *name, *route, *mailbox, *domain;
 };
 
-Rfc822Address *rfc822_address_parse(Pool pool, const char *str);
+Rfc822Address *rfc822_address_parse(Pool pool, const unsigned char *data,
+				    size_t size);
 
 #endif

Index: rfc822-date.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-date.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- rfc822-date.c	4 Jan 2003 13:22:29 -0000	1.10
+++ rfc822-date.c	4 Jan 2003 17:26:30 -0000	1.11
@@ -17,7 +17,7 @@
 	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
 };
 
-static int parse_timezone(const char *str, size_t len)
+static int parse_timezone(const unsigned char *str, size_t len)
 {
 	int offset;
 	char chr;
@@ -87,7 +87,7 @@
 }
 
 static Rfc822Token next_token(Rfc822TokenizeContext *ctx,
-			      const char **value, size_t *value_len)
+			      const unsigned char **value, size_t *value_len)
 {
 	Rfc822Token token;
 
@@ -102,7 +102,7 @@
 {
 	struct tm tm;
 	Rfc822Token token;
-	const char *value;
+	const unsigned char *value;
 	size_t i, len;
 
 	/* [weekday_name "," ] dd month_name [yy]yy hh:mi[:ss] timezone */
@@ -135,7 +135,7 @@
 		return FALSE;
 
 	for (i = 0; i < 12; i++) {
-		if (strncasecmp(month_names[i], value, 3) == 0) {
+		if (memcasecmp(month_names[i], value, 3) == 0) {
 			tm.tm_mon = i;
 			break;
 		}
@@ -214,7 +214,8 @@
 	if (data == NULL || *data == '\0')
 		return FALSE;
 
-	ctx = rfc822_tokenize_init(data, (size_t)-1, NULL, NULL);
+	ctx = rfc822_tokenize_init((const unsigned char *) data, (size_t)-1,
+				   NULL, NULL);
 	ret = rfc822_parse_date_tokens(ctx, time, timezone_offset);
 	rfc822_tokenize_deinit(ctx);
 

Index: rfc822-tokenize.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-tokenize.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- rfc822-tokenize.c	4 Jan 2003 13:22:29 -0000	1.8
+++ rfc822-tokenize.c	4 Jan 2003 17:26:30 -0000	1.9
@@ -6,7 +6,7 @@
 #include "rfc822-tokenize.h"
 
 struct _Rfc822TokenizeContext {
-	const char *data;
+	const unsigned char *data;
 	size_t size;
 
 	Rfc822TokenizeErrorFunc error_func;
@@ -42,7 +42,7 @@
 
 
 Rfc822TokenizeContext *
-rfc822_tokenize_init(const char *data, size_t size,
+rfc822_tokenize_init(const unsigned char *data, size_t size,
 		     Rfc822TokenizeErrorFunc error_func, void *error_context)
 {
 	Rfc822TokenizeContext *ctx;
@@ -79,7 +79,7 @@
 Rfc822Token rfc822_tokenize_next(Rfc822TokenizeContext *ctx)
 {
 	int token, level, last_atom;
-	const char *data;
+	const unsigned char *data;
 	size_t i, size;
 
 	if (ctx->token == TOKEN_LAST)
@@ -275,8 +275,8 @@
 	return ctx->token;
 }
 
-const char *rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx,
-				      size_t *len)
+const unsigned char *
+rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx, size_t *len)
 {
 	i_assert(IS_TOKEN_STRING(ctx->token));
 
@@ -289,7 +289,7 @@
 				const Rfc822Token *stop_tokens)
 {
 	Rfc822Token token;
-	const char *value;
+	const unsigned char *value;
 	size_t len;
 	int i, token_str, last_str;
 

Index: rfc822-tokenize.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-mail/rfc822-tokenize.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- rfc822-tokenize.h	4 Jan 2003 13:22:29 -0000	1.9
+++ rfc822-tokenize.h	4 Jan 2003 17:26:30 -0000	1.10
@@ -29,14 +29,14 @@
 
    missing_char == '\0': unexpected character at str[pos]
    missing_char != '\0': missing character */
-typedef int (*Rfc822TokenizeErrorFunc)(const char *str, size_t pos,
+typedef int (*Rfc822TokenizeErrorFunc)(const unsigned char *str, size_t pos,
 				       char missing_char, void *context);
 
 /* Tokenize the string. Returns NULL if string is empty. Memory for
    returned array is allocated from data stack. You don't have to use
    the tokens_count, since last token is always 0. */
 Rfc822TokenizeContext *
-rfc822_tokenize_init(const char *data, size_t size,
+rfc822_tokenize_init(const unsigned char *data, size_t size,
 		     Rfc822TokenizeErrorFunc error_func, void *error_context);
 void rfc822_tokenize_deinit(Rfc822TokenizeContext *ctx);
 
@@ -54,8 +54,8 @@
 /* - not including enclosing "", () or []
    - '\' isn't expanded
    - [CR+]LF+LWSP (continued header) isn't removed */
-const char *rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx,
-				      size_t *len);
+const unsigned char *
+rfc822_tokenize_get_value(const Rfc822TokenizeContext *ctx, size_t *len);
 
 /* Read tokens as a string, all quoted strings will be unquoted.
    Reads until stop_token is found. */




More information about the dovecot-cvs mailing list