#ifndef DSYNC_WORKER_H
#define DSYNC_WORKER_H
#include "ioloop.h"
#include "dsync-data.h"
enum dsync_msg_get_result {
DSYNC_MSG_GET_RESULT_SUCCESS,
DSYNC_MSG_GET_RESULT_EXPUNGED,
DSYNC_MSG_GET_RESULT_FAILED
};
struct dsync_worker_subscription {
const char *vname, *storage_name, *ns_prefix;
time_t last_change;
};
struct dsync_worker_unsubscription {
mailbox_guid_t name_sha1;
const char *ns_prefix;
time_t last_change;
};
typedef void dsync_worker_copy_callback_t(bool success, void *context);
typedef void dsync_worker_save_callback_t(void *context);
typedef void dsync_worker_msg_callback_t(enum dsync_msg_get_result result,
const struct dsync_msg_static_data *data,
void *context);
typedef void dsync_worker_finish_callback_t(bool success, void *context);
struct dsync_worker *
dsync_worker_init_local(struct mail_user *user, char alt_char);
struct dsync_worker *dsync_worker_init_proxy_client(int fd_in, int fd_out);
void dsync_worker_deinit(struct dsync_worker **worker);
void dsync_worker_set_readonly(struct dsync_worker *worker);
void dsync_worker_set_verbose(struct dsync_worker *worker);
void dsync_worker_set_input_callback(struct dsync_worker *worker,
io_callback_t *callback, void *context);
bool dsync_worker_is_output_full(struct dsync_worker *worker);
void dsync_worker_set_output_callback(struct dsync_worker *worker,
io_callback_t *callback, void *context);
int dsync_worker_output_flush(struct dsync_worker *worker);
struct dsync_worker_mailbox_iter *
dsync_worker_mailbox_iter_init(struct dsync_worker *worker);
int dsync_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *iter,
struct dsync_mailbox *dsync_box_r);
int dsync_worker_mailbox_iter_deinit(struct dsync_worker_mailbox_iter **iter);
struct dsync_worker_subs_iter *
dsync_worker_subs_iter_init(struct dsync_worker *worker);
int dsync_worker_subs_iter_next(struct dsync_worker_subs_iter *iter,
struct dsync_worker_subscription *rec_r);
int dsync_worker_subs_iter_next_un(struct dsync_worker_subs_iter *iter,
struct dsync_worker_unsubscription *rec_r);
int dsync_worker_subs_iter_deinit(struct dsync_worker_subs_iter **iter);
void dsync_worker_set_subscribed(struct dsync_worker *worker,
const char *name, time_t last_change,
bool set);
struct dsync_worker_msg_iter *
dsync_worker_msg_iter_init(struct dsync_worker *worker,
const mailbox_guid_t mailboxes[],
unsigned int mailbox_count);
int dsync_worker_msg_iter_next(struct dsync_worker_msg_iter *iter,
unsigned int *mailbox_idx_r,
struct dsync_message *msg_r);
int dsync_worker_msg_iter_deinit(struct dsync_worker_msg_iter **iter);
void dsync_worker_create_mailbox(struct dsync_worker *worker,
const struct dsync_mailbox *dsync_box);
void dsync_worker_delete_mailbox(struct dsync_worker *worker,
const struct dsync_mailbox *dsync_box);
void dsync_worker_delete_dir(struct dsync_worker *worker,
const struct dsync_mailbox *dsync_box);
void dsync_worker_rename_mailbox(struct dsync_worker *worker,
const mailbox_guid_t *mailbox,
const struct dsync_mailbox *dsync_box);
void dsync_worker_update_mailbox(struct dsync_worker *worker,
const struct dsync_mailbox *dsync_box);
void dsync_worker_select_mailbox(struct dsync_worker *worker,
const struct dsync_mailbox *box);
void dsync_worker_msg_update_metadata(struct dsync_worker *worker,
const struct dsync_message *msg);
void dsync_worker_msg_update_uid(struct dsync_worker *worker,
uint32_t old_uid, uint32_t new_uid);
void dsync_worker_msg_expunge(struct dsync_worker *worker, uint32_t uid);
void dsync_worker_msg_copy(struct dsync_worker *worker,
const mailbox_guid_t *src_mailbox, uint32_t src_uid,
const struct dsync_message *dest_msg,
dsync_worker_copy_callback_t *callback,
void *context);
void dsync_worker_msg_save(struct dsync_worker *worker,
const struct dsync_message *msg,
const struct dsync_msg_static_data *data,
dsync_worker_save_callback_t *callback,
void *context);
void dsync_worker_msg_save_cancel(struct dsync_worker *worker);
void dsync_worker_msg_get(struct dsync_worker *worker,
const mailbox_guid_t *mailbox, uint32_t uid,
dsync_worker_msg_callback_t *callback, void *context);
void dsync_worker_finish(struct dsync_worker *worker,
dsync_worker_finish_callback_t *callback,
void *context);
bool dsync_worker_has_failed(struct dsync_worker *worker);
bool dsync_worker_has_unexpected_changes(struct dsync_worker *worker);
#endif