# HG changeset patch # User Timo Sirainen # Date 1147092531 -10800 # Node ID 8fd5dfa271efeeef2cd1c80eebb74719de55a8c0 # Parent 327abd67380df9b8068253ad1b4897bbe0914b46 Added mail_cache_field_want_add() and mail_cache_field_can_add() diff -r 327abd67380d -r 8fd5dfa271ef src/lib-index/mail-cache-transaction.c --- a/src/lib-index/mail-cache-transaction.c Mon May 08 14:25:14 2006 +0300 +++ b/src/lib-index/mail-cache-transaction.c Mon May 08 15:48:51 2006 +0300 @@ -747,6 +747,30 @@ buffer_append_zero(ctx->cache_data, 4 - (data_size & 3)); } +bool mail_cache_field_want_add(struct mail_cache_transaction_ctx *ctx, + uint32_t seq, unsigned int field) +{ + enum mail_cache_decision_type decision; + + decision = mail_cache_field_get_decision(ctx->view->cache, field); + if ((decision & ~MAIL_CACHE_DECISION_FORCED) == MAIL_CACHE_DECISION_NO) + return FALSE; + + return mail_cache_field_exists(ctx->view, seq, field) == 0; +} + +bool mail_cache_field_can_add(struct mail_cache_transaction_ctx *ctx, + uint32_t seq, unsigned int field) +{ + enum mail_cache_decision_type decision; + + decision = mail_cache_field_get_decision(ctx->view->cache, field); + if (decision == (MAIL_CACHE_DECISION_FORCED | MAIL_CACHE_DECISION_NO)) + return FALSE; + + return mail_cache_field_exists(ctx->view, seq, field) == 0; +} + static int mail_cache_link_unlocked(struct mail_cache *cache, uint32_t old_offset, uint32_t new_offset) { diff -r 327abd67380d -r 8fd5dfa271ef src/lib-index/mail-cache.h --- a/src/lib-index/mail-cache.h Mon May 08 14:25:14 2006 +0300 +++ b/src/lib-index/mail-cache.h Mon May 08 15:48:51 2006 +0300 @@ -72,6 +72,15 @@ must be exactly the expected size. */ void mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq, unsigned int field, const void *data, size_t data_size); +/* Returns TRUE if field is wanted to be added and it doesn't already exist. + If current caching decisions say not to cache this field, FALSE is returned. + If seq is 0, the existence isn't checked. */ +bool mail_cache_field_want_add(struct mail_cache_transaction_ctx *ctx, + uint32_t seq, unsigned int field); +/* Like mail_cache_field_want_add(), but in caching decisions FALSE is + returned only if the decision is a forced no. */ +bool mail_cache_field_can_add(struct mail_cache_transaction_ctx *ctx, + uint32_t seq, unsigned int field); /* Retursn 1 if field exists, 0 if not, -1 if error. */ int mail_cache_field_exists(struct mail_cache_view *view, uint32_t seq,