Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-ibc-stream.c @ 15471:88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 15 Dec 2012 13:01:09 +0200 |
parents | 01ba0511d04d |
children | 1204e8bae160 |
rev | line source |
---|---|
14584 | 1 /* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ |
2 | |
3 #include "lib.h" | |
4 #include "array.h" | |
5 #include "fd-set-nonblock.h" | |
6 #include "safe-mkstemp.h" | |
7 #include "ioloop.h" | |
8 #include "istream.h" | |
9 #include "istream-seekable.h" | |
10 #include "istream-dot.h" | |
11 #include "ostream.h" | |
12 #include "str.h" | |
13 #include "strescape.h" | |
14 #include "master-service.h" | |
15 #include "mail-cache.h" | |
16 #include "mail-storage-private.h" | |
17 #include "dsync-serializer.h" | |
18 #include "dsync-deserializer.h" | |
19 #include "dsync-mail.h" | |
20 #include "dsync-mailbox.h" | |
21 #include "dsync-mailbox-state.h" | |
22 #include "dsync-mailbox-tree.h" | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
23 #include "dsync-ibc-private.h" |
14584 | 24 |
25 #include <stdlib.h> | |
26 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
27 #define DSYNC_IBC_STREAM_TIMEOUT_MSECS (60*10*1000) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
28 #define DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE (1024*128) |
14584 | 29 |
30 #define DSYNC_PROTOCOL_VERSION_MAJOR 3 | |
31 #define DSYNC_HANDSHAKE_VERSION "VERSION\tdsync\t3\t0\n" | |
32 | |
33 enum item_type { | |
34 ITEM_NONE, | |
35 | |
36 ITEM_HANDSHAKE, | |
37 ITEM_MAILBOX_STATE, | |
38 ITEM_MAILBOX_TREE_NODE, | |
39 ITEM_MAILBOX_DELETE, | |
40 ITEM_MAILBOX, | |
41 | |
42 ITEM_MAIL_CHANGE, | |
43 ITEM_MAIL_REQUEST, | |
44 ITEM_MAIL, | |
45 | |
46 ITEM_MAILBOX_CACHE_FIELD, | |
47 | |
48 ITEM_END_OF_LIST | |
49 }; | |
50 | |
51 #define END_OF_LIST_LINE "." | |
52 static const struct { | |
53 /* full human readable name of the item */ | |
54 const char *name; | |
55 /* unique character identifying the item */ | |
56 char chr; | |
57 const char *required_keys; | |
58 const char *optional_keys; | |
59 } items[ITEM_END_OF_LIST+1] = { | |
60 { NULL, '\0', NULL, NULL }, | |
61 { .name = "handshake", | |
62 .chr = 'H', | |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
63 .optional_keys = "sync_ns_prefix sync_box sync_type debug sync_all_namespaces " |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
64 "mails_have_guids send_guid_requests backup_send backup_recv" |
14584 | 65 }, |
66 { .name = "mailbox_state", | |
67 .chr = 'S', | |
68 .required_keys = "mailbox_guid last_uidvalidity last_common_uid " | |
69 "last_common_modseq" | |
70 }, | |
71 { .name = "mailbox_tree_node", | |
72 .chr = 'N', | |
73 .required_keys = "name existence", | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
74 .optional_keys = "mailbox_guid uid_validity uid_next " |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
75 "last_renamed_or_created subscribed last_subscription_change" |
14584 | 76 }, |
77 { .name = "mailbox_delete", | |
78 .chr = 'D', | |
79 .required_keys = "hierarchy_sep", | |
80 .optional_keys = "mailboxes dirs" | |
81 }, | |
82 { .name = "mailbox", | |
83 .chr = 'B', | |
15470
01ba0511d04d
dsync: Error handling fix when mailbox is unexpectedly lost.
Timo Sirainen <tss@iki.fi>
parents:
15469
diff
changeset
|
84 .required_keys = "mailbox_lost mailbox_guid uid_validity uid_next " |
14584 | 85 "messages_count first_recent_uid highest_modseq", |
86 .optional_keys = "cache_fields" | |
87 }, | |
88 { .name = "mail_change", | |
89 .chr = 'C', | |
90 .required_keys = "type uid", | |
91 .optional_keys = "guid hdr_hash modseq save_timestamp " | |
92 "add_flags remove_flags final_flags " | |
93 "keywords_reset keyword_changes" | |
94 }, | |
95 { .name = "mail_request", | |
96 .chr = 'R', | |
97 .optional_keys = "guid uid" | |
98 }, | |
99 { .name = "mail", | |
100 .chr = 'M', | |
101 .optional_keys = "guid uid pop3_uidl pop3_order received_date stream" | |
102 }, | |
103 { .name = "mailbox_cache_field", | |
104 .chr = 'c', | |
105 .required_keys = "name decision", | |
106 .optional_keys = "last_used" | |
107 }, | |
108 | |
109 { "end_of_list", '\0', NULL, NULL } | |
110 }; | |
111 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
112 struct dsync_ibc_stream { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
113 struct dsync_ibc ibc; |
14584 | 114 |
115 char *name, *temp_path_prefix; | |
116 int fd_in, fd_out; | |
117 struct istream *input; | |
118 struct ostream *output; | |
119 struct io *io; | |
120 struct timeout *to; | |
121 | |
122 struct dsync_serializer *serializers[ITEM_END_OF_LIST]; | |
123 struct dsync_deserializer *deserializers[ITEM_END_OF_LIST]; | |
124 | |
125 pool_t ret_pool; | |
126 struct dsync_deserializer_decoder *cur_decoder; | |
127 | |
128 struct istream *mail_output, *mail_input; | |
129 struct dsync_mail *cur_mail; | |
130 char mail_output_last; | |
131 | |
132 unsigned int version_received:1; | |
133 unsigned int handshake_received:1; | |
134 unsigned int has_pending_data:1; | |
135 }; | |
136 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
137 static void dsync_ibc_stream_stop(struct dsync_ibc_stream *ibc) |
14584 | 138 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
139 i_stream_close(ibc->input); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
140 o_stream_close(ibc->output); |
14584 | 141 io_loop_stop(current_ioloop); |
142 } | |
143 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
144 static int dsync_ibc_stream_read_mail_stream(struct dsync_ibc_stream *ibc) |
14584 | 145 { |
15463
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
146 while (i_stream_read(ibc->mail_input) > 0) { |
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
147 i_stream_skip(ibc->mail_input, |
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
148 i_stream_get_data_size(ibc->mail_input)); |
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
149 } |
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
150 if (ibc->mail_input->eof) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
151 if (ibc->mail_input->stream_errno != 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
152 errno = ibc->mail_input->stream_errno; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
153 i_error("dsync(%s): read() failed: %m", ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
154 dsync_ibc_stream_stop(ibc); |
14584 | 155 return -1; |
156 } | |
157 /* finished reading the mail stream */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
158 i_assert(ibc->mail_input->eof); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
159 i_stream_seek(ibc->mail_input, 0); |
15463
f9e8cbb2792d
dsync: Fixed hangs with remote dsyncing
Timo Sirainen <tss@iki.fi>
parents:
15231
diff
changeset
|
160 ibc->has_pending_data = TRUE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
161 ibc->mail_input = NULL; |
14584 | 162 return 1; |
163 } | |
164 return 0; | |
165 } | |
166 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
167 static void dsync_ibc_stream_input(struct dsync_ibc_stream *ibc) |
14584 | 168 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
169 if (ibc->mail_input != NULL) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
170 if (dsync_ibc_stream_read_mail_stream(ibc) == 0) |
14584 | 171 return; |
172 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
173 ibc->ibc.io_callback(ibc->ibc.io_context); |
14584 | 174 } |
175 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
176 static int dsync_ibc_stream_send_mail_stream(struct dsync_ibc_stream *ibc) |
14584 | 177 { |
178 const unsigned char *data; | |
179 unsigned char add; | |
180 size_t i, size; | |
181 int ret; | |
182 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
183 while ((ret = i_stream_read_data(ibc->mail_output, |
14584 | 184 &data, &size, 0)) > 0) { |
185 add = '\0'; | |
186 for (i = 0; i < size; i++) { | |
187 if (data[i] == '\n') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
188 if ((i == 0 && ibc->mail_output_last != '\r') || |
14584 | 189 (i > 0 && data[i-1] != '\r')) { |
190 /* missing CR */ | |
191 add = '\r'; | |
192 break; | |
193 } | |
194 } else if (data[i] == '.' && | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
195 ((i == 0 && ibc->mail_output_last == '\n') || |
14584 | 196 (i > 0 && data[i-1] == '\n'))) { |
197 /* escape the dot */ | |
198 add = '.'; | |
199 break; | |
200 } | |
201 } | |
202 | |
203 if (i > 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
204 o_stream_nsend(ibc->output, data, i); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
205 ibc->mail_output_last = data[i-1]; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
206 i_stream_skip(ibc->mail_output, i); |
14584 | 207 } |
208 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
209 if (o_stream_get_buffer_used_size(ibc->output) >= 4096) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
210 if ((ret = o_stream_flush(ibc->output)) < 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
211 dsync_ibc_stream_stop(ibc); |
14584 | 212 return -1; |
213 } | |
214 if (ret == 0) { | |
215 /* continue later */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
216 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 217 return 0; |
218 } | |
219 } | |
220 | |
221 if (add != '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
222 o_stream_nsend(ibc->output, &add, 1); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
223 ibc->mail_output_last = add; |
14584 | 224 } |
225 } | |
226 i_assert(ret == -1); | |
227 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
228 if (ibc->mail_output->stream_errno != 0) { |
14584 | 229 i_error("dsync(%s): read(%s) failed: %m", |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
230 ibc->name, i_stream_get_name(ibc->mail_output)); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
231 dsync_ibc_stream_stop(ibc); |
14584 | 232 return -1; |
233 } | |
234 | |
235 /* finished sending the stream */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
236 o_stream_nsend_str(ibc->output, "\r\n.\r\n"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
237 i_stream_unref(&ibc->mail_output); |
14584 | 238 return 1; |
239 } | |
240 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
241 static int dsync_ibc_stream_output(struct dsync_ibc_stream *ibc) |
14584 | 242 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
243 struct ostream *output = ibc->output; |
14584 | 244 int ret; |
245 | |
246 if ((ret = o_stream_flush(output)) < 0) | |
247 ret = 1; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
248 else if (ibc->mail_output != NULL) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
249 if (dsync_ibc_stream_send_mail_stream(ibc) < 0) |
14584 | 250 ret = 1; |
251 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
252 timeout_reset(ibc->to); |
14584 | 253 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
254 if (!dsync_ibc_is_send_queue_full(&ibc->ibc)) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
255 ibc->ibc.io_callback(ibc->ibc.io_context); |
14584 | 256 return ret; |
257 } | |
258 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
259 static void dsync_ibc_stream_timeout(struct dsync_ibc_stream *ibc) |
14584 | 260 { |
261 i_error("dsync(%s): I/O has stalled, no activity for %u seconds", | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
262 ibc->name, DSYNC_IBC_STREAM_TIMEOUT_MSECS/1000); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
263 dsync_ibc_stream_stop(ibc); |
14584 | 264 } |
265 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
266 static void dsync_ibc_stream_init(struct dsync_ibc_stream *ibc) |
14584 | 267 { |
268 unsigned int i; | |
269 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
270 ibc->io = io_add(ibc->fd_in, IO_READ, dsync_ibc_stream_input, ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
271 o_stream_set_no_error_handling(ibc->output, TRUE); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
272 o_stream_set_flush_callback(ibc->output, dsync_ibc_stream_output, ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
273 ibc->to = timeout_add(DSYNC_IBC_STREAM_TIMEOUT_MSECS, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
274 dsync_ibc_stream_timeout, ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
275 o_stream_cork(ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
276 o_stream_nsend_str(ibc->output, DSYNC_HANDSHAKE_VERSION); |
14584 | 277 |
278 /* initialize serializers and send their headers to remote */ | |
279 for (i = 1; i < ITEM_END_OF_LIST; i++) T_BEGIN { | |
280 const char *keys; | |
281 | |
282 keys = items[i].required_keys == NULL ? items[i].optional_keys : | |
283 t_strconcat(items[i].required_keys, " ", | |
284 items[i].optional_keys, NULL); | |
285 if (keys != NULL) { | |
286 i_assert(items[i].chr != '\0'); | |
287 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
288 ibc->serializers[i] = |
14584 | 289 dsync_serializer_init(t_strsplit_spaces(keys, " ")); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
290 o_stream_nsend(ibc->output, &items[i].chr, 1); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
291 o_stream_nsend_str(ibc->output, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
292 dsync_serializer_encode_header_line(ibc->serializers[i])); |
14584 | 293 } |
294 } T_END; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
295 o_stream_nsend_str(ibc->output, ".\n"); |
14584 | 296 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
297 dsync_ibc_flush(&ibc->ibc); |
14584 | 298 } |
299 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
300 static void dsync_ibc_stream_deinit(struct dsync_ibc *_ibc) |
14584 | 301 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
302 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 303 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
304 if (ibc->cur_decoder != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
305 dsync_deserializer_decode_finish(&ibc->cur_decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
306 if (ibc->mail_output != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
307 i_stream_unref(&ibc->mail_output); |
14584 | 308 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
309 timeout_remove(&ibc->to); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
310 if (ibc->io != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
311 io_remove(&ibc->io); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
312 i_stream_destroy(&ibc->input); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
313 o_stream_destroy(&ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
314 pool_unref(&ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
315 i_free(ibc->temp_path_prefix); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
316 i_free(ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
317 i_free(ibc); |
14584 | 318 } |
319 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
320 static int dsync_ibc_stream_next_line(struct dsync_ibc_stream *ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
321 const char **line_r) |
14584 | 322 { |
323 const char *line; | |
324 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
325 line = i_stream_next_line(ibc->input); |
14584 | 326 if (line != NULL) { |
327 *line_r = line; | |
328 return 1; | |
329 } | |
330 | |
331 /* try reading some */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
332 switch (i_stream_read(ibc->input)) { |
14584 | 333 case -1: |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
334 if (ibc->input->stream_errno != 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
335 errno = ibc->input->stream_errno; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
336 i_error("read(%s) failed: %m", ibc->name); |
14584 | 337 } else { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
338 i_assert(ibc->input->eof); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
339 i_error("read(%s) failed: EOF", ibc->name); |
14584 | 340 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
341 dsync_ibc_stream_stop(ibc); |
14584 | 342 return -1; |
343 case 0: | |
344 return 0; | |
345 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
346 *line_r = i_stream_next_line(ibc->input); |
14584 | 347 if (*line_r == NULL) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
348 ibc->has_pending_data = FALSE; |
14584 | 349 return 0; |
350 } | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
351 ibc->has_pending_data = TRUE; |
14584 | 352 return 1; |
353 } | |
354 | |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14584
diff
changeset
|
355 static void ATTR_FORMAT(3, 4) ATTR_NULL(2) |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
356 dsync_ibc_input_error(struct dsync_ibc_stream *ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
357 struct dsync_deserializer_decoder *decoder, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
358 const char *fmt, ...) |
14584 | 359 { |
360 va_list args; | |
361 const char *error; | |
362 | |
363 va_start(args, fmt); | |
364 error = t_strdup_vprintf(fmt, args); | |
365 if (decoder == NULL) | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
366 i_error("dsync(%s): %s", ibc->name, error); |
14584 | 367 else { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
368 i_error("dsync(%s): %s: %s", ibc->name, |
14584 | 369 dsync_deserializer_decoder_get_name(decoder), error); |
370 } | |
371 va_end(args); | |
372 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
373 dsync_ibc_stream_stop(ibc); |
14584 | 374 } |
375 | |
376 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
377 dsync_ibc_stream_send_string(struct dsync_ibc_stream *ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
378 const string_t *str) |
14584 | 379 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
380 i_assert(ibc->mail_output == NULL); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
381 o_stream_nsend(ibc->output, str_data(str), str_len(str)); |
14584 | 382 } |
383 | |
15036
5943cace4e05
dsync: Renamed "io" slave to "stream".
Timo Sirainen <tss@iki.fi>
parents:
15035
diff
changeset
|
384 static int |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
385 dsync_ibc_check_missing_deserializers(struct dsync_ibc_stream *ibc) |
14584 | 386 { |
387 unsigned int i; | |
388 int ret = 0; | |
389 | |
390 for (i = 1; i < ITEM_END_OF_LIST; i++) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
391 if (ibc->deserializers[i] == NULL && |
14584 | 392 (items[i].required_keys != NULL || |
393 items[i].optional_keys != NULL)) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
394 dsync_ibc_input_error(ibc, NULL, |
14584 | 395 "Remote didn't handshake deserializer for %s", |
396 items[i].name); | |
397 ret = -1; | |
398 } | |
399 } | |
400 return ret; | |
401 } | |
402 | |
403 static bool | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
404 dsync_ibc_stream_handshake(struct dsync_ibc_stream *ibc, const char *line) |
14584 | 405 { |
406 enum item_type item = ITEM_NONE; | |
407 const char *const *required_keys, *error; | |
408 unsigned int i; | |
409 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
410 if (ibc->handshake_received) |
14584 | 411 return TRUE; |
412 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
413 if (!ibc->version_received) { |
14584 | 414 if (!version_string_verify(line, "dsync", |
415 DSYNC_PROTOCOL_VERSION_MAJOR)) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
416 dsync_ibc_input_error(ibc, NULL, |
14584 | 417 "Remote dsync doesn't use compatible protocol"); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
418 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 419 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
420 ibc->version_received = TRUE; |
14584 | 421 return FALSE; |
422 } | |
423 | |
424 if (strcmp(line, END_OF_LIST_LINE) == 0) { | |
425 /* finished handshaking */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
426 if (dsync_ibc_check_missing_deserializers(ibc) < 0) |
14584 | 427 return FALSE; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
428 ibc->handshake_received = TRUE; |
14584 | 429 return FALSE; |
430 } | |
431 | |
432 for (i = 1; i < ITEM_END_OF_LIST; i++) { | |
433 if (items[i].chr == line[0]) { | |
434 item = i; | |
435 break; | |
436 } | |
437 } | |
438 if (item == ITEM_NONE) { | |
439 /* unknown deserializer, ignore */ | |
440 return FALSE; | |
441 } | |
442 | |
443 required_keys = items[item].required_keys == NULL ? NULL : | |
444 t_strsplit(items[item].required_keys, " "); | |
445 if (dsync_deserializer_init(items[item].name, | |
446 required_keys, line + 1, | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
447 &ibc->deserializers[item], &error) < 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
448 dsync_ibc_input_error(ibc, NULL, |
14584 | 449 "Remote sent invalid handshake for %s: %s", |
450 items[item].name, error); | |
451 } | |
452 return FALSE; | |
453 } | |
454 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
455 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
456 dsync_ibc_stream_input_next(struct dsync_ibc_stream *ibc, enum item_type item, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
457 struct dsync_deserializer_decoder **decoder_r) |
14584 | 458 { |
459 enum item_type line_item = ITEM_NONE; | |
460 const char *line, *error; | |
461 unsigned int i; | |
462 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
463 i_assert(ibc->mail_input == NULL); |
14584 | 464 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
465 timeout_reset(ibc->to); |
14584 | 466 |
467 do { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
468 if (dsync_ibc_stream_next_line(ibc, &line) <= 0) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
469 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
470 } while (!dsync_ibc_stream_handshake(ibc, line)); |
14584 | 471 |
472 if (strcmp(line, END_OF_LIST_LINE) == 0) { | |
473 /* end of this list */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
474 return DSYNC_IBC_RECV_RET_FINISHED; |
14584 | 475 } |
476 for (i = 1; i < ITEM_END_OF_LIST; i++) { | |
477 if (*line == items[i].chr) { | |
478 line_item = i; | |
479 break; | |
480 } | |
481 } | |
482 if (line_item != item) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
483 dsync_ibc_input_error(ibc, NULL, |
14584 | 484 "Received unexpected input %c != %c", |
485 *line, items[item].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
486 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 487 } |
488 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
489 if (ibc->cur_decoder != NULL) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
490 dsync_deserializer_decode_finish(&ibc->cur_decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
491 if (dsync_deserializer_decode_begin(ibc->deserializers[item], |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
492 line+1, &ibc->cur_decoder, |
14584 | 493 &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
494 dsync_ibc_input_error(ibc, NULL, "Invalid input to %s: %s", |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
495 items[item].name, error); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
496 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 497 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
498 *decoder_r = ibc->cur_decoder; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
499 return DSYNC_IBC_RECV_RET_OK; |
14584 | 500 } |
501 | |
502 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
503 dsync_ibc_stream_send_handshake(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
504 const struct dsync_ibc_settings *set) |
14584 | 505 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
506 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 507 struct dsync_serializer_encoder *encoder; |
508 string_t *str = t_str_new(128); | |
509 char sync_type[2]; | |
510 | |
511 str_append_c(str, items[ITEM_HANDSHAKE].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
512 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_HANDSHAKE]); |
14584 | 513 if (set->sync_ns_prefix != NULL) { |
514 dsync_serializer_encode_add(encoder, "sync_ns_prefix", | |
515 set->sync_ns_prefix); | |
516 } | |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
517 if (set->sync_box != NULL) |
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
518 dsync_serializer_encode_add(encoder, "sync_box", set->sync_box); |
14584 | 519 |
520 sync_type[0] = sync_type[1] = '\0'; | |
521 switch (set->sync_type) { | |
522 case DSYNC_BRAIN_SYNC_TYPE_UNKNOWN: | |
523 break; | |
524 case DSYNC_BRAIN_SYNC_TYPE_FULL: | |
525 sync_type[0] = 'f'; | |
526 break; | |
527 case DSYNC_BRAIN_SYNC_TYPE_CHANGED: | |
528 sync_type[0] = 'c'; | |
529 break; | |
530 case DSYNC_BRAIN_SYNC_TYPE_STATE: | |
531 sync_type[0] = 's'; | |
532 break; | |
533 } | |
534 i_assert(sync_type[0] != '\0'); | |
535 dsync_serializer_encode_add(encoder, "sync_type", sync_type); | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
536 if ((set->brain_flags & DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS) != 0) |
14584 | 537 dsync_serializer_encode_add(encoder, "mails_have_guids", ""); |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
538 if ((set->brain_flags & DSYNC_BRAIN_FLAG_SEND_GUID_REQUESTS) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
539 dsync_serializer_encode_add(encoder, "send_guid_requests", ""); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
540 if ((set->brain_flags & DSYNC_BRAIN_FLAG_BACKUP_SEND) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
541 dsync_serializer_encode_add(encoder, "backup_send", ""); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
542 if ((set->brain_flags & DSYNC_BRAIN_FLAG_BACKUP_RECV) != 0) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
543 dsync_serializer_encode_add(encoder, "backup_recv", ""); |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
544 if ((set->brain_flags & DSYNC_BRAIN_FLAG_DEBUG) != 0) |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
545 dsync_serializer_encode_add(encoder, "debug", ""); |
15469
05d83c4df130
dsync: Added -a parameter to sync all namespaces, not just the default one.
Timo Sirainen <tss@iki.fi>
parents:
15464
diff
changeset
|
546 if ((set->brain_flags & DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES) != 0) |
05d83c4df130
dsync: Added -a parameter to sync all namespaces, not just the default one.
Timo Sirainen <tss@iki.fi>
parents:
15464
diff
changeset
|
547 dsync_serializer_encode_add(encoder, "sync_all_namespaces", ""); |
14584 | 548 |
549 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
550 dsync_ibc_stream_send_string(ibc, str); |
14584 | 551 } |
552 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
553 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
554 dsync_ibc_stream_recv_handshake(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
555 const struct dsync_ibc_settings **set_r) |
14584 | 556 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
557 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 558 struct dsync_deserializer_decoder *decoder; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
559 struct dsync_ibc_settings *set; |
14584 | 560 const char *value; |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
561 pool_t pool = ibc->ret_pool; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
562 enum dsync_ibc_recv_ret ret; |
14584 | 563 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
564 ret = dsync_ibc_stream_input_next(ibc, ITEM_HANDSHAKE, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
565 if (ret != DSYNC_IBC_RECV_RET_OK) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
566 if (ret != DSYNC_IBC_RECV_RET_TRYAGAIN) { |
14584 | 567 i_error("dsync(%s): Unexpected input in handshake", |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
568 ibc->name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
569 dsync_ibc_stream_stop(ibc); |
14584 | 570 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
571 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 572 } |
573 | |
574 p_clear(pool); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
575 set = p_new(pool, struct dsync_ibc_settings, 1); |
14584 | 576 |
577 if (dsync_deserializer_decode_try(decoder, "sync_ns_prefix", &value)) | |
578 set->sync_ns_prefix = p_strdup(pool, value); | |
15471
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
579 if (dsync_deserializer_decode_try(decoder, "sync_box", &value)) |
88ac919f8afe
dsync: Added back support for syncing only one mailbox (-m parameter)
Timo Sirainen <tss@iki.fi>
parents:
15470
diff
changeset
|
580 set->sync_box = p_strdup(pool, value); |
14584 | 581 if (dsync_deserializer_decode_try(decoder, "sync_type", &value)) { |
582 switch (value[0]) { | |
583 case 'f': | |
584 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_FULL; | |
585 break; | |
586 case 'c': | |
587 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_CHANGED; | |
588 break; | |
589 case 's': | |
590 set->sync_type = DSYNC_BRAIN_SYNC_TYPE_STATE; | |
591 break; | |
592 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
593 dsync_ibc_input_error(ibc, decoder, |
14584 | 594 "Unknown sync_type: %s", value); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
595 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 596 } |
597 } | |
598 if (dsync_deserializer_decode_try(decoder, "mails_have_guids", &value)) | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
599 set->brain_flags |= DSYNC_BRAIN_FLAG_MAILS_HAVE_GUIDS; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
600 if (dsync_deserializer_decode_try(decoder, "send_guid_requests", &value)) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
601 set->brain_flags |= DSYNC_BRAIN_FLAG_SEND_GUID_REQUESTS; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
602 if (dsync_deserializer_decode_try(decoder, "backup_send", &value)) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
603 set->brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_SEND; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
604 if (dsync_deserializer_decode_try(decoder, "backup_recv", &value)) |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
605 set->brain_flags |= DSYNC_BRAIN_FLAG_BACKUP_RECV; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
606 if (dsync_deserializer_decode_try(decoder, "debug", &value)) |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
607 set->brain_flags |= DSYNC_BRAIN_FLAG_DEBUG; |
15469
05d83c4df130
dsync: Added -a parameter to sync all namespaces, not just the default one.
Timo Sirainen <tss@iki.fi>
parents:
15464
diff
changeset
|
608 if (dsync_deserializer_decode_try(decoder, "sync_all_namespaces", &value)) |
05d83c4df130
dsync: Added -a parameter to sync all namespaces, not just the default one.
Timo Sirainen <tss@iki.fi>
parents:
15464
diff
changeset
|
609 set->brain_flags |= DSYNC_BRAIN_FLAG_SYNC_ALL_NAMESPACES; |
14584 | 610 |
611 *set_r = set; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
612 return DSYNC_IBC_RECV_RET_OK; |
14584 | 613 } |
614 | |
615 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
616 dsync_ibc_stream_send_end_of_list(struct dsync_ibc *_ibc) |
14584 | 617 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
618 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 619 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
620 i_assert(ibc->mail_output == NULL); |
14584 | 621 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
622 o_stream_nsend_str(ibc->output, END_OF_LIST_LINE"\n"); |
14584 | 623 } |
624 | |
625 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
626 dsync_ibc_stream_send_mailbox_state(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
627 const struct dsync_mailbox_state *state) |
14584 | 628 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
629 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 630 struct dsync_serializer_encoder *encoder; |
631 string_t *str = t_str_new(128); | |
632 | |
633 str_append_c(str, items[ITEM_MAILBOX_STATE].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
634 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_STATE]); |
14584 | 635 dsync_serializer_encode_add(encoder, "mailbox_guid", |
636 guid_128_to_string(state->mailbox_guid)); | |
637 dsync_serializer_encode_add(encoder, "last_uidvalidity", | |
638 dec2str(state->last_uidvalidity)); | |
639 dsync_serializer_encode_add(encoder, "last_common_uid", | |
640 dec2str(state->last_common_uid)); | |
641 dsync_serializer_encode_add(encoder, "last_common_modseq", | |
642 dec2str(state->last_common_modseq)); | |
643 | |
644 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
645 dsync_ibc_stream_send_string(ibc, str); |
14584 | 646 } |
647 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
648 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
649 dsync_ibc_stream_recv_mailbox_state(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
650 struct dsync_mailbox_state *state_r) |
14584 | 651 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
652 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 653 struct dsync_deserializer_decoder *decoder; |
654 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
655 enum dsync_ibc_recv_ret ret; |
14584 | 656 |
657 memset(state_r, 0, sizeof(*state_r)); | |
658 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
659 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAILBOX_STATE, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
660 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 661 return ret; |
662 | |
663 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
664 if (guid_128_from_string(value, state_r->mailbox_guid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
665 dsync_ibc_input_error(ibc, decoder, "Invalid mailbox_guid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
666 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 667 } |
668 value = dsync_deserializer_decode_get(decoder, "last_uidvalidity"); | |
669 if (str_to_uint32(value, &state_r->last_uidvalidity) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
670 dsync_ibc_input_error(ibc, decoder, "Invalid last_uidvalidity"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
671 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 672 } |
673 value = dsync_deserializer_decode_get(decoder, "last_common_uid"); | |
674 if (str_to_uint32(value, &state_r->last_uidvalidity) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
675 dsync_ibc_input_error(ibc, decoder, "Invalid last_common_uid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
676 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 677 } |
678 value = dsync_deserializer_decode_get(decoder, "last_common_modseq"); | |
679 if (str_to_uint32(value, &state_r->last_uidvalidity) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
680 dsync_ibc_input_error(ibc, decoder, "Invalid last_common_modseq"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
681 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 682 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
683 return DSYNC_IBC_RECV_RET_OK; |
14584 | 684 } |
685 | |
686 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
687 dsync_ibc_stream_send_mailbox_tree_node(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
688 const char *const *name, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
689 const struct dsync_mailbox_node *node) |
14584 | 690 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
691 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 692 struct dsync_serializer_encoder *encoder; |
693 string_t *str, *namestr; | |
694 | |
695 i_assert(*name != NULL); | |
696 | |
697 str = t_str_new(128); | |
698 str_append_c(str, items[ITEM_MAILBOX_TREE_NODE].chr); | |
699 | |
700 /* convert all hierarchy separators to tabs. mailbox names really | |
701 aren't supposed to have any tabs, but escape them anyway if there | |
702 are. */ | |
703 namestr = t_str_new(128); | |
704 for (; *name != NULL; name++) { | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
705 str_append_tabescaped(namestr, *name); |
14584 | 706 str_append_c(namestr, '\t'); |
707 } | |
708 str_truncate(namestr, str_len(namestr)-1); | |
709 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
710 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_TREE_NODE]); |
14584 | 711 dsync_serializer_encode_add(encoder, "name", str_c(namestr)); |
712 switch (node->existence) { | |
713 case DSYNC_MAILBOX_NODE_NONEXISTENT: | |
714 dsync_serializer_encode_add(encoder, "existence", "n"); | |
715 break; | |
716 case DSYNC_MAILBOX_NODE_EXISTS: | |
717 dsync_serializer_encode_add(encoder, "existence", "y"); | |
718 break; | |
719 case DSYNC_MAILBOX_NODE_DELETED: | |
720 dsync_serializer_encode_add(encoder, "existence", "d"); | |
721 break; | |
722 } | |
723 | |
724 if (!guid_128_is_empty(node->mailbox_guid)) { | |
725 dsync_serializer_encode_add(encoder, "mailbox_guid", | |
726 guid_128_to_string(node->mailbox_guid)); | |
727 } | |
728 if (node->uid_validity != 0) { | |
729 dsync_serializer_encode_add(encoder, "uid_validity", | |
730 dec2str(node->uid_validity)); | |
731 } | |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
732 if (node->uid_next != 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
733 dsync_serializer_encode_add(encoder, "uid_next", |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
734 dec2str(node->uid_next)); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
735 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
736 if (node->last_renamed_or_created != 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
737 dsync_serializer_encode_add(encoder, "last_renamed_or_created", |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
738 dec2str(node->last_renamed_or_created)); |
14584 | 739 } |
740 if (node->last_subscription_change != 0) { | |
741 dsync_serializer_encode_add(encoder, "last_subscription_change", | |
742 dec2str(node->last_subscription_change)); | |
743 } | |
744 if (node->subscribed) | |
745 dsync_serializer_encode_add(encoder, "subscribed", ""); | |
746 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
747 dsync_ibc_stream_send_string(ibc, str); |
14584 | 748 } |
749 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
750 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
751 dsync_ibc_stream_recv_mailbox_tree_node(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
752 const char *const **name_r, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
753 const struct dsync_mailbox_node **node_r) |
14584 | 754 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
755 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 756 struct dsync_deserializer_decoder *decoder; |
757 struct dsync_mailbox_node *node; | |
758 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
759 enum dsync_ibc_recv_ret ret; |
14584 | 760 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
761 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAILBOX_TREE_NODE, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
762 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 763 return ret; |
764 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
765 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
766 node = p_new(ibc->ret_pool, struct dsync_mailbox_node, 1); |
14584 | 767 |
768 value = dsync_deserializer_decode_get(decoder, "name"); | |
769 if (*value == '\0') { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
770 dsync_ibc_input_error(ibc, decoder, "Empty name"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
771 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 772 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
773 *name_r = (void *)p_strsplit_tabescaped(ibc->ret_pool, value); |
14584 | 774 |
775 value = dsync_deserializer_decode_get(decoder, "existence"); | |
776 switch (*value) { | |
777 case 'n': | |
778 node->existence = DSYNC_MAILBOX_NODE_NONEXISTENT; | |
779 break; | |
780 case 'y': | |
781 node->existence = DSYNC_MAILBOX_NODE_EXISTS; | |
782 break; | |
783 case 'd': | |
784 node->existence = DSYNC_MAILBOX_NODE_DELETED; | |
785 break; | |
786 } | |
787 | |
788 if (dsync_deserializer_decode_try(decoder, "mailbox_guid", &value) && | |
789 guid_128_from_string(value, node->mailbox_guid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
790 dsync_ibc_input_error(ibc, decoder, "Invalid mailbox_guid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
791 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 792 } |
793 if (dsync_deserializer_decode_try(decoder, "uid_validity", &value) && | |
794 str_to_uint32(value, &node->uid_validity) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
795 dsync_ibc_input_error(ibc, decoder, "Invalid uid_validity"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
796 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 797 } |
15231
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
798 if (dsync_deserializer_decode_try(decoder, "uid_next", &value) && |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
799 str_to_uint32(value, &node->uid_next) < 0) { |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
800 dsync_ibc_input_error(ibc, decoder, "Invalid uid_next"); |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
801 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
454d0563927d
doveadm: "backup" command is working again.
Timo Sirainen <tss@iki.fi>
parents:
15068
diff
changeset
|
802 } |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
803 if (dsync_deserializer_decode_try(decoder, "last_renamed_or_created", &value) && |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
804 str_to_time(value, &node->last_renamed_or_created) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
805 dsync_ibc_input_error(ibc, decoder, "Invalid last_renamed_or_created"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
806 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 807 } |
808 if (dsync_deserializer_decode_try(decoder, "last_subscription_change", &value) && | |
809 str_to_time(value, &node->last_subscription_change) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
810 dsync_ibc_input_error(ibc, decoder, "Invalid last_subscription_change"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
811 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 812 } |
813 if (dsync_deserializer_decode_try(decoder, "subscribed", &value)) | |
814 node->subscribed = TRUE; | |
815 | |
816 *node_r = node; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
817 return DSYNC_IBC_RECV_RET_OK; |
14584 | 818 } |
819 | |
820 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
821 dsync_ibc_stream_send_mailbox_deletes(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
822 const struct dsync_mailbox_delete *deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
823 unsigned int count, char hierarchy_sep) |
14584 | 824 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
825 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 826 struct dsync_serializer_encoder *encoder; |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
827 string_t *str, *substr; |
14584 | 828 char sep[2]; |
829 unsigned int i; | |
830 | |
831 str = t_str_new(128); | |
832 str_append_c(str, items[ITEM_MAILBOX_DELETE].chr); | |
833 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
834 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_DELETE]); |
14584 | 835 sep[0] = hierarchy_sep; sep[1] = '\0'; |
836 dsync_serializer_encode_add(encoder, "hierarchy_sep", sep); | |
837 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
838 substr = t_str_new(128); |
14584 | 839 for (i = 0; i < count; i++) { |
840 if (deletes[i].delete_mailbox) { | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
841 str_append(substr, guid_128_to_string(deletes[i].guid)); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
842 str_printfa(substr, " %ld ", (long)deletes[i].timestamp); |
14584 | 843 } |
844 } | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
845 if (str_len(substr) > 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
846 str_truncate(substr, str_len(substr)-1); |
14584 | 847 dsync_serializer_encode_add(encoder, "mailboxes", |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
848 str_c(substr)); |
14584 | 849 } |
850 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
851 str_truncate(substr, 0); |
14584 | 852 for (i = 0; i < count; i++) { |
853 if (!deletes[i].delete_mailbox) { | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
854 str_append(substr, guid_128_to_string(deletes[i].guid)); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
855 str_printfa(substr, " %ld ", (long)deletes[i].timestamp); |
14584 | 856 } |
857 } | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
858 if (str_len(substr) > 0) { |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
859 str_truncate(substr, str_len(substr)-1); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
860 dsync_serializer_encode_add(encoder, "dirs", str_c(substr)); |
14584 | 861 } |
862 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
863 dsync_ibc_stream_send_string(ibc, str); |
14584 | 864 } |
865 | |
866 ARRAY_DEFINE_TYPE(dsync_mailbox_delete, struct dsync_mailbox_delete); | |
867 static int | |
868 decode_mailbox_deletes(ARRAY_TYPE(dsync_mailbox_delete) *deletes, | |
869 const char *value, bool delete_mailbox) | |
870 { | |
871 struct dsync_mailbox_delete *del; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
872 const char *const *tmp; |
14584 | 873 unsigned int i; |
874 | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
875 tmp = t_strsplit(value, " "); |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
876 for (i = 0; tmp[i] != NULL; i += 2) { |
14584 | 877 del = array_append_space(deletes); |
878 del->delete_mailbox = delete_mailbox; | |
15035
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
879 if (guid_128_from_string(tmp[i], del->guid) < 0) |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
880 return -1; |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
881 if (tmp[i+1] == NULL || |
0af20585964d
dsync: Rewritten syncing for mailbox renames.
Timo Sirainen <tss@iki.fi>
parents:
14691
diff
changeset
|
882 str_to_time(tmp[i+1], &del->timestamp) < 0) |
14584 | 883 return -1; |
884 } | |
885 return 0; | |
886 } | |
887 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
888 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
889 dsync_ibc_stream_recv_mailbox_deletes(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
890 const struct dsync_mailbox_delete **deletes_r, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
891 unsigned int *count_r, char *hierarchy_sep_r) |
14584 | 892 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
893 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 894 struct dsync_deserializer_decoder *decoder; |
895 ARRAY_TYPE(dsync_mailbox_delete) deletes; | |
896 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
897 enum dsync_ibc_recv_ret ret; |
14584 | 898 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
899 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAILBOX_DELETE, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
900 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 901 return ret; |
902 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
903 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
904 p_array_init(&deletes, ibc->ret_pool, 16); |
14584 | 905 |
906 value = dsync_deserializer_decode_get(decoder, "hierarchy_sep"); | |
907 if (strlen(value) != 1) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
908 dsync_ibc_input_error(ibc, decoder, "Invalid hierarchy_sep"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
909 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 910 } |
911 *hierarchy_sep_r = value[0]; | |
912 | |
913 if (dsync_deserializer_decode_try(decoder, "mailboxes", &value) && | |
914 decode_mailbox_deletes(&deletes, value, TRUE) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
915 dsync_ibc_input_error(ibc, decoder, "Invalid mailboxes"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
916 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 917 } |
918 if (dsync_deserializer_decode_try(decoder, "dirs", &value) && | |
919 decode_mailbox_deletes(&deletes, value, FALSE) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
920 dsync_ibc_input_error(ibc, decoder, "Invalid dirs"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
921 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 922 } |
923 *deletes_r = array_get(&deletes, count_r); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
924 return DSYNC_IBC_RECV_RET_OK; |
14584 | 925 } |
926 | |
927 static const char * | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
928 get_cache_fields(struct dsync_ibc_stream *ibc, |
14584 | 929 const struct dsync_mailbox *dsync_box) |
930 { | |
931 struct dsync_serializer_encoder *encoder; | |
932 string_t *str; | |
933 const struct mailbox_cache_field *cache_fields; | |
934 unsigned int i, count; | |
935 char decision[3]; | |
936 | |
937 cache_fields = array_get(&dsync_box->cache_fields, &count); | |
938 if (count == 0) | |
939 return ""; | |
940 | |
941 str = t_str_new(128); | |
942 for (i = 0; i < count; i++) { | |
943 const struct mailbox_cache_field *field = &cache_fields[i]; | |
944 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
945 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX_CACHE_FIELD]); |
14584 | 946 dsync_serializer_encode_add(encoder, "name", field->name); |
947 | |
948 memset(decision, 0, sizeof(decision)); | |
949 switch (field->decision & ~MAIL_CACHE_DECISION_FORCED) { | |
950 case MAIL_CACHE_DECISION_NO: | |
951 decision[0] = 'n'; | |
952 break; | |
953 case MAIL_CACHE_DECISION_TEMP: | |
954 decision[0] = 't'; | |
955 break; | |
956 case MAIL_CACHE_DECISION_YES: | |
957 decision[0] = 'y'; | |
958 break; | |
959 } | |
960 i_assert(decision[0] != '\0'); | |
961 if ((field->decision & MAIL_CACHE_DECISION_FORCED) != 0) | |
962 decision[1] = 'F'; | |
963 dsync_serializer_encode_add(encoder, "decision", decision); | |
964 if (field->last_used != 0) { | |
965 dsync_serializer_encode_add(encoder, "last_used", | |
966 dec2str(field->last_used)); | |
967 } | |
968 dsync_serializer_encode_finish(&encoder, str); | |
969 } | |
970 if (i > 0) { | |
971 /* remove the trailing LF */ | |
972 str_truncate(str, str_len(str)-1); | |
973 } | |
974 return str_c(str); | |
975 } | |
976 | |
977 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
978 dsync_ibc_stream_send_mailbox(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
979 const struct dsync_mailbox *dsync_box) |
14584 | 980 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
981 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 982 struct dsync_serializer_encoder *encoder; |
983 string_t *str = t_str_new(128); | |
984 const char *value; | |
985 | |
986 str_append_c(str, items[ITEM_MAILBOX].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
987 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAILBOX]); |
14584 | 988 dsync_serializer_encode_add(encoder, "mailbox_guid", |
989 guid_128_to_string(dsync_box->mailbox_guid)); | |
990 | |
991 if (dsync_box->mailbox_lost) | |
992 dsync_serializer_encode_add(encoder, "mailbox_lost", ""); | |
993 dsync_serializer_encode_add(encoder, "uid_validity", | |
994 dec2str(dsync_box->uid_validity)); | |
995 dsync_serializer_encode_add(encoder, "uid_next", | |
996 dec2str(dsync_box->uid_next)); | |
997 dsync_serializer_encode_add(encoder, "messages_count", | |
998 dec2str(dsync_box->messages_count)); | |
999 dsync_serializer_encode_add(encoder, "first_recent_uid", | |
1000 dec2str(dsync_box->first_recent_uid)); | |
1001 dsync_serializer_encode_add(encoder, "highest_modseq", | |
1002 dec2str(dsync_box->highest_modseq)); | |
1003 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1004 value = get_cache_fields(ibc, dsync_box); |
14584 | 1005 if (value != NULL) |
1006 dsync_serializer_encode_add(encoder, "cache_fields", value); | |
1007 | |
1008 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1009 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1010 } |
1011 | |
1012 static int | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1013 parse_cache_field(struct dsync_ibc_stream *ibc, struct dsync_mailbox *box, |
14584 | 1014 const char *value) |
1015 { | |
1016 struct dsync_deserializer_decoder *decoder; | |
1017 struct mailbox_cache_field field; | |
1018 const char *error; | |
1019 int ret = 0; | |
1020 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1021 if (dsync_deserializer_decode_begin(ibc->deserializers[ITEM_MAILBOX_CACHE_FIELD], |
14584 | 1022 value, &decoder, &error) < 0) { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1023 dsync_ibc_input_error(ibc, NULL, |
14584 | 1024 "cache_field: Invalid input: %s", error); |
1025 return -1; | |
1026 } | |
1027 | |
1028 memset(&field, 0, sizeof(field)); | |
1029 value = dsync_deserializer_decode_get(decoder, "name"); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1030 field.name = p_strdup(ibc->ret_pool, value); |
14584 | 1031 |
1032 value = dsync_deserializer_decode_get(decoder, "decision"); | |
1033 switch (*value) { | |
1034 case 'n': | |
1035 field.decision = MAIL_CACHE_DECISION_NO; | |
1036 break; | |
1037 case 't': | |
1038 field.decision = MAIL_CACHE_DECISION_TEMP; | |
1039 break; | |
1040 case 'y': | |
1041 field.decision = MAIL_CACHE_DECISION_YES; | |
1042 break; | |
1043 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1044 dsync_ibc_input_error(ibc, decoder, "Invalid decision: %s", |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1045 value); |
14584 | 1046 ret = -1; |
1047 break; | |
1048 } | |
1049 if (value[1] == 'F') | |
1050 field.decision |= MAIL_CACHE_DECISION_FORCED; | |
1051 | |
1052 if (dsync_deserializer_decode_try(decoder, "last_used", &value) && | |
1053 str_to_time(value, &field.last_used) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1054 dsync_ibc_input_error(ibc, decoder, "Invalid last_used"); |
14584 | 1055 ret = -1; |
1056 } | |
1057 array_append(&box->cache_fields, &field, 1); | |
1058 | |
1059 dsync_deserializer_decode_finish(&decoder); | |
1060 return ret; | |
1061 } | |
1062 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1063 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1064 dsync_ibc_stream_recv_mailbox(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1065 const struct dsync_mailbox **dsync_box_r) |
14584 | 1066 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1067 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1068 pool_t pool = ibc->ret_pool; |
14584 | 1069 struct dsync_deserializer_decoder *decoder; |
1070 struct dsync_mailbox *box; | |
1071 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1072 enum dsync_ibc_recv_ret ret; |
14584 | 1073 |
1074 p_clear(pool); | |
1075 box = p_new(pool, struct dsync_mailbox, 1); | |
1076 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1077 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAILBOX, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1078 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1079 return ret; |
1080 | |
1081 value = dsync_deserializer_decode_get(decoder, "mailbox_guid"); | |
1082 if (guid_128_from_string(value, box->mailbox_guid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1083 dsync_ibc_input_error(ibc, decoder, "Invalid mailbox_guid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1084 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1085 } |
1086 | |
1087 if (dsync_deserializer_decode_try(decoder, "mailbox_lost", &value)) | |
1088 box->mailbox_lost = TRUE; | |
1089 value = dsync_deserializer_decode_get(decoder, "uid_validity"); | |
1090 if (str_to_uint32(value, &box->uid_validity) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1091 dsync_ibc_input_error(ibc, decoder, "Invalid uid_validity"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1092 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1093 } |
1094 value = dsync_deserializer_decode_get(decoder, "uid_next"); | |
1095 if (str_to_uint32(value, &box->uid_next) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1096 dsync_ibc_input_error(ibc, decoder, "Invalid uid_next"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1097 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1098 } |
1099 value = dsync_deserializer_decode_get(decoder, "messages_count"); | |
1100 if (str_to_uint32(value, &box->messages_count) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1101 dsync_ibc_input_error(ibc, decoder, "Invalid messages_count"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1102 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1103 } |
1104 value = dsync_deserializer_decode_get(decoder, "first_recent_uid"); | |
1105 if (str_to_uint32(value, &box->first_recent_uid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1106 dsync_ibc_input_error(ibc, decoder, "Invalid first_recent_uid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1107 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1108 } |
1109 value = dsync_deserializer_decode_get(decoder, "highest_modseq"); | |
1110 if (str_to_uint64(value, &box->highest_modseq) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1111 dsync_ibc_input_error(ibc, decoder, "Invalid highest_modseq"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1112 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1113 } |
1114 | |
1115 p_array_init(&box->cache_fields, pool, 32); | |
1116 if (dsync_deserializer_decode_try(decoder, "cache_fields", &value)) { | |
1117 const char *const *fields = t_strsplit(value, "\n"); | |
1118 for (; *fields != NULL; fields++) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1119 if (parse_cache_field(ibc, box, *fields) < 0) |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1120 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1121 } |
1122 } | |
1123 | |
1124 *dsync_box_r = box; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1125 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1126 } |
1127 | |
1128 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1129 dsync_ibc_stream_send_change(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1130 const struct dsync_mail_change *change) |
14584 | 1131 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1132 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1133 struct dsync_serializer_encoder *encoder; |
1134 string_t *str = t_str_new(128); | |
1135 char type[2]; | |
1136 | |
1137 str_append_c(str, items[ITEM_MAIL_CHANGE].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1138 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_CHANGE]); |
14584 | 1139 |
1140 type[0] = type[1] = '\0'; | |
1141 switch (change->type) { | |
1142 case DSYNC_MAIL_CHANGE_TYPE_SAVE: | |
1143 type[0] = 's'; | |
1144 break; | |
1145 case DSYNC_MAIL_CHANGE_TYPE_EXPUNGE: | |
1146 type[0] = 'e'; | |
1147 break; | |
1148 case DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE: | |
1149 type[0] = 'f'; | |
1150 break; | |
1151 } | |
1152 i_assert(type[0] != '\0'); | |
1153 dsync_serializer_encode_add(encoder, "type", type); | |
1154 dsync_serializer_encode_add(encoder, "uid", dec2str(change->uid)); | |
1155 if (change->guid != NULL) | |
1156 dsync_serializer_encode_add(encoder, "guid", change->guid); | |
1157 if (change->hdr_hash != NULL) { | |
1158 dsync_serializer_encode_add(encoder, "hdr_hash", | |
1159 change->hdr_hash); | |
1160 } | |
1161 if (change->modseq != 0) { | |
1162 dsync_serializer_encode_add(encoder, "modseq", | |
1163 dec2str(change->modseq)); | |
1164 } | |
1165 if (change->save_timestamp != 0) { | |
1166 dsync_serializer_encode_add(encoder, "save_timestamp", | |
1167 dec2str(change->save_timestamp)); | |
1168 } | |
1169 if (change->add_flags != 0) { | |
1170 dsync_serializer_encode_add(encoder, "add_flags", | |
1171 t_strdup_printf("%x", change->add_flags)); | |
1172 } | |
1173 if (change->remove_flags != 0) { | |
1174 dsync_serializer_encode_add(encoder, "remove_flags", | |
1175 t_strdup_printf("%x", change->remove_flags)); | |
1176 } | |
1177 if (change->final_flags != 0) { | |
1178 dsync_serializer_encode_add(encoder, "final_flags", | |
1179 t_strdup_printf("%x", change->final_flags)); | |
1180 } | |
1181 if (change->keywords_reset) | |
1182 dsync_serializer_encode_add(encoder, "keywords_reset", ""); | |
1183 | |
1184 if (array_is_created(&change->keyword_changes) && | |
1185 array_count(&change->keyword_changes) > 0) { | |
1186 string_t *kw_str = t_str_new(128); | |
1187 const char *const *changes; | |
1188 unsigned int i, count; | |
1189 | |
1190 changes = array_get(&change->keyword_changes, &count); | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
1191 str_append_tabescaped(kw_str, changes[0]); |
14584 | 1192 for (i = 1; i < count; i++) { |
1193 str_append_c(kw_str, '\t'); | |
15068
002e0a120c2a
Renamed str_tabescape_write() to str_append_tabescaped()
Timo Sirainen <tss@iki.fi>
parents:
15037
diff
changeset
|
1194 str_append_tabescaped(kw_str, changes[i]); |
14584 | 1195 } |
1196 dsync_serializer_encode_add(encoder, "keyword_changes", | |
1197 str_c(kw_str)); | |
1198 } | |
1199 | |
1200 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1201 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1202 } |
1203 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1204 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1205 dsync_ibc_stream_recv_change(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1206 const struct dsync_mail_change **change_r) |
14584 | 1207 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1208 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1209 pool_t pool = ibc->ret_pool; |
14584 | 1210 struct dsync_deserializer_decoder *decoder; |
1211 struct dsync_mail_change *change; | |
1212 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1213 enum dsync_ibc_recv_ret ret; |
14584 | 1214 |
1215 p_clear(pool); | |
1216 change = p_new(pool, struct dsync_mail_change, 1); | |
1217 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1218 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAIL_CHANGE, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1219 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1220 return ret; |
1221 | |
1222 value = dsync_deserializer_decode_get(decoder, "type"); | |
1223 switch (*value) { | |
1224 case 's': | |
1225 change->type = DSYNC_MAIL_CHANGE_TYPE_SAVE; | |
1226 break; | |
1227 case 'e': | |
1228 change->type = DSYNC_MAIL_CHANGE_TYPE_EXPUNGE; | |
1229 break; | |
1230 case 'f': | |
1231 change->type = DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE; | |
1232 break; | |
1233 default: | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1234 dsync_ibc_input_error(ibc, decoder, "Invalid type: %s", value); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1235 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1236 } |
1237 | |
1238 value = dsync_deserializer_decode_get(decoder, "uid"); | |
1239 if (str_to_uint32(value, &change->uid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1240 dsync_ibc_input_error(ibc, decoder, "Invalid uid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1241 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1242 } |
1243 | |
1244 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1245 change->guid = p_strdup(pool, value); | |
1246 if (dsync_deserializer_decode_try(decoder, "hdr_hash", &value)) | |
1247 change->hdr_hash = p_strdup(pool, value); | |
1248 if (dsync_deserializer_decode_try(decoder, "modseq", &value) && | |
1249 str_to_uint64(value, &change->modseq) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1250 dsync_ibc_input_error(ibc, decoder, "Invalid modseq"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1251 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1252 } |
1253 if (dsync_deserializer_decode_try(decoder, "save_timestamp", &value) && | |
1254 str_to_time(value, &change->save_timestamp) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1255 dsync_ibc_input_error(ibc, decoder, "Invalid save_timestamp"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1256 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1257 } |
1258 | |
1259 if (dsync_deserializer_decode_try(decoder, "add_flags", &value)) | |
1260 change->add_flags = strtoul(value, NULL, 16); | |
1261 if (dsync_deserializer_decode_try(decoder, "remove_flags", &value)) | |
1262 change->remove_flags = strtoul(value, NULL, 16); | |
1263 if (dsync_deserializer_decode_try(decoder, "final_flags", &value)) | |
1264 change->final_flags = strtoul(value, NULL, 16); | |
1265 if (dsync_deserializer_decode_try(decoder, "keywords_reset", &value)) | |
1266 change->keywords_reset = TRUE; | |
1267 | |
1268 if (dsync_deserializer_decode_try(decoder, "keyword_changes", &value) && | |
1269 *value != '\0') { | |
1270 const char *const *changes = t_strsplit_tab(value); | |
1271 unsigned int i, count = str_array_length(changes); | |
1272 | |
1273 p_array_init(&change->keyword_changes, pool, count); | |
1274 for (i = 0; i < count; i++) { | |
1275 value = p_strdup(pool, changes[i]); | |
1276 array_append(&change->keyword_changes, &value, 1); | |
1277 } | |
1278 } | |
1279 | |
1280 *change_r = change; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1281 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1282 } |
1283 | |
1284 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1285 dsync_ibc_stream_send_mail_request(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1286 const struct dsync_mail_request *request) |
14584 | 1287 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1288 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1289 struct dsync_serializer_encoder *encoder; |
1290 string_t *str = t_str_new(128); | |
1291 | |
1292 str_append_c(str, items[ITEM_MAIL_REQUEST].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1293 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL_REQUEST]); |
14584 | 1294 if (request->guid != NULL) |
1295 dsync_serializer_encode_add(encoder, "guid", request->guid); | |
1296 if (request->uid != 0) { | |
1297 dsync_serializer_encode_add(encoder, "uid", | |
1298 dec2str(request->uid)); | |
1299 } | |
1300 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1301 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1302 } |
1303 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1304 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1305 dsync_ibc_stream_recv_mail_request(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1306 const struct dsync_mail_request **request_r) |
14584 | 1307 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1308 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1309 struct dsync_deserializer_decoder *decoder; |
1310 struct dsync_mail_request *request; | |
1311 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1312 enum dsync_ibc_recv_ret ret; |
14584 | 1313 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1314 p_clear(ibc->ret_pool); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1315 request = p_new(ibc->ret_pool, struct dsync_mail_request, 1); |
14584 | 1316 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1317 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAIL_REQUEST, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1318 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1319 return ret; |
1320 | |
1321 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1322 request->guid = p_strdup(ibc->ret_pool, value); |
14584 | 1323 if (dsync_deserializer_decode_try(decoder, "uid", &value) && |
1324 str_to_uint32(value, &request->uid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1325 dsync_ibc_input_error(ibc, decoder, "Invalid uid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1326 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1327 } |
1328 | |
1329 *request_r = request; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1330 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1331 } |
1332 | |
1333 static void | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1334 dsync_ibc_stream_send_mail(struct dsync_ibc *_ibc, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1335 const struct dsync_mail *mail) |
14584 | 1336 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1337 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1338 struct dsync_serializer_encoder *encoder; |
1339 string_t *str = t_str_new(128); | |
1340 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1341 i_assert(ibc->mail_output == NULL); |
14584 | 1342 |
1343 str_append_c(str, items[ITEM_MAIL].chr); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1344 encoder = dsync_serializer_encode_begin(ibc->serializers[ITEM_MAIL]); |
14584 | 1345 if (mail->guid != NULL) |
1346 dsync_serializer_encode_add(encoder, "guid", mail->guid); | |
1347 if (mail->uid != 0) | |
1348 dsync_serializer_encode_add(encoder, "uid", dec2str(mail->uid)); | |
1349 if (mail->pop3_uidl != NULL) { | |
1350 dsync_serializer_encode_add(encoder, "pop3_uidl", | |
1351 mail->pop3_uidl); | |
1352 } | |
1353 if (mail->pop3_order > 0) { | |
1354 dsync_serializer_encode_add(encoder, "pop3_order", | |
1355 dec2str(mail->pop3_order)); | |
1356 } | |
1357 if (mail->received_date > 0) { | |
1358 dsync_serializer_encode_add(encoder, "received_date", | |
1359 dec2str(mail->received_date)); | |
1360 } | |
1361 if (mail->input != NULL) | |
1362 dsync_serializer_encode_add(encoder, "stream", ""); | |
1363 | |
1364 dsync_serializer_encode_finish(&encoder, str); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1365 dsync_ibc_stream_send_string(ibc, str); |
14584 | 1366 |
1367 if (mail->input != NULL) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1368 ibc->mail_output_last = '\0'; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1369 ibc->mail_output = mail->input; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1370 i_stream_ref(ibc->mail_output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1371 (void)dsync_ibc_stream_send_mail_stream(ibc); |
14584 | 1372 } |
1373 } | |
1374 | |
1375 static int seekable_fd_callback(const char **path_r, void *context) | |
1376 { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1377 struct dsync_ibc_stream *ibc = context; |
14584 | 1378 string_t *path; |
1379 int fd; | |
1380 | |
1381 path = t_str_new(128); | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1382 str_append(path, ibc->temp_path_prefix); |
14584 | 1383 fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1); |
1384 if (fd == -1) { | |
1385 i_error("safe_mkstemp(%s) failed: %m", str_c(path)); | |
1386 return -1; | |
1387 } | |
1388 | |
1389 /* we just want the fd, unlink it */ | |
1390 if (unlink(str_c(path)) < 0) { | |
1391 /* shouldn't happen.. */ | |
1392 i_error("unlink(%s) failed: %m", str_c(path)); | |
14691
3945a3646c67
Changed i_close_fd() API to set the fd to -1 after closing.
Timo Sirainen <tss@iki.fi>
parents:
14687
diff
changeset
|
1393 i_close_fd(&fd); |
14584 | 1394 return -1; |
1395 } | |
1396 | |
1397 *path_r = str_c(path); | |
1398 return fd; | |
1399 } | |
1400 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1401 static enum dsync_ibc_recv_ret |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1402 dsync_ibc_stream_recv_mail(struct dsync_ibc *_ibc, struct dsync_mail **mail_r) |
14584 | 1403 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1404 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1405 pool_t pool = ibc->ret_pool; |
14584 | 1406 struct dsync_deserializer_decoder *decoder; |
1407 struct dsync_mail *mail; | |
1408 struct istream *inputs[2]; | |
1409 const char *value; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1410 enum dsync_ibc_recv_ret ret; |
14584 | 1411 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1412 if (ibc->mail_input != NULL) { |
14584 | 1413 /* wait until the mail's stream has been read */ |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1414 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1415 } |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1416 if (ibc->cur_mail != NULL) { |
14584 | 1417 /* finished reading the stream, return the mail now */ |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1418 *mail_r = ibc->cur_mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1419 ibc->cur_mail = NULL; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1420 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1421 } |
1422 | |
1423 p_clear(pool); | |
1424 mail = p_new(pool, struct dsync_mail, 1); | |
1425 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1426 ret = dsync_ibc_stream_input_next(ibc, ITEM_MAIL, &decoder); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1427 if (ret != DSYNC_IBC_RECV_RET_OK) |
14584 | 1428 return ret; |
1429 | |
1430 if (dsync_deserializer_decode_try(decoder, "guid", &value)) | |
1431 mail->guid = p_strdup(pool, value); | |
1432 if (dsync_deserializer_decode_try(decoder, "uid", &value) && | |
1433 str_to_uint32(value, &mail->uid) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1434 dsync_ibc_input_error(ibc, decoder, "Invalid uid"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1435 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1436 } |
1437 if (dsync_deserializer_decode_try(decoder, "pop3_uidl", &value)) | |
1438 mail->pop3_uidl = p_strdup(pool, value); | |
1439 if (dsync_deserializer_decode_try(decoder, "pop3_order", &value) && | |
1440 str_to_uint(value, &mail->pop3_order) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1441 dsync_ibc_input_error(ibc, decoder, "Invalid pop3_order"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1442 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1443 } |
1444 if (dsync_deserializer_decode_try(decoder, "received_date", &value) && | |
1445 str_to_time(value, &mail->received_date) < 0) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1446 dsync_ibc_input_error(ibc, decoder, "Invalid received_date"); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1447 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1448 } |
1449 if (dsync_deserializer_decode_try(decoder, "stream", &value)) { | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1450 inputs[0] = i_stream_create_dot(ibc->input, FALSE); |
14584 | 1451 inputs[1] = NULL; |
1452 mail->input = i_stream_create_seekable(inputs, | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1453 MAIL_READ_FULL_BLOCK_SIZE, seekable_fd_callback, ibc); |
14584 | 1454 i_stream_unref(&inputs[0]); |
1455 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1456 ibc->mail_input = mail->input; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1457 if (dsync_ibc_stream_read_mail_stream(ibc) <= 0) { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1458 ibc->cur_mail = mail; |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1459 return DSYNC_IBC_RECV_RET_TRYAGAIN; |
14584 | 1460 } |
1461 /* already finished reading the stream */ | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1462 i_assert(ibc->mail_input == NULL); |
14584 | 1463 } |
1464 | |
1465 *mail_r = mail; | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1466 return DSYNC_IBC_RECV_RET_OK; |
14584 | 1467 } |
1468 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1469 static void dsync_ibc_stream_flush(struct dsync_ibc *_ibc) |
14584 | 1470 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1471 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1472 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1473 o_stream_uncork(ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1474 o_stream_cork(ibc->output); |
14584 | 1475 } |
1476 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1477 static bool dsync_ibc_stream_is_send_queue_full(struct dsync_ibc *_ibc) |
14584 | 1478 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1479 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1480 size_t bytes; |
1481 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1482 if (ibc->mail_output != NULL) |
14584 | 1483 return TRUE; |
1484 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1485 bytes = o_stream_get_buffer_used_size(ibc->output); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1486 if (bytes < DSYNC_IBC_STREAM_OUTBUF_THROTTLE_SIZE) |
14584 | 1487 return FALSE; |
1488 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1489 o_stream_set_flush_pending(ibc->output, TRUE); |
14584 | 1490 return TRUE; |
1491 } | |
1492 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1493 static bool dsync_ibc_stream_has_pending_data(struct dsync_ibc *_ibc) |
14584 | 1494 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1495 struct dsync_ibc_stream *ibc = (struct dsync_ibc_stream *)_ibc; |
14584 | 1496 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1497 return ibc->has_pending_data; |
14584 | 1498 } |
1499 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1500 static const struct dsync_ibc_vfuncs dsync_ibc_stream_vfuncs = { |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1501 dsync_ibc_stream_deinit, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1502 dsync_ibc_stream_send_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1503 dsync_ibc_stream_recv_handshake, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1504 dsync_ibc_stream_send_end_of_list, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1505 dsync_ibc_stream_send_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1506 dsync_ibc_stream_recv_mailbox_state, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1507 dsync_ibc_stream_send_mailbox_tree_node, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1508 dsync_ibc_stream_recv_mailbox_tree_node, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1509 dsync_ibc_stream_send_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1510 dsync_ibc_stream_recv_mailbox_deletes, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1511 dsync_ibc_stream_send_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1512 dsync_ibc_stream_recv_mailbox, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1513 dsync_ibc_stream_send_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1514 dsync_ibc_stream_recv_change, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1515 dsync_ibc_stream_send_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1516 dsync_ibc_stream_recv_mail_request, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1517 dsync_ibc_stream_send_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1518 dsync_ibc_stream_recv_mail, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1519 dsync_ibc_stream_flush, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1520 dsync_ibc_stream_is_send_queue_full, |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1521 dsync_ibc_stream_has_pending_data |
14584 | 1522 }; |
1523 | |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1524 struct dsync_ibc * |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1525 dsync_ibc_init_stream(struct istream *input, struct ostream *output, |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1526 const char *name, const char *temp_path_prefix) |
14584 | 1527 { |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1528 struct dsync_ibc_stream *ibc; |
14584 | 1529 |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1530 ibc = i_new(struct dsync_ibc_stream, 1); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1531 ibc->ibc.v = dsync_ibc_stream_vfuncs; |
15464
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1532 ibc->input = input; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1533 ibc->output = output; |
af3b86a16ac3
dsync: Added debugging and rawlogging support.
Timo Sirainen <tss@iki.fi>
parents:
15463
diff
changeset
|
1534 ibc->fd_in = i_stream_get_fd(input); |
15037
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1535 ibc->name = i_strdup(name); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1536 ibc->temp_path_prefix = i_strdup(temp_path_prefix); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1537 ibc->ret_pool = pool_alloconly_create("ibc stream data", 2048); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1538 dsync_ibc_stream_init(ibc); |
920756cd29b8
dsync: Renamed "slave" to "ibc" (= inter-brain communicator)
Timo Sirainen <tss@iki.fi>
parents:
15036
diff
changeset
|
1539 return &ibc->ibc; |
14584 | 1540 } |