From: Timo Sirainen Date: Wed, 25 Nov 2009 18:19:42 +0000 (-0500) Subject: Removed buffer_create_static_hard(). X-Git-Tag: 2.0.beta1~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02752bc8d64df8cd361f464e55422f7b3f2f143e;p=thirdparty%2Fdovecot%2Fcore.git Removed buffer_create_static_hard(). buffer_create_data() handles most of the situations where it was wanted. --HG-- branch : HEAD --- diff --git a/src/auth/mech-digest-md5.c b/src/auth/mech-digest-md5.c index 21f9c88ce5..d6e34fbd0a 100644 --- a/src/auth/mech-digest-md5.c +++ b/src/auth/mech-digest-md5.c @@ -57,10 +57,11 @@ struct digest_auth_request { 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(struct digest_auth_request *request) /* 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 --git a/src/auth/password-scheme.c b/src/auth/password-scheme.c index b7c4c76e3a..5895c2e3e3 100644 --- a/src/auth/password-scheme.c +++ b/src/auth/password-scheme.c @@ -155,8 +155,8 @@ int password_decode(const char *password, const char *scheme, *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, const char *scheme, 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 --git a/src/lib-index/mail-index-sync-keywords.c b/src/lib-index/mail-index-sync-keywords.c index a768b91e35..c2b479843d 100644 --- a/src/lib-index/mail-index-sync-keywords.c +++ b/src/lib-index/mail-index-sync-keywords.c @@ -76,16 +76,17 @@ static void keywords_ext_register(struct mail_index_sync_map_ctx *ctx, 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); + buffer_create_data(&ext_intro_buf, ext_intro_data, + sizeof(ext_intro_data)); - u = buffer_append_space_unsafe(ext_intro_buf, sizeof(*u)); + 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 mail_index_sync_map_ctx *ctx, 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 --git a/src/lib-index/mail-transaction-log-append.c b/src/lib-index/mail-transaction-log-append.c index c4c06d358a..bcd8109ef7 100644 --- a/src/lib-index/mail-transaction-log-append.c +++ b/src/lib-index/mail-transaction-log-append.c @@ -133,8 +133,9 @@ log_append_sync_offset_if_needed(struct mail_transaction_log_append_ctx *ctx) 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 mail_transaction_log_append_ctx *ctx) 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 --git a/src/lib/buffer.c b/src/lib/buffer.c index bcb30149a4..2c948068fd 100644 --- a/src/lib/buffer.c +++ b/src/lib/buffer.c @@ -69,16 +69,6 @@ buffer_check_limits(struct real_buffer *buf, size_t pos, size_t data_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) { struct real_buffer *buf; diff --git a/src/lib/buffer.h b/src/lib/buffer.h index b6452192d1..633bb0e229 100644 --- a/src/lib/buffer.h +++ b/src/lib/buffer.h @@ -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 --git a/src/pop3-login/client.c b/src/pop3-login/client.c index 321fac9bfe..e5f635ae76 100644 --- a/src/pop3-login/client.c +++ b/src/pop3-login/client.c @@ -131,22 +131,22 @@ static void pop3_client_destroy(struct client *client) 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)