]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Removed buffer_create_static_hard().
authorTimo Sirainen <tss@iki.fi>
Wed, 25 Nov 2009 18:19:42 +0000 (13:19 -0500)
committerTimo Sirainen <tss@iki.fi>
Wed, 25 Nov 2009 18:19:42 +0000 (13:19 -0500)
buffer_create_data() handles most of the situations where it was wanted.

--HG--
branch : HEAD

src/auth/mech-digest-md5.c
src/auth/password-scheme.c
src/lib-index/mail-index-sync-keywords.c
src/lib-index/mail-transaction-log-append.c
src/lib/buffer.c
src/lib/buffer.h
src/pop3-login/client.c

index 21f9c88ce5afa519c89638a4e1cb24794bd08006..d6e34fbd0a4819d7d9119d34161838a65117f363 100644 (file)
@@ -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) {
index b7c4c76e3a08e0dd922acbcfce6e25f0639385c4..5895c2e3e3bfd678a8b472b655c0ee917a3711ff 100644 (file)
@@ -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;
 
index a768b91e358a7ec621f8a2f369f53438961e56f8..c2b479843df0dd27d7035eb7b372e030dd829d98 100644 (file)
@@ -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);
        }
 
index c4c06d358a796f2560ce5aaa32235b65ca9c5493..bcd8109ef7cd61d776e1539dd885957a4a863817 100644 (file)
@@ -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
index bcb30149a4c9f0dd1d506dde79863f838c64016d..2c948068fd501c0326bf1fd175a6fb895747b079 100644 (file)
@@ -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;
index b6452192d129803019fc74dd6ab6434db2cd14a1..633bb0e229b6a63fa4d06f8e72e82b06d825e658 100644 (file)
@@ -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);
index 321fac9bfeea0edc8090238e12d1d1b44fb3cbc9..e5f635ae7640f703082fbc3a506df1b168f1c943 100644 (file)
@@ -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)