~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

Viewing changes to src/dsync/dsync-worker.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/{control,rules}: enable PIE hardening.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009-2011 Dovecot authors, see the included COPYING file */
2
 
 
3
 
#include "lib.h"
4
 
#include "istream.h"
5
 
#include "dsync-worker-private.h"
6
 
 
7
 
void dsync_worker_deinit(struct dsync_worker **_worker)
8
 
{
9
 
        struct dsync_worker *worker = *_worker;
10
 
 
11
 
        *_worker = NULL;
12
 
        worker->v.deinit(worker);
13
 
}
14
 
 
15
 
void dsync_worker_set_readonly(struct dsync_worker *worker)
16
 
{
17
 
        worker->readonly = TRUE;
18
 
}
19
 
 
20
 
void dsync_worker_set_verbose(struct dsync_worker *worker)
21
 
{
22
 
        worker->verbose = TRUE;
23
 
}
24
 
 
25
 
void dsync_worker_set_input_callback(struct dsync_worker *worker,
26
 
                                     io_callback_t *callback, void *context)
27
 
{
28
 
        worker->input_callback = callback;
29
 
        worker->input_context = context;
30
 
}
31
 
 
32
 
bool dsync_worker_is_output_full(struct dsync_worker *worker)
33
 
{
34
 
        return worker->v.is_output_full(worker);
35
 
}
36
 
 
37
 
void dsync_worker_set_output_callback(struct dsync_worker *worker,
38
 
                                      io_callback_t *callback, void *context)
39
 
{
40
 
        worker->output_callback = callback;
41
 
        worker->output_context = context;
42
 
}
43
 
 
44
 
int dsync_worker_output_flush(struct dsync_worker *worker)
45
 
{
46
 
        return worker->v.output_flush(worker);
47
 
}
48
 
 
49
 
struct dsync_worker_mailbox_iter *
50
 
dsync_worker_mailbox_iter_init(struct dsync_worker *worker)
51
 
{
52
 
        return worker->v.mailbox_iter_init(worker);
53
 
}
54
 
 
55
 
int dsync_worker_mailbox_iter_next(struct dsync_worker_mailbox_iter *iter,
56
 
                                   struct dsync_mailbox *dsync_box_r)
57
 
{
58
 
        int ret;
59
 
 
60
 
        T_BEGIN {
61
 
                ret = iter->worker->v.mailbox_iter_next(iter, dsync_box_r);
62
 
        } T_END;
63
 
        return ret;
64
 
}
65
 
 
66
 
int dsync_worker_mailbox_iter_deinit(struct dsync_worker_mailbox_iter **_iter)
67
 
{
68
 
        struct dsync_worker_mailbox_iter *iter = *_iter;
69
 
 
70
 
        *_iter = NULL;
71
 
        return iter->worker->v.mailbox_iter_deinit(iter);
72
 
}
73
 
 
74
 
struct dsync_worker_subs_iter *
75
 
dsync_worker_subs_iter_init(struct dsync_worker *worker)
76
 
{
77
 
        return worker->v.subs_iter_init(worker);
78
 
}
79
 
 
80
 
int dsync_worker_subs_iter_next(struct dsync_worker_subs_iter *iter,
81
 
                                struct dsync_worker_subscription *rec_r)
82
 
{
83
 
        return iter->worker->v.subs_iter_next(iter, rec_r);
84
 
}
85
 
 
86
 
int dsync_worker_subs_iter_next_un(struct dsync_worker_subs_iter *iter,
87
 
                                   struct dsync_worker_unsubscription *rec_r)
88
 
{
89
 
        return iter->worker->v.subs_iter_next_un(iter, rec_r);
90
 
}
91
 
 
92
 
int dsync_worker_subs_iter_deinit(struct dsync_worker_subs_iter **_iter)
93
 
{
94
 
        struct dsync_worker_subs_iter *iter = *_iter;
95
 
 
96
 
        *_iter = NULL;
97
 
        return iter->worker->v.subs_iter_deinit(iter);
98
 
}
99
 
 
100
 
void dsync_worker_set_subscribed(struct dsync_worker *worker,
101
 
                                 const char *name, time_t last_change, bool set)
102
 
{
103
 
        worker->v.set_subscribed(worker, name, last_change, set);
104
 
}
105
 
 
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)
110
 
{
111
 
        i_assert(mailbox_count > 0);
112
 
        return worker->v.msg_iter_init(worker, mailboxes, mailbox_count);
113
 
}
114
 
 
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)
118
 
{
119
 
        int ret;
120
 
 
121
 
        T_BEGIN {
122
 
                ret = iter->worker->v.msg_iter_next(iter, mailbox_idx_r, msg_r);
123
 
        } T_END;
124
 
        return ret;
125
 
}
126
 
 
127
 
int dsync_worker_msg_iter_deinit(struct dsync_worker_msg_iter **_iter)
128
 
{
129
 
        struct dsync_worker_msg_iter *iter = *_iter;
130
 
 
131
 
        *_iter = NULL;
132
 
        return iter->worker->v.msg_iter_deinit(iter);
133
 
}
134
 
 
135
 
void dsync_worker_create_mailbox(struct dsync_worker *worker,
136
 
                                 const struct dsync_mailbox *dsync_box)
137
 
