c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef MAIL_INDEX_SYNC_PRIVATE_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define MAIL_INDEX_SYNC_PRIVATE_H
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
93e8e70062fe33db681a9b3b66bb5e523e5a84f7Timo Sirainen#include "mail-index-private.h"
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen#include "mail-transaction-log.h"
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainenstruct uid_range {
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen uint32_t uid1, uid2;
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen};
8d80659e504ffb34bb0c6a633184fece35751b18Timo SirainenARRAY_DEFINE_TYPE(uid_range, struct uid_range);
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen
26ff8f8a4867bf8e9551a27a2de8c12cd138b065Timo Sirainenstruct mail_index_sync_list {
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen const ARRAY_TYPE(uid_range) *array;
26ff8f8a4867bf8e9551a27a2de8c12cd138b065Timo Sirainen unsigned int idx;
bb10ebcf076c959c752f583746d83805d7686df8Timo Sirainen unsigned int keyword_idx:31;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool keyword_remove:1;
26ff8f8a4867bf8e9551a27a2de8c12cd138b065Timo Sirainen};
26ff8f8a4867bf8e9551a27a2de8c12cd138b065Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenstruct mail_index_expunge_handler {
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen mail_index_expunge_handler_t *handler;
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen void *context;
da985034a708db2f61394b30d117050ae6829ee5Timo Sirainen void **sync_context;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen uint32_t record_offset;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen};
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen
7394389230750c45b105cdefb5850c81cae8cdc0Timo Sirainenstruct mail_index_sync_map_ctx {
7394389230750c45b105cdefb5850c81cae8cdc0Timo Sirainen struct mail_index_view *view;
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen struct mail_index_modseq_sync *modseq_ctx;
7ded22760598b78ee29f9418eacc0abe3fb51055Timo Sirainen uint32_t cur_ext_map_idx;
3403e054eacf125e757bf6c66abf0ea9f086a4b6Timo Sirainen uint32_t cur_ext_record_size;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen
2c677e9d339bc91d5b54376ba2986f71476c06abTimo Sirainen uint32_t ext_intro_seq;
f81a4d2002da0db33d11ca694d3a91b3ee2a0fdbTimo Sirainen uoff_t ext_intro_offset, ext_intro_end_offset;
2c677e9d339bc91d5b54376ba2986f71476c06abTimo Sirainen
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(struct mail_index_expunge_handler) expunge_handlers;
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainen ARRAY(void *) extra_contexts;
91d4c7b37580b031ed7b0154ae10c643521803f3Timo Sirainen buffer_t *unknown_extensions;
7394389230750c45b105cdefb5850c81cae8cdc0Timo Sirainen
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen enum mail_index_sync_handler_type type;
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool sync_handlers_initialized:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool expunge_handlers_set:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool expunge_handlers_used:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool cur_ext_ignore:1;
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool internal_update:1; /* used by keywords for ext_intro */
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen bool errors:1;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen};
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainenextern struct mail_transaction_map_functions mail_index_map_sync_funcs;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainenvoid mail_index_sync_map_init(struct mail_index_sync_map_ctx *sync_map_ctx,
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen struct mail_index_view *view,
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainen enum mail_index_sync_handler_type type);
5626ae5e3316eced244adb6485c0927f1c7fdc41Timo Sirainenvoid mail_index_sync_map_deinit(struct mail_index_sync_map_ctx *sync_map_ctx);
b0be0bead3d6963149f7f2a9504b8ab5aced9af5Timo Sirainenint mail_index_sync_map(struct mail_index_map **map,
6a4bfb2b0bb9f53fb1d4e705bf3948ef4d1ecccbTimo Sirainen enum mail_index_sync_handler_type type, bool force,
6a4bfb2b0bb9f53fb1d4e705bf3948ef4d1ecccbTimo Sirainen const char *sync_reason);
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen
d143077bd518de129b8d446fb58e003903e50867Timo Sirainenint mail_index_sync_record(struct mail_index_sync_map_ctx *ctx,
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen const struct mail_transaction_header *hdr,
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen const void *data);
d143077bd518de129b8d446fb58e003903e50867Timo Sirainen
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenstruct mail_index_map *
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenmail_index_sync_get_atomic_map(struct mail_index_sync_map_ctx *ctx);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenvoid mail_index_sync_init_expunge_handlers(struct mail_index_sync_map_ctx *ctx);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenvoid
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenmail_index_sync_deinit_expunge_handlers(struct mail_index_sync_map_ctx *ctx);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenvoid mail_index_sync_init_handlers(struct mail_index_sync_map_ctx *ctx);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenvoid mail_index_sync_deinit_handlers(struct mail_index_sync_map_ctx *ctx);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainenvoid mail_index_sync_ext_init(struct mail_index_sync_map_ctx *ctx,
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen const char *name, bool fix_size,
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen uint32_t *ext_map_idx_r);
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenint mail_index_sync_ext_intro(struct mail_index_sync_map_ctx *ctx,
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen const struct mail_transaction_ext_intro *u);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenint mail_index_sync_ext_reset(struct mail_index_sync_map_ctx *ctx,
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen const struct mail_transaction_ext_reset *u);
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainenint mail_index_sync_ext_hdr_update(struct mail_index_sync_map_ctx *ctx,
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen uint32_t offset, uint32_t size,
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainen const void *data);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenint
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainenmail_index_sync_ext_rec_update(struct mail_index_sync_map_ctx *ctx,
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen const struct mail_transaction_ext_rec_update *u);
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainenint
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainenmail_index_sync_ext_atomic_inc(struct mail_index_sync_map_ctx *ctx,
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainen const struct mail_transaction_ext_atomic_inc *u);
a0d34d3982507f513a9d800082481e9faeb9a943Timo Sirainen
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenint mail_index_sync_keywords(struct mail_index_sync_map_ctx *ctx,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const struct mail_transaction_header *hdr,
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen const struct mail_transaction_keyword_update *rec);
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainenint
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainenmail_index_sync_keywords_reset(struct mail_index_sync_map_ctx *ctx,
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen const struct mail_transaction_header *hdr,
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen const struct mail_transaction_keyword_reset *r);
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainen
9887c39c5ba429169389153ca99de49e084a73f0Timo Sirainenvoid mail_index_sync_set_corrupted(struct mail_index_sync_map_ctx *ctx,
43d32cbe60fdaef2699d99f1ca259053e9350411Timo Sirainen const char *fmt, ...) ATTR_FORMAT(2, 3);
9887c39c5ba429169389153ca99de49e084a73f0Timo Sirainen
e26a771fad55dfba4d5021d12ed5685c951d9b7bTimo Sirainen#ifdef DEBUG
e26a771fad55dfba4d5021d12ed5685c951d9b7bTimo Sirainenvoid mail_index_map_check(struct mail_index_map *map);
e26a771fad55dfba4d5021d12ed5685c951d9b7bTimo Sirainen#endif
e26a771fad55dfba4d5021d12ed5685c951d9b7bTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen#endif