1
/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
5
#include "dsync-worker-private.h"
7
void dsync_worker_deinit(struct dsync_worker **_worker)
9
struct dsync_worker *worker = *_worker;
12
worker->v.deinit(worker);
15
void dsync_worker_set_readonly(struct dsync_worker *worker)
17
worker->readonly = TRUE;
20
void dsync_worker_set_verbose(struct dsync_worker *worker)
22
worker->verbose = TRUE;
25
void dsync_worker_set_input_callback(struct dsync_worker *worker,
26
io_callback_t *callback, void *context)
28
worker->input_callback = callback;
29
worker->input_context = context;
32
bool dsync_worker_is_output_full(struct dsync_worker *worker)
34
return worker->v.is_output_full(worker);
37
void dsync_worker_set_output_callback(struct dsync_worker *worker,
38
io_callback_t *callback, void *context)
40
worker->output_callback = callback;
41
worker->output_context = context;
44
int dsync_worker_output_flush(struct dsync_worker *worker)
46
return worker->v.output_flush(worker);
49
struct dsync_worker_mailbox_iter *
50
dsync_worker_mailbox_iter_init(struct dsync_worker *worker)
52
return worker->v.mailbox_iter_init(worker);
55
int dsync_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *iter,
56
struct dsync_mailbox *dsync_box_r)
61
ret = iter->worker->v.mailbox_iter_next(iter, dsync_box_r);
66
int dsync_worker_mailbox_iter_deinit(struct dsync_worker_mailbox_iter **_iter)
68
struct dsync_worker_mailbox_iter *iter = *_iter;
71
return iter->worker->v.mailbox_iter_deinit(iter);
74
struct dsync_worker_subs_iter *
75
dsync_worker_subs_iter_init(struct dsync_worker *worker)
77
return worker->v.subs_iter_init(worker);
80
int dsync_worker_subs_iter_next(struct dsync_worker_subs_iter *iter,
81
struct dsync_worker_subscription *rec_r)
83
return iter->worker->v.subs_iter_next(iter, rec_r);
86
int dsync_worker_subs_iter_next_un(struct dsync_worker_subs_iter *iter,
87
struct dsync_worker_unsubscription *rec_r)
89
return iter->worker->v.subs_iter_next_un(iter, rec_r);
92
int dsync_worker_subs_iter_deinit(struct dsync_worker_subs_iter **_iter)
94
struct dsync_worker_subs_iter *iter = *_iter;
97
return iter->worker->v.subs_iter_deinit(iter);
100
void dsync_worker_set_subscribed(struct dsync_worker *worker,
101
const char *name, time_t last_change, bool set)
103
worker->v.set_subscribed(worker, name, last_change, set);
106
struct dsync_worker_msg_iter *
107
dsync_worker_msg_iter_init(struct dsync_worker *worker,
108
const mailbox_guid_t mailboxes[],
109
unsigned int mailbox_count)
111
i_assert(mailbox_count > 0);
112
return worker->v.msg_iter_init(worker, mailboxes, mailbox_count);
115
int dsync_worker_msg_iter_next(struct dsync_worker_msg_iter *iter,
116
unsigned int *mailbox_idx_r,
117
struct dsync_message *msg_r)
122
ret = iter->worker->v.msg_iter_next(iter, mailbox_idx_r, msg_r);
127
int dsync_worker_msg_iter_deinit(struct dsync_worker_msg_iter **_iter)
129
struct dsync_worker_msg_iter *iter = *_iter;
132
return iter->worker->v.msg_iter_deinit(iter);
135
void dsync_worker_create_mailbox(struct dsync_worker *worker,
136
const struct dsync_mailbox *dsync_box)
138
i_assert(dsync_box->uid_validity != 0 ||
139
dsync_mailbox_is_noselect(dsync_box));
141
if (!worker->readonly) T_BEGIN {
142
worker->v.create_mailbox(worker, dsync_box);
146
void dsync_worker_delete_mailbox(struct dsync_worker *worker,
147
const struct dsync_mailbox *dsync_box)
149
if (!worker->readonly) T_BEGIN {
150
worker->v.delete_mailbox(worker, dsync_box);
154
void dsync_worker_delete_dir(struct dsync_worker *worker,
155
const struct dsync_mailbox *dsync_box)
157
if (!worker->readonly) T_BEGIN {
158
worker->v.delete_dir(worker, dsync_box);
162
void dsync_worker_rename_mailbox(struct dsync_worker *worker,
163
const mailbox_guid_t *mailbox,
164
const struct dsync_mailbox *dsync_box)
166
if (!worker->readonly) T_BEGIN {
167
worker->v.rename_mailbox(worker, mailbox, dsync_box);
171
void dsync_worker_update_mailbox(struct dsync_worker *worker,
172
const struct dsync_mailbox *dsync_box)
174
if (!worker->readonly) T_BEGIN {
175
worker->v.update_mailbox(worker, dsync_box);
179
void dsync_worker_select_mailbox(struct dsync_worker *worker,
180
const struct dsync_mailbox *box)
183
worker->v.select_mailbox(worker, &box->mailbox_guid,
188
void dsync_worker_msg_update_metadata(struct dsync_worker *worker,
189
const struct dsync_message *msg)
191
if (!worker->failed && !worker->readonly)
192
worker->v.msg_update_metadata(worker, msg);
195
void dsync_worker_msg_update_uid(struct dsync_worker *worker,
196
uint32_t old_uid, uint32_t new_uid)
198
if (!worker->failed && !worker->readonly)
199
worker->v.msg_update_uid(worker, old_uid, new_uid);
202
void dsync_worker_msg_expunge(struct dsync_worker *worker, uint32_t uid)
204
if (!worker->failed && !worker->readonly)
205
worker->v.msg_expunge(worker, uid);
208
void dsync_worker_msg_copy(struct dsync_worker *worker,
209
const mailbox_guid_t *src_mailbox, uint32_t src_uid,
210
const struct dsync_message *dest_msg,
211
dsync_worker_copy_callback_t *callback,
214
if (!worker->failed && !worker->readonly) {
216
worker->v.msg_copy(worker, src_mailbox, src_uid,
217
dest_msg, callback, context);
220
callback(FALSE, context);
224
void dsync_worker_msg_save(struct dsync_worker *worker,
225
const struct dsync_message *msg,
226
const struct dsync_msg_static_data *data,
227
dsync_worker_save_callback_t *callback,
230
if (!worker->readonly) {
234
worker->v.msg_save(worker, msg, data,
238
const unsigned char *d;
241
while ((i_stream_read_data(data->input, &d, &size, 0)) > 0)
242
i_stream_skip(data->input, size);
247
void dsync_worker_msg_save_cancel(struct dsync_worker *worker)
249
worker->v.msg_save_cancel(worker);
252
void dsync_worker_msg_get(struct dsync_worker *worker,
253
const mailbox_guid_t *mailbox, uint32_t uid,
254
dsync_worker_msg_callback_t *callback, void *context)
259
callback(DSYNC_MSG_GET_RESULT_FAILED, NULL, context);
261
worker->v.msg_get(worker, mailbox, uid, callback, context);
265
void dsync_worker_finish(struct dsync_worker *worker,
266
dsync_worker_finish_callback_t *callback,
269
worker->v.finish(worker, callback, context);
272
void dsync_worker_set_failure(struct dsync_worker *worker)
274
worker->failed = TRUE;
277
bool dsync_worker_has_failed(struct dsync_worker *worker)
279
return worker->failed;
282
bool dsync_worker_has_unexpected_changes(struct dsync_worker *worker)
284
return worker->unexpected_changes;