mail-index-transaction-private.h revision 082e82792b8ac33ad42beac510441b37a3c50737
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#ifndef MAIL_INDEX_TRANSACTION_PRIVATE_H
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#define MAIL_INDEX_TRANSACTION_PRIVATE_H
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include "seq-range-array.h"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include "mail-transaction-log.h"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub HrozekARRAY_DEFINE_TYPE(seq_array_array, ARRAY_TYPE(seq_array));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekstruct mail_index_transaction_keyword_update {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY_TYPE(seq_range) add_seq;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY_TYPE(seq_range) remove_seq;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekstruct mail_index_transaction_ext_hdr_update {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek size_t alloc_size;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek /* mask is in bytes, not bits */
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned char *mask;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned char *data;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekstruct mail_index_transaction_vfuncs {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek void (*reset)(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek int (*commit)(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct mail_index_transaction_commit_result *result_r);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek void (*rollback)(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekunion mail_index_transaction_module_context {
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek struct mail_index_module_register *reg;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
2913240aee51ce81195148a4d814e967f66839c4Simo Sorcestruct mail_index_flag_update {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t uid1, uid2;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint16_t add_flags;
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce uint16_t remove_flags;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekstruct mail_index_transaction {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct mail_index_transaction *prev, *next;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek int refcount;
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek enum mail_index_transaction_flags flags;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek struct mail_index_transaction_vfuncs v;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek struct mail_index_view *view;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct mail_index_view *latest_view;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek /* NOTE: If you add anything new, remember to update
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek mail_index_transaction_reset_v() to reset it. */
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(struct mail_index_record) appends;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek uint32_t first_new_seq, last_new_seq;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek uint32_t highest_append_uid;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek /* lowest/highest sequence that updates flags/keywords */
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek uint32_t min_flagupdate_seq, max_flagupdate_seq;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ARRAY(struct mail_transaction_modseq_update) modseq_updates;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ARRAY(struct mail_transaction_expunge_guid) expunges;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ARRAY(struct mail_index_flag_update) updates;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek size_t last_update_idx;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek unsigned char pre_hdr_change[sizeof(struct mail_index_header)];
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek unsigned char pre_hdr_mask[sizeof(struct mail_index_header)];
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek unsigned char post_hdr_change[sizeof(struct mail_index_header)];
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek unsigned char post_hdr_mask[sizeof(struct mail_index_header)];
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(struct mail_index_transaction_ext_hdr_update) ext_hdr_updates;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY_TYPE(seq_array_array) ext_rec_updates;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY_TYPE(seq_array_array) ext_rec_atomics;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(struct mail_transaction_ext_intro) ext_resizes;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(struct mail_transaction_ext_reset) ext_resets;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(uint32_t) ext_reset_ids;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ARRAY(uint32_t) ext_reset_atomic;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ARRAY(struct mail_index_transaction_keyword_update) keyword_updates;
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce buffer_t *attribute_updates; /* [+-][ps]key\0.. */
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek buffer_t *attribute_updates_suffix; /* <timestamp>[<value len>].. */
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek uint64_t min_highest_modseq;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek uint64_t max_modseq;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY_TYPE(seq_range) *conflict_seqs;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek /* Module-specific contexts. */
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY(union mail_index_transaction_module_context *) module_contexts;
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int no_appends:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int sync_transaction:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int appends_nonsorted:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int expunges_nonsorted:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int drop_unnecessary_flag_updates:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int pre_hdr_changed:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int post_hdr_changed:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int reset:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int index_deleted:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int index_undeleted:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int commit_deleted_index:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int tail_offset_changed:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek /* non-extension updates. flag updates don't change this because
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek they may be added and removed, so be sure to check that the updates
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek array is non-empty also. */
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int log_updates:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek /* extension updates */
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int log_ext_updates:1;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek};
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#define MAIL_INDEX_TRANSACTION_HAS_CHANGES(t) \
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ((t)->log_updates || (t)->log_ext_updates || \
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek (array_is_created(&(t)->updates) && array_count(&(t)->updates) > 0) || \
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek (t)->index_deleted || (t)->index_undeleted)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekextern void (*hook_mail_index_transaction_created)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek (struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekstruct mail_index_record *
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekmail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_ref(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_unref(struct mail_index_transaction **t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_reset_v(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_sort_appends(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_sort_expunges(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekuint32_t mail_index_transaction_get_next_uid(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_set_log_updates(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_update_day_headers(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekunsigned int
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekmail_index_transaction_get_flag_update_pos(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int left_idx,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int right_idx,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t seq);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_lookup_latest_keywords(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t seq,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ARRAY_TYPE(keyword_indexes) *keywords);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekbool mail_index_cancel_flag_updates(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t seq);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekbool mail_index_cancel_keyword_updates(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t seq);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_finish(struct mail_index_transaction *t);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_transaction_export(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct mail_transaction_log_append_ctx *append_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekint mail_transaction_expunge_guid_cmp(const struct mail_transaction_expunge_guid *e1,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const struct mail_transaction_expunge_guid *e2);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekunsigned int
2913240aee51ce81195148a4d814e967f66839c4Simo Sorcemail_index_transaction_get_flag_update_pos(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int left_idx,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek unsigned int right_idx,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t seq);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekvoid mail_index_ext_using_reset_id(struct mail_index_transaction *t,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek uint32_t ext_id, uint32_t reset_id);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#endif
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek