[dovecot-cvs] dovecot/src/lib-storage/index index-fetch-section.c,1.21,1.22 index-fetch.c,1.35,1.36 index-search.c,1.50,1.51 index-sort.c,1.3,1.4

cras at procontrol.fi cras at procontrol.fi
Thu Dec 19 03:02:37 EET 2002


Update of /home/cvs/dovecot/src/lib-storage/index
In directory danu:/tmp/cvs-serv11467/lib-storage/index

Modified Files:
	index-fetch-section.c index-fetch.c index-search.c 
	index-sort.c 
Log Message:
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Added str_path() and str_ppath() functions. i_snprintf() now returns only -1
or 0 depending on if buffer got full. dec2str() returns the string allocated
from data stack. Instead of just casting to (long) or (int), we now use
dec2str() with printf-like functions. Added o_stream_send_str(). Added
strocpy() and replaced all strcpy()s and strncpy()s with it.

Pretty much untested, hope it doesn't break too badly :)



Index: index-fetch-section.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch-section.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- index-fetch-section.c	6 Dec 2002 01:09:23 -0000	1.21
+++ index-fetch-section.c	19 Dec 2002 01:02:35 -0000	1.22
@@ -57,7 +57,7 @@
 
 	str = t_strdup_printf("%s {%"PRIuUOFF_T"}\r\n",
 			      prefix, size.virtual_size);
-	if (o_stream_send(ctx->output, str, strlen(str)) < 0)
+	if (o_stream_send_str(ctx->output, str) < 0)
 		return FALSE;
 
 	if (cr_skipped)
@@ -261,7 +261,7 @@
 		/* all headers */
 		str = t_strdup_printf("%s {%"PRIuUOFF_T"}\r\n",
 				      prefix, size->virtual_size);
-		if (o_stream_send(output, str, strlen(str)) < 0)
+		if (o_stream_send_str(output, str) < 0)
 			return FALSE;
 		return message_send(output, input, size,
 				    sect->skip, sect->max_size);
@@ -297,7 +297,7 @@
 	if (!failed) {
 		str = t_strdup_printf("%s {%"PRIuUOFF_T"}\r\n",
 				      prefix, ctx.dest_size);
-		if (o_stream_send(output, str, strlen(str)) < 0)
+		if (o_stream_send_str(output, str) < 0)
 			failed = TRUE;
 	}
 
@@ -402,7 +402,7 @@
 
 	str = t_strdup_printf("%s {%"PRIuUOFF_T"}\r\n",
 			      prefix, part->body_size.virtual_size);
-	if (o_stream_send(ctx->output, str, strlen(str)) < 0)
+	if (o_stream_send_str(ctx->output, str) < 0)
 		return FALSE;
 
 	/* FIXME: potential performance problem with big messages:

Index: index-fetch.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-fetch.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- index-fetch.c	6 Dec 2002 01:09:23 -0000	1.35
+++ index-fetch.c	19 Dec 2002 01:02:35 -0000	1.36
@@ -135,7 +135,7 @@
 	if (ctx->first) {
 		str++; ctx->first = FALSE;
 	}
-	if (o_stream_send(ctx->output, str, strlen(str)) < 0)
+	if (o_stream_send_str(ctx->output, str) < 0)
 		return FALSE;
 
 	body_size.physical_size += hdr_size.physical_size;
@@ -162,7 +162,7 @@
 	if (ctx->first) {
 		str++; ctx->first = FALSE;
 	}
-	if (o_stream_send(ctx->output, str, strlen(str)) < 0)
+	if (o_stream_send_str(ctx->output, str) < 0)
 		return FALSE;
 
 	return message_send(ctx->output, input, &hdr_size, 0, (uoff_t)-1);
@@ -186,7 +186,7 @@
 	if (ctx->first) {
 		str++; ctx->first = FALSE;
 	}
-	if (o_stream_send(ctx->output, str, strlen(str)) < 0)
+	if (o_stream_send_str(ctx->output, str) < 0)
 		return FALSE;
 
 	return message_send(ctx->output, input, &body_size, 0, (uoff_t)-1);

Index: index-search.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-search.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- index-search.c	17 Dec 2002 04:28:41 -0000	1.50
+++ index-search.c	19 Dec 2002 01:02:35 -0000	1.51
@@ -768,7 +768,7 @@
         MailSearchArg *arg;
 	const ModifyLogExpunge *expunges;
 	unsigned int first_uid, last_uid, client_seq, expunges_before;
-	char num[MAX_INT_STRLEN+10];
+	const char *str;
 	int found, failed;
 
 	if (ibox->synced_messages_count == 0)
@@ -830,12 +830,13 @@
 
 			if (found) {
 				if (sort_ctx == NULL) {
-					size_t len;
+					t_push();
+					o_stream_send(output, " ", 1);
 
-					len = i_snprintf(num, sizeof(num),
-							 " %u", uid_result ?
-							 rec->uid : client_seq);
-					o_stream_send(output, num, len);
+					str = dec2str(uid_result ? rec->uid :
+						      client_seq);
+					o_stream_send_str(output, str);
+					t_pop();
 				} else {
 					mail_sort_input(sort_ctx, rec->uid);
 				}
@@ -866,7 +867,7 @@
 
 	if (sorting == NULL) {
 		sort_ctx = NULL;
-		o_stream_send(output, "* SEARCH", 8);
+		o_stream_send_str(output, "* SEARCH");
 	} else {
 		memset(&index_sort_ctx, 0, sizeof(index_sort_ctx));
 		index_sort_ctx.ibox = ibox;
@@ -874,7 +875,7 @@
 
 		sort_ctx = mail_sort_init(sort_unsorted, sorting,
 					  index_sort_funcs, &index_sort_ctx);
-		o_stream_send(output, "* SORT", 6);
+		o_stream_send_str(output, "* SORT");
 	}
 
 	failed = !search_messages(ibox, charset, args, sort_ctx,

Index: index-sort.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/index-sort.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- index-sort.c	17 Dec 2002 04:28:41 -0000	1.3
+++ index-sort.c	19 Dec 2002 01:02:35 -0000	1.4
@@ -141,12 +141,13 @@
 static void _output(unsigned int *data, size_t count, void *context)
 {
 	IndexSortContext *ctx = context;
-	char num[MAX_INT_STRLEN+1];
-	size_t i, len;
+	size_t i;
 
 	for (i = 0; i < count; i++) {
-		len = i_snprintf(num, sizeof(num), " %u", data[i]);
-		o_stream_send(ctx->output, num, len);
+		t_push();
+		o_stream_send(ctx->output, " ", 1);
+		o_stream_send_str(ctx->output, dec2str(data[i]));
+		t_pop();
 	}
 }
 




More information about the dovecot-cvs mailing list