From: Timo Sirainen Date: Sat, 19 Jul 2008 11:43:24 +0000 (+0300) Subject: struct mailbox_header_lookup_ctx can now be referenced/unreferenced so it X-Git-Tag: 1.2.alpha1~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f95b3d29bc56f139c18c880aa574a0ca72b0cffb;p=thirdparty%2Fdovecot%2Fcore.git struct mailbox_header_lookup_ctx can now be referenced/unreferenced so it can be shared among multiple struct mails. --HG-- branch : HEAD --- diff --git a/src/deliver/deliver.c b/src/deliver/deliver.c index 0773e419aa..696979e713 100644 --- a/src/deliver/deliver.c +++ b/src/deliver/deliver.c @@ -1088,7 +1088,7 @@ int main(int argc, char *argv[]) i_free(explicit_envelope_sender); mail_free(&mail); - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); mailbox_transaction_rollback(&t); mailbox_close(&box); diff --git a/src/imap/imap-fetch-body.c b/src/imap/imap-fetch-body.c index 9a102a02cc..5382613872 100644 --- a/src/imap/imap-fetch-body.c +++ b/src/imap/imap-fetch-body.c @@ -444,7 +444,7 @@ fetch_body_header_fields(struct imap_fetch_context *ctx, struct mail *mail, if (mail == NULL) { /* deinit */ - mailbox_header_lookup_deinit(&body->header_ctx); + mailbox_header_lookup_unref(&body->header_ctx); return 0; } diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index 185ef5705e..1efb0a6713 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -568,7 +568,7 @@ int imap_fetch_deinit(struct imap_fetch_context *ctx) ctx->failed = TRUE; } if (ctx->all_headers_ctx != NULL) - mailbox_header_lookup_deinit(&ctx->all_headers_ctx); + mailbox_header_lookup_unref(&ctx->all_headers_ctx); if (ctx->trans != NULL) { /* even if something failed, we want to commit changes to diff --git a/src/imap/imap-sort.c b/src/imap/imap-sort.c index 8994ab3246..45b0c39a68 100644 --- a/src/imap/imap-sort.c +++ b/src/imap/imap-sort.c @@ -108,6 +108,6 @@ int imap_sort(struct client_command_context *cmd, struct mail_search_args *args, } if (headers_ctx != NULL) - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); return ret; } diff --git a/src/lib-storage/index/cydir/cydir-storage.c b/src/lib-storage/index/cydir/cydir-storage.c index df4b6283e2..27b4c87004 100644 --- a/src/lib-storage/index/cydir/cydir-storage.c +++ b/src/lib-storage/index/cydir/cydir-storage.c @@ -441,7 +441,8 @@ struct mailbox cydir_mailbox = { index_storage_get_expunged_uids, index_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock, diff --git a/src/lib-storage/index/dbox/dbox-storage.c b/src/lib-storage/index/dbox/dbox-storage.c index 6ba864fe5b..c089ff818c 100644 --- a/src/lib-storage/index/dbox/dbox-storage.c +++ b/src/lib-storage/index/dbox/dbox-storage.c @@ -701,7 +701,8 @@ struct mailbox dbox_mailbox = { index_storage_get_expunged_uids, dbox_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock, diff --git a/src/lib-storage/index/index-mail-headers.c b/src/lib-storage/index/index-mail-headers.c index 640bfe82c6..81e17543be 100644 --- a/src/lib-storage/index/index-mail-headers.c +++ b/src/lib-storage/index/index-mail-headers.c @@ -458,7 +458,7 @@ int index_mail_headers_get_envelope(struct index_mail *mail) header_ctx = mailbox_header_lookup_init(&mail->ibox->box, imap_envelope_headers); if (mail_get_header_stream(&mail->mail.mail, header_ctx, &stream) < 0) { - mailbox_header_lookup_deinit(&header_ctx); + mailbox_header_lookup_unref(&header_ctx); return -1; } @@ -469,7 +469,7 @@ int index_mail_headers_get_envelope(struct index_mail *mail) imap_envelope_parse_callback, mail); mail->data.save_envelope = FALSE; } - mailbox_header_lookup_deinit(&header_ctx); + mailbox_header_lookup_unref(&header_ctx); if (mail->data.stream != NULL) i_stream_seek(mail->data.stream, old_offset); @@ -595,7 +595,7 @@ index_mail_get_raw_headers(struct index_mail *mail, const char *field, headers_ctx = mailbox_header_lookup_init( &mail->ibox->box, headers); ret = index_mail_parse_headers(mail, headers_ctx); - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); if (ret < 0) return -1; } @@ -818,7 +818,15 @@ index_header_lookup_init(struct mailbox *box, const char *const headers[]) return ctx; } -void index_header_lookup_deinit(struct mailbox_header_lookup_ctx *_ctx) +void index_header_lookup_ref(struct mailbox_header_lookup_ctx *_ctx) +{ + struct index_header_lookup_ctx *ctx = + (struct index_header_lookup_ctx *)_ctx; + + pool_ref(ctx->pool); +} + +void index_header_lookup_unref(struct mailbox_header_lookup_ctx *_ctx) { struct index_header_lookup_ctx *ctx = (struct index_header_lookup_ctx *)_ctx; diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index 8bd906e73f..2423eccbf4 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -1071,7 +1071,10 @@ void index_mail_init(struct index_mail *mail, mail->ibox = t->ibox; mail->trans = t; mail->wanted_fields = wanted_fields; - mail->wanted_headers = wanted_headers; + if (wanted_headers != NULL) { + mail->wanted_headers = wanted_headers; + mailbox_header_lookup_ref(_wanted_headers); + } } void index_mail_close(struct mail *_mail) @@ -1282,6 +1285,8 @@ bool index_mail_set_uid(struct mail *_mail, uint32_t uid) void index_mail_free(struct mail *_mail) { struct index_mail *mail = (struct index_mail *)_mail; + struct mailbox_header_lookup_ctx *headers_ctx = + (struct mailbox_header_lookup_ctx *)mail->wanted_headers; mail->mail.v.close(_mail); @@ -1297,6 +1302,8 @@ void index_mail_free(struct mail *_mail) if (array_is_created(&mail->header_match_lines)) array_free(&mail->header_match_lines); + if (headers_ctx != NULL) + mailbox_header_lookup_unref(&headers_ctx); pool_unref(&mail->data_pool); pool_unref(&mail->mail.pool); } diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 02785a6711..8be12d07a4 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -586,7 +586,7 @@ static bool search_arg_match_text(struct mail_search_arg *args, headers); if (mail_get_header_stream(ctx->mail, headers_ctx, &input) < 0) { - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); return FALSE; } } @@ -603,7 +603,7 @@ static bool search_arg_match_text(struct mail_search_arg *args, message_parse_header(input, NULL, hdr_parser_flags, search_header, &hdr_ctx); if (headers_ctx != NULL) - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); } else { struct message_size hdr_size; diff --git a/src/lib-storage/index/index-storage.h b/src/lib-storage/index/index-storage.h index 8f9ff364a0..60f0404032 100644 --- a/src/lib-storage/index/index-storage.h +++ b/src/lib-storage/index/index-storage.h @@ -157,7 +157,8 @@ bool index_storage_get_expunged_uids(struct mailbox *box, uint64_t modseq, struct mailbox_header_lookup_ctx * index_header_lookup_init(struct mailbox *box, const char *const headers[]); -void index_header_lookup_deinit(struct mailbox_header_lookup_ctx *ctx); +void index_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx); +void index_header_lookup_unref(struct mailbox_header_lookup_ctx *ctx); struct mail_search_context * index_storage_search_init(struct mailbox_transaction_context *t, diff --git a/src/lib-storage/index/index-thread.c b/src/lib-storage/index/index-thread.c index 4b217c7704..e608c1cb59 100644 --- a/src/lib-storage/index/index-thread.c +++ b/src/lib-storage/index/index-thread.c @@ -433,7 +433,7 @@ mail_thread_update(struct mail_thread_context *ctx, bool reset) } T_END; } mail_free(&mail); - mailbox_header_lookup_deinit(&headers_ctx); + mailbox_header_lookup_unref(&headers_ctx); if (ret < 0 || ctx->thread_ctx.failed || ctx->thread_ctx.rebuild) return -1; diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index 1e02ddedc8..e76a42ecb8 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -1046,7 +1046,8 @@ struct mailbox maildir_mailbox = { index_storage_get_expunged_uids, index_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock, diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 8d5186e3e6..b4ce350f3b 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -1002,7 +1002,8 @@ struct mailbox mbox_mailbox = { index_storage_get_expunged_uids, index_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock, diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index c5697e670a..bb57b222de 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -297,7 +297,8 @@ struct mailbox raw_mailbox = { index_storage_get_expunged_uids, index_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock, diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 5d1c2750f9..c29524ca1e 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -145,7 +145,8 @@ struct mailbox_vfuncs { struct mailbox_header_lookup_ctx * (*header_lookup_init)(struct mailbox *box, const char *const headers[]); - void (*header_lookup_deinit)(struct mailbox_header_lookup_ctx *ctx); + void (*header_lookup_ref)(struct mailbox_header_lookup_ctx *ctx); + void (*header_lookup_unref)(struct mailbox_header_lookup_ctx *ctx); struct mail_search_context * (*search_init)(struct mailbox_transaction_context *t, diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index b388a2e7f8..309d65bb76 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -629,12 +629,17 @@ mailbox_header_lookup_init(struct mailbox *box, const char *const headers[]) return box->v.header_lookup_init(box, headers); } -void mailbox_header_lookup_deinit(struct mailbox_header_lookup_ctx **_ctx) +void mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx) +{ + ctx->box->v.header_lookup_ref(ctx); +} + +void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **_ctx) { struct mailbox_header_lookup_ctx *ctx = *_ctx; *_ctx = NULL; - ctx->box->v.header_lookup_deinit(ctx); + ctx->box->v.header_lookup_unref(ctx); } struct mail_search_context * diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index 464c44a04f..2fc9513183 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -404,7 +404,8 @@ bool mailbox_get_expunged_uids(struct mailbox *box, uint64_t modseq, /* Initialize header lookup for given headers. */ struct mailbox_header_lookup_ctx * mailbox_header_lookup_init(struct mailbox *box, const char *const headers[]); -void mailbox_header_lookup_deinit(struct mailbox_header_lookup_ctx **ctx); +void mailbox_header_lookup_ref(struct mailbox_header_lookup_ctx *ctx); +void mailbox_header_lookup_unref(struct mailbox_header_lookup_ctx **ctx); /* Initialize new search request. charset specifies the character set used in the search argument strings. If sort_program is non-NULL, the messages are diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index edd1eaaad6..5e1c4318cc 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -530,7 +530,8 @@ struct mailbox virtual_mailbox = { index_storage_get_expunged_uids, virtual_mail_alloc, index_header_lookup_init, - index_header_lookup_deinit, + index_header_lookup_ref, + index_header_lookup_unref, index_storage_search_init, index_storage_search_deinit, index_storage_search_next_nonblock,