dovecot-2.0-sslstream: Removed buffer_create_static_hard().

dovecot at dovecot.org dovecot at dovecot.org
Sat Feb 13 02:56:43 EET 2010


details:   http://hg.dovecot.org/dovecot-2.0-sslstream/rev/f8151445662e
changeset: 10405:f8151445662e
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Nov 25 13:19:42 2009 -0500
description:
Removed buffer_create_static_hard().
buffer_create_data() handles most of the situations where it was wanted.

diffstat:

7 files changed, 32 insertions(+), 43 deletions(-)
src/auth/mech-digest-md5.c                  |   13 ++++++-------
src/auth/password-scheme.c                  |    8 ++++----
src/lib-index/mail-index-sync-keywords.c    |   15 ++++++++-------
src/lib-index/mail-transaction-log-append.c |   12 ++++++------
src/lib/buffer.c                            |   10 ----------
src/lib/buffer.h                            |    5 ++---
src/pop3-login/client.c                     |   12 ++++++------

diffs (195 lines):

diff -r a1018630276b -r f8151445662e src/auth/mech-digest-md5.c
--- a/src/auth/mech-digest-md5.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/auth/mech-digest-md5.c	Wed Nov 25 13:19:42 2009 -0500
@@ -57,10 +57,11 @@ static string_t *get_digest_challenge(st
 static string_t *get_digest_challenge(struct digest_auth_request *request)
 {
 	struct auth *auth = request->auth_request.auth;
-	buffer_t *buf;
+	buffer_t buf;
 	string_t *str;
 	const char *const *tmp;
 	unsigned char nonce[16];
+	unsigned char nonce_base64[MAX_BASE64_ENCODED_SIZE(sizeof(nonce))+1];
 	int i;
 	bool first_qop;
 
@@ -77,12 +78,10 @@ static string_t *get_digest_challenge(st
 	/* get 128bit of random data as nonce */
 	random_fill(nonce, sizeof(nonce));
 
-	buf = buffer_create_static_hard(pool_datastack_create(),
-				MAX_BASE64_ENCODED_SIZE(sizeof(nonce))+1);
-
-	base64_encode(nonce, sizeof(nonce), buf);
-	buffer_append_c(buf, '\0');
-	request->nonce = p_strdup(request->pool, buffer_get_data(buf, NULL));
+	buffer_create_data(&buf, nonce_base64, sizeof(nonce_base64));
+	base64_encode(nonce, sizeof(nonce), &buf);
+	buffer_append_c(&buf, '\0');
+	request->nonce = p_strdup(request->pool, buf.data);
 
 	str = t_str_new(256);
 	if (*auth->auth_realms == NULL) {
diff -r a1018630276b -r f8151445662e src/auth/password-scheme.c
--- a/src/auth/password-scheme.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/auth/password-scheme.c	Wed Nov 25 13:19:42 2009 -0500
@@ -155,8 +155,8 @@ int password_decode(const char *password
 		*size_r = len;
 		break;
 	case PW_ENCODING_HEX:
-		buf = buffer_create_static_hard(pool_datastack_create(),
-						len / 2 + 1);
+		buf = buffer_create_dynamic(pool_datastack_create(),
+					    len / 2 + 1);
 		if (hex_to_binary(password, buf) == 0) {
 			*raw_password_r = buf->data;
 			*size_r = buf->used;
@@ -166,8 +166,8 @@ int password_decode(const char *password
 		   all. some input lengths produce matching hex and base64
 		   encoded lengths. */
 	case PW_ENCODING_BASE64:
-		buf = buffer_create_static_hard(pool_datastack_create(),
-						MAX_BASE64_DECODED_SIZE(len));
+		buf = buffer_create_dynamic(pool_datastack_create(),
+					    MAX_BASE64_DECODED_SIZE(len));
 		if (base64_decode(password, len, NULL, buf) < 0)
 			return -1;
 
diff -r a1018630276b -r f8151445662e src/lib-index/mail-index-sync-keywords.c
--- a/src/lib-index/mail-index-sync-keywords.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/lib-index/mail-index-sync-keywords.c	Wed Nov 25 13:19:42 2009 -0500
@@ -76,16 +76,17 @@ static void keywords_ext_register(struct
 				  uint32_t ext_map_idx, uint32_t reset_id,
 				  uint32_t hdr_size, uint32_t keywords_count)
 {
-	buffer_t *ext_intro_buf;
+	buffer_t ext_intro_buf;
 	struct mail_transaction_ext_intro *u;
+	unsigned char ext_intro_data[sizeof(*u) +
+				     sizeof(MAIL_INDEX_EXT_KEYWORDS)-1];
 
 	i_assert(keywords_count > 0);
 
-	ext_intro_buf =
-		buffer_create_static_hard(pool_datastack_create(), sizeof(*u) +
-					  sizeof(MAIL_INDEX_EXT_KEYWORDS)-1);
-
-	u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u));
+	buffer_create_data(&ext_intro_buf, ext_intro_data,
+			   sizeof(ext_intro_data));
+
+	u = buffer_append_space_unsafe(&ext_intro_buf, sizeof(*u));
 	u->ext_id = ext_map_idx;
 	u->reset_id = reset_id;
 	u->hdr_size = hdr_size;
@@ -99,7 +100,7 @@ static void keywords_ext_register(struct
 
 	if (ext_map_idx == (uint32_t)-1) {
 		u->name_size = strlen(MAIL_INDEX_EXT_KEYWORDS);
-		buffer_append(ext_intro_buf, MAIL_INDEX_EXT_KEYWORDS,
+		buffer_append(&ext_intro_buf, MAIL_INDEX_EXT_KEYWORDS,
 			      u->name_size);
 	}
 
diff -r a1018630276b -r f8151445662e src/lib-index/mail-transaction-log-append.c
--- a/src/lib-index/mail-transaction-log-append.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/lib-index/mail-transaction-log-append.c	Wed Nov 25 13:19:42 2009 -0500
@@ -133,8 +133,9 @@ log_append_sync_offset_if_needed(struct 
 	struct mail_transaction_log_file *file = ctx->log->head;
 	struct mail_transaction_header_update *u;
 	struct mail_transaction_header *hdr;
-	buffer_t *buf;
 	uint32_t offset;
+	buffer_t buf;
+	unsigned char update_data[sizeof(*u) + sizeof(offset)];
 
 	if (file->max_tail_offset == file->sync_offset) {
 		/* FIXME: when we remove exclusive log locking, we
@@ -151,15 +152,14 @@ log_append_sync_offset_if_needed(struct 
 		return;
 	i_assert(offset > file->saved_tail_offset);
 
-	buf = buffer_create_static_hard(pool_datastack_create(),
-					sizeof(*u) + sizeof(offset));
-	u = buffer_append_space_unsafe(buf, sizeof(*u));
+	buffer_create_data(&buf, update_data, sizeof(update_data));
+	u = buffer_append_space_unsafe(&buf, sizeof(*u));
 	u->offset = offsetof(struct mail_index_header, log_file_tail_offset);
 	u->size = sizeof(offset);
-	buffer_append(buf, &offset, sizeof(offset));
+	buffer_append(&buf, &offset, sizeof(offset));
 
 	mail_transaction_log_append_add(ctx, MAIL_TRANSACTION_HEADER_UPDATE,
-					buf->data, buf->used);
+					buf.data, buf.used);
 }
 
 static int
diff -r a1018630276b -r f8151445662e src/lib/buffer.c
--- a/src/lib/buffer.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/lib/buffer.c	Wed Nov 25 13:19:42 2009 -0500
@@ -67,16 +67,6 @@ buffer_check_limits(struct real_buffer *
 	if (new_size > buf->used)
 		buf->used = new_size;
 	i_assert(buf->used <= buf->alloc);
-}
-
-buffer_t *buffer_create_static_hard(pool_t pool, size_t size)
-{
-	struct real_buffer *buf;
-
-	buf = p_new(pool, struct real_buffer, 1);
-	buf->pool = pool;
-	buffer_alloc(buf, size);
-	return (buffer_t *)buf;
 }
 
 void buffer_create_data(buffer_t *buffer, void *data, size_t size)
diff -r a1018630276b -r f8151445662e src/lib/buffer.h
--- a/src/lib/buffer.h	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/lib/buffer.h	Wed Nov 25 13:19:42 2009 -0500
@@ -12,9 +12,8 @@ struct buffer {
    realloc()ed. You shouldn't rely on it being valid if you have modified
    buffer in any way. */
 
-/* Create a static sized buffer. Writes past this size will kill the program. */
-buffer_t *buffer_create_static_hard(pool_t pool, size_t size);
-/* Create a modifiable buffer from given data. */
+/* Create a modifiable buffer from given data. Writes past this size will
+   i_panic(). */
 void buffer_create_data(buffer_t *buffer, void *data, size_t size);
 /* Create a non-modifiable buffer from given data. */
 void buffer_create_const_data(buffer_t *buffer, const void *data, size_t size);
diff -r a1018630276b -r f8151445662e src/pop3-login/client.c
--- a/src/pop3-login/client.c	Wed Nov 25 12:48:21 2009 -0500
+++ b/src/pop3-login/client.c	Wed Nov 25 13:19:42 2009 -0500
@@ -131,22 +131,22 @@ static char *get_apop_challenge(struct p
 static char *get_apop_challenge(struct pop3_client *client)
 {
 	unsigned char buffer[16];
-	buffer_t *buf;
+	unsigned char buffer_base64[MAX_BASE64_ENCODED_SIZE(sizeof(buffer)) + 1];
+	buffer_t buf;
 
 	auth_client_get_connect_id(auth_client, &client->apop_server_pid,
 				   &client->apop_connect_uid);
 
 	random_fill(buffer, sizeof(buffer));
-	buf = buffer_create_static_hard(pool_datastack_create(),
-			MAX_BASE64_ENCODED_SIZE(sizeof(buffer)) + 1);
-	base64_encode(buffer, sizeof(buffer), buf);
-	buffer_append_c(buf, '\0');
+	buffer_create_data(&buf, buffer_base64, sizeof(buffer_base64));
+	base64_encode(buffer, sizeof(buffer), &buf);
+	buffer_append_c(&buf, '\0');
 
 	return i_strdup_printf("<%x.%x.%lx.%s@%s>",
 			       client->apop_server_pid,
 			       client->apop_connect_uid,
 			       (unsigned long)ioloop_time,
-			       (const char *)buf->data, my_hostname);
+			       (const char *)buf.data, my_hostname);
 }
 
 static void pop3_client_send_greeting(struct client *client)


More information about the dovecot-cvs mailing list