mail-cache-compress.c revision 6157a322f2ac1ea1332d9003ecb0b11466aa8fe7
5f5870385cff47efd2f58e7892f251cf13761528Timo Sirainen/* Copyright (c) 2003-2007 Dovecot authors, see the included COPYING file */
395682d473b161c86165e7b9323ce4e45afb94bdTimo Sirainenmail_cache_merge_bitmask(struct mail_cache_copy_context *ctx,
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen unsigned char *dest;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen unsigned int i, *pos;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen pos = array_idx_modifiable(&ctx->bitmask_pos, field->field_idx);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen if (*pos == 0) {
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* we decided to drop this field */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen dest = buffer_get_space_unsafe(ctx->buffer, *pos, field->size);
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen dest[i] |= ((const unsigned char*)field->data)[i];
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainenmail_cache_compress_field(struct mail_cache_copy_context *ctx,
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen file_field_idx = ctx->field_file_map[field->field_idx];
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen cache_field = &ctx->cache->fields[field->field_idx].field;
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen field_seen = buffer_get_space_unsafe(ctx->field_seen,
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* duplicate */
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen if (cache_field->type == MAIL_CACHE_FIELD_BITMASK)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen dec = cache_field->decision & ~MAIL_CACHE_DECISION_FORCED;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen buffer_append(ctx->buffer, &file_field_idx, sizeof(file_field_idx));
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen if (cache_field->field_size == (unsigned int)-1) {
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen buffer_append(ctx->buffer, &size32, sizeof(size32));
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen if (cache_field->type == MAIL_CACHE_FIELD_BITMASK) {
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen /* remember the position in case we need to update it */
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen array_idx_set(&ctx->bitmask_pos, field->field_idx, &pos);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen buffer_append(ctx->buffer, field->data, field->size);
99695d99930b35c2bac85d52e976b44cf8485d83Timo Sirainen buffer_append_zero(ctx->buffer, 4 - (field->size & 3));
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenget_next_file_seq(struct mail_cache *cache, struct mail_index_view *view)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen ext = mail_index_view_get_ext(view, cache->ext_id);
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen file_seq = ext != NULL ? ext->reset_id + 1 : (uint32_t)ioloop_time;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen if (cache->hdr != NULL && file_seq <= cache->hdr->file_seq)
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainenmail_cache_compress_get_fields(struct mail_cache_copy_context *ctx,
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen unsigned int i, j, idx;
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* Make mail_cache_header_fields_get() return the fields in
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen the same order as we saved them. */
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen memcpy(cache->field_file_map, ctx->field_file_map,
c115c742f730e312d6b6ab5064595cd0d8b4e26eTimo Sirainen /* reverse mapping */
eb0816090cf5a549280ad783b9aa6fec199d36baTimo Sirainen cache->file_field_map = used_fields_count == 0 ? NULL :
363929157786b549c80630bda3c3575f5115c6c5Timo Sirainen for (i = j = 0; i < cache->fields_count; i++) {
for (i = 0; i < orig_fields_count; i++)
used_fields_count = i;
ext_offset = 0;
sizeof(cache_rec));
if (ret >= 0) {
if (ret == 0)
bool *unlock)
unsigned int i, count;
0, &dotlock);
if (ret < 0)
if (*unlock) {
for (i = 0; i < count; i++) {
if (offsets[i] != 0) {
if (*unlock) {
int ret;
if (unlock) {
return ret;