{
138
 
        i_assert(dsync_box->uid_validity != 0 ||
139
 
                 dsync_mailbox_is_noselect(dsync_box));
140
 
 
141
 
        if (!worker->readonly) T_BEGIN {
142
 
                worker->v.create_mailbox(worker, dsync_box);
143
 
        } T_END;
144
 
}
145
 
 
146
 
void dsync_worker_delete_mailbox(struct dsync_worker *worker,
147
 
                                 const struct dsync_mailbox *dsync_box)
148
 
{
149
 
        if (!worker->readonly) T_BEGIN {
150
 
                worker->v.delete_mailbox(worker, dsync_box);
151
 
        } T_END;
152
 
}
153
 
 
154
 
void dsync_worker_delete_dir(struct dsync_worker *worker,
155
 
                             const struct dsync_mailbox *dsync_box)
156
 
{
157
 
        if (!worker->readonly) T_BEGIN {
158
 
                worker->v.delete_dir(worker, dsync_box);
159
 
        } T_END;
160
 
}
161
 
 
162
 
void dsync_worker_rename_mailbox(struct dsync_worker *worker,
163
 
                                 const mailbox_guid_t *mailbox,
164
 
                                 const struct dsync_mailbox *dsync_box)
165
 
{
166
 
        if (!worker->readonly) T_BEGIN {
167
 
                worker->v.rename_mailbox(worker, mailbox, dsync_box);
168
 
        } T_END;
169
 
}
170
 
 
171
 
void dsync_worker_update_mailbox(struct dsync_worker *worker,
172
 
                                 const struct dsync_mailbox *dsync_box)
173
 
{
174
 
        if (!worker->readonly) T_BEGIN {
175
 
                worker->v.update_mailbox(worker, dsync_box);
176
 
        } T_END;
177
 
}
178
 
 
179
 
void dsync_worker_select_mailbox(struct dsync_worker *worker,
180
 
                                 const struct dsync_mailbox *box)
181
 
{
182
 
        T_BEGIN {
183
 
                worker->v.select_mailbox(worker, &box->mailbox_guid,
184
 
                                         &box->cache_fields);
185
 
        } T_END;
186
 
}
187
 
 
188
 
void dsync_worker_msg_update_metadata(struct dsync_worker *worker,
189
 
                                      const struct dsync_message *msg)
190
 
{
191
 
        if (!worker->failed && !worker->readonly)
192
 
                worker->v.msg_update_metadata(worker, msg);
193
 
}
194
 
 
195
 
void dsync_worker_msg_update_uid(struct dsync_worker *worker,
196
 
                                 uint32_t old_uid, uint32_t new_uid)
197
 
{
198
 
        if (!worker->failed && !worker->readonly)
199
 
                worker->v.msg_update_uid(worker, old_uid, new_uid);
200
 
}
201
 
 
202
 
void dsync_worker_msg_expunge(struct dsync_worker *worker, uint32_t uid)
203
 
{
204
 
        if (!worker->failed && !worker->readonly)
205
 
                worker->v.msg_expunge(worker, uid);
206
 
}
207
 
 
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,
212
 
                           void *context)
213
 
{
214
 
        if (!worker->failed && !worker->readonly) {
215
 
                T_BEGIN {
216
 
                        worker->v.msg_copy(worker, src_mailbox, src_uid,
217
 
                                           dest_msg, callback, context);
218
 
                } T_END;
219
 
        } else {
220
 
                callback(FALSE, context);
221
 
        }
222
 
}
223
 
 
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,
228
 
                           void *context)
229
 
{
230
 
        if (!worker->readonly) {
231
 
                if (worker->failed)
232
 
                        callback(context);
233
 
                else T_BEGIN {
234
 
                        worker->v.msg_save(worker, msg, data,
235
 
                                           callback, context);
236
 
                } T_END;
237
 
        } else {
238
 
                const unsigned char *d;
239
 
                size_t size;
240
 
 
241
 
                while ((i_stream_read_data(data->input, &d, &size, 0)) > 0)
242
 
                        i_stream_skip(data->input, size);
243
 
                callback(context);
244
 
        }
245
 
}
246
 
 
247
 
void dsync_worker_msg_save_cancel(struct dsync_worker *worker)
248
 
{
249
 
        worker->v.msg_save_cancel(worker);
250
 
}
251
 
 
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)
255
 
{
256
 
        i_assert(uid != 0);
257
 
 
258
 
        if (worker->failed)
259
 
                callback(DSYNC_MSG_GET_RESULT_FAILED, NULL, context);
260
 
        else T_BEGIN {
261
 
                worker->v.msg_get(worker, mailbox, uid, callback, context);
262
 
        } T_END;
263
 
}
264
 
 
265
 
void dsync_worker_finish(struct dsync_worker *worker,
266
 
                         dsync_worker_finish_callback_t *callback,
267
 
                         void *context)
268
 
{
269
 
        worker->v.finish(worker, callback, context);
270
 
}
271
 
 
272
 
void dsync_worker_set_failure(struct dsync_worker *worker)
273
 
{
274
 
        worker->failed = TRUE;
275
 
}
276
 
 
277
 
bool dsync_worker_has_failed(struct dsync_worker *worker)
278
 
{
279
 
        return worker->failed;
280
 
}
281
 
 
282
 
bool dsync_worker_has_unexpected_changes(struct dsync_worker *worker)
283
 
{
284
 
        return worker->unexpected_changes;
285
 
}